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

Mongo会话管理增加显示字段 #2785

Merged
merged 39 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6ca8e7f
添加favicon图片
May 9, 2024
870ea4e
Merge branch 'master' of https://github.com/hhyo/Archery
May 10, 2024
d24784d
Merge branch 'master' of https://github.com/hhyo/Archery
Jun 20, 2024
e80b335
firset
Jun 20, 2024
e4d02bb
修改
Jun 20, 2024
118504c
撤销
Jun 20, 2024
a4531d0
Merge branch 'master' of https://github.com/hhyo/Archery
Jun 21, 2024
7c2fea5
Merge branch 'master' of https://github.com/hhyo/Archery
Jun 27, 2024
64abe26
Merge branch 'master' of https://github.com/hhyo/Archery
Jul 31, 2024
bf3f327
Merge branch 'master' of https://github.com/hhyo/Archery
Aug 7, 2024
d23edba
Merge branch 'master' of https://github.com/hhyo/Archery
Aug 7, 2024
405b79e
Merge branch 'master' of https://github.com/hhyo/Archery
Aug 14, 2024
36bdde6
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 16, 2024
75edaf7
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 16, 2024
44230c0
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 19, 2024
d9bea16
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 20, 2024
09834da
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 28, 2024
aee2867
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Aug 30, 2024
dd0c01c
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Sep 2, 2024
559019b
mongo会话管理增加字段
feiazifeiazi Sep 2, 2024
caba31d
effectiveUsers_user
feiazifeiazi Sep 2, 2024
a769d28
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Sep 19, 2024
c4734b7
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Sep 19, 2024
1598adc
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Sep 19, 2024
3001ee3
修改单元测试方法
feiazifeiazi Sep 20, 2024
6777a7a
返回结果修改-模拟 MongoDB aggregate 的游标行为
feiazifeiazi Sep 20, 2024
2144fc0
模拟 MongoDB aggregate 的游标行为
feiazifeiazi Sep 20, 2024
95ddd0c
添加favicon图片
May 9, 2024
9b7ed60
firset
Jun 20, 2024
04468ee
修改
Jun 20, 2024
d7e042c
撤销
Jun 20, 2024
84bc27b
mongo会话管理增加字段
feiazifeiazi Sep 2, 2024
8696c87
effectiveUsers_user
feiazifeiazi Sep 2, 2024
fc82de8
修改单元测试方法
feiazifeiazi Sep 20, 2024
908f596
返回结果修改-模拟 MongoDB aggregate 的游标行为
feiazifeiazi Sep 20, 2024
e2de5ab
模拟 MongoDB aggregate 的游标行为
feiazifeiazi Sep 20, 2024
0fc908a
Merge branch 'mongo会话管理增加字段' of https://github.com/feiazifeiazi/Arche…
feiazifeiazi Sep 25, 2024
27d9f3d
Merge branch 'master' of https://github.com/hhyo/Archery
feiazifeiazi Sep 25, 2024
5b5cfa8
Merge branch 'master' of
feiazifeiazi Sep 25, 2024
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
12 changes: 12 additions & 0 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,18 @@ def processlist(self, command_type, **kwargs):
"client"
]

# 获取此会话的用户名
effective_users_key = "effectiveUsers_user"
effective_users = operation.get("effectiveUsers", [])
if isinstance(effective_users, list) and effective_users:
first_user = effective_users[0]
if isinstance(first_user, dict):
operation[effective_users_key] = first_user.get("user", [])
else:
operation[effective_users_key] = None
else:
operation[effective_users_key] = None

# client_s 只是处理的mongos,并不是实际客户端
# client 在sharding获取不到?
if command_type in ["Full"]:
Expand Down
19 changes: 14 additions & 5 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,16 +1841,25 @@ def test_fill_query_columns(self):

@patch("sql.engines.mongo.MongoEngine.get_connection")
def test_processlist(self, mock_get_connection):
class Aggregate:
# 模拟 MongoDB aggregate 的游标行为
class AggregateCursor:
def __enter__(self):
yield {"client": "single_client"}
yield {"clientMetadata": {"mongos": {"client": "sharding_client"}}}
yield {
"client": "single_client",
"effectiveUsers": [{"user": "user_1"}],
"clientMetadata": {"mongos": {"client": "sharding_client"}},
}
yield {
"clientMetadata": {"mongos": {}},
"effectiveUsers": [{"user": "user_2"}],
}
yield {"effectiveUsers": []}

def __exit__(self, *arg, **kwargs):
def __exit__(self, exc_type, exc_value, traceback):
pass

mock_conn = Mock()
mock_conn.admin.aggregate.return_value = Aggregate()
mock_conn.admin.aggregate.return_value = AggregateCursor()
mock_get_connection.return_value = mock_conn
command_types = ["Full", "All", "Inner", "Active"]
for command_type in command_types:
Expand Down
18 changes: 18 additions & 0 deletions sql/templates/dbdiagnostic.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,29 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
title: 'type',
field: 'type',
sortable: true
}, {
title: 'active',
field: 'active',
sortable: true
}, {
title: 'desc',
field: 'desc',
sortable: true
}, {
title: 'ns',
field: 'ns',
sortable: true
}, {
title: 'effectiveUsers_user',
field: 'effectiveUsers_user',
sortable: true
}
, {
title: 'secs_running',
field: 'secs_running',
sortable: true
}
, {
title: 'microsecs_running',
field: 'microsecs_running',
sortable: true
Expand Down
Loading