naming

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedOperator creates an error that represents the fact that we were requested to service a query that
	// Prometheus would be unable to support.
	ErrUnsupportedOperator = errors.New("operator not supported by prometheus")

	// ErrMalformedQuery creates an error that represents the fact that we were requested to service a query
	// that was malformed in its operator/value combination.
	ErrMalformedQuery = errors.New("operator requires values")

	// ErrQueryUnsupportedValues creates an error that represents an unsupported return value from the
	// specified query.
	ErrQueryUnsupportedValues = errors.New("operator does not support values")

	// ErrLabelNotSpecified creates an error that represents the fact that we were requested to service a query
	// that was malformed in its label specification.
	ErrLabelNotSpecified = errors.New("label not specified")
)
View Source
var (
	GroupNameSanitizer = strings.NewReplacer(".", "_", "-", "_")
	NsGroupResource    = schema.GroupResource{Resource: "namespaces"}
	NodeGroupResource  = schema.GroupResource{Resource: "nodes"}
	PVGroupResource    = schema.GroupResource{Resource: "persistentvolumes"}
)

Functions

This section is empty.

Types

type MetricNamer added in v0.5.0

type MetricNamer interface {
	// Selector produces the appropriate Prometheus series selector to match all
	// series handable by this namer.
	Selector() prom.Selector
	// FilterSeries checks to see which of the given series match any additional
	// constraints beyond the series query.  It's assumed that the series given
	// already match the series query.
	FilterSeries(series []prom.Series) []prom.Series
	// MetricNameForSeries returns the name (as presented in the API) for a given series.
	MetricNameForSeries(series prom.Series) (string, error)
	// QueryForSeries returns the query for a given series (not API metric name), with
	// the given namespace name (if relevant), resource, and resource names.
	QueryForSeries(series string, resource schema.GroupResource, namespace string, names ...string) (prom.Selector, error)
	// QueryForExternalSeries returns the query for a given series (not API metric name), with
	// the given namespace name (if relevant), resource, and resource names.
	QueryForExternalSeries(series string, namespace string, targetLabels labels.Selector) (prom.Selector, error)

	ResourceConverter
}

MetricNamer knows how to convert Prometheus series names and label names to metrics API resources, and vice-versa. MetricNamers should be safe to access concurrently. Returned group-resources are "normalized" as per the MetricInfo#Normalized method. Group-resources passed as arguments must themselves be normalized.

func NamersFromConfig added in v0.5.0

func NamersFromConfig(cfg []config.DiscoveryRule, mapper apimeta.RESTMapper) ([]MetricNamer, error)

NamersFromConfig produces a MetricNamer for each rule in the given config.

type MetricsQuery

type MetricsQuery interface {
	// Build constructs Prometheus expressions to represent this query
	// over the given group-resource.  If namespace is empty, the resource
	// is considered to be root-scoped.  extraGroupBy may be used for cases
	// where we need to scope down more specifically than just the group-resource
	// (e.g. container metrics).
	Build(series string, groupRes schema.GroupResource, namespace string, extraGroupBy []string, resourceNames ...string) (prom.Selector, error)
	BuildExternal(seriesName string, namespace string, groupBy string, groupBySlice []string, metricSelector labels.Selector) (prom.Selector, error)
}

MetricsQuery represents a compiled metrics query for some set of series that can be converted into an series of Prometheus expressions to be passed to a client.

func NewMetricsQuery

func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter) (MetricsQuery, error)

NewMetricsQuery constructs a new MetricsQuery by compiling the given Go template. The delimiters on the template are `<<` and `>>`, and it may use the following fields: - Series: the series in question - LabelMatchers: a pre-stringified form of the label matchers for the resources in the query - LabelMatchersByName: the raw map-form of the above matchers - GroupBy: the group-by clause to use for the resources in the query (stringified) - GroupBySlice: the raw slice form of the above group-by clause

type ReMatcher added in v0.5.0

type ReMatcher struct {
	// contains filtered or unexported fields
}

ReMatcher either positively or negatively matches a regex

func NewReMatcher added in v0.5.0

func NewReMatcher(cfg config.RegexFilter) (*ReMatcher, error)

func (*ReMatcher) Matches added in v0.5.0

func (m *ReMatcher) Matches(val string) bool

type ResourceConverter

type ResourceConverter interface {
	// ResourcesForSeries returns the group-resources associated with the given series,
	// as well as whether or not the given series has the "namespace" resource).
	ResourcesForSeries(series prom.Series) (res []schema.GroupResource, namespaced bool)
	// LabelForResource returns the appropriate label for the given resource.
	LabelForResource(resource schema.GroupResource) (pmodel.LabelName, error)
}

ResourceConverter knows the relationship between Kubernetes group-resources and Prometheus labels, and can convert between the two for any given label or series.

func NewResourceConverter

func NewResourceConverter(resourceTemplate string, overrides map[string]config.GroupResource, mapper apimeta.RESTMapper) (ResourceConverter, error)

NewResourceConverter creates a ResourceConverter based on a generic template plus any overrides. Either overrides or the template may be empty, but not both.

Jump to

Keyboard shortcuts

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