Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/http: support tidb-operator SDK #7508

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ go 1.21
require (
github.com/BurntSushi/toml v0.3.1
github.com/cloudfoundry/gosigar v1.3.6
github.com/coreos/go-semver v0.3.1
github.com/docker/go-units v0.5.0
github.com/gogo/protobuf v1.3.2
github.com/opentracing/opentracing-go v1.2.0
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
Expand Down
4 changes: 4 additions & 0 deletions client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudfoundry/gosigar v1.3.6 h1:gIc08FbB3QPb+nAQhINIK/qhf5REKkY0FTGgRGXkcVc=
github.com/cloudfoundry/gosigar v1.3.6/go.mod h1:lNWstu5g5gw59O09Y+wsMNFzBSnU8a0u+Sfx4dq360E=
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
Expand Down
47 changes: 43 additions & 4 deletions client/http/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"fmt"
"net/url"
"time"

"github.com/pingcap/kvproto/pkg/metapb"
)

// The following constants are the paths of PD HTTP APIs.
Expand All @@ -38,11 +40,17 @@ const (
store = "/pd/api/v1/store"
Stores = "/pd/api/v1/stores"
StatsRegion = "/pd/api/v1/stats/region"
LeaderPrefix = "/pd/api/v1/leader"
leaderTransferPrefix = "/pd/api/v1/leader/transfer"
Cluster = "/pd/api/v1/cluster"
Health = "/pd/api/v1/health"
Members = "/pd/api/v1/members"
// Config
Config = "/pd/api/v1/config"
ClusterVersion = "/pd/api/v1/config/cluster-version"
ScheduleConfig = "/pd/api/v1/config/schedule"
ReplicateConfig = "/pd/api/v1/config/replicate"
Config = "/pd/api/v1/config"
ClusterVersion = "/pd/api/v1/config/cluster-version"
ScheduleConfigPrefix = "/pd/api/v1/config/schedule"
ReplicateConfig = "/pd/api/v1/config/replicate"
evictLeaderSchedulerConfigPrefix = "/pd/api/v1/scheduler-config/evict-leader-scheduler/list"
// Rule
PlacementRule = "/pd/api/v1/config/rule"
PlacementRules = "/pd/api/v1/config/rules"
Expand Down Expand Up @@ -72,8 +80,24 @@ const (
MinResolvedTSPrefix = "/pd/api/v1/min-resolved-ts"
Status = "/pd/api/v1/status"
Version = "/pd/api/v1/version"
autoscalingPrefix = "autoscaling"
)

// TransferLeader transfers leader from a source store to a target store.
func TransferLeader(memberName string) string {
return fmt.Sprintf("%s/%s", leaderTransferPrefix, memberName)
}

// MembersByName returns the path of PD HTTP API to get member by name.
func MembersByName(name string) string {
return fmt.Sprintf("%s/name/%s", Members, name)
}

// MembersByID returns the path of PD HTTP API to get member by ID.
func MembersByID(id uint64) string {
return fmt.Sprintf("%s/id/%d", Members, id)
}

// RegionByID returns the path of PD HTTP API to get region by ID.
func RegionByID(regionID uint64) string {
return fmt.Sprintf("%s/%d", RegionByIDPrefix, regionID)
Expand Down Expand Up @@ -114,6 +138,11 @@ func RegionStatsByKeyRange(keyRange *KeyRange, onlyCount bool) string {
StatsRegion, startKeyStr, endKeyStr)
}

// StoresByState returns the store API with store ID parameter.
func StoresByState(state metapb.StoreState) string {
return fmt.Sprintf("%s/?state=%d", store, state)
}

// StoreByID returns the store API with store ID parameter.
func StoreByID(id uint64) string {
return fmt.Sprintf("%s/%d", store, id)
Expand All @@ -124,6 +153,11 @@ func StoreLabelByID(id uint64) string {
return fmt.Sprintf("%s/%d/label", store, id)
}

// StoreStateByID returns the store API with store ID parameter.
func StoreStateByID(id uint64, state string) string {
return fmt.Sprintf("%s/%d/state?state=%s", store, id, state)
}

// ConfigWithTTLSeconds returns the config API with the TTL seconds parameter.
func ConfigWithTTLSeconds(ttlSeconds float64) string {
return fmt.Sprintf("%s?ttlSecond=%.0f", Config, ttlSeconds)
Expand Down Expand Up @@ -159,6 +193,11 @@ func SchedulerByName(name string) string {
return fmt.Sprintf("%s/%s", Schedulers, name)
}

// DeleteSchedulerByNameWithStoreID returns the scheduler API with the given scheduler name.
func DeleteSchedulerByNameWithStoreID(name string, storeID uint64) string {
return fmt.Sprintf("%s/%s-%d", Schedulers, name, storeID)
}

// ScatterRangeSchedulerWithName returns the scatter range scheduler API with name parameter.
func ScatterRangeSchedulerWithName(name string) string {
return fmt.Sprintf("%s%s", scatterRangeScheduler, name)
Expand Down
Loading