Skip to content

Remove subscription.RateCard - #2638

Merged
GAlexIHU merged 2 commits into
mainfrom
galexi/refactor/remove-subscription-ratecard
Apr 10, 2025
Merged

GAlexIHU merged 2 commits into
mainfrom
galexi/refactor/remove-subscription-ratecard

Conversation

@GAlexIHU

@GAlexIHU GAlexIHU commented Apr 9, 2025 •

Copy link
Copy Markdown
Contributor

Overview

Long overdue refactor

Notes for reviewer

Summary by CodeRabbit

  • New Features

    • Introduced dynamic metadata handling for rate cards, enabling on-the-fly modifications and supporting both flat fee and usage-based models.
  • Bug Fixes

    • Enhanced error detection for missing billing cadence, reducing potential runtime issues.
  • Refactor

    • Streamlined how rate card information is accessed and managed across subscription and billing workflows.
    • Updated tests to align with the new rate card structure and metadata handling.
  • Chores

    • Removed legacy serialization and deprecated structures to simplify patch and subscription management.

@GAlexIHU GAlexIHU added the release-note/ignore Ignore this change when generating release notes label Apr 9, 2025
@GAlexIHU GAlexIHU self-assigned this Apr 9, 2025
@GAlexIHU
GAlexIHU requested a review from a team as a code owner April 9, 2025 16:46
@coderabbitai

coderabbitai Bot commented Apr 9, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request refactors how RateCard properties are accessed across multiple modules. Direct field accesses have been replaced by method calls (primarily using AsMeta() and related accessor methods) to encapsulate logic and ensure consistency. Changes span validators, workers, subscription services, tests, and product catalog modules. Additionally, the RateCard type is now sourced from the productcatalog package, a new ChangeMeta method has been introduced, and legacy patch serialization code has been removed.

Changes

File(s) Change Summary
openmeter/billing/.../validator.go, openmeter/billing/.../phaseiterator.go, openmeter/billing/.../sync.go, openmeter/billing/.../phaseiterator_test.go, openmeter/billing/.../sync_test.go Refactored RateCard property access by replacing direct field access with AsMeta() calls and improving error handling.
openmeter/productcatalog/ratecard.go Introduced a new ChangeMeta method to the RateCard interface and its implementations for dynamic metadata updates.
openmeter/subscription/item.go, openmeter/subscription/repository.go, openmeter/subscription/repo/mapping.go, openmeter/subscription/repo/subscriptionitemrepo.go, openmeter/subscription/subscriptionspec.go, openmeter/subscription/service/service.go, openmeter/subscription/service/sync_test.go, openmeter/subscription/subscriptionview.go, openmeter/subscription/testutils/compare.go Updated RateCard type to productcatalog.RateCard and standardized property access via AsMeta(), streamlining validations and mappings.
openmeter/subscription/patch.go, openmeter/subscription/patch/additem_test.go, openmeter/subscription/patch/serialization.go, openmeter/subscription/patch/serialization_test.go, openmeter/subscription/ratecard.go Removed json.Marshaler from the Patch interface, deprecated the local RateCard implementation, and eliminated patch serialization logic.
openmeter/subscription/workflow/service/subscription_test.go, test/subscription/scenario_editaligned_test.go, test/subscription/scenario_editcancel_test.go Modified test cases to adopt usage-based RateCard types and revised billing cadence handling.

Possibly related PRs

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
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 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 ec60da3 and 737fe8b.

