From e6ed9908e379880bc517654a2ecb583b4ed8b636 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Fri, 26 May 2023 11:21:16 +0100 Subject: [PATCH] [v9.4.x] GoogleAPI: Add retries functionallity to GoogleAPI calls (#69142) GoogleAPI: Add retries functionallity to GoogleAPI calls (#69129) * Add retryer to GoogleAPI calls * Add comment (cherry picked from commit 515270f5fd2815a9776655909fd806fd286e6525) Co-authored-by: Dimitris Sotirakis --- pkg/build/gcloud/storage/gsutil.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/build/gcloud/storage/gsutil.go b/pkg/build/gcloud/storage/gsutil.go index 8bc92066e94..2e109651ffd 100644 --- a/pkg/build/gcloud/storage/gsutil.go +++ b/pkg/build/gcloud/storage/gsutil.go @@ -47,14 +47,25 @@ type File struct { // New creates a new Client by checking for the Google Cloud SDK auth key and/or environment variable. func New() (*Client, error) { - client, err := newClient() + storageClient, err := newClient() if err != nil { return nil, err } - return &Client{ - Client: *client, - }, nil + client := &Client{ + Client: *storageClient, + } + client.SetRetryer() + + return client, nil +} + +// SetRetryer adds a retry strategy for the googleapi client calls that fail. +func (client *Client) SetRetryer() { + client.SetRetry([]storage.RetryOption{ + storage.WithPolicy(storage.RetryAlways), + storage.WithErrorFunc(storage.ShouldRetry), + }...) } // newClient initializes the google-cloud-storage (GCS) client. @@ -147,8 +158,6 @@ func (client *Client) Copy(ctx context.Context, file File, bucket *storage.Bucke return fmt.Errorf("failed to copy to Cloud Storage: %w", err) } - log.Printf("Successfully uploaded tarball to Google Cloud Storage, path: %s/%s\n", remote, file.FullPath) - return nil } @@ -257,7 +266,6 @@ func (client *Client) Delete(ctx context.Context, bucket *storage.BucketHandle, if err := object.Delete(ctx); err != nil { return fmt.Errorf("cannot delete %s, err: %w", path, err) } - log.Printf("Successfully deleted tarball to Google Cloud Storage, path: %s", path) return nil }