observe

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LoggingAlertRuleCMName = "kubegems-loki-rules"
	LokiRecordingRulesKey  = "kubegems-loki-recording-rules.yaml"
)

Variables

This section is empty.

Functions

func CheckQueryExprNamespace

func CheckQueryExprNamespace(expr, namespace string) error

func GetBaseAlertmanagerConfig

func GetBaseAlertmanagerConfig(namespace, name string) *v1alpha1.AlertmanagerConfig

func GetBasePrometheusRule

func GetBasePrometheusRule(namespace, name string) *monitoringv1.PrometheusRule

func MutateLoggingAlert

func MutateLoggingAlert(req *LoggingAlertRule) error

func MutateMonitorAlert

func MutateMonitorAlert(req *MonitorAlertRule, tplGetter templates.TplGetter) error

Types

type Action

type Action int
const (
	Add Action = iota
	Update
	Delete
)

type AlertLevel

type AlertLevel struct {
	CompareOp    string `json:"compareOp"`
	CompareValue string `json:"compareValue"` // 支持表达式, eg. 24 * 60
	Severity     string `json:"severity"`     // error, critical
}

type AlertReceiver

type AlertReceiver struct {
	AlertChannel *models.AlertChannel `json:"alertChannel"`
	Interval     string               `json:"interval"` // 分组间隔
}

type AlertRule

type AlertRule interface {
	GetNamespace() string
	GetName() string
	GetInhibitLabels() []string
	GetAlertLevels() []AlertLevel
	GetReceivers() []AlertReceiver
}

type AlertRuleList

type AlertRuleList[T AlertRule] []T

func (AlertRuleList[T]) ToAlertRuleList

func (l AlertRuleList[T]) ToAlertRuleList() []AlertRule

type BaseAlertResource

type BaseAlertResource struct {
	AMConfig      *v1alpha1.AlertmanagerConfig
	Silences      []alertmanagertypes.Silence
	ChannelGetter channels.ChannelGetter
}

func (*BaseAlertResource) GetAlertReceiverMap

func (base *BaseAlertResource) GetAlertReceiverMap() (map[string][]AlertReceiver, error)

func (*BaseAlertResource) GetInhibitRuleMap

func (base *BaseAlertResource) GetInhibitRuleMap() map[string]v1alpha1.InhibitRule

func (*BaseAlertResource) GetSilenceMap

func (base *BaseAlertResource) GetSilenceMap() map[string]alertmanagertypes.Silence

func (*BaseAlertResource) Update

func (base *BaseAlertResource) Update(alertrules AlertRuleList[AlertRule]) error

func (*BaseAlertResource) UpdateInhibitRules

func (base *BaseAlertResource) UpdateInhibitRules(alertrules AlertRuleList[AlertRule])

func (*BaseAlertResource) UpdateReceivers

func (base *BaseAlertResource) UpdateReceivers(alertrules AlertRuleList[AlertRule]) error

func (*BaseAlertResource) UpdateRoutes

func (base *BaseAlertResource) UpdateRoutes(alertrules AlertRuleList[AlertRule])

type BaseAlertRule

type BaseAlertRule struct {
	Namespace string `json:"namespace"`
	Name      string `json:"name"`

	Expr    string `json:"expr"`    // promql/logql表达式,不能包含比较运算符(<, <=, >, >=, ==)
	For     string `json:"for"`     // 持续时间, eg. 10s, 1m, 1h
	Message string `json:"message"` // 告警消息,若为空后端自动填充

	InhibitLabels []string        `json:"inhibitLabels"` // 如果有多个告警级别,需要配置告警抑制的labels
	AlertLevels   []AlertLevel    `json:"alertLevels"`   // 告警级别
	Receivers     []AlertReceiver `json:"receivers"`     // 接收器

	IsOpen bool   `json:"isOpen"` // 是否启用
	State  string `json:"state"`  // 状态
}

func (*BaseAlertRule) CheckAndModify

func (r *BaseAlertRule) CheckAndModify() error

func (BaseAlertRule) GetAlertLevels

func (r BaseAlertRule) GetAlertLevels() []AlertLevel

func (BaseAlertRule) GetInhibitLabels

func (r BaseAlertRule) GetInhibitLabels() []string

func (BaseAlertRule) GetName

func (r BaseAlertRule) GetName() string

func (BaseAlertRule) GetNamespace

func (r BaseAlertRule) GetNamespace() string

func (BaseAlertRule) GetReceivers

func (r BaseAlertRule) GetReceivers() []AlertReceiver

func (*BaseAlertRule) IsExtraAlert

func (r *BaseAlertRule) IsExtraAlert() bool

IsExtraAlert 用于记录额外信息 如在生成监控的amcfg时,避免忽视日志的route

type LoggingAlertRule

type LoggingAlertRule struct {
	LogqlGenerator *LogqlGenerator `json:"logqlGenerator"`
	BaseAlertRule  `json:",inline"`
	RealTimeAlerts []*promv1.Alert `json:"realTimeAlerts,omitempty"` // 实时告警
	Origin         string          `json:"origin,omitempty"`         // 原始的prometheusrule
}

