Alerting: handle err-mimir-label-value-too-long as user error in the prom writer (#98783)

Alerting: handle err-mimir-label-value-too-long as user error in the writer
This commit is contained in:
Alexander Akhmetov 2025-01-10 18:36:05 +01:00 committed by GitHub
parent d7da75c480
commit aaa4fe1fe4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,7 @@ const (
MimirDuplicateTimestampError = "err-mimir-sample-duplicate-timestamp"
MimirInvalidLabelError = "err-mimir-label-invalid"
MimirMaxSeriesPerUserError = "err-mimir-max-series-per-user"
MimirLabelValueTooLongError = "err-mimir-label-value-too-long"
// Best effort error messages
PrometheusDuplicateTimestampError = "duplicate sample for timestamp"
@ -275,6 +276,10 @@ func checkWriteError(writeErr promremote.WriteError) (err error, ignored bool) {
return errors.Join(ErrRejectedWrite, writeErr), false
}
if strings.Contains(msg, MimirLabelValueTooLongError) {
return errors.Join(ErrRejectedWrite, writeErr), false
}
// For now, all 400s that are not previously known are considered unexpected.
// TODO: Consider blanket-converting all 400s to be known errors. This should only be done once we are confident this is not a problem with this client.
return errors.Join(ErrUnexpectedWriteFailure, writeErr), false

View File

@ -238,6 +238,22 @@ func TestPrometheusWriter_Write(t *testing.T) {
require.Error(t, err)
require.ErrorIs(t, err, ErrRejectedWrite)
})
t.Run("too long labels fit under the client error category", func(t *testing.T) {
msg := "received a series whose label value length exceeds the limit, label: 'label-1', value: 'value-1' (truncated) series: 'some_series (err-mimir-label-value-too-long). To adjust the related per-tenant limit, configure -validation.max-length-label-value, or contact your service administrator."
clientErr := testClientWriteError{
statusCode: http.StatusBadRequest,
msg: &msg,
}
client.writeSeriesFunc = func(ctx context.Context, ts promremote.TSList, opts promremote.WriteOptions) (promremote.WriteResult, promremote.WriteError) {
return promremote.WriteResult{}, clientErr
}
err := writer.Write(ctx, "test", now, frames, 1, map[string]string{"extra": "label"})
require.Error(t, err)
require.ErrorIs(t, err, ErrRejectedWrite)
})
}
func extractValue(t *testing.T, frames data.Frames, labels map[string]string, frameType data.FrameType) float64 {