Commit b6493587 by bergquist

rename alerting engine to service

parent e1b9d361
...@@ -16,7 +16,7 @@ import ( ...@@ -16,7 +16,7 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
) )
type AlertingEngine struct { type AlertingService struct {
execQueue chan *Job execQueue chan *Job
//clock clock.Clock //clock clock.Clock
ticker *Ticker ticker *Ticker
...@@ -28,20 +28,20 @@ type AlertingEngine struct { ...@@ -28,20 +28,20 @@ type AlertingEngine struct {
} }
func init() { func init() {
registry.RegisterService(&AlertingEngine{}) registry.RegisterService(&AlertingService{})
} }
func NewEngine() *AlertingEngine { func NewEngine() *AlertingService {
e := &AlertingEngine{} e := &AlertingService{}
e.Init() e.Init()
return e return e
} }
func (e *AlertingEngine) IsDisabled() bool { func (e *AlertingService) IsDisabled() bool {
return !setting.AlertingEnabled || !setting.ExecuteAlerts return !setting.AlertingEnabled || !setting.ExecuteAlerts
} }
func (e *AlertingEngine) Init() error { func (e *AlertingService) Init() error {
e.ticker = NewTicker(time.Now(), time.Second*0, clock.New()) e.ticker = NewTicker(time.Now(), time.Second*0, clock.New())
e.execQueue = make(chan *Job, 1000) e.execQueue = make(chan *Job, 1000)
e.scheduler = NewScheduler() e.scheduler = NewScheduler()
...@@ -52,7 +52,7 @@ func (e *AlertingEngine) Init() error { ...@@ -52,7 +52,7 @@ func (e *AlertingEngine) Init() error {
return nil return nil
} }
func (e *AlertingEngine) Run(ctx context.Context) error { func (e *AlertingService) Run(ctx context.Context) error {
alertGroup, ctx := errgroup.WithContext(ctx) alertGroup, ctx := errgroup.WithContext(ctx)
alertGroup.Go(func() error { return e.alertingTicker(ctx) }) alertGroup.Go(func() error { return e.alertingTicker(ctx) })
alertGroup.Go(func() error { return e.runJobDispatcher(ctx) }) alertGroup.Go(func() error { return e.runJobDispatcher(ctx) })
...@@ -61,7 +61,7 @@ func (e *AlertingEngine) Run(ctx context.Context) error { ...@@ -61,7 +61,7 @@ func (e *AlertingEngine) Run(ctx context.Context) error {
return err return err
} }
func (e *AlertingEngine) alertingTicker(grafanaCtx context.Context) error { func (e *AlertingService) alertingTicker(grafanaCtx context.Context) error {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
e.log.Error("Scheduler Panic: stopping alertingTicker", "error", err, "stack", log.Stack(1)) e.log.Error("Scheduler Panic: stopping alertingTicker", "error", err, "stack", log.Stack(1))
...@@ -86,7 +86,7 @@ func (e *AlertingEngine) alertingTicker(grafanaCtx context.Context) error { ...@@ -86,7 +86,7 @@ func (e *AlertingEngine) alertingTicker(grafanaCtx context.Context) error {
} }
} }
func (e *AlertingEngine) runJobDispatcher(grafanaCtx context.Context) error { func (e *AlertingService) runJobDispatcher(grafanaCtx context.Context) error {
dispatcherGroup, alertCtx := errgroup.WithContext(grafanaCtx) dispatcherGroup, alertCtx := errgroup.WithContext(grafanaCtx)
for { for {
...@@ -106,7 +106,7 @@ var ( ...@@ -106,7 +106,7 @@ var (
alertMaxAttempts = 3 alertMaxAttempts = 3
) )
func (e *AlertingEngine) processJobWithRetry(grafanaCtx context.Context, job *Job) error { func (e *AlertingService) processJobWithRetry(grafanaCtx context.Context, job *Job) error {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
e.log.Error("Alert Panic", "error", err, "stack", log.Stack(1)) e.log.Error("Alert Panic", "error", err, "stack", log.Stack(1))
...@@ -141,7 +141,7 @@ func (e *AlertingEngine) processJobWithRetry(grafanaCtx context.Context, job *Jo ...@@ -141,7 +141,7 @@ func (e *AlertingEngine) processJobWithRetry(grafanaCtx context.Context, job *Jo
} }
} }
func (e *AlertingEngine) endJob(err error, cancelChan chan context.CancelFunc, job *Job) error { func (e *AlertingService) endJob(err error, cancelChan chan context.CancelFunc, job *Job) error {
job.Running = false job.Running = false
close(cancelChan) close(cancelChan)
for cancelFn := range cancelChan { for cancelFn := range cancelChan {
...@@ -150,7 +150,7 @@ func (e *AlertingEngine) endJob(err error, cancelChan chan context.CancelFunc, j ...@@ -150,7 +150,7 @@ func (e *AlertingEngine) endJob(err error, cancelChan chan context.CancelFunc, j
return err return err
} }
func (e *AlertingEngine) processJob(attemptID int, attemptChan chan int, cancelChan chan context.CancelFunc, job *Job) { func (e *AlertingService) processJob(attemptID int, attemptChan chan int, cancelChan chan context.CancelFunc, job *Job) {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
e.log.Error("Alert Panic", "error", err, "stack", log.Stack(1)) e.log.Error("Alert Panic", "error", err, "stack", log.Stack(1))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment