Skip to content

Commit

Permalink
x-pack/filebeat/input/websocket: fix logging
Browse files Browse the repository at this point in the history
The body was previously not being logged since an io.ReadCloser is not JSON
serialisable type.
  • Loading branch information
efd6 committed Jul 9, 2024
1 parent 88d646a commit 3084ea4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion x-pack/filebeat/input/websocket/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
package websocket

import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/url"
"reflect"
"time"
Expand Down Expand Up @@ -109,7 +111,13 @@ func (i input) run(env v2.Context, src *source, cursor map[string]interface{}, p
headers := formHeader(cfg)
c, resp, err := websocket.DefaultDialer.DialContext(ctx, url, headers)
if resp != nil && resp.Body != nil {
log.Debugw("websocket connection response", "body", resp.Body)
var buf bytes.Buffer
const limit = 1e4
io.CopyN(&buf, resp.Body, limit)

Check failure on line 116 in x-pack/filebeat/input/websocket/input.go

View workflow job for this annotation

GitHub Actions / lint (windows)

Error return value of `io.CopyN` is not checked (errcheck)
if n, _ := io.Copy(io.Discard, resp.Body); n != 0 {
buf.WriteString("... truncated")
}
log.Debugw("websocket connection response", "body", &buf)
resp.Body.Close()
}
if err != nil {
Expand Down

0 comments on commit 3084ea4

Please sign in to comment.