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: Datetime constraint #1602

Merged
merged 33 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
388f940
feat(wip): datetime backend
markphelps May 9, 2023
a8ede56
feat(wip): datetime constraint ui
markphelps May 9, 2023
a328753
feat(wip): add link to future docs about datetime constraint
markphelps May 9, 2023
7f57460
Merge branch 'main' into datetime-constraint-redo
markphelps May 10, 2023
8fc328d
chore: change to store utc
markphelps May 10, 2023
32a3ed3
feat(wip): timezone picker
markphelps May 10, 2023
b1f3c94
chore: timezone hook/provider
markphelps May 10, 2023
4a7678a
chore: omg timezone
markphelps May 10, 2023
37591b8
chore: merge main
markphelps May 14, 2023
1d7fb8e
chore: drop support for Go 1.19 in tests
markphelps May 14, 2023
aab2413
feat: different approach with timezone locales
markphelps May 15, 2023
d5c6cd4
chore: forgot console.log; some cleanup
markphelps May 15, 2023
234a947
chore: more timezone fun
markphelps May 15, 2023
360fd92
Merge branch 'main' into datetime-constraint-redo
markphelps May 16, 2023
94805f4
chore: make segment use inTimezone for display
markphelps May 18, 2023
d2c062e
Merge branch 'main' into datetime-constraint-redo
markphelps May 18, 2023
2823f55
fix: link to timezone in constraint form
markphelps May 18, 2023
d1c2bc0
Merge branch 'datetime-constraint-redo' of https://github.com/flipt-i…
markphelps May 18, 2023
d1079a9
chore: move to preferences provider
markphelps May 18, 2023
c94ed23
chore: allow inputing datetimes according to prefs
markphelps May 18, 2023
36c353d
fix: timezonez?
markphelps May 19, 2023
6d39d14
chore: add a couple more tests for validation server side
markphelps May 19, 2023
d75c856
Merge branch 'main' into datetime-constraint-redo
markphelps May 19, 2023
77fd62f
fix: output reporting for ui ITs when running in CI
markphelps May 19, 2023
b44de61
Merge branch 'datetime-constraint-redo' of https://github.com/flipt-i…
markphelps May 19, 2023
76a3487
fix: set CI in IT containers; try to use GH reporter in CI
markphelps May 19, 2023
e719366
fix: namespaces UI tests
markphelps May 19, 2023
65da82f
chore: add basic prefs UI test
markphelps May 19, 2023
85256ba
Merge branch 'main' into datetime-constraint-redo
markphelps May 19, 2023
e924adf
chore: rm uploading of playwright report
markphelps May 21, 2023
d8a02eb
Merge branch 'datetime-constraint-redo' of https://github.com/flipt-i…
markphelps May 21, 2023
05c4c8e
chore: rm comment
markphelps May 22, 2023
e354f3f
Merge branch 'main' into datetime-constraint-redo
markphelps May 22, 2023
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
8 changes: 0 additions & 8 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,3 @@ jobs:
version: latest
args: test:ui
workdir: build

- name: Upload Playwright Report
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 5
markphelps marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.19", "1.20"]
go: ["1.20"]
steps:
- uses: actions/checkout@v3

