Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Fix validation error message for push request
  • Loading branch information
ravishankar15 committed Nov 29, 2024
commit 9ff4612014bc083e20fdf4e5196f833a8429011c
2 changes: 1 addition & 1 deletion pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,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 @@ -629,6 +629,16 @@
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 })

Check warning on line 635 in pkg/distributor/distributor_test.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

unused-parameter: parameter 'addr' seems to be unused, consider removing or renaming it as _ (revive)

_, 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would use the same naming convention as for other error messages

Suggested change
MissingStreams = "error at least one valid stream is required for ingestion"
MissingStreamsErrorMsg = "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
Loading