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

FFM-3703 - Go FF SDK Broken by Kin API Changes #90

Merged
merged 5 commits into from
Jun 24, 2022
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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ endif
all: tidy generate build check test

generate:
oapi-codegen -generate client,spec -package=rest ./resources/client-v1.yaml > rest/services.gen.go
oapi-codegen -generate types -package=rest ./resources/client-v1.yaml > rest/types.gen.go
oapi-codegen -generate client -package=metricsclient ./resources/metrics-v1.yaml > metricsclient/services.gen.go
oapi-codegen -generate types -package=metricsclient ./resources/metrics-v1.yaml > metricsclient/types.gen.go
oapi-codegen --config ./resources/config/rest-client-config.yaml ./resources/client-v1.yaml > rest/services.gen.go
oapi-codegen --config ./resources/config/rest-types-config.yaml ./resources/client-v1.yaml > rest/types.gen.go
oapi-codegen --config ./resources/config/metrics-client-config.yaml ./resources/metrics-v1.yaml > metricsclient/services.gen.go
oapi-codegen --config ./resources/config/metrics-types-config.yaml ./resources/metrics-v1.yaml > metricsclient/types.gen.go

tidy:
go mod tidy
Expand Down Expand Up @@ -95,7 +95,7 @@ $(GOPATH)/bin/gosec:

$(GOPATH)/bin/oapi-codegen:
@echo "🔘 Installing oapicodegen ... (`date '+%H:%M:%S'`)"
@go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.6.0
@go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v1.11.0

