Skip to content

Commit cfe5926

Browse files
authored
fix(evaluation): add segments to the boolean evaluation response (#4766)
1 parent 6cfab3b commit cfe5926

File tree

16 files changed

+33
-16
lines changed

16 files changed

+33
-16
lines changed

internal/server/evaluation/evaluation.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ func (s *Server) Boolean(ctx context.Context, r *rpcevaluation.EvaluationRequest
319319
tracing.AttributeRequestID.String(r.RequestId),
320320
tracing.AttributeValue.Bool(resp.Enabled),
321321
tracing.AttributeReason.String(resp.Reason.String()),
322+
tracing.AttributeSegments.StringSlice(resp.SegmentKeys),
322323
tracing.AttributeFlagTypeBoolean,
323324
))
324325
}
@@ -359,6 +360,7 @@ func (s *Server) boolean(ctx context.Context, store storage.ReadOnlyStore, env e
359360
metrics.AttributeValue.Bool(resp.Enabled),
360361
metrics.AttributeReason.String(resp.Reason.String()),
361362
metrics.AttributeFlagType.String("boolean"),
363+
metrics.AttributeSegments.StringSlice(resp.SegmentKeys),
362364
),
363365
),
364366
)
@@ -408,7 +410,6 @@ func (s *Server) boolean(ctx context.Context, store storage.ReadOnlyStore, env e
408410
)
409411

410412
for k, v := range rollout.Segment.Segments {
411-
segmentKeys = append(segmentKeys, k)
412413
matched, reason, err := s.matchConstraints(r.Context, v.Constraints, v.MatchType, r.EntityId)
413414
if err != nil {
414415
return nil, err
@@ -417,6 +418,7 @@ func (s *Server) boolean(ctx context.Context, store storage.ReadOnlyStore, env e
417418
// if we don't match the segment, fall through to the next rollout.
418419
if matched {
419420
s.logger.Debug(reason)
421+
segmentKeys = append(segmentKeys, k)
420422
segmentMatches++
421423
}
422424
}
@@ -437,6 +439,7 @@ func (s *Server) boolean(ctx context.Context, store storage.ReadOnlyStore, env e
437439
resp.Enabled = rollout.Segment.Value
438440
resp.Reason = rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON
439441
resp.FlagKey = flag.Key
442+
resp.SegmentKeys = segmentKeys
440443

441444
s.logger.Debug("segment based matched", zap.Int("rank", int(rollout.Rank)), zap.Strings("segments", segmentKeys))
442445
return resp, nil

internal/server/evaluation/evaluation_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ func TestBoolean_PercentageRuleFallthrough_SegmentMatch(t *testing.T) {
505505
assert.True(t, res.Enabled)
506506
assert.Equal(t, rpcevaluation.EvaluationReason_MATCH_EVALUATION_REASON, res.Reason)
507507
assert.Equal(t, flagKey, res.FlagKey)
508+
assert.Equal(t, []string{"test-segment"}, res.SegmentKeys)
508509
}
509510

510511
func TestBoolean_SegmentMatch_MultipleConstraints(t *testing.T) {
@@ -1172,7 +1173,6 @@ func Test_matchesString(t *testing.T) {
11721173
wantMatch: true,
11731174
},
11741175
{
1175-
11761176
name: "contains",
11771177
constraint: storage.EvaluationConstraint{
11781178
Property: "foo",
@@ -1183,7 +1183,6 @@ func Test_matchesString(t *testing.T) {
11831183
wantMatch: true,
11841184
},
11851185
{
1186-
11871186
name: "negative contains",
11881187
constraint: storage.EvaluationConstraint{
11891188
Property: "foo",

internal/server/evaluation/ofrep_bridge.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ func (s *Server) OFREPFlagEvaluation(ctx context.Context, r *ofrep.EvaluateFlagR
129129
tracing.AttributeFlag.String(r.Key),
130130
tracing.AttributeValue.Bool(resp.Enabled),
131131
tracing.AttributeReason.String(resp.Reason.String()),
132+
tracing.AttributeSegments.StringSlice(resp.SegmentKeys),
132133
tracing.AttributeFlagTypeBoolean,
133134
))
134135
}

rpc/flipt/audit/event.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/flipt/auth/auth.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/flipt/core/core.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/flipt/evaluation/evaluation.pb.go

Lines changed: 12 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/flipt/evaluation/evaluation.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ message BooleanEvaluationResponse {
6565
double request_duration_millis = 4;
6666
google.protobuf.Timestamp timestamp = 5;
6767
string flag_key = 6;
68+
repeated string segment_keys = 7;
6869
}
6970

7071
message VariantEvaluationResponse {

rpc/flipt/flipt.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/flipt/meta/meta.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)