Skip to content

Commit

Permalink
fix: Fix validation error message for push request
Browse files Browse the repository at this point in the history
  • Loading branch information
ravishankar15 committed Aug 25, 2024
1 parent 246a1df commit ed20552
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log

// Return early if request does not contain any streams
if len(req.Streams) == 0 {
return &logproto.PushResponse{}, nil
return &logproto.PushResponse{}, httpgrpc.Errorf(http.StatusUnprocessableEntity, validation.MissingStreams)
}

// First we flatten out the request into a list of samples.
Expand Down
10 changes: 10 additions & 0 deletions pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ func Test_DiscardEmptyStreamsAfterValidation(t *testing.T) {
topVal := ingester.Peek()
require.Nil(t, topVal)
})

t.Run("it returns unprocessable entity error if the streams is empty", func(t *testing.T) {
limits, ingester := setup()
distributors, _ := prepare(t, 1, 5, limits, func(addr string) (ring_client.PoolClient, error) { return ingester, nil })

_, err := distributors[0].Push(ctx, makeWriteRequestWithLabels(1, 1, []string{}))
require.Equal(t, err, httpgrpc.Errorf(http.StatusUnprocessableEntity, validation.MissingStreams))
topVal := ingester.Peek()
require.Nil(t, topVal)
})
}

func TestStreamShard(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import (
)

const (
ReasonLabel = "reason"
ReasonLabel = "reason"
MissingStreams = "error at least one valid stream is required for ingestion"

// InvalidLabels is a reason for discarding log lines which have labels that cannot be parsed.
InvalidLabels = "invalid_labels"
MissingLabels = "missing_labels"
Expand Down

0 comments on commit ed20552

Please sign in to comment.