Conversation
6176a41 to
ebb5295
Compare
bboreham
left a comment
There was a problem hiding this comment.
Code is broadly fine, but I observe that it goes to a lot of work to capture response headers when they are not asked for in the original issue. I can't immediately think why they would be useful in a 5xx.
middleware/response.go
Outdated
| // response headers if `statusCode` is a 5XX. | ||
| func (b *badResponseLogger) WriteHeader(statusCode int) { | ||
| b.statusCode = statusCode | ||
| b.recorder.WriteHeader(statusCode) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
middleware/response.go
Outdated
| recorder: httptest.NewRecorder(), | ||
| logBody: false, | ||
| bodyBytesLeft: maxResponseBodyInLogs, | ||
| statusCode: http.StatusOK, |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
middleware/response.go
Outdated
|
|
||
| if len(data) > b.bodyBytesLeft { | ||
| b.recorder.Write(data[:b.bodyBytesLeft]) | ||
| b.recorder.WriteString("…") |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
middleware/response.go
Outdated
|
|
||
| if len(data) > b.bodyBytesLeft { | ||
| b.recorder.Write(data[:b.bodyBytesLeft]) | ||
| b.recorder.WriteString("…") |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
middleware/response.go
Outdated
| } | ||
|
|
||
| // WriteHeader implements http.ResponseWriter. It will immediately log the | ||
| // response headers if `statusCode` is a 5XX. |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
middleware/logging.go
Outdated
| logWithRequest(r).Warnf("Is websocket request: %v\n%s", IsWSHandshakeRequest(r), string(headers)) | ||
| response, err := i.dumpResponse() | ||
| if err != nil { | ||
| logWithRequest(r).Errorf("Could not dump response headers: %v", err) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
Does it really? It's been a while since I've looked at this, but I thought most of the work was around making sure we're still streaming headers & body, and that we don't accidentally store massive bodies in memory while building up a log entry. I'm not sure what I'd change if we wanted to stop capturing response headers. Maybe change |
meaning we build a data structure of headers on every response, including the 200s and 400s that we're not going to log
Exactly. Like a |
|
Makes sense. Doing that means that |
|
PTAL @bboreham |
|
Suggest you note this PR makes a quiet change, in that the order of request and headers is reversed in the logs, when |
Part of weaveworks/service#1233
This is kind of a significant change, as it intercepts all incoming requests. I haven't done much in the way of testing.
Also changes the logging order slightly. Previously, when
LogRequestHeaderswas on, we would log headers then request/response summary (method, status, etc). Now, we log method, status, etc. then headers.