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
9 changes: 6 additions & 3 deletions src/sentry/notifications/platform/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

from sentry.integrations.types import EventLifecycleOutcome
from sentry.integrations.utils.metrics import EventLifecycleMetric
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import NotificationCategory, NotificationProviderKey
from sentry.notifications.platform.types import (
NotificationCategory,
NotificationProviderKey,
NotificationSource,
)


class NotificationInteractionType(StrEnum):
Expand All @@ -19,7 +22,7 @@ class NotificationInteractionType(StrEnum):
class NotificationEventLifecycleMetric(EventLifecycleMetric):
interaction_type: NotificationInteractionType
# The template/source of the notification
notification_source: NotificationTemplateSource
notification_source: NotificationSource
# The sender of the notification
notification_provider: NotificationProviderKey | None = None
# The category of the notification
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/notifications/platform/rollout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from sentry import features, options
from sentry.models.organization import Organization
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import NotificationSource
from sentry.organizations.services.organization.model import RpcOrganization

logger = logging.getLogger(__name__)
Expand All @@ -20,7 +20,7 @@ class NotificationRolloutService:

organization: RpcOrganization | Organization

def should_notify(self, source: NotificationTemplateSource) -> bool:
def should_notify(self, source: NotificationSource) -> bool:
option_key = self.has_feature_flag_access()
if option_key is None:
return False
Expand Down Expand Up @@ -52,7 +52,7 @@ def has_feature_flag_access(self) -> str | None:

return option_key

def get_rollout_rate(self, option_key: str, source: NotificationTemplateSource) -> float:
def get_rollout_rate(self, option_key: str, source: NotificationSource) -> float:
try:
rollout_rates = options.get(option_key)
except options.UnknownOption:
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/notifications/platform/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from sentry.notifications.platform.registry import provider_registry, template_registry
from sentry.notifications.platform.rollout import NotificationRolloutService
from sentry.notifications.platform.target import NotificationTargetDto
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
NotificationData,
NotificationProviderKey,
NotificationSource,
NotificationStrategy,
NotificationTarget,
NotificationTemplate,
Expand All @@ -44,7 +44,7 @@ def __init__(self, *, data: T):

@staticmethod
def has_access(
organization: Organization | RpcOrganization, source: NotificationTemplateSource
organization: Organization | RpcOrganization, source: NotificationSource
) -> bool:
return NotificationRolloutService(organization=organization).should_notify(source=source)

Expand Down
4 changes: 2 additions & 2 deletions src/sentry/notifications/platform/templates/custom_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from datetime import datetime

from sentry.notifications.platform.registry import template_registry
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
CodeBlock,
NotificationCategory,
NotificationData,
NotificationRenderedAction,
NotificationRenderedTemplate,
NotificationSource,
NotificationTemplate,
ParagraphBlock,
PlainTextBlock,
Expand All @@ -21,7 +21,7 @@ def format_datetime(dt: datetime) -> str:

@dataclass(frozen=True)
class CustomRuleSamplesFulfilled(NotificationData):
source = NotificationTemplateSource.CUSTOM_RULE_SAMPLES_FULFILLED
source = NotificationSource.CUSTOM_RULE_SAMPLES_FULFILLED
query: str | None
num_samples: int
start_date: datetime
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/notifications/platform/templates/data_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from django.utils import timezone

from sentry.notifications.platform.registry import template_registry
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
CodeBlock,
CodeTextBlock,
NotificationCategory,
NotificationData,
NotificationRenderedAction,
NotificationRenderedTemplate,
NotificationSource,
NotificationTemplate,
ParagraphBlock,
PlainTextBlock,
Expand All @@ -26,7 +26,7 @@ def format_date(date: datetime) -> str:

@dataclass(frozen=True)
class DataExportSuccess(NotificationData):
source = NotificationTemplateSource.DATA_EXPORT_SUCCESS
source = NotificationSource.DATA_EXPORT_SUCCESS
export_url: str
expiration_date: datetime

Expand Down Expand Up @@ -58,7 +58,7 @@ def render(self, data: DataExportSuccess) -> NotificationRenderedTemplate:

@dataclass(frozen=True)
class DataExportFailure(NotificationData):
source = NotificationTemplateSource.DATA_EXPORT_FAILURE
source = NotificationSource.DATA_EXPORT_FAILURE
error_message: str
error_payload: dict[str, Any]
creation_date: datetime
Expand Down
4 changes: 2 additions & 2 deletions src/sentry/notifications/platform/templates/repository.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from dataclasses import dataclass

from sentry.notifications.platform.registry import template_registry
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
CodeTextBlock,
NotificationCategory,
NotificationData,
NotificationRenderedTemplate,
NotificationSource,
NotificationTemplate,
ParagraphBlock,
PlainTextBlock,
Expand All @@ -15,7 +15,7 @@

