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): 监控兼容非轮值告警组 #1646 #1647

Merged
merged 1 commit into from
Nov 2, 2023
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
8 changes: 4 additions & 4 deletions dbm-ui/backend/db_meta/enums/instance_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

class InstancePhase(str, StructuredEnum):
# instance实际可能存在的phase状态
ONLINE = EnumField("online", _("online"))
OFFLINE = EnumField("offline", _("offline"))
ONLINE = EnumField("online", _("正常"))
OFFLINE = EnumField("offline", _("下架"))

# 仅用作单据校验,不实际写入,销毁集群时,请直接删除Instance
DESTROY = EnumField("destroy", _("destroy"))
DESTROY = EnumField("destroy", _("销毁"))

TRANS_STAGE = EnumField("trans_stage", _("trans_stage"))
TRANS_STAGE = EnumField("trans_stage", _(" scr/gcs迁移中"))

@classmethod
def instance_status_transfer_valid(cls, source_phase, target_phase) -> bool:
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/db_meta/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ClusterStatus,
ClusterType,
InstanceInnerRole,
InstancePhase,
InstanceRole,
MachineType,
)
Expand Down Expand Up @@ -365,7 +366,7 @@ class Migration(migrations.Migration):
(
"phase",
models.CharField(
choices=ClusterPhase.get_choices(),
choices=InstancePhase.get_choices(),
default="online",
max_length=64,
),
Expand Down
9 changes: 3 additions & 6 deletions dbm-ui/backend/db_meta/migrations/0021_proxyinstance_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django.db import migrations, models

from backend.db_meta.enums import InstancePhase


class Migration(migrations.Migration):

Expand All @@ -14,12 +16,7 @@ class Migration(migrations.Migration):
model_name="proxyinstance",
name="phase",
field=models.CharField(
choices=[
("online", "online"),
("offline", "offline"),
("destroy", "destroy"),
("trans_stage", "trans_stage"),
],
choices=InstancePhase.get_choices(),
default="online",
max_length=64,
),
Expand Down
23 changes: 23 additions & 0 deletions dbm-ui/backend/db_monitor/migrations/0017_auto_20231102_2100.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.19 on 2023-11-02 13:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("db_monitor", "0016_monitorpolicy_custom_conditions"),
]

operations = [
migrations.AlterField(
model_name="dutyrule",
name="name",
field=models.CharField(max_length=128, verbose_name="轮值规则名称"),
),
migrations.AlterField(
model_name="noticegroup",
name="name",
field=models.CharField(default="", max_length=128, verbose_name="告警通知组名称"),
),
]
24 changes: 13 additions & 11 deletions dbm-ui/backend/db_monitor/models/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class NoticeGroup(AuditedModel):
"""告警通知组:一期粒度仅支持到业务级,可开关是否同步DBA人员数据"""

bk_biz_id = models.IntegerField(help_text=_("业务ID, 0代表全业务"), default=PLAT_BIZ_ID)
name = models.CharField(_("告警通知组名称"), max_length=LEN_LONG, default="")
name = models.CharField(_("告警通知组名称"), max_length=LEN_MIDDLE, default="")
monitor_group_id = models.BigIntegerField(help_text=_("监控通知组ID"), default=0)
monitor_duty_rule_id = models.IntegerField(verbose_name=_("监控轮值规则 ID"), default=0)
db_type = models.CharField(_("数据库类型"), choices=DBType.get_choices(), max_length=LEN_SHORT, default="")
Expand Down Expand Up @@ -128,15 +128,17 @@ def save_monitor_group(self) -> int:
self.monitor_duty_rule_id = resp["id"]
except ApiError as err:
logger.error(f"request monitor api error: {err}")
# 把相同 db_type 的轮值应用到此告警组中
monitor_duty_rule_ids = (
DutyRule.objects.filter(db_type=self.db_type)
.exclude(monitor_duty_rule_id=0)
.order_by("-priority")
.values_list("monitor_duty_rule_id", flat=True)
)
save_monitor_group_params["need_duty"] = True
save_monitor_group_params["duty_rules"] = list(monitor_duty_rule_ids)
save_monitor_group_params["duty_arranges"][0]["users"] = self.receivers
else:
# 轮值生效,把相同 db_type 的轮值应用到此告警组中
monitor_duty_rule_ids = (
DutyRule.objects.filter(db_type=self.db_type)
.exclude(monitor_duty_rule_id=0)
.order_by("-priority")
.values_list("monitor_duty_rule_id", flat=True)
)
save_monitor_group_params["need_duty"] = True
save_monitor_group_params["duty_rules"] = list(monitor_duty_rule_ids)
else:
save_monitor_group_params["duty_arranges"][0]["users"] = self.receivers

Expand Down Expand Up @@ -208,7 +210,7 @@ class DutyRule(AuditedModel):
]
"""

name = models.CharField(verbose_name=_("轮值规则名称"), max_length=LEN_LONG)
name = models.CharField(verbose_name=_("轮值规则名称"), max_length=LEN_MIDDLE)
monitor_duty_rule_id = models.IntegerField(verbose_name=_("监控轮值规则 ID"), default=0)
priority = models.PositiveIntegerField(verbose_name=_("优先级"))
is_enabled = models.BooleanField(verbose_name=_("是否启用"), default=True)
Expand Down
4 changes: 2 additions & 2 deletions helm-charts/bk-dbm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ dependencies:
description: A Helm chart for bkdbm
name: bk-dbm
type: application
version: 1.2.0-alpha.75
appVersion: 1.2.0-alpha.75
version: 1.2.0-alpha.76
appVersion: 1.2.0-alpha.76
2 changes: 1 addition & 1 deletion helm-charts/bk-dbm/charts/dbm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
appVersion: 1.2.0-alpha.440
appVersion: 1.2.0-alpha.443
description: A Helm chart for dbm
name: dbm
type: application
Expand Down
Loading