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

Function newAvgAggregator

pkg/traceql/engine_metrics_average.go:451–481  ·  view source on GitHub ↗
(attr Attribute, by []Attribute, lookups [][]Attribute, start, end, step uint64, instant bool, exemplars uint32)

Source from the content-addressed store, hash-verified

449}
450
451func newAvgAggregator[F FastStatic, S StaticVals](attr Attribute, by []Attribute, lookups [][]Attribute, start, end, step uint64, instant bool, exemplars uint32) SpanAggregator {
452 var fn func(s Span) float64
453
454 switch attr {
455 case IntrinsicDurationAttribute:
456 fn = func(s Span) float64 {
457 return float64(s.DurationNanos()) / float64(time.Second)
458 }
459 default:
460 fn = func(s Span) float64 {
461 f, a := FloatizeAttribute(s, attr)
462 if a == TypeNil {
463 return math.Float64frombits(normalNaN)
464 }
465 return f
466 }
467 }
468
469 return &avgOverTimeSpanAggregator[F, S]{
470 series: map[F]avgOverTimeSeries[S]{},
471 getSpanAttValue: fn,
472 by: by,
473 byLookups: lookups,
474 intervalMapper: NewIntervalMapper(start, end, step, instant),
475 start: start,
476 end: end,
477 step: step,
478 instant: instant,
479 exemplars: exemplars,
480 }
481}
482
483func (g *avgOverTimeSpanAggregator[F, S]) Observe(span Span) {
484 interval := g.intervalMapper.Interval(span.StartTimeUnixNanos())

Callers 1

Calls 3

FloatizeAttributeFunction · 0.85
NewIntervalMapperFunction · 0.85
DurationNanosMethod · 0.65

Tested by

no test coverage detected