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

copyblocks: support copying between tenants #10110

Merged
merged 4 commits into from
Dec 4, 2024
Merged

Conversation

andyasp
Copy link
Contributor

@andyasp andyasp commented Dec 3, 2024

What this PR does

Adds the option user-mapping to copyblocks to allow copying between tenants. Previously it was always assumed that blocks would be copied to a different bucket under the same tenant.

For example, passing --user-mapping="foo:bar" would map the blocks from tenant foo to the destination tenant bar.

Something I did not touch in this PR was the copy marker naming. It is of the form markers/blockID-copied-target-bucket. Now that different tenants can be copied to the marker can clash if you copy data from one tenant to multiple tenants in the same destination bucket. That seemed like a weird use case so I deferred to YAGNI.

Which issue(s) this PR fixes or relates to

N/A

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@andyasp andyasp requested a review from a team as a code owner December 3, 2024 21:48
tools/copyblocks/README.md Outdated Show resolved Hide resolved
tools/copyblocks/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@narqo narqo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of nits, but the changes overall look good 🔥

@@ -297,7 +329,7 @@ func copyBlocks(ctx context.Context, cfg config, logger log.Logger, m *metrics)
m.blocksCopied.Inc()
level.Info(logger).Log("msg", "block copied successfully")

err = uploadCopiedMarkerFile(ctx, sourceBucket, tenantID, blockID, destBucket.Name())
err = uploadCopiedMarkerFile(ctx, sourceBucket, sourceTenantID, blockID, destBucket.Name())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Maybe we can add a note about the behaviour around markers, just it was clear from the code

Suggested change
err = uploadCopiedMarkerFile(ctx, sourceBucket, sourceTenantID, blockID, destBucket.Name())
// Note that markers copying ignores the tenants mapping. This may not work if copying blocks to multiple destination tenants.
err = uploadCopiedMarkerFile(ctx, sourceBucket, sourceTenantID, blockID, destBucket.Name())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded it a bit and added the comment:

// Note that only the blockID and destination bucket are considered in the copy marker.
// If multiple tenants in the same destination bucket are copied to from the same source tenant the markers will currently clash.

@@ -59,6 +62,7 @@ func (c *config) registerFlags(f *flag.FlagSet) {
f.DurationVar(&c.copyPeriod, "copy-period", 0, "How often to repeat the copy. If set to 0, copy is done once, and the program stops. Otherwise, the program keeps running and copying blocks until it is terminated.")
f.Var(&c.enabledUsers, "enabled-users", "If not empty, only blocks for these users are copied.")
f.Var(&c.disabledUsers, "disabled-users", "If not empty, blocks for these users are not copied.")
f.Var(&c.crossTenantMapping, "cross-tenant-mapping", "A comma-separated list of (source tenant):(destination tenant). If a source tenant is not mapped then its destination tenant is assumed to be identical.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cross-tenant-mapping

(nit) Maybe it's better to stick to "users" on the inputs level? The command has --enabled-users and --disabled-users flags. So it feels confusing if one doesn't know that those are the same. Can we name the flag --user-mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks. I changed it to --user-mapping and updated the documentation to reflect that.

@andyasp andyasp merged commit be2f23b into main Dec 4, 2024
29 checks passed
@andyasp andyasp deleted the aasp/copyblocks-cross-tenant branch December 4, 2024 16:55
andyasp added a commit that referenced this pull request Dec 4, 2024
* copyblocks: support copying between tenants

* Update tools/copyblocks/README.md

* Update tools/copyblocks/README.md

Co-authored-by: Taylor C <[email protected]>

* Address feedback

---------

Co-authored-by: Taylor C <[email protected]>
(cherry picked from commit be2f23b)

Co-authored-by: Andy Asp <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants