base

package
v1.6.2-0...-8a36637 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: AGPL-3.0 Imports: 94 Imported by: 0

Documentation

Index

Constants

View Source
const RuleGroupLabel = "rule_group"

RuleGroupLabel is the label added by Prometheus, the value of which comes from the GroupKey function

Variables

View Source
var (
	// ErrNoNamespace signals that no namespace was specified in the request
	ErrNoNamespace = errors.New("a namespace must be provided in the request")
	// ErrNoGroupName signals a group name url parameter was not found
	ErrNoGroupName = errors.New("a matching group name must be provided in the request")
	// ErrNoRuleGroups signals the rule group requested does not exist
	ErrNoRuleGroups = errors.New("no rule groups found")
	// ErrBadRuleGroup is returned when the provided rule group can not be unmarshalled
	ErrBadRuleGroup = errors.New("unable to decoded rule group")
)
View Source
var (
	ErrInvalidLengthRuler = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowRuler   = fmt.Errorf("proto: integer overflow")
)
View Source
var RingOp = ring.NewOp([]ring.InstanceState{ring.ACTIVE}, func(s ring.InstanceState) bool {

	return s != ring.ACTIVE
})

RingOp is the operation used for distributing rule groups between rulers.

View Source
var RulesRequest_RuleType_name = map[int32]string{
	0: "AnyRule",
	1: "AlertingRule",
	2: "RecordingRule",
}
View Source
var RulesRequest_RuleType_value = map[string]int32{
	"AnyRule":       0,
	"AlertingRule":  1,
	"RecordingRule": 2,
}

Functions

func AddRuleTokenToGroupName

func AddRuleTokenToGroupName(g *rulespb.RuleGroupDesc, r *rulespb.RuleDesc) string

AddRuleTokenToGroupName adds a rule shard token to a given group's name to make it unique. Only relevant when using "by-rule" sharding strategy.

func MetricsQueryFunc

func MetricsQueryFunc(qf rules.QueryFunc, queries, failedQueries prometheus.Counter) rules.QueryFunc

func NewErrorTranslateQueryableWithFn

func NewErrorTranslateQueryableWithFn(q storage.Queryable, fn ErrTranslateFn) storage.Queryable

func NewLegacyRuleStore

func NewLegacyRuleStore(cfg RuleStoreConfig, hedgeCfg hedging.Config, clientMetrics storage.ClientMetrics, loader promRules.GroupLoader, logger log.Logger) (rulestore.RuleStore, error)

NewLegacyRuleStore returns a rule store backend client based on the provided cfg. The client used by the function is based a legacy object store clients that shouldn't be used anymore.

func NewRuleStore

NewRuleStore returns a rule store backend client based on the provided cfg.

func RecordAndReportRuleQueryMetrics

func RecordAndReportRuleQueryMetrics(qf rules.QueryFunc, queryTime prometheus.Counter, logger log.Logger) rules.QueryFunc

func RegisterRulerServer

func RegisterRulerServer(s *grpc.Server, srv RulerServer)

func RemoveRuleTokenFromGroupName

func RemoveRuleTokenFromGroupName(name string) string

RemoveRuleTokenFromGroupName removes the rule shard token from the group name. Only relevant when using "by-rule" sharding strategy.

func SendAlerts

func SendAlerts(n sender, externalURL, datasourceUID string) promRules.NotifyFunc

SendAlerts implements a rules.NotifyFunc for a Notifier. It filters any non-firing alerts from the input.

Copied from Prometheus's main.go.

func TranslateToPromqlAPIError

func TranslateToPromqlAPIError(err error) error

TranslateToPromqlAPIError converts error to one of promql.Errors for consumption in PromQL API. PromQL API only recognizes few errors, and converts everything else to HTTP status code 422.

Specifically, it supports:

promql.ErrQueryCanceled, mapped to 503
promql.ErrQueryTimeout, mapped to 503
promql.ErrStorage mapped to 500
anything else is mapped to 422

Querier code produces different kinds of errors, and we want to map them to above-mentioned HTTP status codes correctly.

Details: - vendor/github.com/prometheus/prometheus/web/api/v1/api.go, respondError function only accepts *apiError types. - translation of error to *apiError happens in vendor/github.com/prometheus/prometheus/web/api/v1/api.go, returnAPIError method.

func WrapQueryableErrors

func WrapQueryableErrors(err error) error

Types

type API

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

API is used to handle HTTP requests for the ruler service

func NewAPI

func NewAPI(r *Ruler, s rulestore.RuleStore, logger log.Logger) *API

NewAPI returns a new API struct with the provided ruler and rule store

func (*API) CreateRuleGroup

func (a *API) CreateRuleGroup(w http.ResponseWriter, req *http.Request)

func (*API) DeleteNamespace

func (a *API) DeleteNamespace(w http.ResponseWriter, req *http.Request)

func (*API) DeleteRuleGroup

