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

添加慢SQL的的优化管理功能 #2549

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Conversation

Grain-Yu
Copy link
Contributor

这个功能来自之前的一个想法:#2382
演示demo

另外,关于“编辑详情”页面的“状态”:
image
我的设想是,
open:开始认领这个慢SQL
resolved:已有解决方案
pending:难以优化,暂挂
closed:这个SQL的优化方案已经在业务层面实施完毕

@Grain-Yu
Copy link
Contributor Author

Grain-Yu commented Mar 24, 2024

这个test怎么一直失败呢,我先去掉了

@LeoQuote
Copy link
Collaborator

你写错了, requests.post(json={}) 才能以 json 方式请求

@LeoQuote
Copy link
Collaborator

本地可以跑的 https://github.com/hhyo/Archery/wiki/development#%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95 看一下这里的, 简单配置一下就行

Copy link

codecov bot commented Mar 24, 2024

Codecov Report

Attention: Patch coverage is 48.83721% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 76.74%. Comparing base (5f556a5) to head (962c2da).

Files Patch % Lines
sql/slowlog.py 22.22% 21 Missing ⚠️
sql/views.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2549      +/-   ##
==========================================
- Coverage   76.82%   76.74%   -0.08%     
==========================================
  Files         117      117              
  Lines       16073    16115      +42     
==========================================
+ Hits        12348    12368      +20     
- Misses       3725     3747      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Grain-Yu Grain-Yu marked this pull request as draft March 24, 2024 08:12
@Grain-Yu Grain-Yu marked this pull request as ready for review March 24, 2024 09:36
)
.values(
"SQLText",
"SQLId",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个PR中,SQLId, checksum, SQLChecksum实际上都是archery.mysql_slow_query_review表的checksum字段。是为了显示方便所以有不同叫法。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review_checksum也是

@permission_required("sql.menu_slowquery", raise_exception=True)
def listreview(request):
"""获取优化详情"""
checksum = request.POST.get("review_checksum")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

获取用户在页面中勾选的SQL语句对应的checksum

@@ -251,3 +264,45 @@ def report(request):

result = {"status": 0, "msg": "", "data": line.render_embed()}
return HttpResponse(json.dumps(result), content_type="application/json")


@permission_required("sql.menu_slowquery", raise_exception=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

沿用查看慢日志的权限,没有单独加权限控制,后续可以添加。

@permission_required("sql.menu_slowquery", raise_exception=True)
def editreview(request):
"""更新优化详情"""
checksum = request.POST.get("checksum")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

获取欲操作的SQL语句对应的checksum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

编辑框传过来的值

reviewed_on = reviewed_on,
comments = comments,
reviewed_status = reviewed_status
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新数据库

@Grain-Yu
Copy link
Contributor Author

@LeoQuote 大佬方便的话麻烦加一下单元测试。另外,我看black给我改写的不能用,有些逻辑变了

@LeoQuote
Copy link
Collaborator

能否考虑使用 rest_framework 实现? 我看你这个主要逻辑还是有点restful 风格的,black 必须能过哈,他给你修的不行你就自己修

@Grain-Yu
Copy link
Contributor Author

能否考虑使用 rest_framework 实现? 我看你这个主要逻辑还是有点restful 风格的,black 必须能过哈,他给你修的不行你就自己修

那估计要研究很久了,还是初学者哈哈

@Grain-Yu
Copy link
Contributor Author

ImportError while loading conftest '/home/runner/work/Archery/Archery/conftest.py'.
conftest.py:4: in
from pytest_mock import MockFixture
E ModuleNotFoundError: No module named 'pytest_mock'
Error: Process completed with exit code 4.

@LeoQuote
Copy link
Collaborator

更新了wiki, 得装一批开发用的依赖

@Grain-Yu Grain-Yu closed this Mar 24, 2024
@Grain-Yu Grain-Yu reopened this Mar 24, 2024
@czxin788
Copy link
Contributor

czxin788 commented Apr 3, 2024

我觉得这个功能不错,期待中

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants