Skip to content

Commit

Permalink
Use NewRequestWithContext, remove unnecessary code (#1931)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Oct 13, 2020
1 parent 1b61151 commit dc065c1
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti
compressedData := snappy.Encode(buf, data)

// Create the HTTP POST request to send to the endpoint
httpReq, err := http.NewRequest("POST", prwe.endpointURL.String(), bytes.NewReader(compressedData))
httpReq, err := http.NewRequestWithContext(ctx, "POST", prwe.endpointURL.String(), bytes.NewReader(compressedData))
if err != nil {
return err
}
Expand All @@ -234,11 +234,6 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti
httpReq.Header.Set("Content-Type", "application/x-protobuf")
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")

httpReq = httpReq.WithContext(ctx)

_, cancel := context.WithTimeout(context.Background(), prwe.client.Timeout)
defer cancel()

httpResp, err := prwe.client.Do(httpReq)
if err != nil {
return err
Expand Down

0 comments on commit dc065c1

Please sign in to comment.