schedule

package
v0.0.0-...-56fe054 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 40 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 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

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 RecordingWriter

type RecordingWriter interface {
	WriteDatasource(ctx context.Context, dsUID string, name string, t time.Time, frames data.Frames, orgID int64, extraLabels map[string]string) error
}

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 RuleStateProvider interface {
	GetStatesForRuleUID(orgID int64, alertRuleUID string) []*state.State
}

type RuleStatus

type RuleStatus struct {
	Health              string
	LastError           error
	EvaluationTimestamp time.Time
	EvaluationDuration  time.Duration
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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