mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
### Describe Your Changes fixes #8469 ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/).
35 lines
679 B
Go
35 lines
679 B
Go
package streamaggr
|
|
|
|
type lastAggrValue struct {
|
|
last float64
|
|
timestamp int64
|
|
}
|
|
|
|
func (av *lastAggrValue) pushSample(_ aggrConfig, sample *pushSample, _ string, _ int64) {
|
|
if sample.timestamp >= av.timestamp {
|
|
av.last = sample.value
|
|
av.timestamp = sample.timestamp
|
|
}
|
|
}
|
|
|
|
func (av *lastAggrValue) flush(_ aggrConfig, ctx *flushCtx, key string, _ bool) {
|
|
if av.timestamp > 0 {
|
|
ctx.appendSeries(key, "last", av.last)
|
|
av.timestamp = 0
|
|
}
|
|
}
|
|
|
|
func (*lastAggrValue) state() any {
|
|
return nil
|
|
}
|
|
|
|
func newLastAggrConfig() aggrConfig {
|
|
return &lastAggrConfig{}
|
|
}
|
|
|
|
type lastAggrConfig struct{}
|
|
|
|
func (*lastAggrConfig) getValue(_ any) aggrValue {
|
|
return &lastAggrValue{}
|
|
}
|