func (a *API) DeleteRuleGroup(w http.ResponseWriter, req *http.Request)

func (*API) GetRuleGroup

func (a *API) GetRuleGroup(w http.ResponseWriter, req *http.Request)

func (*API) ListRules

func (a *API) ListRules(w http.ResponseWriter, req *http.Request)

func (*API) PrometheusAlerts

func (a *API) PrometheusAlerts(w http.ResponseWriter, req *http.Request)

func (*API) PrometheusRules

func (a *API) PrometheusRules(w http.ResponseWriter, req *http.Request)

type Alert

type Alert struct {
	Labels      labels.Labels `json:"labels"`
	Annotations labels.Labels `json:"annotations"`
	State       string        `json:"state"`
	ActiveAt    *time.Time    `json:"activeAt"`
	Value       string        `json:"value"`
}

Alert has info for an alert.

type AlertDiscovery

type AlertDiscovery struct {
	Alerts []*Alert `json:"alerts"`
}

AlertDiscovery has info for all active alerts.

type AlertStateDesc

type AlertStateDesc struct {
	State       string                                              `protobuf:"bytes,1,opt,name=state,proto3" json:"state,omitempty"`
	Labels      []github_com_grafana_loki_pkg_logproto.LabelAdapter `protobuf:"bytes,2,rep,name=labels,proto3,customtype=github.com/grafana/loki/pkg/logproto.LabelAdapter" json:"labels"`
	Annotations []github_com_grafana_loki_pkg_logproto.LabelAdapter `` /* 126-byte string literal not displayed */
	Value       float64                                             `protobuf:"fixed64,4,opt,name=value,proto3" json:"value,omitempty"`
	ActiveAt    time.Time                                           `protobuf:"bytes,5,opt,name=active_at,json=activeAt,proto3,stdtime" json:"active_at"`
	FiredAt     time.Time                                           `protobuf:"bytes,6,opt,name=fired_at,json=firedAt,proto3,stdtime" json:"fired_at"`
	ResolvedAt  time.Time                                           `protobuf:"bytes,7,opt,name=resolved_at,json=resolvedAt,proto3,stdtime" json:"resolved_at"`
	LastSentAt  time.Time                                           `protobuf:"bytes,8,opt,name=last_sent_at,json=lastSentAt,proto3,stdtime" json:"last_sent_at"`
	ValidUntil  time.Time                                           `protobuf:"bytes,9,opt,name=valid_until,json=validUntil,proto3,stdtime" json:"valid_until"`
}

func (*AlertStateDesc) Descriptor

func (*AlertStateDesc) Descriptor() ([]byte, []int)

func (*AlertStateDesc) Equal

func (this *AlertStateDesc) Equal(that interface{}) bool

func (*AlertStateDesc) GetActiveAt

func (m *AlertStateDesc) GetActiveAt() time.Time

func (*AlertStateDesc) GetFiredAt

func (m *AlertStateDesc) GetFiredAt() time.Time

func (*AlertStateDesc) GetLastSentAt

func (m *AlertStateDesc) GetLastSentAt() time.Time

func (*AlertStateDesc) GetResolvedAt

func (m *AlertStateDesc) GetResolvedAt() time.Time

func (*AlertStateDesc) GetState

func (m *AlertStateDesc) GetState() string

func (*AlertStateDesc) GetValidUntil

func (m *AlertStateDesc) GetValidUntil() time.Time

func (*AlertStateDesc) GetValue

func (m *AlertStateDesc) GetValue() float64

func (*AlertStateDesc) GoString

func (this *AlertStateDesc) GoString() string

func (*AlertStateDesc) Marshal

func (m *AlertStateDesc) Marshal() (dAtA []byte, err error)

func (*AlertStateDesc) MarshalTo

func (m *AlertStateDesc) MarshalTo(dAtA []byte) (int, error)

func (*AlertStateDesc) MarshalToSizedBuffer

func (m *AlertStateDesc) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*AlertStateDesc) ProtoMessage

func (*AlertStateDesc) ProtoMessage()

func (*AlertStateDesc) Reset

func (m *AlertStateDesc) Reset()

func (*AlertStateDesc) Size

func (m *AlertStateDesc) Size() (n int)

func (*AlertStateDesc) String

func (this *AlertStateDesc) String() string

func (*AlertStateDesc) Unmarshal

func (m *AlertStateDesc) Unmarshal(dAtA []byte) error

func (*AlertStateDesc) XXX_DiscardUnknown

func (m *AlertStateDesc) XXX_DiscardUnknown()

func (*AlertStateDesc) XXX_Marshal

func (m *AlertStateDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*AlertStateDesc) XXX_Merge

func (m *AlertStateDesc) XXX_Merge(src proto.Message)

func (*AlertStateDesc) XXX_Size

func (m *AlertStateDesc) XXX_Size() int

func (*AlertStateDesc) XXX_Unmarshal

