Documentation ¶
Index ¶
- Constants
- func BuildAnnotationTextAndData(rule history_model.RuleMeta, currentState *state.State) (string, *simplejson.Json)
- func BuildLogQuery(query models.HistoryQuery) (string, error)
- func ClampRange(start, end, maxTimeRange int64) (newStart int64, newEnd int64)
- func Join(errs ...error) error
- func NewFakeRequester() *fakeRequester
- func NewRequester() client.Requester
- func ShouldRecordAnnotation(t state.StateTransition) bool
- type AnnotationBackend
- type AnnotationService
- type AnnotationServiceStore
- type AnnotationStore
- type Backend
- type BackendType
- type HttpLokiClient
- type JsonEncoder
- type LokiConfig
- type LokiEntry
- type MultipleBackend
- type NoOpHistorian
- type Operator
- type PanelKey
- type Querier
- type QueryData
- type QueryRes
- type RemoteLokiBackend
- type RuleStore
- type Sample
- type Selector
- type SnappyProtoEncoder
- type Stream
Constants ¶
const ( OrgIDLabel = "orgID" RuleUIDLabel = "ruleUID" GroupLabel = "group" FolderUIDLabel = "folderUID" )
const ( StateHistoryLabelKey = "from" StateHistoryLabelValue = "state-history" )
const StateHistoryWriteTimeout = time.Minute
Variables ¶
This section is empty.
Functions ¶
func BuildAnnotationTextAndData ¶
func BuildAnnotationTextAndData(rule history_model.RuleMeta, currentState *state.State) (string, *simplejson.Json)
func BuildLogQuery ¶
func BuildLogQuery(query models.HistoryQuery) (string, error)
func ClampRange ¶
ClampRange ensures that the time range is within the configured maximum query length.
func Join ¶
TODO: This is vendored verbatim from the Go standard library. TODO: The grafana project doesn't support go 1.20 yet, so we can't use errors.Join() directly. TODO: Remove this and replace calls with "errors.Join(...)" when go 1.20 becomes the minimum supported version.
Join returns an error that wraps the given errors. Any nil error values are discarded. Join returns nil if errs contains no non-nil values. The error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string.
func NewFakeRequester ¶
func NewFakeRequester() *fakeRequester
func NewRequester ¶
func ShouldRecordAnnotation ¶
func ShouldRecordAnnotation(t state.StateTransition) bool
ShouldRecordAnnotation returns true if an annotation should be created for a given state transition. This is stricter than shouldRecord to avoid cluttering panels with state transitions.
Types ¶
type AnnotationBackend ¶
type AnnotationBackend struct {
// contains filtered or unexported fields
}
AnnotationBackend is an implementation of state.Historian that uses Grafana Annotations as the backing datastore.
func NewAnnotationBackend ¶
func NewAnnotationBackend(logger log.Logger, annotations AnnotationStore, rules RuleStore, metrics *metrics.Historian) *AnnotationBackend
func (*AnnotationBackend) Query ¶
func (h *AnnotationBackend) Query(ctx context.Context, query ngmodels.HistoryQuery) (*data.Frame, error)
Query filters state history annotations and formats them into a dataframe.
func (*AnnotationBackend) Record ¶
func (h *AnnotationBackend) Record(ctx context.Context, rule history_model.RuleMeta, states []state.StateTransition) <-chan error
Record writes a number of state transitions for a given rule to state history.
type AnnotationService ¶
type AnnotationService interface { Find(ctx context.Context, query *annotations.ItemQuery) ([]*annotations.ItemDTO, error) SaveMany(ctx context.Context, items []annotations.Item) error }
type AnnotationServiceStore ¶
type AnnotationServiceStore struct {
// contains filtered or unexported fields
}
func NewAnnotationStore ¶
func NewAnnotationStore(svc AnnotationService, dashboards dashboards.DashboardService, metrics *metrics.Historian) *AnnotationServiceStore
func (*AnnotationServiceStore) Find ¶
func (s *AnnotationServiceStore) Find(ctx context.Context, query *annotations.ItemQuery) ([]*annotations.ItemDTO, error)
type AnnotationStore ¶
type Backend ¶
type Backend interface { Record(ctx context.Context, rule history_model.RuleMeta, states []state.StateTransition) <-chan error Query(ctx context.Context, query ngmodels.HistoryQuery) (*data.Frame, error) }
type BackendType ¶
type BackendType string
BackendType identifies different kinds of state history backends.
const ( BackendTypeAnnotations BackendType = "annotations" BackendTypeLoki BackendType = "loki" BackendTypeMultiple BackendType = "multiple" BackendTypeNoop BackendType = "noop" )
func ParseBackendType ¶
func ParseBackendType(s string) (BackendType, error)
func (BackendType) String ¶
func (bt BackendType) String() string
String implements Stringer for BackendType.
type HttpLokiClient ¶
type HttpLokiClient struct {
// contains filtered or unexported fields
}
func NewLokiClient ¶
func NewLokiClient(cfg LokiConfig, req client.Requester, metrics *metrics.Historian, logger log.Logger) *HttpLokiClient
func (*HttpLokiClient) RangeQuery ¶
type JsonEncoder ¶
type JsonEncoder struct{}
type LokiConfig ¶
type LokiConfig struct { ReadPathURL *url.URL WritePathURL *url.URL BasicAuthUser string BasicAuthPassword string TenantID string ExternalLabels map[string]string Encoder encoder MaxQueryLength time.Duration }
func NewLokiConfig ¶
func NewLokiConfig(cfg setting.UnifiedAlertingStateHistorySettings) (LokiConfig, error)
type LokiEntry ¶
type LokiEntry struct { SchemaVersion int `json:"schemaVersion"` Previous string `json:"previous"` Current string `json:"current"` Error string `json:"error,omitempty"` Values *simplejson.Json `json:"values"` Condition string `json:"condition"` DashboardUID string `json:"dashboardUID"` PanelID int64 `json:"panelID"` Fingerprint string `json:"fingerprint"` RuleTitle string `json:"ruleTitle"` RuleID int64 `json:"ruleID"` RuleUID string `json:"ruleUID"` // InstanceLabels is exactly the set of labels associated with the alert instance in Alertmanager. // These should not be conflated with labels associated with log streams. InstanceLabels map[string]string `json:"labels"` }
type MultipleBackend ¶
type MultipleBackend struct {
// contains filtered or unexported fields
}
MultipleBackend is a state.Historian that records history to multiple backends at once. Only one backend is used for reads. The backend selected for read traffic is called the primary and all others are called secondaries.
func NewMultipleBackend ¶
func NewMultipleBackend(primary Backend, secondaries ...Backend) *MultipleBackend
func (*MultipleBackend) Query ¶
func (h *MultipleBackend) Query(ctx context.Context, query ngmodels.HistoryQuery) (*data.Frame, error)
func (*MultipleBackend) Record ¶
func (h *MultipleBackend) Record(ctx context.Context, rule history_model.RuleMeta, states []state.StateTransition) <-chan error
type NoOpHistorian ¶
type NoOpHistorian struct{}
NoOpHistorian is a state.Historian that does nothing with the resulting data, to be used in contexts where history is not needed.
func NewNopHistorian ¶
func NewNopHistorian() *NoOpHistorian
func (*NoOpHistorian) Query ¶
func (f *NoOpHistorian) Query(ctx context.Context, query models.HistoryQuery) (*data.Frame, error)
func (*NoOpHistorian) Record ¶
func (f *NoOpHistorian) Record(ctx context.Context, _ history_model.RuleMeta, _ []state.StateTransition) <-chan error
type PanelKey ¶
type PanelKey struct {
// contains filtered or unexported fields
}
PanelKey uniquely identifies a panel.
type Querier ¶
type Querier interface {
Query(ctx context.Context, query models.HistoryQuery) (*data.Frame, error)
}
Querier represents the ability to query state history. TODO: This package also contains implementations of this interface. TODO: This type should be moved to the side of the consumer, when the consumer is created in the future. We add it here temporarily to more clearly define this package's interface.
type RemoteLokiBackend ¶
type RemoteLokiBackend struct {
// contains filtered or unexported fields
}
RemoteLokibackend is a state.Historian that records state history to an external Loki instance.
func NewRemoteLokiBackend ¶
func NewRemoteLokiBackend(logger log.Logger, cfg LokiConfig, req client.Requester, metrics *metrics.Historian) *RemoteLokiBackend
func (*RemoteLokiBackend) Query ¶
func (h *RemoteLokiBackend) Query(ctx context.Context, query models.HistoryQuery) (*data.Frame, error)
Query retrieves state history entries from an external Loki instance and formats the results into a dataframe.
func (*RemoteLokiBackend) Record ¶
func (h *RemoteLokiBackend) Record(ctx context.Context, rule history_model.RuleMeta, states []state.StateTransition) <-chan error
Record writes a number of state transitions for a given rule to an external Loki instance.
func (*RemoteLokiBackend) TestConnection ¶
func (h *RemoteLokiBackend) TestConnection(ctx context.Context) error
type Selector ¶
type Selector struct { // Label to Select Label string Op Operator // Value that is expected Value string }
func NewSelector ¶
type SnappyProtoEncoder ¶
type SnappyProtoEncoder struct{}