Expand Down
2 changes: 2 additions & 0 deletions build/testing/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"log"
"math/rand"
"os"
"path"
"strings"
"time"
Expand Down Expand Up @@ -90,6 +91,7 @@ func Integration(ctx context.Context, client *dagger.Client, base, flipt *dagger

name := strings.ToLower(replacer.Replace(fmt.Sprintf("flipt-test-%s-config-%s", test.name, config.name)))
flipt = flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_LOG_LEVEL", "debug").
WithEnvVariable("FLIPT_LOG_FILE", fmt.Sprintf("/var/opt/flipt/logs/%s.log", name)).
WithMountedCache("/var/opt/flipt/logs", logs)
Expand Down
2 changes: 2 additions & 0 deletions build/testing/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testing

import (
"context"
"os"
"time"

"dagger.io/dagger"
Expand All @@ -11,6 +12,7 @@ func UI(ctx context.Context, client *dagger.Client, ui, flipt *dagger.Container)
test := ui.
WithExec([]string{"npx", "playwright", "install", "chromium", "--with-deps"}).
WithServiceBinding("flipt", flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_AUTHENTICATION_METHODS_TOKEN_ENABLED", "true").
WithEnvVariable("UNIQUE", time.Now().String()).
WithExec(nil)).
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.2
github.com/testcontainers/testcontainers-go v0.19.0
github.com/testcontainers/testcontainers-go v0.20.0
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/xo/dburl v0.14.2
go.flipt.io/flipt/errors v1.19.3
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v23.0.3+incompatible // indirect
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
Expand All @@ -93,6 +93,7 @@ require (
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m3
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.4.2-0.20190924003213-a8608b5b67c7/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v20.10.13+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v23.0.3+incompatible h1:9GhVsShNWz1hO//9BNg/dpMnZW25KydO4wtVxWAIbho=
github.com/docker/docker v23.0.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v23.0.5+incompatible h1:DaxtlTJjFSnLOXVNUBU1+6kXGz2lpDoEAH6QoxaSg8k=
github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.6.3/go.mod h1:WRaJzqw3CTB9bk10avuGsjVBZsD05qeibJ1/TYlvc0Y=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
Expand Down Expand Up @@ -738,6 +738,7 @@ github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down Expand Up @@ -1225,8 +1226,8 @@ github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I=
github.com/testcontainers/testcontainers-go v0.19.0 h1:3bmFPuQRgVIQwxZJERyzB8AogmJW3Qzh8iDyfJbPhi8=
github.com/testcontainers/testcontainers-go v0.19.0/go.mod h1:3YsSoxK0rGEUzbGD4gUVt1Nm3GJpCIq94GX+2LSf3d4=
github.com/testcontainers/testcontainers-go v0.20.0 h1:ASrcJee7vcWNw43yUgL2n8KA5IOywrF031GawlrkVkE=
github.com/testcontainers/testcontainers-go v0.20.0/go.mod h1:zb+NOlCQBkZ7RQp4QI+YMIHyO2CQ/qsXzNF5eLJ24SY=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
4 changes: 4 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi
github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY=
github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk=
github.com/docker/cli v23.0.0-rc.1+incompatible h1:Vl3pcUK4/LFAD56Ys3BrqgAtuwpWd/IO3amuSL0ZbP0=
github.com/docker/docker v23.0.5+incompatible h1:DaxtlTJjFSnLOXVNUBU1+6kXGz2lpDoEAH6QoxaSg8k=
github.com/docker/docker v23.0.5+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8=
github.com/docker/go-metrics v0.0.1 h1:AgB/0SvBxihN0X8OR4SjsblXkbMvalQ8cjmtKQ2rQV8=
Expand Down Expand Up @@ -923,6 +925,8 @@ github.com/stretchr/testify v1.7.5/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/subosito/gotenv v1.4.0/go.mod h1:mZd6rFysKEcUhUHXJk0C/08wAgyDBFuwEYL7vWWGaGo=
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 h1:kdXcSzyDtseVEc4yCz2qF8ZrQvIDBJLl4S1c3GCXmoI=
github.com/tchap/go-patricia v2.2.6+incompatible h1:JvoDL7JSoIP2HDE8AbDH3zC8QBPxmzYe32HHy5yQ+Ck=
github.com/testcontainers/testcontainers-go v0.20.0 h1:ASrcJee7vcWNw43yUgL2n8KA5IOywrF031GawlrkVkE=
github.com/testcontainers/testcontainers-go v0.20.0/go.mod h1:zb+NOlCQBkZ7RQp4QI+YMIHyO2CQ/qsXzNF5eLJ24SY=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=
Expand Down
55 changes: 55 additions & 0 deletions internal/server/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (s *Server) evaluate(ctx context.Context, r *flipt.EvaluationRequest) (resp
match, err = matchesNumber(c, v)
case flipt.ComparisonType_BOOLEAN_COMPARISON_TYPE:
match, err = matchesBool(c, v)
case flipt.ComparisonType_DATETIME_COMPARISON_TYPE:
match, err = matchesDateTime(c, v)
default:
resp.Reason = flipt.EvaluationReason_ERROR_EVALUATION_REASON
return resp, errs.ErrInvalid("unknown constraint type")
Expand Down Expand Up @@ -443,3 +445,56 @@ func matchesBool(c storage.EvaluationConstraint, v string) (bool, error) {

return false, nil
}

func matchesDateTime(c storage.EvaluationConstraint, v string) (bool, error) {
switch c.Operator {
case flipt.OpNotPresent:
return len(strings.TrimSpace(v)) == 0, nil
case flipt.OpPresent:
return len(strings.TrimSpace(v)) != 0, nil
}

// can't parse an empty string
if v == "" {
return false, nil
}

d, err := tryParseDateTime(v)
if err != nil {
return false, err
}

value, err := tryParseDateTime(c.Value)
if err != nil {
return false, err
}

switch c.Operator {
case flipt.OpEQ:
return value.Equal(d), nil
case flipt.OpNEQ:
return !value.Equal(d), nil
case flipt.OpLT:
return d.Before(value), nil
case flipt.OpLTE:
return d.Before(value) || value.Equal(d), nil
case flipt.OpGT:
return d.After(value), nil
case flipt.OpGTE:
return d.After(value) || value.Equal(d), nil
}

return false, nil
}

func tryParseDateTime(v string) (time.Time, error) {
if d, err := time.Parse(time.RFC3339, v); err == nil {
return d.UTC(), nil
}

if d, err := time.Parse(time.DateOnly, v); err == nil {
markphelps marked this conversation as resolved.
Show resolved Hide resolved
return d.UTC(), nil
}

return time.Time{}, errs.ErrInvalidf("parsing datetime from %q", v)
}
Loading