func (m *AlertStateDesc) XXX_Unmarshal(b []byte) error

type ClientsPool

type ClientsPool interface {
	services.Service
	// GetClientFor returns the ruler client for the given address.
	GetClientFor(addr string) (RulerClient, error)
}

ClientsPool is the interface used to get the client from the pool for a specified address.

type Config

type Config struct {
	// This is used for template expansion in alerts; must be a valid URL.
	ExternalURL flagext.URLValue `yaml:"external_url"`
	// This is used for template expansion in alerts, and represents the corresponding Grafana datasource UID.
	DatasourceUID string `yaml:"datasource_uid"`
	// Labels to add to all alerts
	ExternalLabels labels.Labels `yaml:"external_labels,omitempty" doc:"description=Labels to add to all alerts."`
	// GRPC Client configuration.
	ClientTLSConfig grpcclient.Config `yaml:"ruler_client"`
	// How frequently to evaluate rules by default.
	EvaluationInterval time.Duration `yaml:"evaluation_interval"`
	// How frequently to poll for updated rules.
	PollInterval time.Duration `yaml:"poll_interval"`
	// Rule Storage and Polling configuration.
	StoreConfig RuleStoreConfig `yaml:"storage" doc:"deprecated|description=Use -ruler-storage. CLI flags and their respective YAML config options instead."`
	// Path to store rule files for prom manager.
	RulePath string `yaml:"rule_path"`

	// Global alertmanager config.
	config.AlertManagerConfig `yaml:",inline"`

	// Max time to tolerate outage for restoring "for" state of alert.
	OutageTolerance time.Duration `yaml:"for_outage_tolerance"`
	// Minimum duration between alert and restored "for" state. This is maintained only for alerts with configured "for" time greater than grace period.
	ForGracePeriod time.Duration `yaml:"for_grace_period"`
	// Minimum amount of time to wait before resending an alert to Alertmanager.
	ResendDelay time.Duration `yaml:"resend_delay"`

	// Enable sharding rule groups.
	EnableSharding   bool          `yaml:"enable_sharding"`
	ShardingStrategy string        `yaml:"sharding_strategy"`
	ShardingAlgo     string        `yaml:"sharding_algo"`
	SearchPendingFor time.Duration `yaml:"search_pending_for"`
	Ring             RingConfig    `yaml:"ring" doc:"description=Ring used by Loki ruler. The CLI flags prefix for this block configuration is 'ruler.ring'."`
	FlushCheckPeriod time.Duration `yaml:"flush_period"`

	EnableAPI bool `yaml:"enable_api"`

	EnabledTenants  flagext.StringSliceCSV `yaml:"enabled_tenants"`
	DisabledTenants flagext.StringSliceCSV `yaml:"disabled_tenants"`

	RingCheckPeriod time.Duration `yaml:"-"`

	EnableQueryStats      bool `yaml:"query_stats_enabled"`
	DisableRuleGroupLabel bool `yaml:"disable_rule_group_label"`
}

Config is the configuration for the recording rules server.

func (*Config) RegisterFlags

func (cfg *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

func (*Config) Validate

func (cfg *Config) Validate(_ log.Logger) error

Validate config and returns error on failure

type DefaultMultiTenantManager

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

func NewDefaultMultiTenantManager

func NewDefaultMultiTenantManager(cfg Config, managerFactory ManagerFactory, reg prometheus.Registerer, logger log.Logger, limits RulesLimits, metricsNamespace string) (*DefaultMultiTenantManager, error)

func (*DefaultMultiTenantManager) GetRules

func (r *DefaultMultiTenantManager) GetRules(userID string) []*promRules.Group

func (*DefaultMultiTenantManager) Stop

func (r *DefaultMultiTenantManager) Stop()

func (*DefaultMultiTenantManager) SyncRuleGroups

func (r *DefaultMultiTenantManager) SyncRuleGroups(ctx context.Context, ruleGroups map[string]rulespb.RuleGroupList)

func (*DefaultMultiTenantManager) ValidateRuleGroup

func (*DefaultMultiTenantManager) ValidateRuleGroup(g rulefmt.RuleGroup) []error

type ErrTranslateFn

type ErrTranslateFn func(err error) error

ErrTranslateFn is used to translate or wrap error before returning it by functions in storage.SampleAndChunkQueryable interface. Input error may be nil.

type GroupStateDesc

type GroupStateDesc struct {
	Group               *rulespb.RuleGroupDesc `protobuf:"bytes,1,opt,name=group,proto3" json:"group,omitempty"`
	ActiveRules         []*RuleStateDesc       `protobuf:"bytes,2,rep,name=active_rules,json=activeRules,proto3" json:"active_rules,omitempty"`
	EvaluationTimestamp time.Time              `protobuf:"bytes,3,opt,name=evaluationTimestamp,proto3,stdtime" json:"evaluationTimestamp"`
	EvaluationDuration  time.Duration          `protobuf:"bytes,4,opt,name=evaluationDuration,proto3,stdduration" json:"evaluationDuration"`
}

GroupStateDesc is a proto representation of a rule group

func (*GroupStateDesc) Descriptor

func (*GroupStateDesc) Descriptor() ([]byte, []int)

func (*GroupStateDesc) Equal

func (this *GroupStateDesc) Equal(that interface{}) bool

func (*GroupStateDesc) GetActiveRules

func (m *GroupStateDesc) GetActiveRules() []*RuleStateDesc

func (*GroupStateDesc) GetEvaluationDuration

func (m *GroupStateDesc) GetEvaluationDuration() time.Duration

func (*GroupStateDesc) GetEvaluationTimestamp

func (m *GroupStateDesc) GetEvaluationTimestamp() time.Time

func (*GroupStateDesc) GetGroup

func (m *GroupStateDesc) GetGroup() *rulespb.RuleGroupDesc

func (*GroupStateDesc) GoString

func (this *GroupStateDesc) GoString() string

func (*GroupStateDesc) Marshal

func (m *GroupStateDesc) Marshal() (dAtA []byte, err error)

func (*GroupStateDesc) MarshalTo

func (m *GroupStateDesc) MarshalTo(dAtA []byte) (int, error)

func (*GroupStateDesc) MarshalToSizedBuffer

func (m *GroupStateDesc) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*GroupStateDesc) ProtoMessage

