2019-07-10 11:57:27 +02:00
|
|
|
package promql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2019-12-08 23:52:31 +01:00
|
|
|
|
2020-04-28 14:28:22 +02:00
|
|
|
"github.com/VictoriaMetrics/metricsql"
|
2019-07-10 11:57:27 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// callbacks for optimized incremental calculations for aggregate functions
|
2019-12-25 20:35:47 +01:00
|
|
|
// over rollups over metricsql.MetricExpr.
|
2019-07-10 11:57:27 +02:00
|
|
|
//
|
|
|
|
// These calculations save RAM for aggregates over big number of time series.
|
|
|
|
var incrementalAggrFuncCallbacksMap = map[string]*incrementalAggrFuncCallbacks{
|
|
|
|
"sum": {
|
|
|
|
updateAggrFunc: updateAggrSum,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrSum,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
|
|
|
},
|
|
|
|
"min": {
|
|
|
|
updateAggrFunc: updateAggrMin,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrMin,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
|
|
|
},
|
|
|
|
"max": {
|
|
|
|
updateAggrFunc: updateAggrMax,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrMax,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
|
|
|
},
|
|
|
|
"avg": {
|
|
|
|
updateAggrFunc: updateAggrAvg,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrAvg,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrAvg,
|
|
|
|
},
|
|
|
|
"count": {
|
|
|
|
updateAggrFunc: updateAggrCount,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrCount,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrCount,
|
|
|
|
},
|
|
|
|
"sum2": {
|
|
|
|
updateAggrFunc: updateAggrSum2,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrSum2,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
|
|
|
},
|
|
|
|
"geomean": {
|
|
|
|
updateAggrFunc: updateAggrGeomean,
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc: mergeAggrGeomean,
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc: finalizeAggrGeomean,
|
|
|
|
},
|
2020-05-12 18:45:42 +02:00
|
|
|
"any": {
|
|
|
|
updateAggrFunc: updateAggrAny,
|
|
|
|
mergeAggrFunc: mergeAggrAny,
|
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
2020-07-17 15:47:16 +02:00
|
|
|
|
|
|
|
keepOriginal: true,
|
|
|
|
},
|
|
|
|
"group": {
|
|
|
|
updateAggrFunc: updateAggrGroup,
|
|
|
|
mergeAggrFunc: mergeAggrAny,
|
|
|
|
finalizeAggrFunc: finalizeAggrCommon,
|
2020-05-12 18:45:42 +02:00
|
|
|
},
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type incrementalAggrFuncContext struct {
|
2019-12-25 20:35:47 +01:00
|
|
|
ae *metricsql.AggrFuncExpr
|
2019-07-10 11:57:27 +02:00
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
mLock sync.Mutex
|
|
|
|
m map[uint]map[string]*incrementalAggrContext
|
2019-07-10 11:57:27 +02:00
|
|
|
|
|
|
|
callbacks *incrementalAggrFuncCallbacks
|
|
|
|
}
|
|
|
|
|
2019-12-25 20:35:47 +01:00
|
|
|
func newIncrementalAggrFuncContext(ae *metricsql.AggrFuncExpr, callbacks *incrementalAggrFuncCallbacks) *incrementalAggrFuncContext {
|
2019-07-10 11:57:27 +02:00
|
|
|
return &incrementalAggrFuncContext{
|
|
|
|
ae: ae,
|
2019-07-12 14:51:02 +02:00
|
|
|
m: make(map[uint]map[string]*incrementalAggrContext),
|
2019-07-10 11:57:27 +02:00
|
|
|
callbacks: callbacks,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 15:47:16 +02:00
|
|
|
func (iafc *incrementalAggrFuncContext) updateTimeseries(tsOrig *timeseries, workerID uint) {
|
2019-07-12 14:51:02 +02:00
|
|
|
iafc.mLock.Lock()
|
|
|
|
m := iafc.m[workerID]
|
|
|
|
if m == nil {
|
|
|
|
m = make(map[string]*incrementalAggrContext, 1)
|
|
|
|
iafc.m[workerID] = m
|
|
|
|
}
|
|
|
|
iafc.mLock.Unlock()
|
|
|
|
|
2020-07-17 15:47:16 +02:00
|
|
|
ts := tsOrig
|
|
|
|
keepOriginal := iafc.callbacks.keepOriginal
|
|
|
|
if keepOriginal {
|
|
|
|
var dst timeseries
|
|
|
|
dst.CopyFromMetricNames(tsOrig)
|
|
|
|
ts = &dst
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
removeGroupTags(&ts.MetricName, &iafc.ae.Modifier)
|
|
|
|
bb := bbPool.Get()
|
|
|
|
bb.B = marshalMetricNameSorted(bb.B[:0], &ts.MetricName)
|
2019-07-12 14:51:02 +02:00
|
|
|
iac := m[string(bb.B)]
|
2019-07-10 11:57:27 +02:00
|
|
|
if iac == nil {
|
2020-05-12 18:06:54 +02:00
|
|
|
if iafc.ae.Limit > 0 && len(m) >= iafc.ae.Limit {
|
|
|
|
// Skip this time series, since the limit on the number of output time series has been already reached.
|
|
|
|
return
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
tsAggr := ×eries{
|
|
|
|
Values: make([]float64, len(ts.Values)),
|
|
|
|
Timestamps: ts.Timestamps,
|
|
|
|
denyReuse: true,
|
|
|
|
}
|
2020-07-17 15:47:16 +02:00
|
|
|
if keepOriginal {
|
|
|
|
ts = tsOrig
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
tsAggr.MetricName.CopyFrom(&ts.MetricName)
|
|
|
|
iac = &incrementalAggrContext{
|
|
|
|
ts: tsAggr,
|
|
|
|
values: make([]float64, len(ts.Values)),
|
|
|
|
}
|
2019-07-12 14:51:02 +02:00
|
|
|
m[string(bb.B)] = iac
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
bbPool.Put(bb)
|
2019-07-12 14:51:02 +02:00
|
|
|
iafc.callbacks.updateAggrFunc(iac, ts.Values)
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (iafc *incrementalAggrFuncContext) finalizeTimeseries() []*timeseries {
|
2019-07-12 14:51:02 +02:00
|
|
|
// There is no need in iafc.mLock.Lock here, since finalizeTimeseries must be called
|
2019-07-10 11:57:27 +02:00
|
|
|
// without concurrent goroutines touching iafc.
|
2019-07-12 14:51:02 +02:00
|
|
|
mGlobal := make(map[string]*incrementalAggrContext)
|
|
|
|
mergeAggrFunc := iafc.callbacks.mergeAggrFunc
|
|
|
|
for _, m := range iafc.m {
|
|
|
|
for k, iac := range m {
|
|
|
|
iacGlobal := mGlobal[k]
|
|
|
|
if iacGlobal == nil {
|
2020-05-12 18:06:54 +02:00
|
|
|
if iafc.ae.Limit > 0 && len(mGlobal) >= iafc.ae.Limit {
|
|
|
|
// Skip this time series, since the limit on the number of output time series has been already reached.
|
|
|
|
continue
|
|
|
|
}
|
2019-07-12 14:51:02 +02:00
|
|
|
mGlobal[k] = iac
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
mergeAggrFunc(iacGlobal, iac)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tss := make([]*timeseries, 0, len(mGlobal))
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc := iafc.callbacks.finalizeAggrFunc
|
2019-07-12 14:51:02 +02:00
|
|
|
for _, iac := range mGlobal {
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc(iac)
|
|
|
|
tss = append(tss, iac.ts)
|
|
|
|
}
|
|
|
|
return tss
|
|
|
|
}
|
|
|
|
|
|
|
|
type incrementalAggrFuncCallbacks struct {
|
|
|
|
updateAggrFunc func(iac *incrementalAggrContext, values []float64)
|
2019-07-12 14:51:02 +02:00
|
|
|
mergeAggrFunc func(dst, src *incrementalAggrContext)
|
2019-07-10 11:57:27 +02:00
|
|
|
finalizeAggrFunc func(iac *incrementalAggrContext)
|
2020-07-17 15:47:16 +02:00
|
|
|
|
|
|
|
// Whether to keep the original MetricName for every time series during aggregation
|
|
|
|
keepOriginal bool
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func getIncrementalAggrFuncCallbacks(name string) *incrementalAggrFuncCallbacks {
|
|
|
|
name = strings.ToLower(name)
|
|
|
|
return incrementalAggrFuncCallbacksMap[name]
|
|
|
|
}
|
|
|
|
|
|
|
|
type incrementalAggrContext struct {
|
|
|
|
ts *timeseries
|
|
|
|
values []float64
|
|
|
|
}
|
|
|
|
|
|
|
|
func finalizeAggrCommon(iac *incrementalAggrContext) {
|
|
|
|
counts := iac.values
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
_ = dstValues[len(counts)-1]
|
|
|
|
for i, v := range counts {
|
|
|
|
if v == 0 {
|
|
|
|
dstValues[i] = nan
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateAggrSum(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
2019-07-12 14:51:02 +02:00
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] += v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeAggrSum(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
dstValues[i] += v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateAggrMin(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if v < dstValues[i] {
|
|
|
|
dstValues[i] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
func mergeAggrMin(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if v < dstValues[i] {
|
|
|
|
dstValues[i] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:57:27 +02:00
|
|
|
func updateAggrMax(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if v > dstValues[i] {
|
|
|
|
dstValues[i] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
func mergeAggrMax(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if v > dstValues[i] {
|
|
|
|
dstValues[i] = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:57:27 +02:00
|
|
|
func updateAggrAvg(iac *incrementalAggrContext, values []float64) {
|
|
|
|
// Do not use `Rapid calculation methods` at https://en.wikipedia.org/wiki/Standard_deviation,
|
|
|
|
// since it is slower and has no obvious benefits in increased precision.
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] += v
|
|
|
|
dstCounts[i]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
func mergeAggrAvg(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = srcCounts[i]
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] += v
|
|
|
|
dstCounts[i] += srcCounts[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:57:27 +02:00
|
|
|
func finalizeAggrAvg(iac *incrementalAggrContext) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
counts := iac.values
|
|
|
|
_ = dstValues[len(counts)-1]
|
|
|
|
for i, v := range counts {
|
|
|
|
if v == 0 {
|
|
|
|
dstValues[i] = nan
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] /= v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateAggrCount(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
func mergeAggrCount(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
dstValues[i] += v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:57:27 +02:00
|
|
|
func finalizeAggrCount(iac *incrementalAggrContext) {
|
2019-07-25 21:02:03 +02:00
|
|
|
dstValues := iac.ts.Values
|
|
|
|
for i, v := range dstValues {
|
|
|
|
if v == 0 {
|
|
|
|
dstValues[i] = nan
|
|
|
|
}
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func updateAggrSum2(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
2019-07-12 14:51:02 +02:00
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v * v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
2019-07-10 11:57:27 +02:00
|
|
|
dstValues[i] += v * v
|
2019-07-12 14:51:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func mergeAggrSum2(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] += v
|
2019-07-10 11:57:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateAggrGeomean(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
dstCounts := iac.values
|
|
|
|
_ = dstValues[len(values)-1]
|
|
|
|
_ = dstCounts[len(values)-1]
|
|
|
|
for i, v := range values {
|
|
|
|
if math.IsNaN(v) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = 1
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] *= v
|
|
|
|
dstCounts[i]++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-12 14:51:02 +02:00
|
|
|
func mergeAggrGeomean(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
dstValues := dst.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
_ = srcCounts[len(srcValues)-1]
|
|
|
|
_ = dstCounts[len(srcValues)-1]
|
|
|
|
_ = dstValues[len(srcValues)-1]
|
|
|
|
for i, v := range srcValues {
|
|
|
|
if srcCounts[i] == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if dstCounts[i] == 0 {
|
|
|
|
dstValues[i] = v
|
|
|
|
dstCounts[i] = srcCounts[i]
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] *= v
|
|
|
|
dstCounts[i] += srcCounts[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-10 11:57:27 +02:00
|
|
|
func finalizeAggrGeomean(iac *incrementalAggrContext) {
|
|
|
|
dstValues := iac.ts.Values
|
|
|
|
counts := iac.values
|
|
|
|
_ = dstValues[len(counts)-1]
|
|
|
|
for i, v := range counts {
|
|
|
|
if v == 0 {
|
|
|
|
dstValues[i] = nan
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
dstValues[i] = math.Pow(dstValues[i], 1/v)
|
|
|
|
}
|
|
|
|
}
|
2020-05-12 18:45:42 +02:00
|
|
|
|
|
|
|
func updateAggrAny(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstCounts := iac.values
|
|
|
|
if dstCounts[0] > 0 {
|
|
|
|
return
|
|
|
|
}
|
2020-05-12 19:26:44 +02:00
|
|
|
for i := range values {
|
|
|
|
dstCounts[i] = 1
|
|
|
|
}
|
2020-05-13 10:46:05 +02:00
|
|
|
iac.ts.Values = append(iac.ts.Values[:0], values...)
|
2020-05-12 18:45:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func mergeAggrAny(dst, src *incrementalAggrContext) {
|
|
|
|
srcValues := src.ts.Values
|
|
|
|
srcCounts := src.values
|
|
|
|
dstCounts := dst.values
|
|
|
|
if dstCounts[0] > 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dstCounts[0] = srcCounts[0]
|
2020-05-13 10:46:05 +02:00
|
|
|
dst.ts.Values = append(dst.ts.Values[:0], srcValues...)
|
2020-05-12 18:45:42 +02:00
|
|
|
}
|
2020-07-17 15:47:16 +02:00
|
|
|
|
|
|
|
func updateAggrGroup(iac *incrementalAggrContext, values []float64) {
|
|
|
|
dstCounts := iac.values
|
|
|
|
if dstCounts[0] > 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for i := range values {
|
|
|
|
dstCounts[i] = 1
|
|
|
|
}
|
|
|
|
for i := range values {
|
|
|
|
values[i] = 1
|
|
|
|
}
|
|
|
|
iac.ts.Values = append(iac.ts.Values[:0], values...)
|
|
|
|
}
|