(attr Attribute, op SimpleAggregationOp)
| 487 | var _ VectorAggregator = (*OverTimeAggregator)(nil) |
| 488 | |
| 489 | func NewOverTimeAggregator(attr Attribute, op SimpleAggregationOp) *OverTimeAggregator { |
| 490 | var fn func(s Span) float64 |
| 491 | var agg func(current, n float64) float64 |
| 492 | |
| 493 | switch op { |
| 494 | case maxOverTimeAggregation: |
| 495 | agg = maxOverTime() |
| 496 | case minOverTimeAggregation: |
| 497 | agg = minOverTime() |
| 498 | case sumOverTimeAggregation: |
| 499 | agg = sumOverTime() |
| 500 | } |
| 501 | |
| 502 | switch attr { |
| 503 | case IntrinsicDurationAttribute: |
| 504 | fn = func(s Span) float64 { |
| 505 | return float64(s.DurationNanos()) / float64(time.Second) |
| 506 | } |
| 507 | default: |
| 508 | fn = func(s Span) float64 { |
| 509 | f, a := FloatizeAttribute(s, attr) |
| 510 | if a == TypeNil { |
| 511 | return math.Float64frombits(normalNaN) |
| 512 | } |
| 513 | return f |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | return &OverTimeAggregator{ |
| 518 | getSpanAttValue: fn, |
| 519 | agg: agg, |
| 520 | val: math.Float64frombits(normalNaN), |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | func (c *OverTimeAggregator) Observe(s Span) { |
| 525 | c.val = c.agg(c.val, c.getSpanAttValue(s)) |
no test coverage detected