Documentation ¶
Index ¶
- Variables
- type Alert
- type Config
- type CortexCaller
- type GroupAlert
- type PluginService
- func (s *PluginService) SetConfig(ctx context.Context, configRaw string) error
- func (s *PluginService) SyncRuntimeConfig(ctx context.Context, namespaceID uint64, namespaceURN string, ...) (map[string]string, error)
- func (s *PluginService) TransformToAlerts(ctx context.Context, providerID uint64, namespaceID uint64, ...) ([]alert.Alert, int, error)
- func (s *PluginService) UpsertRule(ctx context.Context, ns namespace.Namespace, prov provider.Provider, ...) error
- type ServiceOption
- type TemplateConfig
Constants ¶
This section is empty.
Variables ¶
var ( //go:embed config/helper.tmpl HelperTemplateString string //go:embed config/config.goyaml ConfigYamlString string )
var Handshake = plugin.HandshakeConfig{ ProtocolVersion: 1, MagicCookieKey: common.PluginName, MagicCookieValue: fmt.Sprintf("%sv1", common.PluginName), }
Functions ¶
This section is empty.
Types ¶
type Alert ¶
type Alert struct { Status string `mapstructure:"status"` Annotations map[string]string `mapstructure:"annotations"` Labels map[string]string `mapstructure:"labels"` GeneratorURL string `mapstructure:"generatorURL"` Fingerprint string `mapstructure:"fingerprint"` StartsAt string `mapstructure:"startsAt"` EndsAt string `mapstructure:"endsAt"` }
type Config ¶
type Config struct { // https://prometheus.io/docs/alerting/latest/configuration/#route GroupWaitDuration string `mapstructure:"group_wait" yaml:"group_wait" json:"group_wait" default:"30s"` GroupIntervalDuration string `mapstructure:"group_interval" yaml:"group_interval" json:"group_interval" default:"5m"` RepeatIntervalDuration string `mapstructure:"repeat_interval" yaml:"repeat_interval" json:"repeat_interval" default:"4h"` WebhookBaseAPI string `` /* 153-byte string literal not displayed */ HTTPClient httpclient.Config `mapstructure:"http_client" json:"http_client" yaml:"http_client"` }
type CortexCaller ¶
type CortexCaller interface { CreateAlertmanagerConfig(ctx context.Context, cfg string, templates map[string]string) error CreateRuleGroup(ctx context.Context, namespace string, rg rwrulefmt.RuleGroup) error DeleteRuleGroup(ctx context.Context, namespace, groupName string) error GetRuleGroup(ctx context.Context, namespace, groupName string) (*rwrulefmt.RuleGroup, error) ListRules(ctx context.Context, namespace string) (map[string][]rwrulefmt.RuleGroup, error) }
type GroupAlert ¶
type GroupAlert struct { GroupKey string `mapstructure:"groupKey"` ExternalURL string `mapstructure:"externalUrl"` Version string `mapstructure:"version"` Alerts []Alert `mapstructure:"alerts"` }
GroupAlert contract is cortex/prometheus webhook_config contract https://prometheus.io/docs/alerting/latest/configuration/#webhook_config
type PluginService ¶
type PluginService struct { base.UnimplementedService // contains filtered or unexported fields }
Service is a service layer of cortex provider plugin
func NewPluginService ¶
func NewPluginService(logger hclog.Logger, opts ...ServiceOption) *PluginService
NewPluginService returns cortex service provider plugin struct
func (*PluginService) SetConfig ¶
func (s *PluginService) SetConfig(ctx context.Context, configRaw string) error
func (*PluginService) SyncRuntimeConfig ¶
func (s *PluginService) SyncRuntimeConfig(ctx context.Context, namespaceID uint64, namespaceURN string, namespaceLabels map[string]string, prov provider.Provider) (map[string]string, error)
SyncRuntimeConfig synchronizes runtime configuration of provider
func (*PluginService) TransformToAlerts ¶
func (s *PluginService) TransformToAlerts(ctx context.Context, providerID uint64, namespaceID uint64, body map[string]any) ([]alert.Alert, int, error)
TransformToAlerts is a function to transform alert body in hook API to []*alert.Alert
func (*PluginService) UpsertRule ¶
func (s *PluginService) UpsertRule(ctx context.Context, ns namespace.Namespace, prov provider.Provider, rl *rule.Rule, templateToUpdate *template.Template) error
UpsertRule manages upsert logic to cortex ruler. Cortex client API granularity is on the rule-group. This function has a logic to work with rule-level granurality and adapt it to cortex logic.
type ServiceOption ¶
type ServiceOption func(*PluginService)
func WithCortexClient ¶
func WithCortexClient(cc CortexCaller) ServiceOption
WithCortexClient uses cortex-tools client passed in the argument
func WithHTTPClient ¶
func WithHTTPClient(cli *httpclient.Client) ServiceOption
WithHTTPClient assigns custom client when creating a http client
type TemplateConfig ¶
type TemplateConfig struct { GroupWaitDuration string GroupIntervalDuration string `mapstructure:"group_interval" yaml:"group_interval" json:"group_interval" default:"5m"` RepeatIntervalDuration string `mapstructure:"repeat_interval" yaml:"repeat_interval" json:"repeat_interval" default:"4h"` WebhookURL string }