alerting

package
v5.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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)

Types

type AlertTestCommand

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

	Result *EvalContext
}

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 {
	Dash  *m.Dashboard
	OrgId int64
	// contains filtered or unexported fields
}

func NewDashAlertExtractor

func NewDashAlertExtractor(dash *m.Dashboard, orgId int64) *DashAlertExtractor

func (*DashAlertExtractor) GetAlertFromPanels

func (e *DashAlertExtractor) GetAlertFromPanels(jsonWithPanels *simplejson.Json) ([]*m.Alert, error)

func (*DashAlertExtractor) GetAlerts

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

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() *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 Engine

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

func NewEngine

func NewEngine() *Engine

func (*Engine) Run

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

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) 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() 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(evalContext *EvalContext) bool

	GetNotifierId() int64
	GetIsDefault() bool
}

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 NotifierSlice

type NotifierSlice []Notifier

func (NotifierSlice) ShouldUploadImage

func (notifiers NotifierSlice) ShouldUploadImage() bool

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
	NoDataState         m.NoDataOption
	ExecutionErrorState m.ExecutionErrorOption
	State               m.AlertStateType
	Conditions          []Condition
	Notifications       []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