func (*GroupStateDesc) ProtoMessage()

func (*GroupStateDesc) Reset

func (m *GroupStateDesc) Reset()

func (*GroupStateDesc) Size

func (m *GroupStateDesc) Size() (n int)

func (*GroupStateDesc) String

func (this *GroupStateDesc) String() string

func (*GroupStateDesc) Unmarshal

func (m *GroupStateDesc) Unmarshal(dAtA []byte) error

func (*GroupStateDesc) XXX_DiscardUnknown

func (m *GroupStateDesc) XXX_DiscardUnknown()

func (*GroupStateDesc) XXX_Marshal

func (m *GroupStateDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GroupStateDesc) XXX_Merge

func (m *GroupStateDesc) XXX_Merge(src proto.Message)

func (*GroupStateDesc) XXX_Size

func (m *GroupStateDesc) XXX_Size() int

func (*GroupStateDesc) XXX_Unmarshal

func (m *GroupStateDesc) XXX_Unmarshal(b []byte) error

type ManagerFactory

type ManagerFactory func(ctx context.Context, userID string, notifier *notifier.Manager, logger log.Logger, reg prometheus.Registerer) RulesManager

ManagerFactory is a function that creates new RulesManager for given user and notifier.Manager.

func DefaultTenantManagerFactory

func DefaultTenantManagerFactory(cfg Config, p Pusher, q storage.Queryable, engine *promql.Engine, reg prometheus.Registerer, metricsNamespace string) ManagerFactory

type ManagerMetrics

type ManagerMetrics struct {
	EvalDuration         *prometheus.Desc
	IterationDuration    *prometheus.Desc
	IterationsMissed     *prometheus.Desc
	IterationsScheduled  *prometheus.Desc
	EvalTotal            *prometheus.Desc
	EvalFailures         *prometheus.Desc
	GroupInterval        *prometheus.Desc
	GroupLastEvalTime    *prometheus.Desc
	GroupLastDuration    *prometheus.Desc
	GroupRules           *prometheus.Desc
	GroupLastEvalSamples *prometheus.Desc
	// contains filtered or unexported fields
}

ManagerMetrics aggregates metrics exported by the Prometheus rules package and returns them as Cortex metrics

func NewManagerMetrics

func NewManagerMetrics(disableRuleGroupLabel bool, tf util.MetricLabelTransformFunc, metricsNamespace string) *ManagerMetrics

NewManagerMetrics returns a ManagerMetrics struct

func (*ManagerMetrics) AddUserRegistry

func (m *ManagerMetrics) AddUserRegistry(user string, reg *prometheus.Registry)

AddUserRegistry adds a user-specific Prometheus registry.

func (*ManagerMetrics) Collect

func (m *ManagerMetrics) Collect(out chan<- prometheus.Metric)

Collect implements the Collector interface

func (*ManagerMetrics) Describe

func (m *ManagerMetrics) Describe(out chan<- *prometheus.Desc)

Describe implements the Collector interface

func (*ManagerMetrics) RemoveUserRegistry

func (m *ManagerMetrics) RemoveUserRegistry(user string)

RemoveUserRegistry removes user-specific Prometheus registry.

type MultiTenantManager

