Skip to content

Commit

Permalink
feat: Eventing support for flagd provider (#317)
Browse files Browse the repository at this point in the history
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Signed-off-by: Kavindu Dodanduwa <[email protected]>
Co-authored-by: Todd Baert <[email protected]>
Co-authored-by: Giovanni Liva <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2023
1 parent 818fae8 commit 6b373cb
Show file tree
Hide file tree
Showing 24 changed files with 1,876 additions and 2,388 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test:
go list -f '{{.Dir}}/...' -m | xargs -I{} go test -v {}

lint:
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.1
$(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run --deadline=3m --timeout=3m $(module)/...;)

new-provider:
Expand Down
2 changes: 1 addition & 1 deletion providers/flagd/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.PHONY: mockgen
mockgen:
mockgen -source=pkg/service/iservice.go -destination=internal/mock/service_mock.go -package=mock
mockgen -source=pkg/iservice.go -destination=internal/mock/service_mock.go -package=mock
40 changes: 30 additions & 10 deletions providers/flagd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func main() {
### Using flagd.FromEnv()
By default the flagd provider will read non-empty environment variables to set its own configuration with the lowest priority. Use the `flagd.FromEnv()` option as an argument for the `flagd.NewProvider()` method to give environment variables a higher priority.

| Option name | Environment variable name | Type | Options | Default |
|-----------------------|--------------------------------|-----------|--------------|-----------|
| host | FLAGD_HOST | string | | localhost |
| port | FLAGD_PORT | number | | 8013 |
| tls | FLAGD_TLS | boolean | | false |
| socketPath | FLAGD_SOCKET_PATH | string | | |
| certPath | FLAGD_SERVER_CERT_PATH | string | | |
| cache | FLAGD_CACHE | string | lru,disabled | lru |
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | | 1000 |
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | | 5 |
| Option name | Environment variable name | Type | Options | Default |
|-----------------------|--------------------------------|---------|--------------------|-----------|
| host | FLAGD_HOST | string | | localhost |
| port | FLAGD_PORT | number | | 8013 |
| tls | FLAGD_TLS | boolean | true, false | false |
| socketPath | FLAGD_SOCKET_PATH | string | | |
| certPath | FLAGD_SERVER_CERT_PATH | string | | |
| cache | FLAGD_CACHE | string | lru, mem, disabled | lru |
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | | 1000 |
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | | 5 |

In the event that another configuration option is passed to the `flagd.NewProvider()` method, such as `flagd.WithPort(8013)` then priority is decided by the order in which the options are passed to the constructor from lowest to highest priority.

Expand Down Expand Up @@ -97,6 +97,26 @@ flagd.WithBasicInMemoryCache()
flagd.WithoutCache()
```

## Supported Events

The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIGURATION_CHANGED` events.

| SDK event | Originating action in flagd |
|----------------------------------|---------------------------------------------------------------------------------|
| `PROVIDER_READY` | The streaming connection with flagd has been established. |
| `PROVIDER_ERROR` | The streaming connection with flagd has been broken. |
| `PROVIDER_CONFIGURATION_CHANGED` | A flag configuration (default value, targeting rule, etc) in flagd has changed. |

For general information on events, see the [official documentation](https://openfeature.dev/docs/reference/concepts/events).

## Flag Metadata

The flagd provider currently support following flag evaluation metadata,

| Field | Type | Value |
|---------|--------|---------------------------------------------------|
| `scope` | string | "selector" set for the associated source in flagd |

## Logging

If not configured, logging falls back to the standard Go log package at error level only.
Expand Down
1 change: 0 additions & 1 deletion providers/flagd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/bufbuild/connect-opentelemetry-go v0.4.0
github.com/go-logr/logr v1.2.4
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/hashicorp/golang-lru/v2 v2.0.4
github.com/open-feature/flagd/core v0.6.2
github.com/open-feature/go-sdk v1.6.0
Expand Down
13 changes: 0 additions & 13 deletions providers/flagd/go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
buf.build/gen/go/grpc-ecosystem/grpc-gateway/protocolbuffers/go v1.29.1-20220906183531-bc28b723cd77.1/go.mod h1:hhON98gyTBA8hmdzw7bPux2Zerm5Sp2hesfc5t6jpoI=
buf.build/gen/go/grpc-ecosystem/grpc-gateway/protocolbuffers/go v1.31.0-20220906183531-bc28b723cd77.1/go.mod h1:/j/LOrpev/FdyGhdj/sOc0peUf2KR0y4nMmLp4t1g14=
buf.build/gen/go/open-feature/flagd/bufbuild/connect-go v1.5.2-20230710190440-2333a9579c1a.1 h1:Cno0dUv5u33SiQ3F9g3UcubY1F/h+ovK7tkmjVzc7uI=
buf.build/gen/go/open-feature/flagd/bufbuild/connect-go v1.5.2-20230710190440-2333a9579c1a.1/go.mod h1:yClM0n7s6o0v+dKv2S9iC+Sb5JbXHtUI3MtFE1TIq78=
buf.build/gen/go/open-feature/flagd/bufbuild/connect-go v1.9.0-20230720212818-3675556880a1.1 h1:famYYNRx3ZbC0FxNOICnjau9T0gelgaoXsenjfNocxg=
buf.build/gen/go/open-feature/flagd/bufbuild/connect-go v1.9.0-20230720212818-3675556880a1.1/go.mod h1:7EjC+x8QSHYXzDCeYfDN3mS/46eboAZLXChIe8iUrF8=
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.29.1-20230317150644-afd1cc2ef580.1 h1:CWgXoLTajc7QagTz76kplcFnjjWIkxhhDdmKYtVShOU=
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.29.1-20230317150644-afd1cc2ef580.1/go.mod h1:WWnccsJMW7QwvXkdXUuQmg28sx+ZoX36+J2TAjcy6u4=
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.31.0-20230720212818-3675556880a1.1 h1:4KG4mmtBU0USgznO6QuhB3oTnCrlI+ayBaGjRfgsXeM=
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.31.0-20230720212818-3675556880a1.1/go.mod h1:kmgvCcQsQkpZ5yNLgO2B22ysHjnfm3IyzymmFHB60vY=
github.com/bufbuild/connect-go v1.9.0 h1:JIgAeNuFpo+SUPfU19Yt5TcWlznsN5Bv10/gI/6Pjoc=
github.com/bufbuild/connect-go v1.9.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
github.com/bufbuild/connect-go v1.10.0 h1:QAJ3G9A1OYQW2Jbk3DeoJbkCxuKArrvZgDt47mjdTbg=
github.com/bufbuild/connect-go v1.10.0/go.mod h1:CAIePUgkDR5pAFaylSMtNK45ANQjp9JvpluG20rhpV8=
github.com/bufbuild/connect-opentelemetry-go v0.4.0 h1:6JAn10SNqlQ/URhvRNGrIlczKw1wEXknBUUtmWqOiak=
Expand All @@ -25,15 +18,10 @@ github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+Licev
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hashicorp/golang-lru/v2 v2.0.4 h1:7GHuZcgid37q8o5i3QI9KMT4nCWQQ3Kx3Ov6bb9MfK0=
github.com/hashicorp/golang-lru/v2 v2.0.4/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/open-feature/flagd/core v0.6.0 h1:sf8BR3YcggLJuUrpWKiknfhhSv2gVQ6hvQgZYmzQMok=
github.com/open-feature/flagd/core v0.6.0/go.mod h1:gYf76egLbU3gYIX5B0720O0HPXnRiMRr4YTvAgQBTFc=
github.com/open-feature/flagd/core v0.6.2 h1:kE687GgvJrbzfwBeywuG52he9UtxQm4LB+1CbaESfN8=
github.com/open-feature/flagd/core v0.6.2/go.mod h1:9ojqWYYJqsHnAC8kNTrMxCpP6OOE3zLxZip/C0Gt6h0=
github.com/open-feature/go-sdk v1.5.1 h1:ja1+XtWwqLqgJSFJ31sh+MCioVW4vWj5ya/e/f81y38=
github.com/open-feature/go-sdk v1.5.1/go.mod h1:yllFTs5yJguao9zdcmYYGJBHTyBGwO2zC+GP2JeFR0o=
github.com/open-feature/go-sdk v1.6.0 h1:9Wi8J77ORVKvm/8d1ZGKI7+/Uq+5JrpxylQ50DvZZnA=
github.com/open-feature/go-sdk v1.6.0/go.mod h1:xR4RHexQNwvE/7IOR0LOiCuH+2wlQyoZwpAc4bp508o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -77,7 +65,6 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
109 changes: 59 additions & 50 deletions providers/flagd/internal/mock/service_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions providers/flagd/internal/model/error.go

This file was deleted.

8 changes: 0 additions & 8 deletions providers/flagd/pkg/cache.go

This file was deleted.

Loading

0 comments on commit 6b373cb

Please sign in to comment.