forked from pingcap/tidb-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/sql index advisor (pingcap#1460)
* feat: add insight index advisor app * chore: sync upstream master * fix: lint
- Loading branch information
1 parent
313386a
commit 85582bd
Showing
71 changed files
with
1,437 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/Overview/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/SQLAdvisor/context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
ISQLAdvisorDataSource, | ||
ISQLAdvisorContext | ||
} from '@pingcap/tidb-dashboard-lib' | ||
import { getGlobalConfig } from '~/utils/globalConfig' | ||
|
||
const { clusterInfo, performanceInsightBaseUrl } = getGlobalConfig() | ||
const { orgId, clusterId, projectId } = clusterInfo | ||
|
||
const csrfToken = localStorage.getItem('clinic.auth.csrf_token') | ||
|
||
class DataSource implements ISQLAdvisorDataSource { | ||
tuningListGet() { | ||
return fetch( | ||
`${performanceInsightBaseUrl}?BackMethod=GetTunedIndexLists&tenantId=${orgId}&projectId=${projectId}&clusterId=${clusterId}&token=${csrfToken}` | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningTaskCreate(startTime: number, endTime: number) { | ||
return fetch( | ||
`${performanceInsightBaseUrl}?BackMethod=CreateAdviseTask&tenantId=${orgId}&projectId=${projectId}&clusterId=${clusterId}&startTime=${startTime}&endTime=${endTime}&token=${csrfToken}` | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningTaskStatusGet() { | ||
return fetch( | ||
`${performanceInsightBaseUrl}?BackMethod=IsOKForTuningTask&tenantId=${orgId}&projectId=${projectId}&clusterId=${clusterId}&token=${csrfToken}` | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningDetailGet(id: number) { | ||
return fetch( | ||
`${performanceInsightBaseUrl}?BackMethod=GetTuningResult&ID=${id}&token=${csrfToken}` | ||
).then((res) => res.json()) | ||
} | ||
} | ||
|
||
const ds = new DataSource() | ||
|
||
export const ctx: ISQLAdvisorContext = { | ||
ds, | ||
orgId, | ||
clusterId | ||
} |
11 changes: 11 additions & 0 deletions
11
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/SQLAdvisor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
import { SQLAdvisorAPP, SQLAdvisorProvider } from '@pingcap/tidb-dashboard-lib' | ||
import { ctx } from './context' | ||
|
||
export default function () { | ||
return ( | ||
<SQLAdvisorProvider value={ctx}> | ||
<SQLAdvisorAPP /> | ||
</SQLAdvisorProvider> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/SQLAdvisor/meta.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
id: 'sql_advisor', | ||
routerPrefix: '/sql_advisor', | ||
reactRoot: () => import('.') | ||
} |
2 changes: 1 addition & 1 deletion
2
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/SlowQuery/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
ui/packages/tidb-dashboard-for-clinic-cloud/src/apps/TopSQL/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
ui/packages/tidb-dashboard-for-dbaas/src/apps/SQLAdvisor/context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { | ||
ISQLAdvisorDataSource, | ||
ISQLAdvisorContext | ||
} from '@pingcap/tidb-dashboard-lib' | ||
|
||
import { IGlobalConfig } from '~/utils/global-config' | ||
|
||
class DataSource implements ISQLAdvisorDataSource { | ||
constructor(public globalConfig: IGlobalConfig) {} | ||
|
||
clusterInfo = this.globalConfig.clusterInfo | ||
orgId = this.clusterInfo.orgId | ||
clusterId = this.clusterInfo.clusterId | ||
projectId = this.clusterInfo.projectId | ||
token = this.globalConfig.apiToken | ||
performanceInsightBaseUrl = this.globalConfig.performanceInsightBaseUrl | ||
|
||
tuningListGet(type: string) { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=GetTunedIndexLists&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}&type=${type}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningTaskCreate(startTime: number, endTime: number) { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=CreateAdviseTask&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}&startTime=${startTime}&endTime=${endTime}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningTaskStatusGet() { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=IsOKForTuningTask&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
tuningDetailGet(id: number) { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=GetTuningResult&ID=${id}&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
registerUserDB(params: { userName: string; password: string }) { | ||
const { userName, password } = params | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=RegisterUserDB&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}&userName=${userName}&password=${password}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
// registerUserDB(params: { userName: string; password: string }) { | ||
// // const { userName, password } = params | ||
// return fetch( | ||
// `${this.performanceInsightBaseUrl}?BackMethod=RegisterUserDB&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}`, | ||
// { | ||
// method: 'POST', | ||
// headers: { | ||
// token: `Bearer ${this.token}` | ||
// }, | ||
// body: JSON.stringify(params) | ||
// } | ||
// ).then((res) => res.json()) | ||
// } | ||
|
||
unRegisterUserDB() { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=UnRegisterUserDB&clusterId=${this.clusterId}&projectId=${this.projectId}&orgId=${this.orgId}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
registerUserDBStatusGet() { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=IsTiDBOKForAdvisor&clusterId=${this.clusterId}&projectId=${this.projectId}&orgId=${this.orgId}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
|
||
sqlValidationGet() { | ||
return fetch( | ||
`${this.performanceInsightBaseUrl}?BackMethod=CheckIfUserTiDBOK&clusterId=${this.clusterId}&projectId=${this.projectId}&orgId=${this.orgId}`, | ||
{ | ||
headers: { | ||
token: `Bearer ${this.token}` | ||
} | ||
} | ||
).then((res) => res.json()) | ||
} | ||
} | ||
|
||
export const ctx: (globalConfig: IGlobalConfig) => ISQLAdvisorContext = ( | ||
globalConfig | ||
) => ({ | ||
ds: new DataSource(globalConfig), | ||
orgId: globalConfig.clusterInfo.orgId, | ||
clusterId: globalConfig.clusterInfo.clusterId, | ||
registerUserDB: true | ||
}) |
14 changes: 14 additions & 0 deletions
14
ui/packages/tidb-dashboard-for-dbaas/src/apps/SQLAdvisor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { useContext } from 'react' | ||
import { SQLAdvisorAPP, SQLAdvisorProvider } from '@pingcap/tidb-dashboard-lib' | ||
import { GlobalConfigContext } from '~/utils/global-config' | ||
import { ctx } from './context' | ||
|
||
export default function () { | ||
const globalConfig = useContext(GlobalConfigContext) | ||
|
||
return ( | ||
<SQLAdvisorProvider value={ctx(globalConfig)}> | ||
<SQLAdvisorAPP /> | ||
</SQLAdvisorProvider> | ||
) | ||
} |
Oops, something went wrong.