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

feat: default variants #3271

Merged
merged 32 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9e88dc5
feat: default variant redo
markphelps Jul 12, 2024
b721012
Merge branch 'main' into default-variant-redo
markphelps Jul 19, 2024
437d7b0
feat: add default variant in ui
markphelps Jul 19, 2024
8859bfd
chore: import/export
markphelps Jul 19, 2024
bfe4c0b
chore: ui lint issues
markphelps Jul 19, 2024
ac934d7
chore: add migrations for other dbs
markphelps Jul 19, 2024
30f5113
chore: fix schemas; fix cli export test
markphelps Jul 19, 2024
0e8d466
chore: import export IT
markphelps Jul 19, 2024
632aad1
chore: set IT log levels to warn to minimize log output
markphelps Jul 19, 2024
7f4dc0e
chore: rm dag import
markphelps Jul 19, 2024
780f82f
chore: fix import/export IT
markphelps Jul 19, 2024
d2a8094
chore: fix ui test
markphelps Jul 19, 2024
65bf39e
chore: update testdata
markphelps Jul 19, 2024
df494d1
chore: support evaluation data api
markphelps Jul 19, 2024
1184869
chore: make default variant optional
markphelps Jul 19, 2024
2a0e3f4
chore: rename default variant field in ui
markphelps Jul 19, 2024
7cabab9
refactor: clean up UI (#3288)
erka Jul 21, 2024
29bdf62
chore: move variant form helper
markphelps Jul 21, 2024
f2eb7fb
chore: rename context key
markphelps Jul 21, 2024
b0d32ad
chore: add legacy evaluator tests
markphelps Jul 21, 2024
f6b100a
chore: rm unused IVariant import
markphelps Jul 21, 2024
ea5b441
chore: db tests
markphelps Jul 21, 2024
b5adf54
chore: add IT
markphelps Jul 21, 2024
53f9fcf
chore: check for default variant in same namespace
markphelps Jul 21, 2024
b6faa0e
chore: add snapshot support
markphelps Jul 22, 2024
3eeca9c
Merge branch 'main' into default-variant-redo
markphelps Jul 22, 2024
bcb5045
chore: try to fix ui ITs
markphelps Jul 22, 2024
c4ab1cf
Merge branch 'default-variant-redo' of https://github.com/flipt-io/fl…
markphelps Jul 22, 2024
6e19727
chore: with workdir
markphelps Jul 22, 2024
147555d
chore: go mod tidy
markphelps Jul 22, 2024
6e9eed5
Merge branch 'main' into default-variant-redo
markphelps Jul 22, 2024
5c193ff
chore: bump playwright/test
markphelps Jul 22, 2024
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
2 changes: 1 addition & 1 deletion build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (f *Flipt) Base(ctx context.Context, source *dagger.Directory) (*Container,
return f.BaseContainer, err
}

// Return container with Flipt binariesin a thinner alpine distribution
// Return container with Flipt binaries in a thinner alpine distribution
func (f *Flipt) Build(ctx context.Context, source *dagger.Directory) (*Container, error) {
base, err := f.Base(ctx, source)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion build/testing/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ segments:
value: buzz
`

expectedYAMLStreamOutput = `version: "1.2"
expectedYAMLStreamOutput = `version: "1.3"
namespace: default
---
namespace: foo
Expand Down
22 changes: 11 additions & 11 deletions build/testing/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func Integration(ctx context.Context, client *dagger.Client, base, flipt *dagger
name := strings.ToLower(replacer.Replace(fmt.Sprintf("flipt-test-%s-config-%s", caseName, config.name)))
flipt = flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_LOG_LEVEL", "debug").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithExposedPort(config.port)

if exportLogs {
Expand Down Expand Up @@ -344,7 +344,7 @@ func withCockroach(fn testCaseFn) testCaseFn {

func cache(ctx context.Context, _ *dagger.Client, base, flipt *dagger.Container, conf testConfig) func() error {
flipt = flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_CACHE_ENABLED", "true").
WithEnvVariable("FLIPT_CACHE_TTL", "1s")

Expand All @@ -369,7 +369,7 @@ func cacheWithTLS(ctx context.Context, client *dagger.Client, base, flipt *dagge
AsService()

flipt = flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_CACHE_ENABLED", "true").
WithEnvVariable("FLIPT_CACHE_TTL", "1s").
WithEnvVariable("FLIPT_CACHE_BACKEND", "redis").
Expand All @@ -389,7 +389,7 @@ const (
func local(ctx context.Context, client *dagger.Client, base, flipt *dagger.Container, conf testConfig) func() error {
flipt = flipt.
WithDirectory("/tmp/testdata", base.Directory(singleRevisionTestdataDir)).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "local").
WithEnvVariable("FLIPT_STORAGE_LOCAL_PATH", "/tmp/testdata").
WithEnvVariable("UNIQUE", uuid.New().String())
Expand Down Expand Up @@ -454,7 +454,7 @@ func git(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("gitea", gitea.AsService()).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "git").
WithEnvVariable("FLIPT_STORAGE_GIT_REPOSITORY", "http://gitea:3000/root/features.git").
WithEnvVariable("FLIPT_STORAGE_GIT_AUTHENTICATION_BASIC_USERNAME", "root").
Expand Down Expand Up @@ -490,7 +490,7 @@ func s3(ctx context.Context, client *dagger.Client, base, flipt *dagger.Containe

flipt = flipt.
WithServiceBinding("minio", minio).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("AWS_ACCESS_KEY_ID", "user").
WithEnvVariable("AWS_SECRET_ACCESS_KEY", "password").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
Expand Down Expand Up @@ -554,7 +554,7 @@ func oci(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("zot", zot.AsService()).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "oci").
WithEnvVariable("FLIPT_STORAGE_OCI_REPOSITORY", "http://zot:5000/readonly:latest").
WithEnvVariable("FLIPT_STORAGE_OCI_AUTHENTICATION_USERNAME", "username").
Expand Down Expand Up @@ -619,7 +619,7 @@ func importExport(ctx context.Context, _ *dagger.Client, base, flipt *dagger.Con

if ns == "default" {
// replace namespace in expected yaml
expected = strings.ReplaceAll(expected, "version: \"1.2\"\n", fmt.Sprintf("version: \"1.2\"\nnamespace: %s\n", ns))
expected = strings.ReplaceAll(expected, "version: \"1.3\"\n", fmt.Sprintf("version: \"1.3\"\nnamespace: %s\n", ns))
}

if ns != "default" {
Expand Down Expand Up @@ -870,7 +870,7 @@ func azblob(ctx context.Context, client *dagger.Client, base, flipt *dagger.Cont

flipt = flipt.
WithServiceBinding("azurite", azurite).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
WithEnvVariable("FLIPT_STORAGE_OBJECT_TYPE", "azblob").
WithEnvVariable("FLIPT_STORAGE_OBJECT_AZBLOB_ENDPOINT", "http://azurite:10000/devstoreaccount1").
Expand Down Expand Up @@ -902,7 +902,7 @@ func gcs(ctx context.Context, client *dagger.Client, base, flipt *dagger.Contain

flipt = flipt.
WithServiceBinding("gcs", gcs).
WithEnvVariable("FLIPT_LOG_LEVEL", "DEBUG").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_STORAGE_TYPE", "object").
WithEnvVariable("FLIPT_STORAGE_OBJECT_TYPE", "googlecloud").
WithEnvVariable("FLIPT_STORAGE_OBJECT_GOOGLECLOUD_BUCKET", "testdata").
Expand Down Expand Up @@ -1014,7 +1014,7 @@ func serveOIDC(_ context.Context, _ *dagger.Client, base, flipt *dagger.Containe
})

return flipt.
WithEnvVariable("FLIPT_LOG_LEVEL", "debug").
WithEnvVariable("FLIPT_LOG_LEVEL", "WARN").
WithEnvVariable("FLIPT_AUTHENTICATION_METHODS_KUBERNETES_DISCOVERY_URL", "https://discover.svc").
WithServiceBinding("discover.svc", base.
WithNewFile("/server.crt", dagger.ContainerWithNewFileOpts{
Expand Down
25 changes: 24 additions & 1 deletion build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {

assert.Equal(t, "Test 2", updated.Name)

t.Log("List all Flags error with invalid page token")
t.Log("List all flags error with invalid page token")

_, err = client.Flipt().ListFlags(ctx, &flipt.ListFlagRequest{
NamespaceKey: namespace.Key,
Expand Down Expand Up @@ -259,6 +259,29 @@ func API(t *testing.T, ctx context.Context, opts integration.TestOpts) {

assert.Equal(t, "one", updatedVariant.Key)
assert.Equal(t, "One", updatedVariant.Name)

t.Log("Set default variant for flag \"test\".")

_, err = client.Flipt().UpdateFlag(ctx, &flipt.UpdateFlagRequest{
NamespaceKey: namespace.Key,
Key: enabled.Key,
Name: "Test 2",
Description: enabled.Description,
Enabled: true,
DefaultVariantId: updatedVariant.Id,
})

require.NoError(t, err)

flag, err = client.Flipt().GetFlag(ctx, &flipt.GetFlagRequest{
NamespaceKey: namespace.Key,
Key: enabled.Key,
})

require.NoError(t, err)
assert.Equal(t, updatedVariant.Id, flag.DefaultVariant.Id)
assert.Equal(t, updatedVariant.Key, flag.DefaultVariant.Key)
assert.Equal(t, updatedVariant.Name, flag.DefaultVariant.Name)
})

t.Run("Segments and Constraints", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.2"
version: "1.3"
flags:
- key: flag_001
name: FLAG_001
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.2"
version: "1.3"
namespace: production
flags:
- key: flag_001
Expand Down
1 change: 1 addition & 0 deletions config/migrations/cockroachdb/11_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE flags ADD COLUMN default_variant_id VARCHAR(255) REFERENCES variants(id) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/mysql/13_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `flags` ADD COLUMN `default_variant_id` VARCHAR(255) REFERENCES variants(`id`) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/postgres/14_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE flags ADD COLUMN default_variant_id VARCHAR(255) REFERENCES variants(id) ON DELETE SET NULL;
1 change: 1 addition & 0 deletions config/migrations/sqlite3/13_default_variant.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `flags` ADD COLUMN `default_variant_id` VARCHAR(255) REFERENCES variants(`id`) ON DELETE SET NULL;
11 changes: 7 additions & 4 deletions core/validation/flipt.cue
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
version: "1.0" | "1.1" | "1.2" | *"1.3"

close({
version: "1.0" | "1.1" | *"1.2"
namespace: string & =~"^[-_,A-Za-z0-9]+$" | *"default"
flags: [...{_version: version} & #Flag]
flags: [...#Flag]
segments: [...#Segment]
})

#Flag: {
_version: string
key: string & =~"^[-_,A-Za-z0-9]+$"
name: string & =~"^.+$"
description?: string
enabled: bool | *false
variants: [...#Variant]
rules: [...#Rule]
if _version == "1.1" || _version == "1.2" {
if version == "1.1" || version == "1.2" || version == "1.3" {
type: "BOOLEAN_FLAG_TYPE" | *"VARIANT_FLAG_TYPE"
#FlagBoolean | *{}
}
Expand All @@ -32,6 +32,9 @@ close({
name?: string & =~"^.+$"
description?: string
attachment: {...} | [...] | *null
if version == "1.3" {
default: bool | *false
}
}

#RuleSegment: {
Expand Down
Loading
Loading