This reverts commit 42665ac87f.
This commit is contained in:
@@ -696,7 +696,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"`
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ const (
|
||||
silencesFilename = "silences"
|
||||
|
||||
workingDir = "alerting"
|
||||
// maintenanceNotificationAndSilences how often should we flush and gargabe collect notifications
|
||||
notificationLogMaintenanceInterval = 15 * time.Minute
|
||||
// maintenanceNotificationAndSilences how often should we flush and gargabe collect notifications and silences
|
||||
maintenanceNotificationAndSilences = 15 * time.Minute
|
||||
// defaultResolveTimeout is the default timeout used for resolving an alert
|
||||
// if the end time is not specified.
|
||||
defaultResolveTimeout = 5 * time.Minute
|
||||
@@ -164,20 +164,15 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nflogOptions := nflog.Options{
|
||||
SnapshotFile: nflogFilepath,
|
||||
Retention: retentionNotificationsAndSilences,
|
||||
Logger: am.logger,
|
||||
Metrics: m.Registerer,
|
||||
}
|
||||
nflogMaintenanceFrequency := notificationLogMaintenanceInterval
|
||||
nflogMaintenanceFunc :=
|
||||
func(state State) (int64, error) {
|
||||
return am.fileStore.Persist(ctx, notificationLogFilename, state)
|
||||
}
|
||||
|
||||
// Initialize the notification log
|
||||
am.notificationLog, err = nflog.New(nflogOptions)
|
||||
am.wg.Add(1)
|
||||
am.notificationLog, err = nflog.New(
|
||||
nflog.WithRetention(retentionNotificationsAndSilences),
|
||||
nflog.WithSnapshot(nflogFilepath),
|
||||
nflog.WithMaintenance(maintenanceNotificationAndSilences, am.stopc, am.wg.Done, func() (int64, error) {
|
||||
return am.fileStore.Persist(ctx, notificationLogFilename, am.notificationLog)
|
||||
}),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to initialize the notification log component of alerting: %w", err)
|
||||
}
|
||||
@@ -197,21 +192,6 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A
|
||||
c = am.peer.AddState(fmt.Sprintf("silences:%d", am.orgID), am.silences, m.Registerer)
|
||||
am.silences.SetBroadcast(c.Broadcast)
|
||||
|
||||
am.wg.Add(1)
|
||||
go func() {
|
||||
// TODO: Backporting https://github.com/grafana/alerting/commit/1cf0f4d256fe92a4d8aaf34d5093cc096526357a
|
||||
// This commit contains a bug (in master, right now) where silencesFilePath appears like it should be should be notificationLogFilename
|
||||
// Preserving it for now, as I'm just backporting that change and don't want to touch anything out of order...
|
||||
am.notificationLog.Maintenance(nflogMaintenanceFrequency, silencesFilePath, am.stopc, func() (int64, error) {
|
||||
if _, err := am.notificationLog.GC(); err != nil {
|
||||
am.logger.Error("notification log garbage collection", "err", err)
|
||||
}
|
||||
|
||||
return nflogMaintenanceFunc(am.notificationLog)
|
||||
})
|
||||
am.wg.Done()
|
||||
}()
|
||||
|
||||
am.wg.Add(1)
|
||||
go func() {
|
||||
am.silences.Maintenance(silenceMaintenanceInterval, silencesFilePath, am.stopc, func() (int64, error) {
|
||||
@@ -358,7 +338,7 @@ func (am *Alertmanager) getTemplate() (*template.Template, error) {
|
||||
}
|
||||
|
||||
func (am *Alertmanager) templateFromPaths(paths ...string) (*template.Template, error) {
|
||||
tmpl, err := template.FromGlobs(paths)
|
||||
tmpl, err := template.FromGlobs(paths...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ func templateForTests(t *testing.T) *template.Template {
|
||||
_, err = f.WriteString(TemplateForTestsString)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpl, err := template.FromGlobs([]string{f.Name()})
|
||||
tmpl, err := template.FromGlobs(f.Name())
|
||||
require.NoError(t, err)
|
||||
|
||||
return tmpl
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestDefaultTemplateString(t *testing.T) {
|
||||
_, err = f.WriteString(DefaultTemplateString)
|
||||
require.NoError(t, err)
|
||||
|
||||
tmpl, err := template.FromGlobs([]string{f.Name()})
|
||||
tmpl, err := template.FromGlobs(f.Name())
|
||||
require.NoError(t, err)
|
||||
|
||||
externalURL, err := url.Parse("http://localhost/grafana")
|
||||
|
||||
@@ -161,7 +161,7 @@ func (tn *TelegramNotifier) buildTelegramMessage(ctx context.Context, as []*type
|
||||
|
||||
tmpl, _ := TmplText(ctx, tn.tmpl, as, tn.log, &tmplErr)
|
||||
// Telegram supports 4096 chars max
|
||||
messageText, truncated := notify.TruncateInRunes(tmpl(tn.settings.Message), 4096)
|
||||
messageText, truncated := notify.Truncate(tmpl(tn.settings.Message), 4096)
|
||||
if truncated {
|
||||
tn.log.Warn("Telegram message too long, truncate message", "original_message", tn.settings.Message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user