-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(hybridcloud) Improve API gateway routing for error-embed #69815
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
import logging | ||
from collections.abc import Iterator | ||
from urllib.parse import urljoin | ||
from urllib.parse import urljoin, urlparse | ||
from wsgiref.util import is_hop_by_hop | ||
|
||
from django.conf import settings | ||
|
@@ -16,6 +16,7 @@ | |
from requests import request as external_request | ||
from requests.exceptions import Timeout | ||
|
||
from sentry import options | ||
from sentry.api.exceptions import RequestTimeout | ||
from sentry.models.integrations.sentry_app import SentryApp | ||
from sentry.models.integrations.sentry_app_installation import SentryAppInstallation | ||
|
@@ -149,6 +150,36 @@ def proxy_sentryapp_request( | |
return proxy_region_request(request, region, url_name) | ||
|
||
|
||
def proxy_error_embed_request( | ||
request: HttpRequest, dsn: str, url_name: str | ||
) -> HttpResponseBase | None: | ||
try: | ||
parsed = urlparse(dsn) | ||
except Exception: | ||
return None | ||
host = parsed.netloc | ||
app_host = urlparse(options.get("system.url-prefix")).netloc | ||
if not host.endswith(app_host): | ||
# Don't further parse URLs that aren't for us. | ||
return None | ||
|
||
app_segments = app_host.split(".") | ||
host_segments = host.split(".") | ||
if len(host_segments) - len(app_segments) < 3: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, if we're running in monolith mode we'd never hit this code path? Thinking about the case for self-hosted where domains might be weird There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the apigateway middleware is only active when the application is in control mode. |
||
# If we don't have a o123.ingest.{region}.{app_host} style domain | ||
# we forward to the monolith region | ||
region = get_region_by_name(settings.SENTRY_MONOLITH_REGION) | ||
return proxy_region_request(request, region, url_name) | ||
try: | ||
region_offset = len(app_segments) + 1 | ||
region_segment = host_segments[region_offset * -1] | ||
region = get_region_by_name(region_segment) | ||
except Exception: | ||
return None | ||
|
||
return proxy_region_request(request, region, url_name) | ||
|
||
|
||
def proxy_region_request( | ||
request: HttpRequest, region: Region, url_name: str | ||
) -> StreamingHttpResponse: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth tracking all the
return None
cases with a metric or log entry?