Skip to content

Commit

Permalink
feat(debug-api): support pagination for ddl history (#1584)
Browse files Browse the repository at this point in the history
  • Loading branch information
baurine authored Aug 30, 2023
1 parent 949927a commit db0052c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
4 changes: 4 additions & 0 deletions pkg/apiserver/debugapi/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ var apiEndpoints = []endpoint.APIDefinition{
Component: topo.KindTiDB,
Path: "/ddl/history",
Method: resty.MethodGet,
QueryParams: []endpoint.APIParamDefinition{
endpoint.APIParamInt("start_job_id", false),
endpoint.APIParamIntWithDefaultVal("limit", false, "10"),
},
},
{
ID: "tidb_server_info",
Expand Down
12 changes: 11 additions & 1 deletion pkg/apiserver/debugapi/endpoint/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (d *APIParamDefinition) Resolve(value string) ([]string, error) {
// UIComponentTextProps is the type of UIComponentProps when UIComponentKind is "text".
type UIComponentTextProps struct {
Placeholder string `json:"placeholder"`
DefaultVal string `json:"default_val"`
}

func APIParamText(name string, required bool) APIParamDefinition {
Expand All @@ -57,12 +58,21 @@ func APIParamText(name string, required bool) APIParamDefinition {
}

func APIParamInt(name string, required bool) APIParamDefinition {
return APIParamIntWithDefaultVal(name, required, "")
}

func APIParamIntWithDefaultVal(name string, required bool, defVal string) APIParamDefinition {
placeHolder := "(int)"
if defVal != "" {
placeHolder = fmt.Sprintf("(int, default: %s)", defVal)
}
return APIParamDefinition{
Name: name,
Required: required,
UIComponentKind: "text",
UIComponentProps: UIComponentTextProps{
Placeholder: "(int)",
Placeholder: placeHolder,
DefaultVal: defVal,
},
OnResolve: func(value string) ([]string, error) {
if _, err := strconv.Atoi(value); err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"tidb": "TiDB",
"tikv": "TiKV",
"pd": "PD",
"tiflash": "TiFlash",
"ticdc": "TiCDC"
}
{"tidb":"TiDB","tikv":"TiKV","pd":"PD","tiflash":"TiFlash","ticdc":"TiCDC"}
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ export default function ApiForm({
setLoading(true)
const { [endpointHostParamKey]: host, ...p } = values
const [hostname, port] = host.split(':')
// filter the null value params
const param_values = Object.entries(p).reduce((prev, [k, v]) => {
if (!(isUndefined(v) || isNull(v) || v === '')) {
prev[k] = v
} else {
// handle the null value params
// fill it with the default value if it has
const param = params.find((p) => p.name === k)
const defVal = (param?.ui_props as any)?.default_val
if (!!defVal) {
prev[k] = defVal
}
}
return prev
}, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ debug_api:
tidb_schema_by_db: Schema Information - by Database
tidb_schema_by_table: Schema Information - by Database + Table
tidb_schema_by_table_id: Schema and Table Information - by TableID
tidb_ddl_history: DDL History - All
tidb_ddl_history: DDL History
tidb_server_info: Server Information - Current
tidb_all_servers_info: Server Information - All Servers
tidb_all_regions_meta: Region - All
Expand All @@ -44,7 +44,6 @@ debug_api:
tidb_schema_db: Schema Information - by Database
tidb_schema_db_table: Schema Information - by Database + Table
tidb_dbtable_tableid: Schema and Table Information - by TableID
# tidb_ddl_history: DDL History - All
tidb_info: Server Information - Current
tidb_info_all: Server Information - All Servers
tidb_regions_meta: Region - All
Expand Down

0 comments on commit db0052c

Please sign in to comment.