Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion probe/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package probe
import (
"bytes"
"encoding/json"
"log"
"net/http"
"time"

Expand Down Expand Up @@ -45,11 +46,14 @@ func (di *diskInfoImpl) Export(metrics *DiskMetrics) error {
return err
}

var resp *http.Response
for retryCounter := 0; retryCounter < maxRetryCount; retryCounter++ {
_, err = http.Post(di.url, "application/json", bytes.NewReader(s))
resp, err = http.Post(di.url, "application/json", bytes.NewReader(s))
if err == nil {
Comment on lines +51 to 52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check err before touching resp.Body.Close()?
resp can be nil on request errors.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I'll fix this.

_ = resp.Body.Close()
return nil
}
log.Printf("failed to post data: %v", err)
time.Sleep(time.Second * retryIntervalSec)
}

Expand Down