From 1b8629904da2682af713b38d285985dddc215931 Mon Sep 17 00:00:00 2001 From: ShuNing Date: Wed, 16 Nov 2022 17:27:35 +0800 Subject: [PATCH 1/6] resource_manager: basic implement about manage resource group Signed-off-by: nolouch --- cmd/pd-server/main.go | 4 + go.mod | 27 +- go.sum | 43 +-- pkg/{msc => mcs}/docs.go | 4 +- pkg/{msc => mcs}/registry/registry.go | 2 + .../resource_manager/server/apis/v1/api.go | 160 ++++++++++ .../resource_manager/server/grpc_service.go | 130 ++++++++ .../server/install/install.go | 32 ++ pkg/mcs/resource_manager/server/manager.go | 143 +++++++++ pkg/mcs/resource_manager/server/metrics.go | 17 ++ .../resource_manager/server/token_bukets.go | 63 ++++ pkg/mcs/resource_manager/server/types.go | 149 ++++++++++ pkg/storage/endpoint/key_path.go | 5 + pkg/storage/endpoint/resource_group.go | 39 +++ server/server.go | 3 +- server/storage/storage.go | 1 + tests/client/go.mod | 14 +- tests/client/go.sum | 28 +- .../resource_manager/resource_manager_test.go | 279 ++++++++++++++++++ tests/registry/registry_test.go | 2 +- 20 files changed, 1092 insertions(+), 53 deletions(-) rename pkg/{msc => mcs}/docs.go (89%) rename pkg/{msc => mcs}/registry/registry.go (98%) create mode 100644 pkg/mcs/resource_manager/server/apis/v1/api.go create mode 100644 pkg/mcs/resource_manager/server/grpc_service.go create mode 100644 pkg/mcs/resource_manager/server/install/install.go create mode 100644 pkg/mcs/resource_manager/server/manager.go create mode 100644 pkg/mcs/resource_manager/server/metrics.go create mode 100644 pkg/mcs/resource_manager/server/token_bukets.go create mode 100644 pkg/mcs/resource_manager/server/types.go create mode 100644 pkg/storage/endpoint/resource_group.go create mode 100644 tests/msc/resource_manager/resource_manager_test.go diff --git a/cmd/pd-server/main.go b/cmd/pd-server/main.go index 20457cac28a..0f39e20243c 100644 --- a/cmd/pd-server/main.go +++ b/cmd/pd-server/main.go @@ -39,6 +39,10 @@ import ( // Register schedulers. _ "github.com/tikv/pd/server/schedulers" + + // Register Service + _ "github.com/tikv/pd/pkg/mcs/registry" + _ "github.com/tikv/pd/pkg/mcs/resource_manager/server/install" ) func main() { diff --git a/go.mod b/go.mod index 29286e152d8..dfc2ae402a9 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( github.com/sasha-s/go-deadlock v0.2.0 github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.8.0 github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba github.com/swaggo/swag v1.8.3 github.com/syndtr/goleveldb v1.0.1-0.20190318030020-c3a204f8e965 @@ -50,6 +50,11 @@ require ( gotest.tools/gotestsum v1.7.0 ) +require ( + github.com/google/go-cmp v0.5.8 // indirect + github.com/onsi/gomega v1.20.1 // indirect +) + require ( github.com/KyleBanks/depth v1.2.1 // indirect github.com/Masterminds/semver v1.5.0 // indirect @@ -74,7 +79,7 @@ require ( github.com/fogleman/gg v1.3.0 // indirect github.com/fsnotify/fsnotify v1.4.9 // indirect github.com/ghodss/yaml v1.0.0 // indirect - github.com/gin-contrib/gzip v0.0.1 // indirect + github.com/gin-contrib/gzip v0.0.1 github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect @@ -89,11 +94,11 @@ require ( github.com/goccy/go-graphviz v0.0.9 // indirect github.com/golang-jwt/jwt v3.2.1+incompatible // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect - github.com/golang/protobuf v1.5.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/pprof v0.0.0-20211122183932-1daafda22083 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect - github.com/google/uuid v1.0.0 // indirect + github.com/google/uuid v1.1.2 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect github.com/grpc-ecosystem/grpc-gateway v1.12.1 // indirect @@ -128,7 +133,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect github.com/prometheus/procfs v0.0.3 // indirect - github.com/rs/cors v1.7.0 // indirect + github.com/rs/cors v1.7.0 github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 // indirect github.com/shirou/gopsutil v3.21.3+incompatible // indirect @@ -136,7 +141,7 @@ require ( github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/sirupsen/logrus v1.4.2 // indirect github.com/soheilhy/cmux v0.1.4 // indirect - github.com/stretchr/objx v0.2.0 // indirect + github.com/stretchr/objx v0.4.0 // indirect github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 // indirect github.com/thoas/go-funk v0.8.0 // indirect github.com/tidwall/gjson v1.9.3 // indirect @@ -158,10 +163,10 @@ require ( golang.org/x/exp v0.0.0-20220321173239-a90fa8a75705 golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect - golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/appengine v1.4.0 // indirect @@ -169,15 +174,17 @@ require ( google.golang.org/protobuf v1.28.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/mysql v1.0.6 // indirect gorm.io/driver/sqlite v1.1.4 // indirect gorm.io/gorm v1.21.9 // indirect moul.io/zapgorm2 v1.1.0 // indirect - sigs.k8s.io/yaml v1.1.0 // indirect + sigs.k8s.io/yaml v1.2.0 // indirect ) // When you modify PD cooperatively with kvproto, this will be useful to submit the PR to PD and the PR to // kvproto at the same time. You can run `go mod tidy` to make it replaced with go-mod style specification. // After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`. // replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch + +replace github.com/pingcap/kvproto => github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46 diff --git a/go.sum b/go.sum index 8f923489b9e..6c6405f32f0 100644 --- a/go.sum +++ b/go.sum @@ -164,7 +164,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IPQQ= github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v0.0.0-20180717141946-636bf0302bc9/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -179,14 +178,14 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v0.0.0-20180814211427-aa810b61a9c7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -196,16 +195,18 @@ github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl76 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20211122183932-1daafda22083 h1:c8EUapQFi+kjzedr4c6WqbwMdmB95+oDBWZ5XFHFYxY= github.com/google/pprof v0.0.0-20211122183932-1daafda22083/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= -github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -320,6 +321,8 @@ github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/R github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46 h1:SqblNt1oTZg6N+g7ltm++c4D253bv08h1OeZ7BlvhLU= +github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= @@ -329,8 +332,9 @@ github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FW github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= +github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= @@ -349,9 +353,6 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce h1:Y1kCxlCtlPTMtVcOkjUcuQKh+YrluSo7+7YMCQSzy30= github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce/go.mod h1:w4PEZ5y16LeofeeGwdgZB4ddv9bLyDuIX+ljstgKZyk= -github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= -github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1 h1:iJXUNA0LoOYuuMJ6U0tJGg2gCo/8xGZVhKLvuUWNjzw= -github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw= @@ -424,8 +425,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -433,8 +434,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM= github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= @@ -575,8 +577,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -615,8 +617,8 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -668,11 +670,9 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c h1:hrpEMCZ2O7DR5gC1n2AJGVhrwiEjOi35+jxtIuZpTMo= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/grpc v0.0.0-20180607172857-7a6a684ca69e/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= @@ -681,6 +681,7 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= @@ -708,8 +709,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.0.6 h1:mA0XRPjIKi4bkE9nv+NKs6qj6QWOchqUSdWOcpd3x1E= gorm.io/driver/mysql v1.0.6/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYnU= gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM= @@ -727,5 +729,6 @@ honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= moul.io/zapgorm2 v1.1.0 h1:qwAlMBYf+qJkJ7PAzJl4oCe6eS6QGiKAXUPeis0+RBE= moul.io/zapgorm2 v1.1.0/go.mod h1:emRfKjNqSzVj5lcgasBdovIXY1jSOwFz2GQZn1Rddks= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/pkg/msc/docs.go b/pkg/mcs/docs.go similarity index 89% rename from pkg/msc/docs.go rename to pkg/mcs/docs.go index 3af6a2b241f..e345fecc423 100644 --- a/pkg/msc/docs.go +++ b/pkg/mcs/docs.go @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package mcs used to implement the core logic of the external services which rely on the PD banckend provider. -package mcs +// Package msc used to implement the core logic of the external services which rely on the PD banckend provider. +package msc diff --git a/pkg/msc/registry/registry.go b/pkg/mcs/registry/registry.go similarity index 98% rename from pkg/msc/registry/registry.go rename to pkg/mcs/registry/registry.go index e8f74d56973..aadd84853a9 100644 --- a/pkg/msc/registry/registry.go +++ b/pkg/mcs/registry/registry.go @@ -63,6 +63,7 @@ func (r *ServiceRegistry) InstallAllGRPCServices(srv *server.Server, g *grpc.Ser continue } l := builder(srv) + r.services[name] = l l.RegisterGRPCService(g) log.Info("gRPC service register success", zap.String("service-name", name)) } @@ -77,6 +78,7 @@ func (r *ServiceRegistry) InstallAllRESTHandler(srv *server.Server, h map[string continue } l := builder(srv) + r.services[name] = l l.RegisterRESTHandler(h) log.Info("restful API service register success", zap.String("service-name", name)) } diff --git a/pkg/mcs/resource_manager/server/apis/v1/api.go b/pkg/mcs/resource_manager/server/apis/v1/api.go new file mode 100644 index 00000000000..60f626f594e --- /dev/null +++ b/pkg/mcs/resource_manager/server/apis/v1/api.go @@ -0,0 +1,160 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package apis + +import ( + "errors" + "net/http" + + "github.com/gin-contrib/gzip" + "github.com/gin-gonic/gin" + "github.com/pingcap/errcode" + cors "github.com/rs/cors/wrapper/gin" + rmserver "github.com/tikv/pd/pkg/mcs/resource_manager/server" + "github.com/tikv/pd/server" +) + +// APIPathPrefix is the prefix of the API path. +const APIPathPrefix = "/resource-manager/api/v1/" + +var ( + apiServiceGroup = server.APIServiceGroup{ + Name: "resource-manager", + Version: "v1", + IsCore: false, + PathPrefix: APIPathPrefix, + } +) + +func init() { + rmserver.SetUpRestHandler = func(srv *rmserver.Service) (http.Handler, server.APIServiceGroup) { + s := NewService(srv) + return s.handler(), apiServiceGroup + } +} + +// Service is the resource group service. +type Service struct { + apiHandlerEngine *gin.Engine + baseEndpoint *gin.RouterGroup + + manager *rmserver.Manager +} + +// NewService returns a new Service. +func NewService(srv *rmserver.Service) *Service { + apiHandlerEngine := gin.New() + apiHandlerEngine.Use(gin.Recovery()) + apiHandlerEngine.Use(cors.AllowAll()) + apiHandlerEngine.Use(gzip.Gzip(gzip.DefaultCompression)) + endpoint := apiHandlerEngine.Group(APIPathPrefix) + manager := srv.GetManager() + + s := &Service{ + manager: manager, + apiHandlerEngine: apiHandlerEngine, + baseEndpoint: endpoint, + } + s.RegisterRouter() + return s +} + +// RegisterRouter registers the router of the service. +func (s *Service) RegisterRouter() { + configEndpoint := s.baseEndpoint.Group("/config") + configEndpoint.POST("/group", s.postResourceGroup) + configEndpoint.PUT("group", s.putResourceGroup) + configEndpoint.GET("/group/:name", s.getResourceGroup) + configEndpoint.GET("/groups", s.getResourceGroupList) + configEndpoint.DELETE("/group/:name", s.deleteResourceGroup) +} + +func (s *Service) handler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + s.apiHandlerEngine.ServeHTTP(w, r) + }) +} + +// @Summary add a resource group +// @Param address path string true "ip:port" +// @Success 200 "added successfully" +// @Failure 401 {object} rest.ErrorResponse +// @Router /config/group/ [POST] +func (s *Service) postResourceGroup(c *gin.Context) { + var group rmserver.ResourceGroup + if err := c.ShouldBindJSON(&group); err != nil { + c.JSON(http.StatusBadRequest, err) + return + } + if err := s.manager.AddResourceGroup(&group); err != nil { + c.JSON(http.StatusInternalServerError, err) + return + } + c.JSON(http.StatusOK, "Success!") +} + +// @Summary add a resource group +// @Param address path string true "ip:port" +// @Success 200 "added successfully" +// @Failure 401 {object} rest.ErrorResponse +// @Router /config/group/ [PUT] +func (s *Service) putResourceGroup(c *gin.Context) { + var group rmserver.ResourceGroup + if err := c.ShouldBindJSON(&group); err != nil { + c.JSON(http.StatusBadRequest, err) + return + } + if err := s.manager.ModifyResourceGroup(&group); err != nil { + c.JSON(http.StatusInternalServerError, err) + return + } + c.JSON(http.StatusOK, "Success!") +} + +// @ID getResourceGroup +// @Summary Get current alert count from AlertManager +// @Success 200 {object} int +// @Param name string true "groupName" +// @Router /config/group/{name} [GET] +// @Failure 404 {object} rest.ErrorResponse +func (s *Service) getResourceGroup(c *gin.Context) { + group := s.manager.GetResourceGroup(c.Param("name")) + if group == nil { + c.JSON(http.StatusNotFound, errcode.NewNotFoundErr(errors.New("resource group not found"))) + } + c.JSON(http.StatusOK, group) +} + +// @ID getResourceGroupList +// @Summary Get current alert count from AlertManager +// @Success 200 {array} ResourceGroup +// @Router /config/groups [GET] +func (s *Service) getResourceGroupList(c *gin.Context) { + groups := s.manager.GetResourceGroupList() + c.JSON(http.StatusOK, groups) +} + +// @ID getResourceGroup +// @Summary Get current alert count from AlertManager +// @Success 200 "deleted successfully" +// @Param name string true "groupName" +// @Router /config/group/{name} [DELETE] +// @Failure 404 {object} error +func (s *Service) deleteResourceGroup(c *gin.Context) { + if err := s.manager.DeleteResourceGroup(c.Param("name")); err != nil { + c.JSON(http.StatusNotFound, err) + } + c.JSON(http.StatusOK, "Success!") +} diff --git a/pkg/mcs/resource_manager/server/grpc_service.go b/pkg/mcs/resource_manager/server/grpc_service.go new file mode 100644 index 00000000000..817a55951bf --- /dev/null +++ b/pkg/mcs/resource_manager/server/grpc_service.go @@ -0,0 +1,130 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package server + +import ( + "context" + "net/http" + + "github.com/pingcap/errors" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" + "github.com/tikv/pd/pkg/mcs/registry" + "github.com/tikv/pd/server" + "google.golang.org/grpc" +) + +var _ rmpb.ResourceManagerServer = (*Service)(nil) + +// SetUpRestHandler is a hook to sets up the REST service. +var SetUpRestHandler = func(srv *Service) (http.Handler, server.APIServiceGroup) { + return dummyRestService{}, server.APIServiceGroup{} +} + +type dummyRestService struct{} + +func (d dummyRestService) ServeHTTP(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotImplemented) + w.Write([]byte("not implemented")) +} + +// Service is the gRPC service for resource manager. +type Service struct { + ctx context.Context + manager *Manager + // settings +} + +// NewService creates a new resource manager service. +func NewService(svr *server.Server) registry.RegistrableService { + manager := NewManager(svr) + + return &Service{ + ctx: svr.Context(), + manager: manager, + } +} + +// RegisterGRPCService registers the service to gRPC server. +func (s *Service) RegisterGRPCService(g *grpc.Server) { + rmpb.RegisterResourceManagerServer(g, s) +} + +// RegisterRESTHandler registers the service to REST server. +func (s *Service) RegisterRESTHandler(userDefineHandlers map[string]http.Handler) { + hander, group := SetUpRestHandler(s) + server.RegisterUserDefinedHandlers(userDefineHandlers, &group, hander) +} + +// GetManager returns the resource manager. +func (s *Service) GetManager() *Manager { + return s.manager +} + +// GetResourceGroup implements ResourceManagerServer.GetResourceGroup. +func (s *Service) GetResourceGroup(ctx context.Context, req *rmpb.GetResourceGroupRequest) (*rmpb.GetResourceGroupResponse, error) { + rg := s.manager.GetResourceGroup(req.ResourceGroupName) + if rg == nil { + return nil, errors.New("resource group not found") + } + return &rmpb.GetResourceGroupResponse{ + Group: rg.IntoProtoResourceGroup(), + }, nil +} + +// ListResourceGroups implements ResourceManagerServer.ListResourceGroups. +func (s *Service) ListResourceGroups(ctx context.Context, req *rmpb.ListResourceGroupsRequest) (*rmpb.ListResourceGroupsResponse, error) { + groups := s.manager.GetResourceGroupList() + resp := &rmpb.ListResourceGroupsResponse{ + Groups: make([]*rmpb.ResourceGroup, 0, len(groups)), + } + for _, group := range groups { + resp.Groups = append(resp.Groups, group.IntoProtoResourceGroup()) + } + return resp, nil +} + +// AddResourceGroup implements ResourceManagerServer.AddResourceGroup. +func (s *Service) AddResourceGroup(ctx context.Context, req *rmpb.PutResourceGroupRequest) (*rmpb.PutResourceGroupResponse, error) { + rg := FromProtoResourceGroup(req.GetGroup()) + err := s.manager.AddResourceGroup(rg) + if err != nil { + return nil, err + } + return &rmpb.PutResourceGroupResponse{ResponseBody: "Success!"}, nil +} + +// DeleteResourceGroup implements ResourceManagerServer.DeleteResourceGroup. +func (s *Service) DeleteResourceGroup(ctx context.Context, req *rmpb.DeleteResourceGroupRequest) (*rmpb.DeleteResourceGroupResponse, error) { + err := s.manager.DeleteResourceGroup(req.ResourceGroupName) + if err != nil { + return nil, err + } + return &rmpb.DeleteResourceGroupResponse{ResponseBody: "Success!"}, nil +} + +// ModifyResourceGroup implements ResourceManagerServer.ModifyResourceGroup. +func (s *Service) ModifyResourceGroup(ctx context.Context, req *rmpb.PutResourceGroupRequest) (*rmpb.PutResourceGroupResponse, error) { + rg := FromProtoResourceGroup(req.GetGroup()) + err := s.manager.ModifyResourceGroup(rg) + if err != nil { + return nil, err + } + return &rmpb.PutResourceGroupResponse{ResponseBody: "Success!"}, nil +} + +// AcquireTokenBuckets implements ResourceManagerServer.AcquireTokenBuckets. +func (s *Service) AcquireTokenBuckets(stream rmpb.ResourceManager_AcquireTokenBucketsServer) error { + return errors.New("not implemented") +} diff --git a/pkg/mcs/resource_manager/server/install/install.go b/pkg/mcs/resource_manager/server/install/install.go new file mode 100644 index 00000000000..209a504cc4e --- /dev/null +++ b/pkg/mcs/resource_manager/server/install/install.go @@ -0,0 +1,32 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package install + +import ( + "github.com/tikv/pd/pkg/mcs/registry" + rm_server "github.com/tikv/pd/pkg/mcs/resource_manager/server" + + // init API gorup + _ "github.com/tikv/pd/pkg/mcs/resource_manager/server/apis/v1" +) + +func init() { + Install(registry.ServerServiceRegistry) +} + +// Install registers the API group and grpc service. +func Install(register *registry.ServiceRegistry) { + register.RegisterService("ResourceManager", rm_server.NewService) +} diff --git a/pkg/mcs/resource_manager/server/manager.go b/pkg/mcs/resource_manager/server/manager.go new file mode 100644 index 00000000000..9b9dc6a1d7a --- /dev/null +++ b/pkg/mcs/resource_manager/server/manager.go @@ -0,0 +1,143 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package server + +import ( + "encoding/json" + "sort" + "sync" + + "github.com/pingcap/errors" + "github.com/tikv/pd/server" + "github.com/tikv/pd/server/core" + "github.com/tikv/pd/server/storage" +) + +// Manager is the manager of resource group. +type Manager struct { + sync.RWMutex + groups map[string]*ResourceGroup + storage func() storage.Storage + // TODO: dispatch resource group to storage node + getStores func() ([]*core.StoreInfo, error) +} + +// NewManager returns a new Manager. +func NewManager(srv *server.Server) *Manager { + getStores := func() ([]*core.StoreInfo, error) { + rc := srv.GetRaftCluster() + if rc == nil { + return nil, errors.New("RaftCluster is nil") + } + return rc.GetStores(), nil + } + + m := &Manager{ + groups: make(map[string]*ResourceGroup), + storage: srv.GetStorage, + getStores: getStores, + } + srv.AddStartCallback(m.Init) + return m +} + +// Init initializes the resource group manager. +func (m *Manager) Init() { + handler := func(k, v string) { + var group ResourceGroup + if err := json.Unmarshal([]byte(v), &group); err != nil { + panic(err) + } + m.groups[group.Name] = &group + } + m.storage().LoadResourceGroups(handler) +} + +// AddResourceGroup puts a resource group. +func (m *Manager) AddResourceGroup(group *ResourceGroup) error { + m.RLock() + _, ok := m.groups[group.Name] + m.RUnlock() + if ok { + return errors.New("this group already exists") + } + err := group.CheckAndInit() + if err != nil { + return err + } + if err := m.storage().SaveResourceGroup(group.Name, group); err != nil { + return err + } + m.Lock() + m.groups[group.Name] = group + m.Unlock() + return nil +} + +// ModifyResourceGroup modifies a exists resource group. +func (m *Manager) ModifyResourceGroup(group *ResourceGroup) error { + m.RLock() + _, ok := m.groups[group.Name] + m.RUnlock() + if !ok { + return errors.New("not exists the group") + } + err := group.CheckAndInit() + if err != nil { + return err + } + if err := m.storage().SaveResourceGroup(group.Name, group); err != nil { + return err + } + m.Lock() + m.groups[group.Name] = group + m.Unlock() + return nil +} + +// DeleteResourceGroup deletes a resource group. +func (m *Manager) DeleteResourceGroup(name string) error { + if err := m.storage().DeleteResourceGroup(name); err != nil { + return err + } + m.Lock() + delete(m.groups, name) + m.Unlock() + return nil +} + +// GetResourceGroup returns a resource group. +func (m *Manager) GetResourceGroup(name string) *ResourceGroup { + m.RLock() + defer m.RUnlock() + if group, ok := m.groups[name]; ok { + return group + } + return nil +} + +// GetResourceGroupList returns a resource group list. +func (m *Manager) GetResourceGroupList() []*ResourceGroup { + m.RLock() + res := make([]*ResourceGroup, 0, len(m.groups)) + for _, group := range m.groups { + res = append(res, group) + } + m.RUnlock() + sort.Slice(res, func(i, j int) bool { + return res[i].Name < res[j].Name + }) + return res +} diff --git a/pkg/mcs/resource_manager/server/metrics.go b/pkg/mcs/resource_manager/server/metrics.go new file mode 100644 index 00000000000..24bb8431587 --- /dev/null +++ b/pkg/mcs/resource_manager/server/metrics.go @@ -0,0 +1,17 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package server + +// TODO: add metrics diff --git a/pkg/mcs/resource_manager/server/token_bukets.go b/pkg/mcs/resource_manager/server/token_bukets.go new file mode 100644 index 00000000000..083949aef0b --- /dev/null +++ b/pkg/mcs/resource_manager/server/token_bukets.go @@ -0,0 +1,63 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS,g +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package server + +import ( + "time" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" +) + +const defaultRefillRate = 10000 + +const defaultInitialTokens = 10 * 10000 + +// GroupTokenBucket is a token bucket for a resource group. +type GroupTokenBucket struct { + *rmpb.TokenBucket `json:"token_bucket,omitempty"` + Consumption *rmpb.TokenBucketsRequest `json:"consumption,omitempty"` + LastUpdate *time.Time `json:"last_update,omitempty"` + Initialized bool `json:"initialized"` +} + +// Update updates the token bucket. +func (t *GroupTokenBucket) Update(now time.Time) { + if !t.Initialized { + t.Settings.Fillrate = defaultRefillRate + t.Tokens = defaultInitialTokens + t.LastUpdate = &now + t.Initialized = true + return + } + + delta := now.Sub(*t.LastUpdate) + if delta > 0 { + t.Tokens += float64(t.Settings.Fillrate) * delta.Seconds() + t.LastUpdate = &now + } +} + +// GetTokenBucket returns the token bucket. +func (t *GroupTokenBucket) GetTokenBucket() *rmpb.TokenBucket { + return t.TokenBucket +} + +// Request requests tokens from the token bucket. +func (t *GroupTokenBucket) Request( + neededTokens float64, targetPeriodMs uint64, +) *rmpb.TokenBucket { + // TODO: Implement the token bucket algorithm. + return nil +} diff --git a/pkg/mcs/resource_manager/server/types.go b/pkg/mcs/resource_manager/server/types.go new file mode 100644 index 00000000000..5d1f201c255 --- /dev/null +++ b/pkg/mcs/resource_manager/server/types.go @@ -0,0 +1,149 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package server provides a set of struct definitions for the resource group, can be imported. +package server + +import ( + "encoding/json" + "fmt" + + "github.com/pingcap/errors" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" +) + +// ResourceGroup is the definition of a resource group, for REST API. +type ResourceGroup struct { + Name string `json:"name"` + Mode rmpb.GroupMode `json:"mode"` + // RU settings + RUSettings *RequestUnitSettings `json:"r_u_settings,omitempty"` + // Native resource settings + ResourceSettings *NativeResourceSettings `json:"resource_settings,omitempty"` +} + +// RequestUnitSettings is the definition of the RU settings. +type RequestUnitSettings struct { + RRU GroupTokenBucket `json:"rru,omitempty"` + WRU GroupTokenBucket `json:"wru,omitempty"` +} + +// NativeResourceSettings is the definition of the native resource settings. +type NativeResourceSettings struct { + CPU GroupTokenBucket `json:"cpu,omitempty"` + IOReadBandwidth GroupTokenBucket `json:"io_read_bandwidth,omitempty"` + IOWriteBandwidth GroupTokenBucket `json:"io_write_bandwidth,omitempty"` +} + +// CheckAndInit checks the validity of the resource group and initializes the default values if not setting. +func (rg *ResourceGroup) CheckAndInit() error { + res, _ := json.Marshal(rg) + fmt.Println("CheckAndInit", string(res)) + if len(rg.Name) == 0 || len(rg.Name) > 32 { + return errors.New("invalid resource group name, the length should be in [1,32]") + } + if rg.Mode != rmpb.GroupMode_RUMode && rg.Mode != rmpb.GroupMode_NativeMode { + return errors.New("invalid resource group mode") + } + if rg.Mode == rmpb.GroupMode_RUMode { + if rg.RUSettings == nil { + rg.RUSettings = &RequestUnitSettings{} + } + if rg.ResourceSettings != nil { + return errors.New("invalid resource group settings, RU mode should not set resource settings") + } + } + if rg.Mode == rmpb.GroupMode_NativeMode { + if rg.ResourceSettings == nil { + rg.ResourceSettings = &NativeResourceSettings{} + } + if rg.RUSettings != nil { + return errors.New("invalid resource group settings, native mode should not set RU settings") + } + } + return nil +} + +// FromProtoResourceGroup converts a rmpb.ResourceGroup to a ResourceGroup. +func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup { + var ( + resourceSettings *NativeResourceSettings + ruSettings *RequestUnitSettings + ) + + if settings := group.GetSettings().GetResourceSettings(); settings != nil { + resourceSettings = &NativeResourceSettings{ + CPU: GroupTokenBucket{ + TokenBucket: settings.GetCpu(), + }, + IOReadBandwidth: GroupTokenBucket{ + TokenBucket: settings.GetIoRead(), + }, + IOWriteBandwidth: GroupTokenBucket{ + TokenBucket: settings.GetIoWrite(), + }, + } + } + + if settings := group.GetSettings().GetRUSettings(); settings != nil { + ruSettings = &RequestUnitSettings{ + RRU: GroupTokenBucket{ + TokenBucket: settings.GetRRU(), + }, + WRU: GroupTokenBucket{ + TokenBucket: settings.GetWRU(), + }, + } + } + + rg := &ResourceGroup{ + Name: group.ResourceGroupName, + Mode: group.Settings.Mode, + RUSettings: ruSettings, + ResourceSettings: resourceSettings, + } + return rg +} + +// IntoProtoResourceGroup converts a ResourceGroup to a rmpb.ResourceGroup. +func (rg *ResourceGroup) IntoProtoResourceGroup() *rmpb.ResourceGroup { + switch rg.Mode { + case rmpb.GroupMode_RUMode: // RU mode + group := &rmpb.ResourceGroup{ + ResourceGroupName: rg.Name, + Settings: &rmpb.GroupSettings{ + Mode: rmpb.GroupMode_RUMode, + RUSettings: &rmpb.GroupRequestUnitSettings{ + RRU: rg.RUSettings.RRU.GetTokenBucket(), + WRU: rg.RUSettings.WRU.GetTokenBucket(), + }, + }, + } + return group + case rmpb.GroupMode_NativeMode: // Native mode + group := &rmpb.ResourceGroup{ + ResourceGroupName: rg.Name, + Settings: &rmpb.GroupSettings{ + Mode: rmpb.GroupMode_NativeMode, + ResourceSettings: &rmpb.GroupResourceSettings{ + Cpu: rg.ResourceSettings.CPU.GetTokenBucket(), + IoRead: rg.ResourceSettings.IOReadBandwidth.GetTokenBucket(), + IoWrite: rg.ResourceSettings.IOWriteBandwidth.GetTokenBucket(), + }, + }, + } + return group + } + return nil +} diff --git a/pkg/storage/endpoint/key_path.go b/pkg/storage/endpoint/key_path.go index 3d73b3a5d4f..2bb4c7e6298 100644 --- a/pkg/storage/endpoint/key_path.go +++ b/pkg/storage/endpoint/key_path.go @@ -28,6 +28,7 @@ const ( schedulePath = "schedule" gcPath = "gc" rulesPath = "rules" + resourceGroupPath = "resource_group" ruleGroupPath = "rule_group" regionLabelPath = "region_label" replicationPath = "replication_mode" @@ -104,6 +105,10 @@ func RegionPath(regionID uint64) string { return buf.String() } +func resourceGroupKeyPath(groupName string) string { + return path.Join(resourceGroupPath, groupName) +} + func ruleKeyPath(ruleKey string) string { return path.Join(rulesPath, ruleKey) } diff --git a/pkg/storage/endpoint/resource_group.go b/pkg/storage/endpoint/resource_group.go new file mode 100644 index 00000000000..4fc169973ab --- /dev/null +++ b/pkg/storage/endpoint/resource_group.go @@ -0,0 +1,39 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package endpoint + +// ResourceGroupStorage defines the storage operations on the rule. +type ResourceGroupStorage interface { + LoadResourceGroups(f func(k, v string)) error + SaveResourceGroup(groupName string, groupPayload interface{}) error + DeleteResourceGroup(groupName string) error +} + +var _ ResourceGroupStorage = (*StorageEndpoint)(nil) + +// SaveResourceGroup stores a resource group to storage. +func (se *StorageEndpoint) SaveResourceGroup(groupName string, payload interface{}) error { + return se.saveJSON(resourceGroupPath, groupName, payload) +} + +// DeleteResourceGroup removes a resource group from storage. +func (se *StorageEndpoint) DeleteResourceGroup(groupName string) error { + return se.Remove(resourceGroupKeyPath(groupName)) +} + +// LoadResourceGroups loads all resource groups from storage. +func (se *StorageEndpoint) LoadResourceGroups(f func(k, v string)) error { + return se.loadRangeByPrefix(resourceGroupPath+"/", f) +} diff --git a/server/server.go b/server/server.go index f09721b4844..89049b8e25b 100644 --- a/server/server.go +++ b/server/server.go @@ -234,8 +234,9 @@ func CreateServer(ctx context.Context, cfg *config.Config, legacyServiceBuilders keyspacepb.RegisterKeyspaceServer(gs, &KeyspaceServer{GrpcServer: grpcServer}) diagnosticspb.RegisterDiagnosticsServer(gs, s) // Register the micro services GRPC service. - NewServiceregistry().InstallAllGRPCServices(s, gs) + registry.InstallAllGRPCServices(s, gs) } + s.etcdCfg = etcdCfg s.lg = cfg.GetZapLogger() s.logProps = cfg.GetZapLogProperties() diff --git a/server/storage/storage.go b/server/storage/storage.go index 4a4d4c604fa..c3874b92470 100644 --- a/server/storage/storage.go +++ b/server/storage/storage.go @@ -42,6 +42,7 @@ type Storage interface { endpoint.ExternalTSStorage endpoint.KeySpaceGCSafePointStorage endpoint.KeyspaceStorage + endpoint.ResourceGroupStorage } // NewStorageWithMemoryBackend creates a new storage with memory backend. diff --git a/tests/client/go.mod b/tests/client/go.mod index 71ebce787e9..ad4962e28f5 100644 --- a/tests/client/go.mod +++ b/tests/client/go.mod @@ -6,7 +6,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1 - github.com/stretchr/testify v1.7.1 + github.com/stretchr/testify v1.8.0 github.com/tikv/pd v0.0.0-00010101000000-000000000000 github.com/tikv/pd/client v0.0.0-00010101000000-000000000000 go.etcd.io/etcd v0.5.0-alpha.5.0.20220915004622-85b640cee793 @@ -60,7 +60,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/pprof v0.0.0-20211122183932-1daafda22083 // indirect - github.com/google/uuid v1.0.0 // indirect + github.com/google/uuid v1.1.2 // indirect github.com/gorilla/mux v1.7.4 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4 // indirect @@ -109,7 +109,7 @@ require ( github.com/sirupsen/logrus v1.6.0 // indirect github.com/soheilhy/cmux v0.1.4 // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/stretchr/objx v0.2.0 // indirect + github.com/stretchr/objx v0.4.0 // indirect github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 // indirect github.com/swaggo/http-swagger v0.0.0-20200308142732-58ac5e232fba // indirect github.com/swaggo/swag v1.8.3 // indirect @@ -133,10 +133,10 @@ require ( golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/exp v0.0.0-20220321173239-a90fa8a75705 // indirect golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect - golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect + golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect golang.org/x/tools v0.1.10 // indirect @@ -145,12 +145,12 @@ require ( google.golang.org/protobuf v1.28.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/driver/mysql v1.0.6 // indirect gorm.io/driver/sqlite v1.1.4 // indirect gorm.io/gorm v1.21.9 // indirect moul.io/zapgorm2 v1.1.0 // indirect - sigs.k8s.io/yaml v1.1.0 // indirect + sigs.k8s.io/yaml v1.2.0 // indirect ) replace ( diff --git a/tests/client/go.sum b/tests/client/go.sum index d8fa53d0a4a..96adc47ede1 100644 --- a/tests/client/go.sum +++ b/tests/client/go.sum @@ -181,14 +181,15 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20211122183932-1daafda22083 h1:c8EUapQFi+kjzedr4c6WqbwMdmB95+oDBWZ5XFHFYxY= github.com/google/pprof v0.0.0-20211122183932-1daafda22083/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc= github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -294,8 +295,8 @@ github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:v github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= @@ -379,16 +380,17 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14 h1:PyYN9JH5jY9j6av01SpfRMb+1DWg/i3MbGOKPxJ2wjM= github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14/go.mod h1:gxQT6pBGRuIGunNf/+tSOB5OHvguWi8Tbt82WOkf35E= github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI= @@ -520,8 +522,8 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= -golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -563,8 +565,8 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= -golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -658,8 +660,9 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gorm.io/driver/mysql v1.0.6 h1:mA0XRPjIKi4bkE9nv+NKs6qj6QWOchqUSdWOcpd3x1E= gorm.io/driver/mysql v1.0.6/go.mod h1:KdrTanmfLPPyAOeYGyG+UpDys7/7eeWT1zCq+oekYnU= gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM= @@ -672,5 +675,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= moul.io/zapgorm2 v1.1.0 h1:qwAlMBYf+qJkJ7PAzJl4oCe6eS6QGiKAXUPeis0+RBE= moul.io/zapgorm2 v1.1.0/go.mod h1:emRfKjNqSzVj5lcgasBdovIXY1jSOwFz2GQZn1Rddks= -sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= +sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q= +sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/tests/msc/resource_manager/resource_manager_test.go b/tests/msc/resource_manager/resource_manager_test.go new file mode 100644 index 00000000000..05f007d2e59 --- /dev/null +++ b/tests/msc/resource_manager/resource_manager_test.go @@ -0,0 +1,279 @@ +// Copyright 2022 TiKV Project Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package resourcemanager_test + +import ( + "context" + "encoding/json" + "io" + "net/http" + "strings" + "testing" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" + "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/mcs/resource_manager/server" + "github.com/tikv/pd/pkg/utils/testutil" + "github.com/tikv/pd/tests" + "go.uber.org/goleak" + "google.golang.org/grpc" + + // Register Service + _ "github.com/tikv/pd/pkg/mcs/registry" + _ "github.com/tikv/pd/pkg/mcs/resource_manager/server/install" +) + +func TestMain(m *testing.M) { + goleak.VerifyTestMain(m, testutil.LeakOptions...) +} + +func TestBasicReourceGroupCURD(t *testing.T) { + re := require.New(t) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + cluster, err := tests.NewTestCluster(ctx, 1) + defer cluster.Destroy() + re.NoError(err) + + err = cluster.RunInitialServers() + re.NoError(err) + + leaderName := cluster.WaitLeader() + leader := cluster.GetServer(leaderName) + + // Test registered GRPC Service + cc, err := grpc.DialContext(ctx, strings.TrimPrefix(leader.GetAddr(), "http://"), grpc.WithInsecure()) + re.NoError(err) + defer cc.Close() + + grpcclient := rmpb.NewResourceManagerClient(cc) + + testCasesSet1 := []struct { + name string + mode rmpb.GroupMode + addSuccess bool + modifySuccess bool + expectMarshal string + modifySettings func(*rmpb.GroupSettings) + }{ + {"test1", rmpb.GroupMode_RUMode, true, true, + `{"name":"test1","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":10000}},"initialized":false},"wru":{"initialized":false}}}`, + func(gs *rmpb.GroupSettings) { + gs.RUSettings = &rmpb.GroupRequestUnitSettings{ + RRU: &rmpb.TokenBucket{ + Settings: &rmpb.TokenLimitSettings{ + Fillrate: 10000, + }, + }, + } + }, + }, + + {"test2", rmpb.GroupMode_RUMode, true, true, + `{"name":"test2","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":20000}},"initialized":false},"wru":{"initialized":false}}}`, + func(gs *rmpb.GroupSettings) { + gs.RUSettings = &rmpb.GroupRequestUnitSettings{ + RRU: &rmpb.TokenBucket{ + Settings: &rmpb.TokenLimitSettings{ + Fillrate: 20000, + }, + }, + } + }, + }, + {"test2", rmpb.GroupMode_RUMode, false, true, + `{"name":"test2","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":30000}},"initialized":false},"wru":{"initialized":false}}}`, + func(gs *rmpb.GroupSettings) { + gs.RUSettings = &rmpb.GroupRequestUnitSettings{ + RRU: &rmpb.TokenBucket{ + Settings: &rmpb.TokenLimitSettings{ + Fillrate: 30000, + }, + }, + } + }, + }, + {"test3", rmpb.GroupMode_NativeMode, true, false, + `{"name":"test3","mode":1}`, + func(gs *rmpb.GroupSettings) { + gs.RUSettings = &rmpb.GroupRequestUnitSettings{ + RRU: &rmpb.TokenBucket{ + Settings: &rmpb.TokenLimitSettings{ + Fillrate: 10000, + }, + }, + } + }, + }, + {"test3", rmpb.GroupMode_NativeMode, false, true, + `{"name":"test3","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fillrate":10000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`, + func(gs *rmpb.GroupSettings) { + gs.ResourceSettings = &rmpb.GroupResourceSettings{ + Cpu: &rmpb.TokenBucket{ + Settings: &rmpb.TokenLimitSettings{ + Fillrate: 10000, + }, + }, + } + }, + }, + } + + checkErr := func(err error, success bool) { + if success { + re.NoError(err) + } else { + re.Error(err) + } + } + + finalNum := 0 + // Test Resource Group CURD via gRPC + for i, tcase := range testCasesSet1 { + group := &rmpb.ResourceGroup{ + ResourceGroupName: tcase.name, + Settings: &rmpb.GroupSettings{ + Mode: tcase.mode, + }, + } + // Create Resource Group + resp, err := grpcclient.AddResourceGroup(ctx, &rmpb.PutResourceGroupRequest{Group: group}) + checkErr(err, tcase.addSuccess) + if tcase.addSuccess { + finalNum++ + re.Contains(resp.ResponseBody, "Success!") + } + + // Modify Resource Group + tcase.modifySettings(group.Settings) + mresp, err := grpcclient.ModifyResourceGroup(ctx, &rmpb.PutResourceGroupRequest{Group: group}) + checkErr(err, tcase.modifySuccess) + if tcase.modifySuccess { + re.Contains(mresp.ResponseBody, "Success!") + } + + // Get Resource Group + gresp, err := grpcclient.GetResourceGroup(ctx, &rmpb.GetResourceGroupRequest{ResourceGroupName: tcase.name}) + re.NoError(err) + re.Equal(tcase.name, gresp.Group.ResourceGroupName) + if tcase.modifySuccess { + re.Equal(group, gresp.Group) + } + + // Last one, Check list and delete all resource groups + if i == len(testCasesSet1)-1 { + // List Resource Group + lresp, err := grpcclient.ListResourceGroups(ctx, &rmpb.ListResourceGroupsRequest{}) + re.NoError(err) + re.Equal(finalNum, len(lresp.Groups)) + + for _, g := range lresp.Groups { + // Delete Resource Group + dresp, err := grpcclient.DeleteResourceGroup(ctx, &rmpb.DeleteResourceGroupRequest{ResourceGroupName: g.ResourceGroupName}) + re.NoError(err) + re.Contains(dresp.ResponseBody, "Success!") + } + } + } + + // Test Resource Group CURD via HTTP + finalNum = 0 + for i, tcase := range testCasesSet1 { + // Create Resource Group + group := &rmpb.ResourceGroup{ + ResourceGroupName: tcase.name, + Settings: &rmpb.GroupSettings{ + Mode: tcase.mode, + }, + } + createJSON, err := json.Marshal(server.FromProtoResourceGroup(group)) + re.NoError(err) + resp, err := http.Post(leader.GetAddr()+"/resource-manager/api/v1/config/group", "application/json", strings.NewReader(string(createJSON))) + re.NoError(err) + defer resp.Body.Close() + if tcase.addSuccess { + re.Equal(http.StatusOK, resp.StatusCode) + finalNum++ + } else { + re.Equal(http.StatusInternalServerError, resp.StatusCode) + } + + // Modify Resource Group + tcase.modifySettings(group.Settings) + modifyJSON, err := json.Marshal(server.FromProtoResourceGroup(group)) + re.NoError(err) + req, err := http.NewRequest(http.MethodPut, leader.GetAddr()+"/resource-manager/api/v1/config/group", strings.NewReader(string(modifyJSON))) + re.NoError(err) + req.Header.Set("Content-Type", "application/json") + resp, err = http.DefaultClient.Do(req) + re.NoError(err) + defer resp.Body.Close() + if tcase.modifySuccess { + re.Equal(http.StatusOK, resp.StatusCode) + } else { + re.Equal(http.StatusInternalServerError, resp.StatusCode) + } + + // Get Resource Group + resp, err = http.Get(leader.GetAddr() + "/resource-manager/api/v1/config/group/" + tcase.name) + re.NoError(err) + defer resp.Body.Close() + re.Equal(http.StatusOK, resp.StatusCode) + respString, err := io.ReadAll(resp.Body) + re.NoError(err) + re.Contains(string(respString), tcase.name) + if tcase.modifySuccess { + re.Equal(string(respString), tcase.expectMarshal) + } + + // Last one, Check list and delete all resource groups + if i == len(testCasesSet1)-1 { + resp, err := http.Get(leader.GetAddr() + "/resource-manager/api/v1/config/groups") + re.NoError(err) + defer resp.Body.Close() + re.Equal(http.StatusOK, resp.StatusCode) + respString, err := io.ReadAll(resp.Body) + re.NoError(err) + groups := make([]server.ResourceGroup, 0) + json.Unmarshal(respString, &groups) + re.Equal(finalNum, len(groups)) + + // Delete all resource groups + for _, g := range groups { + req, err := http.NewRequest(http.MethodDelete, leader.GetAddr()+"/resource-manager/api/v1/config/group/"+g.Name, nil) + re.NoError(err) + resp, err := http.DefaultClient.Do(req) + re.NoError(err) + defer resp.Body.Close() + re.Equal(http.StatusOK, resp.StatusCode) + respString, err := io.ReadAll(resp.Body) + re.NoError(err) + re.Contains(string(respString), "Success!") + } + + // verify again + resp1, err := http.Get(leader.GetAddr() + "/resource-manager/api/v1/config/groups") + re.NoError(err) + defer resp1.Body.Close() + re.Equal(http.StatusOK, resp1.StatusCode) + respString1, err := io.ReadAll(resp1.Body) + re.NoError(err) + groups1 := make([]server.ResourceGroup, 0) + json.Unmarshal(respString1, &groups1) + re.Equal(0, len(groups1)) + } + } +} diff --git a/tests/registry/registry_test.go b/tests/registry/registry_test.go index 4cc8a57fdf7..66135c03ee7 100644 --- a/tests/registry/registry_test.go +++ b/tests/registry/registry_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/stretchr/testify/require" - "github.com/tikv/pd/pkg/msc/registry" + "github.com/tikv/pd/pkg/mcs/registry" "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/tests" From 400f1efd1c6ca27d400e828f4b3c2e182ac973cc Mon Sep 17 00:00:00 2001 From: nolouch Date: Mon, 19 Dec 2022 17:00:14 +0800 Subject: [PATCH 2/6] address comments Signed-off-by: nolouch --- go.mod | 17 ++++---- go.sum | 42 ++++++++++++++----- .../resource_manager/server/apis/v1/api.go | 24 ++++++----- pkg/mcs/resource_manager/server/manager.go | 2 +- pkg/mcs/resource_manager/server/types.go | 18 ++++++-- tests/client/go.mod | 14 ++++--- tests/client/go.sum | 40 +++++++++++++----- 7 files changed, 107 insertions(+), 50 deletions(-) diff --git a/go.mod b/go.mod index dfc2ae402a9..685a97f2e46 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,8 @@ require ( github.com/coreos/go-semver v0.3.0 github.com/docker/go-units v0.4.0 github.com/elliotchance/pie/v2 v2.1.0 - github.com/gin-gonic/gin v1.7.4 + github.com/gin-contrib/cors v1.4.0 + github.com/gin-gonic/gin v1.8.1 github.com/go-echarts/go-echarts v1.0.0 github.com/gogo/protobuf v1.3.2 github.com/google/btree v1.1.2 @@ -51,8 +52,10 @@ require ( ) require ( + github.com/goccy/go-json v0.9.7 // indirect github.com/google/go-cmp v0.5.8 // indirect github.com/onsi/gomega v1.20.1 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect ) require ( @@ -86,9 +89,9 @@ require ( github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/spec v0.20.4 // indirect github.com/go-openapi/swag v0.19.15 // indirect - github.com/go-playground/locales v0.13.0 // indirect - github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-graphviz v0.0.9 // indirect @@ -113,10 +116,10 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect - github.com/leodido/go-urn v1.2.0 // indirect + github.com/leodido/go-urn v1.2.1 // indirect github.com/mailru/easyjson v0.7.6 // indirect github.com/mattn/go-colorable v0.1.8 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.8 // indirect github.com/mattn/go-sqlite3 v1.14.9 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect @@ -133,7 +136,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect github.com/prometheus/procfs v0.0.3 // indirect - github.com/rs/cors v1.7.0 + github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 // indirect github.com/shirou/gopsutil v3.21.3+incompatible // indirect diff --git a/go.sum b/go.sum index 6c6405f32f0..2eb6a220b1d 100644 --- a/go.sum +++ b/go.sum @@ -110,6 +110,8 @@ github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWo github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= +github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= @@ -119,8 +121,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM= -github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs= github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-echarts/go-echarts v1.0.0 h1:n181E4iXwj4zrU9VYmdM2m8dyhERt2w9k9YhHqdp6A8= @@ -148,13 +150,15 @@ github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyr github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= @@ -163,6 +167,8 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IPQQ= github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -265,14 +271,17 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -287,8 +296,9 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0= @@ -319,7 +329,6 @@ github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjY github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46 h1:SqblNt1oTZg6N+g7ltm++c4D253bv08h1OeZ7BlvhLU= github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= @@ -337,6 +346,8 @@ github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -363,6 +374,7 @@ github.com/pingcap/tidb-dashboard v0.0.0-20221201151320-ea3ee6971f2e h1:FUdoQ6zW github.com/pingcap/tidb-dashboard v0.0.0-20221201151320-ea3ee6971f2e/go.mod h1:NNF1CfnM5TqrLNfzfSal723h2fVQlieyVBBdQBzfPTg= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e h1:FBaTXU8C3xgt/drM58VHxojHo/QoG1oPsgWTGvaSpO4= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -392,6 +404,9 @@ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40T github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= @@ -535,6 +550,7 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -574,6 +590,7 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -615,6 +632,8 @@ golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= @@ -687,8 +706,9 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= diff --git a/pkg/mcs/resource_manager/server/apis/v1/api.go b/pkg/mcs/resource_manager/server/apis/v1/api.go index 60f626f594e..798681cf21f 100644 --- a/pkg/mcs/resource_manager/server/apis/v1/api.go +++ b/pkg/mcs/resource_manager/server/apis/v1/api.go @@ -18,10 +18,10 @@ import ( "errors" "net/http" + "github.com/gin-contrib/cors" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" "github.com/pingcap/errcode" - cors "github.com/rs/cors/wrapper/gin" rmserver "github.com/tikv/pd/pkg/mcs/resource_manager/server" "github.com/tikv/pd/server" ) @@ -57,7 +57,7 @@ type Service struct { func NewService(srv *rmserver.Service) *Service { apiHandlerEngine := gin.New() apiHandlerEngine.Use(gin.Recovery()) - apiHandlerEngine.Use(cors.AllowAll()) + apiHandlerEngine.Use(cors.Default()) apiHandlerEngine.Use(gzip.Gzip(gzip.DefaultCompression)) endpoint := apiHandlerEngine.Group(APIPathPrefix) manager := srv.GetManager() @@ -88,9 +88,10 @@ func (s *Service) handler() http.Handler { } // @Summary add a resource group -// @Param address path string true "ip:port" +// @Param group body of "ResourceGroup", json format. // @Success 200 "added successfully" -// @Failure 401 {object} rest.ErrorResponse +// @Failure 400 {object} error +// @Failure 500 {object} error // @Router /config/group/ [POST] func (s *Service) postResourceGroup(c *gin.Context) { var group rmserver.ResourceGroup @@ -105,10 +106,11 @@ func (s *Service) postResourceGroup(c *gin.Context) { c.JSON(http.StatusOK, "Success!") } -// @Summary add a resource group -// @Param address path string true "ip:port" +// @Summary updates an exists resource group +// @Param group body of "ResourceGroup", json format. // @Success 200 "added successfully" -// @Failure 401 {object} rest.ErrorResponse +// @Failure 400 {object} error +// @Failure 500 {object} error // @Router /config/group/ [PUT] func (s *Service) putResourceGroup(c *gin.Context) { var group rmserver.ResourceGroup @@ -124,11 +126,11 @@ func (s *Service) putResourceGroup(c *gin.Context) { } // @ID getResourceGroup -// @Summary Get current alert count from AlertManager +// @Summary Get resource group by name. // @Success 200 {object} int // @Param name string true "groupName" // @Router /config/group/{name} [GET] -// @Failure 404 {object} rest.ErrorResponse +// @Failure 404 {object} error func (s *Service) getResourceGroup(c *gin.Context) { group := s.manager.GetResourceGroup(c.Param("name")) if group == nil { @@ -138,7 +140,7 @@ func (s *Service) getResourceGroup(c *gin.Context) { } // @ID getResourceGroupList -// @Summary Get current alert count from AlertManager +// @Summary get all resource group with a list. // @Success 200 {array} ResourceGroup // @Router /config/groups [GET] func (s *Service) getResourceGroupList(c *gin.Context) { @@ -147,7 +149,7 @@ func (s *Service) getResourceGroupList(c *gin.Context) { } // @ID getResourceGroup -// @Summary Get current alert count from AlertManager +// @Summary delete resource group by name. // @Success 200 "deleted successfully" // @Param name string true "groupName" // @Router /config/group/{name} [DELETE] diff --git a/pkg/mcs/resource_manager/server/manager.go b/pkg/mcs/resource_manager/server/manager.go index 9b9dc6a1d7a..90994a74dfd 100644 --- a/pkg/mcs/resource_manager/server/manager.go +++ b/pkg/mcs/resource_manager/server/manager.go @@ -133,7 +133,7 @@ func (m *Manager) GetResourceGroupList() []*ResourceGroup { m.RLock() res := make([]*ResourceGroup, 0, len(m.groups)) for _, group := range m.groups { - res = append(res, group) + res = append(res, group.Copy()) } m.RUnlock() sort.Slice(res, func(i, j int) bool { diff --git a/pkg/mcs/resource_manager/server/types.go b/pkg/mcs/resource_manager/server/types.go index 5d1f201c255..2c4df5bd8d2 100644 --- a/pkg/mcs/resource_manager/server/types.go +++ b/pkg/mcs/resource_manager/server/types.go @@ -17,7 +17,6 @@ package server import ( "encoding/json" - "fmt" "github.com/pingcap/errors" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" @@ -46,10 +45,23 @@ type NativeResourceSettings struct { IOWriteBandwidth GroupTokenBucket `json:"io_write_bandwidth,omitempty"` } +// Copy copies the resource group. +func (rg *ResourceGroup) Copy() *ResourceGroup { + // TODO: use a better way to copy + res, err := json.Marshal(rg) + if err != nil { + panic(err) + } + var newRG ResourceGroup + err = json.Unmarshal(res, &newRG) + if err != nil { + panic(err) + } + return &newRG +} + // CheckAndInit checks the validity of the resource group and initializes the default values if not setting. func (rg *ResourceGroup) CheckAndInit() error { - res, _ := json.Marshal(rg) - fmt.Println("CheckAndInit", string(res)) if len(rg.Name) == 0 || len(rg.Name) > 32 { return errors.New("invalid resource group name, the length should be in [1,32]") } diff --git a/tests/client/go.mod b/tests/client/go.mod index ad4962e28f5..8affac4ab78 100644 --- a/tests/client/go.mod +++ b/tests/client/go.mod @@ -42,18 +42,19 @@ require ( github.com/fogleman/gg v1.3.0 // indirect github.com/gin-contrib/gzip v0.0.1 // indirect github.com/gin-contrib/sse v0.1.0 // indirect - github.com/gin-gonic/gin v1.7.4 // indirect + github.com/gin-gonic/gin v1.8.1 // indirect github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/spec v0.20.4 // indirect github.com/go-openapi/swag v0.19.15 // indirect - github.com/go-playground/locales v0.13.0 // indirect - github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-playground/validator/v10 v10.4.1 // indirect + github.com/go-playground/locales v0.14.0 // indirect + github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-playground/validator/v10 v10.10.0 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-graphviz v0.0.9 // indirect + github.com/goccy/go-json v0.9.7 // indirect github.com/golang-jwt/jwt v3.2.1+incompatible // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -77,9 +78,9 @@ require ( github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect - github.com/leodido/go-urn v1.2.0 // indirect + github.com/leodido/go-urn v1.2.1 // indirect github.com/mailru/easyjson v0.7.6 // indirect - github.com/mattn/go-isatty v0.0.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-sqlite3 v1.14.9 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/minio/sio v0.3.0 // indirect @@ -87,6 +88,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/oleiade/reflections v1.0.1 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect + github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 // indirect github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d // indirect github.com/pingcap/check v0.0.0-20211026125417-57bd13f7b5f0 // indirect diff --git a/tests/client/go.sum b/tests/client/go.sum index 96adc47ede1..3c0de1e7a14 100644 --- a/tests/client/go.sum +++ b/tests/client/go.sum @@ -96,8 +96,8 @@ github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm github.com/gin-gonic/gin v1.3.0/go.mod h1:7cKuhb5qV2ggCFctp2fJQ+ErvciLZrIeoOSOm6mUr7Y= github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= -github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM= -github.com/gin-gonic/gin v1.7.4/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= +github.com/gin-gonic/gin v1.8.1 h1:4+fr/el88TOO3ewCmQr8cx/CtZ/umlIRIs5M4NTNjf8= +github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk= github.com/go-chi/chi v4.0.2+incompatible h1:maB6vn6FqCxrpz4FqWdh4+lwpyZIQS7YEAUcHlgXVRs= github.com/go-chi/chi v4.0.2+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -125,13 +125,15 @@ github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyr github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= -github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= -github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= +github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= +github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= -github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= +github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= +github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= github.com/go-resty/resty/v2 v2.6.0 h1:joIR5PNLM2EFqqESUjCMGXrWmXNHEU9CEiK813oKYS4= github.com/go-resty/resty/v2 v2.6.0/go.mod h1:PwvJS6hvaPkjtjNg9ph+VrSD92bi5Zq73w/BIH7cC3Q= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= @@ -140,6 +142,8 @@ github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LB github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/goccy/go-graphviz v0.0.9 h1:s/FMMJ1Joj6La3S5ApO3Jk2cwM4LpXECC2muFx3IPQQ= github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQFC6TlNvLhk= +github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= +github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v0.0.0-20180717141946-636bf0302bc9/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -248,14 +252,17 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= +github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -265,8 +272,9 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA= @@ -287,7 +295,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= @@ -300,6 +307,8 @@ github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q= github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1/go.mod h1:eD5JxqMiuNYyFNmyY9rkJ/slN8y59oEu4Ei7F8OoKWQ= +github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= +github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36 h1:64bxqeTEN0/xoEqhKGowgihNuzISS9rEG6YUMU4bzJo= github.com/petermattis/goid v0.0.0-20211229010228-4d14c490ee36/go.mod h1:pxMtw7cyUw6B2bRH0ZBANSPg+AoSud1I1iyJHI69jH4= github.com/phf/go-queue v0.0.0-20170504031614-9abe38d0371d h1:U+PMnTlV2tu7RuMK5etusZG3Cf+rpow5hqQByeCzJ2g= @@ -331,6 +340,7 @@ github.com/pingcap/tidb-dashboard v0.0.0-20221201151320-ea3ee6971f2e h1:FUdoQ6zW github.com/pingcap/tidb-dashboard v0.0.0-20221201151320-ea3ee6971f2e/go.mod h1:NNF1CfnM5TqrLNfzfSal723h2fVQlieyVBBdQBzfPTg= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e h1:FBaTXU8C3xgt/drM58VHxojHo/QoG1oPsgWTGvaSpO4= github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -359,6 +369,9 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1 github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= +github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73DK8Y= @@ -480,6 +493,7 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA= golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -519,6 +533,7 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -563,6 +578,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= @@ -635,8 +652,9 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= From 8037ade9686ba294e7396a5efd3e7b6093660f30 Mon Sep 17 00:00:00 2001 From: nolouch Date: Tue, 20 Dec 2022 11:40:39 +0800 Subject: [PATCH 3/6] update API and add test Signed-off-by: nolouch --- go.mod | 2 +- go.sum | 4 +- .../resource_manager/server/apis/v1/api.go | 23 +++--- .../resource_manager/server/grpc_service.go | 11 ++- pkg/mcs/resource_manager/server/manager.go | 27 +++---- .../resource_manager/server/token_bukets.go | 24 +++++-- pkg/mcs/resource_manager/server/types.go | 62 +++++++++++++--- pkg/mcs/resource_manager/server/types_test.go | 70 +++++++++++++++++++ .../resource_manager/resource_manager_test.go | 24 +++---- 9 files changed, 190 insertions(+), 57 deletions(-) create mode 100644 pkg/mcs/resource_manager/server/types_test.go diff --git a/go.mod b/go.mod index 685a97f2e46..6962a571297 100644 --- a/go.mod +++ b/go.mod @@ -190,4 +190,4 @@ require ( // After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`. // replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch -replace github.com/pingcap/kvproto => github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46 +replace github.com/pingcap/kvproto => github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c diff --git a/go.sum b/go.sum index 2eb6a220b1d..7b4c9234610 100644 --- a/go.sum +++ b/go.sum @@ -330,8 +330,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46 h1:SqblNt1oTZg6N+g7ltm++c4D253bv08h1OeZ7BlvhLU= -github.com/nolouch/kvproto v0.0.0-20221215101412-004860b09b46/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= +github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c h1:lx+16iyOjZ4kc7jOYgIEXs/F33Bwg4KT9o1EXMYwp2U= +github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= diff --git a/pkg/mcs/resource_manager/server/apis/v1/api.go b/pkg/mcs/resource_manager/server/apis/v1/api.go index 798681cf21f..670d2b2b85e 100644 --- a/pkg/mcs/resource_manager/server/apis/v1/api.go +++ b/pkg/mcs/resource_manager/server/apis/v1/api.go @@ -21,7 +21,7 @@ import ( "github.com/gin-contrib/cors" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" - "github.com/pingcap/errcode" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" rmserver "github.com/tikv/pd/pkg/mcs/resource_manager/server" "github.com/tikv/pd/server" ) @@ -94,32 +94,33 @@ func (s *Service) handler() http.Handler { // @Failure 500 {object} error // @Router /config/group/ [POST] func (s *Service) postResourceGroup(c *gin.Context) { - var group rmserver.ResourceGroup + var group rmpb.ResourceGroup if err := c.ShouldBindJSON(&group); err != nil { - c.JSON(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) return } - if err := s.manager.AddResourceGroup(&group); err != nil { - c.JSON(http.StatusInternalServerError, err) + nGroup := rmserver.FromProtoResourceGroup(&group) + if err := s.manager.AddResourceGroup(nGroup); err != nil { + c.String(http.StatusInternalServerError, err.Error()) return } c.JSON(http.StatusOK, "Success!") } // @Summary updates an exists resource group -// @Param group body of "ResourceGroup", json format. +// @Param group body of "resource", json format. // @Success 200 "added successfully" // @Failure 400 {object} error // @Failure 500 {object} error // @Router /config/group/ [PUT] func (s *Service) putResourceGroup(c *gin.Context) { - var group rmserver.ResourceGroup + var group rmpb.ResourceGroup if err := c.ShouldBindJSON(&group); err != nil { - c.JSON(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) return } if err := s.manager.ModifyResourceGroup(&group); err != nil { - c.JSON(http.StatusInternalServerError, err) + c.String(http.StatusInternalServerError, err.Error()) return } c.JSON(http.StatusOK, "Success!") @@ -134,7 +135,7 @@ func (s *Service) putResourceGroup(c *gin.Context) { func (s *Service) getResourceGroup(c *gin.Context) { group := s.manager.GetResourceGroup(c.Param("name")) if group == nil { - c.JSON(http.StatusNotFound, errcode.NewNotFoundErr(errors.New("resource group not found"))) + c.String(http.StatusNotFound, errors.New("resource group not found").Error()) } c.JSON(http.StatusOK, group) } @@ -156,7 +157,7 @@ func (s *Service) getResourceGroupList(c *gin.Context) { // @Failure 404 {object} error func (s *Service) deleteResourceGroup(c *gin.Context) { if err := s.manager.DeleteResourceGroup(c.Param("name")); err != nil { - c.JSON(http.StatusNotFound, err) + c.String(http.StatusNotFound, err.Error()) } c.JSON(http.StatusOK, "Success!") } diff --git a/pkg/mcs/resource_manager/server/grpc_service.go b/pkg/mcs/resource_manager/server/grpc_service.go index 817a55951bf..45b68642f1a 100644 --- a/pkg/mcs/resource_manager/server/grpc_service.go +++ b/pkg/mcs/resource_manager/server/grpc_service.go @@ -102,7 +102,7 @@ func (s *Service) AddResourceGroup(ctx context.Context, req *rmpb.PutResourceGro if err != nil { return nil, err } - return &rmpb.PutResourceGroupResponse{ResponseBody: "Success!"}, nil + return &rmpb.PutResourceGroupResponse{Body: "Success!"}, nil } // DeleteResourceGroup implements ResourceManagerServer.DeleteResourceGroup. @@ -111,20 +111,19 @@ func (s *Service) DeleteResourceGroup(ctx context.Context, req *rmpb.DeleteResou if err != nil { return nil, err } - return &rmpb.DeleteResourceGroupResponse{ResponseBody: "Success!"}, nil + return &rmpb.DeleteResourceGroupResponse{Body: "Success!"}, nil } // ModifyResourceGroup implements ResourceManagerServer.ModifyResourceGroup. func (s *Service) ModifyResourceGroup(ctx context.Context, req *rmpb.PutResourceGroupRequest) (*rmpb.PutResourceGroupResponse, error) { - rg := FromProtoResourceGroup(req.GetGroup()) - err := s.manager.ModifyResourceGroup(rg) + err := s.manager.ModifyResourceGroup(req.GetGroup()) if err != nil { return nil, err } - return &rmpb.PutResourceGroupResponse{ResponseBody: "Success!"}, nil + return &rmpb.PutResourceGroupResponse{Body: "Success!"}, nil } // AcquireTokenBuckets implements ResourceManagerServer.AcquireTokenBuckets. func (s *Service) AcquireTokenBuckets(stream rmpb.ResourceManager_AcquireTokenBucketsServer) error { - return errors.New("not implemented") + return errors.New("Not implemented") } diff --git a/pkg/mcs/resource_manager/server/manager.go b/pkg/mcs/resource_manager/server/manager.go index 90994a74dfd..5c913005ee8 100644 --- a/pkg/mcs/resource_manager/server/manager.go +++ b/pkg/mcs/resource_manager/server/manager.go @@ -20,6 +20,7 @@ import ( "sync" "github.com/pingcap/errors" + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/tikv/pd/server" "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/storage" @@ -87,23 +88,25 @@ func (m *Manager) AddResourceGroup(group *ResourceGroup) error { } // ModifyResourceGroup modifies a exists resource group. -func (m *Manager) ModifyResourceGroup(group *ResourceGroup) error { - m.RLock() - _, ok := m.groups[group.Name] - m.RUnlock() +func (m *Manager) ModifyResourceGroup(group *rmpb.ResourceGroup) error { + if group == nil || group.Name == "" { + return errors.New("invalid group name") + } + m.Lock() + defer m.Unlock() + curGroup, ok := m.groups[group.Name] if !ok { return errors.New("not exists the group") } - err := group.CheckAndInit() + newGroup := curGroup.Copy() + err := newGroup.PatchSettings(group.GetSettings()) if err != nil { return err } - if err := m.storage().SaveResourceGroup(group.Name, group); err != nil { + if m.storage().SaveResourceGroup(group.Name, newGroup); err != nil { return err } - m.Lock() - m.groups[group.Name] = group - m.Unlock() + m.groups[group.Name] = newGroup return nil } @@ -118,17 +121,17 @@ func (m *Manager) DeleteResourceGroup(name string) error { return nil } -// GetResourceGroup returns a resource group. +// GetResourceGroup returns a copy of a resource group. func (m *Manager) GetResourceGroup(name string) *ResourceGroup { m.RLock() defer m.RUnlock() if group, ok := m.groups[name]; ok { - return group + return group.Copy() } return nil } -// GetResourceGroupList returns a resource group list. +// GetResourceGroupList returns copies of resource group list. func (m *Manager) GetResourceGroupList() []*ResourceGroup { m.RLock() res := make([]*ResourceGroup, 0, len(m.groups)) diff --git a/pkg/mcs/resource_manager/server/token_bukets.go b/pkg/mcs/resource_manager/server/token_bukets.go index 083949aef0b..00d4a3fe04f 100644 --- a/pkg/mcs/resource_manager/server/token_bukets.go +++ b/pkg/mcs/resource_manager/server/token_bukets.go @@ -17,6 +17,7 @@ package server import ( "time" + "github.com/gogo/protobuf/proto" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" ) @@ -32,6 +33,24 @@ type GroupTokenBucket struct { Initialized bool `json:"initialized"` } +// patch patches the token bucket settings. +func (t *GroupTokenBucket) patch(settings *rmpb.TokenBucket) { + if settings == nil { + return + } + tb := proto.Clone(t.TokenBucket).(*rmpb.TokenBucket) + if settings.GetSettings() != nil { + if tb == nil { + tb = &rmpb.TokenBucket{} + } + tb.Settings = settings.GetSettings() + } + + // the settings in token is delta of the last update and now. + tb.Tokens += settings.GetTokens() + t.TokenBucket = tb +} + // Update updates the token bucket. func (t *GroupTokenBucket) Update(now time.Time) { if !t.Initialized { @@ -49,11 +68,6 @@ func (t *GroupTokenBucket) Update(now time.Time) { } } -// GetTokenBucket returns the token bucket. -func (t *GroupTokenBucket) GetTokenBucket() *rmpb.TokenBucket { - return t.TokenBucket -} - // Request requests tokens from the token bucket. func (t *GroupTokenBucket) Request( neededTokens float64, targetPeriodMs uint64, diff --git a/pkg/mcs/resource_manager/server/types.go b/pkg/mcs/resource_manager/server/types.go index 2c4df5bd8d2..92768df8912 100644 --- a/pkg/mcs/resource_manager/server/types.go +++ b/pkg/mcs/resource_manager/server/types.go @@ -17,13 +17,17 @@ package server import ( "encoding/json" + "sync" "github.com/pingcap/errors" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" + "github.com/pingcap/log" + "go.uber.org/zap" ) // ResourceGroup is the definition of a resource group, for REST API. type ResourceGroup struct { + sync.RWMutex Name string `json:"name"` Mode rmpb.GroupMode `json:"mode"` // RU settings @@ -45,9 +49,20 @@ type NativeResourceSettings struct { IOWriteBandwidth GroupTokenBucket `json:"io_write_bandwidth,omitempty"` } +func (rg *ResourceGroup) String() string { + res, err := json.Marshal(rg) + if err != nil { + log.Error("marshal resource group failed", zap.Error(err)) + return "" + } + return string(res) +} + // Copy copies the resource group. func (rg *ResourceGroup) Copy() *ResourceGroup { // TODO: use a better way to copy + rg.RLock() + defer rg.RUnlock() res, err := json.Marshal(rg) if err != nil { panic(err) @@ -61,6 +76,7 @@ func (rg *ResourceGroup) Copy() *ResourceGroup { } // CheckAndInit checks the validity of the resource group and initializes the default values if not setting. +// Only used to initialize the resource group when creating. func (rg *ResourceGroup) CheckAndInit() error { if len(rg.Name) == 0 || len(rg.Name) > 32 { return errors.New("invalid resource group name, the length should be in [1,32]") @@ -87,6 +103,34 @@ func (rg *ResourceGroup) CheckAndInit() error { return nil } +// PatchSettings patches the resource group settings. +// Only used to patch the resource group when updating. +// Note: the tokens is the delta value to patch. +func (rg *ResourceGroup) PatchSettings(groupSettings *rmpb.GroupSettings) error { + rg.Lock() + defer rg.Unlock() + if groupSettings.GetMode() != rg.Mode { + return errors.New("only support reconfigure in same mode, maybe you should delete and create a new one") + } + switch rg.Mode { + case rmpb.GroupMode_RUMode: + if groupSettings.GetRUSettings() == nil { + return errors.New("invalid resource group settings, RU mode should set RU settings") + } + rg.RUSettings.RRU.patch(groupSettings.GetRUSettings().GetRRU()) + rg.RUSettings.WRU.patch(groupSettings.GetRUSettings().GetWRU()) + case rmpb.GroupMode_NativeMode: + if groupSettings.GetResourceSettings() == nil { + return errors.New("invalid resource group settings, native mode should set resource settings") + } + rg.ResourceSettings.CPU.patch(groupSettings.GetResourceSettings().GetCpu()) + rg.ResourceSettings.IOReadBandwidth.patch(groupSettings.GetResourceSettings().GetIoRead()) + rg.ResourceSettings.IOWriteBandwidth.patch(groupSettings.GetResourceSettings().GetIoWrite()) + } + log.Info("patch resource group settings", zap.String("name", rg.Name), zap.String("settings", rg.String())) + return nil +} + // FromProtoResourceGroup converts a rmpb.ResourceGroup to a ResourceGroup. func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup { var ( @@ -120,7 +164,7 @@ func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup { } rg := &ResourceGroup{ - Name: group.ResourceGroupName, + Name: group.Name, Mode: group.Settings.Mode, RUSettings: ruSettings, ResourceSettings: resourceSettings, @@ -130,28 +174,30 @@ func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup { // IntoProtoResourceGroup converts a ResourceGroup to a rmpb.ResourceGroup. func (rg *ResourceGroup) IntoProtoResourceGroup() *rmpb.ResourceGroup { + rg.RLock() + defer rg.RUnlock() switch rg.Mode { case rmpb.GroupMode_RUMode: // RU mode group := &rmpb.ResourceGroup{ - ResourceGroupName: rg.Name, + Name: rg.Name, Settings: &rmpb.GroupSettings{ Mode: rmpb.GroupMode_RUMode, RUSettings: &rmpb.GroupRequestUnitSettings{ - RRU: rg.RUSettings.RRU.GetTokenBucket(), - WRU: rg.RUSettings.WRU.GetTokenBucket(), + RRU: rg.RUSettings.RRU.TokenBucket, + WRU: rg.RUSettings.WRU.TokenBucket, }, }, } return group case rmpb.GroupMode_NativeMode: // Native mode group := &rmpb.ResourceGroup{ - ResourceGroupName: rg.Name, + Name: rg.Name, Settings: &rmpb.GroupSettings{ Mode: rmpb.GroupMode_NativeMode, ResourceSettings: &rmpb.GroupResourceSettings{ - Cpu: rg.ResourceSettings.CPU.GetTokenBucket(), - IoRead: rg.ResourceSettings.IOReadBandwidth.GetTokenBucket(), - IoWrite: rg.ResourceSettings.IOWriteBandwidth.GetTokenBucket(), + Cpu: rg.ResourceSettings.CPU.TokenBucket, + IoRead: rg.ResourceSettings.IOReadBandwidth.TokenBucket, + IoWrite: rg.ResourceSettings.IOWriteBandwidth.TokenBucket, }, }, } diff --git a/pkg/mcs/resource_manager/server/types_test.go b/pkg/mcs/resource_manager/server/types_test.go new file mode 100644 index 00000000000..1e22559f591 --- /dev/null +++ b/pkg/mcs/resource_manager/server/types_test.go @@ -0,0 +1,70 @@ +package server + +import ( + "encoding/json" + "testing" + + rmpb "github.com/pingcap/kvproto/pkg/resource_manager" + "github.com/stretchr/testify/require" +) + +func TestPatchResourceGroup(t *testing.T) { + re := require.New(t) + rg1 := &ResourceGroup{Name: "test", Mode: rmpb.GroupMode_RUMode} + err := rg1.CheckAndInit() + re.NoError(err) + testCaseRU := []struct { + patchJSONString string + expectJSONString string + }{ + {`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"initialized":false}}}`}, + {`{"mode":0, "r_u_settings": {"w_r_u":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`}, + {`{"mode":0, "r_u_settings": {"w_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}}}`, + `{"name":"test","mode":0,"r_u_settings":{"rru":{"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`}, + {`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}}}`, + `{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"initialized":false}}}`}, + {`{"mode":0, "r_u_settings": {"r_r_u":{"settings":{"fillrate": 200000, "burst": 100000}}, "w_r_u":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":0,"r_u_settings":{"rru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"wru":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`}, + } + + for _, ca := range testCaseRU { + rg := rg1.Copy() + patch := &rmpb.GroupSettings{} + err := json.Unmarshal([]byte(ca.patchJSONString), patch) + re.NoError(err) + err = rg.PatchSettings(patch) + re.NoError(err) + res, err := json.Marshal(rg) + re.NoError(err) + re.Equal(ca.expectJSONString, string(res)) + } + + rg2 := &ResourceGroup{Name: "test", Mode: rmpb.GroupMode_NativeMode} + err = rg2.CheckAndInit() + re.NoError(err) + testCaseResource := []struct { + patchJSONString string + expectJSONString string + }{ + {`{"mode":1, "resource_settings": {"cpu":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`}, + {`{"mode":1, "resource_settings": {"io_read":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false},"io_write_bandwidth":{"initialized":false}}}`}, + {`{"mode":1, "resource_settings": {"io_write":{"settings":{"fillrate": 200000}}}}`, + `{"name":"test","mode":1,"resource_settings":{"cpu":{"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"token_bucket":{"settings":{"fillrate":200000}},"initialized":false}}}`}, + } + + for _, ca := range testCaseResource { + rg := rg2.Copy() + patch := &rmpb.GroupSettings{} + err := json.Unmarshal([]byte(ca.patchJSONString), patch) + re.NoError(err) + err = rg.PatchSettings(patch) + re.NoError(err) + res, err := json.Marshal(rg) + re.NoError(err) + re.Equal(ca.expectJSONString, string(res)) + } +} diff --git a/tests/msc/resource_manager/resource_manager_test.go b/tests/msc/resource_manager/resource_manager_test.go index 05f007d2e59..57f7275da59 100644 --- a/tests/msc/resource_manager/resource_manager_test.go +++ b/tests/msc/resource_manager/resource_manager_test.go @@ -119,12 +119,12 @@ func TestBasicReourceGroupCURD(t *testing.T) { }, }, {"test3", rmpb.GroupMode_NativeMode, false, true, - `{"name":"test3","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fillrate":10000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`, + `{"name":"test3","mode":1,"resource_settings":{"cpu":{"token_bucket":{"settings":{"fillrate":1000000}},"initialized":false},"io_read_bandwidth":{"initialized":false},"io_write_bandwidth":{"initialized":false}}}`, func(gs *rmpb.GroupSettings) { gs.ResourceSettings = &rmpb.GroupResourceSettings{ Cpu: &rmpb.TokenBucket{ Settings: &rmpb.TokenLimitSettings{ - Fillrate: 10000, + Fillrate: 1000000, }, }, } @@ -144,7 +144,7 @@ func TestBasicReourceGroupCURD(t *testing.T) { // Test Resource Group CURD via gRPC for i, tcase := range testCasesSet1 { group := &rmpb.ResourceGroup{ - ResourceGroupName: tcase.name, + Name: tcase.name, Settings: &rmpb.GroupSettings{ Mode: tcase.mode, }, @@ -154,7 +154,7 @@ func TestBasicReourceGroupCURD(t *testing.T) { checkErr(err, tcase.addSuccess) if tcase.addSuccess { finalNum++ - re.Contains(resp.ResponseBody, "Success!") + re.Contains(resp.Body, "Success!") } // Modify Resource Group @@ -162,13 +162,13 @@ func TestBasicReourceGroupCURD(t *testing.T) { mresp, err := grpcclient.ModifyResourceGroup(ctx, &rmpb.PutResourceGroupRequest{Group: group}) checkErr(err, tcase.modifySuccess) if tcase.modifySuccess { - re.Contains(mresp.ResponseBody, "Success!") + re.Contains(mresp.Body, "Success!") } // Get Resource Group gresp, err := grpcclient.GetResourceGroup(ctx, &rmpb.GetResourceGroupRequest{ResourceGroupName: tcase.name}) re.NoError(err) - re.Equal(tcase.name, gresp.Group.ResourceGroupName) + re.Equal(tcase.name, gresp.Group.Name) if tcase.modifySuccess { re.Equal(group, gresp.Group) } @@ -182,9 +182,9 @@ func TestBasicReourceGroupCURD(t *testing.T) { for _, g := range lresp.Groups { // Delete Resource Group - dresp, err := grpcclient.DeleteResourceGroup(ctx, &rmpb.DeleteResourceGroupRequest{ResourceGroupName: g.ResourceGroupName}) + dresp, err := grpcclient.DeleteResourceGroup(ctx, &rmpb.DeleteResourceGroupRequest{ResourceGroupName: g.Name}) re.NoError(err) - re.Contains(dresp.ResponseBody, "Success!") + re.Contains(dresp.Body, "Success!") } } } @@ -194,12 +194,12 @@ func TestBasicReourceGroupCURD(t *testing.T) { for i, tcase := range testCasesSet1 { // Create Resource Group group := &rmpb.ResourceGroup{ - ResourceGroupName: tcase.name, + Name: tcase.name, Settings: &rmpb.GroupSettings{ Mode: tcase.mode, }, } - createJSON, err := json.Marshal(server.FromProtoResourceGroup(group)) + createJSON, err := json.Marshal(group) re.NoError(err) resp, err := http.Post(leader.GetAddr()+"/resource-manager/api/v1/config/group", "application/json", strings.NewReader(string(createJSON))) re.NoError(err) @@ -213,7 +213,7 @@ func TestBasicReourceGroupCURD(t *testing.T) { // Modify Resource Group tcase.modifySettings(group.Settings) - modifyJSON, err := json.Marshal(server.FromProtoResourceGroup(group)) + modifyJSON, err := json.Marshal(group) re.NoError(err) req, err := http.NewRequest(http.MethodPut, leader.GetAddr()+"/resource-manager/api/v1/config/group", strings.NewReader(string(modifyJSON))) re.NoError(err) @@ -247,7 +247,7 @@ func TestBasicReourceGroupCURD(t *testing.T) { re.Equal(http.StatusOK, resp.StatusCode) respString, err := io.ReadAll(resp.Body) re.NoError(err) - groups := make([]server.ResourceGroup, 0) + groups := make([]*server.ResourceGroup, 0) json.Unmarshal(respString, &groups) re.Equal(finalNum, len(groups)) From 3bb1248aade9e5674cbbe6376aa108feac5d855a Mon Sep 17 00:00:00 2001 From: nolouch Date: Tue, 20 Dec 2022 16:27:12 +0800 Subject: [PATCH 4/6] address comments Signed-off-by: nolouch --- pkg/mcs/registry/registry.go | 4 +- pkg/mcs/resource_manager/server/manager.go | 18 ++----- pkg/mcs/resource_manager/server/types.go | 58 +++++++++++----------- 3 files changed, 35 insertions(+), 45 deletions(-) diff --git a/pkg/mcs/registry/registry.go b/pkg/mcs/registry/registry.go index aadd84853a9..16055910c62 100644 --- a/pkg/mcs/registry/registry.go +++ b/pkg/mcs/registry/registry.go @@ -65,7 +65,7 @@ func (r *ServiceRegistry) InstallAllGRPCServices(srv *server.Server, g *grpc.Ser l := builder(srv) r.services[name] = l l.RegisterGRPCService(g) - log.Info("gRPC service register success", zap.String("service-name", name)) + log.Info("gRPC service registered successfully", zap.String("service-name", name)) } } @@ -80,7 +80,7 @@ func (r *ServiceRegistry) InstallAllRESTHandler(srv *server.Server, h map[string l := builder(srv) r.services[name] = l l.RegisterRESTHandler(h) - log.Info("restful API service register success", zap.String("service-name", name)) + log.Info("restful API service registered successfully", zap.String("service-name", name)) } } diff --git a/pkg/mcs/resource_manager/server/manager.go b/pkg/mcs/resource_manager/server/manager.go index 5c913005ee8..166063d43b4 100644 --- a/pkg/mcs/resource_manager/server/manager.go +++ b/pkg/mcs/resource_manager/server/manager.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/errors" rmpb "github.com/pingcap/kvproto/pkg/resource_manager" "github.com/tikv/pd/server" - "github.com/tikv/pd/server/core" "github.com/tikv/pd/server/storage" ) @@ -31,24 +30,13 @@ type Manager struct { sync.RWMutex groups map[string]*ResourceGroup storage func() storage.Storage - // TODO: dispatch resource group to storage node - getStores func() ([]*core.StoreInfo, error) } // NewManager returns a new Manager. func NewManager(srv *server.Server) *Manager { - getStores := func() ([]*core.StoreInfo, error) { - rc := srv.GetRaftCluster() - if rc == nil { - return nil, errors.New("RaftCluster is nil") - } - return rc.GetStores(), nil - } - m := &Manager{ - groups: make(map[string]*ResourceGroup), - storage: srv.GetStorage, - getStores: getStores, + groups: make(map[string]*ResourceGroup), + storage: srv.GetStorage, } srv.AddStartCallback(m.Init) return m @@ -87,7 +75,7 @@ func (m *Manager) AddResourceGroup(group *ResourceGroup) error { return nil } -// ModifyResourceGroup modifies a exists resource group. +// ModifyResourceGroup modifies an existing resource group. func (m *Manager) ModifyResourceGroup(group *rmpb.ResourceGroup) error { if group == nil || group.Name == "" { return errors.New("invalid group name") diff --git a/pkg/mcs/resource_manager/server/types.go b/pkg/mcs/resource_manager/server/types.go index 92768df8912..72686ad4c94 100644 --- a/pkg/mcs/resource_manager/server/types.go +++ b/pkg/mcs/resource_manager/server/types.go @@ -138,36 +138,38 @@ func FromProtoResourceGroup(group *rmpb.ResourceGroup) *ResourceGroup { ruSettings *RequestUnitSettings ) - if settings := group.GetSettings().GetResourceSettings(); settings != nil { - resourceSettings = &NativeResourceSettings{ - CPU: GroupTokenBucket{ - TokenBucket: settings.GetCpu(), - }, - IOReadBandwidth: GroupTokenBucket{ - TokenBucket: settings.GetIoRead(), - }, - IOWriteBandwidth: GroupTokenBucket{ - TokenBucket: settings.GetIoWrite(), - }, - } + rg := &ResourceGroup{ + Name: group.Name, + Mode: group.Settings.Mode, } - - if settings := group.GetSettings().GetRUSettings(); settings != nil { - ruSettings = &RequestUnitSettings{ - RRU: GroupTokenBucket{ - TokenBucket: settings.GetRRU(), - }, - WRU: GroupTokenBucket{ - TokenBucket: settings.GetWRU(), - }, + switch group.GetSettings().GetMode() { + case rmpb.GroupMode_RUMode: + if settings := group.GetSettings().GetRUSettings(); settings != nil { + ruSettings = &RequestUnitSettings{ + RRU: GroupTokenBucket{ + TokenBucket: settings.GetRRU(), + }, + WRU: GroupTokenBucket{ + TokenBucket: settings.GetWRU(), + }, + } + rg.RUSettings = ruSettings + } + case rmpb.GroupMode_NativeMode: + if settings := group.GetSettings().GetResourceSettings(); settings != nil { + resourceSettings = &NativeResourceSettings{ + CPU: GroupTokenBucket{ + TokenBucket: settings.GetCpu(), + }, + IOReadBandwidth: GroupTokenBucket{ + TokenBucket: settings.GetIoRead(), + }, + IOWriteBandwidth: GroupTokenBucket{ + TokenBucket: settings.GetIoWrite(), + }, + } + rg.ResourceSettings = resourceSettings } - } - - rg := &ResourceGroup{ - Name: group.Name, - Mode: group.Settings.Mode, - RUSettings: ruSettings, - ResourceSettings: resourceSettings, } return rg } From a47f944737faf67a6c045f94cc36385cc8320281 Mon Sep 17 00:00:00 2001 From: nolouch Date: Tue, 20 Dec 2022 16:33:48 +0800 Subject: [PATCH 5/6] address comments Signed-off-by: nolouch --- pkg/mcs/resource_manager/server/manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/mcs/resource_manager/server/manager.go b/pkg/mcs/resource_manager/server/manager.go index 166063d43b4..5faad4f5f07 100644 --- a/pkg/mcs/resource_manager/server/manager.go +++ b/pkg/mcs/resource_manager/server/manager.go @@ -66,10 +66,10 @@ func (m *Manager) AddResourceGroup(group *ResourceGroup) error { if err != nil { return err } + m.Lock() if err := m.storage().SaveResourceGroup(group.Name, group); err != nil { return err } - m.Lock() m.groups[group.Name] = group m.Unlock() return nil From 87b0be96b9ad3a3fa48976331b701e5e22d39b54 Mon Sep 17 00:00:00 2001 From: nolouch Date: Wed, 21 Dec 2022 18:06:16 +0800 Subject: [PATCH 6/6] replace kvproto Signed-off-by: nolouch --- go.mod | 4 +--- go.sum | 9 +++++++-- tests/client/go.mod | 2 +- tests/client/go.sum | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 6962a571297..23cf2ecbf39 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/pingcap/errcode v0.3.0 github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce - github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1 + github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26 github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 github.com/pingcap/sysutil v0.0.0-20211208032423-041a72e5860d github.com/pingcap/tidb-dashboard v0.0.0-20221201151320-ea3ee6971f2e @@ -189,5 +189,3 @@ require ( // kvproto at the same time. You can run `go mod tidy` to make it replaced with go-mod style specification. // After the PR to kvproto is merged, remember to comment this out and run `go mod tidy`. // replace github.com/pingcap/kvproto => github.com/$YourPrivateRepo $YourPrivateBranch - -replace github.com/pingcap/kvproto => github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c diff --git a/go.sum b/go.sum index 7b4c9234610..19c5daac87f 100644 --- a/go.sum +++ b/go.sum @@ -170,6 +170,7 @@ github.com/goccy/go-graphviz v0.0.9/go.mod h1:wXVsXxmyMQU6TN3zGRttjNn3h+iCAS7xQF github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= +github.com/gogo/protobuf v0.0.0-20180717141946-636bf0302bc9/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= @@ -184,6 +185,7 @@ github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef h1:veQD95Isof8w9/WXiA+pa3tz3fJXkt5B7QaRBrM62gk= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v0.0.0-20180814211427-aa810b61a9c7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -330,8 +332,6 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5 h1:BvoENQQU+fZ9uukda/RzCAL/191HHwJA5b13R6diVlY= github.com/nfnt/resize v0.0.0-20160724205520-891127d8d1b5/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= -github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c h1:lx+16iyOjZ4kc7jOYgIEXs/F33Bwg4KT9o1EXMYwp2U= -github.com/nolouch/kvproto v0.0.0-20221219165002-73f7af2e539c/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM= github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60= @@ -364,6 +364,9 @@ github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c h1:xpW9bvK+HuuTm github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c/go.mod h1:X2r9ueLEUZgtx2cIogM0v4Zj5uvvzhuuiu7Pn8HzMPg= github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce h1:Y1kCxlCtlPTMtVcOkjUcuQKh+YrluSo7+7YMCQSzy30= github.com/pingcap/failpoint v0.0.0-20200702092429-9f69995143ce/go.mod h1:w4PEZ5y16LeofeeGwdgZB4ddv9bLyDuIX+ljstgKZyk= +github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= +github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26 h1:Tw4afZ2Tyr8iT8Oln6/szMjh5IDs+GtlnLsDo/Y2HEE= +github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw= @@ -689,9 +692,11 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c h1:hrpEMCZ2O7DR5gC1n2AJGVhrwiEjOi35+jxtIuZpTMo= google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/grpc v0.0.0-20180607172857-7a6a684ca69e/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= diff --git a/tests/client/go.mod b/tests/client/go.mod index 8affac4ab78..85ca22dd688 100644 --- a/tests/client/go.mod +++ b/tests/client/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 - github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1 + github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26 github.com/stretchr/testify v1.8.0 github.com/tikv/pd v0.0.0-00010101000000-000000000000 github.com/tikv/pd/client v0.0.0-00010101000000-000000000000 diff --git a/tests/client/go.sum b/tests/client/go.sum index 3c0de1e7a14..ab7065da67b 100644 --- a/tests/client/go.sum +++ b/tests/client/go.sum @@ -328,8 +328,8 @@ github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 h1:C3N3itkduZXDZ github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB0QK0wBzKtFEGDhxXnSnbQApw1gc9siScUl8ew= github.com/pingcap/kvproto v0.0.0-20191211054548-3c6b38ea5107/go.mod h1:WWLmULLO7l8IOcQG+t+ItJ3fEcrL5FxF0Wu+HrMy26w= github.com/pingcap/kvproto v0.0.0-20221026112947-f8d61344b172/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= -github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1 h1:iJXUNA0LoOYuuMJ6U0tJGg2gCo/8xGZVhKLvuUWNjzw= -github.com/pingcap/kvproto v0.0.0-20221104101942-09d82b914df1/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= +github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26 h1:Tw4afZ2Tyr8iT8Oln6/szMjh5IDs+GtlnLsDo/Y2HEE= +github.com/pingcap/kvproto v0.0.0-20221221093947-0a9b14f1fc26/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuRurdGxZXBz0At+9avep+ub7U1AGYLIMM= github.com/pingcap/log v1.1.1-0.20221110025148-ca232912c9f3 h1:HR/ylkkLmGdSSDaD8IDP+SZrdhV1Kibl9KrHxJ9eciw=