@@ -107,19 +107,18 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
107107		repoExists  bool 
108108	)
109109	start  :=  time .Now ()
110- 	defer  func () {
111- 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
112- 	}()
113110
114111	detailedErrorGitOpsConfigActions .StageErrorMap  =  make (map [string ]error )
115112	url , repoExists , isEmpty , err  =  impl .repoExists (config .GitRepoName , impl .project )
116113	if  err  !=  nil  {
117114		impl .logger .Errorw ("error in communication with azure" , "err" , err )
118115		detailedErrorGitOpsConfigActions .StageErrorMap [GetRepoUrlStage ] =  err 
116+ 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
119117		return  "" , false , isEmpty , detailedErrorGitOpsConfigActions 
120118	}
121119	if  repoExists  {
122120		detailedErrorGitOpsConfigActions .SuccessfulStages  =  append (detailedErrorGitOpsConfigActions .SuccessfulStages , GetRepoUrlStage )
121+ 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , nil )
123122		return  url , false , isEmpty , detailedErrorGitOpsConfigActions 
124123	}
125124	gitRepositoryCreateOptions  :=  git.GitRepositoryCreateOptions {
@@ -138,6 +137,7 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
138137			impl .logger .Errorw ("error in communication with azure" , "err" , err )
139138		}
140139		if  err  !=  nil  ||  ! repoExists  {
140+ 			globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
141141			return  "" , true , isEmpty , detailedErrorGitOpsConfigActions 
142142		}
143143	}
@@ -146,11 +146,14 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
146146	validated , err  :=  impl .ensureProjectAvailabilityOnHttp (config .GitRepoName )
147147	if  err  !=  nil  {
148148		impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
149+ 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
149150		detailedErrorGitOpsConfigActions .StageErrorMap [CloneHttpStage ] =  err 
150151		return  * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions 
151152	}
152153	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 )
154157		return  "" , true , isEmpty , detailedErrorGitOpsConfigActions 
155158	}
156159	detailedErrorGitOpsConfigActions .SuccessfulStages  =  append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneHttpStage )
@@ -159,6 +162,7 @@ func (impl GitAzureClient) CreateRepository(ctx context.Context, config *bean2.G
159162	if  err  !=  nil  {
160163		impl .logger .Errorw ("error in creating readme azure" , "project" , config .GitRepoName , "err" , err )
161164		detailedErrorGitOpsConfigActions .StageErrorMap [CreateReadmeStage ] =  err 
165+ 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
162166		return  * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions 
163167	}
164168	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
167171	if  err  !=  nil  {
168172		impl .logger .Errorw ("error in ensuring project availability azure" , "project" , config .GitRepoName , "err" , err )
169173		detailedErrorGitOpsConfigActions .StageErrorMap [CloneSshStage ] =  err 
174+ 		globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , err )
170175		return  * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions 
171176	}
172177	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 )
174181		return  "" , true , isEmpty , detailedErrorGitOpsConfigActions 
175182	}
176183	detailedErrorGitOpsConfigActions .SuccessfulStages  =  append (detailedErrorGitOpsConfigActions .SuccessfulStages , CloneSshStage )
184+ 	globalUtil .TriggerGitOpsMetrics ("CreateRepository" , "GitAzureClient" , start , nil )
177185	return  * operationReference .WebUrl , true , isEmpty , detailedErrorGitOpsConfigActions 
178186}
179187
@@ -196,14 +204,15 @@ func (impl GitAzureClient) CreateReadme(ctx context.Context, config *bean2.GitOp
196204		UserName :       config .Username ,
197205		UserEmailId :    config .UserEmailId ,
198206	}
199- 	hash , _ , err  :=  impl .CommitValues (ctx , cfg , config )
207+ 	hash , _ , err  :=  impl .CommitValues (ctx , cfg , config ,  true )
200208	if  err  !=  nil  {
201209		impl .logger .Errorw ("error in creating readme azure" , "repo" , config .GitRepoName , "err" , err )
202210	}
203211	return  hash , err 
204212}
205213
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 ()
207216	branch  :=  config .TargetRevision 
208217	if  len (branch ) ==  0  {
209218		branch  =  globalUtil .GetDefaultTargetRevision ()
@@ -229,13 +238,15 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
229238			if  err  !=  nil  {
230239				if  e , ok  :=  err .(azuredevops.WrappedError ); ! ok  ||  * e .StatusCode  >=  500  {
231240					impl .logger .Errorw ("error in fetching branch from azure devops" , "err" , err )
241+ 					globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
232242					return  "" , time.Time {}, err 
233243				}
234244			} else  if  branchStat  !=  nil  {
235245				oldObjId  =  * branchStat .Commit .CommitId 
236246			}
237247		} else  {
238248			impl .logger .Errorw ("error in fetching file from azure devops" , "err" , err )
249+ 			globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
239250			return  "" , time.Time {}, err 
240251		}
241252	} else  {
@@ -292,9 +303,13 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
292303	})
293304	if  e  :=  (azuredevops.WrappedError {}); errors .As (err , & e ) &&  e .StatusCode  !=  nil  &&  * e .StatusCode  ==  http2 .StatusConflict  {
294305		impl .logger .Warn ("conflict found in commit azure" , "err" , err , "config" , config )
306+ 		if  publishStatusConflictError  {
307+ 			globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
308+ 		}
295309		return  "" , time.Time {}, retryFunc .NewRetryableError (err )
296310	} else  if  err  !=  nil  {
297311		impl .logger .Errorw ("error in commit azure" , "err" , err )
312+ 		globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , err )
298313		return  "" , time.Time {}, err 
299314	}
300315	//gitPush.Commits 
@@ -305,6 +320,7 @@ func (impl GitAzureClient) CommitValues(ctx context.Context, config *ChartConfig
305320		commitAuthorTime  =  (* push .Commits )[0 ].Author .Date .Time 
306321	}
307322	//	push.Commits[0].CommitId 
323+ 	globalUtil .TriggerGitOpsMetrics ("CommitValues" , "GitAzureClient" , start , nil )
308324	return  commitId , commitAuthorTime , nil 
309325}
310326
0 commit comments