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

将阿里云RDS的功能抽到单独engine #2087

Merged
merged 8 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 2 additions & 21 deletions sql/db_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
from sql.engines import get_engine
from common.utils.extend_json_encoder import ExtendJSONEncoder, ExtendJSONEncoderBytes
from sql.utils.resource_group import user_instances
from .models import AliyunRdsConfig, Instance
from .models import Instance

# from .aliyun_rds import process_status as aliyun_process_status, create_kill_session as aliyun_create_kill_session, \
# kill_session as aliyun_kill_session, sapce_status as aliyun_sapce_status

logger = logging.getLogger("default")

Expand All @@ -34,10 +32,6 @@ def process(request):
query_engine = get_engine(instance=instance)
query_result = None
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
# if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
# result = aliyun_process_status(request)
# else:
query_result = query_engine.processlist(command_type)

elif instance.db_type == "mongo":
Expand Down Expand Up @@ -81,10 +75,6 @@ def create_kill_session(request):
result = {"status": 0, "msg": "ok", "data": []}
query_engine = get_engine(instance=instance)
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
# if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
# result = aliyun_create_kill_session(request)
# else:
result["data"] = query_engine.get_kill_command(json.loads(thread_ids))
elif instance.db_type == "mongo":
kill_command = query_engine.get_kill_command(json.loads(thread_ids))
Expand All @@ -110,7 +100,6 @@ def create_kill_session(request):
def kill_session(request):
instance_name = request.POST.get("instance_name")
thread_ids = request.POST.get("ThreadIDs")
request_params = request.POST.get("request_params", "{}")
result = {"status": 0, "msg": "ok", "data": []}

try:
Expand All @@ -122,11 +111,7 @@ def kill_session(request):
engine = get_engine(instance=instance)
r = None
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
# if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
# result = aliyun_kill_session(request)
# else:
r = engine.kill(json.loads(thread_ids), request_params=request_params)
r = engine.kill(json.loads(thread_ids))
elif instance.db_type == "mongo":
r = engine.kill_op(json.loads(thread_ids))
elif instance.db_type == "oracle":
Expand Down Expand Up @@ -162,10 +147,6 @@ def tablespace(request):

query_engine = get_engine(instance=instance)
if instance.db_type == "mysql":
# 判断是RDS还是其他实例
# if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
# result = aliyun_sapce_status(request)
# else:
query_result = query_engine.tablespace(offset, limit)
elif instance.db_type == "oracle":
query_result = query_engine.tablespace(offset, limit)
Expand Down
6 changes: 2 additions & 4 deletions sql/engines/cloud/aliyun_rds.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def get_kill_command(self, thread_ids):

return kill_sql

def kill(self, thread_ids, request_params):
hhyo marked this conversation as resolved.
Show resolved Hide resolved
# request_params = request.POST.get('request_params')
def kill(self, thread_ids):
kill_sql = ""
for i in thread_ids:
kill_sql = kill_sql + f"kill {i};"
Expand All @@ -64,8 +63,7 @@ def kill(self, thread_ids, request_params):
instance__instance_name=self.instance_name
)
# 调用aliyun接口获取终止进程
request_params = json.loads(request_params)
service_request_param = dict({"Language": "zh"}, **request_params)
service_request_param = {"Language": "zh"}
kill_result = Aliyun(rds=instance_info).RequestServiceOfCloudDBA(
"ConfirmKillSessionRequest", service_request_param
)
Expand Down
4 changes: 0 additions & 4 deletions sql/slowlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from common.utils.extend_json_encoder import ExtendJSONEncoder
from .models import Instance, SlowQuery, SlowQueryHistory, AliyunRdsConfig

# from .aliyun_rds import slowquery_review as aliyun_rds_slowquery_review, \
# slowquery_review_history as aliyun_rds_slowquery_review_history

import logging

Expand All @@ -43,7 +41,6 @@ def slowquery_review(request):
instance_info = Instance.objects.get(instance_name=instance_name)
if AliyunRdsConfig.objects.filter(instance=instance_info, is_enable=True).exists():
# 调用阿里云慢日志接口
# result = aliyun_rds_slowquery_review(request)
query_engine = get_engine(instance=instance_info)
result = query_engine.slowquery_review(
hhyo marked this conversation as resolved.
Show resolved Hide resolved
self, start_time, end_time, db_name, limit, offset
Expand Down Expand Up @@ -134,7 +131,6 @@ def slowquery_review_history(request):
instance_info = Instance.objects.get(instance_name=instance_name)
if AliyunRdsConfig.objects.filter(instance=instance_info, is_enable=True).exists():
# 调用阿里云慢日志接口
# result = aliyun_rds_slowquery_review_history(request)
query_engine = get_engine(instance=instance_info)
result = query_engine.slowquery_review_history(
start_time, end_time, db_name, sql_id, limit, offset
Expand Down