historian

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: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrgIDLabel     = "orgID"
	RuleUIDLabel   = "ruleUID"
	GroupLabel     = "group"
	FolderUIDLabel = "folderUID"
)
View Source
const (
	StateHistoryLabelKey   = "from"
	StateHistoryLabelValue = "state-history"
)
View Source
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

func ClampRange(start, end, maxTimeRange int64) (newStart int64, newEnd int64)

ClampRange ensures that the time range is within the configured maximum query length.

func Join

func Join(errs ...error) error

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 NewRequester() client.Requester

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

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 (*AnnotationServiceStore) Find

func (*AnnotationServiceStore) Save

func (s *AnnotationServiceStore) Save(ctx context.Context, panel *PanelKey, annotations []annotations.Item, orgID int64, logger log.Logger) error

type AnnotationStore

type AnnotationStore interface {
	Find(ctx context.Context, query *annotations.ItemQuery) ([]*annotations.ItemDTO, error)
	Save(ctx context.Context, panel *PanelKey, annotations []annotations.Item, orgID int64, logger log.Logger) error
}

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

func (c *HttpLokiClient) Ping(ctx context.Context) error

func (*HttpLokiClient) Push

func (c *HttpLokiClient) Push(ctx context.Context, s []Stream) error

func (*HttpLokiClient) RangeQuery

func (c *HttpLokiClient) RangeQuery(ctx context.Context, logQL string, start, end, limit int64) (QueryRes, error)

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
}

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

type Operator

type Operator string

Kind of Operation (=, !=, =~, !~)

const (
	// Equal operator (=)
	Eq Operator = "="
	// Not Equal operator (!=)
	Neq Operator = "!="
	// Equal operator supporting RegEx (=~)
	EqRegEx Operator = "=~"
	// Not Equal operator supporting RegEx (!~)
	NeqRegEx Operator = "!~"
)

type PanelKey

type PanelKey struct {
	// contains filtered or unexported fields
}

PanelKey uniquely identifies a panel.

func NewPanelKey

func NewPanelKey(orgID int64, dashUID string, panelID int64) PanelKey

func (PanelKey) DashUID

func (p PanelKey) DashUID() string

func (PanelKey) OrgID

func (p PanelKey) OrgID() int64

func (PanelKey) PanelID

func (p PanelKey) PanelID() int64

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 QueryData

type QueryData struct {
	Result []Stream `json:"result"`
}

type QueryRes

type QueryRes struct {
	Data QueryData `json:"data"`
}

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

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 RuleStore

type RuleStore interface {
	GetAlertRuleByUID(ctx context.Context, query *ngmodels.GetAlertRuleByUIDQuery) (*ngmodels.AlertRule, error)
}

type Sample

type Sample struct {
	T time.Time
	V string
}

func (*Sample) MarshalJSON

func (r *Sample) MarshalJSON() ([]byte, error)

func (*Sample) UnmarshalJSON

func (r *Sample) UnmarshalJSON(b []byte) error

type Selector

type Selector struct {
	// Label to Select
	Label string
	Op    Operator
	// Value that is expected
	Value string
}

func NewSelector

func NewSelector(label, op, value string) (Selector, error)

type SnappyProtoEncoder

type SnappyProtoEncoder struct{}

type Stream

type Stream struct {
	Stream map[string]string `json:"stream"`
	Values []Sample          `json:"values"`
}

func StatesToStream

func StatesToStream(rule history_model.RuleMeta, states []state.StateTransition, externalLabels map[string]string, logger log.Logger) Stream

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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