I need a query to summarise data from two different metrics, both of the same field type, with the following rules:
- If a type does not exist in metric_a, return metric_b’s result
- If a type does not exist in metric_b, return metric_a’s result
Problem Statement
I need a query to summarise data from two different metrics, metric_a
and metric_b
, both of which have the same field type. The query should adhere to the following rules:
- If a type does not exist in
metric_a
, returnmetric_b
’s result - If a type does not exist in
metric_b
, returnmetric_a
’s result
Examples
Scenario 1
metric_a :
- type = type_1, sum = 5
- type = type_2, sum = 2
metric_b :
- type = type_1, sum = 4
- type = type_3, sum = 3
Expected result:
- type = type_1, sum = 9
- type = type_2, sum = 2
- type = type_3, sum = 3
Attempted Solutions
-
sum by (type)(metric_a{job=~"provision-dev"}) or vector(0) + sum by(type)(metric_b{job=~"provision-dev"}) or vector(0)
: returns only the values frommetric_a
, and doesn’t calculatemetric_b
’s results. -
sum by (type)(metric_a{job=~"provision-dev"}) + sum by(type)(metric_b{job=~"provision-dev"})
: returns only the values frommetric_b
, and doesn’t calculatemetric_a
’s results. -
sum by (cluster_id)(provision_scale_out_failures{job=~"provision-dev"} + provision_scale_out_success{job=~"provision-dev"})
: this isn’t a valid query.