Skip to content

Commit

Permalink
feat(conprof): support conprof on new o11y for clinic
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine committed Nov 7, 2023
1 parent 13ee5c8 commit 27a48ed
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 31 deletions.
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint --fix",
"prettier --write"
],
"*.+(json|css|md)": "prettier --write"
"*.+(json|css|md|html)": "prettier --write"
},
"husky": {
"hooks": {
Expand Down
8 changes: 7 additions & 1 deletion ui/packages/tidb-dashboard-for-clinic-cloud/public/ngm.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,14 @@
customAbsoluteRangePicker: true
},
autoRefresh: false
},
conProf: {
checkNgm: false,
showSetting: false,
listDuration: 1
}
}
},
appsEnabled: ['topsql', 'slow_query', 'conprof', 'sql_advisor']
})
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {
IConProfilingDataSource,
IConProfilingContext,
ReqConfig
ReqConfig,
IConProfilingConfig
} from '@pingcap/tidb-dashboard-lib'

import client, { ConprofNgMonitoringConfig } from '~/client'
Expand Down Expand Up @@ -84,7 +85,15 @@ class DataSource implements IConProfilingDataSource {

const ds = new DataSource()

export const ctx: IConProfilingContext = {
export const ctx: (
cfg: Partial<IConProfilingConfig>
) => IConProfilingContext = (cfg) => ({
ds,
cfg: { apiPathBase: client.getBasePath(), publicPathBase }
}
cfg: {
apiPathBase: client.getBasePath(),
publicPathBase,
checkNgm: true,
showSetting: true,
...cfg
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import {
ConProfilingProvider
} from '@pingcap/tidb-dashboard-lib'
import { ctx } from './context'
import { getGlobalConfig } from '~/utils/globalConfig'

export default function () {
return (
<ConProfilingProvider value={ctx}>
<ConProfilingProvider
value={ctx(getGlobalConfig().appsConfig?.conProf || {})}
>
<ConProfilingApp />
</ConProfilingProvider>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
IConProfilingConfig,
IOverviewConfig,
ISlowQueryConfig,
IStatementConfig,
Expand Down Expand Up @@ -45,6 +46,7 @@ export type AppsConfig = {
slowQuery?: Partial<ISlowQueryConfig>
statement?: Partial<IStatementConfig>
topSQL?: Partial<ITopSQLConfig>
conProf?: Partial<IConProfilingConfig>
}

export type GlobalConfig = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,11 @@ const ds = new DataSource()

export const ctx: IConProfilingContext = {
ds,
cfg: { apiPathBase: client.getBasePath(), publicPathBase }
cfg: {
apiPathBase: client.getBasePath(),
publicPathBase,
checkNgm: true,
showSetting: true,
listDuration: 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ export interface IConProfilingDataSource {
getPDTopology(options?: ReqConfig): AxiosPromise<Array<TopologyPDInfo>>
}

export interface IConProfilingConfig extends IContextConfig {
publicPathBase: string
checkNgm: boolean
showSetting: boolean
listDuration?: number // unit hour, 1 means 1 hour, 2 means 2 hours
}

export interface IConProfilingContext {
ds: IConProfilingDataSource
cfg: IContextConfig & { publicPathBase: string }
cfg: IConProfilingConfig
}

export const ConProfilingContext = createContext<IConProfilingContext | null>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,36 @@ addTranslations(translations)

function AppRoutes() {
useLocationChange()
const ctx = useContext(ConProfilingContext)

return (
<Routes>
<Route
path="/continuous_profiling"
element={
<NgmNotStartedGuard>
ctx?.cfg.checkNgm ? (
<NgmNotStartedGuard>
<List />
</NgmNotStartedGuard>
) : (
<List />
</NgmNotStartedGuard>
)
}
/>
<Route
path="/continuous_profiling/detail"
element={
<NgmNotStartedGuard>
ctx?.cfg.checkNgm ? (
<NgmNotStartedGuard>
<ParamsPageWrapper>
<Detail />
</ParamsPageWrapper>
</NgmNotStartedGuard>
) : (
<ParamsPageWrapper>
<Detail />
</ParamsPageWrapper>
</NgmNotStartedGuard>
)
}
/>
</Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ export default function Page() {
maxWidth: 100,
onRender: (record) => {
const profileType = record.profile_type
if (profileType === 'profile') {
// in the ngm, the `profile` is `cpu`
if (profileType === 'profile' || profileType === 'cpu') {
return `CPU - ${profileDuration}s`
}
return upperFirst(profileType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ import { useURLTimeRange } from '@lib/hooks/useURLTimeRange'

export default function Page() {
const ctx = useContext(ConProfilingContext)
const durationHour = ctx?.cfg.listDuration ?? 2

const { timeRange, setTimeRange } = useURLTimeRange()
const endTime = timeRange.type === 'recent' ? '' : `${timeRange.value[1]}`
const setEndTime = (v) => {
if (!v) {
setTimeRange({ type: 'recent', value: 2 * 60 * 60 })
setTimeRange({ type: 'recent', value: durationHour * 60 * 60 })
} else {
const endUnix = v.unix()
setTimeRange({
type: 'absolute',
value: [endUnix - 2 * 60 * 60, endUnix]
value: [endUnix - durationHour * 60 * 60, endUnix]
})
}
}
Expand Down Expand Up @@ -78,7 +79,7 @@ export default function Page() {
} else {
_rangeEndTime = rangeEndTime
}
const _rangeStartTime = _rangeEndTime.subtract(2, 'h')
const _rangeStartTime = _rangeEndTime.subtract(durationHour, 'h')

return ctx!.ds.continuousProfilingGroupProfilesGet(
_rangeStartTime.unix(),
Expand Down Expand Up @@ -234,7 +235,7 @@ export default function Page() {
/>
</Form.Item>
<Form.Item label={t('conprof.list.toolbar.range_duration')}>
<span>-2h</span>
<span>-{durationHour}h</span>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit" loading={listLoading}>
Expand All @@ -256,19 +257,21 @@ export default function Page() {
<ReloadOutlined onClick={refresh} />
)}
</Tooltip>
<Tooltip
mouseEnterDelay={0}
mouseLeaveDelay={0}
title={t('conprof.list.toolbar.settings')}
placement="bottom"
>
<SettingOutlined
onClick={() => {
setShowSettings(true)
telemetry.clickSettings('settingIcon')
}}
/>
</Tooltip>
{ctx?.cfg.showSetting && (
<Tooltip
mouseEnterDelay={0}
mouseLeaveDelay={0}
title={t('conprof.list.toolbar.settings')}
placement="bottom"
>
<SettingOutlined
onClick={() => {
setShowSettings(true)
telemetry.clickSettings('settingIcon')
}}
/>
</Tooltip>
)}
{!isDistro() && (
<Tooltip
mouseEnterDelay={0}
Expand Down

0 comments on commit 27a48ed

Please sign in to comment.