Browse Source

Feat/opt automator add region (#54631)

Added region to the options automator.
Neo Huang 1 year ago
parent
commit
722aee030f

+ 3 - 0
src/sentry/conf/server.py

@@ -632,6 +632,9 @@ SILO_MODE = os.environ.get("SENTRY_SILO_MODE", None)
 # If this instance is a region silo, which region is it running in?
 SENTRY_REGION = os.environ.get("SENTRY_REGION", None)
 
+# Returns the customer single tenant ID.
+CUSTOMER_ID = os.environ.get("CUSTOMER_ID", None)
+
 # Enable siloed development environment.
 USE_SILOS = os.environ.get("SENTRY_USE_SILOS", None)
 

+ 2 - 2
src/sentry/runner/commands/configoptions.py

@@ -2,7 +2,7 @@ import sys
 from typing import Any, Optional, Set
 
 import click
-from yaml import safe_dump, safe_load
+from yaml import safe_load
 
 from sentry.runner.commands.presenters.presenterdelegator import PresenterDelegator
 from sentry.runner.decorators import configuration, log_options
@@ -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)
         return
 
     last_update_channel = options.get_last_update_channel(key)

+ 2 - 1
src/sentry/runner/commands/presenters/consolepresenter.py

@@ -1,6 +1,7 @@
 from typing import Any, List, Tuple
 
 import click
+from yaml import safe_dump
 
 from sentry.runner.commands.presenters.optionspresenter import OptionsPresenter
 
@@ -47,7 +48,7 @@ class ConsolePresenter(OptionsPresenter):
                 # This is yaml instead of the python representation as the
                 # expected flow, in this case, is to use the output of this
                 # line to copy paste it in the config map.
-                click.echo(db_value)
+                click.echo(safe_dump(db_value))
 
         for key in self.channel_updated_options:
             click.echo(self.CHANNEL_UPDATE_MSG % key)

+ 6 - 1
src/sentry/runner/commands/presenters/slackpresenter.py

@@ -1,4 +1,4 @@
-from typing import Any, List, Tuple
+from typing import Any, List, Optional, Tuple
 
 import requests
 from django.conf import settings
@@ -66,7 +66,12 @@ class SlackPresenter(OptionsPresenter):
             raise
 
     def flush(self) -> None:
+        region: Optional[str] = settings.SENTRY_REGION
+        if not region:
+            region = settings.CUSTOMER_ID
+
         json_data = {
+            "region": region,
             "drifted_options": [
                 {"option_name": key, "option_value": self.truncate_value(value)}
                 for key, value in self.drifted_options

+ 3 - 0
tests/sentry/runner/commands/presenters/test_slackpresenter.py

@@ -11,6 +11,7 @@ class TestSlackPresenter:
     def setup(self):
         self.slackPresenter = SlackPresenter()
         settings.OPTIONS_AUTOMATOR_SLACK_WEBHOOK_URL = "https://test/"
+        settings.SENTRY_REGION = "test_region"
 
     @responses.activate
     def test_is_slack_enabled(self):
@@ -44,6 +45,7 @@ class TestSlackPresenter:
         self.slackPresenter.flush()
 
         expected_json_data = {
+            "region": "test_region",
             "drifted_options": [
                 {"option_name": "option9", "option_value": "db_value9"},
                 {"option_name": "option10", "option_value": "db_value10"},
@@ -97,6 +99,7 @@ class TestSlackPresenter:
         self.slackPresenter.flush()
 
         expected_json_data = {
+            "region": "test_region",
             "drifted_options": [{"option_name": "drifted", "option_value": "{'key': 'value'}"}],
             "updated_options": [{"option_name": "updated", "db_value": "1.0", "value": "0.0"}],
             "set_options": [