type MultiTenantManager interface {
	// SyncRuleGroups is used to sync the Manager with rules from the RuleStore.
	// If existing user is missing in the ruleGroups map, its ruler manager will be stopped.
	SyncRuleGroups(ctx context.Context, ruleGroups map[string]rulespb.RuleGroupList)
	// GetRules fetches rules for a particular tenant (userID).
	GetRules(userID string) []*promRules.Group
	// Stop stops all Manager components.
	Stop()
	// ValidateRuleGroup validates a rulegroup
	ValidateRuleGroup(rulefmt.RuleGroup) []error
}

MultiTenantManager is the interface of interaction with a Manager that is tenant aware.

type Pusher

type Pusher interface {
	Push(context.Context, *logproto.WriteRequest) (*logproto.WriteResponse, error)
}

Pusher is an ingester server that accepts pushes.

type PusherAppendable

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

PusherAppendable fulfills the storage.Appendable interface for prometheus manager

func NewPusherAppendable

func NewPusherAppendable(pusher Pusher, userID string, totalWrites, failedWrites prometheus.Counter) *PusherAppendable

func (*PusherAppendable) Appender

func (t *PusherAppendable) Appender(ctx context.Context) storage.Appender

Appender returns a storage.Appender

type PusherAppender

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

func (*PusherAppender) Append

func (*PusherAppender) AppendCTZeroSample

func (a *PusherAppender) AppendCTZeroSample(_ storage.SeriesRef, _ labels.Labels, _ int64, _ int64) (storage.SeriesRef, error)

func (*PusherAppender) AppendExemplar

func (*PusherAppender) AppendHistogram

func (*PusherAppender) Commit

func (a *PusherAppender) Commit() error

func (*PusherAppender) Rollback

func (a *PusherAppender) Rollback() error

func (*PusherAppender) UpdateMetadata

type QueryableError

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

func (QueryableError) Error

func (q QueryableError) Error() string

func (QueryableError) Unwrap

func (q QueryableError) Unwrap() error

type Request

type Request struct {
	UserID    string
	Namespace string
	Group     string
	Labels    []labels.Label
}

type RingConfig

type RingConfig struct {
	KVStore          kv.Config     `yaml:"kvstore"`
	HeartbeatPeriod  time.Duration `yaml:"heartbeat_period"`
	HeartbeatTimeout time.Duration `yaml:"heartbeat_timeout"`

	// Instance details
	InstanceID             string   `yaml:"instance_id" doc:"hidden"`
	InstanceInterfaceNames []string `yaml:"instance_interface_names" doc:"default=[<private network interfaces>]"`
	InstancePort           int      `yaml:"instance_port" doc:"hidden"`
	InstanceAddr           string   `yaml:"instance_addr" doc:"hidden"`
	EnableIPv6             bool     `yaml:"instance_enable_ipv6" doc:"hidden"`
	NumTokens              int      `yaml:"num_tokens"`

	// Injected internally
	ListenPort int `yaml:"-"`

	// Used for testing
	SkipUnregister bool `yaml:"-"`
}

RingConfig masks the ring lifecycler config which contains many options not really required by the rulers ring. This config is used to strip down the config to the minimum, and avoid confusion to the user.

func (*RingConfig) RegisterFlags

func (cfg *RingConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

func (*RingConfig) ToLifecyclerConfig

func (cfg *RingConfig) ToLifecyclerConfig(logger log.Logger) (ring.BasicLifecyclerConfig, error)

ToLifecyclerConfig returns a LifecyclerConfig based on the ruler ring config.

func (*RingConfig) ToRingConfig

func (cfg *RingConfig) ToRingConfig() ring.Config

type RuleDiscovery

type RuleDiscovery struct {
	RuleGroups []*RuleGroup `json:"groups"`
}

RuleDiscovery has info for all rules

type RuleGroup

type RuleGroup struct {
	Name string `json:"name"`
	File string `json:"file"`
	// In order to preserve rule ordering, while exposing type (alerting or recording)
	// specific properties, both alerting and recording rules are exposed in the
	// same array.
	Rules          []rule    `json:"rules"`
	Interval       float64   `json:"interval"`
	Limit          int64     `json:"limit"`
	LastEvaluation time.Time `json:"lastEvaluation"`
	EvaluationTime float64   `json:"evaluationTime"`
}

RuleGroup has info for rules which are part of a group

type RuleStateDesc

type RuleStateDesc struct {
	Rule                *rulespb.RuleDesc `protobuf:"bytes,1,opt,name=rule,proto3" json:"rule,omitempty"`
	State               string            `protobuf:"bytes,2,opt,name=state,proto3" json:"state,omitempty"`
	Health              string            `protobuf:"bytes,3,opt,name=health,proto3" json:"health,omitempty"`
	LastError           string            `protobuf:"bytes,4,opt,name=lastError,proto3" json:"lastError,omitempty"`
	Alerts              []*AlertStateDesc `protobuf:"bytes,5,rep,name=alerts,proto3" json:"alerts,omitempty"`
	EvaluationTimestamp time.Time         `protobuf:"bytes,6,opt,name=evaluationTimestamp,proto3,stdtime" json:"evaluationTimestamp"`
	EvaluationDuration  time.Duration     `protobuf:"bytes,7,opt,name=evaluationDuration,proto3,stdduration" json:"evaluationDuration"`
}

RuleStateDesc is a proto representation of a Prometheus Rule

func (*RuleStateDesc) Descriptor

func (*RuleStateDesc) Descriptor() ([]byte, []int)

func (*RuleStateDesc) Equal

func (this *RuleStateDesc) Equal(that interface{}) bool

func (*RuleStateDesc) GetAlerts

func (m *RuleStateDesc) GetAlerts() []*AlertStateDesc

func (*RuleStateDesc) GetEvaluationDuration

func (m *RuleStateDesc) GetEvaluationDuration() time.Duration

func (*RuleStateDesc) GetEvaluationTimestamp

func (m *RuleStateDesc) GetEvaluationTimestamp() time.Time

func (*RuleStateDesc) GetHealth

func (m *RuleStateDesc) GetHealth() string

func (*RuleStateDesc) GetLastError

func (m *RuleStateDesc) GetLastError() string

func (*RuleStateDesc) GetRule

func (m *RuleStateDesc) GetRule() *rulespb.RuleDesc

func (*RuleStateDesc) GetState

func (m *RuleStateDesc) GetState() string

func (*RuleStateDesc) GoString

func (this *RuleStateDesc) GoString() string

func (*RuleStateDesc) Marshal

func (m *RuleStateDesc) Marshal() (dAtA []byte, err error)

func (*RuleStateDesc) MarshalTo

func (m *RuleStateDesc) MarshalTo(dAtA []byte) (int, error)

func (*RuleStateDesc) MarshalToSizedBuffer

func (m *RuleStateDesc) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*RuleStateDesc) ProtoMessage

