Documentation
¶
Overview ¶
Copyright 2022 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2022 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func FormatDuration(for_ string) (string, error)
- func FormatExpr(expr string) (string, error)
- func GenEndpointRuleId(group string, epRule *alerting.AlertingRule, ...) (string, error)
- func GenResourceRuleIdIgnoreFormat(group string, rule *promresourcesv1.Rule) string
- func GetAlertingRuleStatus(ruleNamespace string, rule *ResourceRule, epRuleGroups []*alerting.RuleGroup, ...) (*v2alpha1.GettableAlertingRule, error)
- func GetAlertingRulesStatus(ruleNamespace string, ruleChunk *ResourceRuleChunk, ...) ([]*v2alpha1.GettableAlertingRule, error)
- func InjectExprNamespaceLabel(expr, namespace string) (string, error)
- func ParseAlertingRules(epRuleGroups []*alerting.RuleGroup, custom bool, level v2alpha1.RuleLevel, ...) ([]*v2alpha1.GettableAlertingRule, error)
- type PrometheusRuler
- func (r *PrometheusRuler) AddAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
- func (r *PrometheusRuler) DeleteAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
- func (r *PrometheusRuler) ExternalLabels() func() map[string]string
- func (r *PrometheusRuler) ListRuleResources(ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector) ([]*promresourcesv1.PrometheusRule, error)
- func (r *PrometheusRuler) Namespace() string
- func (r *PrometheusRuler) RuleResourceNamespaceSelector() (labels.Selector, error)
- func (r *PrometheusRuler) RuleResourceSelector(extraRuleResourceSelector labels.Selector) (labels.Selector, error)
- func (r *PrometheusRuler) UpdateAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
- type ResourceRule
- type ResourceRuleChunk
- type ResourceRuleCollection
- type ResourceRuleItem
- type RuleCache
- func (c *RuleCache) GetRule(ruler Ruler, ruleNamespace *corev1.Namespace, ...) (*ResourceRuleItem, error)
- func (c *RuleCache) GetRuleByIdOrName(ruler Ruler, ruleNamespace *corev1.Namespace, ...) ([]*ResourceRuleItem, error)
- func (c *RuleCache) ListRules(ruler Ruler, ruleNamespace *corev1.Namespace, ...) (map[string]*ResourceRuleCollection, error)
- type RuleWithGroup
- type Ruler
- type ThanosRuler
- func (r *ThanosRuler) AddAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
- func (r *ThanosRuler) DeleteAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
- func (r *ThanosRuler) ExternalLabels() func() map[string]string
- func (r *ThanosRuler) ListRuleResources(ruleNamespace *corev1.Namespace, extraRuleSelector labels.Selector) ([]*promresourcesv1.PrometheusRule, error)
- func (r *ThanosRuler) Namespace() string
- func (r *ThanosRuler) RuleResourceNamespaceSelector() (labels.Selector, error)
- func (r *ThanosRuler) RuleResourceSelector(extraRuleSelector labels.Selector) (labels.Selector, error)
- func (r *ThanosRuler) UpdateAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ...) ([]*v2alpha1.BulkItemResponse, error)
Constants ¶
const ( ErrGenRuleId = "error generating rule id" LabelKeyInternalRuleGroup = "__rule_group__" LabelKeyInternalRuleName = "__rule_name__" LabelKeyInternalRuleQuery = "__rule_query__" LabelKeyInternalRuleDuration = "__rule_duration__" LabelKeyThanosRulerReplica = "thanos_ruler_replica" LabelKeyPrometheusReplica = "prometheus_replica" LabelKeyRuleId = "rule_id" LabelKeyAlertType = "alerttype" LabelValueAlertType = "metric" )
const (
CustomRuleResourceLabelKeyLevel = "custom-alerting-rule-level"
)
Variables ¶
This section is empty.
Functions ¶
func FormatDuration ¶
func FormatExpr ¶
func GenEndpointRuleId ¶
func GenResourceRuleIdIgnoreFormat ¶
func GenResourceRuleIdIgnoreFormat(group string, rule *promresourcesv1.Rule) string
func GetAlertingRuleStatus ¶
func GetAlertingRuleStatus(ruleNamespace string, rule *ResourceRule, epRuleGroups []*alerting.RuleGroup, extLabels func() map[string]string) (*v2alpha1.GettableAlertingRule, error)
func GetAlertingRulesStatus ¶
func GetAlertingRulesStatus(ruleNamespace string, ruleChunk *ResourceRuleChunk, epRuleGroups []*alerting.RuleGroup, extLabels func() map[string]string) ([]*v2alpha1.GettableAlertingRule, error)
GetAlertingRulesStatus mix rules from prometheusrule custom resources and rules from endpoints. Use rules from prometheusrule custom resources as the main reference.
func InjectExprNamespaceLabel ¶
InjectExprNamespaceLabel injects an label, whose key is "namespace" and whose value is the given namespace, into the prometheus query expression, which will limit the query scope.
func ParseAlertingRules ¶
Types ¶
type PrometheusRuler ¶
type PrometheusRuler struct {
// contains filtered or unexported fields
}
func (*PrometheusRuler) AddAlertingRules ¶
func (r *PrometheusRuler) AddAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, rules ...*RuleWithGroup) ([]*v2alpha1.BulkItemResponse, error)
func (*PrometheusRuler) DeleteAlertingRules ¶
func (r *PrometheusRuler) DeleteAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error)
func (*PrometheusRuler) ExternalLabels ¶
func (r *PrometheusRuler) ExternalLabels() func() map[string]string
func (*PrometheusRuler) ListRuleResources ¶
func (r *PrometheusRuler) ListRuleResources(ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector) ( []*promresourcesv1.PrometheusRule, error)
func (*PrometheusRuler) Namespace ¶
func (r *PrometheusRuler) Namespace() string
func (*PrometheusRuler) RuleResourceNamespaceSelector ¶
func (r *PrometheusRuler) RuleResourceNamespaceSelector() (labels.Selector, error)
func (*PrometheusRuler) RuleResourceSelector ¶
func (*PrometheusRuler) UpdateAlertingRules ¶
func (r *PrometheusRuler) UpdateAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error)
type ResourceRule ¶
type ResourceRule struct { Level v2alpha1.RuleLevel Custom bool ResourceRuleItem }
type ResourceRuleChunk ¶
type ResourceRuleChunk struct { Level v2alpha1.RuleLevel Custom bool ResourceRulesMap map[string]*ResourceRuleCollection }
type ResourceRuleCollection ¶
type ResourceRuleCollection struct { GroupSet map[string]struct{} IdRules map[string]*ResourceRuleItem NameRules map[string][]*ResourceRuleItem }
type ResourceRuleItem ¶
type ResourceRuleItem struct { ResourceName string RuleWithGroup }
type RuleCache ¶
type RuleCache struct {
// contains filtered or unexported fields
}
RuleCache caches all rules from the prometheusrule custom resources
func NewRuleCache ¶
func NewRuleCache(ruleResourceInformer prominformersv1.PrometheusRuleInformer) *RuleCache
func (*RuleCache) GetRuleByIdOrName ¶
type RuleWithGroup ¶
type RuleWithGroup struct { Group string Id string promresourcesv1.Rule }
type Ruler ¶
type Ruler interface { Namespace() string RuleResourceNamespaceSelector() (labels.Selector, error) RuleResourceSelector(extraRuleResourceSelector labels.Selector) (labels.Selector, error) ExternalLabels() func() map[string]string ListRuleResources(ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector) ( []*promresourcesv1.PrometheusRule, error) AddAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, rules ...*RuleWithGroup) ([]*v2alpha1.BulkItemResponse, error) UpdateAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error) DeleteAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error) }
func NewPrometheusRuler ¶
func NewPrometheusRuler(resource *promresourcesv1.Prometheus, informer prominformersv1.PrometheusRuleInformer, client promresourcesclient.Interface) Ruler
func NewThanosRuler ¶
func NewThanosRuler(resource *promresourcesv1.ThanosRuler, informer prominformersv1.PrometheusRuleInformer, client promresourcesclient.Interface) Ruler
type ThanosRuler ¶
type ThanosRuler struct {
// contains filtered or unexported fields
}
func (*ThanosRuler) AddAlertingRules ¶
func (r *ThanosRuler) AddAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, rules ...*RuleWithGroup) ([]*v2alpha1.BulkItemResponse, error)
func (*ThanosRuler) DeleteAlertingRules ¶
func (r *ThanosRuler) DeleteAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error)
func (*ThanosRuler) ExternalLabels ¶
func (r *ThanosRuler) ExternalLabels() func() map[string]string
func (*ThanosRuler) ListRuleResources ¶
func (r *ThanosRuler) ListRuleResources(ruleNamespace *corev1.Namespace, extraRuleSelector labels.Selector) ( []*promresourcesv1.PrometheusRule, error)
func (*ThanosRuler) Namespace ¶
func (r *ThanosRuler) Namespace() string
func (*ThanosRuler) RuleResourceNamespaceSelector ¶
func (r *ThanosRuler) RuleResourceNamespaceSelector() (labels.Selector, error)
func (*ThanosRuler) RuleResourceSelector ¶
func (*ThanosRuler) UpdateAlertingRules ¶
func (r *ThanosRuler) UpdateAlertingRules(ctx context.Context, ruleNamespace *corev1.Namespace, extraRuleResourceSelector labels.Selector, ruleResourceLabels map[string]string, ruleItems ...*ResourceRuleItem) ([]*v2alpha1.BulkItemResponse, error)