Skip to content

Commit

Permalink
Merge branch 'master' into issue-3936
Browse files Browse the repository at this point in the history
  • Loading branch information
nolouch authored Oct 14, 2021
2 parents 3dba704 + 0a32ac8 commit 74758c4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,12 @@ func (h *confHandler) SetReplicationMode(w http.ResponseWriter, r *http.Request)
}
h.rd.JSON(w, http.StatusOK, "The replication mode config is updated.")
}

// @Tags config
// @Summary Get PD server config.
// @Produce json
// @Success 200 {object} config.PDServerConfig
// @Router /config/pd-server [get]
func (h *confHandler) GetPDServer(w http.ResponseWriter, r *http.Request) {
h.rd.JSON(w, http.StatusOK, h.svr.GetPDServerConfig())
}
23 changes: 23 additions & 0 deletions server/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ func (s *testConfigSuite) TestConfigDefault(c *C) {
c.Assert(defaultCfg.PDServerCfg.MetricStorage, Equals, "")
}

func (s *testConfigSuite) TestConfigPDServer(c *C) {
addr := fmt.Sprintf("%s/config", s.urlPrefix)

ms := map[string]interface{}{
"metric-storage": "",
}
postData, err := json.Marshal(ms)
c.Assert(err, IsNil)
c.Assert(postJSON(testDialClient, addr, postData), IsNil)

addr = fmt.Sprintf("%s/config/pd-server", s.urlPrefix)
sc := &config.PDServerConfig{}
c.Assert(readJSON(testDialClient, addr, sc), IsNil)

c.Assert(sc.UseRegionStorage, Equals, bool(true))
c.Assert(sc.KeyType, Equals, "table")
c.Assert(sc.RuntimeServices, DeepEquals, typeutil.StringSlice([]string{}))
c.Assert(sc.MetricStorage, Equals, "")
c.Assert(sc.DashboardAddress, Equals, "auto")
c.Assert(sc.FlowRoundByDigit, Equals, int(3))
c.Assert(sc.MaxResetTSGap.Duration, Equals, time.Duration(24*time.Hour))
}

var ttlConfig = map[string]interface{}{
"schedule.max-snapshot-count": 999,
"schedule.enable-location-replacement": false,
Expand Down
1 change: 1 addition & 0 deletions server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router {
apiRouter.HandleFunc("/config/default", confHandler.GetDefault).Methods("GET")
apiRouter.HandleFunc("/config/schedule", confHandler.GetSchedule).Methods("GET")
apiRouter.HandleFunc("/config/schedule", confHandler.SetSchedule).Methods("POST")
apiRouter.HandleFunc("/config/pd-server", confHandler.GetPDServer).Methods("GET")
apiRouter.HandleFunc("/config/replicate", confHandler.GetReplication).Methods("GET")
apiRouter.HandleFunc("/config/replicate", confHandler.SetReplication).Methods("POST")
apiRouter.HandleFunc("/config/label-property", confHandler.GetLabelProperty).Methods("GET")
Expand Down
36 changes: 36 additions & 0 deletions tests/pdctl/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,42 @@ func (s *configTestSuite) TestUpdateDefaultReplicaConfig(c *C) {
checkRuleLocationLabels(1)
}

func (s *configTestSuite) TestPDServerConfig(c *C) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cluster, err := tests.NewTestCluster(ctx, 1)
c.Assert(err, IsNil)
err = cluster.RunInitialServers()
c.Assert(err, IsNil)
cluster.WaitLeader()
pdAddr := cluster.GetConfig().GetClientURL()
cmd := pdctlCmd.GetRootCmd()

store := &metapb.Store{
Id: 1,
State: metapb.StoreState_Up,
LastHeartbeat: time.Now().UnixNano(),
}
leaderServer := cluster.GetServer(cluster.GetLeader())
c.Assert(leaderServer.BootstrapCluster(), IsNil)
svr := leaderServer.GetServer()
pdctl.MustPutStore(c, svr, store)
defer cluster.Destroy()

output, err := pdctl.ExecuteCommand(cmd, "-u", pdAddr, "config", "show", "server")
c.Assert(err, IsNil)
var conf config.PDServerConfig
json.Unmarshal(output, &conf)

c.Assert(conf.UseRegionStorage, Equals, bool(true))
c.Assert(conf.MaxResetTSGap.Duration, Equals, time.Duration(24*time.Hour))
c.Assert(conf.KeyType, Equals, "table")
c.Assert(conf.RuntimeServices, DeepEquals, typeutil.StringSlice([]string{}))
c.Assert(conf.MetricStorage, Equals, "")
c.Assert(conf.DashboardAddress, Equals, "auto")
c.Assert(conf.FlowRoundByDigit, Equals, int(3))
}

func assertBundles(a, b []placement.GroupBundle, c *C) {
c.Assert(len(a), Equals, len(b))
for i := 0; i < len(a); i++ {
Expand Down
20 changes: 20 additions & 0 deletions tools/pd-ctl/pdctl/command/config_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
ruleGroupsPrefix = "pd/api/v1/config/rule_groups"
replicationModePrefix = "pd/api/v1/config/replication-mode"
ruleBundlePrefix = "pd/api/v1/config/placement-rule"
pdServerPrefix = "pd/api/v1/config/pd-server"
)

// NewConfigCommand return a config subcommand of rootCmd
Expand Down Expand Up @@ -71,6 +72,7 @@ func NewShowConfigCommand() *cobra.Command {
sc.AddCommand(NewShowLabelPropertyCommand())
sc.AddCommand(NewShowClusterVersionCommand())
sc.AddCommand(newShowReplicationModeCommand())
sc.AddCommand(NewShowServerConfigCommand())
return sc
}

Expand Down Expand Up @@ -132,6 +134,15 @@ func newShowReplicationModeCommand() *cobra.Command {
}
}

// NewShowServerConfigCommand returns a server configuration of show subcommand.
func NewShowServerConfigCommand() *cobra.Command {
return &cobra.Command{
Use: "server",
Short: "show PD server config",
Run: showServerCommandFunc,
}
}

// NewSetConfigCommand return a set subcommand of configCmd
func NewSetConfigCommand() *cobra.Command {
sc := &cobra.Command{
Expand Down Expand Up @@ -302,6 +313,15 @@ func showReplicationModeCommandFunc(cmd *cobra.Command, args []string) {
cmd.Println(r)
}

func showServerCommandFunc(cmd *cobra.Command, args []string) {
r, err := doRequest(cmd, pdServerPrefix, http.MethodGet)
if err != nil {
cmd.Printf("Failed to get server config: %s\n", err)
return
}
cmd.Println(r)
}

func postConfigDataWithPath(cmd *cobra.Command, key, value, path string) error {
var val interface{}
data := make(map[string]interface{})
Expand Down

0 comments on commit 74758c4

Please sign in to comment.