func (*RuleStateDesc) ProtoMessage()

func (*RuleStateDesc) Reset

func (m *RuleStateDesc) Reset()

func (*RuleStateDesc) Size

func (m *RuleStateDesc) Size() (n int)

func (*RuleStateDesc) String

func (this *RuleStateDesc) String() string

func (*RuleStateDesc) Unmarshal

func (m *RuleStateDesc) Unmarshal(dAtA []byte) error

func (*RuleStateDesc) XXX_DiscardUnknown

func (m *RuleStateDesc) XXX_DiscardUnknown()

func (*RuleStateDesc) XXX_Marshal

func (m *RuleStateDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RuleStateDesc) XXX_Merge

func (m *RuleStateDesc) XXX_Merge(src proto.Message)

func (*RuleStateDesc) XXX_Size

func (m *RuleStateDesc) XXX_Size() int

func (*RuleStateDesc) XXX_Unmarshal

func (m *RuleStateDesc) XXX_Unmarshal(b []byte) error

type RuleStoreConfig

type RuleStoreConfig struct {
	Type string `yaml:"type"`

	// Object Storage Configs
	Azure        azure.BlobStorageConfig   `yaml:"azure" doc:"description=Configures backend rule storage for Azure."`
	AlibabaCloud alibaba.OssConfig         `yaml:"alibabacloud" doc:"description=Configures backend rule storage for AlibabaCloud Object Storage (OSS)."`
	GCS          gcp.GCSConfig             `yaml:"gcs" doc:"description=Configures backend rule storage for GCS."`
	S3           aws.S3Config              `yaml:"s3" doc:"description=Configures backend rule storage for S3."`
	BOS          baidubce.BOSStorageConfig `yaml:"bos" doc:"description=Configures backend rule storage for Baidu Object Storage (BOS)."`
	Swift        openstack.SwiftConfig     `yaml:"swift" doc:"description=Configures backend rule storage for Swift."`
	COS          ibmcloud.COSConfig        `yaml:"cos" doc:"description=Configures backend rule storage for IBM Cloud Object Storage (COS)."`
	Local        local.Config              `yaml:"local" doc:"description=Configures backend rule storage for a local file system directory."`
	// contains filtered or unexported fields
}

RuleStoreConfig configures a rule store. TODO remove this legacy config in Cortex 1.11.

func (*RuleStoreConfig) IsDefaults

func (cfg *RuleStoreConfig) IsDefaults() bool

IsDefaults returns true if the storage options have not been set

func (*RuleStoreConfig) RegisterFlags

func (cfg *RuleStoreConfig) RegisterFlags(f *flag.FlagSet)

RegisterFlags registers flags.

func (*RuleStoreConfig) Validate

func (cfg *RuleStoreConfig) Validate() error

Validate config and returns error on failure

type Ruler

type Ruler struct {
	services.Service
	// contains filtered or unexported fields
}

Ruler evaluates rules.

