Skip to content

Commit

Permalink
pkg/canary: use default HTTP client when reading from Loki
Browse files Browse the repository at this point in the history
The documentation[1] for net/http.Client says the following:

  A Client is an HTTP client. Its zero value (DefaultClient) is a usable
  client that uses DefaultTransport.

  The Client's Transport typically has internal state (cached TCP
  connections), so Clients should be reused instead of created as needed.
  Clients are safe for concurrent use by multiple goroutines.

  A Client is higher-level than a RoundTripper (such as Transport) and
  additionally handles HTTP details such as cookies and redirects.

Canary was creating a new http.Client every time a query request was
made to Loki, causing a new TCP connection to be established each time.
If Loki has an outage, it's possible to get into a situation where all
websocket requests are failing and for a high volume of requests to go
through the normal query route. This can possibly lead to networking
issues like socket starvation.

[1]: https://golang.org/pkg/net/http/#Client
  • Loading branch information
rfratto authored and Ed Welch committed Oct 9, 2019
1 parent 2cb3c82 commit f1c1097
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions pkg/canary/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,14 @@ func (r *Reader) Query(start time.Time, end time.Time) ([]time.Time, error) {
}
_, _ = fmt.Fprintf(r.w, "Querying loki for missing values with query: %v\n", u.String())

client := &http.Client{}

req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}

req.SetBasicAuth(r.user, r.pass)

resp, err := client.Do(req)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f1c1097

Please sign in to comment.