Skip to content

Commit 6e1e3c9

Browse files
committed
Add chunk stats to a tracing span tag
1 parent 535e052 commit 6e1e3c9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pkg/store/proxy_merge.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ func newLazyRespSet(
333333
l.span.SetTag("processed.chunks", seriesStats.Chunks)
334334
l.span.SetTag("processed.samples", seriesStats.Samples)
335335
l.span.SetTag("processed.bytes", bytesProcessed)
336+
if len(seriesStats.ChunkSt) > 0 {
337+
l.span.SetTag("processed.chunk_stats", seriesStats.ChunkSt)
338+
}
336339
l.span.Finish()
337340
}()
338341

@@ -491,6 +494,7 @@ func newAsyncRespSet(
491494

492495
switch retrievalStrategy {
493496
case LazyRetrieval:
497+
span.SetTag("retrival_strategy", LazyRetrieval)
494498
return newLazyRespSet(
495499
span,
496500
frameTimeout,
@@ -503,6 +507,7 @@ func newAsyncRespSet(
503507
emptyStreamResponses,
504508
), nil
505509
case EagerRetrieval:
510+
span.SetTag("retrival_strategy", EagerRetrieval)
506511
return newEagerRespSet(
507512
span,
508513
frameTimeout,
@@ -596,6 +601,9 @@ func newEagerRespSet(
596601
l.span.SetTag("processed.chunks", seriesStats.Chunks)
597602
l.span.SetTag("processed.samples", seriesStats.Samples)
598603
l.span.SetTag("processed.bytes", bytesProcessed)
604+
if len(seriesStats.ChunkSt) > 0 {
605+
l.span.SetTag("processed.chunk_stats", seriesStats.ChunkSt)
606+
}
599607
l.span.Finish()
600608
ret.wg.Done()
601609
}()

pkg/store/storepb/custom.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,19 @@ func (m *Chunk) XORNumSamples() int {
478478
return 0
479479
}
480480

481+
type ChunkStats struct {
482+
MinTime, MaxTime int64
483+
Samples int
484+
}
485+
481486
type SeriesStatsCounter struct {
482487
lastSeriesHash uint64
483488

484489
Series int
485490
Chunks int
486491
Samples int
487492
Bytes uint64
493+
ChunkSt []ChunkStats
488494
}
489495

490496
func (c *SeriesStatsCounter) CountSeries(seriesLabels []labelpb.ZLabel) {
@@ -499,7 +505,10 @@ func (c *SeriesStatsCounter) Count(r *SeriesResponse) {
499505
if r.GetSeries() != nil {
500506
series := r.GetSeries()
501507
c.CountSeries(series.Labels)
502-
for _, chk := range series.Chunks {
508+
c.ChunkSt = make([]ChunkStats, min(10, len(series.Chunks)))
509+
for ci, chk := range series.Chunks {
510+
// Keep the old value of c.Samples so that the samples in this chunck can be computed
511+
accSamples := c.Samples
503512
if chk.Raw != nil {
504513
c.Chunks++
505514
c.Samples += chk.Raw.XORNumSamples()
@@ -529,6 +538,11 @@ func (c *SeriesStatsCounter) Count(r *SeriesResponse) {
529538
c.Chunks++
530539
c.Samples += chk.Sum.XORNumSamples()
531540
}
541+
if ci < len(c.ChunkSt) {
542+
c.ChunkSt[ci].MinTime = chk.MinTime
543+
c.ChunkSt[ci].MaxTime = chk.MaxTime
544+
c.ChunkSt[ci].Samples = c.Samples - accSamples
545+
}
532546
}
533547
}
534548

0 commit comments

Comments
 (0)