From 382d17cc8561b14cadda196c7f0b646a82fe7567 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 2 Oct 2024 12:13:26 +0200 Subject: [PATCH] feat: do not use logger.Debug in critical path --- internal/proxy/director/director.go | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/internal/proxy/director/director.go b/internal/proxy/director/director.go index 7ebba03..c2480ec 100644 --- a/internal/proxy/director/director.go +++ b/internal/proxy/director/director.go @@ -41,21 +41,11 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) { for _, p := range proxies { for _, from := range p.From { - logger.Debug( - ctx, "matching request with proxy's from", - logger.F("from", from), - ) - if matches := wildcard.Match(url.String(), from); !matches { continue } - logger.Debug( - ctx, "proxy's from matched", - logger.F("from", from), - ) - - ctx = logger.With(ctx, + proxyCtx := logger.With(ctx, logger.F("proxy", p.Name), logger.F("host", r.Host), logger.F("remoteAddr", r.RemoteAddr), @@ -63,7 +53,7 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) { metricProxyRequestsTotal.With(prometheus.Labels{metricLabelProxy: string(p.Name)}).Add(1) - proxyLayers, err := d.getLayers(ctx, p.Name) + proxyLayers, err := d.getLayers(proxyCtx, p.Name) if err != nil { return r, errors.WithStack(err) } @@ -83,8 +73,8 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) { r.URL.Scheme = toURL.Scheme r.URL.Path = toURL.JoinPath(r.URL.Path).Path - ctx = withLayers(ctx, layers) - r = r.WithContext(ctx) + proxyCtx = withLayers(proxyCtx, layers) + r = r.WithContext(proxyCtx) return r, nil }