Skip to content

Commit

Permalink
fix(backend): 修复send msg超频的问题 #5840
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Jul 29, 2024
1 parent 32065fd commit 4f06d3f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions dbm-ui/backend/components/cmsi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MsgType(str, StructuredEnum):
VOICE = EnumField("voice", _("语音"))
RTX = EnumField("rtx", _("企业微信"))
WECOM_ROBOT = EnumField("wecom_robot", _("企业微信机器人"))
# 未知发送类型,配置此type一般用于跳过消息发送
UNKNOWN = EnumField("unknown", _("未知"))

def __init__(self):
self.send_msg = self.generate_data_api(
Expand Down
4 changes: 4 additions & 0 deletions dbm-ui/backend/db_services/dbbase/resources/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,10 @@ def _list_machines(
Q(storageinstance__instance_role=query_params.get("instance_role"))
| Q(proxyinstance__access_layer=query_params.get("instance_role"))
),
"instance_status": (
Q(storageinstance__status=query_params.get("instance_status"))
| Q(proxyinstance__status=query_params.get("instance_status"))
),
"cluster_ids": (
Q(storageinstance__cluster__in=query_params.get("cluster_ids", "").split(","))
| Q(proxyinstance__cluster__in=query_params.get("cluster_ids", "").split(","))
Expand Down
5 changes: 4 additions & 1 deletion dbm-ui/backend/db_services/dbbase/resources/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.translation import gettext_lazy as _
from rest_framework import serializers

from backend.db_meta.enums import ClusterStatus, ClusterType, MachineType
from backend.db_meta.enums import ClusterStatus, ClusterType, InstanceStatus, MachineType
from backend.db_meta.models.cluster import Cluster
from backend.db_services.dbbase.constants import IP_PORT_DIVIDER

Expand Down Expand Up @@ -132,6 +132,9 @@ class ListMachineSLZ(serializers.Serializer):
bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID"), required=False)
bk_agent_id = serializers.CharField(help_text=_("agent id"), required=False)
instance_role = serializers.CharField(help_text=_("机器部署的实例角色"), required=False)
instance_status = serializers.ChoiceField(
help_text=_("集群状态"), choices=InstanceStatus.get_choices(), required=False
)
creator = serializers.CharField(help_text=_("创建者"), required=False)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.utils.translation import ugettext_lazy as _

from backend import env
from backend.components import CmsiApi
from backend.components.gcs.client import GcsApi, GcsDirectApi
from backend.components.mysql_priv_manager.client import DBPrivManagerApi
from backend.components.scr.client import ScrApi
Expand Down Expand Up @@ -199,6 +200,8 @@ def parse_domain(raw_domain):
creator=operator or self.operator,
remark=_("第三方请求授权"),
details=authorize_info_slz.validated_data,
# 自动授权单,不发送通知
send_msg_config={"msg_type": [CmsiApi.MsgType.UNKNOWN.value]},
)
task_id = str(ticket.id)
return {"task_id": task_id, "platform": "dbm", "job_id": task_id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ def get_remote_infos(insts: List[StorageInstance]):
machine_pair_cnt = len(machine_list) / 2
# 获取集群规格
spec_id = cluster.storages[0].machine.spec_id
cluster_spec = kwargs["remote_spec_map"].get(spec_id)
spec = kwargs["remote_spec_map"].get(spec_id)

cluster_extra_info = {
"cluster_spec": model_to_dict(cluster_spec),
"cluster_capacity": cluster_spec.capacity * machine_pair_cnt,
"cluster_spec": model_to_dict(spec) if spec else {},
"cluster_capacity": spec.capacity * machine_pair_cnt if spec else 0,
"spider_master": spider[TenDBClusterSpiderRole.SPIDER_MASTER],
"spider_slave": spider[TenDBClusterSpiderRole.SPIDER_SLAVE],
"spider_mnt": spider[TenDBClusterSpiderRole.SPIDER_MNT],
# TODO: 待补充当前集群使用容量,需要监控采集的支持
"cluster_shard_num": len(remote_db),
"remote_shard_num": len(remote_db) / machine_pair_cnt,
"machine_pair_cnt": machine_pair_cnt,
Expand Down
6 changes: 4 additions & 2 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,10 @@ class MySQLBackupTypeEnum(str, StructuredEnum):


class MySQLBackupFileTagEnum(str, StructuredEnum):
MYSQL_FULL_BACKUP = EnumField("MYSQL_FULL_BACKUP", _("全备-保留25天"))
LONGDAY_DBFILE_3Y = EnumField("LONGDAY_DBFILE_3Y", _("长久存储-保留三年"))
DBFILE1M = EnumField("DBFILE1M", _("备份1个月"))
DBFILE6M = EnumField("DBFILE6M", _("备份6个月"))
DBFILE1Y = EnumField("DBFILE1Y", _("备份1年"))
DBFILE3Y = EnumField("DBFILE3Y", _("备份3年"))


class MongoDBBackupFileTagEnum(str, StructuredEnum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,4 @@ def __get_sql_file_name_list(self) -> list:
file_list = []
for obj in self.data["execute_objects"]:
file_list.append(obj["sql_file"])
return file_list
return list(set(file_list))
4 changes: 4 additions & 0 deletions dbm-ui/backend/ticket/models/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def create_ticket(
remark: str,
details: Dict[str, Any],
auto_execute: bool = True,
send_msg_config: dict = None,
) -> "Ticket":
"""
自动创建单据
Expand All @@ -175,11 +176,13 @@ def create_ticket(
:param remark: 备注
:param details: 单据参数details
:param auto_execute: 是否自动初始化执行单据
:param send_msg_config: 消息发送类配置
"""

from backend.ticket.builders import BuilderFactory

with transaction.atomic():
send_msg_config = send_msg_config or {}
ticket = Ticket.objects.create(
group=BuilderFactory.get_builder_cls(ticket_type).group,
creator=creator,
Expand All @@ -188,6 +191,7 @@ def create_ticket(
ticket_type=ticket_type,
remark=remark,
details=details,
send_msg_config=send_msg_config,
)
logger.info(_("正在自动创建单据,单据详情: {}").format(ticket.__dict__))
builder = BuilderFactory.create_builder(ticket)
Expand Down

0 comments on commit 4f06d3f

Please sign in to comment.