@@ -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
134162func (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