Skip to content

Commit

Permalink
Fix Azure issue where 404 not recognized (#5399)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasslessParticle authored Feb 15, 2022
1 parent 64589d0 commit 7378b69
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/storage/chunk/azure/blob_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 25 additions & 0 deletions pkg/storage/chunk/azure/blob_storage_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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))
}

0 comments on commit 7378b69

Please sign in to comment.