|
|
@ -68,6 +68,7 @@ type Matrix []SampleStream
|
|
|
|
type groupedAggregation struct {
|
|
|
|
type groupedAggregation struct {
|
|
|
|
labels clientmodel.COWMetric
|
|
|
|
labels clientmodel.COWMetric
|
|
|
|
value clientmodel.SampleValue
|
|
|
|
value clientmodel.SampleValue
|
|
|
|
|
|
|
|
valuesSquaredSum clientmodel.SampleValue
|
|
|
|
groupCount int
|
|
|
|
groupCount int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -128,6 +129,8 @@ const (
|
|
|
|
Min
|
|
|
|
Min
|
|
|
|
Max
|
|
|
|
Max
|
|
|
|
Count
|
|
|
|
Count
|
|
|
|
|
|
|
|
Stdvar
|
|
|
|
|
|
|
|
Stddev
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
@ -468,6 +471,12 @@ func (node *VectorAggregation) groupedAggregationsToVector(aggregations map[uint
|
|
|
|
aggregation.value = aggregation.value / clientmodel.SampleValue(aggregation.groupCount)
|
|
|
|
aggregation.value = aggregation.value / clientmodel.SampleValue(aggregation.groupCount)
|
|
|
|
case Count:
|
|
|
|
case Count:
|
|
|
|
aggregation.value = clientmodel.SampleValue(aggregation.groupCount)
|
|
|
|
aggregation.value = clientmodel.SampleValue(aggregation.groupCount)
|
|
|
|
|
|
|
|
case Stdvar:
|
|
|
|
|
|
|
|
avg := float64(aggregation.value) / float64(aggregation.groupCount)
|
|
|
|
|
|
|
|
aggregation.value = clientmodel.SampleValue(float64(aggregation.valuesSquaredSum)/float64(aggregation.groupCount) - avg*avg)
|
|
|
|
|
|
|
|
case Stddev:
|
|
|
|
|
|
|
|
avg := float64(aggregation.value) / float64(aggregation.groupCount)
|
|
|
|
|
|
|
|
aggregation.value = clientmodel.SampleValue(math.Sqrt(float64(aggregation.valuesSquaredSum)/float64(aggregation.groupCount) - avg*avg))
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
// For other aggregations, we already have the right value.
|
|
|
|
// For other aggregations, we already have the right value.
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -509,6 +518,10 @@ func (node *VectorAggregation) Eval(timestamp clientmodel.Timestamp) Vector {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case Count:
|
|
|
|
case Count:
|
|
|
|
groupedResult.groupCount++
|
|
|
|
groupedResult.groupCount++
|
|
|
|
|
|
|
|
case Stdvar, Stddev:
|
|
|
|
|
|
|
|
groupedResult.value += sample.Value
|
|
|
|
|
|
|
|
groupedResult.valuesSquaredSum += sample.Value * sample.Value
|
|
|
|
|
|
|
|
groupedResult.groupCount++
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
panic("Unknown aggregation type")
|
|
|
|
panic("Unknown aggregation type")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -531,6 +544,7 @@ func (node *VectorAggregation) Eval(timestamp clientmodel.Timestamp) Vector {
|
|
|
|
result[groupingKey] = &groupedAggregation{
|
|
|
|
result[groupingKey] = &groupedAggregation{
|
|
|
|
labels: m,
|
|
|
|
labels: m,
|
|
|
|
value: sample.Value,
|
|
|
|
value: sample.Value,
|
|
|
|
|
|
|
|
valuesSquaredSum: sample.Value * sample.Value,
|
|
|
|
groupCount: 1,
|
|
|
|
groupCount: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|