Skip to content

Commit

Permalink
Merge pull request #1525 from sunpa93/log-retries
Browse files Browse the repository at this point in the history
[V2] chore: add retry details to workflow logging in UpdateCRIWithRetry
  • Loading branch information
k8s-ci-robot authored Sep 22, 2022
2 parents 9b298ac + 73412cc commit 1d01adc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/azureconstants/azure_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const (
StorageAccountTypeField = "storageaccounttype"
TagsField = "tags"
ThrottlingKey = "throttlingKey"
RetryKey = "number_of_retry"
NetRetryKey = "number_of_net_retry"
TrueValue = "true"
FalseValue = "false"
UserAgentField = "useragent"
Expand Down
18 changes: 12 additions & 6 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,16 @@ type UpdateCRIFunc func(client.Object) error

func UpdateCRIWithRetry(ctx context.Context, informerFactory azdiskinformers.SharedInformerFactory, cachedClient client.Client, azDiskClient azdisk.Interface, obj client.Object, updateFunc UpdateCRIFunc, maxNetRetry int, updateMode CRIUpdateMode) (client.Object, error) {
var err error

curNetRetry := 0
curRetry := 0

objName := obj.GetName()
ctx, w := workflow.New(ctx, workflow.WithCaller(1))
defer func() { w.Finish(err) }()
defer func() {
w.AddDetailToLogger(consts.RetryKey, curRetry, consts.NetRetryKey, curNetRetry)
w.Finish(err)
}()

var updatedObj client.Object

Expand Down Expand Up @@ -1170,15 +1177,14 @@ func UpdateCRIWithRetry(ctx context.Context, informerFactory azdiskinformers.Sha
return nil
}

curRetry := 0
maxRetry := maxNetRetry
isRetriable := func(err error) bool {
if k8serrors.IsConflict(err) {
curRetry++
return true
}
if isNetError(err) {
defer func() { curRetry++ }()
return curRetry < maxRetry
defer func() { curNetRetry++ }()
return curNetRetry < maxNetRetry
}
return false
}
Expand All @@ -1196,7 +1202,7 @@ func UpdateCRIWithRetry(ctx context.Context, informerFactory azdiskinformers.Sha

// if encountered net error from api server unavailability, exit process
if isNetError(err) {
ExitOnNetError(err, maxRetry > 0 && curRetry >= maxRetry)
ExitOnNetError(err, maxNetRetry > 0 && curNetRetry >= maxNetRetry)
}
return updatedObj, err
}
Expand Down

0 comments on commit 1d01adc

Please sign in to comment.