mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
promql: refactor: extract generateGroupingLabels function
Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
bbfc72b4e2
commit
8e04ab6dd4
|
@ -2691,19 +2691,7 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, grouping []string, par
|
||||||
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 {
|
||||||
var m labels.Labels
|
m := generateGroupingLabels(enh, metric, without, grouping)
|
||||||
enh.resetBuilder(metric)
|
|
||||||
switch {
|
|
||||||
case without:
|
|
||||||
enh.lb.Del(grouping...)
|
|
||||||
enh.lb.Del(labels.MetricName)
|
|
||||||
m = enh.lb.Labels()
|
|
||||||
case len(grouping) > 0:
|
|
||||||
enh.lb.Keep(grouping...)
|
|
||||||
m = enh.lb.Labels()
|
|
||||||
default:
|
|
||||||
m = labels.EmptyLabels()
|
|
||||||
}
|
|
||||||
newAgg := &groupedAggregation{
|
newAgg := &groupedAggregation{
|
||||||
labels: m,
|
labels: m,
|
||||||
floatValue: s.F,
|
floatValue: s.F,
|
||||||
|
@ -2969,6 +2957,21 @@ func generateGroupingKey(metric labels.Labels, grouping []string, without bool,
|
||||||
return metric.HashForLabels(buf, grouping...)
|
return metric.HashForLabels(buf, grouping...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateGroupingLabels(enh *EvalNodeHelper, metric labels.Labels, without bool, grouping []string) labels.Labels {
|
||||||
|
enh.resetBuilder(metric)
|
||||||
|
switch {
|
||||||
|
case without:
|
||||||
|
enh.lb.Del(grouping...)
|
||||||
|
enh.lb.Del(labels.MetricName)
|
||||||
|
return enh.lb.Labels()
|
||||||
|
case len(grouping) > 0:
|
||||||
|
enh.lb.Keep(grouping...)
|
||||||
|
return enh.lb.Labels()
|
||||||
|
default:
|
||||||
|
return labels.EmptyLabels()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// btos returns 1 if b is true, 0 otherwise.
|
// btos returns 1 if b is true, 0 otherwise.
|
||||||
func btos(b bool) float64 {
|
func btos(b bool) float64 {
|
||||||
if b {
|
if b {
|
||||||
|
|
Loading…
Reference in a new issue