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: implement in-process-flagd provider #327

Merged
merged 11 commits into from
Sep 13, 2023
Merged
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
65 changes: 65 additions & 0 deletions providers/flagd-in-process/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# In-process Flagd Provider

This provider implements parts of the functionality of [Flagd](https://github.com/open-feature/flagd), and follows its
specification for [in-process providers](https://github.com/open-feature/flagd/blob/main/docs/other_resources/in-process-providers/specification.md).

## Setup
To use flagd with the [OpenFeature SDK](https://github.com/open-feature/go-sdk) set the provider to the `openfeature` global singleton as shown below (using default values which align with those of `flagd`)
```go
openfeature.SetProvider(inprocessflagd.NewProvider())
```
You may also provide additional options to configure the provider client
```go
WithSourceURI("localhost:8015") // sets the source URI
inprocessflagd.FromEnv() // sets the provider configuration from environment variables
inprocessflagd.WithSocketPath(string) // no default, when set a unix socket connection is used (only available for GRPC)
inprocessflagd.WithTLS(certPath string) // default of false, if certPath is not given, system certs are used
inprocessflagd.WithLogger(logger) // sets a custom logger (see logging section)
inprocessflagd.WithOtelInterceptor(bool) // enable or disable OpenTelemetry interceptor for flagd communication
```
for example:
```go
package main

import (
inprocessflagd "github.com/open-feature/go-sdk-contrib/providers/flagd-in-process/pkg"
"github.com/open-feature/go-sdk/pkg/openfeature"
)

func main() {
openfeature.SetProvider(inprocessflagd.NewProvider(
inprocessflagd.WithSourceURI("localhost:8015"),
inprocessflagd.WithSourceProviderType(inprocessflagd.SourceTypeGrpc),
))
}
```

### Using inprocessflagd.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_PROXY_HOST | string | | localhost |
| port | FLAGD_PROXY_PORT | number | | 8013 |
| tls | FLAGD_PROXY_TLS | boolean | | false |
| socketPath | FLAGD_PROXY_SOCKET_PATH | string | | |
| certPath | FLAGD_PROXY_SERVER_CERT_PATH | string | | |
| sourceURI | FLAGD_SOURCE_URI | string | | |
| sourceProviderType | FLAGD_SOURCE_PROVIDER_TYPE | string | | grpc |
| sourceSelector | FLAGD_SOURCE_SELECTOR | string | | |
| maxSyncRetries | FLAGD_MAX_SYNC_RETRIES | int | | 0 (0 means unlimited) |
| maxSyncRetryInterval | FLAGD_MAX_SYNC_RETRY_INTERVAL | int | | 60s |

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

e.g. below the values set by `FromEnv()` overwrite the value set by `WithSourceURI("localhost:8015")`.
```go
openfeature.SetProvider(flagd.NewProvider(
flagd.WithSourceURI("localhost:8015"),
flagd.FromEnv(),
))
```

## License

Apache 2.0 - See [LICENSE](./../../LICENSE) for more information.
111 changes: 111 additions & 0 deletions providers/flagd-in-process/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
module github.com/open-feature/go-sdk-contrib/providers/flagd-in-process

go 1.20

require (
buf.build/gen/go/open-feature/flagd/grpc/go v1.3.0-20230710190440-2333a9579c1a.1
buf.build/gen/go/open-feature/flagd/protocolbuffers/go v1.31.0-20230720212818-3675556880a1.1
github.com/golang/mock v1.6.0
github.com/open-feature/flagd/core v0.6.5
github.com/open-feature/go-sdk v1.6.0
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
)

require (
buf.build/gen/go/open-feature/flagd/bufbuild/connect-go v1.9.0-20230720212818-3675556880a1.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bufbuild/connect-go v1.10.0 // indirect
github.com/bufbuild/connect-opentelemetry-go v0.4.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/diegoholiveira/jsonlogic/v3 v3.3.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/open-feature/open-feature-operator v0.2.36 // indirect
github.com/open-feature/schemas v0.2.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/robfig/cron v1.2.0 // indirect
github.com/rs/cors v1.10.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/otel v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.40.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.40.0 // indirect
go.opentelemetry.io/otel/metric v1.17.0 // indirect
go.opentelemetry.io/otel/sdk v1.17.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.40.0 // indirect
go.opentelemetry.io/otel/trace v1.17.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.28.1 // indirect
k8s.io/apiextensions-apiserver v0.28.0 // indirect
k8s.io/apimachinery v0.28.1 // indirect
k8s.io/client-go v0.28.1 // indirect
k8s.io/component-base v0.28.1 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/controller-runtime v0.16.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading