mirror of
https://github.com/prometheus/prometheus
synced 2024-12-28 09:42:22 +00:00
promql: store labels per-group only for count_values
This saves memory in other kinds of aggregation. We don't need `orderedResult` in `aggregationCountValues`; the ordering is not guaranteed. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
185290a0d2
commit
2cf3c9de8f
@ -2730,7 +2730,6 @@ func vectorElemBinop(op parser.ItemType, lhs, rhs float64, hlhs, hrhs *histogram
|
|||||||
type groupedAggregation struct {
|
type groupedAggregation struct {
|
||||||
hasFloat bool // Has at least 1 float64 sample aggregated.
|
hasFloat bool // Has at least 1 float64 sample aggregated.
|
||||||
hasHistogram bool // Has at least 1 histogram sample aggregated.
|
hasHistogram bool // Has at least 1 histogram sample aggregated.
|
||||||
labels labels.Labels
|
|
||||||
floatValue float64
|
floatValue float64
|
||||||
histogramValue *histogram.FloatHistogram
|
histogramValue *histogram.FloatHistogram
|
||||||
floatMean float64
|
floatMean float64
|
||||||
@ -3044,8 +3043,11 @@ func (ev *evaluator) aggregationK(e *parser.AggregateExpr, k int, inputMatrix Ma
|
|||||||
// aggregationK evaluates count_values on vec.
|
// aggregationK evaluates count_values on vec.
|
||||||
// Outputs as many series per group as there are values in the input.
|
// Outputs as many series per group as there are values in the input.
|
||||||
func (ev *evaluator) aggregationCountValues(e *parser.AggregateExpr, grouping []string, valueLabel string, vec Vector, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
func (ev *evaluator) aggregationCountValues(e *parser.AggregateExpr, grouping []string, valueLabel string, vec Vector, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
|
||||||
result := map[uint64]*groupedAggregation{}
|
type groupCount struct {
|
||||||
orderedResult := []*groupedAggregation{}
|
labels labels.Labels
|
||||||
|
count int
|
||||||
|
}
|
||||||
|
result := map[uint64]*groupCount{}
|
||||||
|
|
||||||
var buf []byte
|
var buf []byte
|
||||||
for _, s := range vec {
|
for _, s := range vec {
|
||||||
@ -3062,24 +3064,21 @@ func (ev *evaluator) aggregationCountValues(e *parser.AggregateExpr, grouping []
|
|||||||
group, ok := result[groupingKey]
|
group, ok := result[groupingKey]
|
||||||
// Add a new group if it doesn't exist.
|
// Add a new group if it doesn't exist.
|
||||||
if !ok {
|
if !ok {
|
||||||
newAgg := &groupedAggregation{
|
result[groupingKey] = &groupCount{
|
||||||
labels: generateGroupingLabels(enh, metric, e.Without, grouping),
|
labels: generateGroupingLabels(enh, metric, e.Without, grouping),
|
||||||
groupCount: 1,
|
count: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
result[groupingKey] = newAgg
|
|
||||||
orderedResult = append(orderedResult, newAgg)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
group.groupCount++
|
group.count++
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the result Vector from the aggregated groups.
|
// Construct the result Vector from the aggregated groups.
|
||||||
for _, aggr := range orderedResult {
|
for _, aggr := range result {
|
||||||
enh.Out = append(enh.Out, Sample{
|
enh.Out = append(enh.Out, Sample{
|
||||||
Metric: aggr.labels,
|
Metric: aggr.labels,
|
||||||
F: float64(aggr.groupCount),
|
F: float64(aggr.count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return enh.Out, nil
|
return enh.Out, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user