-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bloom-gw): Add
metrics.go
style log line to bloom gateway `Fil…
…terChunks` call (#12354) This PR adds a "metrics.go" style log line to the bloom gateway that contains latencies for queueing, processing, post-processing, as well as number of chunks/series requested/filtered. This log line should give operators a better understanding where time is spent for individual requests. Example log line: ``` ts=2024-03-26T13:16:11.869619964Z caller=spanlogger.go:109 component=bloom-gateway tenant=XXX method=bloomgateway.FilterChunkRefs user=XXX traceID=6239d49e1e88f88645bd7f1f6f1b85c8 level=info status=success tasks=1 series_requested=35 series_filtered=31 chunks_requested=103 chunks_filtered=93 queue_time=4.108128936s metas_fetch_time=22.040408ms blocks_fetch_time=1.284575ms processing_time=30.215863002s post_processing_time=16.084µs ``` Signed-off-by: Christian Haudum <christian.haudum@gmail.com>
- Loading branch information
Showing
4 changed files
with
149 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package bloomgateway | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.uber.org/atomic" | ||
) | ||
|
||
type Stats struct { | ||
Status string | ||
NumTasks, NumFilters int | ||
ChunksRequested, ChunksFiltered, SeriesRequested, SeriesFiltered int | ||
QueueTime, MetasFetchTime, BlocksFetchTime, ProcessingTime, PostProcessingTime atomic.Duration | ||
} | ||
|
||
type statsKey int | ||
|
||
var ctxKey = statsKey(0) | ||
|
||
// ContextWithEmptyStats returns a context with empty stats. | ||
func ContextWithEmptyStats(ctx context.Context) (*Stats, context.Context) { | ||
stats := &Stats{Status: "unknown"} | ||
ctx = context.WithValue(ctx, ctxKey, stats) | ||
return stats, ctx | ||
} | ||
|
||
// FromContext gets the Stats out of the Context. Returns nil if stats have not | ||
// been initialised in the context. | ||
func FromContext(ctx context.Context) *Stats { | ||
o := ctx.Value(ctxKey) | ||
if o == nil { | ||
return nil | ||
} | ||
return o.(*Stats) | ||
} | ||
|
||
func (s *Stats) KVArgs() []any { | ||
if s == nil { | ||
return []any{} | ||
} | ||
return []any{ | ||
"status", s.Status, | ||
"tasks", s.NumTasks, | ||
"series_requested", s.SeriesRequested, | ||
"series_filtered", s.SeriesFiltered, | ||
"chunks_requested", s.ChunksRequested, | ||
"chunks_filtered", s.ChunksFiltered, | ||
"queue_time", s.QueueTime.Load(), | ||
"metas_fetch_time", s.MetasFetchTime.Load(), | ||
"blocks_fetch_time", s.BlocksFetchTime.Load(), | ||
"processing_time", s.ProcessingTime.Load(), | ||
"post_processing_time", s.PostProcessingTime.Load(), | ||
} | ||
} | ||
|
||
func (s *Stats) AddQueueTime(t time.Duration) { | ||
if s == nil { | ||
return | ||
} | ||
s.QueueTime.Add(t) | ||
} | ||
|
||
func (s *Stats) AddMetasFetchTime(t time.Duration) { | ||
if s == nil { | ||
return | ||
} | ||
s.MetasFetchTime.Add(t) | ||
} | ||
|
||
func (s *Stats) AddBlocksFetchTime(t time.Duration) { | ||
if s == nil { | ||
return | ||
} | ||
s.BlocksFetchTime.Add(t) | ||
} | ||
|
||
func (s *Stats) AddProcessingTime(t time.Duration) { | ||
if s == nil { | ||
return | ||
} | ||
s.ProcessingTime.Add(t) | ||
} | ||
|
||
func (s *Stats) AddPostProcessingTime(t time.Duration) { | ||
if s == nil { | ||
return | ||
} | ||
s.PostProcessingTime.Add(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters