integration

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package integration .. Copyright 2019 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Package integration ... Copyright 2019 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Package integration ... Copyright 2019 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Package integration ... Copyright 2019 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Package integration ... Copyright 2019 New Relic Corporation. All rights reserved. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	// Name of the integration
	Name = "nri-prometheus"
)

Variables

View Source
var (
	// Version of the integration
	Version = "dev"
)

Functions

func AddAttributes

func AddAttributes(targetMetrics *TargetMetrics, rules []AddAttributesRule)

AddAttributes applies the AddAttributeRule. It adds the attributes defined in the rules to the metrics that match.

func AutoDecorateLabels

func AutoDecorateLabels(targetMetrics *TargetMetrics)

AutoDecorateLabels mixes automatically all the "_info" labels within the other metrics, when correspond, according to the following rules: - For each "non-info" metric:

  1. Check the largest label set whose label names coincide with any of the infos.
  2. If the label set coinciding by name, also coincide by value, all the labels from the "info" will be added to the metric.

- The added labels will be suffixed by the name of the info_metric (e.g. version.nginx_info) - If the intersection of label names is an empty set, it is counted as coincidence and all the labels from the "info" will be added to the metric. - If the labels coincide with more than a same info metric, we don't do join because we assume they are not vinculating. For example:

stuff_info{os="linux", version="1.2.3", id="12345"} 1
stuff_info{os="linux", version="3.3.3", id="4432"} 1
stuff_metric{os="linux"} 3

Result: Stuff metric won't have added metrics

- If the labels coincide with diverse info metrics, we can add them because they will be suffixed differently:

stuff_info{os="linux", version="1.2.3", id="12345"} 1
thing_info{os="linux", version="3.3.3", id="4432"} 1
stuff_metric{os="linux"} 3

Result: Stuff metric will be exported as:
stuff_metric{os="linux", version.stuff_info="1.2.3", id.stuff_info="12345", version.thing_info="3.3.3", id.thing_info="4432"}

func CopyAttributes

func CopyAttributes(targetMetrics *TargetMetrics, rules []DecorateRule)

CopyAttributes decorate the labels of an entity

func Decorate

func Decorate(targetMetrics *TargetMetrics, decorateRules []DecorateRule)

Decorate merges the entity and metrics metadata into each metric label

func Execute

func Execute(
	scrapeDuration time.Duration,
	selfRetriever endpoints.TargetRetriever,
	retrievers []endpoints.TargetRetriever,
	fetcher Fetcher,
	processor Processor,
	emitters []Emitter,
)

Execute the integration loop. It sets the retrievers to start watching for new targets and starts the processing pipeline. The pipeline fetches metrics from the registered targets, transforms them according to a set of rules and emits them.

with first-class functions

func Filter

func Filter(targetMetrics *TargetMetrics, rules ignoreRules)

Filter removes the metrics whose name matches the prefixes in the given ignore rules

func NewBearerAuthFileRoundTripper

func NewBearerAuthFileRoundTripper(bearerFile string, rt http.RoundTripper) http.RoundTripper

NewBearerAuthFileRoundTripper adds the bearer token read from the provided file to a request unless the authorization header has already been set. This file is read for every request.

func NewMutualTLSRoundTripper

func NewMutualTLSRoundTripper(cfg endpoints.TLSConfig) (http.RoundTripper, error)

NewMutualTLSRoundTripper creates a new roundtripper with the specified Mutual TLS configuration.

func NewRoundTripper

func NewRoundTripper(BearerTokenFile string, CaFile string, InsecureSkipVerify bool) (http.RoundTripper, error)

NewRoundTripper creates a new roundtripper with the specified TLS configuration.

func NewTLSConfig

func NewTLSConfig(CAFile string, InsecureSkipVerify bool) (*tls.Config, error)

NewTLSConfig creates a TLS configuration. If a CA cert is provided it is read and used to validate the scrape target's certificate properly.

func Rename

func Rename(targetMetrics *TargetMetrics, rules []RenameRule)

Rename apply the given rename rules to the entities metrics

Types

