Documentation ¶
Index ¶
- Constants
- Variables
- func FromLabelValue(key, label string) definition.FetchFunc
- func FromLabelValueEntityIDGenerator(key, label string) definition.EntityIDGeneratorFunc
- func FromLabelValueEntityTypeGenerator(key string) definition.EntityTypeGeneratorFunc
- func FromLabelsValueEntityIDGeneratorForPendingPods() definition.EntityIDGeneratorFunc
- func FromSummary(key string) definition.FetchFunc
- func FromValue(metricName string, labelsFilter ...LabelsFilter) definition.FetchFunc
- func FromValueWithOverriddenName(metricName string, nameOverride string, labelsFilter ...LabelsFilter) definition.FetchFunc
- func GroupEntityMetricsBySpec(specs definition.SpecGroups, families []MetricFamily, rawEntityID string) (g definition.RawGroups, errs []error)
- func GroupMetricsBySpec(specs definition.SpecGroups, families []MetricFamily) (g definition.RawGroups, errs []error)
- func IgnoreLabelsFilter(labelsToIgnore ...string) func(Labels) Labels
- func IncludeOnlyLabelsFilter(labelsToInclude ...string) func(Labels) Labels
- func InheritAllLabelsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc
- func InheritAllSelectorsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc
- func InheritSpecificLabelValuesFrom(parentGroupLabel, relatedMetricKey string, labelsToRetrieve map[string]string) definition.FetchFunc
- func NewRequest(method, url string) (*http.Request, error)
- type CounterValue
- type GaugeValue
- type Labels
- type LabelsFilter
- type Metric
- type MetricFamily
- type Query
- type QueryLabels
- type QueryOperator
- type QueryValue
- type Value
Constants ¶
const AcceptHeader = `text/plain`
AcceptHeader starting with ksm 1.5 only plain text encoding is supported
const EmptyValue noValueType = "no_value"
EmptyValue means we couuld not get the value.
Variables ¶
var ControlPlaneComponentTypeGenerator = func( groupLabel string, _ string, _ definition.RawGroups, clusterName string, ) (string, error) { return fmt.Sprintf("k8s:%s:controlplane:%s", clusterName, groupLabel), nil }
ControlPlaneComponentTypeGenerator generates the entity type of a control plane component.
var FromRawEntityIDGenerator = func(_, rawEntityID string, _ definition.RawGroups) (string, error) { return rawEntityID, nil }
FromRawEntityIDGenerator generates the entity type of a control plane component.
Functions ¶
func FromLabelValue ¶
func FromLabelValue(key, label string) definition.FetchFunc
FromLabelValue creates a FetchFunc that fetches values from prometheus metrics labels.
func FromLabelValueEntityIDGenerator ¶
func FromLabelValueEntityIDGenerator(key, label string) definition.EntityIDGeneratorFunc
FromLabelValueEntityIDGenerator generates an entityID using the value of the specified label for the given metric key.
func FromLabelValueEntityTypeGenerator ¶
func FromLabelValueEntityTypeGenerator(key string) definition.EntityTypeGeneratorFunc
FromLabelValueEntityTypeGenerator generates the entity type using the cluster name and group label. If group label is different than "namespace" or "node", then entity type is also composed of namespace. If group label is "container" then pod name is also included.
func FromLabelsValueEntityIDGeneratorForPendingPods ¶
func FromLabelsValueEntityIDGeneratorForPendingPods() definition.EntityIDGeneratorFunc
FromLabelsValueEntityIDGeneratorForPendingPods generates entity ID for a pod in pending status, which is not scheduled. Otherwise entity ID is not generated. This is due to the fact that Kubelet /pods endpoint does not have information about those pods. The rest of the pods is reported from Kubelet /pods endpoint.
func FromSummary ¶
func FromSummary(key string) definition.FetchFunc
FromSummary creates a FetchFunc that fetches values from prometheus histogram.
It will create one attribute for the count, one for the sum and one per quantile. The attributes names will be genereated by suffixing the time-series labels to the given key, and by suffixing and identifier for type of the time-series in relation to the summary (count, sum or quantile).
- <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_sum - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_count - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_quantile_<quantile_dimention_1> - ... - <metric_name>_<label_1>_<label_1_value>_..._<label_n>_<label_n_value>_quantile_<quantile_dimention_n>
Since it expects the RawValue to be of type []Metric it should be used when grouping with GroupEntityMetricsBySpec.
func FromValue ¶
func FromValue(metricName string, labelsFilter ...LabelsFilter) definition.FetchFunc
FromValue creates a FetchFunc that fetches values from prometheus metrics values.
func FromValueWithOverriddenName ¶
func FromValueWithOverriddenName(metricName string, nameOverride string, labelsFilter ...LabelsFilter) definition.FetchFunc
FromValueWithOverriddenName creates a FetchFunc that fetches values from prometheus metrics values. If there are multiple values returned, and nameOverride is not empty, this name will be used as a prefix instead of the metricName.
func GroupEntityMetricsBySpec ¶
func GroupEntityMetricsBySpec( specs definition.SpecGroups, families []MetricFamily, rawEntityID string, ) (g definition.RawGroups, errs []error)
GroupEntityMetricsBySpec groups metrics coming from Prometheus by the given rawEntityID and metric spec.
It differes from GroupMetricsBySpec in that the key that maps to the RawMetrics is always the given rawEntityID and that the RawValues are of the form []Metric instead of Metric.
Using the given rawEntityID as the entity key for the metrics is useful in cases when all the []MetricFamily belong to the same entity and there is no way to infer that from the metrics. A good example is querying the metrics endpoint of a control plane component.
The resulting RawGroups are of the form:
{ groupLabel: { rawEntityID: { metric_name: [ Metric1, Metric2, ..., Metricn ] } } }
func GroupMetricsBySpec ¶
func GroupMetricsBySpec(specs definition.SpecGroups, families []MetricFamily) (g definition.RawGroups, errs []error)
GroupMetricsBySpec groups metrics coming from Prometheus by a given metric spec. Example: grouping by K8s pod, container, etc.
func IgnoreLabelsFilter ¶
IgnoreLabelsFilter returns a function that filters-out the given labels.
func IncludeOnlyLabelsFilter ¶
IncludeOnlyLabelsFilter returns a function that filters-out all but the given labels.
func InheritAllLabelsFrom ¶
func InheritAllLabelsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc
InheritAllLabelsFrom gets all the label values from from a related metric. Related metric means any metric you can get with the info that you have in your own metric.
func InheritAllSelectorsFrom ¶
func InheritAllSelectorsFrom(parentGroupLabel, relatedMetricKey string) definition.FetchFunc
InheritAllSelectorsFrom gets all the label values from from a related metric and changes the prefix "selector_" for "selector.". It's meant to be used with metrics that contain label selectors. Related metric means any metric you can get with the info that you have in your own metric.
func InheritSpecificLabelValuesFrom ¶
func InheritSpecificLabelValuesFrom(parentGroupLabel, relatedMetricKey string, labelsToRetrieve map[string]string) definition.FetchFunc
InheritSpecificLabelValuesFrom gets the specified label values from a related metric. Related metric means any metric you can get with the info that you have in your own metric.
Types ¶
type CounterValue ¶
type CounterValue float64
CounterValue represents the value of a counter type metric.
func (CounterValue) String ¶
func (v CounterValue) String() string
String implements the Stringer interface method.
type GaugeValue ¶
type GaugeValue float64
GaugeValue represents the value of a gauge type metric.
func (GaugeValue) String ¶
func (v GaugeValue) String() string
String implements the Stringer interface method.
type Labels ¶
Labels is a map containing the label pair of a metric.
type LabelsFilter ¶
LabelsFilter are functions used to filter labels when executing some definition.FetchFunc.
type MetricFamily ¶
MetricFamily is an aggregation of metrics with same name.
func Do ¶
func Do(c client.HTTPClient, endpoint string, queries []Query) ([]MetricFamily, error)
Do is the main entry point. It runs queries against the Prometheus metrics provided by the endpoint.
func (*MetricFamily) Valid ¶
func (f *MetricFamily) Valid() bool
Valid validates that all the attributes were filled.
type Query ¶
type Query struct { CustomName string MetricName string Labels QueryLabels Value QueryValue // TODO Only supported Counter and Gauge }
Query represents the query object. It will run against Prometheus metrics.
func (Query) Execute ¶
func (q Query) Execute(promMetricFamily *model.MetricFamily) (metricFamily MetricFamily)
Execute runs the query.
type QueryLabels ¶
type QueryLabels struct { Operator QueryOperator Labels Labels }
QueryLabels represents the query for labels.
type QueryOperator ¶
type QueryOperator int
QueryOperator indicates the operator used for the query.
const ( // QueryOpAnd Is the default operator. Means all values should match. QueryOpAnd QueryOperator = iota // QueryOpNor means all values should not match. QueryOpNor )
type QueryValue ¶
type QueryValue struct { Operator QueryOperator Value Value }
QueryValue represents the query for a value.