Browse code

cmd/dockerd: pass debug-router instead of constructing in CreateMux

Now that debug-routes are identical to regular routers, we can pass them
the same as those routers. With this, the daemon also logs those routes
as part of its startup (when in debug mode).

Before this patch, only non-debug endpoints would be logged:

DEBU[2024-12-08T15:24:47.320933959Z] Registering routers
...
DEBU[2024-12-08T15:24:47.324420709Z] Registering POST, /networks/{id:.*}/disconnect
DEBU[2024-12-08T15:24:47.324447251Z] Registering POST, /networks/prune
DEBU[2024-12-08T15:24:47.324460626Z] Registering DELETE, /networks/{id:.*}
INFO[2024-12-08T15:24:47.324828334Z] API listen on /var/run/docker.sock

With this patch, debug endpoints are also logged:

DEBU[2024-12-08T15:24:47.320933959Z] Registering routers
...
DEBU[2024-12-08T15:24:47.324420709Z] Registering POST, /networks/{id:.*}/disconnect
DEBU[2024-12-08T15:24:47.324447251Z] Registering POST, /networks/prune
DEBU[2024-12-08T15:24:47.324460626Z] Registering DELETE, /networks/{id:.*}
DEBU[2024-12-08T15:24:47.324486834Z] Registering GET, /debug/vars
DEBU[2024-12-08T15:24:47.324506751Z] Registering GET, /debug/pprof/
DEBU[2024-12-08T15:24:47.324532126Z] Registering GET, /debug/pprof/cmdline
DEBU[2024-12-08T15:24:47.324549293Z] Registering GET, /debug/pprof/profile
DEBU[2024-12-08T15:24:47.324564501Z] Registering GET, /debug/pprof/symbol
DEBU[2024-12-08T15:24:47.324582043Z] Registering GET, /debug/pprof/trace
DEBU[2024-12-08T15:24:47.324604751Z] Registering GET, /debug/pprof/{name}
INFO[2024-12-08T15:24:47.324828334Z] API listen on /var/run/docker.sock

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/12/09 00:22:46
Showing 2 changed files
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"github.com/docker/docker/api/server/httputils"
10 10
 	"github.com/docker/docker/api/server/middleware"
11 11
 	"github.com/docker/docker/api/server/router"
12
-	"github.com/docker/docker/api/server/router/debug"
13 12
 	"github.com/docker/docker/api/types"
14 13
 	"github.com/docker/docker/dockerversion"
15 14
 	"github.com/gorilla/mux"
... ...
@@ -80,13 +79,7 @@ func (s *Server) CreateMux(routers ...router.Router) *mux.Router {
80 80
 		}
81 81
 	}
82 82
 
83
-	debugRouter := debug.NewRouter()
84
-	for _, r := range debugRouter.Routes() {
85
-		f := s.makeHTTPHandler(r.Handler(), r.Method()+" "+r.Path())
86
-		m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f)
87
-		m.Path(r.Path()).Methods(r.Method()).Handler(f)
88
-	}
89
-
83
+	// Setup handlers for undefined paths and methods
90 84
 	notFoundHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
91 85
 		_ = httputils.WriteJSON(w, http.StatusNotFound, &types.ErrorResponse{
92 86
 			Message: "page not found",
... ...
@@ -25,6 +25,7 @@ import (
25 25
 	"github.com/docker/docker/api/server/router/build"
26 26
 	checkpointrouter "github.com/docker/docker/api/server/router/checkpoint"
27 27
 	"github.com/docker/docker/api/server/router/container"
28
+	debugrouter "github.com/docker/docker/api/server/router/debug"
28 29
 	distributionrouter "github.com/docker/docker/api/server/router/distribution"
29 30
 	grpcrouter "github.com/docker/docker/api/server/router/grpc"
30 31
 	"github.com/docker/docker/api/server/router/image"
... ...
@@ -716,6 +717,7 @@ func buildRouters(opts routerOptions) []router.Router {
716 716
 		pluginrouter.NewRouter(opts.daemon.PluginManager()),
717 717
 		distributionrouter.NewRouter(opts.daemon.ImageBackend()),
718 718
 		network.NewRouter(opts.daemon, opts.cluster),
719
+		debugrouter.NewRouter(),
719 720
 	}
720 721
 
721 722
 	if opts.buildBackend != nil {