@@ -107,19 +107,18 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
107
107
repoExists bool
108
108
)
109
109
start := time .Now ()
110
- defer func () {
111
- globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
112
- }()
113
110
114
111
detailedErrorGitOpsConfigActions .StageErrorMap = make (map [string ]error )
115
112
url , repoExists , isEmpty , err = impl .repoExists (config .GitRepoName , impl .project )
116
113
if err != nil {
117
114
impl .logger .Errorw ("error in communication with azure" , "err" , err )
118
115
detailedErrorGitOpsConfigActions .StageErrorMap [GetRepoUrlStage ] = err
116
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
119
117
return "" , false , isEmpty , detailedErrorGitOpsConfigActions
120
118
}
121
119
if repoExists {
122
120
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , GetRepoUrlStage )
121
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , nil )
123
122
return url , false , isEmpty , detailedErrorGitOpsConfigActions
124
123
}
125
124
gitRepositoryCreateOptions := git.GitRepositoryCreateOptions {
@@ -138,6 +137,7 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
138
137
impl .logger .Errorw ("error in communication with azure" , "err" , err )
139
138
}
140
139
if err != nil || ! repoExists {
140
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
141
141
return "" , true , isEmpty , detailedErrorGitOpsConfigActions
142
142
}
143
143
}
@@ -146,11 +146,14 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
146
146
validated , err := impl .ensureProjectAvailabilityOnHttp (config .GitRepoName )
147
147
if err != nil {
148
148
impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
149
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
149
150
detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] = err
150
151
return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
151
152
}
152
153
if ! validated {
153
- detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
154
+ err = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
155
+ detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] = err
156
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
154
157
return "" , true , isEmpty , detailedErrorGitOpsConfigActions
155
158
}
156
159
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneHttpStage )
@@ -159,6 +162,7 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
159
162
if err != nil {
160
163
impl .logger .Errorw ("error in creating readme azure" , "project" , config .GitRepoName , "err" , err )
161
164
detailedErrorGitOpsConfigActions .StageErrorMap [CreateReadmeStage ] = err
165
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
162
166
return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
163
167
}
164
168
isEmpty = false //As we have created readme, repo is no longer empty
@@ -167,13 +171,17 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
167
171
if err != nil {
168
172
impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
169
173
detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] = err
174
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
170
175
return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
171
176
}
172
177
if ! validated {
173
- detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
178
+ err = fmt .Errorf ("unable to validate project:%s in given time" , config .GitRepoName )
179
+ detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] = err
180
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
174
181
return "" , true , isEmpty , detailedErrorGitOpsConfigActions
175
182
}
176
183
detailedErrorGitOpsConfigActions .SuccessfulStages = append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneSshStage )
184
+ globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , nil )
177
185
return * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions
178
186
}
179
187
@@ -196,14 +204,15 @@ func (impl GitAzureClient) CreateReadme(ctx context.Context, config *bean2.GitOp
196
204
UserName : config .Username ,
197
205
UserEmailId : config .UserEmailId ,
198
206
}
199
- hash , _ , err := impl .CommitValues (ctx , cfg , config )
207
+ hash , _ , err := impl .CommitValues (ctx , cfg , config , true )
200
208
if err != nil {
201
209
impl .logger .Errorw ("error in creating readme azure" , "repo" , config .GitRepoName , "err" , err )
202
210
}
203
211
return hash , err
204
212
}
205
213
206
- func (impl GitAzureClient ) CommitValues (ctx context.Context , config * ChartConfig , gitOpsConfig * bean2.GitOpsConfigDto ) (commitHash string , commitTime time.Time , err error ) {
214
+ func (impl GitAzureClient ) CommitValues (ctx context.Context , config * ChartConfig , gitOpsConfig * bean2.GitOpsConfigDto , publishStatusConflictError bool ) (commitHash string , commitTime time.Time , err error ) {
215
+ start := time .Now ()
207
216
branch := config .TargetRevision
208
217
if len (branch ) == 0 {
209
218
branch = globalUtil .GetDefaultTargetRevision ()
@@ -229,13 +238,15 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
229
238
if err != nil {
230
239
if e , ok := err .(azuredevops.WrappedError ); ! ok || * e .StatusCode >= 500 {
231
240
impl .logger .Errorw ("error in fetching branch from azure devops" , "err" , err )
241
+ globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
232
242
return "" , time.Time {}, err
233
243
}
234
244
} else if branchStat != nil {
235
245
oldObjId = * branchStat .Commit .CommitId
236
246
}
237
247
} else {
238
248
impl .logger .Errorw ("error in fetching file from azure devops" , "err" , err )
249
+ globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
239
250
return "" , time.Time {}, err
240
251
}
241
252
} else {
@@ -292,9 +303,13 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
292
303
})
293
304
if e := (azuredevops.WrappedError {}); errors .As (err , & e ) && e .StatusCode != nil && * e .StatusCode == http2 .StatusConflict {
294
305
impl .logger .Warn ("conflict found in commit azure" , "err" , err , "config" , config )
306
+ if publishStatusConflictError {
307
+ globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
308
+ }
295
309
return "" , time.Time {}, retryFunc .NewRetryableError (err )
296
310
} else if err != nil {
297
311
impl .logger .Errorw ("error in commit azure" , "err" , err )
312
+ globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
298
313
return "" , time.Time {}, err
299
314
}
300
315
//gitPush.Commits
@@ -305,6 +320,7 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
305
320
commitAuthorTime = (* push .Commits )[0 ].Author .Date .Time
306
321
}
307
322
// push.Commits[0].CommitId
323
+ globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , nil )
308
324
return commitId , commitAuthorTime , nil
309
325
}
310
326
0 commit comments