query

package
v0.0.0-...-8ca999e Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAlertFilter

func RegisterAlertFilter(name string, constructor AlertFilterConstructor)

func RegisterAlertStatsQuery

func RegisterAlertStatsQuery(name string, constructor alertStatsQueryConstructor)

RegisterAlertStatsQuery registers a new AlertStatsQuery.

func SortAlertsByFields

func SortAlertsByFields(alerts []model.Alert, fields []string, order Order) sort.Interface

Types

type AlertCountQuery

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

AlertCountQuery counts the number of alerts that match the filter.

func (*AlertCountQuery) Filter

func (q *AlertCountQuery) Filter() AlertFilter

func (*AlertCountQuery) Gather

func (q *AlertCountQuery) Gather(ctx context.Context) []StatsResult

func (*AlertCountQuery) Process

func (q *AlertCountQuery) Process(ctx context.Context, alert *model.Alert) error

type AlertFilter

type AlertFilter interface {
	Type() string
	MatchesAlert(ctx context.Context, alert *model.Alert) bool
}

AlertFilter is a query that can be run against a DB to pull things out of it.

func ExactLabelMatch

func ExactLabelMatch(labels model.Labels) AlertFilter

func UnmarshalAlertFilter

func UnmarshalAlertFilter(args map[string]string) (AlertFilter, error)

UnmarshalAlertFilter unmarshals an AlertFilter from a set of arguments.

type AlertFilterConstructor

type AlertFilterConstructor func(args map[string]string) AlertFilter

AlertFilterConstructor is a function that can construct an AlertFilter from a set of arguments.

type AlertFilterFunc

type AlertFilterFunc func(ctx context.Context, alert *model.Alert) bool

func (AlertFilterFunc) MatchesAlert

func (a AlertFilterFunc) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (AlertFilterFunc) Type

func (a AlertFilterFunc) Type() string

type AlertQuery

type AlertQuery struct {
	Query
	Filter AlertFilter
}

func NewAlertQuery

func NewAlertQuery(filter AlertFilter, ops ...QueryOption) AlertQuery

type AlertStatsQuery

type AlertStatsQuery interface {
	// Filter returns the filter that this filters the data that gets passed to Process().
	Filter() AlertFilter

	// Process is called for each alert that matches the filter.
	Process(ctx context.Context, alert *model.Alert) error

	// Gather is called after all alerts have been processed. It returns the results of the query.
	Gather(ctx context.Context) []StatsResult
}

AlertStatsQuery is a query that can be run against a DB to pull aggregated numbers out of it.

func NewAlertCountQuery

func NewAlertCountQuery(args map[string]string) (AlertStatsQuery, error)

func NewAlertStatusCountQuery

func NewAlertStatusCountQuery(args map[string]string) (AlertStatsQuery, error)

func UnmarshalAlertStatsQuery

func UnmarshalAlertStatsQuery(ty string, args map[string]string) (AlertStatsQuery, error)

UnmarshalAlertStatsQuery unmarshals an AlertStatsQuery from a set of arguments.

type AlertStatusCountQuery

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

AlertStatusCountQuery counts the number of alerts, grouped by status.

func (*AlertStatusCountQuery) Filter

func (q *AlertStatusCountQuery) Filter() AlertFilter

func (*AlertStatusCountQuery) Gather

func (*AlertStatusCountQuery) Process

func (q *AlertStatusCountQuery) Process(ctx context.Context, alert *model.Alert) error

type AllFilter

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

func AllAlerts

func AllAlerts(queries ...AlertFilter) *AllFilter

func AllSilences

func AllSilences(queries ...SilenceFilter) *AllFilter

func (*AllFilter) MatchesAlert

func (a *AllFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*AllFilter) MatchesSilence

func (a *AllFilter) MatchesSilence(ctx context.Context, silence *model.Silence) bool

func (*AllFilter) Type

func (a *AllFilter) Type() string

type AllMatchFilter

type AllMatchFilter struct{}

AllMatchFilter is a query that returns every alert.

func MatchAll

func MatchAll() *AllMatchFilter

func (*AllMatchFilter) MatchesAlert

func (a *AllMatchFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*AllMatchFilter) MatchesSilence

func (a *AllMatchFilter) MatchesSilence(ctx context.Context, silence *model.Silence) bool

func (*AllMatchFilter) Type

func (a *AllMatchFilter) Type() string

type ExactLabelMatchFilter

type ExactLabelMatchFilter struct {
	Labels model.Labels
	// contains filtered or unexported fields
}

ExactLabelMatchFilter is an AlertFilter that matches alerts that contain exactly the given labelset.

func (*ExactLabelMatchFilter) MatchesAlert

func (e *ExactLabelMatchFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*ExactLabelMatchFilter) Type

func (e *ExactLabelMatchFilter) Type() string

type IDFilter

type IDFilter struct {
	ID string
}

