diff --git a/app/vmselect/promql/binary_op.go b/app/vmselect/promql/binary_op.go index 3bf8ff5648..1c56173bdb 100644 --- a/app/vmselect/promql/binary_op.go +++ b/app/vmselect/promql/binary_op.go @@ -257,7 +257,7 @@ func groupJoin(singleTimeseriesSide string, be *metricsql.BinaryOpExpr, rvsLeft, var tsCopy timeseries tsCopy.CopyFromShallowTimestamps(tsLeft) 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)] if !ok { m[string(bb.B)] = &tsPair{ @@ -522,7 +522,9 @@ func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*time mn := storage.GetMetricName() for _, ts := range arg { mn.CopyFrom(&ts.MetricName) - mn.ResetMetricGroup() + if !be.KeepMetricNames { + mn.ResetMetricGroup() + } switch groupOp { case "on": mn.RemoveTagsOn(groupTags) @@ -531,7 +533,7 @@ func createTimeseriesMapByTagSet(be *metricsql.BinaryOpExpr, left, right []*time default: 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) m[k] = append(m[k], ts) } diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index a66f8093d4..a2b2532386 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -3716,7 +3716,7 @@ func TestExecSuccess(t *testing.T) { q := `( (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` r := netstorage.Result{ MetricName: metricNameExpected, diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a10f81ab18..1d8a4c7a53 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -28,6 +28,8 @@ The sandbox cluster installation is running under the constant load generated by ## 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) Released at 2024-01-30