Skip to content

feat(customer): get by usage attribution - #3082

Merged
hekike merged 2 commits into
mainfrom
feat/customer-get-usage-attribution
Jul 9, 2025
Merged

hekike merged 2 commits into
mainfrom
feat/customer-get-usage-attribution

Conversation

@hekike

@hekike hekike commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor

Lookup customer by usage attribution subject key.

Summary by CodeRabbit

  • New Features
    • Added the ability to retrieve a customer using a usage attribution subject key.
    • Introduced input validation for retrieving customers by usage attribution.
  • Refactor
    • Improved modularity and reduced duplication in customer query construction.
  • Tests
    • Added tests to verify customer retrieval by usage attribution subject key.

@hekike
hekike requested a review from chrisgacsal July 8, 2025 14:18
@hekike
hekike requested a review from a team as a code owner July 8, 2025 14:18
@hekike hekike added release-note/ignore Ignore this change when generating release notes area/billing labels Jul 8, 2025
@coderabbitai

coderabbitai Bot commented Jul 8, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

A new method, GetCustomerByUsageAttribution, was introduced across the customer domain's interfaces, adapters, and service layers. Supporting input validation and query logic were added, along with corresponding tests. Query construction in the adapter was refactored for modularity. Test coverage was expanded to verify the new method's behavior.

Changes

Files Change Summary
openmeter/customer/adapter.go
openmeter/customer/service.go
Added GetCustomerByUsageAttribution method to CustomerAdapter and CustomerService interfaces.
openmeter/customer/adapter/customer.go Refactored query logic into helpers; implemented GetCustomerByUsageAttribution with input validation and query.
openmeter/customer/customer.go Added GetCustomerByUsageAttributionInput struct and its validation method.
openmeter/customer/service/customer.go Implemented GetCustomerByUsageAttribution on the Service struct, delegating to the adapter.
openmeter/server/server_test.go Added no-op GetCustomerByUsageAttribution to NoopCustomerService for test compatibility.
test/customer/customer.go Added TestGetByUsageAttribution to test retrieving a customer by usage attribution subject key.
test/customer/customer_test.go Registered new subtest for TestGetByUsageAttribution in the customer test suite.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8137710 and cd01284.

📒 Files selected for processing (2)
  • openmeter/customer/adapter/customer.go (4 hunks)
  • test/customer/customer.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/customer/customer.go
  • openmeter/customer/adapter/customer.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Commit hooks
  • GitHub Check: CI
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Quickstart
  • GitHub Check: Developer environment
  • GitHub Check: Migration Checks
  • GitHub Check: Build
  • GitHub Check: Test
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
openmeter/customer/service/customer.go (1)

84-87: Implementation is correct, but consider input validation for consistency.

The method correctly delegates to the adapter following the established pattern. However, unlike other service methods (CreateCustomer, UpdateCustomer, DeleteCustomer), this method doesn't perform input validation through the request validator registry.

Consider adding validation for consistency:

func (s *Service) GetCustomerByUsageAttribution(ctx context.Context, input customer.GetCustomerByUsageAttributionInput) (*customer.Customer, error) {
+	// Validate the input
+	if err := s.requestValidatorRegistry.ValidateGetCustomerByUsageAttribution(ctx, input); err != nil {
+		return nil, models.NewGenericValidationError(err)
+	}
+
	return s.adapter.GetCustomerByUsageAttribution(ctx, input)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 72f441d and 8137710.

📒 Files selected for processing (8)
  • openmeter/customer/adapter.go (1 hunks)
  • openmeter/customer/adapter/customer.go (4 hunks)
  • openmeter/customer/customer.go (1 hunks)
  • openmeter/customer/service.go (1 hunks)
  • openmeter/customer/service/customer.go (1 hunks)
  • openmeter/server/server_test.go (1 hunks)
  • test/customer/customer.go (1 hunks)
  • test/customer/customer_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
openmeter/customer/service.go (3)
openmeter/customer/customer.go (2)
  • GetCustomerByUsageAttributionInput (141-144)
  • Customer (15-24)
openmeter/ent/schema/customer.go (5)
  • Customer (17-19)
  • Customer (21-28)
  • Customer (30-38)
  • Customer (40-53)
  • Customer (55-67)
openmeter/ent/db/customer.go (2)
  • Customer (20-62)
  • Customer (129-144)
openmeter/customer/customer.go (3)
openmeter/ent/db/customersubjects/where.go (2)
  • Namespace (59-61)
  • SubjectKey (69-71)
pkg/models/validator.go (1)
  • Validate (16-26)
pkg/models/errors.go (1)
  • NewGenericValidationError (138-140)
openmeter/customer/adapter.go (4)
openmeter/customer/customer.go (2)
  • GetCustomerByUsageAttributionInput (141-144)
  • Customer (15-24)
api/api.gen.go (1)
  • Customer (2113-2160)
api/client/go/client.gen.go (1)
  • Customer (1943-1990)
openmeter/ent/db/predicate/predicate.go (1)
  • Customer (153-153)
test/customer/customer.go (1)
openmeter/customer/customer.go (5)
  • Customer (15-24)
  • CreateCustomerInput (187-190)
  • CustomerMutate (47-56)
  • CustomerUsageAttribution (127-129)
  • GetCustomerByUsageAttributionInput (141-144)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Artifacts / Container image
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: E2E
  • GitHub Check: CI
  • GitHub Check: Quickstart
  • GitHub Check: Test
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: Developer environment
  • GitHub Check: Build
  • GitHub Check: Commit hooks
🔇 Additional comments (9)
test/customer/customer_test.go (1)

42-44: LGTM! Test integration follows established patterns.

The new test case is properly integrated into the existing test suite and follows the same pattern as other tests.

openmeter/customer/adapter.go (1)

21-21: LGTM! Interface method addition is consistent.

The new method follows the established pattern of other interface methods and has appropriate input/output types.

openmeter/customer/service.go (1)

24-24: LGTM! Service interface method is properly defined.

The method signature is consistent with the adapter interface and is logically placed within the service interface.

openmeter/server/server_test.go (1)

1037-1039: LGTM! No-op implementation is consistent with testing patterns.

The implementation follows the same pattern as other no-op methods and returns appropriate values for testing purposes.

openmeter/customer/customer.go (1)

140-156: LGTM! Well-structured input struct and validation.

The new GetCustomerByUsageAttributionInput struct follows the established patterns in the codebase with proper validation logic. The validation method correctly checks for required fields and uses consistent error handling.

test/customer/customer.go (1)

538-570: LGTM! Comprehensive test coverage for the new functionality.

The test method follows the established patterns in the test suite and provides good coverage of the GetCustomerByUsageAttribution functionality. It properly:

  • Sets up the test environment with a namespace
  • Creates a customer with usage attribution subject keys
  • Exercises the new method with valid input
  • Validates all expected fields in the response
openmeter/customer/adapter/customer.go (3)

40-42: LGTM! Good refactoring to use helper functions.

The refactoring improves code modularity by extracting common query building logic into reusable helper functions.


307-309: LGTM! Consistent use of helper functions.

The refactoring maintains consistency with the ListCustomers method and improves code maintainability.


615-635: LGTM! Well-designed helper functions.

The helper functions properly encapsulate common query building logic:

  • withSubjects correctly filters out deleted subjects
  • withActiveSubscription and withSubscription properly handle subscription filtering and plan loading

These functions improve code maintainability and reduce duplication.

Comment thread openmeter/customer/adapter/customer.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/billing release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants