mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Reduce piecemeal state fields * Read data directly off state instead of rule * Unify state and context into single struct * Expose contextual information to layer above setNextState * Work in terms of ContextualState and call historian in batches * Call annotations service in batches * Export format state and reason and remove workaround in unrelated test package * Add new method to annotation service for batch inserting * Fix loop variable aliasing bug caught by linter, didn't change behavior * Incl timerange on annotation tests * Insert one at a time if tags are present * Point to rule from ContextualState rather than copy fields * Build annotations and copy data prior to starting goroutine * Rename to StateTransition * Use new bulk-insert utility * Remove rule from StateTransition and pass in directly to historian * Simplify annotations logic since we have only one rule * Fix logs and context, nilcheck, simplify method name * Regenerate mock
28 lines
1011 B
Go
28 lines
1011 B
Go
package state
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
|
)
|
|
|
|
// InstanceStore represents the ability to fetch and write alert instances.
|
|
type InstanceStore interface {
|
|
FetchOrgIds(ctx context.Context) ([]int64, error)
|
|
ListAlertInstances(ctx context.Context, cmd *models.ListAlertInstancesQuery) error
|
|
SaveAlertInstances(ctx context.Context, cmd ...models.AlertInstance) error
|
|
DeleteAlertInstances(ctx context.Context, keys ...models.AlertInstanceKey) error
|
|
DeleteAlertInstancesByRule(ctx context.Context, key models.AlertRuleKey) error
|
|
}
|
|
|
|
// RuleReader represents the ability to fetch alert rules.
|
|
type RuleReader interface {
|
|
ListAlertRules(ctx context.Context, query *models.ListAlertRulesQuery) error
|
|
}
|
|
|
|
// Historian maintains an audit log of alert state history.
|
|
type Historian interface {
|
|
// RecordStates writes a number of state transitions for a given rule to state history.
|
|
RecordStates(ctx context.Context, rule *models.AlertRule, states []StateTransition)
|
|
}
|