From 633cedd6c31dcbeb46c6d08be481875b560d7c36 Mon Sep 17 00:00:00 2001 From: Travis Patterson Date: Tue, 15 Feb 2022 07:43:22 -0700 Subject: [PATCH] Fix Azure issue where 404 not recognized --- .../chunk/azure/blob_storage_client.go | 9 ++++++- .../chunk/azure/blob_storage_client_test.go | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/pkg/storage/chunk/azure/blob_storage_client.go b/pkg/storage/chunk/azure/blob_storage_client.go index 094375db7136..7df20f67d00f 100644 --- a/pkg/storage/chunk/azure/blob_storage_client.go +++ b/pkg/storage/chunk/azure/blob_storage_client.go @@ -286,6 +286,13 @@ func (c *BlobStorageConfig) Validate() error { // IsObjectNotFoundErr returns true if error means that object is not found. Relevant to GetObject and DeleteObject operations. func (b *BlobStorage) IsObjectNotFoundErr(err error) bool { + // Some versions of the SDK return a pointer, cover both cases + // to be sure var e azblob.StorageError - return errors.As(err, &e) && e.ErrorCode == azblob.StorageErrorCodeBlobNotFound + if errors.As(err, &e) { + return e.ErrorCode == azblob.StorageErrorCodeBlobNotFound + } + + var ep *azblob.StorageError + return errors.As(err, &ep) && ep.ErrorCode == azblob.StorageErrorCodeBlobNotFound } diff --git a/pkg/storage/chunk/azure/blob_storage_client_test.go b/pkg/storage/chunk/azure/blob_storage_client_test.go index 685685dc4e28..698d4b6435b5 100644 --- a/pkg/storage/chunk/azure/blob_storage_client_test.go +++ b/pkg/storage/chunk/azure/blob_storage_client_test.go @@ -3,11 +3,14 @@ package azure import ( "bytes" "context" + "fmt" "net/http" "strings" "testing" "time" + "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" + "github.com/stretchr/testify/require" "go.uber.org/atomic" @@ -96,3 +99,25 @@ func Test_Hedging(t *testing.T) { }) } } + +func Test_IsObjectNotFoundErr(t *testing.T) { + c, err := NewBlobStorage( + &BlobStorageConfig{ + AccountName: "account", + Environment: azureGlobal, + MaxRetries: 0, + }, + metrics, + hedging.Config{}) + require.NoError(t, err) + + storageError := azblob.StorageError{ + ErrorCode: azblob.StorageErrorCodeBlobNotFound, + } + + err = fmt.Errorf("wrapping error %w", &storageError) + require.True(t, c.IsObjectNotFoundErr(err)) + + err = fmt.Errorf("wrapping error %w", storageError) + require.True(t, c.IsObjectNotFoundErr(err)) +}