Browse Source

feat(relay): Introduce options to global config (#61024)

Setup infrastructure to add options to the global config, also update
the global config endpoint to signal relay the global config is fully
ready.
David Herberth 1 year ago
parent
commit
b5778482df

+ 1 - 0
src/sentry/api/endpoints/relay/project_configs.py

@@ -64,6 +64,7 @@ class RelayProjectConfigsEndpoint(Endpoint):
 
         if version == "3" and request.relay_request_data.get("global"):
             response["global"] = get_global_config()
+            response["global_status"] = "ready"
 
         if self._should_post_or_schedule(version, request):
             # Always compute the full config. It's invalid to send partial

+ 24 - 2
src/sentry/relay/globalconfig.py

@@ -1,10 +1,32 @@
-from sentry.relay.config.measurements import get_measurements_config
+from typing import Any, Dict, List, TypedDict
+
+import sentry.options
+from sentry.relay.config.measurements import MeasurementsConfig, get_measurements_config
 from sentry.utils import metrics
 
+# List of options to include in the global config.
+RELAY_OPTIONS: List[str] = []
+
+
+class GlobalConfig(TypedDict, total=False):
+    measurements: MeasurementsConfig
+    options: Dict[str, Any]
+
 
 @metrics.wraps("relay.globalconfig.get")
 def get_global_config():
     """Return the global configuration for Relay."""
-    return {
+
+    global_config: GlobalConfig = {
         "measurements": get_measurements_config(),
     }
+
+    options = dict()
+    for option in RELAY_OPTIONS:
+        if (value := sentry.options.get(option)) is not None:
+            options[option] = value
+
+    if options:
+        global_config["options"] = options
+
+    return global_config

+ 1 - 0
tests/sentry/api/endpoints/test_relay_projectconfigs_v3.py

@@ -189,4 +189,5 @@ def test_return_project_and_global_config(
         "configs": {default_projectkey.public_key: {"is_mock_config": True}},
         "pending": [],
         "global": {"global_mock_config": True},
+        "global_status": "ready",
     }