-
Notifications
You must be signed in to change notification settings - Fork 143
fix: entitlement config compare #3741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe change replaces a direct string equality check with a JSON diff-based comparison when validating entitlement configuration against its template, adding error handling for the diff operation. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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/subscription/subscriptionview.go (1)
162-169: Nice improvement! JSON diff handles semantic equivalence better than string comparison.Using jsondiff properly handles cases where JSON is semantically equivalent but formatted differently (whitespace, key ordering, etc.). This is definitely an upgrade from direct string comparison.
A couple of small suggestions:
Consider validating that
ent.Configis not nil before the comparison. Currently,lo.FromPtr(ent.Config)returns an empty string if Config is nil, which might mask a legitimate configuration issue. If nil Config should fail validation, an explicit check would be clearer.Include the diff in the error message for easier debugging. Something like:
return fmt.Errorf("entitlement %s config does not match template config: %v", s.Entitlement.Entitlement.ID, diff)🔎 Potential improvements
+ if ent.Config == nil { + return fmt.Errorf("entitlement %s config is nil but template expects config", s.Entitlement.Entitlement.ID) + } + diff, err := jsondiff.CompareJSON([]byte(configJSON), []byte(lo.FromPtr(ent.Config))) if err != nil { return fmt.Errorf("failed to compare entitlement with template config for Item %s: %w", s.SubscriptionItem.Key, err) } if len(diff) > 0 { - return fmt.Errorf("entitlement %s config does not match template config", s.Entitlement.Entitlement.ID) + return fmt.Errorf("entitlement %s config does not match template config: %v", s.Entitlement.Entitlement.ID, diff) }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
go.modis excluded by!**/*.modgo.sumis excluded by!**/*.sum,!**/*.sum
📒 Files selected for processing (1)
openmeter/subscription/subscriptionview.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
⚙️ CodeRabbit configuration file
**/*.go: In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.Performance should be a priority in critical code paths. Anything related to event ingestion, message processing, database operations (regardless of database) should be vetted for potential performance bottlenecks.
Files:
openmeter/subscription/subscriptionview.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). (7)
- GitHub Check: E2E
- GitHub Check: Quickstart
- GitHub Check: Build
- GitHub Check: Lint
- GitHub Check: Code Generators
- GitHub Check: Test
- GitHub Check: Analyze (go)
tothandras
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a more lightweight alternative to jsondiff?
Overview
Use
jsondifflibrary to compare JSON strings in order to detect any drifts.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.