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

fixed listing blocks for backend/s3 #567

Merged
merged 1 commit into from
Mar 4, 2021
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 21 additions & 11 deletions tempodb/backend/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down