📒 Files selected for processing (27)
  • openmeter/billing/validators/subscription/validator.go (1 hunks)
  • openmeter/billing/worker/subscription/phaseiterator.go (10 hunks)
  • openmeter/billing/worker/subscription/phaseiterator_test.go (1 hunks)
  • openmeter/billing/worker/subscription/sync.go (3 hunks)
  • openmeter/billing/worker/subscription/sync_test.go (5 hunks)
  • openmeter/productcatalog/ratecard.go (3 hunks)
  • openmeter/productcatalog/subscription/http/mapping.go (3 hunks)
  • openmeter/productcatalog/subscription/plan.go (1 hunks)
  • openmeter/productcatalog/subscription/service/plan_test.go (1 hunks)
  • openmeter/subscription/item.go (2 hunks)
  • openmeter/subscription/patch.go (0 hunks)
  • openmeter/subscription/patch/additem_test.go (4 hunks)
  • openmeter/subscription/patch/patch_test.go (4 hunks)
  • openmeter/subscription/patch/serialization.go (0 hunks)
  • openmeter/subscription/patch/serialization_test.go (0 hunks)
  • openmeter/subscription/ratecard.go (0 hunks)
  • openmeter/subscription/repo/mapping.go (2 hunks)
  • openmeter/subscription/repo/subscriptionitemrepo.go (1 hunks)
  • openmeter/subscription/repository.go (1 hunks)
  • openmeter/subscription/service/service.go (1 hunks)
  • openmeter/subscription/service/sync_test.go (3 hunks)
  • openmeter/subscription/subscriptionspec.go (10 hunks)
  • openmeter/subscription/subscriptionview.go (5 hunks)
  • openmeter/subscription/testutils/compare.go (3 hunks)
  • openmeter/subscription/workflow/service/subscription_test.go (4 hunks)
  • test/subscription/scenario_editaligned_test.go (2 hunks)
  • test/subscription/scenario_editcancel_test.go (1 hunks)
💤 Files with no reviewable changes (4)
  • openmeter/subscription/ratecard.go
  • openmeter/subscription/patch.go
  • openmeter/subscription/patch/serialization_test.go
  • openmeter/subscription/patch/serialization.go
🚧 Files skipped from review as they are similar to previous changes (18)
  • openmeter/billing/validators/subscription/validator.go
  • openmeter/subscription/item.go
  • openmeter/subscription/repository.go
  • openmeter/subscription/testutils/compare.go
  • openmeter/subscription/subscriptionview.go
  • openmeter/subscription/patch/patch_test.go
  • openmeter/productcatalog/subscription/service/plan_test.go
  • test/subscription/scenario_editaligned_test.go
  • openmeter/subscription/repo/subscriptionitemrepo.go
  • openmeter/subscription/workflow/service/subscription_test.go
  • openmeter/subscription/service/service.go
  • openmeter/billing/worker/subscription/phaseiterator.go
  • openmeter/productcatalog/subscription/http/mapping.go
  • openmeter/subscription/service/sync_test.go
  • openmeter/productcatalog/subscription/plan.go
  • openmeter/subscription/repo/mapping.go
  • openmeter/subscription/subscriptionspec.go
  • openmeter/billing/worker/subscription/sync.go
🧰 Additional context used
🧬 Code Graph Analysis (5)
test/subscription/scenario_editcancel_test.go (2)
openmeter/productcatalog/ratecard.go (3)
  • RateCard (27-38)
  • UsageBasedRateCard (322-328)
  • RateCardMeta (49-80)
openmeter/testutils/time.go (1)
  • GetISODuration (19-26)
openmeter/subscription/patch/additem_test.go (3)
openmeter/productcatalog/ratecard.go (3)
  • RateCard (27-38)
  • FlatFeeRateCard (212-219)
  • RateCardMeta (49-80)
openmeter/productcatalog/subscription/plan.go (1)
  • RateCard (130-133)
openmeter/productcatalog/price.go (2)
  • NewPriceFrom (342-364)
  • InAdvancePaymentTerm (20-20)
openmeter/billing/worker/subscription/phaseiterator_test.go (4)
openmeter/productcatalog/ratecard.go (4)
  • RateCard (27-38)
  • UsageBasedRateCard (322-328)
  • RateCardMeta (49-80)
  • FlatFeeRateCard (212-219)
pkg/isodate/date.go (1)
  • MustParse (151-158)
openmeter/productcatalog/price.go (1)
  • NewPriceFrom (342-364)
openmeter/subscription/item.go (1)
  • SubscriptionItem (9-39)
openmeter/productcatalog/ratecard.go (1)
pkg/models/validator.go (1)
  • Validate (16-26)
openmeter/billing/worker/subscription/sync_test.go (2)
openmeter/productcatalog/ratecard.go (3)
  • RateCard (27-38)
  • FlatFeeRateCard (212-219)
  • RateCardMeta (49-80)
openmeter/productcatalog/price.go (1)
  • NewPriceFrom (342-364)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: Artifacts / Benthos Collector Container image
  • GitHub Check: Test
  • GitHub Check: Quickstart
  • GitHub Check: Migration Checks
  • GitHub Check: Lint
  • GitHub Check: E2E
  • GitHub Check: Developer environment
  • GitHub Check: CI
  • GitHub Check: Build
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Commit hooks
🔇 Additional comments (17)
test/subscription/scenario_editcancel_test.go (1)

