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!: Updated service to use connect #163

Merged
merged 26 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
079c63a
initial commit - tested with rest, need to build remaining clients
james-milligan Sep 5, 2022
a0e9f4c
added TLS support
james-milligan Sep 7, 2022
45ea73d
unit tests + fix unix support
james-milligan Sep 20, 2022
2142ad6
error handling and readme
james-milligan Sep 20, 2022
a84f4a0
updated all examples
james-milligan Sep 20, 2022
e02089d
updated examples
james-milligan Sep 20, 2022
1376cac
merge
james-milligan Sep 20, 2022
dd370c7
merge
james-milligan Sep 20, 2022
12e4de3
linting fixes
james-milligan Sep 20, 2022
740d10d
removed error from benchmark, reduces logging should be more accurate
james-milligan Sep 20, 2022
c5d0cab
Merge branch 'main' into connect-refactor
james-milligan Sep 20, 2022
dfcb670
removed error route from benchmark
james-milligan Sep 21, 2022
121f050
merge conflict
james-milligan Sep 21, 2022
6eba48c
Merge branch 'connect-refactor' of https://github.com/james-milligan/…
james-milligan Sep 21, 2022
7b9aa73
update README and docs
james-milligan Sep 21, 2022
c5edb18
added disabled error reason
james-milligan Sep 21, 2022
9631751
removed comment line
james-milligan Sep 21, 2022
72e1223
updated missed curl requests
james-milligan Sep 21, 2022
f5fce5e
add cors flag
james-milligan Sep 21, 2022
85598d4
added data loss code for parse error
james-milligan Sep 21, 2022
b57a7c7
lint fix
james-milligan Sep 21, 2022
65e04cc
linting fixes and test fix
james-milligan Sep 22, 2022
154dfc3
merge
james-milligan Sep 22, 2022
3cc0bca
added error prefix for parsing, added cors flag
james-milligan Sep 22, 2022
3f1b61e
cors headers comment
james-milligan Sep 26, 2022
daa9ca6
Merge branch 'main' into connect-refactor
AlexsJones Sep 26, 2022
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ This now provides an accessible http or [https](#https) endpoint for flag evalua
Command:

```sh
curl -X POST "localhost:8013/flags/myBoolFlag/resolve/boolean"
curl -X POST "localhost:8013/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"myBoolFlag","context":{}}' -H "Content-Type: application/json"
```

Result:

```sh
{"value":true,"reason":"STATIC","variant":"on"}
{"value":true,"reason":"TARGETING_MATCH","variant":"on"}
beeme1mr marked this conversation as resolved.
Show resolved Hide resolved
```

<br />
Expand All @@ -52,7 +52,7 @@ Result:
Command:

```sh
curl -X POST "localhost:8013/flags/myStringFlag/resolve/string"
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"myStringFlag","context":{}}' -H "Content-Type: application/json"
```

Result:
Expand All @@ -68,7 +68,7 @@ Result:
Command:

```sh
curl -X POST "localhost:8013/flags/myIntFlag/resolve/int"
curl -X POST "localhost:8013/schema.v1.Service/ResolveInt" -d '{"flagKey":"myIntFlag","context":{}}' -H "Content-Type: application/json"
```

Result:
Expand All @@ -86,7 +86,7 @@ Result:
Command:

```sh
curl -X POST "localhost:8013/flags/myFloatFlag/resolve/float"
curl -X POST "localhost:8013/schema.v1.Service/ResolveFloat" -d '{"flagKey":"myFloatFlag","context":{}}' -H "Content-Type: application/json"
```

Result:
Expand All @@ -102,7 +102,7 @@ Result:
Command:

```sh
curl -X POST "localhost:8013/flags/myObjectFlag/resolve/object"
curl -X POST "localhost:8013/schema.v1.Service/ResolveObject" -d '{"flagKey":"myObjectFlag","context":{}}' -H "Content-Type: application/json"
```

Result:
Expand All @@ -118,7 +118,7 @@ Result:
Command:

```sh
curl -X POST "localhost:8013/flags/isColorYellow/resolve/boolean" -d '{"color": "yellow"}'
curl -X POST "localhost:8013/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"isColorYellow","context":{"color":"yellow"}}' -H "Content-Type: application/json"
```

Result:
Expand All @@ -136,13 +136,13 @@ A type mismatch error is returned when the resolved value of a flag does not mat
Command:

```sh
curl -X POST "localhost:8013/flags/myBoolFlag/resolve/string"
curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d '{"flagKey":"myBoolFlag","context":{}}' -H "Content-Type: application/json"
```

Result:

```sh
{"error_code":"TYPE_MISMATCH","reason":"ERROR"}
{"code":"invalid_argument","message":"TYPE_MISMATCH"}
```

<br />
Expand All @@ -154,13 +154,13 @@ The flag not found error is returned when flag key in the request doesn't match
Command:

```sh
curl -X POST "localhost:8013/flags/aMissingFlag/resolve/string"
curl -X POST "localhost:8013/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"aMissingFlag","context":{}}' -H "Content-Type: application/json"
```

Result:

```sh
{"error_code":"FLAG_NOT_FOUND","reason":"ERROR"}
{"code":"not_found","message":"FLAG_NOT_FOUND"}
```

### https
Expand Down Expand Up @@ -243,7 +243,7 @@ returns
whereas

```shell
curl -X POST "localhost:8013/flags/isColorYellow/resolve/boolean" -d '{"color": "white"}'
curl -X POST "localhost:8013/schema.v1.Service/ResolveBoolean" -d '{"flagKey":"isColorYellow","context":{"color":"white"}}' -H "Content-Type: application/json"
```

returns
Expand Down
22 changes: 9 additions & 13 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import (
)

const (
portFlagName = "port"
serviceProviderFlagName = "service-provider"
socketPathFlagName = "socket-path"
syncProviderFlagName = "sync-provider"
providerArgsFlagName = "sync-provider-args"
evaluatorFlagName = "evaluator"
serverCertPathFlagName = "server-cert-path"
serverKeyPathFlagName = "server-key-path"
uriFlagName = "uri"
bearerTokenFlagName = "bearer-token"
portFlagName = "port"
socketPathFlagName = "socket-path"
syncProviderFlagName = "sync-provider"
providerArgsFlagName = "sync-provider-args"
evaluatorFlagName = "evaluator"
serverCertPathFlagName = "server-cert-path"
serverKeyPathFlagName = "server-key-path"
uriFlagName = "uri"
bearerTokenFlagName = "bearer-token"
)

func init() {
Expand All @@ -34,7 +33,6 @@ func init() {
flags.StringP(socketPathFlagName, "d", "", "Flagd socket path. "+
"With grpc the service will become available on this address. "+
"With http(s) the grpc-gateway proxy will use this address internally.")
flags.StringP(serviceProviderFlagName, "s", "http", "Set a service provider e.g. http or grpc")
flags.StringP(
syncProviderFlagName, "y", "filepath", "Set a sync provider e.g. filepath or remote",
)
Expand All @@ -52,7 +50,6 @@ func init() {

_ = viper.BindPFlag(portFlagName, flags.Lookup(portFlagName))
_ = viper.BindPFlag(socketPathFlagName, flags.Lookup(socketPathFlagName))
_ = viper.BindPFlag(serviceProviderFlagName, flags.Lookup(serviceProviderFlagName))
_ = viper.BindPFlag(syncProviderFlagName, flags.Lookup(syncProviderFlagName))
_ = viper.BindPFlag(providerArgsFlagName, flags.Lookup(providerArgsFlagName))
_ = viper.BindPFlag(evaluatorFlagName, flags.Lookup(evaluatorFlagName))
Expand All @@ -78,7 +75,6 @@ var startCmd = &cobra.Command{
}
// Build Runtime -----------------------------------------------------------
rt, err := runtime.FromConfig(runtime.Config{
ServiceProvider: viper.GetString(serviceProviderFlagName),
ServicePort: viper.GetInt32(portFlagName),
ServiceSocketPath: viper.GetString(socketPathFlagName),
ServiceCertPath: viper.GetString(serverCertPathFlagName),
Expand Down
1 change: 0 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Supported flags are as follows (result of running `./flagd start --help`):
-p, --port int32 Port to listen on (default 8013)
-c, --server-cert-path string Server side tls certificate path
-k, --server-key-path string Server side tls key path
-s, --service-provider string Set a service provider e.g. http or grpc (default "http")
-a, --sync-provider-args Sync provider arguments as key values separated by =
-d, --socket-path string Set the flagd socket path. With grpc the service will become available on this address. With http(s) the grpc-gateway proxy will use this address internally
AlexsJones marked this conversation as resolved.
Show resolved Hide resolved
-y, --sync-provider string Set a sync provider e.g. filepath or remote (default "filepath")
Expand Down
50 changes: 50 additions & 0 deletions docs/configuration.md.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
### Configuration

`flagd` supports configuration via config file, environment variables and flags. In cases of conflict, flags have the
highest priority, followed by environment variables and finally config file.

Supported flags are as follows (result of running `./flagd start --help`):

```
-b, --bearer-token string Set a bearer token to use for remote sync
-e, --evaluator string Set an evaluator e.g. json (default "json")
-h, --help help for start
-p, --port int32 Port to listen on (default 8013)
-c, --server-cert-path string Server side tls certificate path
-k, --server-key-path string Server side tls key path
<<<<<<< HEAD
AlexsJones marked this conversation as resolved.
Show resolved Hide resolved
=======
-s, --service-provider string Set a service provider e.g. http or grpc (default "http")
-a, --sync-provider-args Sync provider arguments as key values separated by =
>>>>>>> 82278c7cf08cc6b50f49ab500caf6f9003fc0823
-d, --socket-path string Set the flagd socket path. With grpc the service will become available on this address. With http(s) the grpc-gateway proxy will use this address internally
-y, --sync-provider string Set a sync provider e.g. filepath or remote (default "filepath")
-f, --uri strings Set a sync provider uri to read data from this can be a filepath or url. Using multiple providers is supported where collisions between flags with the same key, the later will be used.
```

Environment variable keys are uppercased, prefixed with `FLAGD_` and all `-` are replaced with `_`. For example,
`sync-provider` in environment variable form is `FLAGD_SYNC_PROVIDER`.

Config file expects the keys to have the exact naming as the flags.


### Customising sync providers

Custom sync providers can be used to provide flag evaluation logic.

#### Kubernetes provider

The Kubernetes provider allows flagD to connect to a Kubernetes cluster and evaluate flags against a specified FeatureFlagConfiguration resource as defined within the [open-feature-operator](https://github.com/open-feature/open-feature-operator/blob/main/apis/core/v1alpha1/featureflagconfiguration_types.go) spec.

To use an existing FeatureFlagConfiguration custom resource, start flagD with the following command:

```shell
flagd start --sync-provider=kubernetes --sync-provider-args=featureflagconfiguration=my-example --sync-provider-args=namespace=default
```

An additional optional flag `refreshtime` can be applied to shorten the cache refresh when using the Kubernetes provider ( The default is 5s ). As an example:

```shell
flagd start --sync-provider=kubernetes --sync-provider-args=featureflagconfiguration=my-example --sync-provider-args=namespace=default
--sync-provider-args=refreshtime=1s
```
4 changes: 2 additions & 2 deletions docs/fractional_evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Flags defined as such:
will return variant `red` 50% of the time, `blue` 20% of the time & `green` 30% of the time.

```shell
$ curl -X POST "localhost:8013/flags/headerColor/resolve/string" -d '{"email": "foo@bar.com"}'
$ curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d ''{"flagKey":"headerColor","context":{"email": "foo@bar.com"}}'' -H "Content-Type: application/json"
{"value":"#0000FF","reason":"TARGETING_MATCH","variant":"blue"}%

$ curl -X POST "localhost:8013/flags/headerColor/resolve/string" -d '{"email": "foo@test.com"}'
$ curl -X POST "localhost:8013/schema.v1.Service/ResolveString" -d ''{"flagKey":"headerColor","context":{"email": "foo@test.com"}}'' -H "Content-Type: application/json"
{"value":"#00FF00","reason":"TARGETING_MATCH","variant":"green"}%
```
6 changes: 3 additions & 3 deletions docs/http_int_response.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Why is my `int` response a `string`?
Command:
```sh
curl -X POST "localhost:8013/flags/myIntFlag/resolve/int"
curl -X POST "localhost:8013/schema.v1.Service/ResolveInt" -d '{"flagKey":"myIntFlag","context":{}}' -H "Content-Type: application/json"
```
Result:
```sh
Expand All @@ -14,9 +14,9 @@ When interacting directly with the flagD http(s) api and requesting an `int` the
<br />
Command:
```sh
curl -X POST "localhost:8013/flags/myIntFlag/resolve/float"
curl -X POST "localhost:8013/schema.v1.Service/ResolveFloat" -d '{"flagKey":"myIntFlag","context":{}}' -H "Content-Type: application/json"
```
Result:
```sh
{"value":1.23,"reason":"STATIC","variant":"one"}
{"value":1,"reason":"STATIC","variant":"one"}
```
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ module github.com/open-feature/flagd
go 1.18

require (
github.com/bufbuild/connect-go v0.4.0
github.com/deepmap/oapi-codegen v1.11.0
github.com/diegoholiveira/jsonlogic/v3 v3.2.3
github.com/dimiro1/banner v1.1.0
github.com/fsnotify/fsnotify v1.5.4
github.com/go-chi/chi/v5 v5.0.7
github.com/golang/mock v1.6.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.1
github.com/mattn/go-colorable v0.1.12
github.com/open-feature/open-feature-operator v0.0.10-0.20220826061622-a6421d66936a
github.com/open-feature/schemas v0.0.0-20220809125333-185e3bd77775
github.com/robfig/cron v1.2.0
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.8.1
github.com/soheilhy/cmux v0.1.5
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.7.4
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zeebo/xxh3 v1.0.2
go.buf.build/open-feature/flagd-server/open-feature/flagd v1.1.2
go.buf.build/open-feature/flagd-connect/open-feature/flagd v1.1.3
golang.org/x/net v0.0.0-20220909164309-bea034e7d591
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
Expand Down Expand Up @@ -73,7 +74,6 @@ require (
github.com/subosito/gotenv v1.3.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
Loading