Skip to content

fix(aci): Add an initial UptimeSubscription serializer #92150

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

Merged
merged 1 commit into from
May 23, 2025
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
34 changes: 32 additions & 2 deletions src/sentry/uptime/endpoints/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import MutableMapping, Sequence
from typing import Any, Literal, TypedDict, cast
from typing import Any, Literal, TypedDict, cast, override

from django.db.models import prefetch_related_objects
from sentry_kafka_schemas.schema_types.snuba_uptime_results_v1 import (
Expand All @@ -10,7 +10,7 @@
from sentry.api.serializers import Serializer, register, serialize
from sentry.api.serializers.models.actor import ActorSerializer, ActorSerializerResponse
from sentry.types.actor import Actor
from sentry.uptime.models import ProjectUptimeSubscription
from sentry.uptime.models import ProjectUptimeSubscription, UptimeSubscription
from sentry.uptime.subscriptions.regions import get_region_config
from sentry.uptime.types import EapCheckEntry, IncidentStatus

Expand Down Expand Up @@ -134,3 +134,33 @@ def serialize(
"region": obj.region,
"regionName": region_name,
}


class UptimeSubscriptionSerializerResponse(TypedDict):
timeoutMs: int
intervalSeconds: int
method: str
url: str
urlDomain: str
urlDomainSuffix: str
traceSampling: bool
hostProviderId: str
hostProviderName: str


@register(UptimeSubscription)
class UptimeSubscriptionSerializer(Serializer):

@override
def serialize(self, obj: UptimeSubscription, attrs, user, **kwargs) -> dict[str, Any]:
return {
"timeoutMs": obj.timeout_ms,
"intervalSeconds": obj.interval_seconds,
"method": obj.method,
"url": obj.url,
"urlDomain": obj.url_domain,
"urlDomainSuffix": obj.url_domain_suffix,
"traceSampling": obj.trace_sampling,
"hostProviderId": obj.host_provider_id,
"hostProviderName": obj.host_provider_name,
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)
from sentry.testutils.cases import APITestCase
from sentry.testutils.silo import region_silo_test
from sentry.uptime.grouptype import UptimeDomainCheckFailure
from sentry.uptime.types import DATA_SOURCE_UPTIME_SUBSCRIPTION
from sentry.workflow_engine.models import DataCondition, DataConditionGroup, DataSource, Detector
from sentry.workflow_engine.models.data_condition import Condition
from sentry.workflow_engine.registry import data_source_type_registry
Expand Down Expand Up @@ -49,6 +51,31 @@ def test_simple(self):
)
assert response.data == serialize([detector, detector_2])

def test_uptime_detector(self):
subscription = self.create_uptime_subscription()
data_source = self.create_data_source(
organization_id=self.organization.id,
source_id=subscription.id,
type=DATA_SOURCE_UPTIME_SUBSCRIPTION,
)
detector = self.create_detector(
project_id=self.project.id,
name="Test Detector",
type=UptimeDomainCheckFailure.slug,
config={
"mode": 1,
"environment": "production",
},
)
self.create_data_source_detector(
data_source=data_source,
detector=detector,
)
response = self.get_success_response(
self.organization.slug, qs_params={"project": self.project.id}
)
assert response.data[0]["dataSources"][0]["queryObj"] == serialize(subscription)

def test_empty_result(self):
response = self.get_success_response(
self.organization.slug, qs_params={"project": self.project.id}
Expand Down
Loading