From d16ede358a2ec049bda28bf37e79c9cfcaa64c29 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 17 Sep 2020 23:46:24 -0400 Subject: metrics: Fix hidden panic while observing with bad exemplars (#3733) * metrics: Fixing panic while observing with bad exemplars Signed-off-by: Dave Henderson * Minor cleanup The server is already added to the context. So, we can simply use that to get the server name, which is a field on the server. * Add integration test for auto HTTP->HTTPS redirects A test like this would have caught the problem in the first place Co-authored-by: Matthew Holt --- modules/caddyhttp/routes.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'modules/caddyhttp/routes.go') diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go index be23d39..83e6354 100644 --- a/modules/caddyhttp/routes.go +++ b/modules/caddyhttp/routes.go @@ -243,12 +243,9 @@ func wrapRoute(route Route) Middleware { // pointer into its own stack frame to preserve it so it // won't be overwritten in future loop iterations. func wrapMiddleware(ctx caddy.Context, mh MiddlewareHandler) Middleware { - // first, wrap the middleware with metrics instrumentation - metricsHandler := newMetricsInstrumentedHandler( - serverNameFromContext(ctx.Context), - caddy.GetModuleName(mh), - mh, - ) + // wrap the middleware with metrics instrumentation + metricsHandler := newMetricsInstrumentedHandler(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 -- cgit v1.2.3