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(hc): Adds support for region URL overrides in CLI #2003

Conversation

GabeVillalobos
Copy link
Member

Adds support for region-specific URL overrides, so long as the region URL matches the region_url encoded on a supplied organization authentication token.

src/config.rs Outdated
_ => bail!(
"Two different url values supplied: `{token_url}` (from token), `{default_url}`."
"URL must match one of the provided URLs on the authentication token: `{token_url}` or `{region_url}`, received: `{default_url}`."
Copy link
Member Author

Choose a reason for hiding this comment

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

This could probably use some better wording, but it feels appropriate to include the region URL here as an option for the user to select it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also this is a little quirky. If the region_url and token_url match, you'll essentially get a message with the same expected URL twice. I can make this exhaustive at the expense of adding multiple distinct error message cases.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think we should add the distinct error message cases; might be confusing if we list the same URL twice in the same error message

Comment on lines +2 to +6
$ sentry-cli --auth-token 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 --url http://localhost:8000 sourcemaps upload --org nomatch test_path
? failed
error: the following required arguments were not provided:
<PATHS>...
error: Two different org values supplied: `sentry` (from token), `nomatch`.

Usage: sentry-cli[EXE] sourcemaps upload <PATHS>...

For more information, try '--help'.
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Copy link
Member Author

Choose a reason for hiding this comment

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

This test wasn't actually asserting the URL matches correctly. It appears that the upload <paths> check occurs before the URL checking logic is run.

Copy link
Member

Choose a reason for hiding this comment

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

Great catch!

@GabeVillalobos GabeVillalobos requested review from szokeasaurusrex and a team March 26, 2024 20:09
Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

I think we might want to go a different direction with this PR.

Specifically, I would propose that we simply change the logic so that when an org auth token is used, we route all requests to the region URL specified in the token (not just the region specific ones). Simultaneously, we should deprecate the --url option when the org auth token is used, since it is redundant to specify both a --url and an auth token.

Instead, if a user provides a --url argument with an org auth token, we should print a warning to let them know that using --url with an org auth token is deprecated, and we should simply ignore the --url argument.

I can prepare some PRs to implement this functionality

Comment on lines +2 to +6
$ sentry-cli --auth-token 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 --url http://localhost:8000 sourcemaps upload --org nomatch test_path
? failed
error: the following required arguments were not provided:
<PATHS>...
error: Two different org values supplied: `sentry` (from token), `nomatch`.

Usage: sentry-cli[EXE] sourcemaps upload <PATHS>...

For more information, try '--help'.
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Copy link
Member

Choose a reason for hiding this comment

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

Great catch!

@szokeasaurusrex
Copy link
Member

Actually, we currently cannot send all requests to the region endpoint, as this breaks the sentry-cli info command. This command accesses the /api/0/ (root) endpoint, which only exists on the control silo. We would need to make the /api/0/ endpoint also accessible on the regions to be able to implement my suggestion. We would likely also need to do a comprehensive check to make sure all other endpoints we use in the CLI are also available as region endpoints.

Copy link
Member

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

I would say this generally looks good, if you would like to go with this option.

I would however slightly prefer something like #2005 since I think it would make the CLI more maintainable if we reduce the number of user-configurable options, and if I recall correctly from our meeting, we anyways wanted to move towards sending all requests directly to the region

src/config.rs Outdated
_ => bail!(
"Two different url values supplied: `{token_url}` (from token), `{default_url}`."
"URL must match one of the provided URLs on the authentication token: `{token_url}` or `{region_url}`, received: `{default_url}`."
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I think we should add the distinct error message cases; might be confusing if we list the same URL twice in the same error message

@GabeVillalobos
Copy link
Member Author

Actually, we currently cannot send all requests to the region endpoint, as this breaks the sentry-cli info command. This command accesses the /api/0/ (root) endpoint, which only exists on the control silo. We would need to make the /api/0/ endpoint also accessible on the regions to be able to implement my suggestion. We would likely also need to do a comprehensive check to make sure all other endpoints we use in the CLI are also available as region endpoints.

@szokeasaurusrex Agreed. I do think we surface the base control silo URL in our org auth tokens as well, so maybe we can add some logic that defaults to the region whenever possible for all calls except for the very few control-silo specific calls that we can explicitly mark as control-silo bound requests.

I can help audit all of the calls to ensure those get marked/routed accordingly.

Copy link

This pull request has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

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.

2 participants