Alerting: Do not retry rule evaluations with "input data must be a wide series but got type long" style errors (#87343)

add typed error for series must be wide, do not retry
This commit is contained in:
Alexander Weaver
2024-05-07 11:31:07 -05:00
committed by GitHub
parent 5fb87de321
commit 6c47968f6c
4 changed files with 19 additions and 4 deletions
+2 -2
View File
@@ -79,7 +79,7 @@ func (c *ResultConverter) Convert(ctx context.Context,
}
if schema.Type != data.TimeSeriesTypeWide && !allowLongFrames {
return "", mathexp.Results{}, fmt.Errorf("input data must be a wide series but got type %s (input refid)", schema.Type)
return "", mathexp.Results{}, fmt.Errorf("%w but got type %s (input refid)", ErrSeriesMustBeWide, schema.Type)
}
filtered = append(filtered, frame)
totalLen += len(schema.ValueIndices)
@@ -249,7 +249,7 @@ func extractNumberSet(frame *data.Frame) ([]mathexp.Number, error) {
func WideToMany(frame *data.Frame, fixSeries func(series mathexp.Series, valueField *data.Field)) ([]mathexp.Series, error) {
tsSchema := frame.TimeSeriesSchema()
if tsSchema.Type != data.TimeSeriesTypeWide {
return nil, fmt.Errorf("input data must be a wide series but got type %s", tsSchema.Type)
return nil, fmt.Errorf("%w but got type %s", ErrSeriesMustBeWide, tsSchema.Type)
}
if len(tsSchema.ValueIndices) == 1 {
+2
View File
@@ -7,6 +7,8 @@ import (
"github.com/grafana/grafana/pkg/util/errutil"
)
var ErrSeriesMustBeWide = errors.New("input data must be a wide series")
var ConversionError = errutil.BadRequest("sse.readDataError").MustTemplate(
"[{{ .Public.refId }}] got error: {{ .Error }}",
errutil.WithPublic(
+4 -1
View File
@@ -166,7 +166,7 @@ func (evalResults Results) HasErrors() bool {
// HasNonRetryableErrors returns true if we have at least 1 result with:
// 1. A `State` of `Error`
// 2. The `Error` attribute is not nil
// 3. The `Error` type is of `&invalidEvalResultFormatError`
// 3. The `Error` type is of `&invalidEvalResultFormatError` or `ErrSeriesMustBeWide`
// Our thinking with this approach, is that we don't want to retry errors that have relation with invalid alert definition format.
func (evalResults Results) HasNonRetryableErrors() bool {
for _, r := range evalResults {
@@ -175,6 +175,9 @@ func (evalResults Results) HasNonRetryableErrors() bool {
if errors.As(r.Error, &nonRetryableError) {
return true
}
if errors.Is(r.Error, expr.ErrSeriesMustBeWide) {
return true
}
}
}
return false
+11 -1
View File
@@ -957,7 +957,7 @@ func TestResults_HasNonRetryableErrors(t *testing.T) {
expected bool
}{
{
name: "with non-retryable errors",
name: "with invalid format error",
eval: Results{
{
State: Error,
@@ -966,6 +966,16 @@ func TestResults_HasNonRetryableErrors(t *testing.T) {
},
expected: true,
},
{
name: "with expected wide series but got type long error",
eval: Results{
{
State: Error,
Error: fmt.Errorf("%w but got type long", expr.ErrSeriesMustBeWide),
},
},
expected: true,
},
{
name: "with retryable errors",
eval: Results{