-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crons): Add api for fetching checkin processing errors for an org (
#70563) This allows us to return processing errors for organizations. Can be filtered by project id <!-- Describe your PR here. -->
- Loading branch information
Showing
5 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/sentry/monitors/endpoints/organization_monitor_processing_errors_index.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from drf_spectacular.utils import extend_schema | ||
from rest_framework.response import Response | ||
|
||
from sentry.api.api_owners import ApiOwner | ||
from sentry.api.api_publish_status import ApiPublishStatus | ||
from sentry.api.base import region_silo_endpoint | ||
from sentry.api.bases import OrganizationEndpoint | ||
from sentry.api.paginator import SequencePaginator | ||
from sentry.api.serializers import serialize | ||
from sentry.apidocs.constants import RESPONSE_FORBIDDEN, RESPONSE_NOT_FOUND, RESPONSE_UNAUTHORIZED | ||
from sentry.apidocs.parameters import GlobalParams | ||
from sentry.apidocs.utils import inline_sentry_response_serializer | ||
from sentry.models.organization import Organization | ||
from sentry.monitors.processing_errors import ( | ||
CheckinProcessErrorsManager, | ||
CheckinProcessingErrorData, | ||
) | ||
from sentry.utils.auth import AuthenticatedHttpRequest | ||
|
||
|
||
@region_silo_endpoint | ||
@extend_schema(tags=["Crons"]) | ||
class OrganizationMonitorProcessingErrorsIndexEndpoint(OrganizationEndpoint): | ||
publish_status = { | ||
"GET": ApiPublishStatus.PRIVATE, | ||
} | ||
owner = ApiOwner.CRONS | ||
|
||
@extend_schema( | ||
operation_id="Retrieve checkin processing errors for an Organization", | ||
parameters=[ | ||
GlobalParams.ORG_SLUG, | ||
GlobalParams.PROJECT_ID_OR_SLUG, | ||
], | ||
responses={ | ||
200: inline_sentry_response_serializer( | ||
"CheckinProcessingError", list[CheckinProcessingErrorData] | ||
), | ||
401: RESPONSE_UNAUTHORIZED, | ||
403: RESPONSE_FORBIDDEN, | ||
404: RESPONSE_NOT_FOUND, | ||
}, | ||
) | ||
def get(self, request: AuthenticatedHttpRequest, organization: Organization) -> Response: | ||
""" | ||
Retrieves checkin processing errors for a monitor | ||
""" | ||
projects = self.get_projects(request, organization) | ||
paginator = SequencePaginator( | ||
list(enumerate(CheckinProcessErrorsManager().get_for_projects(projects))) | ||
) | ||
|
||
return self.paginate( | ||
request=request, | ||
paginator=paginator, | ||
on_results=lambda results: serialize(results, request.user), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
tests/sentry/monitors/endpoints/test_organization_monitor_processing_errors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from sentry.api.serializers import serialize | ||
from sentry.monitors.processing_errors import ( | ||
CheckinProcessErrorsManager, | ||
ProcessingError, | ||
ProcessingErrorType, | ||
) | ||
from sentry.monitors.testutils import build_checkin_processing_error | ||
from sentry.testutils.cases import APITestCase, MonitorTestCase | ||
from sentry.utils import json | ||
|
||
|
||
class OrganizationMonitorProcessingErrorsIndexEndpointTest(MonitorTestCase, APITestCase): | ||
endpoint = "sentry-api-0-organization-monitor-processing-errors-index" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.login_as(user=self.user) | ||
|
||
def test_empty(self): | ||
resp = self.get_success_response(self.organization.slug) | ||
assert resp.data == [] | ||
|
||
def test(self): | ||
monitor = self.create_monitor() | ||
project_2 = self.create_project() | ||
|
||
manager = CheckinProcessErrorsManager() | ||
monitor_error = build_checkin_processing_error( | ||
[ProcessingError(ProcessingErrorType.CHECKIN_INVALID_GUID, {"guid": "bad"})], | ||
message_overrides={"project_id": self.project.id}, | ||
payload_overrides={"monitor_slug": monitor.slug}, | ||
) | ||
|
||
project_errors = [ | ||
build_checkin_processing_error( | ||
[ProcessingError(ProcessingErrorType.ORGANIZATION_KILLSWITCH_ENABLED)], | ||
message_overrides={"project_id": self.project.id}, | ||
), | ||
build_checkin_processing_error( | ||
[ProcessingError(ProcessingErrorType.MONITOR_DISABLED, {"some": "data"})], | ||
message_overrides={"project_id": self.project.id}, | ||
), | ||
build_checkin_processing_error( | ||
[ProcessingError(ProcessingErrorType.MONITOR_DISABLED, {"some": "data"})], | ||
message_overrides={"project_id": project_2.id}, | ||
), | ||
] | ||
|
||
manager.store(monitor_error, monitor) | ||
for error in project_errors: | ||
manager.store(error, None) | ||
|
||
resp = self.get_success_response( | ||
self.organization.slug, project=[self.project.id, project_2.id] | ||
) | ||
assert resp.data == json.loads(json.dumps(serialize(list(reversed(project_errors))))) | ||
|
||
resp = self.get_success_response(self.organization.slug, project=[self.project.id]) | ||
assert resp.data == json.loads(json.dumps(serialize(list(reversed(project_errors[:2]))))) | ||
|
||
resp = self.get_success_response(self.organization.slug, project=[project_2.id]) | ||
assert resp.data == json.loads(json.dumps(serialize(list(reversed(project_errors[2:]))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters