Update grafana/alerting to the latest main (#61810)
* Update `grafana/alerting` to the latest main Also updates prometheus-alertmanager since we use that one directly for some structs.
This commit is contained in:
@@ -695,7 +695,7 @@ func (c *GettableApiAlertingConfig) validate() error {
|
||||
type Config struct {
|
||||
Global *config.GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
|
||||
Route *Route `yaml:"route,omitempty" json:"route,omitempty"`
|
||||
InhibitRules []*config.InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
|
||||
InhibitRules []config.InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
|
||||
MuteTimeIntervals []config.MuteTimeInterval `yaml:"mute_time_intervals,omitempty" json:"mute_time_intervals,omitempty"`
|
||||
Templates []string `yaml:"templates" json:"templates"`
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ func (a AlertingConfiguration) DispatcherLimits() alerting.DispatcherLimits {
|
||||
return &nilLimits{}
|
||||
}
|
||||
|
||||
func (a AlertingConfiguration) InhibitRules() []*alerting.InhibitRule {
|
||||
func (a AlertingConfiguration) InhibitRules() []alerting.InhibitRule {
|
||||
return a.AlertmanagerConfig.InhibitRules
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/grafana/alerting/alerting"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/api/tooling/definitions"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestInvalidReceiverError_Error(t *testing.T) {
|
||||
e := InvalidReceiverError{
|
||||
Receiver: &definitions.PostableGrafanaReceiver{
|
||||
e := alerting.InvalidReceiverError{
|
||||
Receiver: &alerting.GrafanaReceiver{
|
||||
Name: "test",
|
||||
UID: "uid",
|
||||
},
|
||||
@@ -23,8 +23,8 @@ func TestInvalidReceiverError_Error(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestReceiverTimeoutError_Error(t *testing.T) {
|
||||
e := ReceiverTimeoutError{
|
||||
Receiver: &definitions.PostableGrafanaReceiver{
|
||||
e := alerting.ReceiverTimeoutError{
|
||||
Receiver: &alerting.GrafanaReceiver{
|
||||
Name: "test",
|
||||
UID: "uid",
|
||||
},
|
||||
@@ -45,18 +45,18 @@ func (e timeoutError) Timeout() bool {
|
||||
|
||||
func TestProcessNotifierError(t *testing.T) {
|
||||
t.Run("assert ReceiverTimeoutError is returned for context deadline exceeded", func(t *testing.T) {
|
||||
r := &definitions.PostableGrafanaReceiver{
|
||||
r := &alerting.GrafanaReceiver{
|
||||
Name: "test",
|
||||
UID: "uid",
|
||||
}
|
||||
require.Equal(t, ReceiverTimeoutError{
|
||||
require.Equal(t, alerting.ReceiverTimeoutError{
|
||||
Receiver: r,
|
||||
Err: context.DeadlineExceeded,
|
||||
}, processNotifierError(r, context.DeadlineExceeded))
|
||||
}, alerting.ProcessNotifierError(r, context.DeadlineExceeded))
|
||||
})
|
||||
|
||||
t.Run("assert ReceiverTimeoutError is returned for *url.Error timeout", func(t *testing.T) {
|
||||
r := &definitions.PostableGrafanaReceiver{
|
||||
r := &alerting.GrafanaReceiver{
|
||||
Name: "test",
|
||||
UID: "uid",
|
||||
}
|
||||
@@ -65,44 +65,18 @@ func TestProcessNotifierError(t *testing.T) {
|
||||
URL: "https://grafana.net",
|
||||
Err: timeoutError{},
|
||||
}
|
||||
require.Equal(t, ReceiverTimeoutError{
|
||||
require.Equal(t, alerting.ReceiverTimeoutError{
|
||||
Receiver: r,
|
||||
Err: urlError,
|
||||
}, processNotifierError(r, urlError))
|
||||
}, alerting.ProcessNotifierError(r, urlError))
|
||||
})
|
||||
|
||||
t.Run("assert unknown error is returned unmodified", func(t *testing.T) {
|
||||
r := &definitions.PostableGrafanaReceiver{
|
||||
r := &alerting.GrafanaReceiver{
|
||||
Name: "test",
|
||||
UID: "uid",
|
||||
}
|
||||
err := errors.New("this is an error")
|
||||
require.Equal(t, err, processNotifierError(r, err))
|
||||
require.Equal(t, err, alerting.ProcessNotifierError(r, err))
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: Copied from Alerting, needs to be made public.
|
||||
func processNotifierError(config *definitions.PostableGrafanaReceiver, err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var urlError *url.Error
|
||||
if errors.As(err, &urlError) {
|
||||
if urlError.Timeout() {
|
||||
return ReceiverTimeoutError{
|
||||
Receiver: config,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
return ReceiverTimeoutError{
|
||||
Receiver: config,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user