IDFilter is a query that matches a specific alert or silence by ID.

func ID

func ID(id string) *IDFilter

func (*IDFilter) MatchesAlert

func (i *IDFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*IDFilter) MatchesSilence

func (i *IDFilter) MatchesSilence(ctx context.Context, silence *model.Silence) bool

func (*IDFilter) Type

func (i *IDFilter) Type() string

type LastNotifyTimeRangeFilter

type LastNotifyTimeRangeFilter struct {
	MinTime time.Time
	MaxTime time.Time
}

func LastNotifyTimeMax

func LastNotifyTimeMax(maxTime time.Time) *LastNotifyTimeRangeFilter

func LastNotifyTimeMin

func LastNotifyTimeMin(minTime time.Time) *LastNotifyTimeRangeFilter

func LastNotifyTimeWithin

func LastNotifyTimeWithin(minTime, maxTime time.Time) *LastNotifyTimeRangeFilter

func (*LastNotifyTimeRangeFilter) MatchesAlert

func (l *LastNotifyTimeRangeFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*LastNotifyTimeRangeFilter) Type

type MatcherFilter

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

MatcherFilter is a Filter that matches alerts or silences that contain the given matcher.

func Matcher

func Matcher(m model.Matcher) *MatcherFilter

func (*MatcherFilter) MatchesAlert

func (m *MatcherFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

MatchesAlert returns true if the given matcher matcher the given alert.

func (*MatcherFilter) MatchesSilence

func (m *MatcherFilter) MatchesSilence(ctx context.Context, silence *model.Silence) bool

MatchesSilence returns true if the given matcher is in the given silence.

func (*MatcherFilter) Type

func (i *MatcherFilter) Type() string

type Order

type Order string
const (
	OrderAsc  Order = "ASC"
	OrderDesc Order = "DESC"
)

type PartialLabelMatchFilter

type PartialLabelMatchFilter struct {
	Labels model.Labels
}

PartialLabelMatchFilter is an AlertFilter that matches alerts that contain the given labels (but may have extras on top of these).

func PartialLabelMatch

func PartialLabelMatch(labels model.Labels) *PartialLabelMatchFilter

func (*PartialLabelMatchFilter) MatchesAlert

func (p *PartialLabelMatchFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*PartialLabelMatchFilter) MatchesSilence

func (p *PartialLabelMatchFilter) MatchesSilence(ctx context.Context, silence *model.Silence) bool

func (*PartialLabelMatchFilter) Type

func (p *PartialLabelMatchFilter) Type() string

type Query

type Query struct {
	// OrderBy is a direction to order the results by.
	Order Order

	// OrderBy is a list of fields to order the results by.
	OrderBy []string

	// Offset is the number of results to skip before returning results.
	Offset int

	// Limit is the maximum number of results to return.
	Limit int
}

Query represents a generic query based on SQL semantics.

type QueryOpFunc

type QueryOpFunc func(*Query)

func (QueryOpFunc) Apply

func (f QueryOpFunc) Apply(q *Query)

type QueryOption

type QueryOption interface {
	Apply(*Query)
}

QueryOption represents an option that can be applied to a query.

func Limit

func Limit(limit int) QueryOption

func Offset

func Offset(offset int) QueryOption

func OrderBy

func OrderBy(fields []string, order Order) QueryOption

type SilenceFilter

type SilenceFilter interface {
	MatchesSilence(ctx context.Context, silence *model.Silence) bool
}

SilenceFilter is a query that can be run against a DB to pull things out of it.

func SilenceIsActive

func SilenceIsActive() SilenceFilter

SilenceIsActive returns a SilenceFilter that matches only active silences.

type SilenceFilterFunc

type SilenceFilterFunc func(ctx context.Context, alert *model.Silence) bool

func (SilenceFilterFunc) MatchesSilence

func (a SilenceFilterFunc) MatchesSilence(ctx context.Context, alert *model.Silence) bool

type SilenceQuery

type SilenceQuery struct {
	Query
	Filter SilenceFilter
}

func NewSilenceQuery

func NewSilenceQuery(filter SilenceFilter, ops ...QueryOption) SilenceQuery

type StatsResult

type StatsResult struct {
	// Labels are the labels that apply to this result.
	Labels map[string]string `json:"labels"`

	// Frames are the data frames that apply to this result.
	Frames [][]float64 `json:"frames"`
}

StatsResult is a single result from a StatsQuery.

type StatusFilter

type StatusFilter struct {
	Status model.AlertStatus
}

StatusFilter returns all the alerts that match the given status.

func Status

func Status(s model.AlertStatus) *StatusFilter

func (*StatusFilter) MatchesAlert

func (s *StatusFilter) MatchesAlert(ctx context.Context, alert *model.Alert) bool

func (*StatusFilter) Type

func (s *StatusFilter) Type() string

Jump to

Keyboard shortcuts

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