Skip to content

Commit

Permalink
Add retries for modified services to google_project_service (#3960) (#…
Browse files Browse the repository at this point in the history
…7230)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Sep 9, 2020
1 parent d170b87 commit c805284
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changelog/3960.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
serviceusage: added retries when a service is already being modified
```
```release-note:bug
serviceusage: fixed an issue where `bigquery.googleapis.com` was getting enabled as the `bigquery-json.googleapis.com` alias instead, incorrectly. This had no user impact yet, but the alias may go away in the future.
```
15 changes: 15 additions & 0 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ func isSqlOperationInProgressError(err error) (bool, string) {
return false, ""
}

// Retry if service usage decides you're activating the same service multiple
// times. This can happen if a service and a dependent service aren't batched
// together- eg container.googleapis.com in one request followed by compute.g.c
// in the next (container relies on compute and implicitly activates it)
func serviceUsageServiceBeingActivated(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 400 {
if strings.Contains(gerr.Body, "Another activation or deactivation is in progress") {
return false, ""
}

return true, "Waiting for same service activation/deactivation to finish"
}
return false, ""
}

// Retry if Monitoring operation returns a 429 with a specific message for
// concurrent operations.
func isMonitoringConcurrentEditError(err error) (bool, string) {
Expand Down
2 changes: 1 addition & 1 deletion google/resource_google_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func doEnableServicesRequest(services []string, project string, config *Config,
op, rerr = config.clientServiceUsage.Services.BatchEnable(name, req).Do()
}
return handleServiceUsageRetryableError(rerr)
}, timeout)
}, timeout, serviceUsageServiceBeingActivated)
if err != nil {
return errwrap.Wrapf("failed to send enable services request: {{err}}", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/serviceusage_batching.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func tryEnableRenamedService(service, altName string, project string, d *schema.
// use a short timeout- failures are likely

log.Printf("[DEBUG] attempting enabling service with user-specified name %s", service)
err := enableServiceUsageProjectServices([]string{altName}, project, config, 1*time.Minute)
err := enableServiceUsageProjectServices([]string{service}, project, config, 1*time.Minute)
if err != nil {
log.Printf("[DEBUG] saw error %s. attempting alternate name %v", err, altName)
err2 := enableServiceUsageProjectServices([]string{altName}, project, config, 1*time.Minute)
Expand Down

0 comments on commit c805284

Please sign in to comment.