MCPcopy
hub / github.com/grafana/tempo / CompileMetricsQueryRange

Method CompileMetricsQueryRange

pkg/traceql/engine_metrics.go:982–1137  ·  view source on GitHub ↗

CompileMetricsQueryRange returns an evaluator that can be reused across multiple data sources.

(req *tempopb.QueryRangeRequest, opts ...CompileOption)

Source from the content-addressed store, hash-verified

980
981// CompileMetricsQueryRange returns an evaluator that can be reused across multiple data sources.
982func (e *Engine) CompileMetricsQueryRange(req *tempopb.QueryRangeRequest, opts ...CompileOption) (*MetricsEvaluator, error) {
983 cfg := applyCompileOptions(opts...)
984
985 if req.Exemplars > maxExemplars {
986 level.Warn(log.Logger).Log("msg", "capping exemplars to safety limit", "requested", req.Exemplars, "cap", maxExemplars)
987 req.Exemplars = maxExemplars
988 }
989
990 if req.Start <= 0 {
991 return nil, fmt.Errorf("start required")
992 }
993 if req.End <= 0 {
994 return nil, fmt.Errorf("end required")
995 }
996 if req.End <= req.Start {
997 return nil, fmt.Errorf("end must be greater than start")
998 }
999 if req.Step <= 0 {
1000 return nil, fmt.Errorf("step required")
1001 }
1002
1003 expr, eval, metricsPipeline, _, storageReq, err := Compile(req.Query, opts...)
1004 if err != nil {
1005 return nil, fmt.Errorf("compiling query: %w", err)
1006 }
1007
1008 needsFullTrace := expr.NeedsFullTrace()
1009
1010 if metricsPipeline == nil {
1011 return nil, fmt.Errorf("not a metrics query")
1012 }
1013
1014 // Debug sampling hints, remove once we settle on approach.
1015 if traceSample, traceSampleOk := expr.Hints.GetFloat(HintTraceSample, cfg.allowUnsafeHints); traceSampleOk {
1016 storageReq.TraceSampler = newProbablisticSampler(traceSample)
1017 }
1018 if spanSample, spanSampleOk := expr.Hints.GetFloat(HintSpanSample, cfg.allowUnsafeHints); spanSampleOk {
1019 storageReq.SpanSampler = newProbablisticSampler(spanSample)
1020 }
1021
1022 if sample, sampleOk := expr.Hints.GetBool(HintSample, cfg.allowUnsafeHints); sampleOk && sample {
1023 // Automatic sampling
1024 // Get other params
1025 s := newAdaptiveSampler()
1026 if debug, ok := expr.Hints.GetBool(HintDebug, cfg.allowUnsafeHints); ok {
1027 s.debug = debug
1028 }
1029 if info, ok := expr.Hints.GetBool(HintInfo, cfg.allowUnsafeHints); ok {
1030 s.info = info
1031 }
1032
1033 // Classify the query and determine if it needs to be at the trace-level or can be at span-level (better)
1034 if expr.NeedsFullTrace() {
1035 storageReq.TraceSampler = s
1036 } else {
1037 storageReq.SpanSampler = s
1038 }
1039 }

Calls 13

applyCompileOptionsFunction · 0.85
CompileFunction · 0.85
newProbablisticSamplerFunction · 0.85
newAdaptiveSamplerFunction · 0.85
optimizeFunction · 0.85
NeedsFullTraceMethod · 0.80
GetFloatMethod · 0.80
GetBoolMethod · 0.80
DurationMethod · 0.80
HasAttributeMethod · 0.80
LogMethod · 0.65