Skip to content
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

Allow more variations for a flag #363

Merged
merged 60 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4d48849
Introducing the new InternalFlag and all the associated behaviors
thomaspoignant Jul 28, 2022
309335c
Fix test bug
thomaspoignant Jul 28, 2022
18fb288
Using new struct with legacy syntax
thomaspoignant Jul 29, 2022
84f729f
Remove nil field
thomaspoignant Jul 29, 2022
16e0312
Remove unused test files
thomaspoignant Jul 29, 2022
0679472
Unused util function
thomaspoignant Jul 29, 2022
9118f83
Remove println
thomaspoignant Jul 29, 2022
a229b13
Remove flag_data from variation test
thomaspoignant Jul 29, 2022
ae0b313
Remove usage of flagv1.FlagData
thomaspoignant Jul 29, 2022
cd84bf9
continue to remove flagv1
thomaspoignant Jul 29, 2022
5e158d2
Remove usage of flagv1 package
thomaspoignant Jul 29, 2022
386c299
Order for constitency
thomaspoignant Jul 29, 2022
c0a2c02
Merge remote-tracking branch 'origin/main' into more-variant
thomaspoignant Aug 1, 2022
6a46813
Remove flagv1 package
thomaspoignant Aug 1, 2022
942d2d7
Merge remote-tracking branch 'origin/main' into more-variant
thomaspoignant Aug 1, 2022
1514d89
Disable schedule step in schedule step
thomaspoignant Aug 1, 2022
988870e
Add test to ensure we cannot have scheduled step with scheduled steps
thomaspoignant Aug 1, 2022
12f0c21
converter tests
thomaspoignant Aug 1, 2022
ec35950
Add comments
thomaspoignant Aug 1, 2022
08f46c1
WIP
thomaspoignant Aug 3, 2022
145df10
WIP
thomaspoignant Aug 7, 2022
db81cf2
WIP
thomaspoignant Aug 7, 2022
f62e565
Rework the convert layer
thomaspoignant Aug 7, 2022
0507b01
Merge remote-tracking branch 'origin/main' into more-variant
thomaspoignant Aug 7, 2022
429141e
adding field
thomaspoignant Aug 7, 2022
d394e84
remove method string from the flag contract
thomaspoignant Aug 7, 2022
48d0187
Adding more test for internal flag
thomaspoignant Aug 8, 2022
cb85346
Stop using DTOv0 directly
thomaspoignant Aug 8, 2022
f2e1a4b
Manage to unmarshal multiple fields with same name
thomaspoignant Aug 8, 2022
6b1319b
wrong file
thomaspoignant Aug 8, 2022
66c2fd6
Rename cli
thomaspoignant Aug 8, 2022
4f36f99
add doc
thomaspoignant Aug 8, 2022
e949a88
Remove usage of ioutil
thomaspoignant Aug 8, 2022
724f074
Add godoc
thomaspoignant Aug 9, 2022
5dfc143
Change TOML lib to use BurntSushi/toml
thomaspoignant Aug 9, 2022
f4053ea
Merge branch 'main' into more-variant
thomaspoignant Aug 9, 2022
61968c9
Add test for new flag format
thomaspoignant Aug 9, 2022
1473330
Merge branch 'main' into more-variant
thomaspoignant Aug 9, 2022
d45b63e
Merge branch 'main' into more-variant
thomaspoignant Sep 9, 2022
54e7301
Bump github.com/google/go-cmp from 0.5.8 to 0.5.9 (#335)
dependabot[bot] Sep 9, 2022
f0964c8
Bump github.com/aws/aws-sdk-go from 1.44.93 to 1.44.94 (#336)
dependabot[bot] Sep 9, 2022
42abbde
Add a validation for the flag to avoid to have invalid flag in the cache
thomaspoignant Sep 26, 2022
9e8dbf6
Merge remote-tracking branch 'origin/main' into more-variant
thomaspoignant Sep 26, 2022
c72254c
Move the rollout options to the top level of the flag
thomaspoignant Sep 29, 2022
3db50b5
Merge remote-tracking branch 'origin/main' into more-variant
thomaspoignant Sep 29, 2022
c3f782d
update doc
thomaspoignant Oct 4, 2022
a6e3c70
Move rollout on top level
thomaspoignant Oct 4, 2022
b3272b8
migration cli binary
thomaspoignant Oct 5, 2022
d93e91e
Merge branch 'main' into more-variant
thomaspoignant Oct 5, 2022
0573fd0
Modify flagv1 for compatibility
thomaspoignant Oct 5, 2022
65c24b4
Merge branch 'main' into more-variant
thomaspoignant Oct 10, 2022
8180392
fix doc
thomaspoignant Oct 12, 2022
298511e
Bump go version CI
thomaspoignant Oct 12, 2022
f3d14d7
Fix antlr dependencies
thomaspoignant Oct 12, 2022
4a50755
Add test for convertion cli
thomaspoignant Oct 12, 2022
ec3a805
improve makefile
thomaspoignant Oct 12, 2022
dc229d4
remove unused function
thomaspoignant Oct 12, 2022
e4d8f4f
remove Print
thomaspoignant Oct 12, 2022
82951a2
remove header for v1
thomaspoignant Oct 12, 2022
51f7ad7
Format the files
thomaspoignant Oct 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop using DTOv0 directly
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Aug 8, 2022
commit cb85346988b833878194c67bb221ba6bcd41cc76
76 changes: 38 additions & 38 deletions internal/dto/converter_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
// ConvertV0DtoToInternalFlag is converting a flag in the config file to the internal format.
// this function convert only the old format of the flag (before v1.0.0), to keep
// backward support of the configurations.
func ConvertV0DtoToInternalFlag(d DTOv0, isScheduledStep bool) flag.InternalFlag {
func ConvertV0DtoToInternalFlag(d DTO, isScheduledStep bool) flag.InternalFlag {
// Create variations based on the available definition in the flag v0
var variations *map[string]*interface{}
newVariations := createVariationsV0(d, isScheduledStep)
Expand Down Expand Up @@ -49,7 +49,7 @@ func ConvertV0DtoToInternalFlag(d DTOv0, isScheduledStep bool) flag.InternalFlag
}

var rollout *flag.Rollout
if d.Rollout != nil && (d.Rollout.Experimentation != nil || d.Rollout.Scheduled != nil) {
if d.RolloutV0 != nil && (d.RolloutV0.Experimentation != nil || d.RolloutV0.Scheduled != nil) {
rollout = convertRollout(d, internalFlag)
}

Expand All @@ -58,25 +58,25 @@ func ConvertV0DtoToInternalFlag(d DTOv0, isScheduledStep bool) flag.InternalFlag
}

// createDefaultLegacyRuleV0 create the default rule based on the legacy format.
func createDefaultLegacyRuleV0(d DTOv0, hasTargetRule bool) *flag.Rule {
hasProgressiveRollout := d.Rollout != nil &&
d.Rollout.Progressive != nil &&
d.Rollout.Progressive.ReleaseRamp.Start != nil &&
d.Rollout.Progressive.ReleaseRamp.End != nil
func createDefaultLegacyRuleV0(d DTO, hasTargetRule bool) *flag.Rule {
hasProgressiveRollout := d.RolloutV0 != nil &&
d.RolloutV0.Progressive != nil &&
d.RolloutV0.Progressive.ReleaseRamp.Start != nil &&
d.RolloutV0.Progressive.ReleaseRamp.End != nil

if hasProgressiveRollout && !hasTargetRule {
return &flag.Rule{
Name: &defaultRuleName,
ProgressiveRollout: &flag.ProgressiveRollout{
Initial: &flag.ProgressiveRolloutStep{
Variation: &falseVariation,
Percentage: &d.Rollout.Progressive.Percentage.Initial,
Date: d.Rollout.Progressive.ReleaseRamp.Start,
Percentage: &d.RolloutV0.Progressive.Percentage.Initial,
Date: d.RolloutV0.Progressive.ReleaseRamp.Start,
},
End: &flag.ProgressiveRolloutStep{
Variation: &trueVariation,
Percentage: &d.Rollout.Progressive.Percentage.End,
Date: d.Rollout.Progressive.ReleaseRamp.End,
Percentage: &d.RolloutV0.Progressive.Percentage.End,
Date: d.RolloutV0.Progressive.ReleaseRamp.End,
},
},
}
Expand All @@ -103,23 +103,23 @@ func createDefaultLegacyRuleV0(d DTOv0, hasTargetRule bool) *flag.Rule {
}

// createLegacyRuleV0 will create a rule based on the previous format
func createLegacyRuleV0(d DTOv0) flag.Rule {
func createLegacyRuleV0(d DTO) flag.Rule {
// Handle the specific use case of progressive rollout.
var progressiveRollout *flag.ProgressiveRollout
if d.Rollout != nil &&
d.Rollout.Progressive != nil &&
d.Rollout.Progressive.ReleaseRamp.Start != nil &&
d.Rollout.Progressive.ReleaseRamp.End != nil {
if d.RolloutV0 != nil &&
d.RolloutV0.Progressive != nil &&
d.RolloutV0.Progressive.ReleaseRamp.Start != nil &&
d.RolloutV0.Progressive.ReleaseRamp.End != nil {
progressiveRollout = &flag.ProgressiveRollout{
Initial: &flag.ProgressiveRolloutStep{
Variation: &falseVariation,
Percentage: &d.Rollout.Progressive.Percentage.Initial,
Date: d.Rollout.Progressive.ReleaseRamp.Start,
Percentage: &d.RolloutV0.Progressive.Percentage.Initial,
Date: d.RolloutV0.Progressive.ReleaseRamp.Start,
},
End: &flag.ProgressiveRolloutStep{
Variation: &trueVariation,
Percentage: &d.Rollout.Progressive.Percentage.End,
Date: d.Rollout.Progressive.ReleaseRamp.End,
Percentage: &d.RolloutV0.Progressive.Percentage.End,
Date: d.RolloutV0.Progressive.ReleaseRamp.End,
},
}
}
Expand All @@ -145,7 +145,7 @@ func createLegacyRuleV0(d DTOv0) flag.Rule {
}

// createVariationsV0 will create a set of variations based on the previous format
func createVariationsV0(d DTOv0, isScheduleStep bool) *map[string]*interface{} {
func createVariationsV0(d DTO, isScheduleStep bool) *map[string]*interface{} {
variations := make(map[string]*interface{}, 3)
if d.True != nil {
variations[trueVariation] = d.True
Expand All @@ -171,7 +171,7 @@ func createScheduledStep(f flag.InternalFlag, dto ScheduledStepV0) flag.Schedule
step := flag.ScheduledStep{
Date: dto.Date,
InternalFlag: flag.InternalFlag{
Variations: createVariationsV0(dto.DTOv0, true),
Variations: createVariationsV0(dto.DTO, true),
},
}

Expand Down Expand Up @@ -260,21 +260,21 @@ func createScheduledStep(f flag.InternalFlag, dto ScheduledStepV0) flag.Schedule
return step
}

func convertRollout(dto DTOv0, f flag.InternalFlag) *flag.Rollout {
func convertRollout(dto DTO, f flag.InternalFlag) *flag.Rollout {
r := flag.Rollout{}
if dto.Rollout.Experimentation != nil &&
dto.Rollout.Experimentation.Start != nil &&
dto.Rollout.Experimentation.End != nil {
if dto.RolloutV0.Experimentation != nil &&
dto.RolloutV0.Experimentation.Start != nil &&
dto.RolloutV0.Experimentation.End != nil {
r.Experimentation = &flag.ExperimentationRollout{
Start: dto.Rollout.Experimentation.Start,
End: dto.Rollout.Experimentation.End,
Start: dto.RolloutV0.Experimentation.Start,
End: dto.RolloutV0.Experimentation.End,
}
}

// it is not allowed to have a scheduled step inside a scheduled step
if dto.Rollout.Scheduled != nil && dto.Rollout.Scheduled.Steps != nil {
if dto.RolloutV0.Scheduled != nil && dto.RolloutV0.Scheduled.Steps != nil {
var convertedSteps []flag.ScheduledStep
for _, v := range dto.Rollout.Scheduled.Steps {
for _, v := range dto.RolloutV0.Scheduled.Steps {
convertedSteps = append(convertedSteps, createScheduledStep(f, v))
}
r.Scheduled = &convertedSteps
Expand Down Expand Up @@ -304,23 +304,23 @@ func deepCopyPercentages(in map[string]float64) *map[string]float64 {
// convertProgressiveRollout convert the legacy format to the new format.
// If we can't convert we return a nil value.
func convertScheduledStepProgressiveRollout(dto ScheduledStepV0) *flag.ProgressiveRollout {
hasProgressiveRollout := dto.Rollout != nil &&
dto.Rollout.Progressive != nil &&
dto.Rollout.Progressive.ReleaseRamp.End != nil &&
dto.Rollout.Progressive.ReleaseRamp.Start != nil
hasProgressiveRollout := dto.RolloutV0 != nil &&
dto.RolloutV0.Progressive != nil &&
dto.RolloutV0.Progressive.ReleaseRamp.End != nil &&
dto.RolloutV0.Progressive.ReleaseRamp.Start != nil

var progressive *flag.ProgressiveRollout
if hasProgressiveRollout {
progressive = &flag.ProgressiveRollout{
Initial: &flag.ProgressiveRolloutStep{
Variation: &falseVariation,
Percentage: &dto.Rollout.Progressive.Percentage.Initial,
Date: dto.Rollout.Progressive.ReleaseRamp.Start,
Percentage: &dto.RolloutV0.Progressive.Percentage.Initial,
Date: dto.RolloutV0.Progressive.ReleaseRamp.Start,
},
End: &flag.ProgressiveRolloutStep{
Variation: &trueVariation,
Percentage: &dto.Rollout.Progressive.Percentage.End,
Date: dto.Rollout.Progressive.ReleaseRamp.End,
Percentage: &dto.RolloutV0.Progressive.Percentage.End,
Date: dto.RolloutV0.Progressive.ReleaseRamp.End,
},
}
}
Expand Down
Loading