style(alerting): rename executor -> handler

This commit is contained in:
bergquist 2016-06-15 11:49:20 +02:00
parent 777ca4cd7d
commit 779ea55ee0
6 changed files with 16 additions and 16 deletions

View File

@ -17,7 +17,7 @@ type Engine struct {
clock clock.Clock
ticker *Ticker
scheduler Scheduler
executor Executor
handler AlertingHandler
ruleReader RuleReader
log log.Logger
}
@ -28,7 +28,7 @@ func NewEngine() *Engine {
execQueue: make(chan *AlertJob, 1000),
resultQueue: make(chan *AlertResult, 1000),
scheduler: NewScheduler(),
executor: NewExecutor(),
handler: NewHandler(),
ruleReader: NewRuleReader(),
log: log.New("alerting.engine"),
}
@ -84,7 +84,7 @@ func (e *Engine) executeJob(job *AlertJob) {
now := time.Now()
resultChan := make(chan *AlertResult, 1)
go e.executor.Execute(job, resultChan)
go e.handler.Execute(job, resultChan)
select {
case <-time.After(time.Second * 5):

View File

@ -14,17 +14,17 @@ var (
descriptionFmt = "Actual value: %1.2f for %s. "
)
type ExecutorImpl struct {
type HandlerImpl struct {
log log.Logger
}
func NewExecutor() *ExecutorImpl {
return &ExecutorImpl{
func NewHandler() *HandlerImpl {
return &HandlerImpl{
log: log.New("alerting.executor"),
}
}
func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
func (e *HandlerImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
timeSeries, err := e.executeQuery(job)
if err != nil {
resultQueue <- &AlertResult{
@ -39,7 +39,7 @@ func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
resultQueue <- result
}
func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
func (e *HandlerImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
getDsInfo := &m.GetDataSourceByIdQuery{
Id: job.Rule.Query.DatasourceId,
OrgId: job.Rule.OrgId,
@ -68,7 +68,7 @@ func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error)
return result, nil
}
func (e *ExecutorImpl) GetRequestForAlertRule(rule *AlertRule, datasource *m.DataSource) *tsdb.Request {
func (e *HandlerImpl) GetRequestForAlertRule(rule *AlertRule, datasource *m.DataSource) *tsdb.Request {
e.log.Debug("GetRequest", "query", rule.Query.Query, "from", rule.Query.From, "datasourceId", datasource.Id)
req := &tsdb.Request{
TimeRange: tsdb.TimeRange{
@ -92,7 +92,7 @@ func (e *ExecutorImpl) GetRequestForAlertRule(rule *AlertRule, datasource *m.Dat
return req
}
func (e *ExecutorImpl) evaluateRule(rule *AlertRule, series tsdb.TimeSeriesSlice) *AlertResult {
func (e *HandlerImpl) evaluateRule(rule *AlertRule, series tsdb.TimeSeriesSlice) *AlertResult {
e.log.Debug("Evaluating Alerting Rule", "seriesCount", len(series), "ruleName", rule.Name)
triggeredAlert := make([]*TriggeredAlert, 0)

View File

@ -11,7 +11,7 @@ import (
func TestAlertingExecutor(t *testing.T) {
Convey("Test alert execution", t, func() {
executor := NewExecutor()
executor := NewHandler()
Convey("single time serie", func() {
Convey("Show return ok since avg is above 2", func() {

View File

@ -2,7 +2,7 @@ package alerting
import "time"
type Executor interface {
type AlertingHandler interface {
Execute(rule *AlertJob, resultChan chan *AlertResult)
}

View File

@ -22,14 +22,14 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
alert := m.Alert{}
has, err := sess.Id(cmd.AlertId).Get(&alert)
if !has {
return fmt.Errorf("Could not find alert")
}
if err != nil {
return err
}
if !has {
return fmt.Errorf("Could not find alert")
}
if alert.State == cmd.NewState {
cmd.Result = &m.Alert{}
return nil