Files
Andrii Chubatiuk c174a046e2 lib/streamaggr: fixed streamaggr panic (#8471)
### Describe Your Changes

fixes #8469

### Checklist

The following checks are **mandatory**:

- [ ] My change adheres [VictoriaMetrics contributing
guidelines](https://docs.victoriametrics.com/contributing/).
2025-03-10 13:50:55 +01:00

38 lines
682 B
Go

package streamaggr
type maxAggrValue struct {
max float64
defined bool
}
func (av *maxAggrValue) pushSample(_ aggrConfig, sample *pushSample, _ string, _ int64) {
if sample.value > av.max || !av.defined {
av.max = sample.value
}
if !av.defined {
av.defined = true
}
}
func (av *maxAggrValue) flush(_ aggrConfig, ctx *flushCtx, key string, _ bool) {
if av.defined {
ctx.appendSeries(key, "max", av.max)
av.max = 0
av.defined = false
}
}
func (*maxAggrValue) state() any {
return nil
}
func newMaxAggrConfig() aggrConfig {
return &maxAggrConfig{}
}
type maxAggrConfig struct{}
func (*maxAggrConfig) getValue(_ any) aggrValue {
return &maxAggrValue{}
}