Skip to content

Commit

Permalink
clustermsi: be smarter about logging responses
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kuznetsov <[email protected]>
  • Loading branch information
stevekuznetsov committed Feb 10, 2025
1 parent 1e37c00 commit 2ab7e9c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/env/prod.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,24 @@ func ClientDebugLoggerMiddleware(log *logrus.Entry) policy.Policy {
log.WithError(err).Error("error closing response body")
}
// n.b.: we only send one request now, this is best-effort but would need to be updated if we use other methods
response := dataplane.ManagedIdentityCredentials{}
if err := json.Unmarshal(body, &response); err != nil {
log.WithError(err).Error("error unmarshalling response body")
var responseBody string
if resp.StatusCode == http.StatusOK {
response := dataplane.ManagedIdentityCredentials{}
if err := json.Unmarshal(body, &response); err != nil {
log.WithError(err).Error("error unmarshalling response body")
} else {
censorCredentials(&response)
censored, err := json.Marshal(response)
if err != nil {
log.WithError(err).Error("error marshalling response body after censoring")
}
responseBody = string(censored)
}
} else {
censorCredentials(&response)
log = log.WithField("body", string(body))
// error codes don't have anything in them that we need to censor
responseBody = string(body)
}
log = log.WithField("body", responseBody)
resp.Body = io.NopCloser(bytes.NewBuffer(body)) // reset body so the upstream round-trippers can use it
}
log.Info("Received response.")
Expand Down

0 comments on commit 2ab7e9c

Please sign in to comment.