Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Azure issue where 404 not recognized #5399

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}