@dataclass(frozen=True)
class UnableToDeleteRepository(NotificationData):
source = NotificationTemplateSource.UNABLE_TO_DELETE_REPOSITORY
source = NotificationSource.UNABLE_TO_DELETE_REPOSITORY
repository_name: str
provider_name: str
error_message: str
Expand Down
12 changes: 6 additions & 6 deletions src/sentry/notifications/platform/templates/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dataclasses import dataclass

from sentry.notifications.platform.registry import template_registry
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
BoldTextBlock,
CodeBlock,
Expand All @@ -15,6 +14,7 @@
NotificationRenderedAction,
NotificationRenderedImage,
NotificationRenderedTemplate,
NotificationSource,
NotificationTemplate,
ParagraphBlock,
PlainTextBlock,
Expand All @@ -23,7 +23,7 @@

@dataclass(frozen=True)
class ErrorAlertData(NotificationData):
source = NotificationTemplateSource.ERROR_ALERT
source = NotificationSource.ERROR_ALERT
error_type: str
error_message: str
project_name: str
Expand Down Expand Up @@ -117,7 +117,7 @@ def render(self, data: ErrorAlertData) -> NotificationRenderedTemplate:

@dataclass(frozen=True)
class DeploymentData(NotificationData):
source = NotificationTemplateSource.DEPLOYMENT
source = NotificationSource.DEPLOYMENT
project_name: str
version: str
environment: str
Expand Down Expand Up @@ -187,7 +187,7 @@ def render(self, data: DeploymentData) -> NotificationRenderedTemplate:

@dataclass(frozen=True)
class SlowLoadMetricAlertData(NotificationData):
source = NotificationTemplateSource.SLOW_LOAD_METRIC_ALERT
source = NotificationSource.SLOW_LOAD_METRIC_ALERT
alert_type: str
severity: str
project_name: str
Expand Down Expand Up @@ -246,7 +246,7 @@ def render(self, data: SlowLoadMetricAlertData) -> NotificationRenderedTemplate:

@dataclass(frozen=True)
class PerformanceAlertData(NotificationData):
source = NotificationTemplateSource.PERFORMANCE_MONITORING
source = NotificationSource.PERFORMANCE_MONITORING
metric_name: str
threshold: str
current_value: str
Expand Down Expand Up @@ -313,7 +313,7 @@ def render(self, data: PerformanceAlertData) -> NotificationRenderedTemplate:

@dataclass(frozen=True)
class TeamUpdateData(NotificationData):
source = NotificationTemplateSource.TEAM_COMMUNICATION
source = NotificationSource.TEAM_COMMUNICATION
team_name: str
update_type: str
message: str
Expand Down
12 changes: 6 additions & 6 deletions src/sentry/notifications/platform/templates/seer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from sentry.constants import ENABLE_SEER_CODING_DEFAULT
from sentry.notifications.platform.registry import template_registry
from sentry.notifications.platform.templates.types import NotificationTemplateSource
from sentry.notifications.platform.types import (
NotificationCategory,
NotificationData,
NotificationRenderedTemplate,
NotificationSource,
NotificationTemplate,
ParagraphBlock,
PlainTextBlock,
Expand All @@ -33,15 +33,15 @@ def _get_next_stopping_point(current: AutofixStoppingPoint) -> AutofixStoppingPo
@dataclass(frozen=True)
class SeerAutofixError(NotificationData):
error_message: str
source: NotificationTemplateSource = NotificationTemplateSource.SEER_AUTOFIX_ERROR
source: NotificationSource = NotificationSource.SEER_AUTOFIX_ERROR
error_title: str = "Seer had some trouble..."


@template_registry.register(SeerAutofixError.source)
class SeerAutofixErrorTemplate(NotificationTemplate[SeerAutofixError]):
category = NotificationCategory.SEER
example_data = SeerAutofixError(
source=NotificationTemplateSource.SEER_AUTOFIX_ERROR,
source=NotificationSource.SEER_AUTOFIX_ERROR,
error_message="(401): Could not connect to your GitHub repository for this project.",
)

Expand Down Expand Up @@ -77,7 +77,7 @@ class SeerAutofixUpdate(NotificationData):
pull_requests: list[SeerAutofixPullRequest] = field(default_factory=list)
summary: str | None = None
has_progressed: bool = False
source: NotificationTemplateSource = NotificationTemplateSource.SEER_AUTOFIX_UPDATE
source: NotificationSource = NotificationSource.SEER_AUTOFIX_UPDATE

@property
def next_point(self) -> AutofixStoppingPoint | None:
Expand All @@ -104,7 +104,7 @@ def has_next_trigger(self) -> bool:
class SeerAutofixUpdateTemplate(NotificationTemplate[SeerAutofixUpdate]):
category = NotificationCategory.SEER
example_data = SeerAutofixUpdate(
source=NotificationTemplateSource.SEER_AUTOFIX_UPDATE,
source=NotificationSource.SEER_AUTOFIX_UPDATE,
run_id=12152025,
project_id=123,
group_id=456,
Expand Down Expand Up @@ -151,7 +151,7 @@ class SeerAutofixTrigger(NotificationData):
project_id: int
group_id: int
run_id: int | None = None
source: NotificationTemplateSource = NotificationTemplateSource.SEER_AUTOFIX_TRIGGER
source: NotificationSource = NotificationSource.SEER_AUTOFIX_TRIGGER
stopping_point: AutofixStoppingPoint = AutofixStoppingPoint.ROOT_CAUSE

@staticmethod
Expand Down
18 changes: 0 additions & 18 deletions src/sentry/notifications/platform/templates/types.py

This file was deleted.

66 changes: 48 additions & 18 deletions src/sentry/notifications/platform/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Any, Literal, Protocol, Self

from sentry.integrations.types import ExternalProviderEnum
from sentry.notifications.platform.templates.types import NotificationTemplateSource


class NotificationCategory(StrEnum):
Expand All @@ -23,34 +22,65 @@ class NotificationCategory(StrEnum):
REPOSITORY = "repository"
SEER = "seer"

def get_sources(self) -> list[str]:
def get_sources(self) -> list[NotificationSource]:
return NOTIFICATION_SOURCE_MAP[self]


NOTIFICATION_SOURCE_MAP = {
class NotificationSource(StrEnum):
"""
A name for a notification being sent. Each notification sent should have a unique source.
"""

# DEBUG
TEST = "test"
ERROR_ALERT = "error-alert-service"
DEPLOYMENT = "deployment-service"
SLOW_LOAD_METRIC_ALERT = "slow-load-metric-alert"
PERFORMANCE_MONITORING = "performance-monitoring"
TEAM_COMMUNICATION = "team-communication"

# DATA_EXPORT
DATA_EXPORT_SUCCESS = "data-export-success"
DATA_EXPORT_FAILURE = "data-export-failure"

# DYNAMIC_SAMPLING
CUSTOM_RULE_SAMPLES_FULFILLED = "custom-rule-samples-fulfilled"

# REPOSITORY
UNABLE_TO_DELETE_REPOSITORY = "unable-to-delete-repository"

# SEER
SEER_AUTOFIX_ERROR = "seer-autofix-error"
SEER_AUTOFIX_UPDATE = "seer-autofix-update"
SEER_AUTOFIX_TRIGGER = "seer-autofix-trigger"
SEER_AUTOFIX_FOOTER = "seer-autofix-footer"
SEER_AUTOFIX_SUCCESS = "seer-autofix-success"


NOTIFICATION_SOURCE_MAP: dict[NotificationCategory, list[NotificationSource]] = {
NotificationCategory.DEBUG: [
"test",
"error-alert-service",
"deployment-service",
"slow-load-metric-alert",
"performance-monitoring",
"team-communication",
NotificationSource.TEST,
NotificationSource.ERROR_ALERT,
NotificationSource.DEPLOYMENT,
NotificationSource.SLOW_LOAD_METRIC_ALERT,
NotificationSource.PERFORMANCE_MONITORING,
NotificationSource.TEAM_COMMUNICATION,
],
NotificationCategory.DATA_EXPORT: [
"data-export-success",
"data-export-failure",
NotificationSource.DATA_EXPORT_SUCCESS,
NotificationSource.DATA_EXPORT_FAILURE,
],
NotificationCategory.DYNAMIC_SAMPLING: [
"custom-rule-samples-fulfilled",
NotificationSource.CUSTOM_RULE_SAMPLES_FULFILLED,
],
NotificationCategory.REPOSITORY: [
"unable-to-delete-repository",
NotificationSource.UNABLE_TO_DELETE_REPOSITORY,
],
NotificationCategory.SEER: [
"seer-autofix-trigger",
"seer-autofix-error",
"seer-autofix-success",
"seer-autofix-update",
NotificationSource.SEER_AUTOFIX_TRIGGER,
NotificationSource.SEER_AUTOFIX_ERROR,
NotificationSource.SEER_AUTOFIX_SUCCESS,
NotificationSource.SEER_AUTOFIX_UPDATE,
],
}

Expand Down Expand Up @@ -106,7 +136,7 @@ class NotificationData(Protocol):
All data passing through the notification platform must adhere to this protocol.
"""

source: NotificationTemplateSource
source: NotificationSource
"""
The source is uniquely attributable to the way this notification was sent. It will be tracked in
metrics/analytics to determine the egress from a given code-path or service.
Expand Down
Loading
Loading