I would like aggregate a metric with the maximum number of another metric.
Metric 1:
0:00 | 0:01 | 0:02 | |
---|---|---|---|
Instance 1 | 1 | 1 | 1 |
Instance 2 | 2 | 2 |
2 |
Instance 3 | 3 |
3 | 3 |
Metric 2:
0:00 | 0:01 | 0:02 | |
---|---|---|---|
Instance 1 | 1 | 12 | 23 |
Instance 2 | 1 | 14 |
14 |
Instance 3 | 3 |
3 | 3 |
For example, the aggregated result from Metric 1 is (3,2,1)
.
The result using
max(metric2)
is (3,14,23)
and it can be mapping to (instance3, instance2, instance1)
. I would like to apply this result's instance back to metric1.
Query
metric1 and on(instance) topk(1, metric2)
will return data as you want it.
Here:
topk(1, metric2)
takes top 1 value of metric2
(for each timestamp independently). It is similar to max
, but preserves labels of original metric.and on(instance)
filters out results of metric1
based on presence of the respective label instance
in the right hand side.