Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,17 +1349,17 @@
name="sentry-api-0-organization-monitors",
),
url(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id>[^\/]+)/$",
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_slug>[^\/]+)/$",
OrganizationMonitorDetailsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-details",
),
url(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id>[^\/]+)/stats/$",
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_slug>[^\/]+)/stats/$",
OrganizationMonitorStatsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-stats",
),
url(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id>[^\/]+)/checkins/$",
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_slug>[^\/]+)/checkins/$",
method_dispatch(
GET=OrganizationMonitorCheckInIndexEndpoint.as_view(),
POST=MonitorIngestCheckInIndexEndpoint.as_view(), # Legacy ingest endpoint
Expand All @@ -1368,15 +1368,15 @@
name="sentry-api-0-organization-monitor-check-in-index",
),
url(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/$",
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/$",
method_dispatch(
PUT=MonitorIngestCheckInDetailsEndpoint.as_view(), # Legacy ingest endpoint
csrf_exempt=True,
),
name="sentry-api-0-organization-monitor-check-in-details",
),
url(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
method_dispatch(
GET=OrganizationMonitorCheckInAttachmentEndpoint.as_view(),
POST=MonitorIngestCheckinAttachmentEndpoint.as_view(), # Legacy ingest endpoint
Expand Down Expand Up @@ -2625,12 +2625,12 @@
# Top-level monitor checkin APIs. NOTE that there are also organization
# level checkin ingest APIs.
url(
r"^monitors/(?P<monitor_id>[^\/]+)/checkins/$",
r"^monitors/(?P<monitor_slug>[^\/]+)/checkins/$",
MonitorIngestCheckInIndexEndpoint.as_view(),
name="sentry-api-0-monitor-ingest-check-in-index",
),
url(
r"^monitors/(?P<monitor_id>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/$",
r"^monitors/(?P<monitor_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/$",
MonitorIngestCheckInDetailsEndpoint.as_view(),
name="sentry-api-0-monitor-ingest-check-in-details",
),
Expand Down
8 changes: 4 additions & 4 deletions src/sentry/apidocs/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ class CURSOR_QUERY_PARAM(serializers.Serializer): # type: ignore


class MONITOR_PARAMS:
MONITOR_ID = OpenApiParameter(
name="monitor_id",
MONITOR_SLUG = OpenApiParameter(
name="monitor_slug",
location="path",
required=True,
type=OpenApiTypes.UUID,
description="The id of the monitor",
type=str,
description="The slug of the monitor",
)
CHECKIN_ID = OpenApiParameter(
name="checkin_id",
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/conf/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():

from celery.schedules import crontab

# XXX: Make sure to register the monitor_id for each job in `SENTRY_CELERYBEAT_MONITORS`!
# XXX: Make sure to register the monitor_slug for each job in `SENTRY_CELERYBEAT_MONITORS`!
CELERYBEAT_SCHEDULE_FILENAME = os.path.join(tempfile.gettempdir(), "sentry-celerybeat")
CELERYBEAT_SCHEDULE = {
"check-auth": {
Expand Down
18 changes: 9 additions & 9 deletions src/sentry/monitors/endpoints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def convert_args(
self,
request: Request,
organization_slug: str,
monitor_id: str,
monitor_slug: str,
checkin_id: str | None = None,
*args,
**kwargs,
Expand All @@ -58,7 +58,7 @@ def convert_args(
raise ResourceDoesNotExist

try:
monitor = Monitor.objects.get(organization_id=organization.id, slug=monitor_id)
monitor = Monitor.objects.get(organization_id=organization.id, slug=monitor_slug)
except Monitor.DoesNotExist:
raise ResourceDoesNotExist

Expand Down Expand Up @@ -109,7 +109,7 @@ class MonitorIngestEndpoint(Endpoint):

allow_auto_create_monitors = False
"""
Loosens the base endpoint such that a monitor with the provided monitor_id
Loosens the base endpoint such that a monitor with the provided monitor_slug
does not need to exist. This is used for initial checkin creation with
monitor upsert.

Expand All @@ -121,7 +121,7 @@ class MonitorIngestEndpoint(Endpoint):
def convert_args(
self,
request: Request,
monitor_id: str,
monitor_slug: str,
checkin_id: str | None = None,
organization_slug: str | None = None,
*args,
Expand All @@ -130,9 +130,9 @@ def convert_args(
organization = None
monitor = None

# Include monitor_id in kwargs when upsert is enabled
# Include monitor_slug in kwargs when upsert is enabled
if self.allow_auto_create_monitors:
kwargs["monitor_id"] = monitor_id
kwargs["monitor_slug"] = monitor_slug

using_dsn_auth = isinstance(request.auth, ProjectKey)

Expand All @@ -147,20 +147,20 @@ def convert_args(
organization = Organization.objects.get_from_cache(slug=organization_slug)
# Try lookup by slug first. This requires organization context since
# slugs are unique only to the organization
monitor = Monitor.objects.get(organization_id=organization.id, slug=monitor_id)
monitor = Monitor.objects.get(organization_id=organization.id, slug=monitor_slug)
except (Organization.DoesNotExist, Monitor.DoesNotExist):
pass

# Try lookup by GUID
if not monitor:
# Validate GUIDs
try:
UUID(monitor_id)
UUID(monitor_slug)
# When looking up by guid we don't include the org conditional
# (since GUID lookup allows orgless routes), we will validate
# permissions later in this function
try:
monitor = Monitor.objects.get(guid=monitor_id)
monitor = Monitor.objects.get(guid=monitor_slug)
except Monitor.DoesNotExist:
monitor = None
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MonitorIngestCheckInDetailsEndpoint(MonitorIngestEndpoint):
operation_id="Update a check-in",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
MONITOR_PARAMS.CHECKIN_ID,
],
request=MonitorCheckInValidator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MonitorIngestCheckInIndexEndpoint(MonitorIngestEndpoint):
operation_id="Create a new check-in",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
],
request=MonitorCheckInValidator,
responses={
Expand All @@ -82,7 +82,7 @@ def post(
self,
request: Request,
project: Project,
monitor_id: str,
monitor_slug: str,
monitor: Monitor | None,
organization_slug: str | None = None,
) -> Response:
Expand All @@ -104,13 +104,13 @@ def post(

checkin_validator = MonitorCheckInValidator(
data=request.data,
context={"project": project, "request": request, "monitor_id": monitor_id},
context={"project": project, "request": request, "monitor_slug": monitor_slug},
)
if not checkin_validator.is_valid():
return self.respond(checkin_validator.errors, status=400)

if not monitor:
ratelimit_key = monitor_id
ratelimit_key = monitor_slug
else:
ratelimit_key = monitor.id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class OrganizationMonitorCheckInIndexEndpoint(MonitorEndpoint):
operation_id="Retrieve check-ins for a monitor",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
MONITOR_PARAMS.CHECKIN_ID,
],
responses={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OrganizationMonitorDetailsEndpoint(MonitorEndpoint):
operation_id="Retrieve a monitor",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
],
responses={
200: inline_sentry_response_serializer("Monitor", MonitorSerializerResponse),
Expand All @@ -60,7 +60,7 @@ def get(self, request: Request, organization, project, monitor) -> Response:
operation_id="Update a monitor",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
],
request=MonitorValidator,
responses={
Expand Down Expand Up @@ -125,7 +125,7 @@ def put(self, request: Request, organization, project, monitor) -> Response:
operation_id="Delete a monitor",
parameters=[
GLOBAL_PARAMS.ORG_SLUG,
MONITOR_PARAMS.MONITOR_ID,
MONITOR_PARAMS.MONITOR_SLUG,
],
request=MonitorValidator,
responses={
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/monitors/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ def validate(self, attrs):
monitor_validator = MonitorValidator(
data={
"type": "cron_job",
"name": self.context["monitor_id"],
"slug": self.context["monitor_id"],
"name": self.context["monitor_slug"],
"slug": self.context["monitor_slug"],
"project": project.slug,
"config": monitor_config,
},
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/testutils/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,8 +2365,8 @@ def _get_path_functions(self):
# Because removing old urls takes time and consideration of the cost of breaking lingering references, a
# decision to permanently remove either path schema is a TODO.
return (
lambda monitor_id: reverse(self.endpoint, args=[monitor_id]),
lambda monitor_id: reverse(
self.endpoint_with_org, args=[self.organization.slug, monitor_id]
lambda monitor_slug: reverse(self.endpoint, args=[monitor_slug]),
lambda monitor_slug: reverse(
self.endpoint_with_org, args=[self.organization.slug, monitor_slug]
),
)
18 changes: 9 additions & 9 deletions src/sentry/utils/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def connect(app):
if hasattr(app.conf, "beat_schedule")
else app.conf["CELERYBEAT_SCHEDULE"]
)
for schedule_name, monitor_id in settings.SENTRY_CELERYBEAT_MONITORS.items():
for schedule_name, monitor_slug in settings.SENTRY_CELERYBEAT_MONITORS.items():
schedule[schedule_name].setdefault("options", {}).setdefault("headers", {}).setdefault(
"X-Sentry-Monitor", monitor_id
"X-Sentry-Monitor", monitor_slug
)


Expand All @@ -63,16 +63,16 @@ def report_monitor_begin(task, **kwargs):
if not headers:
return

monitor_id = headers.get("X-Sentry-Monitor")
if not monitor_id:
monitor_slug = headers.get("X-Sentry-Monitor")
if not monitor_slug:
return

with configure_scope() as scope:
scope.set_context("monitor", {"id": monitor_id})
scope.set_context("monitor", {"id": monitor_slug})

with SafeSession() as session:
req = session.post(
f"{API_ROOT}/api/0/monitors/{monitor_id}/checkins/",
f"{API_ROOT}/api/0/monitors/{monitor_slug}/checkins/",
headers={"Authorization": f"DSN {SENTRY_DSN}"},
json={"status": "in_progress"},
)
Expand All @@ -90,8 +90,8 @@ def report_monitor_complete(task, retval, **kwargs):
if not headers:
return

monitor_id = headers.get("X-Sentry-Monitor")
if not monitor_id:
monitor_slug = headers.get("X-Sentry-Monitor")
if not monitor_slug:
return

try:
Expand All @@ -103,7 +103,7 @@ def report_monitor_complete(task, retval, **kwargs):

with SafeSession() as session:
session.put(
f"{API_ROOT}/api/0/monitors/{monitor_id}/checkins/{checkin_id}/",
f"{API_ROOT}/api/0/monitors/{monitor_slug}/checkins/{checkin_id}/",
headers={"Authorization": f"DSN {SENTRY_DSN}"},
json={
"status": "error" if isinstance(retval, Exception) else "ok",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def _get_path_functions(self):
# Because removing old urls takes time and consideration of the cost of breaking lingering references, a
# decision to permanently remove either path schema is a TODO.
return (
lambda monitor_id, checkin_id: reverse(self.endpoint, args=[monitor_id, checkin_id]),
lambda monitor_id, checkin_id: reverse(
self.endpoint_with_org, args=[self.organization.slug, monitor_id, checkin_id]
lambda monitor_slug, checkin_id: reverse(
self.endpoint, args=[monitor_slug, checkin_id]
),
lambda monitor_slug, checkin_id: reverse(
self.endpoint_with_org, args=[self.organization.slug, monitor_slug, checkin_id]
),
)

Expand Down