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 Apr 5, 2024
1 parent 82816c3 commit 292cc22
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 @@ -174,17 +174,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 @@ -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,
Expand All @@ -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,
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 292cc22

Please sign in to comment.