Skip to content

Commit 73d019a

Browse files
glintonbitcharmer
authored andcommitted
Buffer metrics from failed writes in influxdb2 output if token is invalid (influxdata#5792)
1 parent ecbf6e1 commit 73d019a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

plugins/outputs/influxdb_v2/http.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,11 @@ func (c *httpClient) writeBatch(ctx context.Context, bucket string, metrics []te
228228
}
229229

230230
switch resp.StatusCode {
231-
case http.StatusBadRequest, http.StatusUnauthorized,
232-
http.StatusForbidden, http.StatusRequestEntityTooLarge:
231+
case http.StatusBadRequest, http.StatusRequestEntityTooLarge:
233232
log.Printf("E! [outputs.influxdb_v2] Failed to write metric: %s\n", desc)
234233
return nil
234+
case http.StatusUnauthorized, http.StatusForbidden:
235+
return fmt.Errorf("failed to write metric: %s", desc)
235236
case http.StatusTooManyRequests, http.StatusServiceUnavailable:
236237
retryAfter := resp.Header.Get("Retry-After")
237238
retry, err := strconv.Atoi(retryAfter)

plugins/outputs/influxdb_v2/influxdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
165165
log.Printf("E! [outputs.influxdb_v2] when writing to [%s]: %v", client.URL(), err)
166166
}
167167

168-
return errors.New("could not write any address")
168+
return err
169169
}
170170

171171
func (i *InfluxDB) getHTTPClient(ctx context.Context, url *url.URL, proxy *url.URL) (Client, error) {

0 commit comments

Comments
 (0)