VictoriaMetrics, MetricsQL - Omit certain labels when computing aggregate function

70 Views Asked by At

I have a working Victoria Metrics query:

avg_over_time(label_1{label_id_1 = "123", label_id_2 = "456"} [100s])

This almost all the time returns one value (vector). However, when the timeseries has a different version, it returns two values which is not desired. Eg:

[
  {
    "metric": {
      "__name__": "label_1",
      "version": "1",
      "label_id_1": "123",
      "label_id_2": "456",
    },
    "value": [
      1710597352.247,
      "2986.54887451"
    ],
    "group": 1
  },
  {
    "metric": {
      "__name__": "label_1",
      "version": "2",
      "label_id_1": "123",
      "label_id_2": "456",
    },
    "value": [
      1710597352.247,
      "369872.158964"
    ],
    "group": 1
  }
]

Is there a way to compute the average without the version label so that I get back a single value every time?

The expected result should be this way (value here is arbitrary):

[
{
    "metric": {
      "__name__": "label_1",
      "label_id_1": "123",
      "label_id_2": "456",
    },
    "value": [
      1710597352.247,
      "12346579.46694"
    ],
    "group": 1
  }]
1

There are 1 best solutions below

10
hagen1778 On

Looks like you have two distinct time series in your data, and version label is what makes them distinct. You can't simply get rid of it. You need to decide how you want your rollup function to compute this:

  1. Compute only one specific version: avg_over_time(label_1{label_id_1="123",label_id_2="456",version="1"}[100s])
  2. Select max or min, or other aggregation across versions avg(avg_over_time(label_1{label_id_1="123",label_id_2="456"}[100s])) without(version)