Alerting: Remove reference to global models package in channels package (#60358)

* remove intermediate struct to create Base struct
* fix alertmanager
This commit is contained in:
Yuri Tseretyan 2022-12-14 16:21:55 -05:00 committed by GitHub
parent 342b0f3668
commit 0e7c95a4d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 24 additions and 167 deletions

View File

@ -13,7 +13,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
// GetDecryptedValueFn is a function that returns the decrypted value of
@ -70,12 +69,7 @@ func AlertmanagerFactory(fc FactoryConfig) (NotificationChannel, error) {
// NewAlertmanagerNotifier returns a new Alertmanager notifier.
func NewAlertmanagerNotifier(config *AlertmanagerConfig, images ImageStore, _ *template.Template, fn GetDecryptedValueFn) *AlertmanagerNotifier {
return &AlertmanagerNotifier{
Base: NewBase(&models.AlertNotification{
Uid: config.UID,
Name: config.Name,
DisableResolveMessage: config.DisableResolveMessage,
Settings: config.Settings,
}),
Base: NewBase(config.NotificationChannelConfig),
images: images,
urls: config.URLs,
basicAuthUser: config.BasicAuthUser,

View File

@ -1,32 +1,22 @@
package channels
import (
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
// Base is the base implementation of a notifier. It contains the common fields across all notifier types.
type Base struct {
Name string
Type string
UID string
IsDefault bool
DisableResolveMessage bool
log log.Logger
}
func (n *Base) GetDisableResolveMessage() bool {
return n.DisableResolveMessage
}
func NewBase(model *models.AlertNotification) *Base {
func NewBase(cfg *NotificationChannelConfig) *Base {
return &Base{
UID: model.Uid,
Name: model.Name,
IsDefault: model.IsDefault,
Type: model.Type,
DisableResolveMessage: model.DisableResolveMessage,
log: log.New("alerting.notifier." + model.Name),
UID: cfg.UID,
Name: cfg.Name,
Type: cfg.Type,
DisableResolveMessage: cfg.DisableResolveMessage,
}
}

View File

@ -11,7 +11,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const defaultDingdingMsgType = "link"
@ -54,13 +53,7 @@ func newDingDingNotifier(fc FactoryConfig) (*DingDingNotifier, error) {
return nil, err
}
return &DingDingNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.dingding"),
ns: fc.NotificationService,
tmpl: fc.Template,

View File

@ -18,7 +18,6 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
@ -67,14 +66,7 @@ func newDiscordNotifier(fc FactoryConfig) (*DiscordNotifier, error) {
}
return &DiscordNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
SecureSettings: fc.Config.SecureSettings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.discord"),
ns: fc.NotificationService,
images: fc.ImageStore,

View File

@ -12,7 +12,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/util"
)
@ -69,13 +68,7 @@ func NewEmailConfig(config *NotificationChannelConfig) (*EmailConfig, error) {
// for the EmailNotifier.
func NewEmailNotifier(config *EmailConfig, ns EmailSender, images ImageStore, t *template.Template) *EmailNotifier {
return &EmailNotifier{
Base: NewBase(&models.AlertNotification{
Uid: config.UID,
Name: config.Name,
Type: config.Type,
DisableResolveMessage: config.DisableResolveMessage,
Settings: config.Settings,
}),
Base: NewBase(config.NotificationChannelConfig),
Addresses: config.Addresses,
SingleEmail: config.SingleEmail,
Message: config.Message,

View File

@ -12,7 +12,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
@ -57,13 +56,7 @@ func newGoogleChatNotifier(fc FactoryConfig) (*GoogleChatNotifier, error) {
}
return &GoogleChatNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.googlechat"),
ns: fc.NotificationService,
images: fc.ImageStore,

View File

@ -58,13 +58,7 @@ func newKafkaNotifier(fc FactoryConfig) (*KafkaNotifier, error) {
details := fc.Config.Settings.Get("details").MustString(DefaultMessageEmbed)
return &KafkaNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.kafka"),
images: fc.ImageStore,
ns: fc.NotificationService,

View File

@ -11,7 +11,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
var (
@ -55,13 +54,7 @@ func newLineNotifier(fc FactoryConfig) (*LineNotifier, error) {
description := fc.Config.Settings.Get("description").MustString(DefaultMessageEmbed)
return &LineNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.line"),
ns: fc.NotificationService,
tmpl: fc.Template,

View File

@ -16,7 +16,6 @@ import (
ptr "github.com/xorcare/pointer"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const (
@ -125,13 +124,7 @@ func NewOpsgenieNotifier(fc FactoryConfig) (*OpsgenieNotifier, error) {
return nil, err
}
return &OpsgenieNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
tmpl: fc.Template,
log: log.New("alerting.notifier.opsgenie"),
ns: fc.NotificationService,

View File

@ -14,7 +14,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const (
@ -130,13 +129,7 @@ func newPagerdutyNotifier(fc FactoryConfig) (*PagerdutyNotifier, error) {
}
return &PagerdutyNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
tmpl: fc.Template,
log: log.New("alerting.notifier." + fc.Config.Name),
ns: fc.NotificationService,

View File

@ -18,7 +18,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const (
@ -147,14 +146,7 @@ func NewPushoverNotifier(fc FactoryConfig) (*PushoverNotifier, error) {
return nil, err
}
return &PushoverNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
SecureSettings: fc.Config.SecureSettings,
}),
Base: NewBase(fc.Config),
tmpl: fc.Template,
log: log.New("alerting.notifier.pushover"),
images: fc.ImageStore,

View File

@ -12,7 +12,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
type SensuGoNotifier struct {
@ -71,14 +70,7 @@ func NewSensuGoNotifier(fc FactoryConfig) (*SensuGoNotifier, error) {
return nil, err
}
return &SensuGoNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
SecureSettings: fc.Config.SecureSettings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.sensugo"),
images: fc.ImageStore,
ns: fc.NotificationService,

View File

@ -23,7 +23,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
@ -156,13 +155,7 @@ func buildSlackNotifier(factoryConfig FactoryConfig) (*SlackNotifier, error) {
settings.Title = DefaultMessageTitleEmbed
}
return &SlackNotifier{
Base: NewBase(&models.AlertNotification{
Uid: factoryConfig.Config.UID,
Name: factoryConfig.Config.Name,
Type: factoryConfig.Config.Type,
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
Settings: factoryConfig.Config.Settings,
}),
Base: NewBase(factoryConfig.Config),
settings: settings,
images: factoryConfig.ImageStore,

View File

@ -12,7 +12,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const (
@ -263,13 +262,7 @@ func NewTeamsNotifier(fc FactoryConfig) (*TeamsNotifier, error) {
return nil, err
}
return &TeamsNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.teams"),
ns: fc.NotificationService,
images: fc.ImageStore,

View File

@ -15,7 +15,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
var (
@ -101,13 +100,7 @@ func NewTelegramNotifier(fc FactoryConfig) (*TelegramNotifier, error) {
return nil, err
}
return &TelegramNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
tmpl: fc.Template,
log: log.New("alerting.notifier.telegram"),
images: fc.ImageStore,

View File

@ -13,7 +13,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
var (
@ -95,13 +94,7 @@ func NewThreemaNotifier(fc FactoryConfig) (*ThreemaNotifier, error) {
return nil, err
}
return &ThreemaNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.threema"),
images: fc.ImageStore,
ns: fc.NotificationService,

View File

@ -14,7 +14,6 @@ import (
"github.com/prometheus/common/model"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
)
@ -76,13 +75,7 @@ func NewVictoropsNotifier(fc FactoryConfig) (*VictoropsNotifier, error) {
return nil, err
}
return &VictoropsNotifier{
Base: NewBase(&models.AlertNotification{
Uid: fc.Config.UID,
Name: fc.Config.Name,
Type: fc.Config.Type,
DisableResolveMessage: fc.Config.DisableResolveMessage,
Settings: fc.Config.Settings,
}),
Base: NewBase(fc.Config),
log: log.New("alerting.notifier.victorops"),
images: fc.ImageStore,
ns: fc.NotificationService,

View File

@ -11,7 +11,6 @@ import (
"github.com/prometheus/alertmanager/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
const webexAPIURL = "https://webexapis.com/v1/messages"
@ -84,13 +83,7 @@ func buildWebexNotifier(factoryConfig FactoryConfig) (*WebexNotifier, error) {
logger := log.New("alerting.notifier.webex")
return &WebexNotifier{
Base: NewBase(&models.AlertNotification{
Uid: factoryConfig.Config.UID,
Name: factoryConfig.Config.Name,
Type: factoryConfig.Config.Type,
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
Settings: factoryConfig.Config.Settings,
}),
Base: NewBase(factoryConfig.Config),
orgID: factoryConfig.Config.OrgID,
log: logger,
ns: factoryConfig.NotificationService,

View File

@ -116,13 +116,7 @@ func buildWebhookNotifier(factoryConfig FactoryConfig) (*WebhookNotifier, error)
return nil, err
}
return &WebhookNotifier{
Base: NewBase(&models.AlertNotification{
Uid: factoryConfig.Config.UID,
Name: factoryConfig.Config.Name,
Type: factoryConfig.Config.Type,
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
Settings: factoryConfig.Config.Settings,
}),
Base: NewBase(factoryConfig.Config),
orgID: factoryConfig.Config.OrgID,
log: log.New("alerting.notifier.webhook"),
ns: factoryConfig.NotificationService,

View File

@ -13,7 +13,6 @@ import (
"golang.org/x/sync/singleflight"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
)
var weComEndpoint = "https://qyapi.weixin.qq.com"
@ -110,13 +109,7 @@ func buildWecomNotifier(factoryConfig FactoryConfig) (*WeComNotifier, error) {
return nil, err
}
return &WeComNotifier{
Base: NewBase(&models.AlertNotification{
Uid: factoryConfig.Config.UID,
Name: factoryConfig.Config.Name,
Type: factoryConfig.Config.Type,
DisableResolveMessage: factoryConfig.Config.DisableResolveMessage,
Settings: factoryConfig.Config.Settings,
}),
Base: NewBase(factoryConfig.Config),
tmpl: factoryConfig.Template,
log: log.New("alerting.notifier.wecom"),
ns: factoryConfig.NotificationService,