@marcel91200 / caddy Mirror · read-only / commits / c82c231b
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddyhttp: Remove server name from metrics

For some reason this breaks automatic HTTP->HTTPS redirects. I am not sure why yet, but as a hotfix remove this until we understand it better.

Matthew Holt committed Sep 17, 2020 at 17:23 UTC c82c231ba7ec7c400e4d48ab943f57a6b29a2a2a
3 files changed -21
modules/caddyhttp/app.go
-2
@@ -226,8 +226,6 @@ func (app *App) Provision(ctx caddy.Context) error {
226 // route handler so that important security checks are done, etc.
227 primaryRoute := emptyHandler
228 if srv.Routes != nil {
229 - // inject the server name for observability purposes
230 - ctx.Context = contextWithServerName(ctx.Context, srvName)
229 err := srv.Routes.ProvisionHandlers(ctx)
230 if err != nil {
231 return fmt.Errorf("server %s: setting up route handlers: %v", srvName, err)
modules/caddyhttp/metrics.go
-4
@@ -94,10 +94,6 @@ func serverNameFromContext(ctx context.Context) string {
94 return srvName
95 }
96
97 -func contextWithServerName(ctx context.Context, serverName string) context.Context {
98 - return context.WithValue(ctx, ctxKeyServerName{}, serverName)
99 -}
100 -
97 type metricsInstrumentedHandler struct {
98 labels prometheus.Labels
99 statusLabels prometheus.Labels
modules/caddyhttp/metrics_test.go
-15
@@ -1,7 +1,6 @@
1 package caddyhttp
2
3 import (
4 - "context"
4 "errors"
5 "net/http"
6 "net/http/httptest"
@@ -10,20 +9,6 @@ import (
9 "github.com/prometheus/client_golang/prometheus/testutil"
10 )
11
13 -func TestServerNameFromContext(t *testing.T) {
14 - ctx := context.Background()
15 - expected := "UNKNOWN"
16 - if actual := serverNameFromContext(ctx); actual != expected {
17 - t.Errorf("Not equal: expected %q, but got %q", expected, actual)
18 - }
19 -
20 - in := "foo"
21 - ctx = contextWithServerName(ctx, in)
22 - if actual := serverNameFromContext(ctx); actual != in {
23 - t.Errorf("Not equal: expected %q, but got %q", in, actual)
24 - }
25 -}
26 -
12 func TestMetricsInstrumentedHandler(t *testing.T) {
13 handlerErr := errors.New("oh noes")
14 response := []byte("hello world!")