Skip to content

Commit 0dac15e

Browse files
committed
interceptor: make request logging optional
Signed-off-by: Jan Wozniak <[email protected]>
1 parent 9b21a5a commit 0dac15e

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This changelog keeps track of work items that have been completed and are ready
3131

3232
### Improvements
3333

34-
- **General**: TODO ([#TODO](https://github.com/kedacore/http-add-on/issues/TODO))
34+
- **General**: Make interceptor request logging optional ([#1375](https://github.com/kedacore/http-add-on/pull/1375))
3535

3636
### Fixes
3737

docs/operate.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ Optional variables
7070
`OTEL_EXPORTER_OTLP_TRACES_INSECURE` - To send traces to the tracing via HTTP rather than HTTPS (`false` by default)
7171
`OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` - The batcher timeout in seconds to send batch of data points (`5` by default)
7272

73+
### Configuring interceptor proxy request logging
74+
75+
The interceptor proxy can log incoming requests for debugging and monitoring purposes. Request logging can be enabled by setting the `KEDA_HTTP_LOG_REQUESTS` environment variable to `true` on the interceptor deployment (`false` by default).
76+
7377
### Configuring Service Failover

interceptor/config/serving.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Serving struct {
5151
ProfilingAddr string `envconfig:"PROFILING_BIND_ADDRESS" default:""`
5252
// EnableColdStartHeader enables/disables the X-KEDA-HTTP-Cold-Start response header
5353
EnableColdStartHeader bool `envconfig:"KEDA_HTTP_ENABLE_COLD_START_HEADER" default:"true"`
54+
// LogRequests enables/disables logging of incoming requests
55+
LogRequests bool `envconfig:"KEDA_HTTP_LOG_REQUESTS" default:"false"`
5456
}
5557

5658
// Parse parses standard configs using envconfig and returns a pointer to the

interceptor/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,13 @@ func runProxyServer(
463463
rootHandler = otelhttp.NewHandler(rootHandler, "keda-http-interceptor")
464464
}
465465

466+
var requestLogger *logr.Logger
467+
if serving.LogRequests {
468+
requestLogger = logger
469+
}
470+
466471
rootHandler = middleware.NewLogging(
467-
logger,
472+
requestLogger,
468473
rootHandler,
469474
)
470475

interceptor/middleware/logging.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func NewLogging(logger logr.Logger, upstreamHandler http.Handler) *Logging {
3030
var _ http.Handler = (*Logging)(nil)
3131

3232
func (lm *Logging) ServeHTTP(w http.ResponseWriter, r *http.Request) {
33+
if r.logger == nil {
34+
lm.upstreamHandler.ServeHTTP(w, r)
35+
return
36+
}
3337
r = util.RequestWithLogger(r, lm.logger.WithName("LoggingMiddleware"))
3438
w = newResponseWriter(w)
3539

0 commit comments

Comments
 (0)