Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): 自定义key过滤策略问题修复 #1615

Merged
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
10 changes: 9 additions & 1 deletion dbm-ui/backend/db_monitor/management/commands/extract_alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_monitor/models/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 11 additions & 2 deletions dbm-ui/backend/db_monitor/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""补充校验
Expand All @@ -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):
Expand Down
20 changes: 1 addition & 19 deletions dbm-ui/backend/db_monitor/tpls/alarm/Pulsar 延迟告警.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -282,7 +264,7 @@
},
"is_enabled": false,
"monitor_indicator": "SUM(pulsar_msg_backlog)",
"version": 0,
"version": 1,
"alert_source": "time_series",
"custom_conditions": [
{
Expand Down
Loading