MCPcopy Create free account
hub / github.com/cortexproject/cortex / reportQueryStats

Method reportQueryStats

pkg/frontend/transport/handler.go:441–603  ·  view source on GitHub ↗
(r *http.Request, source, userID string, queryString url.Values, queryResponseTime time.Duration, stats *querier_stats.QueryStats, error error, statusCode int, resp *http.Response)

Source from the content-addressed store, hash-verified

439}
440
441func (f *Handler) reportQueryStats(r *http.Request, source, userID string, queryString url.Values, queryResponseTime time.Duration, stats *querier_stats.QueryStats, error error, statusCode int, resp *http.Response) {
442 wallTime := stats.LoadWallTime()
443 queryStorageWallTime := stats.LoadQueryStorageWallTime()
444 numResponseSeries := stats.LoadResponseSeries()
445 numFetchedSeries := stats.LoadFetchedSeries()
446 numFetchedChunks := stats.LoadFetchedChunks()
447 numFetchedSamples := stats.LoadFetchedSamples()
448 numScannedSamples := stats.LoadScannedSamples()
449 numPeakSamples := stats.LoadPeakSamples()
450 numChunkBytes := stats.LoadFetchedChunkBytes()
451 numDataBytes := stats.LoadFetchedDataBytes()
452 numStoreGatewayTouchedPostings := stats.LoadStoreGatewayTouchedPostings()
453 numStoreGatewayTouchedPostingBytes := stats.LoadStoreGatewayTouchedPostingBytes()
454 splitQueries := stats.LoadSplitQueries()
455 dataSelectMaxTime := stats.LoadDataSelectMaxTime()
456 dataSelectMinTime := stats.LoadDataSelectMinTime()
457 splitInterval := stats.LoadSplitInterval()
458
459 // Track stats.
460 f.querySeconds.WithLabelValues(source, userID).Add(wallTime.Seconds())
461 f.queryFetchedSeries.WithLabelValues(source, userID).Add(float64(numFetchedSeries))
462 f.queryFetchedSamples.WithLabelValues(source, userID).Add(float64(numFetchedSamples))
463 f.queryScannedSamples.WithLabelValues(source, userID).Add(float64(numScannedSamples))
464 f.queryPeakSamples.WithLabelValues(source, userID).Observe(float64(numPeakSamples))
465 f.queryChunkBytes.WithLabelValues(source, userID).Add(float64(numChunkBytes))
466 f.queryDataBytes.WithLabelValues(source, userID).Add(float64(numDataBytes))
467 f.activeUsers.UpdateUserTimestamp(userID, time.Now())
468
469 var (
470 contentLength int64
471 encoding string
472 )
473 if resp != nil {
474 contentLength = resp.ContentLength
475 encoding = resp.Header.Get("Content-Encoding")
476 }
477
478 // Log stats.
479 logMessage := append([]any{
480 "msg", "query stats",
481 "component", "query-frontend",
482 "method", r.Method,
483 "path", r.URL.Path,
484 "response_time", queryResponseTime,
485 "query_wall_time_seconds", wallTime.Seconds(),
486 "response_series_count", numResponseSeries,
487 "fetched_series_count", numFetchedSeries,
488 "fetched_chunks_count", numFetchedChunks,
489 "fetched_samples_count", numFetchedSamples,
490 "fetched_chunks_bytes", numChunkBytes,
491 "fetched_data_bytes", numDataBytes,
492 "split_queries", splitQueries,
493 "status_code", statusCode,
494 "response_size", contentLength,
495 "samples_scanned", numScannedSamples,
496 }, stats.LoadExtraFields()...)
497
498 if numStoreGatewayTouchedPostings > 0 {

Callers 2

ServeHTTPMethod · 0.95

Calls 15

FormatMillisToSecondsFunction · 0.92
formatGrafanaStatsFieldsFunction · 0.85
formatQueryStringFunction · 0.85
LoadWallTimeMethod · 0.80
LoadResponseSeriesMethod · 0.80
LoadFetchedSeriesMethod · 0.80
LoadFetchedChunksMethod · 0.80
LoadFetchedSamplesMethod · 0.80
LoadScannedSamplesMethod · 0.80
LoadPeakSamplesMethod · 0.80
LoadFetchedChunkBytesMethod · 0.80

Tested by 1