+---------------------------------------------------------------+
|                                                               |
|                   Query       +-------------+                 |
|            +------------------>             |                 |
|            |                  |    Store    |                 |
|            | +----------------+             |                 |
|            | |     Rules      +-------------+                 |
|            | |                                                |
|            | |                                                |
|            | |                                                |
|       +----+-v----+   Filter  +------------+                  |
|       |           +----------->            |                  |
|       |   Ruler   |           |    Ring    |                  |
|       |           <-----------+            |                  |
|       +-------+---+   Rules   +------------+                  |
|               |                                               |
|               |                                               |
|               |                                               |
|               |    Load      +-----------------+              |
|               +-------------->                 |              |
|                              |     Manager     |              |
|                              |                 |              |
|                              +-----------------+              |
|                                                               |
+---------------------------------------------------------------+

func NewRuler

func NewRuler(cfg Config, manager MultiTenantManager, reg prometheus.Registerer, logger log.Logger, ruleStore rulestore.RuleStore, limits RulesLimits, metricsNamespace string) (*Ruler, error)

NewRuler creates a new ruler from a distributor and chunk store.

func (*Ruler) AssertMaxRuleGroups

func (r *Ruler) AssertMaxRuleGroups(userID string, rg int) error

AssertMaxRuleGroups limit has not been reached compared to the current number of total rule groups in input and returns an error if so.

func (*Ruler) AssertMaxRulesPerRuleGroup

func (r *Ruler) AssertMaxRulesPerRuleGroup(userID string, rules int) error

AssertMaxRulesPerRuleGroup limit has not been reached compared to the current number of rules in a rule group in input and returns an error if so.

func (*Ruler) DeleteTenantConfiguration

func (r *Ruler) DeleteTenantConfiguration(w http.ResponseWriter, req *http.Request)

func (*Ruler) GetRules

func (r *Ruler) GetRules(ctx context.Context, req *RulesRequest) ([]*GroupStateDesc, error)

GetRules retrieves the running rules from this ruler and all running rulers in the ring if sharding is enabled

func (*Ruler) ListAllRules

func (r *Ruler) ListAllRules(w http.ResponseWriter, req *http.Request)

func (*Ruler) OnRingInstanceHeartbeat

func (r *Ruler) OnRingInstanceHeartbeat(_ *ring.BasicLifecycler, _ *ring.Desc, _ *ring.InstanceDesc)

func (*Ruler) OnRingInstanceRegister

func (r *Ruler) OnRingInstanceRegister(_ *ring.BasicLifecycler, ringDesc ring.Desc, instanceExists bool, _ string, instanceDesc ring.InstanceDesc) (ring.InstanceState, ring.Tokens)

func (*Ruler) OnRingInstanceStopping

func (r *Ruler) OnRingInstanceStopping(_ *ring.BasicLifecycler)

func (*Ruler) OnRingInstanceTokens

func (r *Ruler) OnRingInstanceTokens(_ *ring.BasicLifecycler, _ ring.Tokens)

func (*Ruler) Rules

func (r *Ruler) Rules(ctx context.Context, req *RulesRequest) (*RulesResponse, error)

Rules implements the rules service

func (*Ruler) ServeHTTP

