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

chore: change to segmentKeys for future proofing #1918

Merged
merged 10 commits into from
Jul 28, 2023
8 changes: 4 additions & 4 deletions build/testing/integration/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
require.NoError(t, err)

require.True(t, result.Match, "Evaluation should have matched.")
assert.Equal(t, "everyone", result.SegmentKey)
assert.Contains(t, result.SegmentKeys, "everyone")
assert.Equal(t, "one", result.VariantKey)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, result.Reason)
})
Expand All @@ -809,7 +809,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.Empty(t, result.SegmentKey)
assert.Empty(t, result.SegmentKeys)
assert.Empty(t, result.VariantKey)
})

Expand All @@ -824,7 +824,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.Empty(t, result.SegmentKey)
assert.Empty(t, result.SegmentKeys)
assert.Empty(t, result.VariantKey)
})

Expand Down Expand Up @@ -941,7 +941,7 @@ func API(t *testing.T, ctx context.Context, client sdk.SDK, namespace string, au
assert.True(t, ok, "value should be variant response")
assert.Equal(t, evaluation.EvaluationResponseType_VARIANT_EVALUATION_RESPONSE_TYPE, result.Responses[1].Type)
assert.Equal(t, evaluation.EvaluationReason_MATCH_EVALUATION_REASON, v.VariantResponse.Reason)
assert.Equal(t, "everyone", v.VariantResponse.SegmentKey)
assert.Contains(t, v.VariantResponse.SegmentKeys, "everyone")
assert.Equal(t, "one", v.VariantResponse.VariantKey)

e, ok := result.Responses[2].Response.(*evaluation.EvaluationResponse_ErrorResponse)
Expand Down
4 changes: 2 additions & 2 deletions build/testing/integration/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func TestReadOnly(t *testing.T) {

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

Expand Down Expand Up @@ -592,7 +592,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, "segment_005", v.VariantResponse.SegmentKey)
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 internal/server/evaluation/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (s *Server) Variant(ctx context.Context, r *rpcevaluation.EvaluationRequest
fliptotel.AttributeMatch.Bool(resp.Match),
fliptotel.AttributeValue.String(resp.VariantKey),
fliptotel.AttributeReason.String(resp.Reason.String()),
fliptotel.AttributeSegment.String(resp.SegmentKey),
fliptotel.AttributeSegments.StringSlice(resp.SegmentKeys),
}

// add otel attributes to span
Expand Down Expand Up @@ -77,7 +77,7 @@ func (s *Server) variant(ctx context.Context, flag *flipt.Flag, r *rpcevaluation

ver := &rpcevaluation.VariantEvaluationResponse{
Match: resp.Match,
SegmentKey: resp.SegmentKey,
SegmentKeys: []string{resp.SegmentKey},
Reason: reason,
VariantKey: resp.Value,
VariantAttachment: resp.Attachment,
Expand Down
4 changes: 2 additions & 2 deletions internal/server/evaluation/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestVariant_Success(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, true, res.Match)
assert.Equal(t, "bar", res.SegmentKey)
assert.Contains(t, res.SegmentKeys, "bar")
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
}

Expand Down Expand Up @@ -719,7 +719,7 @@ func TestBatch_Success(t *testing.T) {
v, ok := res.Responses[2].Response.(*rpcevaluation.EvaluationResponse_VariantResponse)
assert.True(t, ok, "response should be a variant evaluation response")
assert.True(t, v.VariantResponse.Match, "variant response should have matched")
assert.Equal(t, "bar", v.VariantResponse.SegmentKey)
assert.Contains(t, "bar", v.VariantResponse.SegmentKeys)
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, v.VariantResponse.Reason)
assert.Equal(t, rpcevaluation.EvaluationResponseType_VARIANT_EVALUATION_RESPONSE_TYPE, res.Responses[2].Type)
}
4 changes: 2 additions & 2 deletions internal/server/middleware/grpc/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,12 @@ func TestCacheUnaryInterceptor_Evaluation_Variant(t *testing.T) {

if !wantMatch {
assert.False(t, resp.Match)
assert.Empty(t, resp.SegmentKey)
assert.Empty(t, resp.SegmentKeys)
return
}

assert.True(t, resp.Match)
assert.Equal(t, "bar", resp.SegmentKey)
assert.Contains(t, resp.SegmentKeys, "bar")
assert.Equal(t, "boz", resp.VariantKey)
assert.Equal(t, `{"key":"value"}`, resp.VariantAttachment)
})
Expand Down
1 change: 1 addition & 0 deletions internal/server/otel/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var (
AttributeNamespace = attribute.Key("flipt.namespace")
AttributeFlagEnabled = attribute.Key("flipt.flag_enabled")
AttributeSegment = attribute.Key("flipt.segment")
AttributeSegments = attribute.Key("flipt.segments")
AttributeReason = attribute.Key("flipt.reason")
AttributeValue = attribute.Key("flipt.value")
AttributeEntityID = attribute.Key("flipt.entity_id")
Expand Down
Loading
Loading