Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/flipt-io/flipt:
  feat: add flag key to variant and boolean evaluation responses (#2318)
  chore(deps): bump github.com/aws/aws-sdk-go-v2/config (#2310)
  chore(deps): bump github.com/redis/go-redis/v9 from 9.2.0 to 9.2.1 (#2309)
  • Loading branch information
markphelps committed Oct 31, 2023
2 parents b118498 + e88e939 commit 3591c7c
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 84 deletions.
8 changes: 8 additions & 0 deletions build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au

require.True(t, result.Match, "Evaluation should have matched.")
assert.Contains(t, result.SegmentKeys, "everyone")
assert.Equal(t, "test", result.FlagKey)
assert.Equal(t, "one", result.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
})
Expand All @@ -974,6 +975,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.True(t, result.Match, "Evaluation should have matched.")
assert.Contains(t, result.SegmentKeys, "segment")
assert.Contains(t, result.SegmentKeys, "another-segment")
assert.Equal(t, "test", result.FlagKey)
assert.Equal(t, "two", result.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
})
Expand All @@ -991,6 +993,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au

assert.False(t, result.Match, "Evaluation should not have matched.")
assert.Equal(t, evaluation.EvaluationReason_UNKNOWN_EVALUATION_REASON, result.Reason)
assert.Equal(t, "test", result.FlagKey)
assert.Empty(t, result.VariantKey)
})

Expand All @@ -1005,6 +1008,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au

assert.False(t, result.Match, "Evaluation should not have matched.")
assert.Equal(t, evaluation.EvaluationReason_FLAG_DISABLED_EVALUATION_REASON, result.Reason)
assert.Equal(t, "disabled", result.FlagKey)
assert.Empty(t, result.VariantKey)
})

Expand Down Expand Up @@ -1120,6 +1124,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_DEFAULT_EVALUATION_REASON, result.Reason)
assert.Equal(t, "boolean_disabled", result.FlagKey)
assert.False(t, result.Enabled, "value should be the flag state")
})

Expand All @@ -1136,6 +1141,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "boolean_disabled", result.FlagKey)
assert.False(t, result.Enabled, "value should be threshold match value")
})

Expand All @@ -1153,6 +1159,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "boolean_disabled", result.FlagKey)
assert.True(t, result.Enabled, "value should be segment match value")
})

Expand All @@ -1170,6 +1177,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "boolean_disabled", result.FlagKey)
assert.False(t, result.Enabled, "value should be segment match value")
})
})
Expand Down
9 changes: 9 additions & 0 deletions build/testing/integration/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, true, response.Match)
assert.Equal(t, "flag_001", response.FlagKey)
assert.Equal(t, "variant_002", response.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
assert.Contains(t, response.SegmentKeys, "segment_005")
Expand All @@ -459,6 +460,7 @@ func TestReadOnly(t *testing.T) {

assert.Equal(t, true, response.Match)
assert.Equal(t, "variant_002", response.VariantKey)
assert.Equal(t, "flag_variant_and_segments", response.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, response.Reason)
assert.Contains(t, response.SegmentKeys, "segment_001")
assert.Contains(t, response.SegmentKeys, "segment_anding")
Expand Down Expand Up @@ -520,6 +522,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_DEFAULT_EVALUATION_REASON, result.Reason)
assert.Equal(t, "flag_boolean", result.FlagKey)
assert.False(t, result.Enabled, "default flag value should be false")
})

Expand All @@ -534,6 +537,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "flag_boolean", result.FlagKey)
assert.True(t, result.Enabled, "boolean evaluation value should be true")
})

Expand All @@ -550,6 +554,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "flag_boolean", result.FlagKey)
assert.True(t, result.Enabled, "segment evaluation value should be true")
})

Expand All @@ -562,6 +567,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "flag_boolean_no_constraints", result.FlagKey)
assert.True(t, result.Enabled, "segment evaluation value should be true")
})

