alerting

package
v6.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFrequencyCannotBeZeroOrLess = errors.New(`"evaluate every" cannot be zero or below`)
	ErrFrequencyCouldNotBeParsed   = errors.New(`"evaluate every" field could not be parsed`)
)
View Source
var (
	ValueFormatRegex = regexp.MustCompile(`^\d+`)
	UnitFormatRegex  = regexp.MustCompile(`\w{1}$`)
)

Functions

func RegisterCondition

func RegisterCondition(typeName string, factory ConditionFactory)

func RegisterNotifier

func RegisterNotifier(plugin *NotifierPlugin)

RegisterNotifier register an notifier

Types

type AlertTestCommand

type AlertTestCommand struct {
	Dashboard *simplejson.Json
	PanelId   int64
	OrgId     int64
	User      *m.SignedInUser

	Result *EvalContext
}

type AlertingService

type AlertingService struct {
	RenderService rendering.Service `inject:""`
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine() *AlertingService

func (*AlertingService) Init

func (e *AlertingService) Init() error

func (*AlertingService) IsDisabled

func (e *AlertingService) IsDisabled() bool

func (*AlertingService) Run

func (e *AlertingService) Run(ctx context.Context) error

type Condition

type Condition interface {
	Eval(result *EvalContext) (*ConditionResult, error)
}

type ConditionFactory

type ConditionFactory func(model *simplejson.Json, index int) (Condition, error)

type ConditionResult

type ConditionResult struct {
	Firing      bool
	NoDataFound bool
	Operator    string
	EvalMatches []*EvalMatch
}

type DashAlertExtractor

type DashAlertExtractor struct {
	User  *m.SignedInUser
	Dash  *m.Dashboard
	OrgID int64
	// contains filtered or unexported fields
}

DashAlertExtractor extracts alerts from the dashboard json

func NewDashAlertExtractor

func NewDashAlertExtractor(dash *m.Dashboard, orgID int64, user *m.SignedInUser) *DashAlertExtractor

NewDashAlertExtractor returns a new DashAlertExtractor

func (*DashAlertExtractor) GetAlerts

func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error)

GetAlerts extracts alerts from the dashboard json and does full validation on the alert json data

func (*DashAlertExtractor) ValidateAlerts

func (e *DashAlertExtractor) ValidateAlerts() error

ValidateAlerts validates alerts in the dashboard json but does not require a valid dashboard id in the first validation pass

type DefaultEvalHandler

type DefaultEvalHandler struct {
	// contains filtered or unexported fields
}

func NewEvalHandler

func NewEvalHandler() *DefaultEvalHandler

func (*DefaultEvalHandler) Eval

func (e *DefaultEvalHandler) Eval(context *EvalContext)

type DefaultResultHandler

type DefaultResultHandler struct {
	// contains filtered or unexported fields
}

func NewResultHandler

func NewResultHandler(renderService rendering.Service) *DefaultResultHandler

func (*DefaultResultHandler) Handle

func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error

type DefaultRuleReader

type DefaultRuleReader struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRuleReader

func NewRuleReader() *DefaultRuleReader

func (*DefaultRuleReader) Fetch

func (arr *DefaultRuleReader) Fetch() []*Rule

type EvalContext

type EvalContext struct {
	Firing         bool
	IsTestRun      bool
	EvalMatches    []*EvalMatch
	Logs           []*ResultLogEntry
	Error          error
	ConditionEvals string
	StartTime      time.Time
	EndTime        time.Time
	Rule           *Rule

	ImagePublicUrl  string
	ImageOnDiskPath string
	NoDataFound     bool
	PrevAlertState  m.AlertStateType

	Ctx context.Context
	// contains filtered or unexported fields
}

func NewEvalContext

func NewEvalContext(alertCtx context.Context, rule *Rule) *EvalContext

func (*EvalContext) GetDashboardUID

func (c *EvalContext) GetDashboardUID() (*m.DashboardRef, error)

func (*EvalContext) GetDurationMs

func (a *EvalContext) GetDurationMs() float64

func (*EvalContext) GetNewState

func (c *EvalContext) GetNewState() m.AlertStateType

GetNewState returns the new state from the alert rule evaluation

func (*EvalContext) GetNotificationTitle

func (c *EvalContext) GetNotificationTitle() string

func (*EvalContext) GetRuleUrl

func (c *EvalContext) GetRuleUrl() (string, error)

func (*EvalContext) GetStateModel

func (c *EvalContext) GetStateModel() *StateDescription

func (*EvalContext) ShouldUpdateAlertState

