Get total of metrics when value all time equal 1

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?

Hi,

can you share how your data looks in time series chart? Also can you share the config of the pie chart? :smile:

What I think is happening:

  • every series is a different piece of chart, so you might have 7 fails but those fails are for different branches / runs.
  • I think what you’d need to do that would be to only count by status, then you’d have failures and successes and control the runs by variables

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.
And added last_over_time function