From a47515300a5cfac667eca1ca8e8d1a71e590b7d2 Mon Sep 17 00:00:00 2001 From: Dylan Guedes Date: Thu, 19 Sep 2024 12:10:36 -0300 Subject: [PATCH 1/2] fix: Report PSRL error message correctly (#14187) **What this PR does / why we need it**: Modify our `validateEntries` code to report a log failure when a PSRL is identified. --- pkg/ingester/stream.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/ingester/stream.go b/pkg/ingester/stream.go index fe4a644c71109..d1577b1d2fffe 100644 --- a/pkg/ingester/stream.go +++ b/pkg/ingester/stream.go @@ -454,6 +454,9 @@ func (s *stream) validateEntries(ctx context.Context, entries []logproto.Entry, failedEntriesWithError = append(failedEntriesWithError, entryWithError{&toStore[i], &validation.ErrStreamRateLimit{RateLimit: flagext.ByteSize(limit), Labels: s.labelsString, Bytes: flagext.ByteSize(len(toStore[i].Line))}}) rateLimitedBytes += len(toStore[i].Line) } + + // Log the only last error to the write failures manager. + s.writeFailures.Log(s.tenant, failedEntriesWithError[len(failedEntriesWithError)-1].e) } s.streamRateCalculator.Record(s.tenant, s.labelHash, s.labelHashNoShard, totalBytes) From 900751c3bb008c50441c47eef3927a27201b1a11 Mon Sep 17 00:00:00 2001 From: Ashwanth Date: Thu, 19 Sep 2024 21:11:58 +0530 Subject: [PATCH 2/2] fix: report correct status code for metric and log queries in metrics.go (#12102) --- pkg/logql/engine.go | 1 - pkg/querier/http.go | 30 +++++------------------------- pkg/util/server/error.go | 4 ++++ 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/pkg/logql/engine.go b/pkg/logql/engine.go index 23c3073fb7284..c44ee06c16948 100644 --- a/pkg/logql/engine.go +++ b/pkg/logql/engine.go @@ -265,7 +265,6 @@ func (q *query) Exec(ctx context.Context) (logqlmodel.Result, error) { sp.LogKV(statResult.KVList()...) status, _ := server.ClientHTTPStatusAndError(err) - if q.record { RecordRangeAndInstantQueryMetrics(ctx, q.logger, q.params, strconv.Itoa(status), statResult, data) } diff --git a/pkg/querier/http.go b/pkg/querier/http.go index 5f0e928b6a1c0..862f9e2a20138 100644 --- a/pkg/querier/http.go +++ b/pkg/querier/http.go @@ -122,11 +122,7 @@ func (q *QuerierAPI) LabelHandler(ctx context.Context, req *logproto.LabelReques sp.LogKV(statResult.KVList()...) } - status := 200 - if err != nil { - status, _ = serverutil.ClientHTTPStatusAndError(err) - } - + status, _ := serverutil.ClientHTTPStatusAndError(err) logql.RecordLabelQueryMetrics(ctx, util_log.Logger, *req.Start, *req.End, req.Name, req.Query, strconv.Itoa(status), statResult) return resp, err @@ -277,11 +273,7 @@ func (q *QuerierAPI) SeriesHandler(ctx context.Context, req *logproto.SeriesRequ sp.LogKV(statResult.KVList()...) } - status := 200 - if err != nil { - status, _ = serverutil.ClientHTTPStatusAndError(err) - } - + status, _ := serverutil.ClientHTTPStatusAndError(err) logql.RecordSeriesQueryMetrics(ctx, util_log.Logger, req.Start, req.End, req.Groups, strconv.Itoa(status), req.GetShards(), statResult) return resp, statResult, err @@ -308,11 +300,7 @@ func (q *QuerierAPI) IndexStatsHandler(ctx context.Context, req *loghttp.RangeQu sp.LogKV(statResult.KVList()...) } - status := 200 - if err != nil { - status, _ = serverutil.ClientHTTPStatusAndError(err) - } - + status, _ := serverutil.ClientHTTPStatusAndError(err) logql.RecordStatsQueryMetrics(ctx, util_log.Logger, req.Start, req.End, req.Query, strconv.Itoa(status), statResult) return resp, err @@ -340,11 +328,7 @@ func (q *QuerierAPI) IndexShardsHandler(ctx context.Context, req *loghttp.RangeQ sp.LogKV(statResult.KVList()...) } - status := 200 - if err != nil { - status, _ = serverutil.ClientHTTPStatusAndError(err) - } - + status, _ := serverutil.ClientHTTPStatusAndError(err) logql.RecordShardsQueryMetrics( ctx, util_log.Logger, req.Start, req.End, req.Query, targetBytesPerShard, strconv.Itoa(status), resLength, statResult, ) @@ -377,11 +361,7 @@ func (q *QuerierAPI) VolumeHandler(ctx context.Context, req *logproto.VolumeRequ sp.LogKV(statResult.KVList()...) } - status := 200 - if err != nil { - status, _ = serverutil.ClientHTTPStatusAndError(err) - } - + status, _ := serverutil.ClientHTTPStatusAndError(err) logql.RecordVolumeQueryMetrics(ctx, util_log.Logger, req.From.Time(), req.Through.Time(), req.GetQuery(), uint32(req.GetLimit()), time.Duration(req.GetStep()), strconv.Itoa(status), statResult) return resp, nil diff --git a/pkg/util/server/error.go b/pkg/util/server/error.go index 8ff7457a605b2..3044a58f61e2d 100644 --- a/pkg/util/server/error.go +++ b/pkg/util/server/error.go @@ -48,6 +48,10 @@ func WriteError(err error, w http.ResponseWriter) { // ClientHTTPStatusAndError returns error and http status that is "safe" to return to client without // exposing any implementation details. func ClientHTTPStatusAndError(err error) (int, error) { + if err == nil { + return http.StatusOK, nil + } + var ( queryErr storage_errors.QueryError promErr promql.ErrStorage