From fb3023be2ec952bc9cb721198f4d20c193716055 Mon Sep 17 00:00:00 2001 From: Callum Styan Date: Tue, 2 Apr 2024 11:02:00 -0700 Subject: [PATCH] include the stream we failed to create in the stream limit error message Signed-off-by: Callum Styan --- pkg/ingester/ingester_test.go | 3 +++ pkg/ingester/instance.go | 2 +- pkg/validation/validate.go | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/ingester/ingester_test.go b/pkg/ingester/ingester_test.go index bf7922fb61df..94fd5700c680 100644 --- a/pkg/ingester/ingester_test.go +++ b/pkg/ingester/ingester_test.go @@ -405,11 +405,14 @@ func TestIngesterStreamLimitExceeded(t *testing.T) { require.NoError(t, err) req.Streams[0].Labels = `{foo="bar",bar="baz2"}` + // The labels in error messages are sorted lexicographically and cleaned up via Push -> ParseLabels. + expectedLabels, _ := syntax.ParseLabels(req.Streams[0].Labels) _, err = i.Push(ctx, &req) if resp, ok := httpgrpc.HTTPResponseFromError(err); !ok || resp.Code != http.StatusTooManyRequests { t.Fatalf("expected error about exceeding metrics per user, got %v", err) } + require.Contains(t, err.Error(), expectedLabels.String()) } type mockStore struct { diff --git a/pkg/ingester/instance.go b/pkg/ingester/instance.go index e0218c1a4d94..841cb4033466 100644 --- a/pkg/ingester/instance.go +++ b/pkg/ingester/instance.go @@ -303,7 +303,7 @@ func (i *instance) createStream(ctx context.Context, pushReqStream logproto.Stre if i.customStreamsTracker != nil { i.customStreamsTracker.DiscardedBytesAdd(ctx, i.instanceID, validation.StreamLimit, labels, float64(bytes)) } - return nil, httpgrpc.Errorf(http.StatusTooManyRequests, validation.StreamLimitErrorMsg, i.instanceID) + return nil, httpgrpc.Errorf(http.StatusTooManyRequests, validation.StreamLimitErrorMsg, labels, i.instanceID) } fp := i.getHashForLabels(labels) diff --git a/pkg/validation/validate.go b/pkg/validation/validate.go index 4b02505b98e5..0f39ae039cc0 100644 --- a/pkg/validation/validate.go +++ b/pkg/validation/validate.go @@ -28,7 +28,7 @@ const ( // StreamLimit is a reason for discarding lines when we can't create a new stream // because the limit of active streams has been reached. StreamLimit = "stream_limit" - StreamLimitErrorMsg = "Maximum active stream limit exceeded, reduce the number of active streams (reduce labels or reduce label values), or contact your Loki administrator to see if the limit can be increased, user: '%s'" + StreamLimitErrorMsg = "Maximum active stream limit exceeded when trying to create stream %s, reduce the number of active streams (reduce labels or reduce label values), or contact your Loki administrator to see if the limit can be increased, user: '%s'" // StreamRateLimit is a reason for discarding lines when the streams own rate limit is hit // rather than the overall ingestion rate limit. StreamRateLimit = "per_stream_rate_limit"