Skip to content

Commit

Permalink
capturing Azure storage account throttling error
Browse files Browse the repository at this point in the history
reverting the runner changes

changes for more robust code- checking for httpstatuscode

simplifying the levels of nesting of the block of code
  • Loading branch information
LiniSusan committed Mar 14, 2024
1 parent 38ebdae commit eafa458
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/api/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const (
CloudErrorCodeScopeLocked = "ScopeLocked"
CloudErrorCodeRequestDisallowedByPolicy = "RequestDisallowedByPolicy"
CloudErrorCodeInvalidNetworkAddress = "InvalidNetworkAddress"
CloudErrorCodeThrottlingLimitExceeded = "ThrottlingLimitExceeded"
)

// NewCloudError returns a new CloudError
Expand Down
30 changes: 29 additions & 1 deletion pkg/util/storage/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package storage

import (
"context"
"net/http"
"net/url"
"time"

Expand All @@ -13,6 +14,7 @@ import (
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/date"

"github.com/Azure/ARO-RP/pkg/api"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/util/azureclient/mgmt/storage"
)
Expand All @@ -33,6 +35,32 @@ func NewManager(env env.Core, subscriptionID string, authorizer autorest.Authori
}
}

func getCorrectErrWhenTooManyRequests(err error) error {
detailedError, ok := err.(autorest.DetailedError)
if !ok {
return err
}

if detailedError.StatusCode != http.StatusTooManyRequests {
return err
} else {
msg := "Requests are being throttled due to Azure Storage limits being exceeded. Please visit https://learn.microsoft.com/en-us/azure/openshift/troubleshoot#exceeding-azure-storage-limits for more details."
cloudError := &api.CloudError{
StatusCode: http.StatusTooManyRequests,
CloudErrorBody: &api.CloudErrorBody{
Code: api.CloudErrorCodeThrottlingLimitExceeded,
Message: "ThrottlingLimitExceeded",
Details: []api.CloudErrorBody{
{
Message: msg,
},
},
},
}
return cloudError
}
}

func (m *manager) BlobService(ctx context.Context, resourceGroup, account string, p mgmtstorage.Permissions, r mgmtstorage.SignedResourceTypes) (*azstorage.BlobStorageClient, error) {
t := time.Now().UTC().Truncate(time.Second)
res, err := m.storageAccounts.ListAccountSAS(ctx, resourceGroup, account, mgmtstorage.AccountSasParameters{
Expand All @@ -44,7 +72,7 @@ func (m *manager) BlobService(ctx context.Context, resourceGroup, account string
SharedAccessExpiryTime: &date.Time{Time: t.Add(24 * time.Hour)},
})
if err != nil {
return nil, err
return nil, getCorrectErrWhenTooManyRequests(err)
}

v, err := url.ParseQuery(*res.AccountSasToken)
Expand Down

0 comments on commit eafa458

Please sign in to comment.