@@ -17,6 +17,7 @@ type MetricsCollectorStats struct {
1717 projectBuildCount * prometheus.CounterVec
1818 projectBuildWait * prometheus.SummaryVec
1919 projectBuildDuration * prometheus.SummaryVec
20+ projectReleaseDuration * prometheus.SummaryVec
2021 }
2122}
2223
@@ -107,20 +108,63 @@ func (m *MetricsCollectorStats) Setup(collector *CollectorProject) {
107108 },
108109 )
109110
111+ m .prometheus .projectReleaseDuration = prometheus .NewSummaryVec (
112+ prometheus.SummaryOpts {
113+ Name : "azure_devops_stats_project_release_duration" ,
114+ Help : "Azure DevOps stats project release process duration" ,
115+ MaxAge : * opts .StatsSummaryMaxAge ,
116+ },
117+ []string {
118+ "projectID" ,
119+ "releaseDefinitionID" ,
120+ "definitionEnvironmentID" ,
121+ "status" ,
122+ },
123+ )
124+
125+
110126 prometheus .MustRegister (m .prometheus .agentPoolBuildCount )
111127 prometheus .MustRegister (m .prometheus .agentPoolBuildWait )
112128 prometheus .MustRegister (m .prometheus .agentPoolBuildDuration )
113129
114130 prometheus .MustRegister (m .prometheus .projectBuildCount )
115131 prometheus .MustRegister (m .prometheus .projectBuildWait )
116132 prometheus .MustRegister (m .prometheus .projectBuildDuration )
133+
134+ prometheus .MustRegister (m .prometheus .projectReleaseDuration )
117135}
118136
119137func (m * MetricsCollectorStats ) Reset () {
120138}
121139
122140func (m * MetricsCollectorStats ) Collect (ctx context.Context , callback chan <- func (), project devopsClient.Project ) {
123141 m .CollectBuilds (ctx , callback , project )
142+ m .CollectReleases (ctx , callback , project )
143+ }
144+
145+ func (m * MetricsCollectorStats ) CollectReleases (ctx context.Context , callback chan <- func (), project devopsClient.Project ) {
146+ minTime := * m .CollectorReference .collectionLastTime
147+
148+ releaseList , err := AzureDevopsClient .ListLatestReleases (project .Id , minTime )
149+ if err != nil {
150+ Logger .Errorf ("project[%v]call[ListLatestReleases]: %v" , project .Name , err )
151+ return
152+ }
153+
154+ for _ , release := range releaseList .List {
155+ for _ , environment := range release .Environments {
156+ timeToDeploy := environment .TimeToDeploy * 60
157+
158+ if timeToDeploy > 0 {
159+ m .prometheus .projectReleaseDuration .With (prometheus.Labels {
160+ "projectID" : release .Project .Id ,
161+ "releaseDefinitionID" : int64ToString (release .Definition .Id ),
162+ "definitionEnvironmentID" : int64ToString (environment .DefinitionEnvironmentId ),
163+ "status" : environment .Status ,
164+ }).Observe (timeToDeploy )
165+ }
166+ }
167+ }
124168}
125169
126170func (m * MetricsCollectorStats ) CollectBuilds (ctx context.Context , callback chan <- func (), project devopsClient.Project ) {
0 commit comments