type AddAttributesRule

type AddAttributesRule struct {
	MetricPrefix string                 `mapstructure:"metric_prefix"`
	Attributes   map[string]interface{} `mapstructure:"attributes"`
}

AddAttributesRule adds the Attributes to the metrics that match with MetricPrefix.

type CopyAttributesRule

type CopyAttributesRule struct {
	FromMetric string   `mapstructure:"from_metric"`
	ToMetrics  []string `mapstructure:"to_metrics"`
	MatchBy    []string `mapstructure:"match_by"`
	Attributes []string `mapstructure:"attributes"`
}

CopyAttributesRule is a rule that copies the Attributes from the metric that matches FromMetric to the metrics that matches (as prefix) with ToMetrics only if both have the same values for all the labels defined in MatchBy.

type DecorateRule

type DecorateRule struct {
	Source     string     // source metric name
	Dest       []string   // destination metrics names
	Join       labels.Set // Join labels: values of this set are ignored, it's only to mark the label names
	Attributes labels.Set // Only attributes here will be copied. If empty: all the attributes are copied
}

DecorateRule specifies a label decoration rule: a Source metric may decorate a set of Dest metrics if they have in common the labels that are named in the Join keyset

type DecorationMap

type DecorationMap struct {
	Dests        map[string][]DecorateRule // Set of rules that have as destination the metric named as the key
	SourceLabels map[string][]labels.Set   // For a given source metric names, the label set from all the found entries
}

DecorationMap is an intermediate rules representation that allows accessing in hashtable-complexity from destination metrics to the source metrics that may decorate them

func MatchingDecorate

func MatchingDecorate(targetMetrics *TargetMetrics, rules []DecorateRule) DecorationMap

MatchingDecorate return the rules that may be applied to the entity, because this entity data contains at last one metric whose name coincides with entity and another metric whose name coincide with one of the destinations.

type Emitter

type Emitter interface {
	Name() string
	Emit([]Metric) error
}

Emitter is an interface representing the ability to emit metrics.

type Fetcher

type Fetcher interface {
	// Fetcher fetches data from a set of Prometheus /metrics endpoints. It ignores failed endpoints.
	// It returns each data entry from a channel, assuming this function may run in background.
	Fetch(t []endpoints.Target) <-chan TargetMetrics
}

Fetcher provides fetching functionality to a set of Prometheus endpoints

func NewFetcher

func NewFetcher(fetchDuration time.Duration, fetchTimeout time.Duration, maxConnections int, BearerTokenFile string, CaFile string, InsecureSkipVerify bool, queueLength int) Fetcher

NewFetcher returns the default Fetcher implementation

type IgnoreRule

type IgnoreRule struct {
	Prefixes []string `mapstructure:"prefixes"`
	Except   []string `mapstructure:"except"`
}

IgnoreRule skips for processing metrics that match any of the Prefixes. Metrics that match any of the Except are never skipped. If Prefixes is empty and Except is not, then all metrics that do not match Except will be skipped.

type Metric

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

Metric represents a Prometheus metric. https://prometheus.io/docs/concepts/data_model/

type ProcessingRule

type ProcessingRule struct {
	Description      string
	AddAttributes    []AddAttributesRule  `mapstructure:"add_attributes"`
	RenameAttributes []RenameRule         `mapstructure:"rename_attributes"`
	IgnoreMetrics    []IgnoreRule         `mapstructure:"ignore_metrics"`
	CopyAttributes   []CopyAttributesRule `mapstructure:"copy_attributes"`
}

ProcessingRule is a bundle of multiple rules of different types to be applied to metrics.

type Processor

type Processor func(pairs <-chan TargetMetrics) <-chan TargetMetrics

A Processor is something that transform the metrics of a target that are received by a channel, and submits them by another channel

func RuleProcessor

func RuleProcessor(processingRules []ProcessingRule, queueLength int) Processor

RuleProcessor process apply the Rename, Decorate and Filter metrics processing and returns them through a channel.

type RenameRule

type RenameRule struct {
	MetricPrefix string                 `mapstructure:"metric_prefix"`
	Attributes   map[string]interface{} `mapstructure:"attributes"`
}

