Search code examples
prometheusgrafanapromql

Grafana expression suddently says 2 items dropped from union(s)


After upgrading from Grafana 10.1 to 10.2, some panels stopped working.
More specifically, the expression $A + $B * -1 stopped working and gave a warning:

2 items dropped from union(s): ...

enter image description here Any idea why?

I am no promql ninja, is there a way to get those metrics in a single query?


Solution

  • I don't know why it stopped working, and if I had to guess, I'd say it shouldn't be working at all. Reasoning: your metrics have different labelsets.

    If all you need is to get result of subtraction of metric with "positive" label from "negative" one, you can use following promql query:

    badin42_energy_power{direction="negative"} - ignoring(direction) badin42_energy_power{direction="positive"}
    

    Here we are using ignoring keyword, to make Prometheus match two metrics based on all labels except for the direction.