otel

package
v0.0.0-...-446d60b Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package otel provides data structures to represent and generate otel configuration.

Index

Constants

View Source
const MetricsPort = 20201

Variables

View Source
var ToggleScalarDataType = map[string]interface{}{"action": "toggle_scalar_data_type"}

ToggleScalarDataType transforms int -> double and double -> int.

Functions

func AddLabel

func AddLabel(key, value string) map[string]interface{}

AddLabel adds a label with a fixed value.

func AddPrefix

func AddPrefix(prefix string, operations ...map[string]interface{}) map[string]interface{}

AddPrefix returns a config snippet that adds a domain prefix to all metrics.

func AggregateLabelValues

func AggregateLabelValues(aggregationType string, label string, new string, old ...string) map[string]interface{}

AggregateLabelValues combines the given values into a single value

func AggregateLabels

func AggregateLabels(aggregationType string, labels ...string) map[string]interface{}

AggregateLabels removes all labels except those in the passed list, aggregating values using aggregationType.

func ChangePrefix

func ChangePrefix(oldPrefix, newPrefix string) map[string]interface{}

ChangePrefix returns a config snippet that updates a prefix on all metrics.

func CombineMetrics

func CombineMetrics(old, new string, operations ...map[string]interface{}) map[string]interface{}

CombineMetrics returns a config snippet that renames metrics matching the regex old to new, applying zero or more transformations.

func DeleteLabelValue

func DeleteLabelValue(label, value string) map[string]interface{}

DeleteLabelValue removes streams with the given label value

func DuplicateMetric

func DuplicateMetric(old, new string, operations ...map[string]interface{}) map[string]interface{}

DuplicateMetric returns a config snippet that copies old to new, applying zero or more transformations.

func RegexpRename

func RegexpRename(regexp string, rename string, operations ...map[string]interface{}) map[string]interface{}

RegexpRename returns a config snippet that renames metrics matching the given regexp. The `rename` argument supports capture groups as `${1}`, `${2}`, and so on.

func RenameLabel

func RenameLabel(old, new string) map[string]interface{}

RenameLabel renames old to new

func RenameLabelValues

func RenameLabelValues(label string, transforms map[string]string) map[string]interface{}

RenameLabelValues renames label values

func RenameMetric

func RenameMetric(old, new string, operations ...map[string]interface{}) map[string]interface{}

RenameMetric returns a config snippet that renames old to new, applying zero or more transformations.

func ScaleValue

func ScaleValue(factor float64) map[string]interface{}

ScaleValue multiplies the value by factor

func UpdateMetric

func UpdateMetric(metric string, operations ...map[string]interface{}) map[string]interface{}

UpdateMetric returns a config snippet applies transformations to the given metric name

func UpdateMetricRegexp

func UpdateMetricRegexp(metricRegex string, operations ...map[string]interface{}) map[string]interface{}

UpdateMetricRegexp returns a config snippet that applies transformations to metrics matching the input regex

Types

type Component

type Component struct {
	// Type is the string type needed to instantiate the OT component (e.g. "windowsperfcounters")
	Type string
	// Config is an object which can be serialized by mapstructure into the configuration for the component.
	// This can either be a map[string]interface{} or a Config struct from OT.
	Config interface{}
}

Component represents a single OT component (receiver, processor, exporter, etc.)

func CastToSum

func CastToSum(metrics ...string) Component

CastToSum returns a Component that performs a cast of each metric to a sum.

func CondenseResourceMetrics

func CondenseResourceMetrics() Component

CondenseResourceMetrics merges multiple resource metrics on a slice of metrics to a single resource metrics payload, if they have the same resource.

func Filter

func Filter(dataType, context string, expressions []ottl.Value) Component

Filter returns a filter processor object that drops dataType.context data matching any of the expressions.

func GCPResourceDetector

func GCPResourceDetector(override bool) Component

GCPResourceDetector returns a resourcedetection processor configured for only GCP.

func GroupByGMPAttrs

func GroupByGMPAttrs() Component

GroupByGMPAttrs moves the "namespace", "cluster", and "location" metric attributes to resource attributes. The googlemanagedprometheus exporter will use these resource attributes to populate metric labels.

func MetricsFilter

func MetricsFilter(polarity, matchType string, metricNames ...string) Component

MetricsFilter returns a Component that filters metrics. polarity should be "include" or "exclude". matchType should be "strict" or "regexp".

func MetricsOTTLFilter

func MetricsOTTLFilter(metricQueries []string, datapointQueries []string) Component

MetricsOTTLFilter returns a Component that filters metrics using OTTL. OTTL can only be used as an exclude filter, any metrics or datapoints that match one of the provided queries are dropped. Example query: 'name == "jvm.memory.heap.used" and resource.attributes["elasticsearch.node.name"] == nil'

func MetricsTransform

func MetricsTransform(metrics ...map[string]interface{}) Component

MetricsTransform returns a Component that performs the transformations specified as arguments.

