mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Timeout after 30 seconds when posting usage analytics (#1577)
This commit is contained in:
parent
084fcdfec4
commit
e63e690fdb
2 changed files with 10 additions and 3 deletions
1
changes/timeout-in-request-analytics
Normal file
1
changes/timeout-in-request-analytics
Normal file
|
|
@ -0,0 +1 @@
|
|||
* When posting usage analytics, timeout after 30secs.
|
||||
|
|
@ -426,12 +426,18 @@ func trySendStatistics(ds fleet.Datastore, frequency time.Duration, url string)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.Post(url, "application/json", bytes.NewBuffer(statsBytes))
|
||||
client := &http.Client{Timeout: 30 * time.Second}
|
||||
req, err := http.NewRequest("POST", url, bytes.NewBuffer(statsBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if req.StatusCode != http.StatusOK {
|
||||
return errors.Errorf("Error posting to %s: %d", url, req.StatusCode)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return errors.Errorf("Error posting to %s: %d", url, resp.StatusCode)
|
||||
}
|
||||
return ds.RecordStatisticsSent()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue