Skip to content

Commit ca94cf6

Browse files
authored
Merge pull request #693 from actiontech/feature/sql-insights
Feature/sql insights
2 parents 25d35e8 + 2160962 commit ca94cf6

38 files changed

+9544
-134
lines changed

packages/base/src/hooks/useThemeStyleData/__snapshots__/index.test.tsx.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,10 @@ exports[`test base/hooks/useThemeStyleData should match snapshot 3`] = `
923923
},
924924
"loadingColor": "#4583ff",
925925
},
926+
"sqlInsight": {
927+
"dataMarkerColor": "#ff4d4f",
928+
"regionFillColor": "rgba(197, 212, 235, 0.6)",
929+
},
926930
"statistics": {
927931
"auditRateStatus": {
928932
"error": {

packages/base/src/page/Nav/SideMenu/MenuList/menus/__tests__/__snapshots__/common.test.tsx.snap

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,20 @@ exports[`test genMenuItemsWithMenuStructTree should match snapshot 4`] = `
301301
"structKey": "sql-management-conf",
302302
"to": "/sqle/project/600300/sql-management-conf",
303303
},
304+
{
305+
"icon": <DashboardOutlined
306+
height={20}
307+
width={20}
308+
/>,
309+
"key": "sqle/project/projectID/sql-insights",
310+
"label": <ForwardRef(TypedLink)
311+
to="/sqle/project/600300/sql-insights"
312+
>
313+
性能洞察
314+
</ForwardRef(TypedLink)>,
315+
"structKey": "sql-insights",
316+
"to": "/sqle/project/600300/sql-insights",
317+
},
304318
],
305319
"label": "SQL管控",
306320
"permission": undefined,

packages/base/src/page/Nav/SideMenu/MenuList/menus/__tests__/common.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const menuStruct: MenuTreeTranslated[] = [
3838
{
3939
type: 'group',
4040
label: t('dmsMenu.groupLabel.SQLManagement'),
41-
groups: ['sql-management', 'sql-management-conf']
41+
groups: ['sql-management', 'sql-management-conf', 'sql-insights']
4242
},
4343
{ type: 'divider' },
4444
{

packages/base/src/router/test/__snapshots__/router.base.test.tsx.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,13 @@ exports[`base/router-base-ee render base route data snap 1`] = `
476476
"key": "sqlManagementConf",
477477
"path": ":projectID/sql-management-conf",
478478
},
479+
{
480+
"element": <div>
481+
sqlInsights
482+
</div>,
483+
"key": "sqlInsights",
484+
"path": ":projectID/sql-insights",
485+
},
479486
{
480487
"children": [
481488
{

packages/base/src/router/test/__snapshots__/router.ce.base.test.tsx.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,13 @@ exports[`base/router-base-ce render base route data snap 1`] = `
340340
"key": "sqlManagementConf",
341341
"path": ":projectID/sql-management-conf",
342342
},
343+
{
344+
"element": <div>
345+
sqlInsights
346+
</div>,
347+
"key": "sqlInsights",
348+
"path": ":projectID/sql-insights",
349+
},
343350
{
344351
"children": [
345352
{

packages/base/src/router/test/__snapshots__/router.sqle.test.tsx.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,24 @@ exports[`base/router-sqle-ee render sqle project detail router render sqle proje
546546
</body>
547547
`;
548548

549+
exports[`base/router-sqle-ee render sqle project detail router render sqle project detail router when version is ce render route sqlInsights 1`] = `
550+
<body>
551+
<div>
552+
<div
553+
data-test-parent-id="availabilityZoneWrapper"
554+
>
555+
<div
556+
data-test-parent-id="sqleProjectDetail"
557+
>
558+
<div>
559+
sqlInsights
560+
</div>
561+
</div>
562+
</div>
563+
</div>
564+
</body>
565+
`;
566+
549567
exports[`base/router-sqle-ee render sqle project detail router render sqle project detail router when version is ce render route sqlManagement render sqlManagement 1`] = `
550568
<body>
551569
<div>

packages/base/src/router/test/router.sqle.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ describe('base/router-sqle-ee', () => {
301301
expect(screen.getByText('dashboard')).toBeInTheDocument();
302302
});
303303

304+
it('render route sqlInsights', async () => {
305+
const { baseElement } = customRender([
306+
`/sqle/project/${projectID}/sql-insights`
307+
]);
308+
309+
await act(async () => jest.advanceTimersByTime(300));
310+
expect(baseElement).toMatchSnapshot();
311+
expect(screen.getByText('sqlInsights')).toBeInTheDocument();
312+
});
313+
304314
describe('render route sqlManagementConf', () => {
305315
it('render route list', async () => {
306316
const { baseElement } = customRender([

packages/shared/lib/testUtil/mockApi/sqle/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export { default as system } from './system';
2222
export { default as task } from './task';
2323
export { default as user } from './user';
2424
export { default as workflowTemplate } from './workflowTemplate';
25+
export { default as sqlInsight } from './sqlInsight';
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import {
2+
IRelatedSQLInfo,
3+
ISqlPerformanceInsights
4+
} from '../../../../api/sqle/service/common';
5+
import { RelatedSQLInfoSourceEnum } from '../../../../api/sqle/service/common.enum';
6+
7+
export const mockSqlPerformanceInsightsData: ISqlPerformanceInsights = {
8+
task_support: true,
9+
task_enable: true,
10+
x_info: '时间',
11+
y_info: '会话数',
12+
message: '',
13+
lines: [
14+
{
15+
line_name: '活跃会话数',
16+
points: [
17+
{
18+
x: '2025-07-22 15:57:56',
19+
y: 0,
20+
info: [
21+
{
22+
会话数: '0'
23+
}
24+
]
25+
},
26+
{
27+
x: '2025-07-22 18:21:56',
28+
y: 0,
29+
info: [
30+
{
31+
会话数: '0'
32+
}
33+
]
34+
},
35+
{
36+
x: '2025-07-22 20:45:56',
37+
y: 1,
38+
info: [
39+
{
40+
会话数: '1'
41+
}
42+
]
43+
},
44+
{
45+
x: '2025-07-22 23:09:56',
46+
y: 0,
47+
info: [
48+
{
49+
会话数: '0'
50+
}
51+
]
52+
},
53+
{
54+
x: '2025-07-23 01:33:56',
55+
y: 0,
56+
info: [
57+
{
58+
会话数: '0'
59+
}
60+
],
61+
status: 1
62+
},
63+
{
64+
x: '2025-07-23 03:57:56',
65+
y: 0,
66+
info: [
67+
{
68+
会话数: '0'
69+
}
70+
]
71+
},
72+
{
73+
x: '2025-07-23 06:21:56',
74+
y: 0,
75+
info: [
76+
{
77+
会话数: '0'
78+
}
79+
]
80+
},
81+
{
82+
x: '2025-07-23 08:45:56',
83+
y: 0,
84+
info: [
85+
{
86+
会话数: '0'
87+
}
88+
]
89+
},
90+
{
91+
x: '2025-07-23 11:09:56',
92+
y: 0,
93+
info: [
94+
{
95+
会话数: '0'
96+
}
97+
]
98+
},
99+
{
100+
x: '2025-07-23 13:33:56',
101+
y: 0,
102+
info: [
103+
{
104+
会话数: '0'
105+
}
106+
]
107+
}
108+
]
109+
}
110+
]
111+
};
112+
113+
export const mockSqlPerformanceInsightsRelatedSQLData: IRelatedSQLInfo[] = [
114+
{
115+
sql_fingerprint: 'SELECT * FROM `DMS`.`USERS` WHERE `name`!=?',
116+
source: RelatedSQLInfoSourceEnum.workflow,
117+
execute_time_avg: 0.011,
118+
execute_time_max: 0.011,
119+
execute_time_min: 0.011,
120+
execute_time_sum: 0.011,
121+
lock_wait_time: 0,
122+
execution_time_trend: {
123+
points: [
124+
{
125+
time: '2025-07-23T13:43:52.686+08:00',
126+
execute_time: 0.011,
127+
sql: "SELECT * FROM dms.users where name \u003c\u003e ''",
128+
id: 1,
129+
is_in_transaction: false,
130+
info: [{ 执行时长: '0.01' }]
131+
}
132+
],
133+
x_info: '时间',
134+
y_info: '执行时长',
135+
message: ''
136+
}
137+
}
138+
];
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import SqlInsight from '../../../../api/sqle/service/SqlInsight';
2+
import { MockSpyApy, createSpySuccessResponse } from '../../common';
3+
import {
4+
mockSqlPerformanceInsightsData,
5+
mockSqlPerformanceInsightsRelatedSQLData
6+
} from './data';
7+
8+
class MockSqlManageApi implements MockSpyApy {
9+
public mockAllApi(): void {
10+
this.getSqlPerformanceInsights();
11+
this.getSqlPerformanceInsightsRelatedSQL();
12+
this.getSqlPerformanceInsightsRelatedTransaction();
13+
}
14+
15+
public getSqlPerformanceInsights() {
16+
const spy = jest.spyOn(SqlInsight, 'GetSqlPerformanceInsights');
17+
spy.mockImplementation(() =>
18+
createSpySuccessResponse({
19+
data: mockSqlPerformanceInsightsData
20+
})
21+
);
22+
return spy;
23+
}
24+
25+
public getSqlPerformanceInsightsRelatedSQL() {
26+
const spy = jest.spyOn(SqlInsight, 'GetSqlPerformanceInsightsRelatedSQL');
27+
spy.mockImplementation(() =>
28+
createSpySuccessResponse({
29+
data: mockSqlPerformanceInsightsRelatedSQLData
30+
})
31+
);
32+
return spy;
33+
}
34+
35+
public getSqlPerformanceInsightsRelatedTransaction() {
36+
const spy = jest.spyOn(
37+
SqlInsight,
38+
'GetSqlPerformanceInsightsRelatedTransaction'
39+
);
40+
spy.mockImplementation(() =>
41+
createSpySuccessResponse({
42+
data: []
43+
})
44+
);
45+
return spy;
46+
}
47+
}
48+
49+
export default new MockSqlManageApi();

0 commit comments

Comments
 (0)