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

Add middleware to PD microservice #8548

Open
HuSharp opened this issue Aug 21, 2024 · 1 comment
Open

Add middleware to PD microservice #8548

HuSharp opened this issue Aug 21, 2024 · 1 comment
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@HuSharp
Copy link
Member

HuSharp commented Aug 21, 2024

Enhancement Task

Currently, the API for microservice nodes(TSO/Scheduling) is implemented by the redirector and does not take into account the middleware of the API itself, such as audit logs.

redirector

pd/server/api/server.go

Lines 67 to 93 in f3602e3

router.PathPrefix(apiPrefix).Handler(negroni.New(
serverapi.NewRuntimeServiceValidator(svr, group),
serverapi.NewRedirector(svr,
serverapi.MicroserviceRedirectRule(
prefix+"/admin/reset-ts",
tsoapi.APIPathPrefix+"/admin/reset-ts",
constant.TSOServiceName,
[]string{http.MethodPost}),
serverapi.MicroserviceRedirectRule(
prefix+"/operators",
scheapi.APIPathPrefix+"/operators",
constant.SchedulingServiceName,
[]string{http.MethodPost, http.MethodGet, http.MethodDelete}),
serverapi.MicroserviceRedirectRule(
prefix+"/checker", // Note: this is a typo in the original code
scheapi.APIPathPrefix+"/checkers",
constant.SchedulingServiceName,
[]string{http.MethodPost, http.MethodGet}),
serverapi.MicroserviceRedirectRule(
prefix+"/region/id",
scheapi.APIPathPrefix+"/config/regions",
constant.SchedulingServiceName,
[]string{http.MethodGet},
func(r *http.Request) bool {
// The original code uses the path "/region/id" to get the region id.
// However, the path "/region/id" is used to get the region by id, which is not what we want.
return strings.Contains(r.URL.Path, "label")

PD-API Middlewares

func newServiceMiddlewareBuilder(s *server.Server) *serviceMiddlewareBuilder {
return &serviceMiddlewareBuilder{
svr: s,
handlers: []negroni.Handler{newRequestInfoMiddleware(s), newAuditMiddleware(s), newRateLimitMiddleware(s)},
}
}

ref

#5766
#7178
#7078

@HuSharp HuSharp added the type/enhancement The issue or PR belongs to an enhancement. label Aug 21, 2024
@lhy1024
Copy link
Contributor

lhy1024 commented Aug 21, 2024

Do we need to add them? cc @niubell @rleungx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants