Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

mcs: add config api for tso service #7858

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to panic here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem we need to use Get?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think it barely happens.

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())
}
Loading