Documentation
¶
Index ¶
- func NewScheduler(cfg SchedulerCfg, stateManager *state.Manager) *schedule
- func SchedulerUserFor(orgID int64) *user.SignedInUser
- type AlertRuleStopReasonProvider
- type AlertingResultsFromRuleState
- type AlertsSender
- type AlertsSenderMock
- type AlertsSenderMock_Expecter
- type AlertsSenderMock_Send_Call
- func (_c *AlertsSenderMock_Send_Call) Return() *AlertsSenderMock_Send_Call
- func (_c *AlertsSenderMock_Send_Call) Run(run func(ctx context.Context, key models.AlertRuleKey, ...)) *AlertsSenderMock_Send_Call
- func (_c *AlertsSenderMock_Send_Call) RunAndReturn(run func(context.Context, models.AlertRuleKey, definitions.PostableAlerts)) *AlertsSenderMock_Send_Call
- type Evaluation
- type JitterStrategy
- type RecordingWriter
- type RetryConfig
- type Rule
- type RuleStateProvider
- type RuleStatus
- type RulesStore
- type ScheduleService
- type SchedulerCfg
- type SyncAlertsSenderMock
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewScheduler ¶
func NewScheduler(cfg SchedulerCfg, stateManager *state.Manager) *schedule
NewScheduler returns a new scheduler.
func SchedulerUserFor ¶
func SchedulerUserFor(orgID int64) *user.SignedInUser
Types ¶
type AlertRuleStopReasonProvider ¶
type AlertRuleStopReasonProvider interface {
// FindReason returns two values:
// 1. The first value is the reason for stopping the alert rule (error type).
// 2. The second value is an error indicating any issues that occurred while determining the stop reason.
// If this is non-nil, the scheduler uses the default reason.
FindReason(ctx context.Context, logger log.Logger, key ngmodels.AlertRuleKeyWithGroup) (error, error)
}
AlertRuleStopReasonProvider is an interface for determining the reason why an alert rule was stopped.
type AlertingResultsFromRuleState ¶
type AlertingResultsFromRuleState struct {
Manager RuleStateProvider
Rule *ngmodels.AlertRule
}
AlertingResultsFromRuleState implements eval.AlertingResultsReader that gets the data from state manager. It returns results fingerprints only for Alerting and Pending states that have empty StateReason.
func (AlertingResultsFromRuleState) Read ¶
func (n AlertingResultsFromRuleState) Read() map[data.Fingerprint]struct{}
type AlertsSender ¶
type AlertsSender interface {
Send(ctx context.Context, key ngmodels.AlertRuleKey, alerts definitions.PostableAlerts)
}
AlertsSender is an interface for a service that is responsible for sending notifications to the end-user.
type AlertsSenderMock ¶
AlertsSenderMock is an autogenerated mock type for the AlertsSender type
func NewAlertsSenderMock ¶
func NewAlertsSenderMock(t interface {
mock.TestingT
Cleanup(func())
}) *AlertsSenderMock
NewAlertsSenderMock creates a new instance of AlertsSenderMock. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*AlertsSenderMock) EXPECT ¶
func (_m *AlertsSenderMock) EXPECT() *AlertsSenderMock_Expecter
func (*AlertsSenderMock) Send ¶
func (_m *AlertsSenderMock) Send(ctx context.Context, key models.AlertRuleKey, alerts definitions.PostableAlerts)
Send provides a mock function with given fields: ctx, key, alerts
type AlertsSenderMock_Expecter ¶
type AlertsSenderMock_Expecter struct {
// contains filtered or unexported fields
}
func (*AlertsSenderMock_Expecter) Send ¶
func (_e *AlertsSenderMock_Expecter) Send(ctx interface{}, key interface{}, alerts interface{}) *AlertsSenderMock_Send_Call
Send is a helper method to define mock.On call
- ctx context.Context
- key models.AlertRuleKey
- alerts definitions.PostableAlerts
type AlertsSenderMock_Send_Call ¶
AlertsSenderMock_Send_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Send'
func (*AlertsSenderMock_Send_Call) Return ¶
func (_c *AlertsSenderMock_Send_Call) Return() *AlertsSenderMock_Send_Call
func (*AlertsSenderMock_Send_Call) Run ¶
func (_c *AlertsSenderMock_Send_Call) Run(run func(ctx context.Context, key models.AlertRuleKey, alerts definitions.PostableAlerts)) *AlertsSenderMock_Send_Call
func (*AlertsSenderMock_Send_Call) RunAndReturn ¶
func (_c *AlertsSenderMock_Send_Call) RunAndReturn(run func(context.Context, models.AlertRuleKey, definitions.PostableAlerts)) *AlertsSenderMock_Send_Call
type Evaluation ¶
type Evaluation struct {
// contains filtered or unexported fields
}
func (*Evaluation) Fingerprint ¶
func (e *Evaluation) Fingerprint() fingerprint
type JitterStrategy ¶
type JitterStrategy int
JitterStrategy represents a modifier to alert rule timing that affects how evaluations are distributed.
const ( JitterNever JitterStrategy = iota JitterByGroup JitterByRule )
func JitterStrategyFrom ¶
func JitterStrategyFrom(cfg setting.UnifiedAlertingSettings, toggles featuremgmt.FeatureToggles) JitterStrategy
JitterStrategyFrom returns the JitterStrategy indicated by the current Grafana feature toggles.
type RecordingWriter ¶
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int64
InitialRetryDelay time.Duration
MaxRetryDelay time.Duration
RandomizationFactor float64
}
RetryConfig configures the exponential backoff for alert rule and recording rule evaluations.
type Rule ¶
type Rule interface {
// Run creates the resources that will perform the rule's work, and starts it. It blocks indefinitely, until Stop is called or another signal is sent.
Run() error
// Stop shuts down the rule's execution with an optional reason. It has no effect if the rule has not yet been Run.
Stop(reason error)
// Eval sends a signal to execute the work represented by the rule, exactly one time.
// It has no effect if the rule has not yet been Run, or if the rule is Stopped.
Eval(eval *Evaluation) (bool, *Evaluation)
// Update sends a singal to change the definition of the rule.
Update(eval *Evaluation) bool
// Type gives the type of the rule.
Type() ngmodels.RuleType
// Status indicates the status of the evaluating rule.
Status() ngmodels.RuleStatus
// Identifier returns the identifier of the rule.
Identifier() ngmodels.AlertRuleKeyWithGroup
}
Rule represents a single piece of work that is executed periodically by the ruler.
type RuleStateProvider ¶
type RuleStatus ¶
type RulesStore ¶
type RulesStore interface {
GetAlertRulesKeysForScheduling(ctx context.Context) ([]ngmodels.AlertRuleKeyWithVersion, error)
GetAlertRulesForScheduling(ctx context.Context, query *ngmodels.GetAlertRulesForSchedulingQuery) error
}
RulesStore is a store that provides alert rules for scheduling
type ScheduleService ¶
type ScheduleService interface {
// Run the scheduler until the context is canceled or the scheduler returns
// an error. The scheduler is terminated when this function returns.
Run(context.Context) error
}
ScheduleService is an interface for a service that schedules the evaluation of alert rules.
type SchedulerCfg ¶
type SchedulerCfg struct {
RetryConfig RetryConfig
BaseInterval time.Duration
C clock.Clock
MinRuleInterval time.Duration
DisableGrafanaFolder bool
RecordingRulesCfg setting.RecordingRuleSettings
AppURL *url.URL
JitterEvaluations JitterStrategy
EvaluatorFactory eval.EvaluatorFactory
RuleStore RulesStore
Metrics *metrics.Scheduler
AlertSender AlertsSender
Tracer tracing.Tracer
Log log.Logger
RecordingWriter RecordingWriter
RuleStopReasonProvider AlertRuleStopReasonProvider
FeatureToggles featuremgmt.FeatureToggles
}
SchedulerCfg is the scheduler configuration.
type SyncAlertsSenderMock ¶
type SyncAlertsSenderMock struct {
*AlertsSenderMock
// contains filtered or unexported fields
}
func NewSyncAlertsSenderMock ¶
func NewSyncAlertsSenderMock() *SyncAlertsSenderMock
func (*SyncAlertsSenderMock) Calls ¶
func (m *SyncAlertsSenderMock) Calls() []mock.Call
func (*SyncAlertsSenderMock) Send ¶
func (m *SyncAlertsSenderMock) Send(ctx context.Context, key models.AlertRuleKey, alerts definitions.PostableAlerts)