Skip to content
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

Add retries for modified services to google_project_service #7230

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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