mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Use typed errors in prometheus remote writer (#93500)
Strongly typed writer errors
This commit is contained in:
@@ -2,6 +2,7 @@ package writer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -29,6 +30,11 @@ const (
|
||||
PrometheusDuplicateTimestampError = "duplicate sample for timestamp"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrWriteFailure = errors.New("failed to write time series")
|
||||
ErrBadFrame = errors.New("failed to read dataframe")
|
||||
)
|
||||
|
||||
var DuplicateTimestampErrors = [...]string{
|
||||
MimirDuplicateTimestampError,
|
||||
PrometheusDuplicateTimestampError,
|
||||
@@ -179,7 +185,7 @@ func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, f
|
||||
|
||||
points, err := PointsFromFrames(name, t, frames, extraLabels)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.Join(ErrBadFrame, err)
|
||||
}
|
||||
|
||||
series := make([]promremote.TimeSeries, 0, len(points))
|
||||
@@ -202,7 +208,7 @@ func (w PrometheusWriter) Write(ctx context.Context, name string, t time.Time, f
|
||||
w.metrics.WritesTotal.WithLabelValues(lvs...).Inc()
|
||||
|
||||
if err, ignored := checkWriteError(writeErr); err != nil {
|
||||
return fmt.Errorf("failed to write time series: %w", err)
|
||||
return errors.Join(ErrWriteFailure, err)
|
||||
} else if ignored {
|
||||
l.Debug("Ignored write error", "error", err, "status_code", res.StatusCode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user