Skip to content

Commit 06a9cd4

Browse files
authored
Merge pull request #311 from coroot/remote_write_content_length
send remote-write requests with an explicit Content-Length
2 parents b006f1c + a5999af commit 06a9cd4

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

prom/remote_writer.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package prom
22

33
import (
4+
"bytes"
45
"crypto/md5"
56
"encoding/hex"
67
"errors"
@@ -130,12 +131,13 @@ func (a *Agent) sendLoop() {
130131
}
131132

132133
func (a *Agent) send(fPath string) error {
133-
f, err := os.Open(fPath)
134+
// Read into memory so the request has an explicit Content-Length; streaming an *os.File
135+
// makes net/http use chunked encoding, which some middleboxes reset (seen as EOF).
136+
payload, err := os.ReadFile(fPath)
134137
if err != nil {
135138
return err
136139
}
137-
defer f.Close()
138-
req, err := http.NewRequest(http.MethodPost, a.url.String(), f)
140+
req, err := http.NewRequest(http.MethodPost, a.url.String(), bytes.NewReader(payload))
139141
if err != nil {
140142
return err
141143
}

0 commit comments

Comments
 (0)