cortex

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed config/helper.tmpl
	HelperTemplateString string
	//go:embed config/config.goyaml
	ConfigYamlString string
)

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"`
}

func (Alert) Validate added in v0.5.8

func (a Alert) Validate() error

type AppConfig

type AppConfig struct {
	// https://prometheus.io/docs/alerting/latest/configuration/#route
	GroupWaitDuration      string            `mapstructure:"group_wait" yaml:"group_wait" default:"30s"`
	GroupIntervalDuration  string            `mapstructure:"group_interval" yaml:"group_interval" default:"5m"`
	RepeatIntervalDuration string            `mapstructure:"repeat_interval" yaml:"repeat_interval" default:"4h"`
	WebhookBaseAPI         string            `mapstructure:"webhook_base_api" yaml:"webhook_base_api" default:"http://localhost:8080/v1beta1/alerts/cortex"`
	HTTPClient             httpclient.Config `mapstructure:"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 log.Logger, appConfig AppConfig, opts ...ServiceOption) *PluginService

NewPluginService returns cortex service provider plugin struct

func (*PluginService) SyncRuntimeConfig

func (s *PluginService) SyncRuntimeConfig(ctx context.Context, namespaceID uint64, namespaceURN string, prov provider.Provider) error

SyncRuntimeConfig synchronizes runtime configuration of provider

func (*PluginService) TransformToAlerts

func (s *PluginService) TransformToAlerts(ctx context.Context, providerID uint64, namespaceID uint64, body map[string]interface{}) ([]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, namespaceURN string, 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 added in v0.5.2

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" default:"5m"`
	RepeatIntervalDuration string `mapstructure:"repeat_interval" yaml:"repeat_interval" default:"4h"`
	WebhookURL             string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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