Skip to content

Commit

Permalink
feat(tiproxy): support conprof and debug api for tiproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine committed Mar 13, 2024
1 parent abee03e commit 40e829b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 12 deletions.
26 changes: 23 additions & 3 deletions pkg/apiserver/debugapi/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pingcap/tidb-dashboard/util/topo"
)

var commomParamPprofKinds = endpoint.APIParamEnum("kind", true, []endpoint.EnumItemDefinition{
var commonParamPprofKinds = endpoint.APIParamEnum("kind", true, []endpoint.EnumItemDefinition{
{Value: "allocs"},
{Value: "block"},
{Value: "cmdline"},
Expand Down Expand Up @@ -159,7 +159,7 @@ var apiEndpoints = []endpoint.APIDefinition{
Path: "/debug/pprof/{kind}",
Method: resty.MethodGet,
PathParams: []endpoint.APIParamDefinition{
commomParamPprofKinds,
commonParamPprofKinds,
},
QueryParams: []endpoint.APIParamDefinition{
commonParamPprofSeconds,
Expand Down Expand Up @@ -394,7 +394,7 @@ var apiEndpoints = []endpoint.APIDefinition{
Path: "/debug/pprof/{kind}",
Method: resty.MethodGet,
PathParams: []endpoint.APIParamDefinition{
commomParamPprofKinds,
commonParamPprofKinds,
},
QueryParams: []endpoint.APIParamDefinition{
commonParamPprofSeconds,
Expand Down Expand Up @@ -439,4 +439,24 @@ var apiEndpoints = []endpoint.APIDefinition{
req.SetHeader("Content-Type", "application/protobuf")
},
},
// TiProxy Endpoints
{
ID: "tiproxy_config",
Component: topo.KindTiProxy,
Path: "/api/admin/config",
Method: resty.MethodGet,
},
{
ID: "tiproxy_pprof",
Component: topo.KindTiProxy,
Path: "/debug/pprof/{kind}",
Method: resty.MethodGet,
PathParams: []endpoint.APIParamDefinition{
commonParamPprofKinds,
},
QueryParams: []endpoint.APIParamDefinition{
commonParamPprofSeconds,
commonParamPprofDebug,
},
},
}
2 changes: 1 addition & 1 deletion pkg/apiserver/debugapi/endpoint/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (p *ResolvedRequestPayload) verifyEndpoint(ctx context.Context, etcdClient
}
matched := false
for _, info := range infos {
if info.IP == p.host && info.Port == uint(p.port) {
if info.IP == p.host && info.StatusPort == uint(p.port) {

Check warning on line 301 in pkg/apiserver/debugapi/endpoint/payload.go

View check run for this annotation

Codecov / codecov/patch

pkg/apiserver/debugapi/endpoint/payload.go#L301

Added line #L301 was not covered by tests
matched = true
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class DataSource implements IDebugAPIDataSource {
getPDTopology(options?: ReqConfig) {
return client.getInstance().getPDTopology(options)
}

getTiProxyTopology(options?: ReqConfig) {
return client.getInstance().getTiProxyTopology(options)
}
}

const ds = new DataSource()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export default function Page() {
minWidth: 250,
maxWidth: 300,
onRender: (rec) => {
const { tikv, tidb, pd, tiflash, ticdc } = rec.component_num
const { tikv, tidb, pd, tiflash, ticdc, tiproxy } = rec.component_num
let s = `${tikv} ${instanceKindName(
'tikv'
)}, ${tidb} ${instanceKindName('tidb')}, ${pd} ${instanceKindName(
Expand All @@ -120,6 +120,9 @@ export default function Page() {
if (ticdc !== undefined) {
s = `${s}, ${ticdc} ${instanceKindName('ticdc')}`
}
if (tiproxy !== undefined) {
s = `${s}, ${tiproxy} ${instanceKindName('tiproxy')}`
}
return s
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Topology {
tikv: TopologyStoreInfo[]
tiflash: TopologyStoreInfo[]
pd: TopologyPDInfo[]
tiproxy: TopologyPDInfo[]
}

export default function ApiForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,25 @@ export default function Page() {
const { endpoints, filterBy } = useFilterEndpoints(endpointData)

// TODO: refine with components/InstanceSelect
const { data: tidbTopology = [], isLoading: isTiDBTopology } =
const { data: tidbTopology = [], isLoading: isTiDBLoading } =
useClientRequest(ctx!.ds.getTiDBTopology)
const { data: pdTopology = [], isLoading: isPDLoading } = useClientRequest(
ctx!.ds.getPDTopology
)
const { data: storeTopology, isLoading: isStoreLoading } = useClientRequest(
ctx!.ds.getStoreTopology
)
const { data: tiproxyTopology = [], isLoading: isTiProxyLoading } =
useClientRequest(ctx!.ds.getTiProxyTopology)
const topology: Topology = {
tidb: tidbTopology!,
tikv: storeTopology?.tikv || [],
tiflash: storeTopology?.tiflash || [],
pd: pdTopology!
pd: pdTopology!,
tiproxy: tiproxyTopology!
}
const isTopologyLoading = isTiDBTopology || isPDLoading || isStoreLoading
const isTopologyLoading =
isTiDBLoading || isPDLoading || isStoreLoading || isTiProxyLoading

const groups = useMemo(
() =>
Expand All @@ -89,7 +93,7 @@ export default function Page() {
)
const sortedGroups = useMemo(
() =>
['tidb', 'tikv', 'tiflash', 'pd']
['tidb', 'tikv', 'tiflash', 'pd', 'tiproxy']
.filter((sortKey) => groups[sortKey])
.map((sortKey) => groups[sortKey]),
[groups]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const portKeys: { [k: string]: string } = {
tidb: 'status_port',
tikv: 'status_port',
tiflash: 'status_port',
pd: 'port'
pd: 'port',
tiproxy: 'status_port'
}

export const HostSelectWidget: ApiFormWidget = ({ endpoint, topology }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
InfoTableSchema,
TopologyTiDBInfo,
ClusterinfoStoreTopologyResponse,
TopologyPDInfo
TopologyPDInfo,
TopologyTiProxyInfo
} from '@lib/client'

import { IContextConfig, ReqConfig } from '@lib/types'
Expand Down Expand Up @@ -37,6 +38,10 @@ export interface IDebugAPIDataSource {
): AxiosPromise<ClusterinfoStoreTopologyResponse>

getPDTopology(options?: ReqConfig): AxiosPromise<Array<TopologyPDInfo>>

getTiProxyTopology(
options?: ReqConfig
): AxiosPromise<Array<TopologyTiProxyInfo>>
}

export interface IDebugAPIContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ debug_api:
pd_store_id: Store - by StoreID (pd-ctl store [id])
# pd_pprof: pprof
# pd_pprof_desc: The `seconds` parameter is only effective to `kind=profile` and `kind=trace`.
tiproxy:
name: '{{distro.tiproxy}}'
endpoints:
tiproxy_config: Current Config
tiproxy_pprof: pprof
tiproxy_pprof_desc: The `seconds` parameter is only effective to `kind=profile` and `kind=trace`.
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,13 @@ function InstanceSelect(
)

const [tableItems] = useMemo(() => {
if (loadingTiDB || loadingStores || loadingPD) {
if (
loadingTiDB ||
loadingStores ||
loadingPD ||
loadingTiCDC ||
loadingTiProxy
) {
return [[], []]
}
return buildInstanceTable({
Expand Down

0 comments on commit 40e829b

Please sign in to comment.