Expand All @@ -577,6 +583,7 @@ func TestReadOnly(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
assert.Equal(t, "flag_boolean_and_segments", result.FlagKey)
assert.True(t, result.Enabled, "segment evaluation value should be true")
})
})
Expand Down Expand Up @@ -613,6 +620,7 @@ func TestReadOnly(t *testing.T) {
b, ok := result.Responses[0].Response.(*evaluation.EvaluationResponse_BooleanResponse)
assert.True(t, ok, "response should be boolean evaluation response")
assert.True(t, b.BooleanResponse.Enabled, "boolean response should have true value")
assert.Equal(t, "flag_boolean", b.BooleanResponse.FlagKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, b.BooleanResponse.Reason)
assert.Equal(t, evaluation.EvaluationResponseType_BOOLEAN_EVALUATION_RESPONSE_TYPE, result.Responses[0].Type)

Expand All @@ -627,6 +635,7 @@ func TestReadOnly(t *testing.T) {
assert.True(t, v.VariantResponse.Match, "variant response match should have true value")
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, v.VariantResponse.Reason)
assert.Equal(t, "variant_002", v.VariantResponse.VariantKey)
assert.Equal(t, "flag_001", v.VariantResponse.FlagKey)
assert.Contains(t, v.VariantResponse.SegmentKeys, "segment_005")
assert.Equal(t, evaluation.EvaluationResponseType_VARIANT_EVALUATION_RESPONSE_TYPE, result.Responses[2].Type)
})
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/Masterminds/squirrel v1.5.4
github.com/XSAM/otelsql v0.26.0
github.com/aws/aws-sdk-go-v2 v1.21.2
github.com/aws/aws-sdk-go-v2/config v1.19.0
github.com/aws/aws-sdk-go-v2/config v1.19.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2
github.com/blang/semver/v4 v4.0.0
github.com/cenkalti/backoff/v4 v4.2.1
Expand Down Expand Up @@ -41,7 +41,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/prometheus/client_golang v1.17.0
github.com/redis/go-redis/v9 v9.2.0
github.com/redis/go-redis/v9 v9.2.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ github.com/aws/aws-sdk-go-v2 v1.21.2 h1:+LXZ0sgo8quN9UOKXXzAWRT3FWd4NxeXWOZom9pE
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 h1:Sc82v7tDQ/vdU1WtuSyzZ1I7y/68j//HJ6uozND1IDs=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14/go.mod h1:9NCTOURS8OpxvoAVHq79LK81/zC78hfRWFn+aL0SPcY=
github.com/aws/aws-sdk-go-v2/config v1.19.0 h1:AdzDvwH6dWuVARCl3RTLGRc4Ogy+N7yLFxVxXe1ClQ0=
github.com/aws/aws-sdk-go-v2/config v1.19.0/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
github.com/aws/aws-sdk-go-v2/config v1.19.1 h1:oe3vqcGftyk40icfLymhhhNysAwk0NfiwkDi2GTPMXs=
github.com/aws/aws-sdk-go-v2/config v1.19.1/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ=
Expand Down Expand Up @@ -615,8 +615,8 @@ github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/redis/go-redis/v9 v9.0.0-rc.4/go.mod h1:Vo3EsyWnicKnSKCA7HhgnvnyA74wOA69Cd2Meli5mmA=
github.com/redis/go-redis/v9 v9.2.0 h1:zwMdX0A4eVzse46YN18QhuDiM4uf3JmkOB4VZrdt5uI=
github.com/redis/go-redis/v9 v9.2.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
Expand Down
4 changes: 4 additions & 0 deletions internal/server/evaluation/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (s *Server) variant(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
Reason: reason,
VariantKey: resp.Value,
VariantAttachment: resp.Attachment,
FlagKey: resp.FlagKey,
}

