Skip to content

Commit

Permalink
feat: add requestID to batch response (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
markphelps authored Sep 29, 2023
1 parent 03373d7 commit 195ec9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/server/evaluation/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (s *Server) variant(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
}

ver := &rpcevaluation.VariantEvaluationResponse{
RequestId: r.RequestId,
Match: resp.Match,
Reason: reason,
VariantKey: resp.Value,
Expand Down Expand Up @@ -131,7 +132,9 @@ func (s *Server) boolean(ctx context.Context, flag *flipt.Flag, r *rpcevaluation
}

var (
resp = &rpcevaluation.BooleanEvaluationResponse{}
resp = &rpcevaluation.BooleanEvaluationResponse{
RequestId: r.RequestId,
}
lastRank int32
)

Expand Down
5 changes: 5 additions & 0 deletions internal/server/evaluation/evaluation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ func TestBatch_Success(t *testing.T) {
res, err := s.Batch(context.TODO(), &rpcevaluation.BatchEvaluationRequest{
Requests: []*rpcevaluation.EvaluationRequest{
{
RequestId: "1",
FlagKey: flagKey,
EntityId: "test-entity",
NamespaceKey: namespaceKey,
Expand All @@ -776,6 +777,7 @@ func TestBatch_Success(t *testing.T) {
},
},
{
RequestId: "2",
FlagKey: anotherFlagKey,
EntityId: "test-entity",
NamespaceKey: namespaceKey,
Expand All @@ -784,6 +786,7 @@ func TestBatch_Success(t *testing.T) {
},
},
{
RequestId: "3",
FlagKey: variantFlagKey,
EntityId: "test-entity",
NamespaceKey: namespaceKey,
Expand All @@ -803,6 +806,7 @@ func TestBatch_Success(t *testing.T) {
assert.True(t, b.BooleanResponse.Enabled, "value should be true from match")
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)

e, ok := res.Responses[1].Response.(*rpcevaluation.EvaluationResponse_ErrorResponse)
assert.True(t, ok, "response should be a error evaluation response")
Expand All @@ -817,4 +821,5 @@ func TestBatch_Success(t *testing.T) {
assert.Contains(t, v.VariantResponse.SegmentKeys, "bar")
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)
}

0 comments on commit 195ec9e

Please sign in to comment.