Skip to content

Commit 55349ca

Browse files
xiepaupiSecloud
authored andcommitted
feat(redis): redis整机替换单据值守 TencentBlueKing#16385
1 parent da0fdfe commit 55349ca

File tree

8 files changed

+76
-4
lines changed

8 files changed

+76
-4
lines changed

dbm-ui/backend/core/translation/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"backend/ticket/constants.py",
4848
# aidev 快捷指令中文
4949
"backend/dbm_aiagent/agent/commands/commands.py",
50+
"backend/dbm_aiagent/agent/commands/redis_commands.py",
5051
]
5152
ALL_EXCLUDE_DIRS = set(EXCLUDE_DIRS + EXCLUDE_FILE_PATHS)
5253

dbm-ui/backend/db_services/redis/autofix/message.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from backend.core.notify.handlers import CmsiHandler
2020
from backend.db_meta.enums import ClusterType
2121
from backend.db_meta.models import AppCache
22+
from backend.dbm_aiagent.agent.constants import DBMAgentCode
23+
from backend.dbm_aiagent.agent.handlers import AgentHandler
2224
from backend.utils.time import date2str
2325

2426
from .enums import AutofixItem
@@ -55,7 +57,12 @@ def send_msg_2_qywx(sub_title: str, msgs):
5557
content += _("业务DBA : {}(@{})\n".format(redis_DBA[0], redis_DBA[0]))
5658
else:
5759
content += _("{} : {}\n".format(k, v))
60+
if db_type == DBType.Redis.value:
61+
content = _("""查询这个{}集群最新的qps和CPU情况""".format("-".join(sub_title.split("-")[:-1])))
62+
rest = AgentHandler.ask_agent_with_content(DBMAgentCode.REDIS_TASK_GUARDIAN.value, "", redis_DBA)
63+
content += _("当前负载 : {}\n".format(rest))
5864
content += _("消息时间 : {}\n".format(date2str(datetime.datetime.now(), "%Y-%m-%d %H:%M:%S")))
65+
5966
CmsiHandler(_("Tendis自愈"), content, msg_ids).send_wecom_robot()
6067

6168

dbm-ui/backend/dbm_aiagent/agent/commands/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from aidev_agent.services.command_handler import CommandProcessor as BaseCommandProcessor
1515

1616
from .commands import *
17+
from .redis_commands import *
1718
from .register import command, register_command
1819

1920
CommandProcessor = BaseCommandProcessor()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from aidev_agent.services.command_handler import CommandHandler
12+
from django.utils.translation import gettext as _
13+
14+
from ..constants import DBMAgentCode
15+
from .register import command
16+
17+
18+
@command
19+
class CheckRedisClusterCommand(CommandHandler):
20+
name = _("查询单据运行期间这批Redis集群的是否存在风险性")
21+
command = "check_redis_cluster_operating_status"
22+
agent_code = DBMAgentCode.REDIS_TASK_GUARDIAN
23+
24+
def get_template(self) -> str:
25+
return """
26+
查询单据运行期间这批Redis集群的是否存在风险性:
27+
业务ID:{{ bk_biz_id }}
28+
集群主域名列表:{{ cluster_domains }}
29+
查询起始时间点:{{ start_time }}
30+
查询截止时间点:{{ end_time }}
31+
"""
32+
33+
34+
@command
35+
class GenRedisUpdReporterCommand(CommandHandler):
36+
name = _("生成Redis变更报告")
37+
command = "gen_redis_updater_report"
38+
agent_code = DBMAgentCode.REDIS_TASK_GUARDIAN
39+
40+
def get_init(self) -> str:
41+
return "查询{{ cluster_domain }}集群部署情况"
42+
43+
def get_report(self) -> str:
44+
return "再次查询{{ cluster_domain }}集群部署情况,并与上一次查询结果进行对比,生成变更报告"

