Browse Source

ref(globalconfig): Add measurements to global config (#55337)

Add `measurements` measurements config to the global config, currently
unused.
Iker Barriocanal 1 year ago
parent
commit
833ce710d4

+ 4 - 3
src/sentry/relay/globalconfig.py

@@ -1,9 +1,10 @@
+from sentry.relay.config.measurements import get_measurements_config
 from sentry.utils import metrics
 
 
 @metrics.wraps("relay.globalconfig.get")
 def get_global_config():
     """Return the global configuration for Relay."""
-    # TODO(iker): Add entries for the global config as needed, empty during
-    # development.
-    return {}
+    return {
+        "measurements": get_measurements_config(),
+    }

+ 43 - 2
tests/sentry/api/endpoints/test_relay_globalconfig_v4.py

@@ -1,6 +1,9 @@
+from unittest.mock import patch
+
 import pytest
 from django.urls import reverse
 
+from sentry.relay.globalconfig import get_global_config
 from sentry.testutils.pytest.fixtures import django_db_all
 from sentry.utils import json
 
@@ -26,6 +29,41 @@ def call_endpoint(client, relay, private_key):
     return inner
 
 
+def test_global_config():
+    assert get_global_config() == {
+        "measurements": {
+            "builtinMeasurements": [
+                {"name": "app_start_cold", "unit": "millisecond"},
+                {"name": "app_start_warm", "unit": "millisecond"},
+                {"name": "cls", "unit": "none"},
+                {"name": "fcp", "unit": "millisecond"},
+                {"name": "fid", "unit": "millisecond"},
+                {"name": "fp", "unit": "millisecond"},
+                {"name": "frames_frozen_rate", "unit": "ratio"},
+                {"name": "frames_frozen", "unit": "none"},
+                {"name": "frames_slow_rate", "unit": "ratio"},
+                {"name": "frames_slow", "unit": "none"},
+                {"name": "frames_total", "unit": "none"},
+                {"name": "inp", "unit": "millisecond"},
+                {"name": "lcp", "unit": "millisecond"},
+                {"name": "stall_count", "unit": "none"},
+                {"name": "stall_longest_time", "unit": "millisecond"},
+                {"name": "stall_percentage", "unit": "ratio"},
+                {"name": "stall_total_time", "unit": "millisecond"},
+                {"name": "ttfb.requesttime", "unit": "millisecond"},
+                {"name": "ttfb", "unit": "millisecond"},
+                {"name": "time_to_full_display", "unit": "millisecond"},
+                {"name": "time_to_initial_display", "unit": "millisecond"},
+            ],
+            "maxCustomMeasurements": 10,
+        }
+    }
+
+
+@patch(
+    "sentry.api.endpoints.relay.project_configs.get_global_config",
+    lambda *args, **kargs: {"global_mock_config": True},
+)
 @pytest.mark.parametrize(
     ("version, request_global_config, expect_global_config"),
     [
@@ -37,11 +75,14 @@ def call_endpoint(client, relay, private_key):
 )
 @django_db_all
 def test_return_global_config_on_right_version(
-    call_endpoint, version, request_global_config, expect_global_config
+    call_endpoint,
+    version,
+    request_global_config,
+    expect_global_config,
 ):
     result, status_code = call_endpoint(version, request_global_config)
     assert status_code < 400
     if not expect_global_config:
         assert "global" not in result
     else:
-        assert result.get("global") == {}
+        assert result.get("global") == {"global_mock_config": True}

+ 24 - 10
tests/sentry/api/endpoints/test_relay_projectconfigs_v4.py

@@ -54,6 +54,14 @@ def projectconfig_cache_get_mock_config(monkeypatch):
     )
 
 
+@pytest.fixture
+def globalconfig_get_mock_config(monkeypatch):
+    monkeypatch.setattr(
+        "sentry.relay.globalconfig.get_global_config",
+        lambda *args, **kargs: {"global_mock_config": True},
+    )
+
+
 @pytest.fixture
 def single_mock_proj_cached(monkeypatch):
     def cache_get(*args, **kwargs):
@@ -82,7 +90,10 @@ def project_config_get_mock(monkeypatch):
 
 @django_db_all
 def test_return_full_config_if_in_cache(
-    call_endpoint, default_projectkey, projectconfig_cache_get_mock_config
+    call_endpoint,
+    default_projectkey,
+    projectconfig_cache_get_mock_config,
+    globalconfig_get_mock_config,
 ):
     result, status_code = call_endpoint(full_config=True)
     assert status_code == 200
@@ -92,22 +103,28 @@ def test_return_full_config_if_in_cache(
     }
 
 
+@patch(
+    "sentry.api.endpoints.relay.project_configs.get_global_config",
+    lambda *args, **kargs: {"global_mock_config": True},
+)
 @django_db_all
 def test_return_project_and_global_config(
-    call_endpoint, default_projectkey, projectconfig_cache_get_mock_config
+    call_endpoint,
+    default_projectkey,
+    projectconfig_cache_get_mock_config,
 ):
     result, status_code = call_endpoint(full_config=True, global_=True)
     assert status_code == 200
     assert result == {
         "configs": {default_projectkey.public_key: {"is_mock_config": True}},
         "pending": [],
-        "global": {},
+        "global": {"global_mock_config": True},
     }
 
 
 @django_db_all
 def test_proj_in_cache_and_another_pending(
-    call_endpoint, default_projectkey, single_mock_proj_cached
+    call_endpoint, default_projectkey, single_mock_proj_cached, globalconfig_get_mock_config
 ):
     result, status_code = call_endpoint(
         full_config=True, public_keys=["must_exist", default_projectkey.public_key]
@@ -122,9 +139,7 @@ def test_proj_in_cache_and_another_pending(
 @patch("sentry.tasks.relay.build_project_config.delay")
 @django_db_all
 def test_enqueue_task_if_config_not_cached_not_queued(
-    schedule_mock,
-    call_endpoint,
-    default_projectkey,
+    schedule_mock, call_endpoint, default_projectkey, globalconfig_get_mock_config
 ):
     result, status_code = call_endpoint(full_config=True)
     assert status_code == 200
@@ -139,6 +154,7 @@ def test_debounce_task_if_proj_config_not_cached_already_enqueued(
     call_endpoint,
     default_projectkey,
     projectconfig_debounced_cache,
+    globalconfig_get_mock_config,
 ):
     result, status_code = call_endpoint(full_config=True)
     assert status_code == 200
@@ -149,9 +165,7 @@ def test_debounce_task_if_proj_config_not_cached_already_enqueued(
 @patch("sentry.relay.projectconfig_cache.backend.set_many")
 @django_db_all
 def test_task_writes_config_into_cache(
-    cache_set_many_mock,
-    default_projectkey,
-    project_config_get_mock,
+    cache_set_many_mock, default_projectkey, project_config_get_mock, globalconfig_get_mock_config
 ):
     build_project_config(
         public_key=default_projectkey.public_key,