PHONY+= tools
tools: $(GOPATH)/bin/golangci-lint $(GOPATH)/bin/golint $(GOPATH)/bin/gosec $(GOPATH)/bin/goimports $(GOPATH)/bin/oapi-codegen
Expand Down
2 changes: 1 addition & 1 deletion analyticsservice/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (as *AnalyticsService) sendDataAndResetCache(ctx context.Context) {
md := metricsclient.MetricsData{
Timestamp: time.Now().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)),
Count: analytic.count,
MetricsType: ffMetricType,
MetricsType: metricsclient.MetricsDataMetricsType(ffMetricType),
Attributes: metricAttributes,
}
metricData = append(metricData, md)
Expand Down
5 changes: 2 additions & 3 deletions evaluation/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (e Evaluator) evaluateVariationMap(variationsMap []rest.VariationMap, targe

func (e Evaluator) evaluateFlag(fc rest.FeatureConfig, target *Target) (rest.Variation, error) {
var variation = fc.OffVariation
if fc.State == rest.FeatureState_on {
if fc.State == rest.FeatureStateOn {
variation = ""
if fc.VariationToTargetMap != nil {
variation = e.evaluateVariationMap(*fc.VariationToTargetMap, target)
Expand Down Expand Up @@ -321,8 +321,7 @@ func (e Evaluator) evaluate(identifier string, target *Target, kind string) (res
if err != nil {
return rest.Variation{}, err
}

if flag.Kind != kind {
if string(flag.Kind) != kind {
jcox250 marked this conversation as resolved.
Show resolved Hide resolved
return rest.Variation{}, fmt.Errorf("%w, expected: %s, got: %s", ErrFlagKindMismatch, kind, flag.Kind)
}

Expand Down
42 changes: 21 additions & 21 deletions evaluation/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var (
map[string]rest.FeatureConfig{
simple: {
Feature: simple,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &identifierTrue,
},
Expand All @@ -113,7 +113,7 @@ var (
},
theme: {
Feature: theme,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &lighttheme,
},
Expand All @@ -122,7 +122,7 @@ var (
},
size: {
Feature: size,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &mediumSize,
},
Expand All @@ -131,7 +131,7 @@ var (
},
weight: {
Feature: weight,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &heavyWeight,
},
Expand All @@ -140,7 +140,7 @@ var (
},
org: {
Feature: org,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &json2,
},
Expand All @@ -149,7 +149,7 @@ var (
},
invalidInt: {
Feature: invalidInt,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &invalidIntValue,
},
Expand All @@ -163,7 +163,7 @@ var (
},
invalidNumber: {
Feature: invalidNumber,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &invalidNumberValue,
},
Expand All @@ -177,7 +177,7 @@ var (
},
invalidJSON: {
Feature: invalidJSON,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &invalidNumberValue,
},
Expand All @@ -191,7 +191,7 @@ var (
},
simpleWithPrereq: {
Feature: simpleWithPrereq,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &identifierTrue,
},
Expand All @@ -206,7 +206,7 @@ var (
},
prereqNotFound: {
Feature: prereqNotFound,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &identifierTrue,
},
Expand All @@ -222,7 +222,7 @@ var (
prereqVarNotFound: {
Feature: prereqVarNotFound,
OffVariation: offVariation,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &identifierTrue,
},
Expand All @@ -237,7 +237,7 @@ var (
},
notValidFlag: {
Feature: notValidFlag,
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
DefaultServe: rest.Serve{
Variation: &empty,
},
Expand Down Expand Up @@ -952,7 +952,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
args: args{
fc: rest.FeatureConfig{
OffVariation: offVariation,
State: rest.FeatureState_off,
State: rest.FeatureStateOff,
Variations: boolVariations,
},
},
Expand All @@ -964,7 +964,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
args: args{
fc: rest.FeatureConfig{
OffVariation: offVariation,
State: rest.FeatureState_off,
State: rest.FeatureStateOff,
Variations: boolVariations,
},
target: &Target{
Expand All @@ -978,7 +978,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
name: "evaluate flag should return default serve variation",
args: args{
fc: rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Variations: boolVariations,
DefaultServe: rest.Serve{
Variation: &boolVariations[0].Value,
Expand All @@ -995,7 +995,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
name: "evaluate flag should return default serve distribution",
args: args{
fc: rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Variations: boolVariations,
DefaultServe: rest.Serve{
Distribution: &rest.Distribution{
Expand Down Expand Up @@ -1023,7 +1023,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
name: "evaluate flag should return rule serve",
args: args{
fc: rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Variations: boolVariations,
Rules: &[]rest.ServingRule{
{
Expand Down Expand Up @@ -1051,7 +1051,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
name: "evaluate flag using variationMap and target should return 'true'",
args: args{
fc: rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Variations: boolVariations,
VariationToTargetMap: &[]rest.VariationMap{
{
Expand All @@ -1075,7 +1075,7 @@ func TestEvaluator_evaluateFlag(t *testing.T) {
name: "evaluate flag variation returns an error",
args: args{
fc: rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
},
target: &Target{
Identifier: targetIdentifier,
Expand Down Expand Up @@ -1240,7 +1240,7 @@ func TestEvaluator_checkPreRequisite(t *testing.T) {
},
args: args{
parent: &rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Prerequisites: &[]rest.Prerequisite{
{
Feature: simple,
Expand All @@ -1258,7 +1258,7 @@ func TestEvaluator_checkPreRequisite(t *testing.T) {
},
args: args{
parent: &rest.FeatureConfig{
State: rest.FeatureState_on,
State: rest.FeatureStateOn,
Prerequisites: &[]rest.Prerequisite{
{
Feature: "prereq not found",
Expand Down
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ module github.com/harness/ff-golang-server-sdk
go 1.16

require (
github.com/deepmap/oapi-codegen v1.6.0
github.com/fatih/structtag v1.2.0 // indirect
github.com/getkin/kin-openapi v0.53.0
github.com/golang-jwt/jwt v3.2.1+incompatible
github.com/google/uuid v1.2.0
github.com/deepmap/oapi-codegen v1.11.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be careful when increasing dep versions, this module is used with ff-server so probably it will need some sanity check

github.com/getkin/kin-openapi v0.94.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/uuid v1.3.0
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/hashicorp/golang-lru v0.5.4
github.com/jarcoal/httpmock v1.0.8
github.com/json-iterator/go v1.1.10
github.com/json-iterator/go v1.1.12
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.3
github.com/r3labs/sse v0.0.0-20201126193848-34e640891548
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.5.1
github.com/stretchr/testify v1.7.1
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.16.0
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0
)
Loading