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

chore: Remove support for v0 format #2496

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions cmd/editor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/thomaspoignant/go-feature-flag/internal/utils"
"github.com/thomaspoignant/go-feature-flag/model"
"github.com/thomaspoignant/go-feature-flag/model/dto"
"github.com/thomaspoignant/go-feature-flag/utils/fflog"
)

// This service is an API used to evaluate a flag with an evaluation context
Expand Down Expand Up @@ -55,8 +54,7 @@ func EvaluateHandler(c echo.Context) error {
if err := c.Bind(u); err != nil {
return err
}
logger := fflog.FFLogger{}
f := u.Flag.Convert(&logger, u.FlagName)
f := u.Flag.Convert()
value, resolutionDetails := f.Value(
u.FlagName,
utils.ConvertEvaluationCtxFromRequest(u.Context.Key, u.Context.Custom),
Expand Down
7 changes: 1 addition & 6 deletions cmd/lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package main
import (
"encoding/json"
"fmt"
"log/slog"
"os"
"strings"

"github.com/BurntSushi/toml"
"github.com/thomaspoignant/go-feature-flag/model/dto"
"github.com/thomaspoignant/go-feature-flag/utils/fflog"
"k8s.io/apimachinery/pkg/util/yaml"
)

Expand Down Expand Up @@ -41,10 +39,7 @@ func (l *Linter) Lint() []error {

errs := make([]error, 0)
for key, flagDto := range flags {
logger := fflog.FFLogger{
LeveledLogger: slog.Default(),
}
flag := flagDto.Convert(&logger, key)
flag := flagDto.Convert()
if err := flag.IsValid(); err != nil {
errs = append(errs, fmt.Errorf("%s: invalid flag %s: %w", l.InputFile, key, err))
}
Expand Down
14 changes: 0 additions & 14 deletions feature_flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,6 @@ func TestValidUseCase(t *testing.T) {
assert.True(t, ffclient.ForceRefresh())
}

func TestAllFlagsFromCache(t *testing.T) {
err := ffclient.Init(ffclient.Config{
Retriever: &fileretriever.Retriever{Path: "testdata/flag-config.yaml"},
PollingInterval: 5 * time.Second,
})
defer ffclient.Close()

assert.NoError(t, err)
flags, err := ffclient.GetFlagsFromCache()

assert.NoError(t, err)
assert.Len(t, flags, 2)
}

func TestValidUseCaseToml(t *testing.T) {
// Valid use case
gffClient, err := ffclient.New(ffclient.Config{
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/in_memory_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (fc *InMemoryCache) All() map[string]flag.Flag {
func (fc *InMemoryCache) Init(flags map[string]dto.DTO) {
cache := make(map[string]flag.InternalFlag)
for key, flagDto := range flags {
flagToAdd := flagDto.Convert(fc.Logger, key)
flagToAdd := flagDto.Convert()
if err := flagToAdd.IsValid(); err == nil {
cache[key] = flagToAdd
} else {
Expand Down
86 changes: 39 additions & 47 deletions internal/cache/in_memory_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ func TestAll(t *testing.T) {
name: "all with 1 flag",
param: map[string]dto.DTO{
"test": {
DTOv1: dto.DTOv1{
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
},
},
Expand All @@ -55,34 +53,30 @@ func TestAll(t *testing.T) {
name: "all with multiple flags",
param: map[string]dto.DTO{
"test": {
DTOv1: dto.DTOv1{
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
},
},
"test1": {
DTOv1: dto.DTOv1{
Variations: &map[string]*interface{}{
"True": testconvert.Interface(true),
"False": testconvert.Interface(false),
"Default": testconvert.Interface(false),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 30,
"False": 70,
},
Variations: &map[string]*interface{}{
"True": testconvert.Interface(true),
"False": testconvert.Interface(false),
"Default": testconvert.Interface(false),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 30,
"False": 70,
},
},
},
Expand Down Expand Up @@ -142,18 +136,16 @@ func TestCopy(t *testing.T) {
name: "copy with 1 flag",
param: map[string]dto.DTO{
"test": {
DTOv1: dto.DTOv1{
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
Variations: &map[string]*interface{}{
"True": testconvert.Interface("true"),
"False": testconvert.Interface("false"),
"Default": testconvert.Interface("default"),
},
DefaultRule: &flag.Rule{
Name: testconvert.String("defaultRule"),
Percentages: &map[string]float64{
"True": 40,
"False": 60,
},
},
},
Expand Down
8 changes: 5 additions & 3 deletions model/dto/convert_v1.go → model/dto/converter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dto

import "github.com/thomaspoignant/go-feature-flag/internal/flag"
import (
"github.com/thomaspoignant/go-feature-flag/internal/flag"
)

// ConvertV1DtoToInternalFlag is converting a DTO to a flag.InternalFlag
func ConvertV1DtoToInternalFlag(dto DTO) flag.InternalFlag {
// ConvertDtoToInternalFlag is converting a DTO to a flag.InternalFlag
func ConvertDtoToInternalFlag(dto DTO) flag.InternalFlag {
var experimentation *flag.ExperimentationRollout
if dto.Experimentation != nil {
experimentation = &flag.ExperimentationRollout{
Expand Down
86 changes: 42 additions & 44 deletions model/dto/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,55 @@ func TestConvertV1DtoToInternalFlag(t *testing.T) {
{
name: "all fields set",
input: dto.DTO{
DTOv1: dto.DTOv1{
BucketingKey: testconvert.String("bucketKey"),
Variations: &map[string]*interface{}{
"var1": testconvert.Interface("var1"),
"var2": testconvert.Interface("var2"),
},
Rules: &[]flag.Rule{{
Name: testconvert.String("rule1"),
Query: testconvert.String("key eq \"key\""),
Percentages: &map[string]float64{"var_true": 100, "var_false": 0}},
{
Name: testconvert.String("rule2"),
Query: testconvert.String("key eq \"key2\""),
ProgressiveRollout: &flag.ProgressiveRollout{
Initial: &flag.ProgressiveRolloutStep{
Variation: testconvert.String("var1"),
Percentage: testconvert.Float64(30),
Date: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
},
End: &flag.ProgressiveRolloutStep{
Variation: testconvert.String("var2"),
Percentage: testconvert.Float64(70),
Date: testconvert.Time(time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)),
},
BucketingKey: testconvert.String("bucketKey"),
Variations: &map[string]*interface{}{
"var1": testconvert.Interface("var1"),
"var2": testconvert.Interface("var2"),
},
Rules: &[]flag.Rule{{
Name: testconvert.String("rule1"),
Query: testconvert.String("key eq \"key\""),
Percentages: &map[string]float64{"var_true": 100, "var_false": 0}},
{
Name: testconvert.String("rule2"),
Query: testconvert.String("key eq \"key2\""),
ProgressiveRollout: &flag.ProgressiveRollout{
Initial: &flag.ProgressiveRolloutStep{
Variation: testconvert.String("var1"),
Percentage: testconvert.Float64(30),
Date: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
},
End: &flag.ProgressiveRolloutStep{
Variation: testconvert.String("var2"),
Percentage: testconvert.Float64(70),
Date: testconvert.Time(time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC)),
},
},
{
Name: testconvert.String("rule3"),
Query: testconvert.String("key eq \"key3\""),
VariationResult: testconvert.String("var2"),
},
},
DefaultRule: &flag.Rule{
VariationResult: testconvert.String("var1"),
{
Name: testconvert.String("rule3"),
Query: testconvert.String("key eq \"key3\""),
VariationResult: testconvert.String("var2"),
},
Scheduled: &[]flag.ScheduledStep{
{
Date: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
InternalFlag: flag.InternalFlag{
DefaultRule: &flag.Rule{
VariationResult: testconvert.String("var2"),
},
},
DefaultRule: &flag.Rule{
VariationResult: testconvert.String("var1"),
},
Scheduled: &[]flag.ScheduledStep{
{
Date: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
InternalFlag: flag.InternalFlag{
DefaultRule: &flag.Rule{
VariationResult: testconvert.String("var2"),
},
},
},
Experimentation: &dto.ExperimentationDto{
Start: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
End: testconvert.Time(time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC)),
},
Metadata: &map[string]interface{}{"key": "value"},
},
Experimentation: &dto.ExperimentationDto{
Start: testconvert.Time(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)),
End: testconvert.Time(time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC)),
},
Metadata: &map[string]interface{}{"key": "value"},
TrackEvents: testconvert.Bool(true),
Disable: testconvert.Bool(false),
Version: testconvert.String("v1"),
Expand Down Expand Up @@ -137,7 +135,7 @@ func TestConvertV1DtoToInternalFlag(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.input.Convert(nil, "random-flag-name")
result := tt.input.Convert()
assert.Equal(t, tt.expected, result)
})
}
Expand Down
Loading
Loading