lib/streamaggr: added rate_sum and rate_avg to benchmarks, lint fix (#6264)

fixed lint for rate outputs

(cherry picked from commit ce25d68b45)
This commit is contained in:
Andrii Chubatiuk 2024-05-13 17:40:37 +03:00 committed by hagen1778
parent d9cddf1ad8
commit b9eb527d98
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640
2 changed files with 6 additions and 4 deletions

View file

@ -19,7 +19,7 @@ type rateAggrState struct {
type rateStateValue struct { type rateStateValue struct {
mu sync.Mutex mu sync.Mutex
lastValues map[string]*rateLastValueState lastValues map[string]rateLastValueState
deleteDeadline uint64 deleteDeadline uint64
deleted bool deleted bool
} }
@ -57,7 +57,7 @@ func (as *rateAggrState) pushSamples(samples []pushSample) {
if !ok { if !ok {
// The entry is missing in the map. Try creating it. // The entry is missing in the map. Try creating it.
v = &rateStateValue{ v = &rateStateValue{
lastValues: make(map[string]*rateLastValueState), lastValues: make(map[string]rateLastValueState),
} }
vNew, loaded := as.m.LoadOrStore(outputKey, v) vNew, loaded := as.m.LoadOrStore(outputKey, v)
if loaded { if loaded {
@ -85,8 +85,6 @@ func (as *rateAggrState) pushSamples(samples []pushSample) {
// counter reset // counter reset
lv.total += s.value lv.total += s.value
} }
} else {
lv = &rateLastValueState{}
} }
lv.value = s.value lv.value = s.value
lv.timestamp = s.timestamp lv.timestamp = s.timestamp
@ -104,6 +102,7 @@ func (as *rateAggrState) pushSamples(samples []pushSample) {
} }
func (as *rateAggrState) flushState(ctx *flushCtx, resetState bool) { func (as *rateAggrState) flushState(ctx *flushCtx, resetState bool) {
_ = resetState // it isn't used here
currentTime := fasttime.UnixTimestamp() currentTime := fasttime.UnixTimestamp()
currentTimeMsec := int64(currentTime) * 1000 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) rate += v1.total * 1000 / float64(v1.timestamp-v1.prevTimestamp)
v1.prevTimestamp = v1.timestamp v1.prevTimestamp = v1.timestamp
v1.total = 0 v1.total = 0
m[k1] = v1
} }
} }
if as.suffix == "rate_avg" { if as.suffix == "rate_avg" {

View file

@ -15,6 +15,8 @@ var benchOutputs = []string{
"total_prometheus", "total_prometheus",
"increase", "increase",
"increase_prometheus", "increase_prometheus",
"rate_sum",
"rate_avg",
"count_series", "count_series",
"count_samples", "count_samples",
"unique_samples", "unique_samples",