2022-09-26 13:55:05 -05:00
|
|
|
package state
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
2023-01-25 11:29:57 -06:00
|
|
|
history_model "github.com/grafana/grafana/pkg/services/ngalert/state/historian/model"
|
2022-09-26 13:55:05 -05:00
|
|
|
)
|
|
|
|
|
|
2022-09-27 08:56:30 -05:00
|
|
|
// InstanceStore represents the ability to fetch and write alert instances.
|
2022-09-26 13:55:05 -05:00
|
|
|
type InstanceStore interface {
|
|
|
|
|
FetchOrgIds(ctx context.Context) ([]int64, error)
|
2023-03-28 10:34:35 +02:00
|
|
|
ListAlertInstances(ctx context.Context, cmd *models.ListAlertInstancesQuery) ([]*models.AlertInstance, error)
|
2023-04-06 12:06:25 -04:00
|
|
|
SaveAlertInstance(ctx context.Context, instance models.AlertInstance) error
|
2022-10-06 14:22:58 +08:00
|
|
|
DeleteAlertInstances(ctx context.Context, keys ...models.AlertInstanceKey) error
|
2022-09-26 13:55:05 -05:00
|
|
|
DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error
|
|
|
|
|
}
|
2022-09-27 08:56:30 -05:00
|
|
|
|
|
|
|
|
// RuleReader represents the ability to fetch alert rules.
|
|
|
|
|
type RuleReader interface {
|
2023-03-28 10:34:35 +02:00
|
|
|
ListAlertRules(ctx context.Context, query *models.ListAlertRulesQuery) (models.RulesGroup, error)
|
2022-09-27 08:56:30 -05:00
|
|
|
}
|
2022-10-05 15:32:20 -05:00
|
|
|
|
|
|
|
|
// Historian maintains an audit log of alert state history.
|
|
|
|
|
type Historian interface {
|
2023-01-24 15:41:38 +00:00
|
|
|
// RecordStates writes a number of state transitions for a given rule to state history. It returns a channel that
|
|
|
|
|
// is closed when writing the state transitions has completed. If an error has occurred, the channel will contain a
|
|
|
|
|
// non-nil error.
|
2023-03-17 12:41:18 -05:00
|
|
|
Record(ctx context.Context, rule history_model.RuleMeta, states []StateTransition) <-chan error
|
2022-10-05 15:32:20 -05:00
|
|
|
}
|
2022-11-09 15:06:49 -06:00
|
|
|
|
|
|
|
|
// ImageCapturer captures images.
|
|
|
|
|
//
|
|
|
|
|
//go:generate mockgen -destination=image_mock.go -package=state github.com/grafana/grafana/pkg/services/ngalert/state ImageCapturer
|
|
|
|
|
type ImageCapturer interface {
|
|
|
|
|
NewImage(ctx context.Context, r *models.AlertRule) (*models.Image, error)
|
|
|
|
|
}
|