dbm-ui/backend/dbm_aiagent/agent/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ class DBMAgentCode(StrStructuredEnum):
2424
MYSQL_TASK_GUARDIAN = EnumField("ai-mysql-taskgd", _("MySQL单据值守智能体"))
2525
SQLSERVER_TASK_GUARDIAN = EnumField("ai-sqlsvr-tgd", _("SQLServer单据值守智能体"))
2626
REDIS_MEMORY_ANALYSIS = EnumField("ai-redis-memchk", _("Redis内存增长分析智能体"))
27+
REDIS_HELPER = EnumField("ai-tendis-agent", _("Redis智能助手"))
28+
REDIS_TASK_GUARDIAN = EnumField("ai-redis-taskgd", _("Redis单据值守"))
29+
REDIS_LOG_ANA = EnumField("ai-redis-logana", _("Redis日志解析"))
30+
REDIS_TOOLS = EnumField("ai-redis-wb", _("Redis工具箱"))
31+
REDIS_METRICS = EnumField("ai-tendismetrics", _("Redis指标助手"))

dbm-ui/backend/dbm_aiagent/agent/handlers.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ def create_chat_completion(cls, session_code, session_content_id):
5555
return result
5656

5757
@classmethod
58-
def ask_agent_with_content(cls, agent_code: DBMAgentCode, content: str, username=DEFAULT_USERNAME):
58+
def ask_agent_with_content(
59+
cls, agent_code: DBMAgentCode, content: str, username=DEFAULT_USERNAME, session_code=None
60+
):
5961
"""根据agent直接内容询问agent"""
6062
# 创建临时会话
61-
session_code = cls.create_temporary_session(username)
63+
session_code = session_code or cls.create_temporary_session(username)
6264

6365
# 创建会话内容
6466
# 主智能体直接询问,子智能体走快捷指令切换询问
@@ -73,6 +75,15 @@ def ask_agent_with_content(cls, agent_code: DBMAgentCode, content: str, username
7375
ai_response = cls.create_chat_completion(session_code, session_content_id)
7476
return ai_response["choices"][0]["delta"]["content"]
7577

78+
@classmethod
79+
def ask_agent_with_content_in_session(
80+
cls, agent_code: DBMAgentCode, content: str, username=DEFAULT_USERNAME, session_code=None
81+
):
82+
"""根据agent直接内容询问agent, 连续对话"""
83+
session_code = session_code or cls.create_temporary_session(username)
84+
ai_response = cls.ask_agent_with_content(agent_code, content, username, session_code)
85+
return ai_response, session_code
86+
7687
@classmethod
7788
def ask_agent_with_command(cls, command: str, command_params: dict, username=DEFAULT_USERNAME):
7889
"""根据快捷指令询问agent"""

dbm-ui/backend/flow/engine/bamboo/scene/redis/redis_cluster_scene_cmr.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ def __init_builder(self, operate_name: str):
220220
# 这里整理替换所需要的参数
221221
def complete_machine_replace(self):
222222
redis_pipeline, act_kwargs = self.__init_builder(_("REDIS-整机替换"))
223-
sub_pipelines = []
223+
sub_pipelines, cluster_ids = [], []
224224
for cluster_replacement in self.data["infos"]:
225225
for cluster_id in cluster_replacement["cluster_ids"]:
226+
cluster_ids.append(int(cluster_id))
226227
cluster_kwargs = deepcopy(act_kwargs)
227228
cluster_info = self.get_cluster_info(self.data["bk_biz_id"], cluster_id)
228229
sync_type = SyncType.SYNC_MMS.value # ssd sync from master
@@ -244,7 +245,8 @@ def complete_machine_replace(self):
244245
sub_pipelines.append(sub_pipeline)
245246
if len(sub_pipelines) > 0:
246247
redis_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines)
247-
return redis_pipeline.run_pipeline()
248+
# return redis_pipeline.run_pipeline()
249+
return redis_pipeline.run_pipeline_with_sidecar(check_ai_monitor_cluster_list=cluster_ids)
248250

249251
# 组装&控制 集群替换流程
250252
def generate_cluster_replacement(self, flow_data, act_kwargs, replacement_param):

dbm-ui/backend/flow/plugins/components/collections/common/check_cluster_alarm_for_ai.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
DBType.MySQL: commands.CheckMysqlClusterCommand,
3232
DBType.TenDBCluster: commands.CheckMysqlClusterCommand,
3333
DBType.Sqlserver: commands.CheckSQLServerClusterCommand,
34+
DBType.Redis: commands.CheckRedisClusterCommand,
3435
}
3536

3637

0 commit comments

Comments
 (0)