From 479891c9be688e35de03f2db4619eeceeacaed68 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Wed, 29 Apr 2015 10:26:49 +0200 Subject: [PATCH] Rename RuleManager to Manager, remove interface. This commits renames the RuleManager to Manager as the package name is 'rules' now. The unused layer of abstraction of the RuleManager interface is removed. --- main.go | 4 ++-- rules/manager.go | 44 +++++++++++++++++--------------------------- web/alerts.go | 2 +- web/status.go | 4 ++-- 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/main.go b/main.go index 3e6f77550..bc092239d 100644 --- a/main.go +++ b/main.go @@ -78,7 +78,7 @@ var ( type prometheus struct { queryEngine *promql.Engine - ruleManager rules.RuleManager + ruleManager *rules.Manager targetManager retrieval.TargetManager notificationHandler *notification.NotificationHandler storage local.Storage @@ -159,7 +159,7 @@ func NewPrometheus() *prometheus { queryEngine := promql.NewEngine(memStorage) - ruleManager := rules.NewRuleManager(&rules.RuleManagerOptions{ + ruleManager := rules.NewManager(&rules.ManagerOptions{ SampleAppender: sampleAppender, NotificationHandler: notificationHandler, EvaluationInterval: conf.EvaluationInterval(), diff --git a/rules/manager.go b/rules/manager.go index 26d12f95d..3b2bed6ee 100644 --- a/rules/manager.go +++ b/rules/manager.go @@ -70,20 +70,8 @@ func init() { prometheus.MustRegister(evalDuration) } -// A RuleManager manages recording and alerting rules. Create instances with -// NewRuleManager. -type RuleManager interface { - // Start the rule manager's periodic rule evaluation. - Run() - // Stop the rule manager's rule evaluation cycles. - Stop() - // Return all rules. - Rules() []Rule - // Return all alerting rules. - AlertingRules() []*AlertingRule -} - -type ruleManager struct { +// The Manager manages recording and alerting rules. +type Manager struct { // Protects the rules list. sync.Mutex rules []Rule @@ -100,8 +88,8 @@ type ruleManager struct { pathPrefix string } -// RuleManagerOptions bundles options for the RuleManager. -type RuleManagerOptions struct { +// ManagerOptions bundles options for the Manager. +type ManagerOptions struct { EvaluationInterval time.Duration QueryEngine *promql.Engine @@ -112,10 +100,10 @@ type RuleManagerOptions struct { PathPrefix string } -// NewRuleManager returns an implementation of RuleManager, ready to be started +// NewManager returns an implementation of Manager, ready to be started // by calling the Run method. -func NewRuleManager(o *RuleManagerOptions) RuleManager { - manager := &ruleManager{ +func NewManager(o *ManagerOptions) *Manager { + manager := &Manager{ rules: []Rule{}, done: make(chan bool), @@ -131,7 +119,8 @@ func NewRuleManager(o *RuleManagerOptions) RuleManager { return manager } -func (m *ruleManager) Run() { +// Run the rule manager's periodic rule evaluation. +func (m *Manager) Run() { defer glog.Info("Rule manager stopped.") ticker := time.NewTicker(m.interval) @@ -158,12 +147,13 @@ func (m *ruleManager) Run() { } } -func (m *ruleManager) Stop() { +// Stop the rule manager's rule evaluation cycles. +func (m *Manager) Stop() { glog.Info("Stopping rule manager...") m.done <- true } -func (m *ruleManager) queueAlertNotifications(rule *AlertingRule, timestamp clientmodel.Timestamp) { +func (m *Manager) queueAlertNotifications(rule *AlertingRule, timestamp clientmodel.Timestamp) { activeAlerts := rule.ActiveAlerts() if len(activeAlerts) == 0 { return @@ -217,7 +207,7 @@ func (m *ruleManager) queueAlertNotifications(rule *AlertingRule, timestamp clie m.notificationHandler.SubmitReqs(notifications) } -func (m *ruleManager) runIteration() { +func (m *Manager) runIteration() { now := clientmodel.Now() wg := sync.WaitGroup{} @@ -268,7 +258,7 @@ func (m *ruleManager) runIteration() { wg.Wait() } -func (m *ruleManager) AddAlertingRule(ctx context.Context, r *promql.AlertStmt) error { +func (m *Manager) AddAlertingRule(ctx context.Context, r *promql.AlertStmt) error { rule := NewAlertingRule(r.Name, r.Expr, r.Duration, r.Labels, r.Summary, r.Description) m.Lock() @@ -277,7 +267,7 @@ func (m *ruleManager) AddAlertingRule(ctx context.Context, r *promql.AlertStmt) return nil } -func (m *ruleManager) AddRecordingRule(ctx context.Context, r *promql.RecordStmt) error { +func (m *Manager) AddRecordingRule(ctx context.Context, r *promql.RecordStmt) error { rule := &RecordingRule{r.Name, r.Expr, r.Labels} m.Lock() @@ -286,7 +276,7 @@ func (m *ruleManager) AddRecordingRule(ctx context.Context, r *promql.RecordStmt return nil } -func (m *ruleManager) Rules() []Rule { +func (m *Manager) Rules() []Rule { m.Lock() defer m.Unlock() @@ -295,7 +285,7 @@ func (m *ruleManager) Rules() []Rule { return rules } -func (m *ruleManager) AlertingRules() []*AlertingRule { +func (m *Manager) AlertingRules() []*AlertingRule { m.Lock() defer m.Unlock() diff --git a/web/alerts.go b/web/alerts.go index 5744b074d..0e02965f2 100644 --- a/web/alerts.go +++ b/web/alerts.go @@ -46,7 +46,7 @@ func (s byAlertStateSorter) Swap(i, j int) { // AlertsHandler implements http.Handler. type AlertsHandler struct { - RuleManager rules.RuleManager + RuleManager *rules.Manager PathPrefix string mutex sync.Mutex diff --git a/web/status.go b/web/status.go index 4180874ed..6b6dd0a65 100644 --- a/web/status.go +++ b/web/status.go @@ -29,10 +29,10 @@ type PrometheusStatusHandler struct { BuildInfo map[string]string Config string Flags map[string]string - RuleManager rules.RuleManager + RuleManager *rules.Manager TargetPools map[string]*retrieval.TargetPool - Birth time.Time + Birth time.Time PathPrefix string }