From 6d6fa079c8fa8405e8cde5250ce5d65246849668 Mon Sep 17 00:00:00 2001 From: Josef Janda Date: Thu, 4 Mar 2021 11:00:10 +0100 Subject: [PATCH] fixed listing blocks for backend/s3 when the list is truncated --- CHANGELOG.md | 2 +- tempodb/backend/s3/s3.go | 32 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5076fbdea4..5fa6190cb10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This is a **breaking change** and will likely result in query errors on rollout as the query signature b/n QueryFrontend & Querier has changed. [#557](https://github.com/grafana/tempo/pull/557) * [BUGFIX] Fixes permissions errors on startup in GCS. [#554](https://github.com/grafana/tempo/pull/554) * [BUGFIX] Fixes error where Dell ECS cannot list objects. [#561](https://github.com/grafana/tempo/pull/561) - +* [BUGFIX] Fixes listing blocks in S3 when the list is truncated. [#567](https://github.com/grafana/tempo/pull/567) ## v0.6.0 diff --git a/tempodb/backend/s3/s3.go b/tempodb/backend/s3/s3.go index bfb22e72d17..d7ca32861ab 100644 --- a/tempodb/backend/s3/s3.go +++ b/tempodb/backend/s3/s3.go @@ -272,21 +272,31 @@ func (rw *readerWriter) Tenants(ctx context.Context) ([]string, error) { // Blocks implements backend.Reader func (rw *readerWriter) Blocks(ctx context.Context, tenantID string) ([]uuid.UUID, error) { prefix := tenantID + "/" - // ListObjects(bucket, prefix, marker, delimiter string, maxKeys int) - res, err := rw.core.ListObjects(rw.cfg.Bucket, prefix, "", "/", 0) - if err != nil { - return nil, errors.Wrapf(err, "error listing blocks in s3 bucket, bucket: %s", rw.cfg.Bucket) - } - - level.Debug(rw.logger).Log("msg", "listing blocks", "tenantID", tenantID, "found", len(res.CommonPrefixes)) var blockIDs []uuid.UUID - for _, cp := range res.CommonPrefixes { - blockID, err := uuid.Parse(strings.Split(strings.TrimPrefix(cp.Prefix, prefix), "/")[0]) + + nextMarker := "" + isTruncated := true + for isTruncated { + // ListObjects(bucket, prefix, nextMarker, delimiter string, maxKeys int) + res, err := rw.core.ListObjects(rw.cfg.Bucket, prefix, nextMarker, "/", 0) if err != nil { - return nil, errors.Wrapf(err, "error parsing uuid of obj, objectName: %s", cp.Prefix) + return nil, errors.Wrapf(err, "error listing blocks in s3 bucket, bucket: %s", rw.cfg.Bucket) + } + isTruncated = res.IsTruncated + nextMarker = res.NextMarker + + level.Debug(rw.logger).Log("msg", "listing blocks", "tenantID", tenantID, + "found", len(res.CommonPrefixes), "IsTruncated", res.IsTruncated, "NextMarker", res.NextMarker) + + for _, cp := range res.CommonPrefixes { + blockID, err := uuid.Parse(strings.Split(strings.TrimPrefix(cp.Prefix, prefix), "/")[0]) + if err != nil { + return nil, errors.Wrapf(err, "error parsing uuid of obj, objectName: %s", cp.Prefix) + } + blockIDs = append(blockIDs, blockID) } - blockIDs = append(blockIDs, blockID) } + return blockIDs, nil }