From f3c171b32b4303894850e810812b9b239aaf36de Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Thu, 28 Mar 2024 07:55:50 +0530 Subject: [PATCH] Add reason tag to duration metrics Added reason tag to duration metrics. Different failures cause difference in duration of pipelineruns and taskruns. --- pkg/pipelinerunmetrics/metrics.go | 10 ++++++---- pkg/pipelinerunmetrics/metrics_test.go | 2 ++ pkg/taskrunmetrics/metrics.go | 10 ++++++---- pkg/taskrunmetrics/metrics_test.go | 1 + 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/pipelinerunmetrics/metrics.go b/pkg/pipelinerunmetrics/metrics.go index 4794bc8955e..3a99a917d4e 100644 --- a/pkg/pipelinerunmetrics/metrics.go +++ b/pkg/pipelinerunmetrics/metrics.go @@ -154,6 +154,12 @@ func viewRegister(cfg *config.Metrics) error { } } + prCountViewTags := []tag.Key{statusTag} + if cfg.CountWithReason { + prCountViewTags = append(prCountViewTags, reasonTag) + prunTag = append(prunTag, reasonTag) + } + prDurationView = &view.View{ Description: prDuration.Description(), Measure: prDuration, @@ -161,10 +167,6 @@ func viewRegister(cfg *config.Metrics) error { TagKeys: append([]tag.Key{statusTag, namespaceTag}, prunTag...), } - prCountViewTags := []tag.Key{statusTag} - if cfg.CountWithReason { - prCountViewTags = append(prCountViewTags, reasonTag) - } prCountView = &view.View{ Description: prCount.Description(), Measure: prCount, diff --git a/pkg/pipelinerunmetrics/metrics_test.go b/pkg/pipelinerunmetrics/metrics_test.go index 6e96fe84006..cdf9c809308 100644 --- a/pkg/pipelinerunmetrics/metrics_test.go +++ b/pkg/pipelinerunmetrics/metrics_test.go @@ -339,6 +339,7 @@ func TestRecordPipelineRunDurationCount(t *testing.T) { "pipeline": "pipeline-1", "pipelinerun": "pipelinerun-1", "namespace": "ns", + "reason": "Failed", "status": "failed", }, expectedCountTags: map[string]string{ @@ -375,6 +376,7 @@ func TestRecordPipelineRunDurationCount(t *testing.T) { "pipelinerun": "pipelinerun-1", "namespace": "ns", "status": "cancelled", + "reason": ReasonCancelled.String(), }, expectedCountTags: map[string]string{ "status": "cancelled", diff --git a/pkg/taskrunmetrics/metrics.go b/pkg/taskrunmetrics/metrics.go index e5b251b497d..41338b00e53 100644 --- a/pkg/taskrunmetrics/metrics.go +++ b/pkg/taskrunmetrics/metrics.go @@ -192,6 +192,12 @@ func viewRegister(cfg *config.Metrics) error { } } + trCountViewTags := []tag.Key{statusTag} + if cfg.CountWithReason { + trCountViewTags = append(trCountViewTags, reasonTag) + trunTag = append(trunTag, reasonTag) + } + trDurationView = &view.View{ Description: trDuration.Description(), Measure: trDuration, @@ -205,10 +211,6 @@ func viewRegister(cfg *config.Metrics) error { TagKeys: append([]tag.Key{statusTag, namespaceTag}, append(trunTag, prunTag...)...), } - trCountViewTags := []tag.Key{statusTag} - if cfg.CountWithReason { - trCountViewTags = append(trCountViewTags, reasonTag) - } trCountView = &view.View{ Description: trCount.Description(), Measure: trCount, diff --git a/pkg/taskrunmetrics/metrics_test.go b/pkg/taskrunmetrics/metrics_test.go index 437fd032846..63498ebfdff 100644 --- a/pkg/taskrunmetrics/metrics_test.go +++ b/pkg/taskrunmetrics/metrics_test.go @@ -390,6 +390,7 @@ func TestRecordTaskRunDurationCount(t *testing.T) { "task": "task-1", "taskrun": "taskrun-1", "namespace": "ns", + "reason": "TaskRunImagePullFailed", "status": "failed", }, expectedCountTags: map[string]string{