feat(alerting): progress on testing alerts
This commit is contained in:
@@ -104,8 +104,7 @@ func (e *Engine) executeJob(job *AlertJob) {
|
||||
close(resultChan)
|
||||
e.log.Debug("Job Execution timeout", "alertRuleId", job.Rule.Id)
|
||||
case result := <-resultChan:
|
||||
duration := float64(result.EndTime.Nanosecond()-result.StartTime.Nanosecond()) / float64(1000000)
|
||||
e.log.Debug("Job Execution done", "timeTakenMs", duration, "ruleId", job.Rule.Id)
|
||||
e.log.Debug("Job Execution done", "timing", result.GetDurationSeconds(), "ruleId", job.Rule.Id)
|
||||
e.resultQueue <- result
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ func (e *HandlerImpl) Execute(rule *AlertRule, resultQueue chan *AlertResultCont
|
||||
func (e *HandlerImpl) eval(rule *AlertRule) *AlertResultContext {
|
||||
result := &AlertResultContext{
|
||||
StartTime: time.Now(),
|
||||
Rule: rule,
|
||||
}
|
||||
|
||||
for _, condition := range rule.Conditions {
|
||||
|
||||
@@ -36,6 +36,10 @@ type AlertResultContext struct {
|
||||
Rule *AlertRule
|
||||
}
|
||||
|
||||
func (a *AlertResultContext) GetDurationSeconds() float64 {
|
||||
return float64(a.EndTime.Nanosecond()-a.StartTime.Nanosecond()) / float64(1000000000)
|
||||
}
|
||||
|
||||
type AlertResultDetail struct {
|
||||
Value float64
|
||||
Metric string
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
type TestAlertRuleCommand struct {
|
||||
type AlertTestCommand struct {
|
||||
Dashboard *simplejson.Json
|
||||
PanelId int64
|
||||
OrgId int64
|
||||
@@ -18,24 +18,26 @@ type TestAlertRuleCommand struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
bus.AddHandler("alerting", handleTestAlertRuleCommand)
|
||||
bus.AddHandler("alerting", handleAlertTestCommand)
|
||||
}
|
||||
|
||||
func handleTestAlertRuleCommand(cmd *TestAlertRuleCommand) error {
|
||||
func handleAlertTestCommand(cmd *AlertTestCommand) error {
|
||||
|
||||
dash, err := m.NewDashboardFromJson(cmd.Dashboard)
|
||||
dash := m.NewDashboardFromJson(cmd.Dashboard)
|
||||
|
||||
extractor := NewDashAlertExtractor(dash, cmd.OrgId)
|
||||
alerts, err := extractor.GetAlerts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
extractor := NewDashAlertExtractor(cmd.Dashboard)
|
||||
rules, err := extractor.GetAlerts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, alert := range alerts {
|
||||
if alert.PanelId == cmd.PanelId {
|
||||
rule, err := NewAlertRuleFromDBModel(alert)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rule := range rules {
|
||||
if rule.PanelId == cmd.PanelId {
|
||||
if res, err := testAlertRule(rule); err != nil {
|
||||
return err
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user