func ModifyInstrumentationScope

func ModifyInstrumentationScope(name string, version string) Component

ModifyInstrumentationScope sets the instrumentation scope name and version fields which will later be exported to Cloud Monitoring metric labels. The name will always be prefixed with "agent.googleapis.com/".

func NormalizeSums

func NormalizeSums() Component

NormalizeSums returns a Component that performs counter normalization.

func ResourceTransform

func ResourceTransform(attributes map[string]string, override bool) Component

ResourceTransform returns a Component that applies changes on resource attributes.

func Transform

func Transform(statementType, context string, statements ottl.Statements) Component

Transform returns a transform processor object that executes statements on statementType data.

func TransformationMetrics

func TransformationMetrics(queries ...TransformQuery) Component

TransformationMetrics returns a transform processor object that contains all the queries passed into it.

type ExporterType

type ExporterType int
const (
	// N.B. Every ExporterType increases the QPS and thus quota
	// consumption in consumer projects; think hard before adding
	// another exporter type.
	OTel ExporterType = iota
	System
	GMP
)

func (ExporterType) Name

func (t ExporterType) Name() string

type ModularConfig

type ModularConfig struct {
	LogLevel          string
	ReceiverPipelines map[string]ReceiverPipeline
	Pipelines         map[string]Pipeline

	Exporters map[ExporterType]Component

	// Test-only options:
	// Don't generate any self-metrics
	DisableMetrics bool
	// Emit collector logs as JSON
	JSONLogs bool
}

func (ModularConfig) Generate

func (c ModularConfig) Generate(ctx context.Context) (string, error)

Generate an OT YAML config file for c. Each pipeline gets generated as a receiver, per-pipeline processors, global processors, and then global exporter. For example: metrics/mypipe:

receivers: [hostmetrics/mypipe]
processors: [filter/mypipe_1, metrics_filter/mypipe_2, resourcedetection/_global_0]
exporters: [googlecloud]

type Pipeline

type Pipeline struct {
	// Type is "metrics" or "traces".
	Type                 string
	ReceiverPipelineName string
	Processors           []Component
}

Pipeline represents one (of potentially many) pipelines consuming data from a ReceiverPipeline.

type ReceiverPipeline

type ReceiverPipeline struct {
	Receiver Component
	// Processors is a map with processors for each pipeline type ("metrics" or "traces").
	// If a key is not in the map, the receiver pipeline will not be used for that pipeline type.
	Processors map[string][]Component
	// ExporterTypes indicates if the pipeline outputs special data (either Prometheus or system metrics) that need to be handled with a special exporter.
	ExporterTypes map[string]ExporterType
	// ResourceDetectionModes indicates whether the resource should be forcibly set, set only if not already present, or never set.
	// If a data type is not present, it will assume the zero value (Override).
	ResourceDetectionModes map[string]ResourceDetectionMode
}

ReceiverPipeline represents a single OT receiver and zero or more processors that must be chained after that receiver.

type ResourceDetectionMode

type ResourceDetectionMode int
const (
	Override ResourceDetectionMode = iota
	SetIfMissing
	None
)

type TransformQuery

type TransformQuery string

TransformQuery is a type wrapper for query expressions supported by the transform processor found here: https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/transformprocessor

func ConvertFloatToInt

func ConvertFloatToInt(metricName string) TransformQuery

ConvertFloatToInt returns an expression where a float-valued metric can be converted to an int

func ConvertGaugeToSum

func ConvertGaugeToSum(metricName string) TransformQuery

ConvertGaugeToSum returns an expression where a gauge metric can be converted into a sum

func FlattenResourceAttribute

func FlattenResourceAttribute(resourceAttribute, metricAttribute string) TransformQuery

FlattenResourceAttribute returns an expression that brings down a resource attribute to a metric attribute.

func RetainResource

func RetainResource(resourceAttributeKeys ...string) TransformQuery

RetainResource retains the resource attributes provided, and drops all other attributes.

func SetAttribute

func SetAttribute(metricName, attributeKey, attributeValue string) TransformQuery

func SetDescription

func SetDescription(metricName, metricDescription string) TransformQuery

SetDescription returns a metrics transform expression where the metrics description will be set to what is provided

func SetName

func SetName(oldName, newName string) TransformQuery

SetName returns a metrics transform expression where the metric name is set to provided value

func SetUnit

func SetUnit(metricName, unit string) TransformQuery

SetUnit returns a metrics transform expression where the metric unit is set to provided value

func SummaryCountValToSum

func SummaryCountValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery

SummaryCountValToSum creates a new Sum metric out of a summary metric's count value. The new metric has a name of "<Old Name>_count".

func SummarySumValToSum

func SummarySumValToSum(metricName, aggregation string, isMonotonic bool) TransformQuery

SummarySumValToSum creates a new Sum metric out of a summary metric's sum value. The new metric has a name of "<Old Name>_sum".

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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