feat: do not use logger.Debug in critical path

This commit is contained in:
wpetit 2024-10-02 12:13:26 +02:00
parent 9bd1d0fbd7
commit 382d17cc85
1 changed files with 4 additions and 14 deletions

View File

@ -41,21 +41,11 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) {
for _, p := range proxies { for _, p := range proxies {
for _, from := range p.From { 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 { if matches := wildcard.Match(url.String(), from); !matches {
continue continue
} }
logger.Debug( proxyCtx := logger.With(ctx,
ctx, "proxy's from matched",
logger.F("from", from),
)
ctx = logger.With(ctx,
logger.F("proxy", p.Name), logger.F("proxy", p.Name),
logger.F("host", r.Host), logger.F("host", r.Host),
logger.F("remoteAddr", r.RemoteAddr), 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) 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 { if err != nil {
return r, errors.WithStack(err) 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.Scheme = toURL.Scheme
r.URL.Path = toURL.JoinPath(r.URL.Path).Path r.URL.Path = toURL.JoinPath(r.URL.Path).Path
ctx = withLayers(ctx, layers) proxyCtx = withLayers(proxyCtx, layers)
r = r.WithContext(ctx) r = r.WithContext(proxyCtx)
return r, nil return r, nil
} }