I am attempting to display historical metrics of test results in Grafana Bar Chart using Prometheus as a data source. The goal is to display a summary of failed/passed test cases per day/build_id (date serves as build id here since this only concerns daily builds). In detail I am attempting to make the x-axis of the chart display values of ‘date’ label of the metrics I am filtering with a query.
Here’s a description of what I am trying to achieve:
A typical set of metrics would look something like this:
{_name_=”test_foo_bar_1″, date=”2024-07-01″, instance=”localhost:8000″, job=”build_metrics”, status=”1″}
{_name_=”test_foo_bar_2″, date=”2024-07-01″, instance=”localhost:8000″, job=”build_metrics”, status=”0″}
{_name_=”test_foo_bar_1″, date=”2024-07-02″, instance=”localhost:8000″, job=”build_metrics”, status=”1″}
{_name_=”test_foo_bar_2″, date=”2024-07-02″, instance=”localhost:8000″, job=”build_metrics”, status=”0″}
Where their values would be the duration the test took to complete. These value alone should generate a bar chart with 4 bars grouped into 2 rows(or columns). These rows would be row ‘2024-07-01’ and row ‘2024-07-02’ and the 2 bars of each such row would display a number of metrics which have status ‘1’ or ‘0’(marking whether the test passed of failed).
Here’s what I have tried:
This is promql I have tried to query metrics for this chart:
count({name=~”^test.*”}) by (date)
Where date is a label of each metric starting whose name starts with ‘test’. Date contains the day when the build was executed formatted like so: yyyy-mm-dd
What I am getting now
As you can see, the X-Axis is based on time variable, not values of ‘date’ label. Setting for X-Axis does not show all of the label values, only each individual values and even then only if the promql query contain ‘by (date)’ part.
Shown here: enter image description here
Using this setting also doesn’t resemble anything like the bar chart described above.