Skip to content

Commit

Permalink
nit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinov-Innokentii committed Dec 18, 2024
1 parent 61a6040 commit 1fe72b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
18 changes: 8 additions & 10 deletions engine/apps/alerts/models/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: [<LABEL_KEY_ID>, None, <JINJA2_TEMPLATE>].
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)

Expand Down
3 changes: 1 addition & 2 deletions engine/apps/api/serializers/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engine/apps/labels/alert_group_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "", ""
Expand Down

0 comments on commit 1fe72b4

Please sign in to comment.