Skip to content

Commit

Permalink
Introducing the new InternalFlag and all the associated behaviors
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Jul 28, 2022
1 parent 95d0c42 commit 4d48849
Show file tree
Hide file tree
Showing 44 changed files with 2,588 additions and 275 deletions.
2 changes: 1 addition & 1 deletion exporter/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestFormatEventInJSON(t *testing.T) {
Kind: "feature", ContextKind: "anonymousUser", UserKey: "ABCD", CreationDate: 1617970547, Key: "random-key",
Variation: "Default", Value: "YO", Default: false,
}},
want: "{\"kind\":\"feature\",\"contextKind\":\"anonymousUser\",\"userKey\":\"ABCD\",\"creationDate\":1617970547,\"key\":\"random-key\",\"variation\":\"Default\",\"value\":\"YO\",\"default\":false,\"version\":0}\n",
want: "{\"kind\":\"feature\",\"contextKind\":\"anonymousUser\",\"userKey\":\"ABCD\",\"creationDate\":1617970547,\"key\":\"random-key\",\"variation\":\"Default\",\"value\":\"YO\",\"default\":false,\"version\":\"\"}\n",
wantErr: assert.NoError,
},
}
Expand Down
4 changes: 2 additions & 2 deletions exporter/feature_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func NewFeatureEvent(
value interface{},
variation string,
failed bool,
version float64,
version string,
) FeatureEvent {
contextKind := "user"
if user.IsAnonymous() {
Expand Down Expand Up @@ -65,5 +65,5 @@ type FeatureEvent struct {

// Version contains the version of the flag. If the field is omitted for the flag in the configuration file
// the default version will be 0.
Version float64 `json:"version"`
Version string `json:"version"`
}
4 changes: 2 additions & 2 deletions exporter/feature_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestNewFeatureEvent(t *testing.T) {
value interface{}
variation string
failed bool
version float64
version string
}
tests := []struct {
name string
Expand All @@ -31,7 +31,7 @@ func TestNewFeatureEvent(t *testing.T) {
value: "YO",
variation: "Default",
failed: false,
version: 0,
version: "",
},
want: exporter.FeatureEvent{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "ABCD", CreationDate: time.Now().Unix(), Key: "random-key",
Expand Down
4 changes: 2 additions & 2 deletions exporter/fileexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestFile_Export(t *testing.T) {
},
{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "EFGH", CreationDate: 1617970701, Key: "random-key",
Variation: "Default", Value: "YO2", Default: false, Version: 127,
Variation: "Default", Value: "YO2", Default: false, Version: "127",
},
},
},
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestFile_Export(t *testing.T) {
},
{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "EFGH", CreationDate: 1617970701, Key: "random-key",
Variation: "Default", Value: "YO2", Default: false, Version: 127,
Variation: "Default", Value: "YO2", Default: false, Version: "127",
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions exporter/fileexporter/testdata/all_default.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":0}
{"kind":"feature","contextKind":"anonymousUser","userKey":"EFGH","creationDate":1617970701,"key":"random-key","variation":"Default","value":"YO2","default":false,"version":127}
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":""}
{"kind":"feature","contextKind":"anonymousUser","userKey":"EFGH","creationDate":1617970701,"key":"random-key","variation":"Default","value":"YO2","default":false,"version":"127"}
4 changes: 2 additions & 2 deletions exporter/fileexporter/testdata/custom_file_name.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":0}
{"kind":"feature","contextKind":"anonymousUser","userKey":"EFGH","creationDate":1617970701,"key":"random-key","variation":"Default","value":"YO2","default":false,"version":0}
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":""}
{"kind":"feature","contextKind":"anonymousUser","userKey":"EFGH","creationDate":1617970701,"key":"random-key","variation":"Default","value":"YO2","default":false,"version":""}
2 changes: 1 addition & 1 deletion exporter/s3exporter/testdata/all_default.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":0}
{"kind":"feature","contextKind":"anonymousUser","userKey":"ABCD","creationDate":1617970547,"key":"random-key","variation":"Default","value":"YO","default":false,"version":""}
6 changes: 3 additions & 3 deletions exporter/webhookexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestWebhook_Export(t *testing.T) {
},
{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "EFGH", CreationDate: 1617970701, Key: "random-key",
Variation: "Default", Value: "YO2", Default: false, Version: 127,
Variation: "Default", Value: "YO2", Default: false, Version: "127",
},
},
},
Expand All @@ -93,13 +93,13 @@ func TestWebhook_Export(t *testing.T) {
},
{
Kind: "feature", ContextKind: "anonymousUser", UserKey: "EFGH", CreationDate: 1617970701, Key: "random-key",
Variation: "Default", Value: "YO2", Default: false, Version: 127,
Variation: "Default", Value: "YO2", Default: false, Version: "127",
},
},
},
expected: expected{
bodyFilePath: "./testdata/valid_with_signature.json",
signHeader: "sha256=1ac12dcfbc2f5734a949b301c251a542384735c5552d8570e25bf5a4e7c21a32",
signHeader: "sha256=0c504fe37d423ff0a80e4dc29b93c18c2d1438a5387f36d8e6491e77fb5e70d4",
},
wantErr: false,
},
Expand Down
4 changes: 2 additions & 2 deletions exporter/webhookexporter/testdata/valid_with_signature.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"variation": "Default",
"value": "YO",
"default": false,
"version": 0
"version": ""
},
{
"kind": "feature",
Expand All @@ -23,7 +23,7 @@
"variation": "Default",
"value": "YO2",
"default": false,
"version": 127
"version": "127"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"variation": "Default",
"value": "YO",
"default": false,
"version": 0
"version": ""
},
{
"kind": "feature",
Expand All @@ -23,7 +23,7 @@
"variation": "Default",
"value": "YO2",
"default": false,
"version": 127
"version": "127"
}
]
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ go 1.17
require (
cloud.google.com/go/storage v1.23.0
github.com/aws/aws-sdk-go v1.44.46
github.com/gdexlab/go-render v1.0.1
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.8
github.com/nikunjy/rules v1.1.0
github.com/pelletier/go-toml v1.9.5
github.com/r3labs/diff/v3 v3.0.0
github.com/stretchr/testify v1.8.0
golang.org/x/oauth2 v0.0.0-20220622183110-fd043fe589d2
google.golang.org/api v0.86.0
Expand Down Expand Up @@ -51,6 +53,7 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/gdexlab/go-render v1.0.1 h1:rxqB3vo5s4n1kF0ySmoNeSPRYkEsyHgln4jFIQY7v0U=
github.com/gdexlab/go-render v1.0.1/go.mod h1:wRi5nW2qfjiGj4mPukH4UV0IknS1cHD4VgFTmJX5JzM=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
Expand Down Expand Up @@ -310,6 +312,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/r3labs/diff/v3 v3.0.0 h1:ZhPwNxn9gW5WLPBV9GCYaVbMdLOSmJ0DeKdCiSbOLUI=
github.com/r3labs/diff/v3 v3.0.0/go.mod h1:wCkTySAiDnZao1sZrVTDIzuzgLZ+cNPGn3LC8DlIg5g=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand All @@ -327,6 +331,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
10 changes: 5 additions & 5 deletions internal/dataexporter/data_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestDataExporterScheduler_flushWithTime(t *testing.T) {

inputEvents := []exporter.FeatureEvent{
exporter.NewFeatureEvent(ffuser.NewAnonymousUser("ABCD"), "random-key",
"YO", flagv1.VariationDefault, false, 0),
"YO", flagv1.VariationDefault, false, ""),
}

for _, event := range inputEvents {
Expand All @@ -50,7 +50,7 @@ func TestDataExporterScheduler_flushWithNumberOfEvents(t *testing.T) {
var inputEvents []exporter.FeatureEvent
for i := 0; i <= 100; i++ {
inputEvents = append(inputEvents, exporter.NewFeatureEvent(ffuser.NewAnonymousUser("ABCD"),
"random-key", "YO", flagv1.VariationDefault, false, 0))
"random-key", "YO", flagv1.VariationDefault, false, ""))
}
for _, event := range inputEvents {
dc.AddEvent(event)
Expand All @@ -68,7 +68,7 @@ func TestDataExporterScheduler_defaultFlush(t *testing.T) {
var inputEvents []exporter.FeatureEvent
for i := 0; i <= 100000; i++ {
inputEvents = append(inputEvents, exporter.NewFeatureEvent(ffuser.NewAnonymousUser("ABCD"),
"random-key", "YO", flagv1.VariationDefault, false, 0))
"random-key", "YO", flagv1.VariationDefault, false, ""))
}
for _, event := range inputEvents {
dc.AddEvent(event)
Expand All @@ -92,7 +92,7 @@ func TestDataExporterScheduler_exporterReturnError(t *testing.T) {
var inputEvents []exporter.FeatureEvent
for i := 0; i <= 200; i++ {
inputEvents = append(inputEvents, exporter.NewFeatureEvent(ffuser.NewAnonymousUser("ABCD"),
"random-key", "YO", flagv1.VariationDefault, false, 0))
"random-key", "YO", flagv1.VariationDefault, false, ""))
}
for _, event := range inputEvents {
dc.AddEvent(event)
Expand All @@ -113,7 +113,7 @@ func TestDataExporterScheduler_nonBulkExporter(t *testing.T) {
var inputEvents []exporter.FeatureEvent
for i := 0; i < 100; i++ {
inputEvents = append(inputEvents, exporter.NewFeatureEvent(ffuser.NewAnonymousUser("ABCD"),
"random-key", "YO", flagv1.VariationDefault, false, 0))
"random-key", "YO", flagv1.VariationDefault, false, ""))
}
for _, event := range inputEvents {
dc.AddEvent(event)
Expand Down
4 changes: 3 additions & 1 deletion internal/fflog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"time"
)

const LogDateFormat = time.RFC3339

func Printf(logger *log.Logger, format string, v ...interface{}) {
if logger != nil {
date := time.Now().Format(time.RFC3339)
date := time.Now().Format(LogDateFormat)
v = append([]interface{}{date}, v...)
logger.Printf("[%v] "+format, v...)
}
Expand Down
6 changes: 6 additions & 0 deletions internal/flag/error_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ package flag
type ErrorCode = string

const (
// Proposed in the open-feature specs
ErrorCodeProviderNotReady ErrorCode = "PROVIDER_NOT_READY"
ErrorCodeFlagNotFound ErrorCode = "FLAG_NOT_FOUND"
ErrorCodeParseError ErrorCode = "PARSE_ERROR"
ErrorCodeTypeMismatch ErrorCode = "TYPE_MISMATCH"
ErrorCodeGeneral ErrorCode = "GENERAL"

// Custom error code for Go Feature Flag

// ErrorFlagConfiguration is returned when we were not able to use the flag because of a misconfiguration
ErrorFlagConfiguration ErrorCode = "FLAG_CONFIG"
)
20 changes: 6 additions & 14 deletions internal/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,16 @@ type Flag interface {

// GetVersion is the getter for the field Version
// Default: 0.0
GetVersion() float64
GetVersion() string

// GetTrackEvents is the getter of the field TrackEvents
// IsTrackEvents is the getter of the field TrackEvents
// Default: true
GetTrackEvents() bool
IsTrackEvents() bool

// GetDisable is the getter for the field Disable
// IsDisable is the getter for the field Disable
// Default: false
GetDisable() bool

// GetDefaultVariation return the name of the default variation (if something goes wrong)
GetDefaultVariation() string
IsDisable() bool

// GetVariationValue return the value of variation from his name
GetVariationValue(variationName string) interface{}

// GetRawValues is returning a raw value of the Flag used by the notifiers
// We should not have any logic based on these values, this is only to
// display the information.
GetRawValues() map[string]string
GetVariationValue(name string) interface{}
}
Loading

0 comments on commit 4d48849

Please sign in to comment.