-
Notifications
You must be signed in to change notification settings - Fork 261
fix: allow rollout and percentage zero values in YAML serialization #4678
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
Remove omitempty tag from Distribution.Rollout and ThresholdRule.Percentage fields to fix CUE validation errors when these fields have zero values. - Fixed Distribution.Rollout field to always serialize, even when 0 - Fixed ThresholdRule.Percentage field to always serialize, even when 0 - Added comprehensive tests for YAML and JSON serialization with zero values - Added CUE validation test case with zero values Fixes #4677 Signed-off-by: Claude <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v2 #4678 +/- ##
=======================================
Coverage 62.52% 62.52%
=======================================
Files 131 131
Lines 15510 15510
=======================================
Hits 9698 9698
Misses 5139 5139
Partials 673 673
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR fixes validation errors when using zero values (0 or 0.0) for rollout percentages in variant flag distributions and threshold rollouts in boolean flags by removing the omitempty
YAML/JSON tags that were causing these fields to be omitted during serialization.
- Removes
omitempty
tags fromDistribution.Rollout
andThresholdRule.Percentage
fields in struct definitions - Adds comprehensive test coverage for YAML and JSON serialization with zero values
- Adds validation test data and test case to ensure CUE validation works with zero values
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
internal/ext/common.go | Removes omitempty tags from Rollout and Percentage fields to ensure zero values are serialized |
internal/ext/common_test.go | Adds comprehensive tests for YAML and JSON serialization with zero rollout and percentage values |
core/validation/validate_test.go | Adds test case to verify validation passes with zero values |
core/validation/testdata/valid_zero_values.yaml | Test data containing rollout: 0 and percentage: 0 configurations |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Summary
Fixes validation errors when using rollout value of 0 in variant flag distributions and percentage value of 0 in boolean flag threshold rollouts.
Problem
When updating a variant flag with a distribution rollout value of 0, the operation fails with a CUE validation error:
incomplete value >=0 & <=100
. This occurs because theomitempty
tag on theRollout
field inDistribution
andPercentage
field inThresholdRule
causes zero values to be omitted during YAML serialization, leading to validation failure.Changes
internal/ext/common.go
: Removedomitempty
tags from:Distribution.Rollout
fieldThresholdRule.Percentage
fieldinternal/ext/common_test.go
: Comprehensive tests for YAML and JSON serialization with zero valuescore/validation/testdata/valid_zero_values.yaml
: Test data with rollout: 0 and percentage: 0core/validation/validate_test.go
: Added test case for zero values validationTesting
Backward Compatibility
This change is backward compatible since:
Fixes #4677