Skip to content

Commit

Permalink
Merge pull request #22 from nvaatstra/handle-list-errors
Browse files Browse the repository at this point in the history
S3: Handle errors returned by MinIO Client ListObjects
  • Loading branch information
wojas authored Jan 11, 2023
2 parents 3704775 + 4909c89 commit 8b71881
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 8 additions & 2 deletions backends/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"time"

"github.com/PowerDNS/go-tlsconfig"
"github.com/minio/minio-go/v7"
"github.com/go-logr/logr"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"

"github.com/PowerDNS/simpleblob"
Expand Down Expand Up @@ -117,7 +117,7 @@ func (b *Backend) List(ctx context.Context, prefix string) (simpleblob.BlobList,
m, err := b.Load(ctx, UpdateMarkerFilename)
exists := !errors.Is(err, os.ErrNotExist)
if err != nil && exists {
return nil, err
return nil, err
}
upstreamMarker := string(m)

Expand Down Expand Up @@ -155,6 +155,12 @@ func (b *Backend) doList(ctx context.Context, prefix string) (simpleblob.BlobLis
Recursive: false,
})
for obj := range objCh {
// Handle error returned by MinIO client
if err := convertMinioError(obj.Err); err != nil {
metricCallErrors.WithLabelValues("list").Inc()
return nil, err
}

metricCalls.WithLabelValues("list").Inc()
metricLastCallTimestamp.WithLabelValues("list").SetToCurrentTime()
if obj.Key == UpdateMarkerFilename {
Expand Down
3 changes: 1 addition & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ if [ -z "$SIMPLEBLOB_TEST_S3_CONFIG" ]; then

# Fetch minio if not found
if ! command -v minio >/dev/null; then
source <(go env)
dst="$GOBIN/minio"
curl -v -o "$dst" "https://dl.min.io/server/minio/release/$GOOS-$GOARCH/minio"
curl -v -o "$dst" "https://dl.min.io/server/minio/release/$(go env GOOS)-$(go env GOARCH)/minio"
chmod u+x "$dst"
fi

Expand Down
5 changes: 5 additions & 0 deletions tester/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func DoBackendTests(t *testing.T, b simpleblob.Interface) {
assert.NoError(t, err)
assert.Equal(t, ls.Names(), []string{"bar-1", "bar-2"}) // sorted

// List with non-existing prefix
ls, err = b.List(ctx, "does-not-exist-")
assert.NoError(t, err)
assert.Nil(t, ls.Names())

// Load
data, err := b.Load(ctx, "foo-1")
assert.NoError(t, err)
Expand Down

0 comments on commit 8b71881

Please sign in to comment.