type LogqlGenerator

type LogqlGenerator struct {
	Duration   string            `json:"duration"`             // 时间范围
	Match      string            `json:"match"`                // 正则匹配的字符串
	LabelPairs map[string]string `json:"labelpairs,omitempty"` // 标签键值对
}

func (*LogqlGenerator) IsEmpty

func (g *LogqlGenerator) IsEmpty() bool

func (*LogqlGenerator) ToLogql

func (g *LogqlGenerator) ToLogql(namespace string) string

type MonitorAlertRule

type MonitorAlertRule struct {
	PromqlGenerator *prometheus.PromqlGenerator `json:"promqlGenerator"`

	BaseAlertRule  `json:",inline"`
	RealTimeAlerts []*promv1.Alert `json:"realTimeAlerts,omitempty"` // 实时告警
	Origin         string          `json:"origin,omitempty"`         // 原始的prometheusrule
	Source         string          `json:"source"`                   // 来自哪个prometheusrule
	TplLost        bool            `json:"tplLost"`                  // 监控模板是否丢失
}

type ObserveClient

type ObserveClient struct {
	agents.Client
	*gorm.DB
}

func NewClient

func NewClient(cli agents.Client, db *gorm.DB) *ObserveClient

func (*ObserveClient) CommitRawLoggingAlertResource

func (c *ObserveClient) CommitRawLoggingAlertResource(ctx context.Context, raw *RawLoggingAlertRule) error

func (*ObserveClient) CommitRawMonitorAlertResource

func (c *ObserveClient) CommitRawMonitorAlertResource(ctx context.Context, raw *RawMonitorAlertResource) error

func (*ObserveClient) CreateOrUpdateAlertEmailSecret

func (c *ObserveClient) CreateOrUpdateAlertEmailSecret(ctx context.Context, namespace string, receivers []AlertReceiver) error

func (*ObserveClient) CreateOrUpdateSilenceIfNotExist

func (c *ObserveClient) CreateOrUpdateSilenceIfNotExist(ctx context.Context, info models.AlertInfo) error

use for blacklist

func (*ObserveClient) DeleteSilenceIfExist

func (c *ObserveClient) DeleteSilenceIfExist(ctx context.Context, info models.AlertInfo) error

use for blacklist

func (*ObserveClient) GetOrCreateAlertmanagerConfig

func (c *ObserveClient) GetOrCreateAlertmanagerConfig(ctx context.Context, namespace, name string) (*monitoringv1alpha1.AlertmanagerConfig, error)

func (*ObserveClient) GetOrCreatePrometheusRule

func (c *ObserveClient) GetOrCreatePrometheusRule(ctx context.Context, namespace, name string) (*monitoringv1.PrometheusRule, error)

func (*ObserveClient) GetRawLoggingAlertResource

func (c *ObserveClient) GetRawLoggingAlertResource(ctx context.Context, namespace string) (*RawLoggingAlertRule, error)

func (*ObserveClient) GetRawMonitorAlertResource

func (c *ObserveClient) GetRawMonitorAlertResource(ctx context.Context, namespace, name string, tplGetter templates.TplGetter) (*RawMonitorAlertResource, error)

GetRawMonitorAlertResource get specified namespace's alert

func (*ObserveClient) ListLoggingAlertRules

func (c *ObserveClient) ListLoggingAlertRules(ctx context.Context, namespace string, hasDetail bool) ([]LoggingAlertRule, error)

func (*ObserveClient) ListMonitorAlertRules

func (c *ObserveClient) ListMonitorAlertRules(ctx context.Context, namespace string, hasDetail bool, tplGetter templates.TplGetter) ([]MonitorAlertRule, error)

func (*ObserveClient) ListSilences

func (c *ObserveClient) ListSilences(ctx context.Context, labels map[string]string, commentPrefix string) ([]alertmanagertypes.Silence, error)

type RawLoggingAlertRule

type RawLoggingAlertRule struct {
	Base *BaseAlertResource
	*corev1.ConfigMap
	*rulefmt.RuleGroups
}

func (*RawLoggingAlertRule) ModifyLoggingAlertRule

func (raw *RawLoggingAlertRule) ModifyLoggingAlertRule(r LoggingAlertRule, act Action) error

func (*RawLoggingAlertRule) ToAlerts

func (raw *RawLoggingAlertRule) ToAlerts(hasDetail bool) (AlertRuleList[LoggingAlertRule], error)

type RawMonitorAlertResource

type RawMonitorAlertResource struct {
	Base *BaseAlertResource
	*monitoringv1.PrometheusRule
	TplGetter templates.TplGetter
}

里面资源的namespace必须相同

func (*RawMonitorAlertResource) ModifyAlertRule

func (raw *RawMonitorAlertResource) ModifyAlertRule(newAlertRule MonitorAlertRule, act Action) error

所有alertrule都是一个namespace

func (*RawMonitorAlertResource) ToAlerts

func (raw *RawMonitorAlertResource) ToAlerts(hasDetail bool) (AlertRuleList[MonitorAlertRule], error)

默认认为namespace全部一致

Jump to

Keyboard shortcuts

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