mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 05:11:04 +00:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									3ee663dee1
								
							
						
					
					
						commit
						c82c231ba7
					
				
					 3 changed files with 0 additions and 21 deletions
				
			
		|  | @ -226,8 +226,6 @@ func (app *App) Provision(ctx caddy.Context) error { | ||||||
| 		// route handler so that important security checks are done, etc. | 		// route handler so that important security checks are done, etc. | ||||||
| 		primaryRoute := emptyHandler | 		primaryRoute := emptyHandler | ||||||
| 		if srv.Routes != nil { | 		if srv.Routes != nil { | ||||||
| 			// inject the server name for observability purposes |  | ||||||
| 			ctx.Context = contextWithServerName(ctx.Context, srvName) |  | ||||||
| 			err := srv.Routes.ProvisionHandlers(ctx) | 			err := srv.Routes.ProvisionHandlers(ctx) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				return fmt.Errorf("server %s: setting up route handlers: %v", srvName, err) | 				return fmt.Errorf("server %s: setting up route handlers: %v", srvName, err) | ||||||
|  |  | ||||||
|  | @ -94,10 +94,6 @@ func serverNameFromContext(ctx context.Context) string { | ||||||
| 	return srvName | 	return srvName | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func contextWithServerName(ctx context.Context, serverName string) context.Context { |  | ||||||
| 	return context.WithValue(ctx, ctxKeyServerName{}, serverName) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| type metricsInstrumentedHandler struct { | type metricsInstrumentedHandler struct { | ||||||
| 	labels       prometheus.Labels | 	labels       prometheus.Labels | ||||||
| 	statusLabels prometheus.Labels | 	statusLabels prometheus.Labels | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| package caddyhttp | package caddyhttp | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" |  | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"net/http/httptest" | 	"net/http/httptest" | ||||||
|  | @ -10,20 +9,6 @@ import ( | ||||||
| 	"github.com/prometheus/client_golang/prometheus/testutil" | 	"github.com/prometheus/client_golang/prometheus/testutil" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func TestServerNameFromContext(t *testing.T) { |  | ||||||
| 	ctx := context.Background() |  | ||||||
| 	expected := "UNKNOWN" |  | ||||||
| 	if actual := serverNameFromContext(ctx); actual != expected { |  | ||||||
| 		t.Errorf("Not equal: expected %q, but got %q", expected, actual) |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	in := "foo" |  | ||||||
| 	ctx = contextWithServerName(ctx, in) |  | ||||||
| 	if actual := serverNameFromContext(ctx); actual != in { |  | ||||||
| 		t.Errorf("Not equal: expected %q, but got %q", in, actual) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestMetricsInstrumentedHandler(t *testing.T) { | func TestMetricsInstrumentedHandler(t *testing.T) { | ||||||
| 	handlerErr := errors.New("oh noes") | 	handlerErr := errors.New("oh noes") | ||||||
| 	response := []byte("hello world!") | 	response := []byte("hello world!") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Holt
						Matthew Holt