diff --git a/dbm-ui/backend/db_monitor/management/commands/extract_alarm.py b/dbm-ui/backend/db_monitor/management/commands/extract_alarm.py index 4343334b04..85b65b3934 100644 --- a/dbm-ui/backend/db_monitor/management/commands/extract_alarm.py +++ b/dbm-ui/backend/db_monitor/management/commands/extract_alarm.py @@ -19,7 +19,7 @@ from backend import env from backend.components import BKMonitorV3Api from backend.configuration.constants import DBType -from backend.db_monitor.constants import TPLS_ALARM_DIR, TargetPriority +from backend.db_monitor.constants import TPLS_ALARM_DIR, TargetLevel, TargetPriority from backend.db_monitor.models import RuleTemplate logger = logging.getLogger("root") @@ -184,6 +184,14 @@ def handle(self, *args, **options): filter(lambda x: x["key"] in custom_conditions, query_config.get("agg_condition", [])) ) + if "agg_condition" in query_config: + query_config["agg_condition"] = list( + filter( + lambda x: x["key"] not in ["app"] + TargetLevel.get_values(), + query_config["agg_condition"], + ) + ) + self.clear_id(strategy_template["items"]) with open(os.path.join(TPLS_ALARM_DIR, f"{template_name}.json"), "w") as template_file: diff --git a/dbm-ui/backend/db_monitor/models/alarm.py b/dbm-ui/backend/db_monitor/models/alarm.py index ccfd07f0a1..cd8285fcb5 100644 --- a/dbm-ui/backend/db_monitor/models/alarm.py +++ b/dbm-ui/backend/db_monitor/models/alarm.py @@ -880,7 +880,7 @@ def clone(cls, params, username="system") -> dict: def update(self, params, username="system") -> dict: """更新:patch -> update""" - update_fields = ["targets", "test_rules", "notify_rules", "notify_groups"] + update_fields = ["targets", "test_rules", "notify_rules", "notify_groups", "custom_conditions"] # param -> model for key in update_fields: diff --git a/dbm-ui/backend/db_monitor/serializers.py b/dbm-ui/backend/db_monitor/serializers.py index 43023eb6ef..6fedb7106e 100644 --- a/dbm-ui/backend/db_monitor/serializers.py +++ b/dbm-ui/backend/db_monitor/serializers.py @@ -161,7 +161,6 @@ class TestRuleConfigSerializer(serializers.Serializer): child=serializers.ChoiceField(choices=NoticeSignalEnum.get_choices()), allow_empty=False ) notify_groups = serializers.ListField(child=serializers.IntegerField(), allow_empty=True) - custom_conditions = serializers.ListSerializer(child=serializers.JSONField(), allow_empty=True) class Meta: model = MonitorPolicy @@ -170,6 +169,7 @@ class Meta: class MonitorPolicyCloneSerializer(MonitorPolicyUpdateSerializer): bk_biz_id = serializers.IntegerField(help_text=_("业务ID"), min_value=1) + custom_conditions = serializers.ListSerializer(child=serializers.JSONField(), allow_empty=True) def validate(self, attrs): """补充校验 @@ -187,7 +187,16 @@ def validate(self, attrs): class Meta: model = MonitorPolicy - fields = ["name", "bk_biz_id", "parent_id", "targets", "test_rules", "notify_rules", "notify_groups"] + fields = [ + "name", + "bk_biz_id", + "parent_id", + "targets", + "test_rules", + "notify_rules", + "notify_groups", + "custom_conditions", + ] class MonitorPolicyEmptySerializer(serializers.Serializer): diff --git "a/dbm-ui/backend/db_monitor/tpls/alarm/Pulsar \345\273\266\350\277\237\345\221\212\350\255\246.json" "b/dbm-ui/backend/db_monitor/tpls/alarm/Pulsar \345\273\266\350\277\237\345\221\212\350\255\246.json" index 378a951019..02f6a98763 100644 --- "a/dbm-ui/backend/db_monitor/tpls/alarm/Pulsar \345\273\266\350\277\237\345\221\212\350\255\246.json" +++ "b/dbm-ui/backend/db_monitor/tpls/alarm/Pulsar \345\273\266\350\277\237\345\221\212\350\255\246.json" @@ -41,24 +41,6 @@ "bk_target_service_instance_id" ], "agg_condition": [ - { - "key": "app", - "value": [ - "dba" - ], - "method": "eq", - "condition": "and", - "dimension_name": "app" - }, - { - "key": "cluster_domain", - "value": [ - "pulsar.shenzhen.dba.db" - ], - "method": "eq", - "condition": "and", - "dimension_name": "cluster_domain" - }, { "key": "namespace", "value": [ @@ -282,7 +264,7 @@ }, "is_enabled": false, "monitor_indicator": "SUM(pulsar_msg_backlog)", - "version": 0, + "version": 1, "alert_source": "time_series", "custom_conditions": [ {