alerting: fix a bunch of lint issues. (#17128)

This commit is contained in:
Carl Bergquist
2019-05-20 12:13:32 +02:00
committed by GitHub
parent a564a54b13
commit bd5bcea5d0
18 changed files with 122 additions and 111 deletions
+12 -4
View File
@@ -11,6 +11,7 @@ import (
"github.com/grafana/grafana/pkg/setting"
)
// EvalContext is the context object for an alert evaluation.
type EvalContext struct {
Firing bool
IsTestRun bool
@@ -33,6 +34,7 @@ type EvalContext struct {
Ctx context.Context
}
// NewEvalContext is the EvalContext constructor.
func NewEvalContext(alertCtx context.Context, rule *Rule) *EvalContext {
return &EvalContext{
Ctx: alertCtx,
@@ -45,12 +47,14 @@ func NewEvalContext(alertCtx context.Context, rule *Rule) *EvalContext {
}
}
// StateDescription contains visual information about the alert state.
type StateDescription struct {
Color string
Text string
Data string
}
// GetStateModel returns the `StateDescription` based on current state.
func (c *EvalContext) GetStateModel() *StateDescription {
switch c.Rule.State {
case models.AlertStateOK:
@@ -78,18 +82,21 @@ func (c *EvalContext) GetStateModel() *StateDescription {
}
}
func (c *EvalContext) ShouldUpdateAlertState() bool {
func (c *EvalContext) shouldUpdateAlertState() bool {
return c.Rule.State != c.PrevAlertState
}
func (a *EvalContext) GetDurationMs() float64 {
return float64(a.EndTime.Nanosecond()-a.StartTime.Nanosecond()) / float64(1000000)
// GetDurationMs returns the duration of the alert evaluation.
func (c *EvalContext) GetDurationMs() float64 {
return float64(c.EndTime.Nanosecond()-c.StartTime.Nanosecond()) / float64(1000000)
}
// GetNotificationTitle returns the title of the alert rule including alert state.
func (c *EvalContext) GetNotificationTitle() string {
return "[" + c.GetStateModel().Text + "] " + c.Rule.Name
}
// GetDashboardUID returns the dashboard uid for the alert rule.
func (c *EvalContext) GetDashboardUID() (*models.DashboardRef, error) {
if c.dashboardRef != nil {
return c.dashboardRef, nil
@@ -106,6 +113,7 @@ func (c *EvalContext) GetDashboardUID() (*models.DashboardRef, error) {
const urlFormat = "%s?fullscreen&edit&tab=alert&panelId=%d&orgId=%d"
// GetRuleUrl returns the url to the dashboard containing the alert.
func (c *EvalContext) GetRuleUrl() (string, error) {
if c.IsTestRun {
return setting.AppUrl, nil
@@ -118,7 +126,7 @@ func (c *EvalContext) GetRuleUrl() (string, error) {
return fmt.Sprintf(urlFormat, models.GetFullDashboardUrl(ref.Uid, ref.Slug), c.Rule.PanelId, c.Rule.OrgId), nil
}
// GetNewState returns the new state from the alert rule evaluation
// GetNewState returns the new state from the alert rule evaluation.
func (c *EvalContext) GetNewState() models.AlertStateType {
ns := getNewStateInternal(c)
if ns != models.AlertStateAlerting || c.Rule.For == 0 {