-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Feat/opt automator add region #54631
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
Conversation
src/sentry/conf/server.py
Outdated
@@ -3660,5 +3660,11 @@ def build_cdc_postgres_init_db_volume(settings: Any) -> dict[str, dict[str, str] | |||
# are changed by sentry configoptions. | |||
OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL: Optional[str] = None | |||
|
|||
# This setting is specific to the options automator. It gets the current region or | |||
# customer in the case of single tenant. | |||
SENTRY_REGION_OR_CUSTOMER: Optional[str] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also just make it
CUSTOMER_ID = os.environ.get("CUSTOMER_ID" , None)
and call SENTRY_REGION
as its already defined in server.py?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues here.
I am a little skeptic that we do not already have a unified way to identiy ST customers or regions. I'd expect Hybrid Cloud would have already dealt with this problem. Mind checking in with them if there is arleady a library somewhere that returns the tenant/region ?
If such api to get the region/tenant does not exist, please do not register this unified value as a setting.
By registering something as a setting you are stating that the value has a default but can be customized and overridden. Which is not what you want. What you want is that sentry_region_or_customer
is always either sentry_region or customer_id or None. So you never want this to be overridden to something else.
Thus please move this as a variable or constant inside the presenter that needs it.
Other argument against a dedicated setting. Thiw would add logic into the settings file. This would have unintended consequences that you do not want. It implies the setting file must always be a python file or be able to store arbitrary logic, which makes it less like a setting file and make it hard to move to something like a json/yaml file.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #54631 +/- ##
==========================================
+ Coverage 79.74% 79.75% +0.01%
==========================================
Files 4995 5001 +6
Lines 212236 212309 +73
Branches 36180 36185 +5
==========================================
+ Hits 169250 169337 +87
+ Misses 37777 37760 -17
- Partials 5209 5212 +3
|
The test failure is relevant. Please address that |
@@ -31,7 +31,7 @@ def _attempt_update( | |||
if hide_drift: | |||
presenter_delegator.drift(key, "") | |||
else: | |||
presenter_delegator.drift(key, safe_dump(db_value_to_print)) | |||
presenter_delegator.drift(key, db_value_to_print) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related ?
json_data = { | ||
"region": region, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you deploy this first and this key is passed to the webhook in eng-pipes before the change to eng-pipes goes out? Would the key be safely ignored or would the webhook break.
In other words: which is the right order to deploy changes here and eng-pipes to ensure backwards compatibility and that nothing breaks at any point in time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I'll add the deployment process to the slack as well but:
I made it so that if region is not given eng pipes prints messages as is, that way deployment order is not important.
But Ideally, we would deploy here first, eng-pipes would ignore the extra key, I already tested this.
Then we would deploy eng-pipes.
Then we would add the webhook url to getsentry for ST.
Finally we would turn on the option for the slack_webhook in ST.
src/sentry/conf/server.py
Outdated
@@ -3660,5 +3660,11 @@ def build_cdc_postgres_init_db_volume(settings: Any) -> dict[str, dict[str, str] | |||
# are changed by sentry configoptions. | |||
OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL: Optional[str] = None | |||
|
|||
# This setting is specific to the options automator. It gets the current region or | |||
# customer in the case of single tenant. | |||
SENTRY_REGION_OR_CUSTOMER: Optional[str] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues here.
I am a little skeptic that we do not already have a unified way to identiy ST customers or regions. I'd expect Hybrid Cloud would have already dealt with this problem. Mind checking in with them if there is arleady a library somewhere that returns the tenant/region ?
If such api to get the region/tenant does not exist, please do not register this unified value as a setting.
By registering something as a setting you are stating that the value has a default but can be customized and overridden. Which is not what you want. What you want is that sentry_region_or_customer
is always either sentry_region or customer_id or None. So you never want this to be overridden to something else.
Thus please move this as a variable or constant inside the presenter that needs it.
Other argument against a dedicated setting. Thiw would add logic into the settings file. This would have unintended consequences that you do not want. It implies the setting file must always be a python file or be able to store arbitrary logic, which makes it less like a setting file and make it hard to move to something like a json/yaml file.
region = settings.SENTRY_REGION | ||
|
||
if not region: | ||
region = os.environ.get("CUSTOMER_ID") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not rely on the env variable directly in application code.
Add a setting that defaults to os.environ.get("CUSTOMER_ID")
just like settings.SENTRY_REGION
That's how the application has access to env vars.
The app does not need to know what is set by overriding a setting file or by providing an environment variables. This is a choice of who runs sentry.
We use the settings module as an abstraction so that the application does not have to take both settings and environment variable into account every time it needs a setting.
@@ -66,7 +66,12 @@ def is_slack_enabled(): | |||
raise | |||
|
|||
def flush(self) -> None: | |||
region: Optional[str] = settings.SENTRY_REGION | |||
if not region: | |||
region = settings.CUSTOMER_ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this is None as well ? Would the webhook break if you pass None ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Webhook will not break, it will default to sending the message without region defined. I can reconfigure this behavior in eng-pipes as needed, but I think thats fine.
Added region to the options automator.
for STs "SENTRY_REGION" doesn't work so I'm calling it from "CUSTOMER_ID".
If theres a better way to get the ST region I'm open to it.