mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00

### Describe Your Changes
fixes #8469
### Checklist
The following checks are **mandatory**:
- [ ] My change adheres [VictoriaMetrics contributing
guidelines](https://docs.victoriametrics.com/contributing/).
(cherry picked from commit c174a046e2
)
34 lines
813 B
Go
34 lines
813 B
Go
package streamaggr
|
|
|
|
type uniqueSamplesAggrValue struct {
|
|
samples map[float64]struct{}
|
|
}
|
|
|
|
func (av *uniqueSamplesAggrValue) pushSample(_ aggrConfig, sample *pushSample, _ string, _ int64) {
|
|
if _, ok := av.samples[sample.value]; !ok {
|
|
av.samples[sample.value] = struct{}{}
|
|
}
|
|
}
|
|
|
|
func (av *uniqueSamplesAggrValue) flush(_ aggrConfig, ctx *flushCtx, key string, _ bool) {
|
|
if len(av.samples) > 0 {
|
|
ctx.appendSeries(key, "unique_samples", float64(len(av.samples)))
|
|
clear(av.samples)
|
|
}
|
|
}
|
|
|
|
func (*uniqueSamplesAggrValue) state() any {
|
|
return nil
|
|
}
|
|
|
|
func newUniqueSamplesAggrConfig() aggrConfig {
|
|
return &uniqueSamplesAggrConfig{}
|
|
}
|
|
|
|
type uniqueSamplesAggrConfig struct{}
|
|
|
|
func (*uniqueSamplesAggrConfig) getValue(_ any) aggrValue {
|
|
return &uniqueSamplesAggrValue{
|
|
samples: make(map[float64]struct{}),
|
|
}
|
|
}
|