if len(resp.SegmentKeys) > 0 {
Expand Down Expand Up @@ -192,6 +193,7 @@ func (s *Server) boolean(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
if normalizedValue < rollout.Threshold.Percentage {
resp.Enabled = rollout.Threshold.Value
resp.Reason = rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON
resp.FlagKey = flag.Key
s.logger.Debug("threshold based matched", zap.Int("rank", int(rollout.Rank)), zap.String("rollout_type", "threshold"))
return resp, nil
}
Expand Down Expand Up @@ -231,6 +233,7 @@ func (s *Server) boolean(ctx context.Context, flag *flipt.Flag, r *rpcevaluation

resp.Enabled = rollout.Segment.Value
resp.Reason = rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON
resp.FlagKey = flag.Key

s.logger.Debug("segment based matched", zap.Int("rank", int(rollout.Rank)), zap.Strings("segments", segmentKeys))
return resp, nil
Expand All @@ -240,6 +243,7 @@ func (s *Server) boolean(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
// If we have exhausted all rollouts and we still don't have a match, return flag enabled value.
resp.Reason = rpcevaluation.EvaluationReason_DEFAULT_EVALUATION_REASON
resp.Enabled = flag.Enabled
resp.FlagKey = flag.Key

s.logger.Debug("default rollout matched", zap.Bool("enabled", flag.Enabled))
return resp, nil
Expand Down
8 changes: 8 additions & 0 deletions internal/server/evaluation/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func TestBoolean_DefaultRule_NoRollouts(t *testing.T) {

assert.Equal(t, true, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_DEFAULT_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_DefaultRuleFallthrough_WithPercentageRollout(t *testing.T) {
Expand Down Expand Up @@ -323,6 +324,7 @@ func TestBoolean_DefaultRuleFallthrough_WithPercentageRollout(t *testing.T) {

assert.Equal(t, true, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_DEFAULT_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_PercentageRuleMatch(t *testing.T) {
Expand Down Expand Up @@ -366,6 +368,7 @@ func TestBoolean_PercentageRuleMatch(t *testing.T) {

assert.Equal(t, false, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_PercentageRuleFallthrough_SegmentMatch(t *testing.T) {
Expand Down Expand Up @@ -432,6 +435,7 @@ func TestBoolean_PercentageRuleFallthrough_SegmentMatch(t *testing.T) {

assert.Equal(t, true, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_SegmentMatch_MultipleConstraints(t *testing.T) {
Expand Down Expand Up @@ -496,6 +500,7 @@ func TestBoolean_SegmentMatch_MultipleConstraints(t *testing.T) {

assert.Equal(t, true, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_SegmentMatch_MultipleSegments_WithAnd(t *testing.T) {
Expand Down Expand Up @@ -567,6 +572,7 @@ func TestBoolean_SegmentMatch_MultipleSegments_WithAnd(t *testing.T) {

assert.Equal(t, true, res.Enabled)
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
assert.Equal(t, flagKey, res.FlagKey)
}

func TestBoolean_RulesOutOfOrder(t *testing.T) {
Expand Down Expand Up @@ -807,6 +813,7 @@ func TestBatch_Success(t *testing.T) {
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, b.BooleanResponse.Reason)
assert.Equal(t, rpcevaluation.EvaluationResponseType_BOOLEAN_EVALUATION_RESPONSE_TYPE, res.Responses[0].Type)
assert.Equal(t, "1", b.BooleanResponse.RequestId)
assert.Equal(t, flagKey, b.BooleanResponse.FlagKey)

e, ok := res.Responses[1].Response.(*rpcevaluation.EvaluationResponse_ErrorResponse)
assert.True(t, ok, "response should be a error evaluation response")
Expand All @@ -822,4 +829,5 @@ func TestBatch_Success(t *testing.T) {
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, v.VariantResponse.Reason)
assert.Equal(t, rpcevaluation.EvaluationResponseType_VARIANT_EVALUATION_RESPONSE_TYPE, res.Responses[2].Type)
assert.Equal(t, "3", v.VariantResponse.RequestId)
assert.Equal(t, variantFlagKey, v.VariantResponse.FlagKey)
}
Loading

0 comments on commit 3591c7c

Please sign in to comment.