chore: fixing changeset

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-10-02 14:06:50 +02:00
parent 6916c4b291
commit 0dada05a78
2 changed files with 15 additions and 5 deletions
+6 -1
View File
@@ -2,4 +2,9 @@
'@backstage/backend-tasks': patch
---
Instrument `backend-tasks` with some counters and histograms for duration
Instrument `backend-tasks` with some counters and histograms for duration.
`backend_task_runs_total`: Counter with the total number of times a task has been run.
`backend_task_run_duration`: Histogram with the run durations for each task.
Both these metrics have come with `result` `taskId` and `scope` labels for finer grained grouping andd
@@ -30,6 +30,7 @@ import {
import { validateId } from './util';
import { TaskFunction } from './types';
import { metrics, Counter, Histogram } from '@opentelemetry/api';
/**
* Implements the actual task management.
*/
@@ -122,20 +123,24 @@ export class PluginTaskSchedulerImpl implements PluginTaskScheduler {
opts: { labels: Record<string, string> },
): TaskFunction {
return async abort => {
this.counter.add(1, { ...opts.labels, result: 'started' });
const labels = {
...opts.labels,
};
this.counter.add(1, { ...labels, result: 'started' });
const startTime = process.hrtime();
try {
await fn(abort);
this.counter.add(1, { ...opts.labels, result: 'completed' });
labels.result = 'completed';
} catch (ex) {
this.counter.add(1, { ...opts.labels, result: 'failed' });
labels.result = 'failed';
throw ex;
} finally {
const delta = process.hrtime(startTime);
const endTime = delta[0] + delta[1] / 1e9;
this.duration.record(endTime, { ...opts.labels });
this.counter.add(1, labels);
this.duration.record(endTime, labels);
}
};
}