Repository navigation
feat: add fs for disabling invocing on a namespace - #2768
Conversation
📝 WalkthroughWalkthroughThis change introduces a namespace lockdown feature in the billing subsystem, allowing certain namespaces to be locked and excluded from billing operations. New configuration structs and validation logic are added to support a list of locked namespaces, which is now part of the billing configuration and injected throughout the application using dependency injection. The billing service and related interfaces are extended to handle locked namespaces, and error handling is updated to recognize and process the new "namespace locked" error. Invoice state transitions and invoice creation methods are modified to enforce lockdown restrictions. Tests are added and updated to verify the correct handling of locked namespaces during invoice creation and progression. Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (16)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (15)
⏰ Context from checks skipped due to timeout of 90000ms (11)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
6b930b5 to
36602ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
app/common/billing.go (1)
64-64: LGTM! Configuration properly passed to service.The namespace lockdown configuration is correctly passed to the billing service implementation.
Consider adding a comment explaining the purpose of
FSNamespaceLockdownfor improved code documentation:service, err := billingservice.New(billingservice.Config{ Adapter: billingAdapter, AppService: appService, CustomerService: customerService, FeatureService: featureConnector, Logger: logger, MeterService: meterService, StreamingConnector: streamingConnector, Publisher: eventPublisher, AdvancementStrategy: advancementStrategy, + // FSNamespaceLockdown contains a list of namespace IDs that should be excluded from billing operations FSNamespaceLockdown: fsConfig.NamespaceLockdown, })openmeter/billing/service.go (1)
90-91: Interface methods added for billing service configuration.The addition of these interface methods is appropriate for supporting the new namespace lockdown feature and maintaining a clean configuration approach.
Consider adding doc comments to explain the purpose of these methods:
type ConfigService interface { GetAdvancementStrategy() AdvancementStrategy + // WithAdvancementStrategy returns a new service instance with the specified advancement strategy WithAdvancementStrategy(strategy AdvancementStrategy) Service + // WithLockedNamespaces returns a service that will restrict billing operations for the specified namespaces WithLockedNamespaces(namespaces []string) Service }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
app/common/billing.go(3 hunks)app/common/config.go(1 hunks)app/config/billing.go(2 hunks)cmd/billing-worker/wire_gen.go(1 hunks)cmd/jobs/internal/wire_gen.go(1 hunks)cmd/server/wire_gen.go(1 hunks)openmeter/billing/errors.go(1 hunks)openmeter/billing/service.go(1 hunks)openmeter/billing/service/invoice.go(1 hunks)openmeter/billing/service/invoicestate.go(7 hunks)openmeter/billing/service/service.go(4 hunks)openmeter/billing/worker/collect/collect.go(1 hunks)openmeter/billing/worker/subscription/handlers.go(2 hunks)openmeter/server/server_test.go(1 hunks)test/billing/invoice_test.go(1 hunks)test/billing/suite.go(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
app/common/config.go (1)
app/config/billing.go (1)
BillingConfiguration(12-16)
openmeter/billing/errors.go (1)
openmeter/billing/validationissue.go (1)
NewValidationError(75-81)
cmd/jobs/internal/wire_gen.go (1)
app/common/billing.go (1)
BillingService(41-92)
cmd/billing-worker/wire_gen.go (1)
app/common/billing.go (1)
BillingService(41-92)
app/common/billing.go (1)
app/config/billing.go (1)
BillingFeatureSwitchesConfiguration(35-37)
openmeter/billing/worker/collect/collect.go (2)
openmeter/billing/errors.go (1)
ErrNamespaceLocked(59-59)openmeter/customer/customer.go (1)
CustomerID(74-74)
openmeter/billing/service.go (2)
openmeter/billing/serviceconfig.go (1)
AdvancementStrategy(8-8)openmeter/billing/service/service.go (1)
Service(23-38)
openmeter/billing/worker/subscription/handlers.go (2)
openmeter/billing/errors.go (1)
ErrNamespaceLocked(59-59)api/api.gen.go (1)
Customer(2117-2164)
openmeter/billing/service/service.go (1)
openmeter/billing/service.go (1)
Service(9-19)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: CI
- GitHub Check: Quickstart
- GitHub Check: E2E
- GitHub Check: Developer environment
- GitHub Check: Commit hooks
- GitHub Check: Migration Checks
- GitHub Check: Lint
- GitHub Check: Test
- GitHub Check: Build
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (go)
🔇 Additional comments (29)
app/common/config.go (1)
18-18: Configuration update for feature switches looks good.This change adds support for
FeatureSwitchesdependency injection from theBillingConfigurationstruct, enabling the namespace lockdown feature to be propagated throughout the billing system.openmeter/billing/errors.go (1)
59-59: New validation error defined correctly.The new
ErrNamespaceLockederror is properly defined as a critical validation error, consistent with other validation errors in the system. This error will be used to indicate when a namespace has been locked for billing operations.openmeter/billing/worker/collect/collect.go (1)
161-165: Appropriate error handling for locked namespaces.This change adds proper handling of the new
ErrNamespaceLockederror, allowing the system to gracefully skip invoice collection for locked namespaces. The warning message provides good visibility while maintaining system stability.cmd/jobs/internal/wire_gen.go (1)
278-279: Wire configuration updated correctly for feature switches.The dependency injection setup now correctly extracts and passes the billing feature switches configuration to the billing service. This change ensures the namespace lockdown feature will be properly initialized and available throughout the system.
cmd/billing-worker/wire_gen.go (1)
271-272: LGTM! Good integration of the namespace lockdown feature.This change properly extracts the feature switches configuration from the billing configuration and passes it to the
common.BillingServicefunction, aligning with other initialization files.app/common/billing.go (2)
8-8: LGTM! Import added correctly.The config package import is necessary for the new parameter type.
52-52: LGTM! Proper parameter addition.The new parameter for feature switches configuration extends the function signature correctly to support namespace lockdown functionality.
cmd/server/wire_gen.go (1)
272-273: LGTM! Consistent implementation across initialization files.This change correctly extracts the feature switches configuration and passes it to the billing service, maintaining consistency with other initialization files.
openmeter/billing/service/invoice.go (1)
234-238: Good implementation of namespace lockdown validation.The code correctly checks if a namespace is in the lockdown list before proceeding with invoice processing, returning an appropriate validation error when needed. The early validation ensures no processing resources are wasted on locked namespaces.
openmeter/billing/worker/subscription/handlers.go (2)
56-59: Appropriate error handling for locked namespaces.The code correctly identifies and handles the namespace lockdown case, providing a clear warning log and gracefully continuing execution. This ensures operations aren't disrupted when a namespace is locked.
173-177: Consistent namespace lockdown error handling.The implementation maintains the same error handling pattern for locked namespaces as in the HandleCancelledEvent method, ensuring consistency throughout the codebase while providing appropriate logging.
openmeter/server/server_test.go (1)
1482-1488: Correctly implemented interface methods for test compatibility.The no-op implementations of WithAdvancementStrategy and WithLockedNamespaces methods maintain compatibility with the updated billing.Service interface while preserving the test double pattern. Both methods properly return the receiver to support method chaining.
app/config/billing.go (2)
15-15: Well-structured configuration for namespace lockdown feature.The addition of the FeatureSwitches field and its validation in the BillingConfiguration struct provides a clean way to integrate the namespace lockdown feature into the configuration system.
Also applies to: 28-30
35-41: Clean implementation of feature switches configuration.The new BillingFeatureSwitchesConfiguration struct is well-designed with a clear purpose. The empty Validate method provides a hook for future validation rules as the feature evolves.
test/billing/suite.go (2)
314-388: Renamed method with clear documentationThe
CreateDraftInvoicemethod has been renamed toCreateGatheringInvoice, which better reflects its purpose of creating pending invoice lines without generating an actual invoice.
390-409: Well-designed method implementationThe new
CreateDraftInvoicemethod appropriately reusesCreateGatheringInvoiceand then callsInvoicePendingLines, maintaining the DRY principle while separating concerns. This refactoring enables tests to verify both gathering and draft invoice creation separately, which is essential for testing the new namespace lockdown functionality.openmeter/billing/service/service.go (5)
37-37: Feature switch for namespace lockdown addedAdded a field to store namespaces that should be locked for billing operations.
50-50: Configuration structure extended appropriatelyThe Config struct properly includes the feature switch configuration for namespace lockdown, maintaining consistency with the Service struct.
108-108: Consistent initialization in constructorThe namespace lockdown list is properly initialized from the configuration, ensuring consistency between the configuration and service state.
190-194: Added support for modifying advancement strategyThis method creates a copy of the service with a new advancement strategy, following the functional options pattern for immutable configuration changes.
196-200: Added support for modifying locked namespacesThis method allows dynamic configuration of which namespaces are locked for billing operations, providing flexibility for testing and runtime changes.
test/billing/invoice_test.go (2)
3661-3691: Comprehensive test for namespace lockdown on invoice creationThis test verifies that when a namespace is locked, attempts to create invoices fail with the appropriate
ErrNamespaceLockederror. The test follows a clear arrange-act-assert pattern and properly cleans up after itself by restoring the original billing service.
3693-3737: Thorough test for namespace lockdown on invoice progressionThis test effectively verifies that when a namespace becomes locked, existing invoices cannot be advanced and are properly marked as invalid with the appropriate validation error. It tests the full invoice lifecycle by first creating an invoice without lockdown, then attempting to advance it after locking the namespace.
openmeter/billing/service/invoicestate.go (6)
28-28: Feature switch field added to InvoiceStateMachineAdded field to store the list of locked namespaces, enabling the state machine to enforce lockdown restrictions during invoice operations.
252-252: Proper propagation of locked namespacesThe locked namespaces list is correctly propagated from the service to the state machine, ensuring consistency across the application.
535-537: Namespace lockdown check for validationAppropriate check to prevent invoice validation when the namespace is locked, with a clear error message that includes the namespace name.
550-552: Namespace lockdown check for invoice syncingConsistent implementation of the lockdown check before syncing draft invoices with external systems, using the same error format as other methods.
571-573: Namespace lockdown check for invoice finalizationProper enforcement of namespace lockdown during invoice finalization, ensuring that locked namespaces cannot proceed to payment processing.
606-608: Namespace lockdown check for deleted invoice syncingComplete implementation of the lockdown feature by also preventing sync operations for deleted invoices in locked namespaces.
4954687 to
ce2389a
Compare
Overview
Allow temporary suspending all billing activity on a namespace.
Summary by CodeRabbit