Skip to content

Commit

Permalink
httptransport: fix request_id logging
Browse files Browse the repository at this point in the history
The final HTTP status message was getting an earlier Context which was
missing the request_id key.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
(cherry picked from commit 378a4b5)
  • Loading branch information
hdonnay committed Apr 5, 2023
1 parent 5fd2656 commit 922f33d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion httptransport/indexer_v1.go
Expand Up @@ -56,6 +56,7 @@ var _ http.Handler = (*IndexerV1)(nil)
func (h *IndexerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
wr := responserecorder.NewResponseRecorder(w)
r = withRequestID(r)
defer func() {
if f, ok := wr.(http.Flusher); ok {
f.Flush()
Expand All @@ -68,7 +69,7 @@ func (h *IndexerV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Dur("duration", time.Since(start)).
Msg("handled HTTP request")
}()
h.inner.ServeHTTP(wr, withRequestID(r))
h.inner.ServeHTTP(wr, r)
}

func (h *IndexerV1) indexReport(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 2 additions & 1 deletion httptransport/matcher_v1.go
Expand Up @@ -64,6 +64,7 @@ var _ http.Handler = (*MatcherV1)(nil)
func (h *MatcherV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
wr := responserecorder.NewResponseRecorder(w)
r = withRequestID(r)
defer func() {
if f, ok := wr.(http.Flusher); ok {
f.Flush()
Expand All @@ -76,7 +77,7 @@ func (h *MatcherV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Dur("duration", time.Since(start)).
Msg("handled HTTP request")
}()
h.inner.ServeHTTP(wr, withRequestID(r))
h.inner.ServeHTTP(wr, r)
}

func (h *MatcherV1) vulnerabilityReport(w http.ResponseWriter, r *http.Request) {
Expand Down
3 changes: 2 additions & 1 deletion httptransport/notification_v1.go
Expand Up @@ -56,6 +56,7 @@ func NewNotificationV1(_ context.Context, prefix string, srv notifier.Service, t
func (h *NotificationV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
start := time.Now()
wr := responserecorder.NewResponseRecorder(w)
r = withRequestID(r)
defer func() {
if f, ok := wr.(http.Flusher); ok {
f.Flush()
Expand All @@ -68,7 +69,7 @@ func (h *NotificationV1) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Dur("duration", time.Since(start)).
Msg("handled HTTP request")
}()
h.inner.ServeHTTP(wr, withRequestID(r))
h.inner.ServeHTTP(wr, r)
}

func (h *NotificationV1) serveHTTP(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 922f33d

Please sign in to comment.