RenameRule is a rule for changing the name of attributes of metrics that match the MetricPrefix. When a metric matches, the attributes which match any of the keys of Attributes will be renamed to the value in the map.

type StdoutEmitter

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

StdoutEmitter emits metrics to stdout.

func NewStdoutEmitter

func NewStdoutEmitter() *StdoutEmitter

NewStdoutEmitter returns a NewStdoutEmitter.

func (*StdoutEmitter) Emit

func (se *StdoutEmitter) Emit(metrics []Metric) error

Emit prints the metrics into stdout.

func (*StdoutEmitter) Name

func (se *StdoutEmitter) Name() string

Name is the StdoutEmitter name.

type TargetMetrics

type TargetMetrics struct {
	Metrics []Metric
	Target  endpoints.Target
}

TargetMetrics holds a pair of fetched metrics with the Target where they have been targetted from

type TelemetryEmitter

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

TelemetryEmitter emits metrics using the go-telemetry-sdk.

func NewTelemetryEmitter

func NewTelemetryEmitter(cfg TelemetryEmitterConfig) (*TelemetryEmitter, error)

NewTelemetryEmitter returns a new TelemetryEmitter.

func (*TelemetryEmitter) Emit

func (te *TelemetryEmitter) Emit(metrics []Metric) error

Emit makes the mapping between Prometheus and NR metrics and records them into the NR telemetry harvester.

func (*TelemetryEmitter) Name

func (te *TelemetryEmitter) Name() string

Name returns the emitter name.

type TelemetryEmitterConfig

type TelemetryEmitterConfig struct {
	// Percentile values to calculate for every Prometheus metrics of histogram type.
	Percentiles []float64

	// HarvesterOpts configuration functions for the telemetry Harvester.
	HarvesterOpts []TelemetryHarvesterOpt

	// DeltaExpirationAge sets the cumulative DeltaCalculator expiration age
	// which determines how old an entry must be before it is considered for
	// expiration. Defaults to 30s.
	DeltaExpirationAge time.Duration
	// DeltaExpirationCheckInternval sets the cumulative DeltaCalculator
	// duration between checking for expirations. Defaults to 30s.
	DeltaExpirationCheckInternval time.Duration
}

TelemetryEmitterConfig is the configuration required for the `TelemetryEmitter`

type TelemetryHarvesterOpt

type TelemetryHarvesterOpt = func(*telemetry.Config)

TelemetryHarvesterOpt sets configuration options for the `TelemetryEmitter`'s `telemetry.Harvester`.

func TelemetryHarvesterWithHarvestPeriod added in v1.2.0

func TelemetryHarvesterWithHarvestPeriod(t time.Duration) TelemetryHarvesterOpt

TelemetryHarvesterWithHarvestPeriod sets harvest period.

func TelemetryHarvesterWithLicenseKeyRoundTripper

func TelemetryHarvesterWithLicenseKeyRoundTripper(licenseKey string) TelemetryHarvesterOpt

TelemetryHarvesterWithLicenseKeyRoundTripper wraps the emitter client Transport to use the `licenseKey` instead of the `apiKey`.

Other options that modify the underlying Client.Transport should be set before this one, because this will change the Transport type to licenseKeyRoundTripper.

func TelemetryHarvesterWithMetricsURL

func TelemetryHarvesterWithMetricsURL(url string) TelemetryHarvesterOpt

TelemetryHarvesterWithMetricsURL sets the url to use for the metrics endpoint.

func TelemetryHarvesterWithProxy

func TelemetryHarvesterWithProxy(proxyURL *url.URL) TelemetryHarvesterOpt

TelemetryHarvesterWithProxy sets proxy configuration to the emitter client transport.

func TelemetryHarvesterWithTLSConfig

func TelemetryHarvesterWithTLSConfig(tlsConfig *tls.Config) TelemetryHarvesterOpt

TelemetryHarvesterWithTLSConfig sets the TLS configuration to the emitter client transport.

Jump to

Keyboard shortcuts

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