Skip to content

Commit

Permalink
Simplify the Prometheus remote write export (#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakyll authored Apr 23, 2021
1 parent e51d5dc commit 3735180
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions exporter/prometheusremotewriteexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
package prometheusremotewriteexporter

import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"net/url"
Expand Down Expand Up @@ -334,17 +334,13 @@ func (prwe *PrwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequ
// 5xx errors are recoverable and the exporter should retry
// Reference for different behavior according to status code:
// https://github.com/prometheus/prometheus/pull/2552/files#diff-ae8db9d16d8057358e49d694522e7186
if resp.StatusCode/100 != 2 {
scanner := bufio.NewScanner(io.LimitReader(resp.Body, 256))
var line string
if scanner.Scan() {
line = scanner.Text()
}
err := fmt.Errorf("server returned HTTP status %v: %v ", resp.Status, line)
if resp.StatusCode >= 500 && resp.StatusCode < 600 {
return err
}
return consumererror.Permanent(err)
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
return nil
}
return nil
body, err := ioutil.ReadAll(io.LimitReader(resp.Body, 256))
rerr := fmt.Errorf("remote write returned HTTP status %v; err = %v: %s", resp.Status, err, body)
if resp.StatusCode >= 500 && resp.StatusCode < 600 {
return rerr
}
return consumererror.Permanent(rerr)
}

0 comments on commit 3735180

Please sign in to comment.