Skip to content

Commit 722aee0

Browse files
authored
Feat/opt automator add region (#54631)
Added region to the options automator.
1 parent df68174 commit 722aee0

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

src/sentry/conf/server.py

+3
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ def SOCIAL_AUTH_DEFAULT_USERNAME() -> str:
632632
# If this instance is a region silo, which region is it running in?
633633
SENTRY_REGION = os.environ.get("SENTRY_REGION", None)
634634

635+
# Returns the customer single tenant ID.
636+
CUSTOMER_ID = os.environ.get("CUSTOMER_ID", None)
637+
635638
# Enable siloed development environment.
636639
USE_SILOS = os.environ.get("SENTRY_USE_SILOS", None)
637640

src/sentry/runner/commands/configoptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Optional, Set
33

44
import click
5-
from yaml import safe_dump, safe_load
5+
from yaml import safe_load
66

77
from sentry.runner.commands.presenters.presenterdelegator import PresenterDelegator
88
from sentry.runner.decorators import configuration, log_options
@@ -31,7 +31,7 @@ def _attempt_update(
3131
if hide_drift:
3232
presenter_delegator.drift(key, "")
3333
else:
34-
presenter_delegator.drift(key, safe_dump(db_value_to_print))
34+
presenter_delegator.drift(key, db_value_to_print)
3535
return
3636

3737
last_update_channel = options.get_last_update_channel(key)

src/sentry/runner/commands/presenters/consolepresenter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, List, Tuple
22

33
import click
4+
from yaml import safe_dump
45

56
from sentry.runner.commands.presenters.optionspresenter import OptionsPresenter
67

@@ -47,7 +48,7 @@ def flush(self) -> None:
4748
# This is yaml instead of the python representation as the
4849
# expected flow, in this case, is to use the output of this
4950
# line to copy paste it in the config map.
50-
click.echo(db_value)
51+
click.echo(safe_dump(db_value))
5152

5253
for key in self.channel_updated_options:
5354
click.echo(self.CHANNEL_UPDATE_MSG % key)

src/sentry/runner/commands/presenters/slackpresenter.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List, Tuple
1+
from typing import Any, List, Optional, Tuple
22

33
import requests
44
from django.conf import settings
@@ -66,7 +66,12 @@ def is_slack_enabled():
6666
raise
6767

6868
def flush(self) -> None:
69+
region: Optional[str] = settings.SENTRY_REGION
70+
if not region:
71+
region = settings.CUSTOMER_ID
72+
6973
json_data = {
74+
"region": region,
7075
"drifted_options": [
7176
{"option_name": key, "option_value": self.truncate_value(value)}
7277
for key, value in self.drifted_options

tests/sentry/runner/commands/presenters/test_slackpresenter.py

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class TestSlackPresenter:
1111
def setup(self):
1212
self.slackPresenter = SlackPresenter()
1313
settings.OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL = "https://test/"
14+
settings.SENTRY_REGION = "test_region"
1415

1516
@responses.activate
1617
def test_is_slack_enabled(self):
@@ -44,6 +45,7 @@ def test_is_slack_enabled(self):
4445
self.slackPresenter.flush()
4546

4647
expected_json_data = {
48+
"region": "test_region",
4749
"drifted_options": [
4850
{"option_name": "option9", "option_value": "db_value9"},
4951
{"option_name": "option10", "option_value": "db_value10"},
@@ -97,6 +99,7 @@ def test_slack_presenter_methods_with_different_types(self):
9799
self.slackPresenter.flush()
98100

99101
expected_json_data = {
102+
"region": "test_region",
100103
"drifted_options": [{"option_name": "drifted", "option_value": "{'key': 'value'}"}],
101104
"updated_options": [{"option_name": "updated", "db_value": "1.0", "value": "0.0"}],
102105
"set_options": [

0 commit comments

Comments
 (0)