Skip to content

Commit

Permalink
check nillable props in log roundtripper to prevent panic (#1175)
Browse files Browse the repository at this point in the history
* check nillable props in log roundtripper to prevent panic

* fix lint warnings
  • Loading branch information
nilsgstrabo authored Aug 21, 2024
1 parent 52aa6da commit 8c09428
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 2 additions & 2 deletions charts/radix-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: radix-operator
version: 1.37.8
appVersion: 1.57.16
version: 1.37.9
appVersion: 1.57.17
kubeVersion: ">=1.24.0"
description: Radix Operator
keywords:
Expand Down
19 changes: 13 additions & 6 deletions pkg/apis/utils/http/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ import (
// http.RoundTripper to observe the request duration
func LogRequests(t http.RoundTripper) http.RoundTripper {
return RoundTripperFunc(func(r *http.Request) (*http.Response, error) {
logger := log.Ctx(r.Context()).With().
Str("method", r.Method).
Str("path", r.URL.Path).
Logger()
ev := log.Ctx(r.Context()).Trace().Str("method", r.Method)
if r.URL != nil {
ev = ev.Str("path", r.URL.Path)
}
start := time.Now()
resp, err := t.RoundTrip(r)
elapsedMs := time.Since(start).Milliseconds()
logger.Trace().Err(err).Int64("elapsed_ms", elapsedMs).Int("status", resp.StatusCode).Msg(http.StatusText(resp.StatusCode))
ev = ev.Int64("elapsed_ms", time.Since(start).Milliseconds())
var msg string
if err == nil {
msg = http.StatusText(resp.StatusCode)
ev = ev.Int("status", resp.StatusCode)
} else {
ev = ev.Err(err)
}
ev.Msg(msg)
return resp, err
})
}

0 comments on commit 8c09428

Please sign in to comment.