schedule

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

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 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

type AlertsSenderMock struct {
	mock.Mock
}

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 (*AlertsSenderMock) Send

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

type AlertsSenderMock_Send_Call struct {
	*mock.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 (*AlertsSenderMock_Send_Call) Run

func (*AlertsSenderMock_Send_Call) RunAndReturn

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

JitterStrategyFrom returns the JitterStrategy indicated by the current Grafana feature toggles.

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(key ngmodels.AlertRuleKey) 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(lastVersion RuleVersionAndPauseStatus) bool
}

Rule represents a single piece of work that is executed periodically by the ruler.

type RuleStateProvider

type RuleStateProvider interface {
	GetStatesForRuleUID(orgID int64, alertRuleUID string) []*state.State
}

type RuleVersionAndPauseStatus

type RuleVersionAndPauseStatus struct {
	Fingerprint fingerprint
	IsPaused    bool
}

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 {
	MaxAttempts          int64
	BaseInterval         time.Duration
	C                    clock.Clock
	MinRuleInterval      time.Duration
	DisableGrafanaFolder bool
	FeatureToggles       featuremgmt.FeatureToggles
	AppURL               *url.URL
	JitterEvaluations    JitterStrategy
	EvaluatorFactory     eval.EvaluatorFactory
	RuleStore            RulesStore
	Metrics              *metrics.Scheduler
	AlertSender          AlertsSender
	Tracer               tracing.Tracer
	Log                  log.Logger
	RecordingWriter      writer.Writer
}

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

Jump to

Keyboard shortcuts

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