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

stop converting timeouts to/from minutes #6218

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
3 changes: 3 additions & 0 deletions .changelog/3421.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
* all: fixed bug where timeouts specified in units other than minutes were getting incorrectly rounded. Also fixed several instances of timeout values being used from the wrong method.
```
9 changes: 5 additions & 4 deletions google/access_context_manager_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package google
import (
"encoding/json"
"fmt"
"time"
)

type AccessContextManagerOperationWaiter struct {
Expand Down Expand Up @@ -47,23 +48,23 @@ func createAccessContextManagerWaiter(config *Config, op map[string]interface{},
}

// nolint: deadcode,unused
func accessContextManagerOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, activity string, timeoutMinutes int) error {
func accessContextManagerOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, activity string, timeout time.Duration) error {
w, err := createAccessContextManagerWaiter(config, op, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes, config.PollInterval); err != nil {
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error {
func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeout time.Duration) error {
w, err := createAccessContextManagerWaiter(config, op, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
11 changes: 6 additions & 5 deletions google/appengine_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"time"

"google.golang.org/api/appengine/v1"
)
Expand All @@ -30,10 +31,10 @@ func (w *AppEngineOperationWaiter) QueryOp() (interface{}, error) {
}

func appEngineOperationWait(config *Config, res interface{}, appId, activity string) error {
return appEngineOperationWaitTime(config, res, appId, activity, 4)
return appEngineOperationWaitTime(config, res, appId, activity, 4*time.Minute)
}

func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity string, timeoutMinutes int) error {
func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, response *map[string]interface{}, appId, activity string, timeout time.Duration) error {
op := &appengine.Operation{}
err := Convert(res, op)
if err != nil {
Expand All @@ -48,13 +49,13 @@ func appEngineOperationWaitTimeWithResponse(config *Config, res interface{}, res
if err := w.SetOp(op); err != nil {
return err
}
if err := OperationWait(w, activity, timeoutMinutes, config.PollInterval); err != nil {
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity string, timeoutMinutes int) error {
func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity string, timeout time.Duration) error {
op := &appengine.Operation{}
err := Convert(res, op)
if err != nil {
Expand All @@ -69,5 +70,5 @@ func appEngineOperationWaitTime(config *Config, res interface{}, appId, activity
if err := w.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
5 changes: 3 additions & 2 deletions google/cloudfunctions_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package google

import (
"fmt"
"time"

"google.golang.org/api/cloudfunctions/v1"
)
Expand All @@ -18,12 +19,12 @@ func (w *CloudFunctionsOperationWaiter) QueryOp() (interface{}, error) {
return w.Service.Operations.Get(w.Op.Name).Do()
}

func cloudFunctionsOperationWait(config *Config, op *cloudfunctions.Operation, activity string, timeoutMin int) error {
func cloudFunctionsOperationWait(config *Config, op *cloudfunctions.Operation, activity string, timeout time.Duration) error {
w := &CloudFunctionsOperationWaiter{
Service: config.clientCloudFunctions,
}
if err := w.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMin, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
4 changes: 2 additions & 2 deletions google/common_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func CommonRefreshFunc(w Waiter) resource.StateRefreshFunc {
}
}

func OperationWait(w Waiter, activity string, timeoutMinutes int, pollInterval time.Duration) error {
func OperationWait(w Waiter, activity string, timeout time.Duration, pollInterval time.Duration) error {
if OperationDone(w) {
if w.Error() != nil {
return w.Error()
Expand All @@ -138,7 +138,7 @@ func OperationWait(w Waiter, activity string, timeoutMinutes int, pollInterval t
Pending: w.PendingStates(),
Target: w.TargetStates(),
Refresh: CommonRefreshFunc(w),
Timeout: time.Duration(timeoutMinutes) * time.Minute,
Timeout: timeout,
MinTimeout: 2 * time.Second,
PollInterval: pollInterval,
}
Expand Down
2 changes: 1 addition & 1 deletion google/common_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestOperationWait_TimeoutsShouldRetry(t *testing.T) {
testWaiter := TestWaiter{
runCount: 0,
}
err := OperationWait(&testWaiter, "my-activity", 1, 0*time.Second)
err := OperationWait(&testWaiter, "my-activity", 1*time.Minute, 0*time.Second)
if err != nil {
t.Fatalf("unexpected error waiting for operation: got '%v', want 'nil'", err)
}
Expand Down
5 changes: 3 additions & 2 deletions google/composer_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package google

import (
"fmt"
"time"

composer "google.golang.org/api/composer/v1beta1"
)
Expand All @@ -18,12 +19,12 @@ func (w *ComposerOperationWaiter) QueryOp() (interface{}, error) {
return w.Service.Operations.Get(w.Op.Name).Do()
}

func composerOperationWaitTime(config *Config, op *composer.Operation, project, activity string, timeoutMinutes int) error {
func composerOperationWaitTime(config *Config, op *composer.Operation, project, activity string, timeout time.Duration) error {
w := &ComposerOperationWaiter{
Service: config.clientComposer.Projects.Locations,
}
if err := w.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
7 changes: 4 additions & 3 deletions google/compute_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package google
import (
"bytes"
"fmt"
"time"

"google.golang.org/api/compute/v1"
)
Expand Down Expand Up @@ -79,10 +80,10 @@ func (w *ComputeOperationWaiter) TargetStates() []string {
}

func computeOperationWait(config *Config, res interface{}, project, activity string) error {
return computeOperationWaitTime(config, res, project, activity, 4)
return computeOperationWaitTime(config, res, project, activity, 4*time.Minute)
}

func computeOperationWaitTime(config *Config, res interface{}, project, activity string, timeoutMinutes int) error {
func computeOperationWaitTime(config *Config, res interface{}, project, activity string, timeout time.Duration) error {
op := &compute.Operation{}
err := Convert(res, op)
if err != nil {
Expand All @@ -98,7 +99,7 @@ func computeOperationWaitTime(config *Config, res interface{}, project, activity
if err := w.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}

// ComputeOperationError wraps compute.OperationError and implements the
Expand Down
5 changes: 3 additions & 2 deletions google/container_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"time"

container "google.golang.org/api/container/v1beta1"
)
Expand Down Expand Up @@ -96,7 +97,7 @@ func (w *ContainerOperationWaiter) TargetStates() []string {
return []string{"DONE"}
}

func containerOperationWait(config *Config, op *container.Operation, project, location, activity string, timeoutMinutes int) error {
func containerOperationWait(config *Config, op *container.Operation, project, location, activity string, timeout time.Duration) error {
w := &ContainerOperationWaiter{
Service: config.clientContainerBeta,
Context: config.context,
Expand All @@ -109,5 +110,5 @@ func containerOperationWait(config *Config, op *container.Operation, project, lo
return err
}

return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
7 changes: 4 additions & 3 deletions google/dataproc_cluster_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package google

import (
"fmt"
"time"

"google.golang.org/api/dataproc/v1beta2"
dataproc "google.golang.org/api/dataproc/v1beta2"
)

type DataprocClusterOperationWaiter struct {
Expand All @@ -18,12 +19,12 @@ func (w *DataprocClusterOperationWaiter) QueryOp() (interface{}, error) {
return w.Service.Projects.Regions.Operations.Get(w.Op.Name).Do()
}

func dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeoutMinutes int) error {
func dataprocClusterOperationWait(config *Config, op *dataproc.Operation, activity string, timeout time.Duration) error {
w := &DataprocClusterOperationWaiter{
Service: config.clientDataprocBeta,
}
if err := w.SetOp(op); err != nil {
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
9 changes: 5 additions & 4 deletions google/dataproc_job_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package google
import (
"fmt"
"net/http"
"time"

"google.golang.org/api/dataproc/v1"
)
Expand Down Expand Up @@ -65,14 +66,14 @@ func (w *DataprocJobOperationWaiter) TargetStates() []string {
return []string{"CANCELLED", "DONE", "ATTEMPT_FAILURE", "ERROR"}
}

func dataprocJobOperationWait(config *Config, region, projectId, jobId string, activity string, timeoutMinutes, minTimeoutSeconds int) error {
func dataprocJobOperationWait(config *Config, region, projectId, jobId string, activity string, timeout time.Duration) error {
w := &DataprocJobOperationWaiter{
Service: config.clientDataproc,
Region: region,
ProjectId: projectId,
JobId: jobId,
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}

type DataprocDeleteJobOperationWaiter struct {
Expand Down Expand Up @@ -103,7 +104,7 @@ func (w *DataprocDeleteJobOperationWaiter) QueryOp() (interface{}, error) {
return job, err
}

func dataprocDeleteOperationWait(config *Config, region, projectId, jobId string, activity string, timeoutMinutes, minTimeoutSeconds int) error {
func dataprocDeleteOperationWait(config *Config, region, projectId, jobId string, activity string, timeout time.Duration) error {
w := &DataprocDeleteJobOperationWaiter{
DataprocJobOperationWaiter{
Service: config.clientDataproc,
Expand All @@ -112,5 +113,5 @@ func dataprocDeleteOperationWait(config *Config, region, projectId, jobId string
JobId: jobId,
},
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
9 changes: 5 additions & 4 deletions google/datastore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package google
import (
"encoding/json"
"fmt"
"time"
)

type DatastoreOperationWaiter struct {
Expand Down Expand Up @@ -49,23 +50,23 @@ func createDatastoreWaiter(config *Config, op map[string]interface{}, project, a
}

// nolint: deadcode,unused
func datastoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
func datastoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createDatastoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes, config.PollInterval); err != nil {
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func datastoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
func datastoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createDatastoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
6 changes: 4 additions & 2 deletions google/deployment_manager_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package google
import (
"bytes"
"fmt"
"time"

"google.golang.org/api/compute/v1"
)

Expand Down Expand Up @@ -32,7 +34,7 @@ func (w *DeploymentManagerOperationWaiter) QueryOp() (interface{}, error) {
return op, nil
}

func deploymentManagerOperationWaitTime(config *Config, resp interface{}, project, activity string, timeoutMinutes int) error {
func deploymentManagerOperationWaitTime(config *Config, resp interface{}, project, activity string, timeout time.Duration) error {
op := &compute.Operation{}
err := Convert(resp, op)
if err != nil {
Expand All @@ -50,7 +52,7 @@ func deploymentManagerOperationWaitTime(config *Config, resp interface{}, projec
return err
}

return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}

func (w *DeploymentManagerOperationWaiter) Error() error {
Expand Down
9 changes: 5 additions & 4 deletions google/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package google
import (
"encoding/json"
"fmt"
"time"
)

type FilestoreOperationWaiter struct {
Expand Down Expand Up @@ -49,23 +50,23 @@ func createFilestoreWaiter(config *Config, op map[string]interface{}, project, a
}

// nolint: deadcode,unused
func filestoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeoutMinutes int) error {
func filestoreOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createFilestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
if err := OperationWait(w, activity, timeoutMinutes, config.PollInterval); err != nil {
if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response)
}

func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeout time.Duration) error {
w, err := createFilestoreWaiter(config, op, project, activity)
if err != nil || w == nil {
// If w is nil, the op was synchronous.
return err
}
return OperationWait(w, activity, timeoutMinutes, config.PollInterval)
return OperationWait(w, activity, timeout, config.PollInterval)
}
Loading