From 76b3279531314b617c205e5b26dc649e2bef945e Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 29 Feb 2024 15:02:16 +0800 Subject: [PATCH] add config api for tso service Signed-off-by: Ryan Leung --- pkg/mcs/tso/server/apis/v1/api.go | 23 ++++++++++++++++++++--- tests/integrations/mcs/tso/api_test.go | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/pkg/mcs/tso/server/apis/v1/api.go b/pkg/mcs/tso/server/apis/v1/api.go index 04418283007..44f4b353d58 100644 --- a/pkg/mcs/tso/server/apis/v1/api.go +++ b/pkg/mcs/tso/server/apis/v1/api.go @@ -95,7 +95,8 @@ func NewService(srv *tsoserver.Service) *Service { } s.RegisterAdminRouter() s.RegisterKeyspaceGroupRouter() - s.RegisterHealth() + s.RegisterHealthRouter() + s.RegisterConfigRouter() return s } @@ -112,12 +113,18 @@ func (s *Service) RegisterKeyspaceGroupRouter() { router.GET("/members", GetKeyspaceGroupMembers) } -// RegisterHealth registers the router of the health handler. -func (s *Service) RegisterHealth() { +// RegisterHealthRouter registers the router of the health handler. +func (s *Service) RegisterHealthRouter() { router := s.root.Group("health") router.GET("", GetHealth) } +// RegisterConfigRouter registers the router of the config handler. +func (s *Service) RegisterConfigRouter() { + router := s.root.Group("config") + router.GET("", getConfig) +} + func changeLogLevel(c *gin.Context) { svr := c.MustGet(multiservicesapi.ServiceContextKey).(*tsoserver.Service) var level string @@ -248,3 +255,13 @@ func GetKeyspaceGroupMembers(c *gin.Context) { } c.IndentedJSON(http.StatusOK, members) } + +// @Tags config +// @Summary Get full config. +// @Produce json +// @Success 200 {object} config.Config +// @Router /config [get] +func getConfig(c *gin.Context) { + svr := c.MustGet(multiservicesapi.ServiceContextKey).(*tsoserver.Service) + c.IndentedJSON(http.StatusOK, svr.GetConfig()) +} diff --git a/tests/integrations/mcs/tso/api_test.go b/tests/integrations/mcs/tso/api_test.go index 0a026aff916..32725418462 100644 --- a/tests/integrations/mcs/tso/api_test.go +++ b/tests/integrations/mcs/tso/api_test.go @@ -266,3 +266,22 @@ func (suite *tsoAPITestSuite) TestStatus() { re.Equal(versioninfo.PDGitHash, s.GitHash) re.Equal(versioninfo.PDReleaseVersion, s.Version) } + +func (suite *tsoAPITestSuite) TestConfig() { + re := suite.Require() + + primary := suite.tsoCluster.WaitForDefaultPrimaryServing(re) + resp, err := http.Get(primary.GetConfig().GetAdvertiseListenAddr() + "/tso/api/v1/config") + re.NoError(err) + defer resp.Body.Close() + re.Equal(http.StatusOK, resp.StatusCode) + respBytes, err := io.ReadAll(resp.Body) + re.NoError(err) + var cfg tso.Config + re.NoError(json.Unmarshal(respBytes, &cfg)) + re.Equal(cfg.GetListenAddr(), primary.GetConfig().GetListenAddr()) + re.Equal(cfg.GetTSOSaveInterval(), primary.GetConfig().GetTSOSaveInterval()) + re.Equal(cfg.IsLocalTSOEnabled(), primary.GetConfig().IsLocalTSOEnabled()) + re.Equal(cfg.GetTSOUpdatePhysicalInterval(), primary.GetConfig().GetTSOUpdatePhysicalInterval()) + re.Equal(cfg.GetMaxResetTSGap(), primary.GetConfig().GetMaxResetTSGap()) +}