func (c *EvalContext) ShouldUpdateAlertState() bool

type EvalHandler

type EvalHandler interface {
	Eval(evalContext *EvalContext)
}

type EvalMatch

type EvalMatch struct {
	Value  null.Float        `json:"value"`
	Metric string            `json:"metric"`
	Tags   map[string]string `json:"tags"`
}

type Job

type Job struct {
	Offset     int64
	OffsetWait bool
	Delay      bool
	Running    bool
	Rule       *Rule
}

type Level

type Level struct {
	Operator string
	Value    float64
}

type NotificationService

type NotificationService interface {
	SendIfNeeded(context *EvalContext) error
}

func NewNotificationService

func NewNotificationService(renderService rendering.Service) NotificationService

type NotificationTestCommand

type NotificationTestCommand struct {
	State    m.AlertStateType
	Name     string
	Type     string
	Settings *simplejson.Json
}

type Notifier

type Notifier interface {
	Notify(evalContext *EvalContext) error
	GetType() string
	NeedsImage() bool

	// ShouldNotify checks this evaluation should send an alert notification
	ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.AlertNotificationState) bool

	GetNotifierUid() string
	GetIsDefault() bool
	GetSendReminder() bool
	GetDisableResolveMessage() bool
	GetFrequency() time.Duration
}

func InitNotifier

func InitNotifier(model *m.AlertNotification) (Notifier, error)

InitNotifier instantiate a new notifier based on the model

type NotifierFactory

type NotifierFactory func(notification *m.AlertNotification) (Notifier, error)

type NotifierPlugin

type NotifierPlugin struct {
	Type            string          `json:"type"`
	Name            string          `json:"name"`
	Description     string          `json:"description"`
	OptionsTemplate string          `json:"optionsTemplate"`
	Factory         NotifierFactory `json:"-"`
}

func GetNotifiers

func GetNotifiers() []*NotifierPlugin

type ResultHandler

type ResultHandler interface {
	Handle(evalContext *EvalContext) error
}

type ResultLogEntry

type ResultLogEntry struct {
	Message string
	Data    interface{}
}

type Rule

type Rule struct {
	Id                  int64
	OrgId               int64
	DashboardId         int64
	PanelId             int64
	Frequency           int64
	Name                string
	Message             string
	LastStateChange     time.Time
	For                 time.Duration
	NoDataState         m.NoDataOption
	ExecutionErrorState m.ExecutionErrorOption
	State               m.AlertStateType
	Conditions          []Condition
	Notifications       []string

	StateChanges int64
}

func NewRuleFromDBAlert

func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error)

type RuleReader

type RuleReader interface {
	Fetch() []*Rule
}

type Scheduler

type Scheduler interface {
	Tick(time time.Time, execQueue chan *Job)
	Update(rules []*Rule)
}

func NewScheduler

func NewScheduler() Scheduler

type SchedulerImpl

type SchedulerImpl struct {
	// contains filtered or unexported fields
}

func (*SchedulerImpl) Tick

func (s *SchedulerImpl) Tick(tickTime time.Time, execQueue chan *Job)

func (*SchedulerImpl) Update

func (s *SchedulerImpl) Update(rules []*Rule)

type StateDescription

type StateDescription struct {
	Color string
	Text  string
	Data  string
}

type Ticker

type Ticker struct {
	C chan time.Time
	// contains filtered or unexported fields
}

ticker is a ticker to power the alerting scheduler. it's like a time.Ticker, except:

  • it doesn't drop ticks for slow receivers, rather, it queues up. so that callers are in control to instrument what's going on.
  • it automatically ticks every second, which is the right thing in our current design
  • it ticks on second marks or very shortly after. this provides a predictable load pattern (this shouldn't cause too much load contention issues because the next steps in the pipeline just process at their own pace)
  • the timestamps are used to mark "last datapoint to query for" and as such, are a configurable amount of seconds in the past
  • because we want to allow:
  • a clean "resume where we left off" and "don't yield ticks we already did"
  • adjusting offset over time to compensate for storage backing up or getting fast and providing lower latency you specify a lastProcessed timestamp as well as an offset at creation, or runtime

func NewTicker

func NewTicker(last time.Time, initialOffset time.Duration, c clock.Clock) *Ticker

NewTicker returns a ticker that ticks on second marks or very shortly after, and never drops ticks

type ValidationError

type ValidationError struct {
	Reason      string
	Err         error
	Alertid     int64
	DashboardId int64
	PanelId     int64
}

func (ValidationError) Error

func (e ValidationError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL