chore: Collect basic stats from dataobj queries (#17111)

pull/17123/head
benclive 1 year ago committed by GitHub
parent d197cdac8d
commit 8e421186df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      pkg/dataobj/querier/iter.go
  2. 5
      pkg/logql/bench/bench_test.go

@ -14,6 +14,7 @@ import (
"github.com/grafana/loki/v3/pkg/logql"
"github.com/grafana/loki/v3/pkg/logql/log"
"github.com/grafana/loki/v3/pkg/logql/syntax"
"github.com/grafana/loki/v3/pkg/logqlmodel/stats"
)
var (
@ -71,6 +72,9 @@ func newEntryIterator(ctx context.Context,
streamHash uint64
top = newTopK(int(req.Limit), req.Direction)
)
statistics := stats.FromContext(ctx)
// For dataobjs, this maps to sections downloaded
statistics.AddChunksDownloaded(1)
for {
n, err := reader.Read(ctx, buf)
@ -94,10 +98,13 @@ func newEntryIterator(ctx context.Context,
}
timestamp := record.Timestamp.UnixNano()
statistics.AddDecompressedLines(1)
line, parsedLabels, ok := streamExtractor.Process(timestamp, record.Line, record.Metadata...)
if !ok {
continue
}
statistics.AddPostFilterLines(1)
var metadata []logproto.LabelAdapter
if len(record.Metadata) > 0 {
metadata = logproto.FromLabelsToLabelAdapters(record.Metadata)
@ -293,6 +300,10 @@ func newSampleIterator(ctx context.Context,
streamHash uint64
)
statistics := stats.FromContext(ctx)
// For dataobjs, this maps to sections downloaded
statistics.AddChunksDownloaded(1)
for {
n, err := reader.Read(ctx, buf)
if err != nil && err != io.EOF {
@ -328,10 +339,12 @@ func newSampleIterator(ctx context.Context,
// TODO(twhitney): when iterating over multiple extractors, we need a way to pre-process as much of the line as possible
// In the case of multi-variant expressions, the only difference between the multiple extractors should be the final value, with all
// other filters and processing already done.
statistics.AddDecompressedLines(1)
value, parsedLabels, ok := streamExtractor.Process(timestamp, record.Line, record.Metadata...)
if !ok {
continue
}
statistics.AddPostFilterLines(1)
// Get or create series for the parsed labels
labelString := parsedLabels.String()

@ -150,8 +150,11 @@ func BenchmarkLogQL(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := q.Exec(ctx)
r, err := q.Exec(ctx)
require.NoError(b, err)
b.ReportMetric(float64(r.Statistics.TotalDecompressedLines()), "linesScanned")
b.ReportMetric(float64(r.Statistics.TotalChunksDownloaded()), "chunks/dataobjSections")
b.ReportMetric(float64(r.Statistics.Summary.TotalPostFilterLines), "postFilterLines")
}
})
}

Loading…
Cancel
Save