Skip to content

Commit

Permalink
Add reason tag to duration metrics
Browse files Browse the repository at this point in the history
Added reason tag to duration metrics. Different failures cause difference
in duration of pipelineruns and taskruns.
  • Loading branch information
khrm committed Mar 28, 2024
1 parent ab47f4e commit f3c171b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
10 changes: 6 additions & 4 deletions pkg/pipelinerunmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,19 @@ 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,
Aggregation: distribution,
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,
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipelinerunmetrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions pkg/taskrunmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pkg/taskrunmetrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit f3c171b

Please sign in to comment.