Repository navigation
fix: invoice app serialization - #2724
Conversation
📝 WalkthroughWalkthroughThe changes refactor the representation of invoice events in the billing system by introducing a new 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 (3)
🚧 Files skipped from review as they are similar to previous changes (3)
✨ 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:
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 (
|
0f2894f to
70fce20
Compare
70fce20 to
9e46b91
Compare
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
🧹 Nitpick comments (1)
openmeter/billing/events.go (1)
32-34: Validation field name inconsistencyThe validation error message uses "invocing" which should be updated if the field name is corrected to "Invoicing".
- if err := a.Invocing.Validate(); err != nil { - errs = append(errs, fmt.Errorf("invocing: %w", err)) + if err := a.Invoicing.Validate(); err != nil { + errs = append(errs, fmt.Errorf("invoicing: %w", err))
🛑 Comments failed to post (2)
openmeter/billing/events.go (2)
15-19:
⚠️ Potential issueNew structure to store app base information
The
InvoiceAppBasesstruct is a good approach to extract and store only the necessary app information without serializing the entire App object.However, there's a typo in the field name: "Invocing" should be "Invoicing".
- Invocing app.AppBase `json:"invocing"` + Invoicing app.AppBase `json:"invoicing"`📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.type InvoiceAppBases struct { Tax app.AppBase `json:"tax"` Payment app.AppBase `json:"payment"` Invoicing app.AppBase `json:"invoicing"` }
67-80: 💡 Verification agent
🧩 Analysis chain
Improved event creation with app base extraction
The function correctly extracts app base information from the invoice workflow apps and includes it in the event.
However, there's an inconsistency between the field name "Invocing" in the struct and "Invoicing" used when extracting the app base.
- Invocing: invoice.Workflow.Apps.Invoicing.GetAppBase(), + Invoicing: invoice.Workflow.Apps.Invoicing.GetAppBase(),Additionally, the comment on line 68 states "Apps are always present" but there's still a nil check on line 69, which is contradictory.
Please clarify whether apps are always present or if the nil check is necessary.
🏁 Script executed:
#!/bin/bash set -e echo "1. Locate InvoiceAppBases definition" rg -n "type InvoiceAppBases" -A5 . echo echo "2. Locate Workflow struct and inspect its Apps field" rg -n "type Workflow" -A10 . echo echo "3. Confirm Apps field type (pointer vs non-pointer)" rg -n "Apps" -n .Length of output: 74930
Fix InvoiceAppBases typo & clarify nil check
There are two related issues in openmeter/billing/events.go:
- The
InvoiceAppBasesstruct defines the field asInvocing(and JSON tag"invocing"), but you’re populating it frominvoice.Workflow.Apps.Invoicing.- The TODO comment “Apps are always present” contradicts the subsequent
if invoice.Workflow.Apps != nilguard.Please address both:
• Rename the struct field and JSON tag, then update the literal assignment:
--- a/openmeter/billing/events.go @@ type InvoiceAppBases struct { - Invocing app.AppBase `json:"invocing"` + Invoicing app.AppBase `json:"invoicing"` } ... @@ func EventInvoice(invoice billing.Invoice) EventInvoice { - Invocing: invoice.Workflow.Apps.Invoicing.GetAppBase(), + Invoicing: invoice.Workflow.Apps.Invoicing.GetAppBase(),• Decide whether
Workflow.Appsis indeed always non-nil. If so, remove the nil check (and/or update the TODO); otherwise, refine the comment to reflect when nil can occur.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.// openmeter/billing/events.go type InvoiceAppBases struct { Tax app.AppBase `json:"tax"` Payment app.AppBase `json:"payment"` Invoicing app.AppBase `json:"invoicing"` } func EventInvoice(invoice billing.Invoice) EventInvoice { appBases := InvoiceAppBases{} // TODO[later]: Apps are always present, so we should only use the struct without a pointer if invoice.Workflow.Apps != nil { appBases = InvoiceAppBases{ Tax: invoice.Workflow.Apps.Tax.GetAppBase(), Payment: invoice.Workflow.Apps.Payment.GetAppBase(), Invoicing: invoice.Workflow.Apps.Invoicing.GetAppBase(), } } return EventInvoice{ Invoice: payload, AppBases: appBases, } }
9e46b91 to
ff9a3ba
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
openmeter/billing/events.go (4)
15-19: Fix typo in field name: "Invocing" should be "Invoicing"There's a typo in the field name "Invocing" which should be "Invoicing" to maintain consistency with the usage at line 73 where the app base is extracted from
invoice.Workflow.Apps.Invoicing.type InvoiceAppBases struct { Tax app.AppBase `json:"tax"` Payment app.AppBase `json:"payment"` - Invocing app.AppBase `json:"invocing"` + Invoicing app.AppBase `json:"invoicing"` }
32-34: Update field reference to match corrected field nameUpdate the validation error message to match the corrected field name "Invoicing".
- if err := a.Invocing.Validate(); err != nil { - errs = append(errs, fmt.Errorf("invocing: %w", err)) + if err := a.Invoicing.Validate(); err != nil { + errs = append(errs, fmt.Errorf("invoicing: %w", err))
73-73: Field name mismatch between assignment and struct declarationThere's an inconsistency between the field name in the struct (
Invocing) and the source field name (Invoicing). This will work but is confusing. Update this line after fixing the struct field name.- Invocing: invoice.Workflow.Apps.Invoicing.GetAppBase(), + Invoicing: invoice.Workflow.Apps.Invoicing.GetAppBase(),
68-68: Consider addressing TODO comment in future PRThe TODO comment indicates that Apps are always present and shouldn't need to be a pointer. This seems like a good improvement for a future PR to simplify the code structure.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
openmeter/billing/events.go(3 hunks)openmeter/billing/worker/subscription/handlers.go(2 hunks)test/billing/event_test.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- test/billing/event_test.go
- openmeter/billing/worker/subscription/handlers.go
⏰ Context from checks skipped due to timeout of 90000ms (14)
- GitHub Check: Artifacts / Container image
- GitHub Check: Artifacts / Benthos Collector Container image
- GitHub Check: Quickstart
- GitHub Check: E2E
- GitHub Check: CI
- GitHub Check: Analyze (javascript)
- GitHub Check: Analyze (go)
- GitHub Check: Developer environment
- GitHub Check: Analyze (actions)
- GitHub Check: Commit hooks
- GitHub Check: Test
- GitHub Check: Migration Checks
- GitHub Check: Build
- GitHub Check: Lint
🔇 Additional comments (3)
openmeter/billing/events.go (3)
58-81: LGTM! Good refactoring to avoid serialization issuesThe refactoring elegantly solves the serialization issue with App types by:
- Clearing the Apps field to avoid circular references
- Extracting only the necessary metadata via AppBase
- Structuring the event to include both invoice data and app metadata
This approach aligns perfectly with the PR objective of avoiding serialization problems while maintaining necessary contextual information.
95-95: LGTM! Appropriate version bump for structural changesGood job bumping the event version from "v1" to "v2" to reflect the significant structural changes to the event payload. This ensures consumers are aware of the changed format.
101-102: LGTM! Correctly updated field referencesThe metadata method references have been properly updated to access fields through the embedded Invoice struct, maintaining the same functionality while working with the new structure.
ff9a3ba to
3516ced
Compare
Overview
Given we should not serialize the App type as it's:
We should rather extract the metadata as contextual information into the event payload.
Summary by CodeRabbit