Skip to content

Commit

Permalink
mcs: add config api for tso service (#7858)
Browse files Browse the repository at this point in the history
ref #5839

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
rleungx and ti-chi-bot[bot] committed Feb 29, 2024
1 parent 92a31c1 commit 2e3e4c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/mcs/tso/server/apis/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ func NewService(srv *tsoserver.Service) *Service {
}
s.RegisterAdminRouter()
s.RegisterKeyspaceGroupRouter()
s.RegisterHealth()
s.RegisterHealthRouter()
s.RegisterConfigRouter()
return s
}

Expand All @@ -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
Expand Down Expand Up @@ -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())
}
19 changes: 19 additions & 0 deletions tests/integrations/mcs/tso/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 2e3e4c0

Please sign in to comment.