Skip to content

Commit

Permalink
Merge branch 'main' into RN_Loki32
Browse files Browse the repository at this point in the history
  • Loading branch information
JStickler authored Sep 19, 2024
2 parents 8e97006 + 900751c commit 4995dd6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
3 changes: 3 additions & 0 deletions pkg/ingester/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/logql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
30 changes: 5 additions & 25 deletions pkg/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/util/server/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4995dd6

Please sign in to comment.