func (r *Ruler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type RulerClient

type RulerClient interface {
	Rules(ctx context.Context, in *RulesRequest, opts ...grpc.CallOption) (*RulesResponse, error)
}

RulerClient is the client API for Ruler service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewRulerClient

func NewRulerClient(cc *grpc.ClientConn) RulerClient

type RulerServer

type RulerServer interface {
	Rules(context.Context, *RulesRequest) (*RulesResponse, error)
}

RulerServer is the server API for Ruler service.

type RulesLimits

type RulesLimits interface {
	RulerTenantShardSize(userID string) int
	RulerMaxRuleGroupsPerTenant(userID string) int
	RulerMaxRulesPerRuleGroup(userID string) int
	RulerAlertManagerConfig(userID string) *config.AlertManagerConfig
}

RulesLimits defines limits used by Ruler.

type RulesManager

type RulesManager interface {
	// Starts rules manager. Blocks until Stop is called.
	Run()

	// Stops rules manager. (Unblocks Run.)
	Stop()

	// Updates rules manager state.
	Update(interval time.Duration, files []string, externalLabels labels.Labels, externalURL string, ruleGroupPostProcessFunc rules.GroupEvalIterationFunc) error

	// Returns current rules groups.
	RuleGroups() []*rules.Group
}

This interface mimicks rules.Manager API. Interface is used to simplify tests.

type RulesRequest

type RulesRequest struct {
	Filter    RulesRequest_RuleType `protobuf:"varint,1,opt,name=filter,proto3,enum=base.RulesRequest_RuleType" json:"filter,omitempty"`
	RuleName  []string              `protobuf:"bytes,2,rep,name=rule_name,json=ruleName,proto3" json:"rule_name,omitempty"`
	RuleGroup []string              `protobuf:"bytes,3,rep,name=rule_group,json=ruleGroup,proto3" json:"rule_group,omitempty"`
	File      []string              `protobuf:"bytes,4,rep,name=file,proto3" json:"file,omitempty"`
}

func (*RulesRequest) Descriptor

func (*RulesRequest) Descriptor() ([]byte, []int)

func (*RulesRequest) Equal

func (this *RulesRequest) Equal(that interface{}) bool

func (*RulesRequest) GetFile

func (m *RulesRequest) GetFile() []string

func (*RulesRequest) GetFilter

func (m *RulesRequest) GetFilter() RulesRequest_RuleType

func (*RulesRequest) GetRuleGroup

func (m *RulesRequest) GetRuleGroup() []string

func (*RulesRequest) GetRuleName

func (m *RulesRequest) GetRuleName() []string

func (*RulesRequest) GoString

func (this *RulesRequest) GoString() string

func (*RulesRequest) Marshal

func (m *RulesRequest) Marshal() (dAtA []byte, err error)

func (*RulesRequest) MarshalTo

func (m *RulesRequest) MarshalTo(dAtA []byte) (int, error)

func (*RulesRequest) MarshalToSizedBuffer

func (m *RulesRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*RulesRequest) ProtoMessage

func (*RulesRequest) ProtoMessage()

func (*RulesRequest) Reset

func (m *RulesRequest) Reset()

func (*RulesRequest) Size

func (m *RulesRequest) Size() (n int)

func (*RulesRequest) String

func (this *RulesRequest) String() string

func (*RulesRequest) Unmarshal

func (m *RulesRequest) Unmarshal(dAtA []byte) error

func (*RulesRequest) XXX_DiscardUnknown

func (m *RulesRequest) XXX_DiscardUnknown()

func (*RulesRequest) XXX_Marshal

func (m *RulesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RulesRequest) XXX_Merge

func (m *RulesRequest) XXX_Merge(src proto.Message)

func (*RulesRequest) XXX_Size

func (m *RulesRequest) XXX_Size() int

func (*RulesRequest) XXX_Unmarshal

func (m *RulesRequest) XXX_Unmarshal(b []byte) error

type RulesRequest_RuleType

type RulesRequest_RuleType int32
const (
	AnyRule       RulesRequest_RuleType = 0
	AlertingRule  RulesRequest_RuleType = 1
	RecordingRule RulesRequest_RuleType = 2
)

func (RulesRequest_RuleType) EnumDescriptor

func (RulesRequest_RuleType) EnumDescriptor() ([]byte, []int)

func (RulesRequest_RuleType) String

func (x RulesRequest_RuleType) String() string

type RulesResponse

type RulesResponse struct {
	Groups []*GroupStateDesc `protobuf:"bytes,1,rep,name=groups,proto3" json:"groups,omitempty"`
}

func (*RulesResponse) Descriptor

func (*RulesResponse) Descriptor() ([]byte, []int)

func (*RulesResponse) Equal

func (this *RulesResponse) Equal(that interface{}) bool

func (*RulesResponse) GetGroups

func (m *RulesResponse) GetGroups() []*GroupStateDesc

func (*RulesResponse) GoString

func (this *RulesResponse) GoString() string

func (*RulesResponse) Marshal

func (m *RulesResponse) Marshal() (dAtA []byte, err error)

func (*RulesResponse) MarshalTo

func (m *RulesResponse) MarshalTo(dAtA []byte) (int, error)

func (*RulesResponse) MarshalToSizedBuffer

func (m *RulesResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*RulesResponse) ProtoMessage

func (*RulesResponse) ProtoMessage()

func (*RulesResponse) Reset

func (m *RulesResponse) Reset()

func (*RulesResponse) Size

func (m *RulesResponse) Size() (n int)

func (*RulesResponse) String

func (this *RulesResponse) String() string

func (*RulesResponse) Unmarshal

func (m *RulesResponse) Unmarshal(dAtA []byte) error

func (*RulesResponse) XXX_DiscardUnknown

func (m *RulesResponse) XXX_DiscardUnknown()

func (*RulesResponse) XXX_Marshal

func (m *RulesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*RulesResponse) XXX_Merge

func (m *RulesResponse) XXX_Merge(src proto.Message)

func (*RulesResponse) XXX_Size

func (m *RulesResponse) XXX_Size() int

func (*RulesResponse) XXX_Unmarshal

func (m *RulesResponse) XXX_Unmarshal(b []byte) error

type StringFilterSet

type StringFilterSet map[string]struct{}

func (StringFilterSet) IsFiltered

func (fs StringFilterSet) IsFiltered(val string) bool

IsFiltered returns whether to filter the value or not. If the set is empty, then nothing is filtered.

type UnimplementedRulerServer

type UnimplementedRulerServer struct {
}

UnimplementedRulerServer can be embedded to have forward compatible implementations.

func (*UnimplementedRulerServer) Rules

Jump to

Keyboard shortcuts

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