Skip to content

Commit 9ff4612

Browse files
committed
fix: Fix validation error message for push request
1 parent 990f71c commit 9ff4612

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

‎pkg/distributor/distributor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
429429

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

435435
// First we flatten out the request into a list of samples.

‎pkg/distributor/distributor_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,16 @@ func Test_DiscardEmptyStreamsAfterValidation(t *testing.T) {
629629
topVal := ingester.Peek()
630630
require.Nil(t, topVal)
631631
})
632+
633+
t.Run("it returns unprocessable entity error if the streams is empty", func(t *testing.T) {
634+
limits, ingester := setup()
635+
distributors, _ := prepare(t, 1, 5, limits, func(addr string) (ring_client.PoolClient, error) { return ingester, nil })
636+
637+
_, err := distributors[0].Push(ctx, makeWriteRequestWithLabels(1, 1, []string{}))
638+
require.Equal(t, err, httpgrpc.Errorf(http.StatusUnprocessableEntity, validation.MissingStreams))
639+
topVal := ingester.Peek()
640+
require.Nil(t, topVal)
641+
})
632642
}
633643

634644
func TestStreamShard(t *testing.T) {

‎pkg/validation/validate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import (
1111
)
1212

1313
const (
14-
ReasonLabel = "reason"
14+
ReasonLabel = "reason"
15+
MissingStreams = "error at least one valid stream is required for ingestion"
16+
1517
// InvalidLabels is a reason for discarding log lines which have labels that cannot be parsed.
1618
InvalidLabels = "invalid_labels"
1719
MissingLabels = "missing_labels"

0 commit comments

Comments
 (0)