Skip to content

Commit

Permalink
fix api retry for offline synapse (#195)
Browse files Browse the repository at this point in the history
* fix api retry for offline synapse

* fix duplicate client option code

* resolve PR comment
  • Loading branch information
VikrantKS authored Jun 22, 2022
1 parent 28bedf9 commit 644837d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"

"github.com/LambdaTest/test-at-scale/config"
Expand All @@ -24,6 +25,7 @@ var (
defaultBufferSize = 3 * 1024 * 1024
defaultMaxBuffers = 4
coverageContainerName = "coverage"
maxRetry = 10
)

// store represents the azure storage
Expand Down Expand Up @@ -72,8 +74,7 @@ func NewAzureBlobEnv(cfg *config.NucleusConfig, requests core.Requests, logger l
if err != nil {
return nil, err
}

serviceClient, err := azblob.NewServiceClientWithSharedKey(u.String(), credential, nil)
serviceClient, err := azblob.NewServiceClientWithSharedKey(u.String(), credential, getClientOptions())
if err != nil {
logger.Errorf("Failed to create azure service client, error: %v", err)
return nil, err
Expand Down Expand Up @@ -113,7 +114,7 @@ func (s *store) CreateUsingSASURL(ctx context.Context, sasURL string, reader io.
if err != nil {
return "", err
}
blobClient, err := azblob.NewBlockBlobClientWithNoCredential(u.String(), &azblob.ClientOptions{})
blobClient, err := azblob.NewBlockBlobClientWithNoCredential(u.String(), getClientOptions())
if err != nil {
s.logger.Errorf("failed to create blob client, error: %v", err)
return "", err
Expand Down Expand Up @@ -205,3 +206,12 @@ func handleError(err error) error {
}
return err
}

func getClientOptions() *azblob.ClientOptions {
return &azblob.ClientOptions{
Retry: policy.RetryOptions{
MaxRetries: int32(maxRetry),
TryTimeout: global.DefaultAPITimeout,
},
}
}
4 changes: 4 additions & 0 deletions pkg/requestutils/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -61,6 +62,9 @@ func (r *requests) MakeAPIRequest(
}
defer resp.Body.Close()
statusCode = resp.StatusCode
if 500 <= statusCode && statusCode < 600 {
return fmt.Errorf("status code %d received", statusCode)
}
respBody, err = io.ReadAll(resp.Body)
if err != nil {
r.logger.Errorf("error while reading http response body %v", err)
Expand Down

0 comments on commit 644837d

Please sign in to comment.