mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-11 14:53:49 +00:00
25 lines
601 B
Go
25 lines
601 B
Go
package streamaggr
|
|
|
|
func uniqueSamplesInitFn(values []aggrValue) []aggrValue {
|
|
for i := range values {
|
|
values[i] = &uniqueSamplesAggrValue{
|
|
samples: make(map[float64]struct{}),
|
|
}
|
|
}
|
|
return values
|
|
}
|
|
|
|
type uniqueSamplesAggrValue struct {
|
|
samples map[float64]struct{}
|
|
}
|
|
|
|
func (av *uniqueSamplesAggrValue) pushSample(ctx *pushSampleCtx) {
|
|
if _, ok := av.samples[ctx.sample.value]; !ok {
|
|
av.samples[ctx.sample.value] = struct{}{}
|
|
}
|
|
}
|
|
|
|
func (av *uniqueSamplesAggrValue) flush(ctx *flushCtx, key string) {
|
|
ctx.appendSeries(key, "unique_samples", float64(len(av.samples)))
|
|
clear(av.samples)
|
|
}
|