Alerting: Update alerting module + refactor (#111761)
* update alerting module * replace compat with ones from alerting * update type references Receiver and Integration to *Status * update route in provisioning test that is invalid after recent change * use right type for LINE ingtegration
This commit is contained in:
@@ -14,8 +14,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
alertingNotify "github.com/grafana/alerting/notify"
|
||||
"github.com/grafana/alerting/receivers/schema"
|
||||
"github.com/grafana/alerting/notify/notifytest"
|
||||
prometheus "github.com/prometheus/alertmanager/config"
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
"github.com/prometheus/alertmanager/timeinterval"
|
||||
@@ -2033,12 +2032,12 @@ func TestApiContactPointExportSnapshot(t *testing.T) {
|
||||
t.Run(fmt.Sprintf("exportType=%s", exportType), func(t *testing.T) {
|
||||
for _, redacted := range []bool{true, false} {
|
||||
t.Run(fmt.Sprintf("redacted=%t", redacted), func(t *testing.T) {
|
||||
allIntegrations := make([]models.Integration, 0, len(alertingNotify.AllKnownConfigsForTesting))
|
||||
for integrationType := range alertingNotify.AllKnownConfigsForTesting {
|
||||
allIntegrations := make([]models.Integration, 0, len(notifytest.AllKnownV1ConfigsForTesting))
|
||||
for integrationType := range notifytest.AllKnownV1ConfigsForTesting {
|
||||
integration := models.IntegrationGen(
|
||||
models.IntegrationMuts.WithName(allIntegrationsName),
|
||||
models.IntegrationMuts.WithUID(fmt.Sprintf("%s-uid", integrationType)),
|
||||
models.IntegrationMuts.WithValidConfig(schema.IntegrationType(integrationType)),
|
||||
models.IntegrationMuts.WithUID(fmt.Sprintf("%s-uid", strings.ToLower(string(integrationType)))),
|
||||
models.IntegrationMuts.WithValidConfig(integrationType),
|
||||
)()
|
||||
integration.DisableResolveMessage = redacted
|
||||
allIntegrations = append(allIntegrations, integration)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
alertingModels "github.com/grafana/alerting/models"
|
||||
"github.com/grafana/alerting/notify"
|
||||
"github.com/grafana/alerting/receivers"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
@@ -53,7 +54,7 @@ func ContactPointToContactPointExport(cp definitions.ContactPoint) (notify.APIRe
|
||||
len(cp.Threema) + len(cp.Victorops) + len(cp.Webhook) + len(cp.Wecom) +
|
||||
len(cp.Webex) + len(cp.Mqtt)
|
||||
|
||||
integration := make([]*notify.GrafanaIntegrationConfig, 0, contactPointsLength)
|
||||
integration := make([]*alertingModels.IntegrationConfig, 0, contactPointsLength)
|
||||
|
||||
var errs []error
|
||||
for _, i := range cp.Alertmanager {
|
||||
@@ -222,20 +223,20 @@ func ContactPointToContactPointExport(cp definitions.ContactPoint) (notify.APIRe
|
||||
return notify.APIReceiver{}, errors.Join(errs...)
|
||||
}
|
||||
contactPoint := notify.APIReceiver{
|
||||
ConfigReceiver: notify.ConfigReceiver{Name: cp.Name},
|
||||
GrafanaIntegrations: notify.GrafanaIntegrations{Integrations: integration},
|
||||
ConfigReceiver: notify.ConfigReceiver{Name: cp.Name},
|
||||
ReceiverConfig: alertingModels.ReceiverConfig{Integrations: integration},
|
||||
}
|
||||
return contactPoint, nil
|
||||
}
|
||||
|
||||
// marshallIntegration converts the API model integration to the storage model that contains settings in the JSON format.
|
||||
// The secret fields are not encrypted.
|
||||
func marshallIntegration(json jsoniter.API, integrationType string, integration interface{}, disableResolveMessage *bool) (*notify.GrafanaIntegrationConfig, error) {
|
||||
func marshallIntegration(json jsoniter.API, integrationType string, integration interface{}, disableResolveMessage *bool) (*alertingModels.IntegrationConfig, error) {
|
||||
data, err := json.Marshal(integration)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshall integration '%s' to JSON: %w", integrationType, err)
|
||||
}
|
||||
e := ¬ify.GrafanaIntegrationConfig{
|
||||
e := &alertingModels.IntegrationConfig{
|
||||
Type: integrationType,
|
||||
Settings: data,
|
||||
}
|
||||
|
||||
@@ -7,8 +7,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
alertingmodels "github.com/grafana/alerting/models"
|
||||
"github.com/grafana/alerting/notify"
|
||||
"github.com/grafana/alerting/notify/notifytest"
|
||||
"github.com/grafana/alerting/receivers/line"
|
||||
receiversTesting "github.com/grafana/alerting/receivers/testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
apicompat "github.com/grafana/grafana/pkg/services/ngalert/api/compat"
|
||||
@@ -53,12 +57,12 @@ func TestContactPointFromContactPointExports(t *testing.T) {
|
||||
}
|
||||
|
||||
// use the configs for testing because they have all fields supported by integrations
|
||||
for integrationType, cfg := range notify.AllKnownConfigsForTesting {
|
||||
t.Run(integrationType, func(t *testing.T) {
|
||||
for integrationType, cfg := range notifytest.AllKnownV1ConfigsForTesting {
|
||||
t.Run(string(integrationType), func(t *testing.T) {
|
||||
recCfg := ¬ify.APIReceiver{
|
||||
ConfigReceiver: notify.ConfigReceiver{Name: "test-receiver"},
|
||||
GrafanaIntegrations: notify.GrafanaIntegrations{
|
||||
Integrations: []*notify.GrafanaIntegrationConfig{
|
||||
ReceiverConfig: alertingmodels.ReceiverConfig{
|
||||
Integrations: []*alertingmodels.IntegrationConfig{
|
||||
cfg.GetRawNotifierConfig("test"),
|
||||
},
|
||||
},
|
||||
@@ -87,9 +91,15 @@ func TestContactPointFromContactPointExports(t *testing.T) {
|
||||
}
|
||||
if integrationType != "webhook" {
|
||||
// Many notifiers now support HTTPClientConfig but only Webhook currently has it enabled in schema.
|
||||
//TODO: Remove this once HTTPClientConfig is added to other schemas.
|
||||
// TODO: Remove this once HTTPClientConfig is added to other schemas.
|
||||
pathFilters = append(pathFilters, "HTTPClientConfig")
|
||||
}
|
||||
if integrationType == line.Type {
|
||||
for _, l := range actual.LineConfigs {
|
||||
assert.Equal(t, "line", l.Type)
|
||||
l.Type = string(line.Type)
|
||||
}
|
||||
}
|
||||
pathFilter := cmp.FilterPath(func(path cmp.Path) bool {
|
||||
for _, filter := range pathFilters {
|
||||
if strings.Contains(path.String(), filter) {
|
||||
|
||||
@@ -603,15 +603,15 @@ type AlertGroups = amv2.AlertGroups
|
||||
|
||||
type AlertGroup = amv2.AlertGroup
|
||||
|
||||
type Receiver = alertingmodels.Receiver
|
||||
type Receiver = alertingmodels.ReceiverStatus
|
||||
|
||||
// swagger:response receiversResponse
|
||||
type ReceiversResponse struct {
|
||||
// in:body
|
||||
Body []alertingmodels.Receiver
|
||||
Body []alertingmodels.ReceiverStatus
|
||||
}
|
||||
|
||||
type Integration = alertingmodels.Integration
|
||||
type Integration = alertingmodels.IntegrationStatus
|
||||
|
||||
// swagger:parameters RouteGetAMAlerts RouteGetAMAlertGroups RouteGetGrafanaAMAlerts RouteGetGrafanaAMAlertGroups
|
||||
type AlertsParams struct {
|
||||
|
||||
Reference in New Issue
Block a user