mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
style(alerting): rename executor -> handler
This commit is contained in:
parent
777ca4cd7d
commit
779ea55ee0
@ -17,7 +17,7 @@ type Engine struct {
|
|||||||
clock clock.Clock
|
clock clock.Clock
|
||||||
ticker *Ticker
|
ticker *Ticker
|
||||||
scheduler Scheduler
|
scheduler Scheduler
|
||||||
executor Executor
|
handler AlertingHandler
|
||||||
ruleReader RuleReader
|
ruleReader RuleReader
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ func NewEngine() *Engine {
|
|||||||
execQueue: make(chan *AlertJob, 1000),
|
execQueue: make(chan *AlertJob, 1000),
|
||||||
resultQueue: make(chan *AlertResult, 1000),
|
resultQueue: make(chan *AlertResult, 1000),
|
||||||
scheduler: NewScheduler(),
|
scheduler: NewScheduler(),
|
||||||
executor: NewExecutor(),
|
handler: NewHandler(),
|
||||||
ruleReader: NewRuleReader(),
|
ruleReader: NewRuleReader(),
|
||||||
log: log.New("alerting.engine"),
|
log: log.New("alerting.engine"),
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func (e *Engine) executeJob(job *AlertJob) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
resultChan := make(chan *AlertResult, 1)
|
resultChan := make(chan *AlertResult, 1)
|
||||||
go e.executor.Execute(job, resultChan)
|
go e.handler.Execute(job, resultChan)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Second * 5):
|
case <-time.After(time.Second * 5):
|
||||||
|
@ -14,17 +14,17 @@ var (
|
|||||||
descriptionFmt = "Actual value: %1.2f for %s. "
|
descriptionFmt = "Actual value: %1.2f for %s. "
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExecutorImpl struct {
|
type HandlerImpl struct {
|
||||||
log log.Logger
|
log log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecutor() *ExecutorImpl {
|
func NewHandler() *HandlerImpl {
|
||||||
return &ExecutorImpl{
|
return &HandlerImpl{
|
||||||
log: log.New("alerting.executor"),
|
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)
|
timeSeries, err := e.executeQuery(job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resultQueue <- &AlertResult{
|
resultQueue <- &AlertResult{
|
||||||
@ -39,7 +39,7 @@ func (e *ExecutorImpl) Execute(job *AlertJob, resultQueue chan *AlertResult) {
|
|||||||
resultQueue <- result
|
resultQueue <- result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
|
func (e *HandlerImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error) {
|
||||||
getDsInfo := &m.GetDataSourceByIdQuery{
|
getDsInfo := &m.GetDataSourceByIdQuery{
|
||||||
Id: job.Rule.Query.DatasourceId,
|
Id: job.Rule.Query.DatasourceId,
|
||||||
OrgId: job.Rule.OrgId,
|
OrgId: job.Rule.OrgId,
|
||||||
@ -68,7 +68,7 @@ func (e *ExecutorImpl) executeQuery(job *AlertJob) (tsdb.TimeSeriesSlice, error)
|
|||||||
return result, nil
|
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)
|
e.log.Debug("GetRequest", "query", rule.Query.Query, "from", rule.Query.From, "datasourceId", datasource.Id)
|
||||||
req := &tsdb.Request{
|
req := &tsdb.Request{
|
||||||
TimeRange: tsdb.TimeRange{
|
TimeRange: tsdb.TimeRange{
|
||||||
@ -92,7 +92,7 @@ func (e *ExecutorImpl) GetRequestForAlertRule(rule *AlertRule, datasource *m.Dat
|
|||||||
return req
|
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)
|
e.log.Debug("Evaluating Alerting Rule", "seriesCount", len(series), "ruleName", rule.Name)
|
||||||
|
|
||||||
triggeredAlert := make([]*TriggeredAlert, 0)
|
triggeredAlert := make([]*TriggeredAlert, 0)
|
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
func TestAlertingExecutor(t *testing.T) {
|
func TestAlertingExecutor(t *testing.T) {
|
||||||
Convey("Test alert execution", t, func() {
|
Convey("Test alert execution", t, func() {
|
||||||
executor := NewExecutor()
|
executor := NewHandler()
|
||||||
|
|
||||||
Convey("single time serie", func() {
|
Convey("single time serie", func() {
|
||||||
Convey("Show return ok since avg is above 2", func() {
|
Convey("Show return ok since avg is above 2", func() {
|
@ -2,7 +2,7 @@ package alerting
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Executor interface {
|
type AlertingHandler interface {
|
||||||
Execute(rule *AlertJob, resultChan chan *AlertResult)
|
Execute(rule *AlertJob, resultChan chan *AlertResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,14 +22,14 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
|||||||
|
|
||||||
alert := m.Alert{}
|
alert := m.Alert{}
|
||||||
has, err := sess.Id(cmd.AlertId).Get(&alert)
|
has, err := sess.Id(cmd.AlertId).Get(&alert)
|
||||||
if !has {
|
|
||||||
return fmt.Errorf("Could not find alert")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !has {
|
||||||
|
return fmt.Errorf("Could not find alert")
|
||||||
|
}
|
||||||
|
|
||||||
if alert.State == cmd.NewState {
|
if alert.State == cmd.NewState {
|
||||||
cmd.Result = &m.Alert{}
|
cmd.Result = &m.Alert{}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user