-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increase Retry Time on Data Sources #454
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -130,7 +130,7 @@ func resourcePagerDutyServiceDependencyAssociate(d *schema.ResourceData, meta in | |||||||||||||
log.Printf("[INFO] Associating PagerDuty dependency %s", serviceDependency.ID) | ||||||||||||||
|
||||||||||||||
var dependencies *pagerduty.ListServiceDependencies | ||||||||||||||
retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { | ||||||||||||||
retryErr := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||||||||||||||
if dependencies, _, err = client.ServiceDependencies.AssociateServiceDependencies(&input); err != nil { | ||||||||||||||
if isErrCode(err, 404) { | ||||||||||||||
return resource.RetryableError(err) | ||||||||||||||
|
@@ -166,26 +166,30 @@ func resourcePagerDutyServiceDependencyDisassociate(d *schema.ResourceData, meta | |||||||||||||
|
||||||||||||||
log.Printf("[INFO] Disassociating PagerDuty dependency %s", dependency.DependentService.ID) | ||||||||||||||
|
||||||||||||||
// listServiceRelationships by calling get dependencies using the serviceDependency.DependentService.ID | ||||||||||||||
depResp, _, err := client.ServiceDependencies.GetServiceDependenciesForType(dependency.DependentService.ID, dependency.DependentService.Type) | ||||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
var foundDep *pagerduty.ServiceDependency | ||||||||||||||
|
||||||||||||||
// loop serviceRelationships until relationship.IDs match | ||||||||||||||
for _, rel := range depResp.Relationships { | ||||||||||||||
if rel.ID == d.Id() { | ||||||||||||||
foundDep = rel | ||||||||||||||
break | ||||||||||||||
// listServiceRelationships by calling get dependencies using the serviceDependency.DependentService.ID | ||||||||||||||
retryErr := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||||||||||||||
if dependencies, _, err := client.ServiceDependencies.GetServiceDependenciesForType(dependency.DependentService.ID, dependency.DependentService.Type); err != nil { | ||||||||||||||
if isErrCode(err, 404) || isErrCode(err, 500) || isErrCode(err, 429) { | ||||||||||||||
return resource.RetryableError(err) | ||||||||||||||
} | ||||||||||||||
return resource.NonRetryableError(err) | ||||||||||||||
} else if dependencies != nil { | ||||||||||||||
for _, rel := range dependencies.Relationships { | ||||||||||||||
if rel.ID == d.Id() { | ||||||||||||||
foundDep = rel | ||||||||||||||
break | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
// check if relationship not found | ||||||||||||||
if foundDep == nil { | ||||||||||||||
d.SetId("") | ||||||||||||||
return nil | ||||||||||||||
}) | ||||||||||||||
if retryErr != nil { | ||||||||||||||
time.Sleep(5 * time.Second) | ||||||||||||||
return retryErr | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// convertType is needed because the PagerDuty API returns the 'reference' values in responses but wants the other | ||||||||||||||
// values in requests | ||||||||||||||
foundDep.SupportingService.Type = convertType(foundDep.SupportingService.Type) | ||||||||||||||
|
@@ -199,17 +203,17 @@ func resourcePagerDutyServiceDependencyDisassociate(d *schema.ResourceData, meta | |||||||||||||
input := pagerduty.ListServiceDependencies{ | ||||||||||||||
Relationships: r, | ||||||||||||||
} | ||||||||||||||
retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { | ||||||||||||||
retryErr = resource.Retry(5*time.Minute, func() *resource.RetryError { | ||||||||||||||
if _, _, err = client.ServiceDependencies.DisassociateServiceDependencies(&input); err != nil { | ||||||||||||||
if isErrCode(err, 404) { | ||||||||||||||
if isErrCode(err, 404) || isErrCode(err, 429) { | ||||||||||||||
return resource.RetryableError(err) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stmcallister I am a bit concerned the end users might have to wait for 5 min to find out a resource already exists or had already been deleted manually which are not that uncommon. One solution that seems fairly easy to implement at a glance would be to add a max timeout to the retryable error as an extra optional parameter
Suggested change
|
||||||||||||||
} | ||||||||||||||
return resource.NonRetryableError(err) | ||||||||||||||
} | ||||||||||||||
return nil | ||||||||||||||
}) | ||||||||||||||
if retryErr != nil { | ||||||||||||||
time.Sleep(2 * time.Second) | ||||||||||||||
time.Sleep(5 * time.Second) | ||||||||||||||
return retryErr | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
@@ -273,7 +277,7 @@ func findDependencySetState(depID, serviceID, serviceType string, d *schema.Reso | |||||||||||||
|
||||||||||||||
// Pausing to let the PD API sync. | ||||||||||||||
time.Sleep(1 * time.Second) | ||||||||||||||
retryErr := resource.Retry(30*time.Second, func() *resource.RetryError { | ||||||||||||||
retryErr := resource.Retry(5*time.Minute, func() *resource.RetryError { | ||||||||||||||
if dependencies, _, err := client.ServiceDependencies.GetServiceDependenciesForType(serviceID, serviceType); err != nil { | ||||||||||||||
if isErrCode(err, 404) || isErrCode(err, 500) || isErrCode(err, 429) { | ||||||||||||||
return resource.RetryableError(err) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stmcallister, would be a good idea to centralize the logic of what is a returnable error? I'm not sure if it is worth it to retry on 400 at all for example. I can see the benefit of increasing the retry to 5min for 429 and maybe 503/504 errors, but it might substantially hurt the experience if there is a real 404 or 400.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drastawi Thanks for the feedback! The tricky part is that in some race condition situations we do want to retry on a 404 🤔 Good point on the centralizing of the logic.