app/vmselect/promql: really keep metric names when keep_metric_names modifier is applied to binary operator

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5556
This commit is contained in:
Aliaksandr Valialkin 2024-01-31 02:32:02 +02:00
parent a0043e214f
commit 2033fe4caf
No known key found for this signature in database
GPG Key ID: 52C003EE2BCDB9EB
3 changed files with 8 additions and 4 deletions

View File

@ -257,7 +257,7 @@ func groupJoin(singleTimeseriesSide string, be *metricsql.BinaryOpExpr, rvsLeft,
var tsCopy timeseries var tsCopy timeseries
tsCopy.CopyFromShallowTimestamps(tsLeft) tsCopy.CopyFromShallowTimestamps(tsLeft)
tsCopy.MetricName.SetTags(joinTags, joinPrefix, skipTags, &tsRight.MetricName) tsCopy.MetricName.SetTags(joinTags, joinPrefix, skipTags, &tsRight.MetricName)
bb.B = marshalMetricTagsSorted(bb.B[:0], &tsCopy.MetricName) bb.B = marshalMetricNameSorted(bb.B[:0], &tsCopy.MetricName)
pair, ok := m[string(bb.B)] pair, ok := m[string(bb.B)]
if !ok { if !ok {
m[string(bb.B)] = &tsPair{ m[string(bb.B)] = &tsPair{
@ -522,7 +522,9 @@ func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*time
mn := storage.GetMetricName() mn := storage.GetMetricName()
for _, ts := range arg { for _, ts := range arg {
mn.CopyFrom(&ts.MetricName) mn.CopyFrom(&ts.MetricName)
if !be.KeepMetricNames {
mn.ResetMetricGroup() mn.ResetMetricGroup()
}
switch groupOp { switch groupOp {
case "on": case "on":
mn.RemoveTagsOn(groupTags) mn.RemoveTagsOn(groupTags)
@ -531,7 +533,7 @@ func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*time
default: default:
logger.Panicf("BUG: unexpected binary op modifier %q", groupOp) logger.Panicf("BUG: unexpected binary op modifier %q", groupOp)
} }
bb.B = marshalMetricTagsSorted(bb.B[:0], mn) bb.B = marshalMetricNameSorted(bb.B[:0], mn)
k := string(bb.B) k := string(bb.B)
m[k] = append(m[k], ts) m[k] = append(m[k], ts)
} }

View File

@ -3716,7 +3716,7 @@ func TestExecSuccess(t *testing.T) {
q := `( q := `(
(label_set(time(), "t1", "v1", "__name__", "q1") or label_set(10, "t2", "v2", "__name__", "q2")) (label_set(time(), "t1", "v1", "__name__", "q1") or label_set(10, "t2", "v2", "__name__", "q2"))
+ +
(label_set(100, "t1", "v1", "__name__", "q3") or label_set(time(), "t2", "v3")) (label_set(100, "t1", "v1", "__name__", "q1") or label_set(time(), "t2", "v3"))
) keep_metric_names` ) keep_metric_names`
r := netstorage.Result{ r := netstorage.Result{
MetricName: metricNameExpected, MetricName: metricNameExpected,

View File

@ -28,6 +28,8 @@ The sandbox cluster installation is running under the constant load generated by
## tip ## tip
* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly handle `avg_over_time({some_filter}[d]) keep_metric_names` queries, where [`some_filter`](https://docs.victoriametrics.com/keyconcepts/#filtering) matches multiple time series with multiple names, while `d` is bigger or equal to `3h`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5556).
## [v1.97.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.97.0) ## [v1.97.0](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.97.0)
Released at 2024-01-30 Released at 2024-01-30