Get 0 for `count by` calculation when grouped label goes away

  • What Grafana version and what operating system are you using?

Grafana 11.1 (Docker Image)

  • What are you trying to achieve?

Show a plot of the distribution of OS versions within all nodes.
Additionally, the legend (table format) should display the numerical value of how many nodes currently run each OS version.

  • How are you trying to achieve it?

The OS version distribution is determined using count by(image_version) which works good for the plot and the “Last *” reducer for the table legend.

  • What happened?

The “Last *” reducer returns the most recent value where the group still had members instead of 0.

  • What did you expect to happen?

The “Last *” reducer should use 0 for the value — or the count by() statement should return 0 once the group has no more members

  • Can you copy/paste the configuration(s) that you are having problems with?

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

n/a

  • Did you follow any online instructions? If so, what is the URL?

No

  • Others

Alternatively I could split this into two panels and use e.g. a pie chart for the instantaneous data. However, that has the problem that the series are now colored differently (the blue are in the pie chart corresponds to the orange area in the timeline):

Using “Classic palette (by series name)” also does not work because then everything has the same color: