From 292cc2215b9b0c77c8290d7f54c8a4ec55bc1fd1 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 b389cf4907b..c89428bd67f 100644 --- a/pkg/pipelinerunmetrics/metrics.go +++ b/pkg/pipelinerunmetrics/metrics.go @@ -174,6 +174,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, @@ -181,10 +187,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 5a7c757e512..0633335008a 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 d60b5e567f9..1de022456f9 100644 --- a/pkg/taskrunmetrics/metrics.go +++ b/pkg/taskrunmetrics/metrics.go @@ -212,6 +212,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, @@ -225,10 +231,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 c7e581d8962..012096dd7a0 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{