Skip to content

Commit

Permalink
server/api: add an API to configure failpoints in runtime (#3488) (#3809
Browse files Browse the repository at this point in the history
)

Signed-off-by: Yilin Chen <sticnarf@gmail.com>

Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com>

Co-authored-by: Ti Chi Robot <71242396+ti-chi-bot@users.noreply.github.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
3 people authored Jul 6, 2021
1 parent 1b82288 commit 4a50ce9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion server/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"context"
"net/http"
"net/http/pprof"
"strings"

"github.com/gorilla/mux"
"github.com/pingcap/failpoint"
"github.com/tikv/pd/server"
"github.com/unrolled/render"
)
Expand Down Expand Up @@ -51,7 +53,8 @@ func createRouter(ctx context.Context, prefix string, svr *server.Server) *mux.R
rootRouter := mux.NewRouter().PathPrefix(prefix).Subrouter()
handler := svr.GetHandler()

apiRouter := rootRouter.PathPrefix("/api/v1").Subrouter()
apiPrefix := "/api/v1"
apiRouter := rootRouter.PathPrefix(apiPrefix).Subrouter()

clusterRouter := apiRouter.NewRoute().Subrouter()
clusterRouter.Use(newClusterMiddleware(svr).Middleware)
Expand Down Expand Up @@ -211,6 +214,15 @@ func createRouter(ctx context.Context, prefix string, svr *server.Server) *mux.R
apiRouter.HandleFunc("/gc/safepoint", serviceGCSafepointHandler.List).Methods("GET")
apiRouter.HandleFunc("/gc/safepoint/{service_id}", serviceGCSafepointHandler.Delete).Methods("DELETE")

// API to set or unset failpoints
failpoint.Inject("enableFailpointAPI", func() {
apiRouter.PathPrefix("/fail").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// 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)
})
})

// Deprecated
rootRouter.Handle("/health", newHealthHandler(svr, rd)).Methods("GET")
// Deprecated
Expand Down

0 comments on commit 4a50ce9

Please sign in to comment.