From 5115b714a824f6e714a03a2ddf061370b24578fd Mon Sep 17 00:00:00 2001 From: Lukasz Mierzwa Date: Tue, 26 May 2026 14:35:46 +0100 Subject: [PATCH] fix(backend): stop using middleware.RealIP --- cmd/karma/exporter.go | 2 +- cmd/karma/main.go | 2 +- cmd/karma/tests/testscript/035_log_requests.txt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/karma/exporter.go b/cmd/karma/exporter.go index 35c9d8659..55c439b2e 100644 --- a/cmd/karma/exporter.go +++ b/cmd/karma/exporter.go @@ -71,7 +71,7 @@ func promMiddleware(next http.Handler) http.Handler { if config.Config.Log.Requests { slog.Info( "Request completed", - slog.String("address", r.RemoteAddr), + slog.String("address", middleware.GetClientIP(r.Context())), slog.String("path", r.URL.RequestURI()), slog.String("duration", time.Since(start).String()), slog.String("method", r.Method), diff --git a/cmd/karma/main.go b/cmd/karma/main.go index 9f19cb5c3..b100f97e3 100644 --- a/cmd/karma/main.go +++ b/cmd/karma/main.go @@ -80,8 +80,8 @@ func setupRouter(router *chi.Mux, historyPoller *historyPoller) { _ = mime.AddExtensionType(".ico", "image/x-icon") router.Use(proxyPathFixMiddleware) + router.Use(middleware.ClientIPFromRemoteAddr) router.Use(promMiddleware) - router.Use(middleware.RealIP) compressor := middleware.NewCompressor(flate.DefaultCompression) router.Use(compressor.Handler) diff --git a/cmd/karma/tests/testscript/035_log_requests.txt b/cmd/karma/tests/testscript/035_log_requests.txt index cd5df3cc5..3a3880252 100644 --- a/cmd/karma/tests/testscript/035_log_requests.txt +++ b/cmd/karma/tests/testscript/035_log_requests.txt @@ -3,8 +3,8 @@ exec bash -x ./test.sh & exec karma --pid-file=karma.pid --alertmanager.uri=http://127.0.0.1:7035 --listen.address=127.0.0.1 --listen.port=8035 --log.requests ! stdout . -stderr 'level=INFO msg="Request completed" address=127.0.0.1:[0-9]+ path=/alerts.json duration=.+ method=POST code=200 bytes=[0-9]+' -stderr 'level=INFO msg="Request completed" address=127.0.0.1:[0-9]+ path=/alerts.json duration=.+ method=POST code=200 bytes=[0-9]+' +stderr 'level=INFO msg="Request completed" address=127.0.0.1 path=/alerts.json duration=.+ method=POST code=200 bytes=[0-9]+' +stderr 'level=INFO msg="Request completed" address=127.0.0.1 path=/alerts.json duration=.+ method=POST code=200 bytes=[0-9]+' wait -- test.sh --