189-205: Well-structured replacement of subscription.RateCard with productcatalog.UsageBasedRateCard

The code now uses a more structured approach by replacing the direct RateCard fields with a nested RateCardMeta structure. This aligns with the broader refactoring to remove subscription.RateCard dependencies.

openmeter/subscription/patch/additem_test.go (4)

137-146: Good refactoring to productcatalog.FlatFeeRateCard

The change correctly transitions from the old RateCard structure to the new productcatalog.FlatFeeRateCard with nested RateCardMeta. The use of a pointer type is appropriate here since RateCards are likely shared resources.


176-185: Consistent RateCard structure in expected results

The test's expected results have been properly updated to match the new RateCard structure, ensuring consistency between the input and expected output.


205-214: Consistent implementation in another test case

The FlatFeeRateCard structure is consistently implemented across test cases with proper nesting of RateCardMeta.


262-271: Consistent structure in final test case

The expected results are consistently updated with the new structure throughout all test cases.

openmeter/billing/worker/subscription/phaseiterator_test.go (5)

503-508: Good refactoring with new variables for better type handling

The introduction of rc (RateCard) and bc (BillingCadence) variables improves type safety and clarifies the intent of the test code. This change makes the test more maintainable and easier to understand.


515-521: Well-structured UsageBasedRateCard instantiation

The switch case now properly creates a UsageBasedRateCard with appropriate metadata for unit pricing. This ensures that the correct implementation is used based on the price type.


526-537: Proper handling of FlatFeeRateCard and non-priced items

The code correctly distinguishes between flat fee rate cards and items without prices, creating appropriate structures for each case. The conditional use of BillingCadence as a pointer type in FlatFeeRateCard allows for the representation of one-time fees.


541-547: Good default case handling

The default case provides a reasonable fallback with a flat fee rate card, ensuring the test remains robust even with unexpected price types.


549-550: Clean assignment of rate card to both spec and view

The assignment of the created rate card to both the spec and view objects is concise and ensures consistency between these related structures.

openmeter/productcatalog/ratecard.go (3)

35-35: Well-designed ChangeMeta method addition to RateCard interface

The new ChangeMeta method provides a clean way to modify RateCardMeta while ensuring validation. This is a good abstraction that encapsulates the metadata modification logic.


225-229: Good implementation of ChangeMeta for FlatFeeRateCard

The implementation correctly applies the provided function to update the RateCardMeta and validates the result. This ensures that the rate card remains in a valid state after modification.


341-345: Consistent implementation of ChangeMeta for UsageBasedRateCard

The UsageBasedRateCard implementation follows the same pattern as FlatFeeRateCard, ensuring consistent behavior across different rate card types while maintaining proper validation.

openmeter/billing/worker/subscription/sync_test.go (4)

255-256: Using getter method instead of direct field access

The code has been updated to use GetBillingCadence() method instead of direct field access to BillingCadence. This follows good encapsulation practices and aligns with similar changes in other files that have transitioned to method calls for accessing properties of RateCard.


1432-1442: Updated to use productcatalog.FlatFeeRateCard

The code has been refactored to use productcatalog.FlatFeeRateCard instead of subscription.RateCard. This change is part of the overall effort to standardize RateCard handling across different components of the system and aligns with the removal of subscription.RateCard.


1460-1470: Updated to use productcatalog.FlatFeeRateCard

Similar to the previous change, the code has been refactored to use productcatalog.FlatFeeRateCard from the productcatalog package, maintaining consistency in RateCard implementation throughout the codebase.


3201-3228: Added improved RateCard type determination logic

The AsPatch() method has been enhanced with a new switch statement to properly determine the type of rate card based on the price. This implementation now:

  1. Creates a local rc variable of type productcatalog.RateCard
  2. Properly initializes the RateCard metadata
  3. Uses a switch statement to determine the appropriate RateCard type based on price properties

This change improves code clarity and makes the type handling more robust.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@turip turip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

<3

@turip
turip force-pushed the galexi/refactor/remove-subscription-ratecard branch from ec60da3 to 737fe8b Compare April 9, 2025 19:02
@GAlexIHU
GAlexIHU merged commit a06782b into main Apr 10, 2025
@GAlexIHU
GAlexIHU deleted the galexi/refactor/remove-subscription-ratecard branch April 10, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants