Browse Source

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.
pull/658/head
Fabian Reinartz 10 years ago
parent
commit
479891c9be
  1. 4
      main.go
  2. 44
      rules/manager.go
  3. 2
      web/alerts.go
  4. 4
      web/status.go

4
main.go

@ -78,7 +78,7 @@ var (
type prometheus struct { type prometheus struct {
queryEngine *promql.Engine queryEngine *promql.Engine
ruleManager rules.RuleManager ruleManager *rules.Manager
targetManager retrieval.TargetManager targetManager retrieval.TargetManager
notificationHandler *notification.NotificationHandler notificationHandler *notification.NotificationHandler
storage local.Storage storage local.Storage
@ -159,7 +159,7 @@ func NewPrometheus() *prometheus {
queryEngine := promql.NewEngine(memStorage) queryEngine := promql.NewEngine(memStorage)
ruleManager := rules.NewRuleManager(&rules.RuleManagerOptions{ ruleManager := rules.NewManager(&rules.ManagerOptions{
SampleAppender: sampleAppender, SampleAppender: sampleAppender,
NotificationHandler: notificationHandler, NotificationHandler: notificationHandler,
EvaluationInterval: conf.EvaluationInterval(), EvaluationInterval: conf.EvaluationInterval(),

44
rules/manager.go

@ -70,20 +70,8 @@ func init() {
prometheus.MustRegister(evalDuration) prometheus.MustRegister(evalDuration)
} }
// A RuleManager manages recording and alerting rules. Create instances with // The Manager manages recording and alerting rules.
// NewRuleManager. type Manager struct {
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 {
// Protects the rules list. // Protects the rules list.
sync.Mutex sync.Mutex
rules []Rule rules []Rule
@ -100,8 +88,8 @@ type ruleManager struct {
pathPrefix string pathPrefix string
} }
// RuleManagerOptions bundles options for the RuleManager. // ManagerOptions bundles options for the Manager.
type RuleManagerOptions struct { type ManagerOptions struct {
EvaluationInterval time.Duration EvaluationInterval time.Duration
QueryEngine *promql.Engine QueryEngine *promql.Engine
@ -112,10 +100,10 @@ type RuleManagerOptions struct {
PathPrefix string 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. // by calling the Run method.
func NewRuleManager(o *RuleManagerOptions) RuleManager { func NewManager(o *ManagerOptions) *Manager {
manager := &ruleManager{ manager := &Manager{
rules: []Rule{}, rules: []Rule{},
done: make(chan bool), done: make(chan bool),
@ -131,7 +119,8 @@ func NewRuleManager(o *RuleManagerOptions) RuleManager {
return manager return manager
} }
func (m *ruleManager) Run() { // Run the rule manager's periodic rule evaluation.
func (m *Manager) Run() {
defer glog.Info("Rule manager stopped.") defer glog.Info("Rule manager stopped.")
ticker := time.NewTicker(m.interval) 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...") glog.Info("Stopping rule manager...")
m.done <- true m.done <- true
} }
func (m *ruleManager) queueAlertNotifications(rule *AlertingRule, timestamp clientmodel.Timestamp) { func (m *Manager) queueAlertNotifications(rule *AlertingRule, timestamp clientmodel.Timestamp) {
activeAlerts := rule.ActiveAlerts() activeAlerts := rule.ActiveAlerts()
if len(activeAlerts) == 0 { if len(activeAlerts) == 0 {
return return
@ -217,7 +207,7 @@ func (m *ruleManager) queueAlertNotifications(rule *AlertingRule, timestamp clie
m.notificationHandler.SubmitReqs(notifications) m.notificationHandler.SubmitReqs(notifications)
} }
func (m *ruleManager) runIteration() { func (m *Manager) runIteration() {
now := clientmodel.Now() now := clientmodel.Now()
wg := sync.WaitGroup{} wg := sync.WaitGroup{}
@ -268,7 +258,7 @@ func (m *ruleManager) runIteration() {
wg.Wait() 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) rule := NewAlertingRule(r.Name, r.Expr, r.Duration, r.Labels, r.Summary, r.Description)
m.Lock() m.Lock()
@ -277,7 +267,7 @@ func (m *ruleManager) AddAlertingRule(ctx context.Context, r *promql.AlertStmt)
return nil 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} rule := &RecordingRule{r.Name, r.Expr, r.Labels}
m.Lock() m.Lock()
@ -286,7 +276,7 @@ func (m *ruleManager) AddRecordingRule(ctx context.Context, r *promql.RecordStmt
return nil return nil
} }
func (m *ruleManager) Rules() []Rule { func (m *Manager) Rules() []Rule {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()
@ -295,7 +285,7 @@ func (m *ruleManager) Rules() []Rule {
return rules return rules
} }
func (m *ruleManager) AlertingRules() []*AlertingRule { func (m *Manager) AlertingRules() []*AlertingRule {
m.Lock() m.Lock()
defer m.Unlock() defer m.Unlock()

2
web/alerts.go

@ -46,7 +46,7 @@ func (s byAlertStateSorter) Swap(i, j int) {
// AlertsHandler implements http.Handler. // AlertsHandler implements http.Handler.
type AlertsHandler struct { type AlertsHandler struct {
RuleManager rules.RuleManager RuleManager *rules.Manager
PathPrefix string PathPrefix string
mutex sync.Mutex mutex sync.Mutex

4
web/status.go

@ -29,10 +29,10 @@ type PrometheusStatusHandler struct {
BuildInfo map[string]string BuildInfo map[string]string
Config string Config string
Flags map[string]string Flags map[string]string
RuleManager rules.RuleManager RuleManager *rules.Manager
TargetPools map[string]*retrieval.TargetPool TargetPools map[string]*retrieval.TargetPool
Birth time.Time Birth time.Time
PathPrefix string PathPrefix string
} }

Loading…
Cancel
Save