Skip to content

Commit

Permalink
feat(backend): 监控主策略变更时,需要把子策略都刷新一遍 TencentBlueKing#8935
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 authored and iSecloud committed Jan 7, 2025
1 parent e6499af commit 1a41eda
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions dbm-ui/backend/db_monitor/models/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,7 @@ def patch_bk_biz_id(details):
details["bk_biz_id"] = env.DBA_APP_BK_BIZ_ID
return details

@staticmethod
def patch_target_and_metric_id(details, db_type):
def patch_target_and_metric_id(self, details, db_type):
"""监控目标/自定义事件和指标需要渲染
metric_id: {bk_biz_id}_bkmoinitor_event_{event_data_id}
"""
Expand Down Expand Up @@ -782,6 +781,11 @@ def patch_priority_and_agg_conditions(self, details):
}
)

# dbm 仅允许修改子策略的阈值,因此有修改时,需要先同步父亲的,再进行后续的 patch
if self.parent_id != 0:
parent_policy = MonitorPolicy.objects.get(id=self.parent_id)
details["items"] = copy.deepcopy(parent_policy.details["items"])

for item in details["items"]:
for query_config in item["query_configs"]:
if "agg_condition" in query_config:
Expand Down Expand Up @@ -875,6 +879,11 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields
if self.pk is None and self.bk_biz_id == env.DBA_APP_BK_BIZ_ID:
self.parent_details = self.details

# 父策略有变更时,把子策略也刷新一遍,以保证子策略的配置与父策略的指标、维度、周期一致,才能够使优先级计算生效
if self.parent_id == 0:
for sub_policy in MonitorPolicy.objects.filter(parent_id=self.id):
sub_policy.save()

# step3. save to db
super().save(force_insert, force_update, using, update_fields)

Expand Down

0 comments on commit 1a41eda

Please sign in to comment.