prometheus

package
v0.0.0-...-7a5e26d Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package prometheus contains copied code parts of the prometheus project (https://github.com/prometheus/prometheus) See the description of the different structures to get more information on where they have been extracted These definitions should match the structs in the supported prometheus version

Index

Constants

View Source
const ErrorRate = "error_rate"
View Source
const RequestLatencyP50 = "response_time_p50"
View Source
const RequestLatencyP90 = "response_time_p90"
View Source
const RequestLatencyP95 = "response_time_p95"
View Source
const Throughput = "throughput"

Variables

View Source
var ErrInvalidData = errors.New("query did not return valid values")

ErrInvalidData indicates that the retrieved data from the prometheus api is invalid

View Source
var ErrMultipleValues = errors.New("query did return multiple values")

ErrMultipleValues indicates that multiple values where present in the prometheus api result

View Source
var ErrNoValues = errors.New("query did not return any values")

ErrNoValues indicates that no values where present in the prometheus api result

Functions

This section is empty.

Types

type API

type API = apiv1.API

API is a type alias for the prometheus api interface

type Config

type Config struct {
	GlobalConfig   GlobalConfig    `mapstructure:"global" yaml:"global"`
	AlertingConfig UntypedElement  `mapstructure:"alerting,omitempty" yaml:"alerting,omitempty"`
	RuleFiles      []string        `mapstructure:"rule_files,omitempty" yaml:"rule_files,omitempty"`
	ScrapeConfigs  []*ScrapeConfig `mapstructure:"scrape_configs,omitempty" yaml:"scrape_configs,omitempty"`
	StorageConfig  UntypedElement  `mapstructure:"storage,omitempty" yaml:"storage,omitempty"`
	TracingConfig  UntypedElement  `mapstructure:"tracing,omitempty" yaml:"tracing,omitempty"`

	RemoteWriteConfigs []*UntypedElement `mapstructure:"remote_write,omitempty" yaml:"remote_write,omitempty"`
	RemoteReadConfigs  []*UntypedElement `mapstructure:"remote_read,omitempty" yaml:"remote_read,omitempty"`
}

Config is the root configure structure of Prometheus Origin: https://github.com/prometheus/prometheus/blob/fb2da1f26aec023b1e3c864222aaccbe01969f11/config/config.go#L221-L232

func LoadYamlConfiguration

func LoadYamlConfiguration(yamlContent string) (*Config, error)

LoadYamlConfiguration parses the given yaml configuration of the prometheus.yaml file

type Configs

type Configs []StaticConfigLike

Configs is a type alias for an array of StaticConfigLike structs

type GlobalConfig

type GlobalConfig struct {
	ScrapeInterval     model.Duration    `mapstructure:"scrape_interval,omitempty" yaml:"scrape_interval,omitempty"`
	ScrapeTimeout      model.Duration    `mapstructure:"scrape_timeout,omitempty" yaml:"scrape_timeout,omitempty"`
	EvaluationInterval model.Duration    `mapstructure:"evaluation_interval,omitempty" yaml:"evaluation_interval,omitempty"`
	QueryLogFile       string            `mapstructure:"query_log_file,omitempty" yaml:"query_log_file,omitempty"`
	ExternalLabels     map[string]string `mapstructure:"external_labels,omitempty" yaml:"external_labels,omitempty"`
}

GlobalConfig describes the contents of the prometheus.yml file Origin: https://github.com/prometheus/prometheus/blob/fb2da1f26aec023b1e3c864222aaccbe01969f11/config/config.go#L335-L348

type Handler

type Handler struct {
	ApiURL         string
	Username       string
	Password       string
	Project        string
	Stage          string
	Service        string
	DeploymentType string
	Labels         map[string]string
	PrometheusAPI  API
	CustomFilters  []*keptnv2.SLIFilter
	CustomQueries  map[string]string
}

Handler interacts with a prometheus API endpoint

func NewPrometheusHandler

func NewPrometheusHandler(apiURL string, eventData *keptnv2.EventData, deploymentType string, labels map[string]string, customFilters []*keptnv2.SLIFilter) *Handler

NewPrometheusHandler returns a new prometheus handler that interacts with the Prometheus REST API

func (*Handler) GetMetricQuery

func (ph *Handler) GetMetricQuery(metric string, start time.Time, end time.Time) (string, error)

GetMetricQuery returns the prometheus metric expression for the given SLI, start and end time

func (*Handler) GetSLIValue

func (ph *Handler) GetSLIValue(metric string, start string, end string) (float64, error)

GetSLIValue retrieves the specified value via the Prometheus API

type PrometheusHelper

type PrometheusHelper struct {
	KubeAPI   *kubernetes.Clientset
	Namespace string
}

func NewPrometheusHelper

func NewPrometheusHelper(namespace string) (*PrometheusHelper, error)

NewPrometheusHelper creates a new PrometheusHelper

func (*PrometheusHelper) CreateConfigMap

func (p *PrometheusHelper) CreateConfigMap(cm *v1.ConfigMap, namespace string) error

func (*PrometheusHelper) GetConfigMap

func (p *PrometheusHelper) GetConfigMap(name string, namespace string) (*v1.ConfigMap, error)

func (*PrometheusHelper) UpdateAMConfigMap

func (p *PrometheusHelper) UpdateAMConfigMap(name string, filename string, namespace string) error

func (*PrometheusHelper) UpdateConfigMap

func (p *PrometheusHelper) UpdateConfigMap(cm *v1.ConfigMap, namespace string) error

type ScrapeConfig

type ScrapeConfig struct {
	JobName               string           `mapstructure:"job_name" yaml:"job_name"`
	HonorLabels           bool             `mapstructure:"honor_labels,omitempty" yaml:"honor_labels,omitempty"`
	HonorTimestamps       bool             `mapstructure:"honor_timestamps" yaml:"honor_timestamps"`
	Params                url.Values       `mapstructure:"params,omitempty" yaml:"params,omitempty"`
	ScrapeInterval        model.Duration   `mapstructure:"scrape_interval,omitempty" yaml:"scrape_interval,omitempty"`
	ScrapeTimeout         model.Duration   `mapstructure:"scrape_timeout,omitempty" yaml:"scrape_timeout,omitempty"`
	MetricsPath           string           `mapstructure:"metrics_path,omitempty" yaml:"metrics_path,omitempty"`
	Scheme                string           `mapstructure:"scheme,omitempty" yaml:"scheme,omitempty"`
	BodySizeLimit         units.Base2Bytes `mapstructure:"body_size_limit,omitempty" yaml:"body_size_limit,omitempty"`
	SampleLimit           uint             `mapstructure:"sample_limit,omitempty" yaml:"sample_limit,omitempty"`
	TargetLimit           uint             `mapstructure:"target_limit,omitempty" yaml:"target_limit,omitempty"`
	LabelLimit            uint             `mapstructure:"label_limit,omitempty" yaml:"label_limit,omitempty"`
	LabelNameLengthLimit  uint             `mapstructure:"label_name_length_limit,omitempty" yaml:"label_name_length_limit,omitempty"`
	LabelValueLengthLimit uint             `mapstructure:"label_value_length_limit,omitempty" yaml:"label_value_length_limit,omitempty"`

	StaticConfigs        []StaticConfigLike `mapstructure:"static_configs,omitempty" yaml:"static_configs,omitempty"`
	RelabelConfigs       []*UntypedElement  `mapstructure:"relabel_configs,omitempty" yaml:"relabel_configs,omitempty"`
	MetricRelabelConfigs []*UntypedElement  `mapstructure:"metric_relabel_configs,omitempty" yaml:"metric_relabel_configs,omitempty"`

	RemainingElements UntypedElement `mapstructure:",remain" yaml:",inline"`
}

ScrapeConfig configures a scraping unit for Prometheus. Origin: https://github.com/prometheus/prometheus/blob/fb2da1f26aec023b1e3c864222aaccbe01969f11/config/config.go#L405-L452

type StaticConfigLike

type StaticConfigLike struct {
	Targets []string       `mapstructure:"targets,omitempty" yaml:"targets,omitempty"`
	Labels  model.LabelSet `mapstructure:"labels,omitempty" yaml:"labels,omitempty"`
	Source  string         `mapstructure:"source,omitempty" yaml:"source,omitempty"`

	OtherElements UntypedElement `mapstructure:",remain" yaml:",inline"`
}

StaticConfigLike represents a static_config element in the Prometheus configuration This structure has been adapted from https://github.com/prometheus/prometheus/blob/53ac9d6d666acaebbdb8a004b51958f3147b1bd5/discovery/targetgroup/targetgroup.go#L23-L33

type UntypedElement

type UntypedElement map[string]interface{}

UntypedElement identifies arbitrary data

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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