From 1d4a87eea44f6a5fc5c8982c6c3432eab3fed98c Mon Sep 17 00:00:00 2001 From: Spencer Henry Date: Mon, 10 Oct 2022 09:34:34 -0600 Subject: [PATCH] condense metrics and use a result label Signed-off-by: Spencer Henry --- .changeset/flat-items-perform.md | 22 ++++---------- .../tasks/NunjucksWorkflowRunner.ts | 30 ++++++++----------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/.changeset/flat-items-perform.md b/.changeset/flat-items-perform.md index 949814c064..ce5b95c7ca 100644 --- a/.changeset/flat-items-perform.md +++ b/.changeset/flat-items-perform.md @@ -4,19 +4,13 @@ Added a set of default Prometheus metrics around scaffolding. See below for a list of metrics and an explanation of their labels: -- `scaffolder_task_success_count`: Tracks successful task runs. - - Labels: - - - `template`: The entity ref of the scaffolded template - - `user`: The entity ref of the user that invoked the template run - -- `scaffolder_task_error_count`: a count that track how many task runs error out +- `scaffolder_task_count`: Tracks successful task runs. Labels: - `template`: The entity ref of the scaffolded template - `user`: The entity ref of the user that invoked the template run + - `result`: A string describing whether the task ran successfully, errored out, or was skipped - `scaffolder_task_duration`: a histogram which tracks the duration of a task run @@ -25,19 +19,13 @@ Added a set of default Prometheus metrics around scaffolding. See below for a li - `template`: The entity ref of the scaffolded template - `result`: A boolean describing whether the task ran successfully -- `scaffolder_step_success_count`: a count that tracks each step run - - Labels: - - - `template`: The entity ref of the scaffolded template - - `step`: The name of the step that was run - -- `scaffolder_step_error_count`: a count that tracks how many steps error out +- `scaffolder_step_count`: a count that tracks each step run Labels: - `template`: The entity ref of the scaffolded template - `step`: The name of the step that was run + - `result`: A string describing whether the task ran successfully, errored out, or was skipped - `scaffolder_step_duration`: a histogram which tracks the duration of each step run @@ -45,6 +33,6 @@ Added a set of default Prometheus metrics around scaffolding. See below for a li - `template`: The entity ref of the scaffolded template - `step`: The name of the step that was run - - `result`: A boolean describing whether the task ran successfully + - `result`: A string describing whether the task ran successfully, errored out, or was skipped You can find a guide for running Prometheus metrics here: https://github.com/backstage/backstage/blob/master/contrib/docs/tutorials/prometheus-metrics.md diff --git a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts index f4776bc033..a63bb48694 100644 --- a/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts +++ b/plugins/scaffolder-backend/src/scaffolder/tasks/NunjucksWorkflowRunner.ts @@ -354,30 +354,20 @@ export class NunjucksWorkflowRunner implements WorkflowRunner { } function scaffoldingTracker() { - const taskSuccesses = createCounterMetric({ + const taskCount = createCounterMetric({ name: 'scaffolder_task_success_count', help: 'Count of succesful task runs', - labelNames: ['template', 'user'], - }); - const taskErrors = createCounterMetric({ - name: 'scaffolder_task_error_count', - help: 'Count of failed task runs', - labelNames: ['template', 'user'], + labelNames: ['template', 'user', 'result'], }); const taskDuration = createHistogramMetric({ name: 'scaffolder_task_duration', help: 'Duration of a task run', labelNames: ['template', 'result'], }); - const stepSuccesses = createCounterMetric({ + const stepCount = createCounterMetric({ name: 'scaffolder_step_success_count', help: 'Count of successful step runs', - labelNames: ['template', 'step'], - }); - const stepErrors = createCounterMetric({ - name: 'scaffolder_step_error_count', - help: 'Count of failed step runs', - labelNames: ['template', 'step'], + labelNames: ['template', 'step', 'result'], }); const stepDuration = createHistogramMetric({ name: 'scaffolder_step_duration', @@ -405,9 +395,10 @@ function scaffoldingTracker() { } function markSuccessful() { - taskSuccesses.inc({ + taskCount.inc({ template, user, + result: 'ok' }); taskTimer({ result: 'ok' }); } @@ -417,9 +408,10 @@ function scaffoldingTracker() { stepId: step.id, status: 'failed', }); - taskErrors.inc({ + taskCount.inc({ template, user, + result: 'failed' }); taskTimer({ result: 'failed' }); } @@ -448,17 +440,19 @@ function scaffoldingTracker() { stepId: step.id, status: 'completed', }); - stepSuccesses.inc({ + stepCount.inc({ template, step: step.name, + result: 'ok' }); stepTimer({ result: 'ok' }); } function markFailed() { - stepErrors.inc({ + stepCount.inc({ template, step: step.name, + result: 'failed' }); stepTimer({ result: 'failed' }); }