Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the Prometheus remote write export #2987

Merged
merged 1 commit into from
Apr 23, 2021
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
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 @@ -330,17 +330,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))
rakyll marked this conversation as resolved.
Show resolved Hide resolved
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)
}