From 143aa6e5e09a0828d46e20a4c9df2580f8c4d1cc Mon Sep 17 00:00:00 2001 From: gaohongsong Date: Wed, 1 Nov 2023 15:35:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(backend):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89key=E8=BF=87=E6=BB=A4=E7=AD=96=E7=95=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=20close=20#1614?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../management/commands/extract_alarm.py | 10 +++++++++- ...6\350\277\237\345\221\212\350\255\246.json" | 18 ------------------ 2 files changed, 9 insertions(+), 19 deletions(-) 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/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..e9cc06be04 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": [ From 0beba59e4a6c023c8fde1904ad6e2c2c2d206ce4 Mon Sep 17 00:00:00 2001 From: gaohongsong Date: Wed, 1 Nov 2023 15:35:45 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(backend):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89key=E8=BF=87=E6=BB=A4=E7=AD=96=E7=95=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=20close=20#1614?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ulsar \345\273\266\350\277\237\345\221\212\350\255\246.json" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e9cc06be04..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" @@ -264,7 +264,7 @@ }, "is_enabled": false, "monitor_indicator": "SUM(pulsar_msg_backlog)", - "version": 0, + "version": 1, "alert_source": "time_series", "custom_conditions": [ { From fb9747cb7a1798076d63ce6b4ab1d4de34e826a6 Mon Sep 17 00:00:00 2001 From: gaohongsong Date: Wed, 1 Nov 2023 15:55:31 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(backend):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89key=E8=BF=87=E6=BB=A4=E7=AD=96=E7=95=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=20close=20#1614?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_monitor/serializers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dbm-ui/backend/db_monitor/serializers.py b/dbm-ui/backend/db_monitor/serializers.py index 43023eb6ef..6c28705a6b 100644 --- a/dbm-ui/backend/db_monitor/serializers.py +++ b/dbm-ui/backend/db_monitor/serializers.py @@ -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): From 1a7ba9015d4a89b288eb9f17a0eb7f00cd5daa34 Mon Sep 17 00:00:00 2001 From: gaohongsong Date: Wed, 1 Nov 2023 16:10:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(backend):=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89key=E8=BF=87=E6=BB=A4=E7=AD=96=E7=95=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=20close=20#1614?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbm-ui/backend/db_monitor/models/alarm.py | 2 +- dbm-ui/backend/db_monitor/serializers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 6c28705a6b..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): """补充校验