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

Explicitly initialize snuba take 2 #3326

Merged
merged 2 commits into from
Nov 3, 2022
Merged

Explicitly initialize snuba take 2 #3326

merged 2 commits into from
Nov 3, 2022

Conversation

volokluev
Copy link
Member

This is mostly the same as #3311 with the only difference being the name transformation

if you have a click command like this:

@click.command
def my_command():
    pass

it will be accessible in the cli as my-command. #3311 naively expected it to be my_command.

This PR fixes that and adds a comment explaining why it's important

Testing

Today I remembered about the snuba devserver command which starts up everything with the correct names. If I had done that initially I wouldn't have had to revert.

With this change, snuba devserver starts up properly (before it did not)

@volokluev volokluev requested a review from a team as a code owner November 1, 2022 17:36
Comment on lines +48 to +53
# IMPORTANT!!!!
# Click replaces underscores with dashes for command names
# by default. To mimic this behavior we have to do that here
# since all of our infrastructure depends on this being the
# case
actual_command_name = name.replace("-", "_")
Copy link
Member Author

Choose a reason for hiding this comment

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

bulk of the change

Comment on lines +37 to +42
# IMPORTANT!!!!
# Click replaces underscores with dashes for command names
# by default. To mimic this behavior we have to do that here
# since all of our infrastructure depends on this being the
# case
rv.append(filename[:-3].replace("_", "-"))
Copy link
Member Author

Choose a reason for hiding this comment

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

bulk of the change

Copy link
Member

@evanh evanh left a comment

Choose a reason for hiding this comment

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

I am OK with this change, but it feels a little brittle. If someone checks in a file with an actual dash in it, this will break again.

@volokluev
Copy link
Member Author

If someone checks in a file with an actual dash in it, this will break again.

True but presumably they would run the command at least once before checking it in

@volokluev volokluev merged commit 133a75c into master Nov 3, 2022
@volokluev volokluev deleted the volo/fix_init branch November 3, 2022 22:13
volokluev added a commit that referenced this pull request Nov 3, 2022
volokluev added a commit that referenced this pull request Nov 3, 2022
volokluev pushed a commit that referenced this pull request Nov 4, 2022
volokluev added a commit that referenced this pull request Nov 7, 2022
Compiling changes in #3311 and #3326 and moving the initialization up  before subcommand compilation

The deploy of #3326 caused a crashloop on `snuba-generic-metrics-distributions-subscriptions-scheduler-production`and `snuba-generic-metrics-distributions-subscriptions-scheduler-production` (and only those two)

This happened because:

1. generic_metrics entities are defined in config
2. the subscriptions scheduler cli has the entity argument defined like so:

```
@click.option(
    "--entity",
    "entity_name",
    required=True,
    type=click.Choice([entity_key.value for entity_key in EntityKey]),
    help="The entity to target",
)
```

This makes the cli depend on the entity key being fully populated *at import time*. This also makes it so that the code as is only work *by accident*. 

## The fix

We move up initialization *before* we compile the subcommand code so that all the entity factories are initialized at import time

## The test

This issue was reproducible locally by trying to run those consumer groups `snuba devserver` did not call those commands either. They have been added.

Undoing the fix will make this command fail:

```
SEPARATE_SCHEDULER_EXECUTOR_SUBSCRIPTIONS_DEV=1 ENABLE_METRICS_SUBSCRIPTIONS=1 ENABLE_SENTRY_METRICS_DEV=1 snuba devserver
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants