From 1fe72b46698ba6a5432a822bea4e689474b143ae Mon Sep 17 00:00:00 2001 From: Innokentii Konstantinov Date: Wed, 18 Dec 2024 11:53:30 +0800 Subject: [PATCH] nit fixes --- .../alerts/models/alert_receive_channel.py | 18 ++++++++---------- .../api/serializers/alert_receive_channel.py | 3 +-- engine/apps/labels/alert_group_labels.py | 2 +- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/engine/apps/alerts/models/alert_receive_channel.py b/engine/apps/alerts/models/alert_receive_channel.py index dc8897d8f..74fc5d237 100644 --- a/engine/apps/alerts/models/alert_receive_channel.py +++ b/engine/apps/alerts/models/alert_receive_channel.py @@ -301,23 +301,21 @@ class AlertReceiveChannel(IntegrationOptionsMixin, MaintainableObject): rate_limited_in_slack_at = models.DateTimeField(null=True, default=None) rate_limit_message_task_id = models.CharField(max_length=100, null=True, default=None) - """ - alert_group_labels_custom stores config of dynamic labels - mapping of incoming alert payload to labels - DynamicLabelsEntryDB is a a one entry of a one labels schema. It's a tuple with 3 elements: - 1. Key ID - 2. Value ID or None - Deprecated, but left for backward compatibility with old data. Should be None all the time. - 3. Value Template or None – By business logic it should be always present, but it might be None if a legacy data. - It means only [key_id, None, template] should be present. - // TODO: refactor to use just regular DB fields for dynamic label config. - """ DynamicLabelsEntryDB = tuple[str, str | None, str | None] DynamicLabelsConfigDB = list[DynamicLabelsEntryDB] | None alert_group_labels_custom: DynamicLabelsConfigDB = models.JSONField(null=True, default=None) """ + alert_group_labels_custom stores config of dynamic labels. It's stored as a list of tuples. + Format of tuple is: [, None, ]. + The second element is deprecated, so it's always None. It was used for static labels. + // TODO: refactor to use just regular DB fields for dynamic label config. + """ + + alert_group_labels_template: str | None = models.TextField(null=True, default=None) + """ alert_group_labels_template is a Jinja2 template for "multi-label extraction template". It extracts multiple labels from incoming alert payload. """ - alert_group_labels_template: str | None = models.TextField(null=True, default=None) additional_settings: dict | None = models.JSONField(null=True, default=None) diff --git a/engine/apps/api/serializers/alert_receive_channel.py b/engine/apps/api/serializers/alert_receive_channel.py index 88be863d6..41c0e979e 100644 --- a/engine/apps/api/serializers/alert_receive_channel.py +++ b/engine/apps/api/serializers/alert_receive_channel.py @@ -33,8 +33,7 @@ def _additional_settings_serializer_from_type(integration_type: str) -> serializ return cls -# TODO: refactor this types. -# We no longer support two types of label values here, nut only templates, so it should be simplified. +# TODO: refactor this types as w no longer support storing static labels in this field. # AlertGroupCustomLabelValue represents custom alert group label value for API requests # It handles two types of label's value: # 1. Just Label Value from a label repo for a static label diff --git a/engine/apps/labels/alert_group_labels.py b/engine/apps/labels/alert_group_labels.py index afa186067..d43ce2082 100644 --- a/engine/apps/labels/alert_group_labels.py +++ b/engine/apps/labels/alert_group_labels.py @@ -106,7 +106,7 @@ def _apply_dynamic_labels( def _apply_dynamic_label_entry( - label: "AlertReceiveChannel.DynamicLabelsEntryDB", keys, values, payload + label: "AlertReceiveChannel.DynamicLabelsEntryDB", keys: dict, payload: "Alert.RawRequestData" ) -> typing.Optional[tuple[str, str]]: key_id, value_id, template = label key, value = "", ""