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

scheduler: add aduit log for scheduler config API and add resp msg for evict-leader #7674

Merged
merged 5 commits into from
Jan 9, 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
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func (handler *evictLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
handler.rd.JSON(w, http.StatusOK, nil)
handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.")
}

func (handler *evictLeaderHandler) ListConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_slow_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
return
}
log.Info("evict-slow-store-scheduler update 'recovery-duration' - unit: s", zap.Uint64("prev", prevRecoveryDurationGap), zap.Uint64("cur", recoveryDurationGap))
handler.rd.JSON(w, http.StatusOK, nil)
handler.rd.JSON(w, http.StatusOK, "Config updated.")

Check warning on line 177 in pkg/schedule/schedulers/evict_slow_store.go

View check run for this annotation

Codecov / codecov/patch

pkg/schedule/schedulers/evict_slow_store.go#L177

Added line #L177 was not covered by tests
}

func (handler *evictSlowStoreHandler) ListConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/evict_slow_trend.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
return
}
log.Info("evict-slow-trend-scheduler update 'recovery-duration' - unit: s", zap.Uint64("prev", prevRecoveryDurationGap), zap.Uint64("cur", recoveryDurationGap))
handler.rd.JSON(w, http.StatusOK, nil)
handler.rd.JSON(w, http.StatusOK, "Config updated.")

Check warning on line 263 in pkg/schedule/schedulers/evict_slow_trend.go

View check run for this annotation

Codecov / codecov/patch

pkg/schedule/schedulers/evict_slow_trend.go#L263

Added line #L263 was not covered by tests
}

func (handler *evictSlowTrendHandler) ListConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/schedulers/grant_leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (handler *grantLeaderHandler) UpdateConfig(w http.ResponseWriter, r *http.R
handler.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
}
handler.rd.JSON(w, http.StatusOK, nil)
handler.rd.JSON(w, http.StatusOK, "The scheduler has been applied to the store.")
}

func (handler *grantLeaderHandler) ListConfig(w http.ResponseWriter, r *http.Request) {
Expand Down
9 changes: 5 additions & 4 deletions server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@
// @BasePath /pd/api/v1
func createRouter(prefix string, svr *server.Server) *mux.Router {
serviceMiddle := newServiceMiddlewareBuilder(svr)
registerPrefix := func(router *mux.Router, prefixPath string,
registerPrefix := func(router *mux.Router, prefixPath, name string,
handleFunc func(http.ResponseWriter, *http.Request), opts ...createRouteOption) {
routeCreateFunc(router.PathPrefix(prefixPath), serviceMiddle.createHandler(handleFunc),
getFunctionName(handleFunc), opts...)
name, opts...)
}
registerFunc := func(router *mux.Router, path string,
handleFunc func(http.ResponseWriter, *http.Request), opts ...createRouteOption) {
Expand Down Expand Up @@ -151,7 +151,8 @@
registerFunc(clusterRouter, "/schedulers/diagnostic/{name}", diagnosticHandler.GetDiagnosticResult, setMethods(http.MethodGet), setAuditBackend(prometheus))

schedulerConfigHandler := newSchedulerConfigHandler(svr, rd)
registerPrefix(apiRouter, "/scheduler-config", schedulerConfigHandler.GetSchedulerConfig, setAuditBackend(prometheus))
registerPrefix(apiRouter, "/scheduler-config", "HandleSchedulerConfig", schedulerConfigHandler.HandleSchedulerConfig, setMethods(http.MethodPost, http.MethodDelete, http.MethodPut, http.MethodPatch), setAuditBackend(localLog, prometheus))
Copy link
Member

Choose a reason for hiding this comment

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

How about SetSchedulerConfig?

Copy link
Member Author

Choose a reason for hiding this comment

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

It also includes the deletion method.

Copy link
Member

Choose a reason for hiding this comment

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

got

registerPrefix(apiRouter, "/scheduler-config", "GetSchedulerConfig", schedulerConfigHandler.HandleSchedulerConfig, setMethods(http.MethodGet), setAuditBackend(prometheus))

clusterHandler := newClusterHandler(svr, rd)
registerFunc(apiRouter, "/cluster", clusterHandler.GetCluster, setMethods(http.MethodGet), setAuditBackend(prometheus))
Expand Down Expand Up @@ -373,7 +374,7 @@

// API to set or unset failpoints
if enableFailPointAPI {
registerPrefix(apiRouter, "/fail", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
registerPrefix(apiRouter, "/fail", "FailPoint", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

Check warning on line 377 in server/api/router.go

View check run for this annotation

Codecov / codecov/patch

server/api/router.go#L377

Added line #L377 was not covered by tests
// The HTTP handler of failpoint requires the full path to be the failpoint path.
r.URL.Path = strings.TrimPrefix(r.URL.Path, prefix+apiPrefix+"/fail")
new(failpoint.HttpHandler).ServeHTTP(w, r)
Expand Down
2 changes: 1 addition & 1 deletion server/api/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func newSchedulerConfigHandler(svr *server.Server, rd *render.Render) *scheduler
}
}

func (h *schedulerConfigHandler) GetSchedulerConfig(w http.ResponseWriter, r *http.Request) {
func (h *schedulerConfigHandler) HandleSchedulerConfig(w http.ResponseWriter, r *http.Request) {
handler := h.svr.GetHandler()
sh, err := handler.GetSchedulerConfigHandler()
if err == nil && sh != nil {
Expand Down
5 changes: 4 additions & 1 deletion server/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ func (suite *serviceTestSuite) TestServiceLabels() {
accessPaths = suite.svr.GetServiceLabels("GetSchedulerConfig")
re.Len(accessPaths, 1)
re.Equal("/pd/api/v1/scheduler-config", accessPaths[0].Path)
re.Equal("", accessPaths[0].Method)
re.Equal("GET", accessPaths[0].Method)
accessPaths = suite.svr.GetServiceLabels("HandleSchedulerConfig")
re.Len(accessPaths, 4)
re.Equal("/pd/api/v1/scheduler-config", accessPaths[0].Path)

accessPaths = suite.svr.GetServiceLabels("ResignLeader")
re.Len(accessPaths, 1)
Expand Down
8 changes: 6 additions & 2 deletions tools/pd-ctl/tests/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,13 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "balance-region-scheduler"}, nil)
re.Contains(echo, "Success!")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "evict-leader-scheduler", "1"}, nil)
re.Contains(echo, "Success!")
re.Contains(echo, "Success! The scheduler is created.")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "add", "evict-leader-scheduler", "2"}, nil)
re.Contains(echo, "Success! The scheduler has been applied to the store.")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil)
re.Contains(echo, "Success!")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-2"}, nil)
re.Contains(echo, "Success!")
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "remove", "evict-leader-scheduler-1"}, nil)
re.Contains(echo, "404")
testutil.Eventually(re, func() bool { // wait for removed scheduler to be synced to scheduling server.
Expand Down Expand Up @@ -551,7 +555,7 @@ func (suite *schedulerTestSuite) checkScheduler(cluster *pdTests.TestCluster) {
return strings.Contains(echo, schedulerName)
})
echo = mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", schedulerName, "set", "recovery-duration", "100"}, nil)
re.Contains(echo, "Success!")
re.Contains(echo, "Success! Config updated.")
conf = make(map[string]interface{})
testutil.Eventually(re, func() bool {
mustExec(re, cmd, []string{"-u", pdAddr, "scheduler", "config", schedulerName, "show"}, &conf)
Expand Down
Loading