I need to build a Grafana chart that shows the number of completed test runs by status for a specific branch. For example, over the last 12 hours for the develop branch, 12 runs passed and 3 runs failed.
I have a Gauge metric defined in TypeScript:
this.runStatusGauge = new Gauge({
name: 'test_run_status',
help: 'Test run status',
labelNames: ['runName', 'status'],
registers: [this.register],
});
I always set this metric to 1, only changing the status label:
this.runStatusGauge.set(
{
runName: this.runName,
status: '<passed or failed>',
},
1,
);
Then I group the metric like this and push to Pushgateway:
await this.pushgateway.pushAdd({
jobName: this.jobName,
groupings: {
env: this.options.env,
projectName: this.projectName || 'undefined project',
branchName: this.branchName,
},
});
As a result, Prometheus receives metrics such as:
test_run_status{
branchName="local-new",
env="staging",
exported_env="staging",
exported_job="pw_metrics",
instance="",
job="external-pushgateway",
project="",
projectName="widget",
runName="Local run name 5f99692c-32df-4d33-89f9-d2ddee90c1d9",
service="",
source="",
status="failed"
} 1
I’m trying to build a Pie Chart in Grafana, but it always shows separate values for each status, and they are always equal to 1. How can I make it display the total number of runs per status correctly?
I need to build a Grafana chart that shows the number of completed test runs by status for a specific branch. For example, over the last 12 hours for the develop branch, 12 runs passed and 3 runs failed.
I have a Gauge metric defined in TypeScript:
this.runStatusGauge = new Gauge({
name: 'test_run_status',
help: 'Test run status',
labelNames: ['runName', 'status'],
registers: [this.register],
});
I always set this metric to 1, only changing the status label:
this.runStatusGauge.set(
{
runName: this.runName,
status: '<passed or failed>',
},
1,
);
Then I group the metric like this and push to Pushgateway:
await this.pushgateway.pushAdd({
jobName: this.jobName,
groupings: {
env: this.options.env,
projectName: this.projectName || 'undefined project',
branchName: this.branchName,
},
});
As a result, Prometheus receives metrics such as:
test_run_status{
branchName="local-new",
env="staging",
exported_env="staging",
exported_job="pw_metrics",
instance="",
job="external-pushgateway",
project="",
projectName="widget",
runName="Local run name 5f99692c-32df-4d33-89f9-d2ddee90c1d9",
service="",
source="",
status="failed"
} 1
I’m trying to build a Pie Chart in Grafana, but it always shows separate values for each status, and they are always equal to 1. How can I make it display the total number of runs per status correctly?
Resolved this issue =)
I just added additional query and added filter by status for each query and now its work right for all time ranges.
count_values
. On the other hand, looking more closely into your metrics - I'd say Prometheus is a wrong tool for the job. It looks like you don't want metrics, but rather per run info (and metrics, and especially Prometheus, don't play with that idea well). Consider logging systems instead. For example, Loki is similar to prometheus (with similar query lang), but is specifically designed for logs. – markalex Commented Jan 16 at 23:08