Commit 71c1c0ab by Torkel Ödegaard

feat(alerting): trying to get things to work with new model

parent 0ef68011
......@@ -12,6 +12,7 @@ import (
"gopkg.in/ini.v1"
"github.com/go-stack/stack"
"github.com/inconshreveable/log15"
"github.com/inconshreveable/log15/term"
)
......@@ -228,3 +229,9 @@ func LogFilterHandler(maxLevel log15.Lvl, filters map[string]log15.Lvl, h log15.
return r.Lvl <= maxLevel
}, h)
}
func Stack(skip int) string {
call := stack.Caller(skip)
s := stack.Trace().TrimBelow(call).TrimRuntime()
return s.String()
}
......@@ -38,6 +38,10 @@ func updateDashboardAlerts(cmd *UpdateDashboardAlertsCommand) error {
return nil
}
func getTimeDurationStringToSeconds(str string) int64 {
return 60
}
func ConvetAlertModelToAlertRule(ruleDef *m.Alert) (*AlertRule, error) {
model := &AlertRule{}
model.Id = ruleDef.Id
......@@ -58,7 +62,7 @@ func ConvetAlertModelToAlertRule(ruleDef *m.Alert) (*AlertRule, error) {
Level: warning.Get("level").MustFloat64(),
}
model.Frequency = ruleDef.Expression.Get("frequency").MustInt64()
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Expression.Get("frequency").MustString())
model.Transform = ruleDef.Expression.Get("transform").Get("type").MustString()
model.TransformParams = *ruleDef.Expression.Get("transform")
......
......@@ -50,6 +50,12 @@ func (e *Engine) Stop() {
}
func (e *Engine) alertingTicker() {
defer func() {
if err := recover(); err != nil {
e.log.Error("Scheduler Panic, stopping...", "error", err, "stack", log.Stack(1))
}
}()
tickIndex := 0
for {
......
......@@ -18,12 +18,12 @@ func NewScheduler() Scheduler {
}
}
func (s *SchedulerImpl) Update(rules []*AlertRule) {
s.log.Debug("Scheduler: Update")
func (s *SchedulerImpl) Update(alerts []*AlertRule) {
s.log.Debug("Scheduling update", "alerts.count", len(alerts))
jobs := make(map[int64]*AlertJob, 0)
for i, rule := range rules {
for i, rule := range alerts {
var job *AlertJob
if s.jobs[rule.Id] != nil {
job = s.jobs[rule.Id]
......@@ -40,7 +40,6 @@ func (s *SchedulerImpl) Update(rules []*AlertRule) {
jobs[rule.Id] = job
}
s.log.Debug("Scheduler: Selected new jobs", "job count", len(jobs))
s.jobs = jobs
}
......
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