Skip to content

Commit

Permalink
updated endpoints to use new api in docs and e2e tests
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
bacherfl committed Dec 19, 2023
1 parent 2438284 commit 735a94a
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 96 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Experiment with flagd in your browser using [the Killercoda tutorial](https://ki
Retrieve a `String` value:
```sh
curl -X POST "http://localhost:8013/schema.v1.Service/ResolveString" \
curl -X POST "http://localhost:8013/flagd.evaluation.v1.Service/ResolveString" \
-d '{"flagKey":"myStringFlag","context":{}}' -H "Content-Type: application/json"
```
Expand All @@ -105,7 +105,7 @@ Experiment with flagd in your browser using [the Killercoda tutorial](https://ki
```sh
set json={"flagKey":"myStringFlag","context":{}}
curl -i -X POST -H "Content-Type: application/json" -d %json:"=\"% "localhost:8013/schema.v1.Service/ResolveString"
curl -i -X POST -H "Content-Type: application/json" -d %json:"=\"% "localhost:8013/flagd.evaluation.v1.Service/ResolveString"
```
Result:
Expand Down
6 changes: 4 additions & 2 deletions core/pkg/service/flag-evaluation/connect_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (

// bufSwitchHandler combines the handlers of the old and new evaluation schema and combines them into one
// this way we support both the new and the (deprecated) old schemas until only the new schema is supported
// NOTE: this will not be required anymore when it is time to work on https://github.com/open-feature/flagd/issues/1088
type bufSwitchHandler struct {
old http.Handler
new http.Handler
Expand Down Expand Up @@ -143,7 +144,8 @@ func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listene
}

// register handler for old flag evaluation schema
fes := NewFlagEvaluationService(
// can be removed as a part of https://github.com/open-feature/flagd/issues/1088
fes := NewOldFlagEvaluationService(
s.logger.WithFields(zap.String("component", "flagservice")),
s.eval,
s.eventingConfiguration,
Expand All @@ -160,7 +162,7 @@ func (s *ConnectService) setupServer(svcConf service.Configuration) (net.Listene

// register handler for new flag evaluation schema

newFes := NewFlagEvaluationServiceV2(s.logger.WithFields(zap.String("component", "flagd.evaluation.v1")),
newFes := NewFlagEvaluationService(s.logger.WithFields(zap.String("component", "flagd.evaluation.v1")),
s.eval,
s.eventingConfiguration,
s.metrics,
Expand Down
4 changes: 2 additions & 2 deletions core/pkg/service/flag-evaluation/connect_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ func TestAddMiddleware(t *testing.T) {
}()

require.Eventually(t, func() bool {
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/schema.v1.Service/ResolveAll", port))
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/flagd.evaluation.v1.Service/ResolveAll", port))
// with the default http handler we should get a method not allowed (405) when attempting a GET request
return err == nil && resp.StatusCode == http.StatusMethodNotAllowed
}, 3*time.Second, 100*time.Millisecond)

svc.AddMiddleware(mwMock)

// with the injected middleware, the GET method should work
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/schema.v1.Service/ResolveAll", port))
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/flagd.evaluation.v1.Service/ResolveAll", port))

require.Nil(t, err)
// verify that the status we return in the mocked middleware
Expand Down
26 changes: 14 additions & 12 deletions core/pkg/service/flag-evaluation/flag_evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ import (
type resolverSignature[T constraints] func(context context.Context, reqID, flagKey string, ctx map[string]any) (
T, string, string, map[string]interface{}, error)

type FlagEvaluationService struct {
// OldFlagEvaluationService implements the methods required for the soon-to-be deprecated flag evaluation schema
// this can be removed as a part of https://github.com/open-feature/flagd/issues/1088
type OldFlagEvaluationService struct {
logger *logger.Logger
eval evaluator.IEvaluator
metrics *telemetry.MetricsRecorder
eventingConfiguration *eventingConfiguration
flagEvalTracer trace.Tracer
}

// NewFlagEvaluationService creates a FlagEvaluationService with provided parameters
func NewFlagEvaluationService(log *logger.Logger,
// NewOldFlagEvaluationService creates a OldFlagEvaluationService with provided parameters
func NewOldFlagEvaluationService(log *logger.Logger,
eval evaluator.IEvaluator, eventingCfg *eventingConfiguration, metricsRecorder *telemetry.MetricsRecorder,
) *FlagEvaluationService {
return &FlagEvaluationService{
) *OldFlagEvaluationService {
return &OldFlagEvaluationService{
logger: log,
eval: eval,
metrics: metricsRecorder,
Expand All @@ -46,7 +48,7 @@ func NewFlagEvaluationService(log *logger.Logger,
}

// nolint:dupl
func (s *FlagEvaluationService) ResolveAll(
func (s *OldFlagEvaluationService) ResolveAll(
ctx context.Context,
req *connect.Request[schemaV1.ResolveAllRequest],
) (*connect.Response[schemaV1.ResolveAllResponse], error) {
Expand Down Expand Up @@ -109,7 +111,7 @@ func (s *FlagEvaluationService) ResolveAll(
return connect.NewResponse(res), nil
}

func (s *FlagEvaluationService) EventStream(
func (s *OldFlagEvaluationService) EventStream(
ctx context.Context,
req *connect.Request[schemaV1.EventStreamRequest],
stream *connect.ServerStream[schemaV1.EventStreamResponse],
Expand Down Expand Up @@ -148,7 +150,7 @@ func (s *FlagEvaluationService) EventStream(
}
}

func (s *FlagEvaluationService) ResolveBoolean(
func (s *OldFlagEvaluationService) ResolveBoolean(
ctx context.Context,
req *connect.Request[schemaV1.ResolveBooleanRequest],
) (*connect.Response[schemaV1.ResolveBooleanResponse], error) {
Expand All @@ -172,7 +174,7 @@ func (s *FlagEvaluationService) ResolveBoolean(
return res, err
}

func (s *FlagEvaluationService) ResolveString(
func (s *OldFlagEvaluationService) ResolveString(
ctx context.Context,
req *connect.Request[schemaV1.ResolveStringRequest],
) (*connect.Response[schemaV1.ResolveStringResponse], error) {
Expand All @@ -197,7 +199,7 @@ func (s *FlagEvaluationService) ResolveString(
return res, err
}

func (s *FlagEvaluationService) ResolveInt(
func (s *OldFlagEvaluationService) ResolveInt(
ctx context.Context,
req *connect.Request[schemaV1.ResolveIntRequest],
) (*connect.Response[schemaV1.ResolveIntResponse], error) {
Expand All @@ -222,7 +224,7 @@ func (s *FlagEvaluationService) ResolveInt(
return res, err
}

func (s *FlagEvaluationService) ResolveFloat(
func (s *OldFlagEvaluationService) ResolveFloat(
ctx context.Context,
req *connect.Request[schemaV1.ResolveFloatRequest],
) (*connect.Response[schemaV1.ResolveFloatResponse], error) {
Expand All @@ -247,7 +249,7 @@ func (s *FlagEvaluationService) ResolveFloat(
return res, err
}

func (s *FlagEvaluationService) ResolveObject(
func (s *OldFlagEvaluationService) ResolveObject(
ctx context.Context,
req *connect.Request[schemaV1.ResolveObjectRequest],
) (*connect.Response[schemaV1.ResolveObjectResponse], error) {
Expand Down
22 changes: 11 additions & 11 deletions core/pkg/service/flag-evaluation/flag_evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestConnectService_ResolveAll(t *testing.T) {
tt.evalRes,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestFlag_Evaluation_ResolveBoolean(t *testing.T) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -283,7 +283,7 @@ func BenchmarkFlag_Evaluation_ResolveBoolean(b *testing.B) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestFlag_Evaluation_ResolveString(t *testing.T) {
tt.wantErr,
)
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -436,7 +436,7 @@ func BenchmarkFlag_Evaluation_ResolveString(b *testing.B) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -533,7 +533,7 @@ func TestFlag_Evaluation_ResolveFloat(t *testing.T) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -588,7 +588,7 @@ func BenchmarkFlag_Evaluation_ResolveFloat(b *testing.B) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -685,7 +685,7 @@ func TestFlag_Evaluation_ResolveInt(t *testing.T) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -740,7 +740,7 @@ func BenchmarkFlag_Evaluation_ResolveInt(b *testing.B) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -840,7 +840,7 @@ func TestFlag_Evaluation_ResolveObject(t *testing.T) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down Expand Up @@ -903,7 +903,7 @@ func BenchmarkFlag_Evaluation_ResolveObject(b *testing.B) {
tt.wantErr,
).AnyTimes()
metrics, exp := getMetricReader()
s := NewFlagEvaluationService(
s := NewOldFlagEvaluationService(
logger.NewLogger(nil, false),
eval,
&eventingConfiguration{},
Expand Down
24 changes: 12 additions & 12 deletions core/pkg/service/flag-evaluation/flag_evaluator_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ import (
"google.golang.org/protobuf/types/known/structpb"
)

type FlagEvaluationServiceV2 struct {
type FlagEvaluationService struct {
logger *logger.Logger
eval evaluator.IEvaluator
metrics *telemetry.MetricsRecorder
eventingConfiguration *eventingConfiguration
flagEvalTracer trace.Tracer
}

// NewFlagEvaluationServiceV2 creates a FlagEvaluationService with provided parameters
func NewFlagEvaluationServiceV2(log *logger.Logger,
// NewFlagEvaluationService creates a FlagEvaluationService with provided parameters
func NewFlagEvaluationService(log *logger.Logger,
eval evaluator.IEvaluator,
eventingCfg *eventingConfiguration,
metricsRecorder *telemetry.MetricsRecorder,
) *FlagEvaluationServiceV2 {
return &FlagEvaluationServiceV2{
) *FlagEvaluationService {
return &FlagEvaluationService{
logger: log,
eval: eval,
metrics: metricsRecorder,
Expand All @@ -43,7 +43,7 @@ func NewFlagEvaluationServiceV2(log *logger.Logger,
}

// nolint:dupl,funlen
func (s *FlagEvaluationServiceV2) ResolveAll(
func (s *FlagEvaluationService) ResolveAll(
ctx context.Context,
req *connect.Request[evalV1.ResolveAllRequest],
) (*connect.Response[evalV1.ResolveAllResponse], error) {
Expand Down Expand Up @@ -110,7 +110,7 @@ func (s *FlagEvaluationServiceV2) ResolveAll(
return connect.NewResponse(res), nil
}

func (s *FlagEvaluationServiceV2) EventStream(
func (s *FlagEvaluationService) EventStream(
ctx context.Context,
req *connect.Request[evalV1.EventStreamRequest],
stream *connect.ServerStream[evalV1.EventStreamResponse],
Expand Down Expand Up @@ -149,7 +149,7 @@ func (s *FlagEvaluationServiceV2) EventStream(
}
}

func (s *FlagEvaluationServiceV2) ResolveBoolean(
func (s *FlagEvaluationService) ResolveBoolean(
ctx context.Context,
req *connect.Request[evalV1.ResolveBooleanRequest],
) (*connect.Response[evalV1.ResolveBooleanResponse], error) {
Expand All @@ -173,7 +173,7 @@ func (s *FlagEvaluationServiceV2) ResolveBoolean(
return res, err
}

func (s *FlagEvaluationServiceV2) ResolveString(
func (s *FlagEvaluationService) ResolveString(
ctx context.Context,
req *connect.Request[evalV1.ResolveStringRequest],
) (*connect.Response[evalV1.ResolveStringResponse], error) {
Expand All @@ -198,7 +198,7 @@ func (s *FlagEvaluationServiceV2) ResolveString(
return res, err
}

func (s *FlagEvaluationServiceV2) ResolveInt(
func (s *FlagEvaluationService) ResolveInt(
ctx context.Context,
req *connect.Request[evalV1.ResolveIntRequest],
) (*connect.Response[evalV1.ResolveIntResponse], error) {
Expand All @@ -223,7 +223,7 @@ func (s *FlagEvaluationServiceV2) ResolveInt(
return res, err
}

func (s *FlagEvaluationServiceV2) ResolveFloat(
func (s *FlagEvaluationService) ResolveFloat(
ctx context.Context,
req *connect.Request[evalV1.ResolveFloatRequest],
) (*connect.Response[evalV1.ResolveFloatResponse], error) {
Expand All @@ -248,7 +248,7 @@ func (s *FlagEvaluationServiceV2) ResolveFloat(
return res, err
}

func (s *FlagEvaluationServiceV2) ResolveObject(
func (s *FlagEvaluationService) ResolveObject(
ctx context.Context,
req *connect.Request[evalV1.ResolveObjectRequest],
) (*connect.Response[evalV1.ResolveObjectResponse], error) {
Expand Down
Loading

0 comments on commit 735a94a

Please sign in to comment.