Skip to content

Commit 976f927

Browse files
committed
Add build and release success summary metric
- add azure_devops_stats_project_builds_success - azure_devops_stats_project_release_success Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
1 parent 32d781c commit 976f927

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ Metrics
9595
| `azure_devops_stats_agentpool_builds_duration` | stats | Build duration per agentpool, project and result (summary) |
9696
| `azure_devops_stats_project_builds` | stats | Number of builds per project, definition and result (counter) |
9797
| `azure_devops_stats_project_builds_wait` | stats | Build wait time per project, definition and result (summary) |
98+
| `azure_devops_stats_project_builds_success` | stats | Success rating of build per project and definition (summary) |
9899
| `azure_devops_stats_project_builds_duration` | stats | Build duration per project, definition and result (summary) |
99100
| `azure_devops_stats_project_release_duration` | stats | Release environment duration per project, definition, environment and result (summary) |
101+
| `azure_devops_stats_project_release_success` | stats | Success rating of release environment per project, definition and environment (summary) |
100102
| `azure_devops_resourceusage_build` | resourceusage | Usage of limited and paid Azure DevOps resources (build) |
101103
| `azure_devops_resourceusage_license` | resourceusage | Usage of limited and paid Azure DevOps resources (license) |
102104

metrics_stats.go

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ type MetricsCollectorStats struct {
1818
projectBuildCount *prometheus.CounterVec
1919
projectBuildWait *prometheus.SummaryVec
2020
projectBuildDuration *prometheus.SummaryVec
21+
projectBuildSuccess *prometheus.SummaryVec
2122
projectReleaseDuration *prometheus.SummaryVec
23+
projectReleaseSuccess *prometheus.SummaryVec
2224
}
2325
}
2426

@@ -87,6 +89,18 @@ func (m *MetricsCollectorStats) Setup(collector *CollectorProject) {
8789
)
8890
prometheus.MustRegister(m.prometheus.projectBuildCount)
8991

92+
m.prometheus.projectBuildSuccess = prometheus.NewSummaryVec(
93+
prometheus.SummaryOpts{
94+
Name: "azure_devops_stats_project_success",
95+
Help: "Azure DevOps stats project success",
96+
},
97+
[]string{
98+
"projectID",
99+
"buildDefinitionID",
100+
},
101+
)
102+
prometheus.MustRegister(m.prometheus.projectBuildSuccess)
103+
90104
m.prometheus.projectBuildWait = prometheus.NewSummaryVec(
91105
prometheus.SummaryOpts{
92106
Name: "azure_devops_stats_project_builds_wait",
@@ -129,6 +143,20 @@ func (m *MetricsCollectorStats) Setup(collector *CollectorProject) {
129143
},
130144
)
131145
prometheus.MustRegister(m.prometheus.projectReleaseDuration)
146+
147+
m.prometheus.projectReleaseSuccess = prometheus.NewSummaryVec(
148+
prometheus.SummaryOpts{
149+
Name: "azure_devops_stats_project_release_success",
150+
Help: "Azure DevOps stats project release success",
151+
MaxAge: *opts.Stats.SummaryMaxAge,
152+
},
153+
[]string{
154+
"projectID",
155+
"releaseDefinitionID",
156+
"definitionEnvironmentID",
157+
},
158+
)
159+
prometheus.MustRegister(m.prometheus.projectReleaseSuccess)
132160
}
133161

134162
func (m *MetricsCollectorStats) Reset() {
@@ -150,8 +178,22 @@ func (m *MetricsCollectorStats) CollectReleases(ctx context.Context, logger *log
150178

151179
for _, release := range releaseList.List {
152180
for _, environment := range release.Environments {
153-
timeToDeploy := environment.TimeToDeploy * 60
181+
switch environment.Status {
182+
case "succeeded":
183+
m.prometheus.projectReleaseSuccess.With(prometheus.Labels{
184+
"projectID": release.Project.Id,
185+
"releaseDefinitionID": int64ToString(release.Definition.Id),
186+
"definitionEnvironmentID": int64ToString(environment.DefinitionEnvironmentId),
187+
}).Observe(1)
188+
case "failed","partiallySucceeded":
189+
m.prometheus.projectReleaseSuccess.With(prometheus.Labels{
190+
"projectID": release.Project.Id,
191+
"releaseDefinitionID": int64ToString(release.Definition.Id),
192+
"definitionEnvironmentID": int64ToString(environment.DefinitionEnvironmentId),
193+
}).Observe(0)
194+
}
154195

196+
timeToDeploy := environment.TimeToDeploy * 60
155197
if timeToDeploy > 0 {
156198
m.prometheus.projectReleaseDuration.With(prometheus.Labels{
157199
"projectID": release.Project.Id,
@@ -188,6 +230,19 @@ func (m *MetricsCollectorStats) CollectBuilds(ctx context.Context, logger *log.E
188230
"result": build.Result,
189231
}).Inc()
190232

233+
switch build.Result {
234+
case "succeeded":
235+
m.prometheus.projectBuildSuccess.With(prometheus.Labels{
236+
"projectID": build.Project.Id,
237+
"buildDefinitionID": int64ToString(build.Definition.Id),
238+
}).Observe(1)
239+
case "failed":
240+
m.prometheus.projectBuildSuccess.With(prometheus.Labels{
241+
"projectID": build.Project.Id,
242+
"buildDefinitionID": int64ToString(build.Definition.Id),
243+
}).Observe(0)
244+
}
245+
191246
if build.FinishTime.Second() >= 0 {
192247
jobDuration := build.FinishTime.Sub(build.StartTime)
193248

0 commit comments

Comments
 (0)