Skip to content

Commit

Permalink
Hotifx Index Advisor (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
YiniXu9506 authored Feb 23, 2023
1 parent ef19f17 commit 43533b6
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 83 deletions.
2 changes: 1 addition & 1 deletion ui/packages/tidb-dashboard-for-dbaas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pingcap/tidb-dashboard-for-dbaas",
"version": "0.0.82",
"version": "0.0.85",
"main": "dist/main.js",
"module": "dist/main.js",
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class DataSource implements ISQLAdvisorDataSource {
token = this.globalConfig.apiToken
performanceInsightBaseUrl = this.globalConfig.performanceInsightBaseUrl

tuningListGet() {
tuningListGet(pageNumber?: number, pageSize?: number) {
return fetch(
`${this.performanceInsightBaseUrl}?BackMethod=GetTunedIndexLists&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}`,
`${this.performanceInsightBaseUrl}?BackMethod=GetTunedIndexLists&orgId=${this.orgId}&projectId=${this.projectId}&clusterId=${this.clusterId}&pageNumber=${pageNumber}&pageSize=${pageSize}`,
{
headers: {
token: `Bearer ${this.token}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
Alert,
Modal,
Tooltip,
Drawer
Drawer,
Checkbox
} from 'antd'
import { InfoCircleOutlined } from '@ant-design/icons'
import { Card, Toolbar } from '@lib/components'
Expand All @@ -34,8 +35,15 @@ const IndexInsightList = ({
const [showDeactivateModal, setShowDeactivateModal] = useState<boolean>(false)
const [showSetting, setShowSetting] = useState(false)
const [showCheckUpModal, setShowCheckUpModal] = useState(false)

const [dontRemindCheckUpNotice, setDontRemindCheckUpNotice] =
useState<boolean>(() =>
JSON.parse(
localStorage.getItem('index_insight_dont_remind_checkup_notice') ||
'false'
)
)
const { sqlTunedList, refreshSQLTunedList, loading } = useSQLTunedListGet()
const [cancelRunningTask, setCancelRunningTask] = useState(false)

const taskRunningStatusGet = useRef(() => {
return ctx?.ds
Expand Down Expand Up @@ -68,7 +76,7 @@ const IndexInsightList = ({
}
}
checkStatus()
}, [])
}, [cancelRunningTask])

useEffect(() => {
const checkSQLValidation = async () => {
Expand Down Expand Up @@ -103,7 +111,12 @@ const IndexInsightList = ({
} finally {
setNoTaskRunning(false)
setShowCheckUpModal(false)
localStorage.setItem(
'index_insight_dont_remind_checkup_notice',
JSON.stringify(dontRemindCheckUpNotice)
)
startCheckTaskStatusLoop.current()
setCancelRunningTask(false)
}
}

Expand All @@ -120,14 +133,15 @@ const IndexInsightList = ({
notification.success({
message: res.message
})
setNoTaskRunning(true)
} else {
notification.error({
message: res.message
})
}
} catch (e) {
console.log(e)
} finally {
setCancelRunningTask(true)
}
}

Expand All @@ -136,14 +150,27 @@ const IndexInsightList = ({
setShowSetting(false)
}

const handleCheckUpBtnClick = () => {
// if index_insight_dont_remind_checkup_notice has been checked, don't show comfirm modal again, checkup directly.
if (!dontRemindCheckUpNotice) {
setShowCheckUpModal(true)
} else {
handleIndexCheckUp()
}
}

const handlePaginationChange = (pageNumber: number, pageSize: number) => {
refreshSQLTunedList(pageNumber, pageSize)
}

return (
<>
<Card>
<Toolbar>
<Space align="center">
<Typography.Title level={4}>Performance Insight</Typography.Title>
</Space>
<Space>
<Space align="center" style={{ marginTop: 0 }}>
<Tooltip
title="Each insight will cover diagnosis data from the past 24 hours."
placement="rightTop"
Expand All @@ -152,7 +179,7 @@ const IndexInsightList = ({
</Tooltip>
<Button
disabled={!noTaskRunning || showAlert}
onClick={() => setShowCheckUpModal(true)}
onClick={handleCheckUpBtnClick}
loading={!noTaskRunning}
>
{noTaskRunning ? 'Check Up' : 'Task is Running'}
Expand Down Expand Up @@ -190,7 +217,7 @@ const IndexInsightList = ({
onOk={hanleDeactivate}
>
<p>
After disabling, all generated insight data by this feature will be
After disabling, all insight data generated by this feature will be
deleted.
</p>
</Modal>
Expand All @@ -199,14 +226,25 @@ const IndexInsightList = ({
visible={showCheckUpModal}
onCancel={() => setShowCheckUpModal(false)}
destroyOnClose={true}
onOk={handleIndexCheckUp}
okText="Comfirm"
footer={null}
>
<p>
When performing checks, system tables are queried. It is not
recommended to perform checks when the cluster is already under
heavy load.
</p>
<div style={{ textAlign: 'center' }}>
<Space direction="vertical" align="center">
<Checkbox
onChange={(e) => setDontRemindCheckUpNotice(e.target.checked)}
>
Don't remind me again.
</Checkbox>
<Button onClick={handleIndexCheckUp} type="primary">
Comfirm
</Button>
</Space>
</div>
</Modal>
{showAlert && (
<Alert
Expand All @@ -217,7 +255,11 @@ const IndexInsightList = ({
/>
)}
</Card>
<IndexInsightTable sqlTunedList={sqlTunedList} loading={loading} />
<IndexInsightTable
sqlTunedList={sqlTunedList}
loading={loading}
onHandlePaginationChange={handlePaginationChange}
/>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const UnRegisteredUserDB: React.FC<UnRegisteredUserDBProps> = ({
<Card className={styles.instructionCard}>
<Title level={5}>Permissions required:</Title>
<Alert
message={`Please replace your password in the 'yourpassword' field.`}
message={`Please replace your user name and password in the 'yourusername' and 'yourpassword' field.`}
type="warning"
showIcon
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,37 @@ import { Tooltip, Table } from 'antd'
import { Link } from 'react-router-dom'
import { getSuggestedCommand } from '../utils/suggestedCommandMaps'
import { SQLAdvisorContext } from '../context'
import { TuningDetailProps } from '../types'
import { SQLTunedListProps } from '../types'
import dayjs from 'dayjs'
import tz from '@lib/utils/timezone'

const DEF_PAGINATION_PARAMS = {
pageNumber: 1,
pageSize: 20
}

export const useSQLTunedListGet = () => {
const ctx = useContext(SQLAdvisorContext)
const [sqlTunedList, setSqlTunedList] = useState<TuningDetailProps[] | null>(
const [sqlTunedList, setSqlTunedList] = useState<SQLTunedListProps | null>(
null
)
const [loading, setLoading] = useState(true)

const sqlTunedListGet = useRef(async () => {
try {
const res = await ctx?.ds.tuningListGet()
setSqlTunedList(res!)
} catch (e) {
console.log(e)
} finally {
setLoading(false)
const sqlTunedListGet = useRef(
async (pageNumber?: number, pageSize?: number) => {
try {
const res = await ctx?.ds.tuningListGet(
pageNumber || DEF_PAGINATION_PARAMS.pageNumber,
pageSize || DEF_PAGINATION_PARAMS.pageSize
)
setSqlTunedList(res!)
} catch (e) {
console.log(e)
} finally {
setLoading(false)
}
}
})
)

useEffect(() => {
sqlTunedListGet.current()
Expand All @@ -36,21 +46,22 @@ export const useSQLTunedListGet = () => {
}

interface IndexInsightTableProps {
sqlTunedList: TuningDetailProps[] | null
sqlTunedList: SQLTunedListProps | null
loading: boolean
onHandlePaginationChange?: (pageNumber: number, pageSize: number) => void
}

const IndexInsightTable = ({
sqlTunedList,
loading
loading,
onHandlePaginationChange
}: IndexInsightTableProps) => {
const columns = useMemo(
() => [
{
title: 'Impact',
dataIndex: 'impact',
key: 'impact',
width: 50,
ellipsis: true,
render: (_, record) => {
return <>{record.impact}</>
Expand All @@ -60,7 +71,6 @@ const IndexInsightTable = ({
title: 'Type',
dataIndex: 'insight_type',
key: 'type',
width: 90,
ellipsis: true,
render: (_, record) => {
return <>{record.insight_type}</>
Expand All @@ -70,7 +80,6 @@ const IndexInsightTable = ({
title: 'Suggested Command',
dataIndex: 'suggested_command',
key: 'suggested_command',
width: 200,
ellipsis: true,
render: (_, record) => {
return (
Expand Down Expand Up @@ -100,7 +109,6 @@ const IndexInsightTable = ({
title: 'Related Slow SQL',
dataIndex: 'sql_statement',
key: 'related_slow_sql',
width: 250,
ellipsis: true,
render: (_, record) => {
return (
Expand All @@ -121,7 +129,6 @@ const IndexInsightTable = ({
}${tz.getTimeZone()})`,
dataIndex: 'checked_time',
key: 'check_up_time',
width: 140,
ellipsis: true,
render: (_, record) => {
return (
Expand All @@ -137,7 +144,6 @@ const IndexInsightTable = ({
title: 'Results',
dataIndex: 'detail',
key: 'detail',
width: 80,
render: (_, record) => {
return <Link to={`/sql_advisor/detail?id=${record.id}`}>Detail</Link>
}
Expand All @@ -149,10 +155,18 @@ const IndexInsightTable = ({
return (
<Card noMarginTop>
<Table
dataSource={sqlTunedList!}
dataSource={sqlTunedList?.tuned_results!}
columns={columns}
loading={loading}
size="small"
pagination={{
total: sqlTunedList?.count,
defaultCurrent: DEF_PAGINATION_PARAMS.pageNumber,
pageSize: DEF_PAGINATION_PARAMS.pageSize,
onChange: (pageNumber, pageSize) => {
onHandlePaginationChange?.(pageNumber, pageSize)
}
}}
/>
</Card>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { createContext } from 'react'
import { TuningDetailProps, TuningTaskStatus } from '../types/'
import {
TuningDetailProps,
TuningTaskStatus,
SQLTunedListProps
} from '../types/'

export interface ISQLAdvisorDataSource {
tuningListGet(
pageNumber?: number,
pageSize?: number
): Promise<TuningDetailProps[]>
): Promise<SQLTunedListProps>

tuningTaskStatusGet(): Promise<TuningTaskStatus>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.InlineCodeBlock {
background: 1#f1f1f1;
padding: 1px 8px;
border: 1px solid #dedede;
}

.SuggestedCommand {
background: #f1f1f1;
padding: 3px 10px;
display: flex;
width: 100%;
flex-flow: row;
justify-content: space-between;
}

.HighImpact {
color: #f70000;
}

.MediumImpact {
color: #fc6f03;
}

.LowImpact {
color: #e5c613;
}
Loading

0 comments on commit 43533b6

Please sign in to comment.