summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/routes.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2020-09-17 14:01:20 -0400
committerGitHub <noreply@github.com>2020-09-17 12:01:20 -0600
commit8ec51bbede59e1fa6ac24de3607f6e7bb3e3a654 (patch)
treef598667a352f4606979965e200eedecc9aa4e4e8 /modules/caddyhttp/routes.go
parentbc453fa6ae36287c90d2bf6941cb686490090df2 (diff)
metrics: Initial integration of Prometheus metrics (#3709)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'modules/caddyhttp/routes.go')
-rw-r--r--modules/caddyhttp/routes.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go
index 10e0c9d..be23d39 100644
--- a/modules/caddyhttp/routes.go
+++ b/modules/caddyhttp/routes.go
@@ -157,7 +157,7 @@ func (routes RouteList) ProvisionHandlers(ctx caddy.Context) error {
// pre-compile the middleware handler chain
for _, midhandler := range routes[i].Handlers {
- routes[i].middleware = append(routes[i].middleware, wrapMiddleware(midhandler))
+ routes[i].middleware = append(routes[i].middleware, wrapMiddleware(ctx, midhandler))
}
}
return nil
@@ -242,7 +242,13 @@ func wrapRoute(route Route) Middleware {
// we need to pull this particular MiddlewareHandler
// pointer into its own stack frame to preserve it so it
// won't be overwritten in future loop iterations.
-func wrapMiddleware(mh MiddlewareHandler) Middleware {
+func wrapMiddleware(ctx caddy.Context, mh MiddlewareHandler) Middleware {
+ // first, wrap the middleware with metrics instrumentation
+ metricsHandler := newMetricsInstrumentedHandler(
+ serverNameFromContext(ctx.Context),
+ caddy.GetModuleName(mh),
+ mh,
+ )
return func(next Handler) Handler {
// copy the next handler (it's an interface, so it's
// just a very lightweight copy of a pointer); this
@@ -253,7 +259,7 @@ func wrapMiddleware(mh MiddlewareHandler) Middleware {
return HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
// TODO: This is where request tracing could be implemented
// TODO: see what the std lib gives us in terms of stack tracing too
- return mh.ServeHTTP(w, r, nextCopy)
+ return metricsHandler.ServeHTTP(w, r, nextCopy)
})
}
}