From b9eb527d9822bda5ba731e4cae3dc85da8289e1d Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Mon, 13 May 2024 17:40:37 +0300 Subject: [PATCH] lib/streamaggr: added rate_sum and rate_avg to benchmarks, lint fix (#6264) fixed lint for rate outputs (cherry picked from commit ce25d68b45d4ec81327a41518229639d61fb796a) --- lib/streamaggr/rate.go | 8 ++++---- lib/streamaggr/streamaggr_timing_test.go | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/streamaggr/rate.go b/lib/streamaggr/rate.go index af8fe0786..1eedf1f1d 100644 --- a/lib/streamaggr/rate.go +++ b/lib/streamaggr/rate.go @@ -19,7 +19,7 @@ type rateAggrState struct { type rateStateValue struct { mu sync.Mutex - lastValues map[string]*rateLastValueState + lastValues map[string]rateLastValueState deleteDeadline uint64 deleted bool } @@ -57,7 +57,7 @@ func (as *rateAggrState) pushSamples(samples []pushSample) { if !ok { // The entry is missing in the map. Try creating it. v = &rateStateValue{ - lastValues: make(map[string]*rateLastValueState), + lastValues: make(map[string]rateLastValueState), } vNew, loaded := as.m.LoadOrStore(outputKey, v) if loaded { @@ -85,8 +85,6 @@ func (as *rateAggrState) pushSamples(samples []pushSample) { // counter reset lv.total += s.value } - } else { - lv = &rateLastValueState{} } lv.value = s.value lv.timestamp = s.timestamp @@ -104,6 +102,7 @@ func (as *rateAggrState) pushSamples(samples []pushSample) { } func (as *rateAggrState) flushState(ctx *flushCtx, resetState bool) { + _ = resetState // it isn't used here currentTime := fasttime.UnixTimestamp() currentTimeMsec := int64(currentTime) * 1000 @@ -132,6 +131,7 @@ func (as *rateAggrState) flushState(ctx *flushCtx, resetState bool) { rate += v1.total * 1000 / float64(v1.timestamp-v1.prevTimestamp) v1.prevTimestamp = v1.timestamp v1.total = 0 + m[k1] = v1 } } if as.suffix == "rate_avg" { diff --git a/lib/streamaggr/streamaggr_timing_test.go b/lib/streamaggr/streamaggr_timing_test.go index 0a5dc31c4..f06da26cc 100644 --- a/lib/streamaggr/streamaggr_timing_test.go +++ b/lib/streamaggr/streamaggr_timing_test.go @@ -15,6 +15,8 @@ var benchOutputs = []string{ "total_prometheus", "increase", "increase_prometheus", + "rate_sum", + "rate_avg", "count_series", "count_samples", "unique_samples",