Skip to content
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

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

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sentry/api/endpoints/relay/project_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def _post(self, request: Request):

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
Expand Down
27 changes: 25 additions & 2 deletions src/sentry/relay/globalconfig.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
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:
value = sentry.options.get(option)
if value is not None:
options[option] = value

if options:
global_config["options"] = options
Comment on lines +29 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test it with relay library and make sure this is the protocol relay expects, like in

You may need to make a new librelay release too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be tested the moment we actually add an option we want exposed in Relay. Now this requires monkey patching the global list and the next person adding the first option would actually have to remember to remove the monkey patch again.


return global_config
1 change: 1 addition & 0 deletions tests/sentry/api/endpoints/test_relay_projectconfigs_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}