mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
style(alerting): go lint fixes
This commit is contained in:
parent
50d98b161c
commit
eab81a7781
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
MaxRetries = 3
|
||||
maxRetries = 3
|
||||
)
|
||||
|
||||
func Init() {
|
||||
@ -115,9 +115,9 @@ func (scheduler *Scheduler) handleResponses() {
|
||||
|
||||
if response.State == m.AlertStatePending {
|
||||
response.AlertJob.Retry++
|
||||
if response.AlertJob.Retry > MaxRetries {
|
||||
if response.AlertJob.Retry > maxRetries {
|
||||
response.State = m.AlertStateCritical
|
||||
response.Description = fmt.Sprintf("Failed to run check after %d retires", MaxRetries)
|
||||
response.Description = fmt.Sprintf("Failed to run check after %d retires", maxRetries)
|
||||
scheduler.saveState(response)
|
||||
}
|
||||
} else {
|
||||
|
@ -22,7 +22,7 @@ type GraphiteSerie struct {
|
||||
|
||||
type GraphiteResponse []GraphiteSerie
|
||||
|
||||
func (this GraphiteClient) GetSeries(rule m.AlertJob, datasource m.DataSource) (m.TimeSeriesSlice, error) {
|
||||
func (client GraphiteClient) GetSeries(rule m.AlertJob, datasource m.DataSource) (m.TimeSeriesSlice, error) {
|
||||
v := url.Values{
|
||||
"format": []string{"json"},
|
||||
"target": []string{getTargetFromRule(rule.Rule)},
|
||||
|
@ -1,20 +0,0 @@
|
||||
package alerting
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/log"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DummieExecutor struct{}
|
||||
|
||||
func (this *DummieExecutor) Execute(rule m.AlertRule, responseQueue chan *m.AlertResult) {
|
||||
if rule.Id%3 == 0 {
|
||||
time.Sleep(time.Second * 1)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second)
|
||||
log.Info("Finnished executing: %d", rule.Id)
|
||||
|
||||
responseQueue <- &m.AlertResult{State: "OK", Id: rule.Id}
|
||||
}
|
@ -15,7 +15,8 @@ type Executor interface {
|
||||
}
|
||||
|
||||
var (
|
||||
ResultLogFmt = "%s executor: %s %1.2f %s %1.2f : %v"
|
||||
resultLogFmt = "%s executor: %s %1.2f %s %1.2f : %v"
|
||||
descriptionFmt = "Actual value: %1.2f for %s"
|
||||
)
|
||||
|
||||
type ExecutorImpl struct{}
|
||||
@ -23,14 +24,14 @@ type ExecutorImpl struct{}
|
||||
type compareFn func(float64, float64) bool
|
||||
type aggregationFn func(*m.TimeSeries) float64
|
||||
|
||||
var operators map[string]compareFn = map[string]compareFn{
|
||||
var operators = map[string]compareFn{
|
||||
">": func(num1, num2 float64) bool { return num1 > num2 },
|
||||
">=": func(num1, num2 float64) bool { return num1 >= num2 },
|
||||
"<": func(num1, num2 float64) bool { return num1 < num2 },
|
||||
"<=": func(num1, num2 float64) bool { return num1 <= num2 },
|
||||
"": func(num1, num2 float64) bool { return false },
|
||||
}
|
||||
var aggregator map[string]aggregationFn = map[string]aggregationFn{
|
||||
var aggregator = map[string]aggregationFn{
|
||||
"avg": func(series *m.TimeSeries) float64 {
|
||||
sum := float64(0)
|
||||
|
||||
@ -77,19 +78,19 @@ var aggregator map[string]aggregationFn = map[string]aggregationFn{
|
||||
},
|
||||
}
|
||||
|
||||
func (this *ExecutorImpl) Execute(job *m.AlertJob, responseQueue chan *m.AlertResult) {
|
||||
func (executor *ExecutorImpl) Execute(job *m.AlertJob, responseQueue chan *m.AlertResult) {
|
||||
response, err := b.GetSeries(job)
|
||||
|
||||
if err != nil {
|
||||
responseQueue <- &m.AlertResult{State: m.AlertStatePending, Id: job.Rule.Id, AlertJob: job}
|
||||
}
|
||||
|
||||
result := this.validateRule(job.Rule, response)
|
||||
result := executor.validateRule(job.Rule, response)
|
||||
result.AlertJob = job
|
||||
responseQueue <- result
|
||||
}
|
||||
|
||||
func (this *ExecutorImpl) validateRule(rule m.AlertRule, series m.TimeSeriesSlice) *m.AlertResult {
|
||||
func (executor *ExecutorImpl) validateRule(rule m.AlertRule, series m.TimeSeriesSlice) *m.AlertResult {
|
||||
for _, serie := range series {
|
||||
if aggregator[rule.Aggregator] == nil {
|
||||
continue
|
||||
@ -99,24 +100,24 @@ func (this *ExecutorImpl) validateRule(rule m.AlertRule, series m.TimeSeriesSlic
|
||||
var critOperartor = operators[rule.CritOperator]
|
||||
var critResult = critOperartor(aggValue, rule.CritLevel)
|
||||
|
||||
log.Debug(ResultLogFmt, "Crit", serie.Name, aggValue, rule.CritOperator, rule.CritLevel, critResult)
|
||||
log.Trace(resultLogFmt, "Crit", serie.Name, aggValue, rule.CritOperator, rule.CritLevel, critResult)
|
||||
if critResult {
|
||||
return &m.AlertResult{
|
||||
State: m.AlertStateCritical,
|
||||
Id: rule.Id,
|
||||
ActualValue: aggValue,
|
||||
Description: fmt.Sprintf("Actual value: %1.2f for %s", aggValue, serie.Name),
|
||||
Description: fmt.Sprintf(descriptionFmt, aggValue, serie.Name),
|
||||
}
|
||||
}
|
||||
|
||||
var warnOperartor = operators[rule.CritOperator]
|
||||
var warnResult = warnOperartor(aggValue, rule.CritLevel)
|
||||
log.Debug(ResultLogFmt, "Warn", serie.Name, aggValue, rule.WarnOperator, rule.WarnLevel, warnResult)
|
||||
log.Trace(resultLogFmt, "Warn", serie.Name, aggValue, rule.WarnOperator, rule.WarnLevel, warnResult)
|
||||
if warnResult {
|
||||
return &m.AlertResult{
|
||||
State: m.AlertStateWarn,
|
||||
Id: rule.Id,
|
||||
Description: fmt.Sprintf("Actual value: %1.2f for %s", aggValue, serie.Name),
|
||||
Description: fmt.Sprintf(descriptionFmt, aggValue, serie.Name),
|
||||
ActualValue: aggValue,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user