Skip to content

Commit fe036d5

Browse files
committed
Fix legacy_promql
Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent bf37d03 commit fe036d5

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

pkg/configs/legacy_promql/engine.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,13 +1297,17 @@ func (ev *evaluator) VectorBinop(op ItemType, lhs, rhs Vector, matching *VectorM
12971297
// signatureFunc returns a function that calculates the signature for a metric
12981298
// ignoring the provided labels. If on, then the given labels are only used instead.
12991299
func signatureFunc(on bool, names ...string) func(labels.Labels) uint64 {
1300-
// TODO(fabxc): ensure names are sorted and then use that and sortedness
1301-
// of labels by names to speed up the operations below.
1302-
// Alternatively, inline the hashing and don't build new label sets.
1300+
sort.Strings(names)
13031301
if on {
1304-
return func(lset labels.Labels) uint64 { return lset.HashForLabels(names...) }
1302+
return func(lset labels.Labels) uint64 {
1303+
h, _ := lset.HashForLabels(make([]byte, 0, 1024), names...)
1304+
return h
1305+
}
1306+
}
1307+
return func(lset labels.Labels) uint64 {
1308+
h, _ := lset.HashWithoutLabels(make([]byte, 0, 1024), names...)
1309+
return h
13051310
}
1306-
return func(lset labels.Labels) uint64 { return lset.HashWithoutLabels(names...) }
13071311
}
13081312

13091313
// resultMetric returns the metric for the given sample(s) based on the Vector
@@ -1503,6 +1507,8 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
15031507
}
15041508
}
15051509

1510+
sort.Strings(grouping)
1511+
buf := make([]byte, 0, 1024)
15061512
for _, s := range vec {
15071513
metric := s.Metric
15081514

@@ -1516,9 +1522,9 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
15161522
groupingKey uint64
15171523
)
15181524
if without {
1519-
groupingKey = metric.HashWithoutLabels(grouping...)
1525+
groupingKey, buf = metric.HashWithoutLabels(buf, grouping...)
15201526
} else {
1521-
groupingKey = metric.HashForLabels(grouping...)
1527+
groupingKey, buf = metric.HashForLabels(buf, grouping...)
15221528
}
15231529

15241530
group, ok := result[groupingKey]

0 commit comments

Comments
 (0)