telemetry

package
v0.80.0-devel.0...-0dbee33 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package telemetry defines the interfaces for the telemetry component.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{

	NoDoubleUnderscoreSep: false,
}

DefaultOptions for telemetry metrics which don't need to specify any option.

Functions

func NoFilter

func NoFilter(*MetricFamily) bool

NoFilter returns a MetricFilter that includes all metrics This is not recommended since it will heavily impact costs

func RegisterStatsSender

func RegisterStatsSender(sender StatsTelemetrySender)

RegisterStatsSender regsiters a sender to send the stats metrics

Types

type Bucket

type Bucket struct {
	UpperBound float64
	Count      uint64
}

Bucket is a struct representing the internal bucket state

type Collector

type Collector = prometheus.Collector

Collector is an alias to prometheus.Collector

type Component

type Component interface {
	// Handler returns an http handler to expose the internal metrics
	Handler() http.Handler
	// Reset resets all tracked telemetry
	Reset()
	// RegisterCollector Registers a Collector with the prometheus registry
	RegisterCollector(c Collector)
	// UnregisterCollector unregisters a Collector with the prometheus registry
	UnregisterCollector(c Collector) bool
	// NewCounter creates a Counter with default options for telemetry purpose.
	NewCounter(subsystem, name string, tags []string, help string) Counter
	// NewCounterWithOpts creates a Counter with the given options for telemetry purpose.
	NewCounterWithOpts(subsystem, name string, tags []string, help string, opts Options) Counter

	// NewSimpleCounter creates a new SimpleCounter with default options.
	NewSimpleCounter(subsystem, name, help string) SimpleCounter
	// NewSimpleCounterWithOpts creates a new SimpleCounter.
	NewSimpleCounterWithOpts(subsystem, name, help string, opts Options) SimpleCounter

	// NewGauge creates a Gauge with default options for telemetry purpose.
	NewGauge(subsystem, name string, tags []string, help string) Gauge
	// NewGaugeWithOpts creates a Gauge with the given options for telemetry purpose.
	NewGaugeWithOpts(subsystem, name string, tags []string, help string, opts Options) Gauge

	// NewSimpleGauge creates a new SimpleGauge with default options.
	NewSimpleGauge(subsystem, name, help string) SimpleGauge
	// NewSimpleGaugeWithOpts creates a new SimpleGauge.
	NewSimpleGaugeWithOpts(subsystem, name, help string, opts Options) SimpleGauge

	// NewHistogram creates a Histogram with default options for telemetry purpose.
	NewHistogram(subsystem, name string, tags []string, help string, buckets []float64) Histogram
	// NewHistogramWithOpts creates a Histogram with the given options for telemetry purpose.
	NewHistogramWithOpts(subsystem, name string, tags []string, help string, buckets []float64, opts Options) Histogram

	// NewSimpleHistogram creates a new SimpleHistogram with default options.
	NewSimpleHistogram(subsystem, name, help string, buckets []float64) SimpleHistogram
	// NewSimpleHistogramWithOpts creates a new SimpleHistogram.
	NewSimpleHistogramWithOpts(subsystem, name, help string, buckets []float64, opts Options) SimpleHistogram

	// Gather exposes metrics from the general or default telemetry registry (see options.DefaultMetric)
	Gather(defaultGather bool) ([]*MetricFamily, error)

	// GatherText exposes metrics from the general or default telemetry registry (see options.DefaultMetric) in text format
	GatherText(defaultGather bool, filter MetricFilter) (string, error)
}

Component is the component type.

type Counter

type Counter interface {
	// InitializeToZero creates the counter with the given tags and initializes it to 0.
	// This method is intended to be used when the counter value is important to
	// send even before any incrementing/addition is done on it.
	InitializeToZero(tagsValue ...string)
	// Inc increments the counter with the given tags value.
	Inc(tagsValue ...string)
	// Add adds the given value to the counter with the given tags value.
	Add(value float64, tagsValue ...string)
	// Delete deletes the value for the counter with the given tags value.
	Delete(tagsValue ...string)
	// IncWithTags increments the counter with the given tags.
	// Even if less convenient, this signature could be used in hot path
	// instead of Inc(...string) to avoid escaping the parameters on the heap.
	IncWithTags(tags map[string]string)
	// AddWithTags adds the given value to the counter with the given tags.
	// Even if less convenient, this signature could be used in hot path
	// instead of Add(float64, ...string) to avoid escaping the parameters on the heap.
	AddWithTags(value float64, tags map[string]string)
	// DeleteWithTags deletes the value for the counter with the given tags.
	// Even if less convenient, this signature could be used in hot path
	// instead of Delete(...string) to avoid escaping the parameters on the heap.
	DeleteWithTags(tags map[string]string)
	// WithValues returns SimpleCounter for this metric with the given tag values.
	WithValues(tagsValue ...string) SimpleCounter
	// WithTags returns SimpleCounter for this metric with the given tag values.
	WithTags(tags map[string]string) SimpleCounter
}

Counter tracks how many times something is happening.

type Gauge

type Gauge interface {
	// Set stores the value for the given tags.
	Set(value float64, tagsValue ...string)
	// Inc increments the Gauge value.
	Inc(tagsValue ...string)
	// Dec decrements the Gauge value.
	Dec(tagsValue ...string)
	// Add adds the value to the Gauge value.
	Add(value float64, tagsValue ...string)
	// Sub subtracts the value to the Gauge value.
	Sub(value float64, tagsValue ...string)
	// Delete deletes the value for the Gauge with the given tags.
	Delete(tagsValue ...string)
	// DeletePartialMatch deletes the values for the Gauges that match the subset of given tags
	DeletePartialMatch(tags map[string]string)
	// WithValues returns SimpleGauge for this metric with the given tag values.
	WithValues(tagsValue ...string) SimpleGauge
	// WithTags returns SimpleGauge for this metric with the given tag values.
	WithTags(tags map[string]string) SimpleGauge
}

Gauge tracks the value of one health metric of the Agent.

type Histogram

type Histogram interface {
	// Observe the value to the Histogram value.
	Observe(value float64, tagsValue ...string)
	// Delete deletes the value for the Histogram with the given tags.
	Delete(tagsValue ...string)
	// WithValues returns SimpleHistogram for this metric with the given tag values.
	WithValues(tagsValue ...string) SimpleHistogram
	// WithTags returns SimpleHistogram for this metric with the given tag values.
	WithTags(tags map[string]string) SimpleHistogram
}

Histogram tracks the value of one health metric of the Agent.

type HistogramValue

type HistogramValue struct {
	Count   uint64
	Sum     float64
	Buckets []Bucket
}

HistogramValue is a struct representing the internal histogram state

type MetricFamily

type MetricFamily = dto.MetricFamily

MetricFamily is an alias to dto.MetricFamily

type MetricFilter

type MetricFilter func(*MetricFamily) bool

MetricFilter is a function that filters metrics based on their name It returns true if the metric should be included, false if it should be excluded

func BatchMetricFilter

func BatchMetricFilter(filters ...MetricFilter) MetricFilter

BatchMetricFilter combines multiple MetricFilters into a single MetricFilter It returns true if at least one of the filters return true, false otherwise

func RegexMetricFilter

func RegexMetricFilter(regexes ...regexp.Regexp) MetricFilter

RegexMetricFilter filters metrics based on their name using regular expressions It returns true if the metric name matches at least one of the regular expressions, false otherwise

func StaticMetricFilter

func StaticMetricFilter(metricNames ...string) MetricFilter

StaticMetricFilter filters metrics based on their name It returns true if the metric name is in the list, false otherwise

type Options

type Options struct {
	// NoDoubleUnderscoreSep is set to true when you don't want to
	// separate the subsystem and the name with a double underscore separator.
	//
	// This option is not compatible with the cross-org agent telemetry
	NoDoubleUnderscoreSep bool

	// DefaultMetric exports metric by default via built-in agent_telemetry core check.
	DefaultMetric bool
}

Options for telemetry metrics. Creating an Options struct without specifying any of its fields should be the equivalent of using the DefaultOptions var.

func (*Options) NameWithSeparator

func (opts *Options) NameWithSeparator(subsystem, name string) string

NameWithSeparator returns name prefixed according to NoDoubleUnderscoreOption.

type SimpleCounter

type SimpleCounter interface {
	// Inc increments the counter.
	Inc()
	// Add increments the counter by given amount.
	Add(float64)
	// Get gets the current counter value
	Get() float64
}

SimpleCounter tracks how many times something is happening.

type SimpleGauge

type SimpleGauge interface {
	// Inc increments the gaguge.
	Inc()
	// Dec decrements the gauge.
	Dec()
	// Add increments the gauge by given amount.
	Add(float64)
	// Sub decrements the gauge by given amount.
	Sub(float64)
	// Set sets the value of the gauge.
	Set(float64)
	// Get gets the value of the gauge.
	Get() float64
}

SimpleGauge tracks how many times something is happening.

type SimpleHistogram

type SimpleHistogram interface {
	// Observe the value to the Histogram value.
	Observe(value float64)

	// Get gets the current histogram values
	Get() HistogramValue
}

SimpleHistogram tracks how many times something is happening.

type StatCounterWrapper

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

StatCounterWrapper is a convenience type that allows for migrating telemetry to prometheus Counters while continuing to make the underlying values available for reading

func NewStatCounterWrapper

func NewStatCounterWrapper(comp Component, subsystem string, statName string, tags []string, description string) *StatCounterWrapper

NewStatCounterWrapper returns a new StatCounterWrapper

func (*StatCounterWrapper) Add

func (sgw *StatCounterWrapper) Add(v int64, tags ...string)

Add adds the given value to the counter with the given tags value.

func (*StatCounterWrapper) Delete

func (sgw *StatCounterWrapper) Delete()

Delete deletes the value for the counter with the given tags value.

func (*StatCounterWrapper) Inc

func (sgw *StatCounterWrapper) Inc(tags ...string)

Inc increments the counter with the given tags value.

func (*StatCounterWrapper) IncWithTags

func (sgw *StatCounterWrapper) IncWithTags(tags map[string]string)

IncWithTags increments the counter with the given tags value.

func (*StatCounterWrapper) Load

func (sgw *StatCounterWrapper) Load() int64

Load atomically loads the wrapped value.

type StatGaugeWrapper

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

StatGaugeWrapper is a convenience type that allows for migrating telemetry to prometheus Gauges while continuing to make the underlying values available for reading

func NewStatGaugeWrapper

func NewStatGaugeWrapper(comp Component, subsystem string, statName string, tags []string, description string) *StatGaugeWrapper

NewStatGaugeWrapper returns a new StatGaugeWrapper

func (*StatGaugeWrapper) Add

func (sgw *StatGaugeWrapper) Add(v int64)

Add adds the value to the Gauge value.

func (*StatGaugeWrapper) Dec

func (sgw *StatGaugeWrapper) Dec()

Dec decrements the Gauge value.

func (*StatGaugeWrapper) Inc

func (sgw *StatGaugeWrapper) Inc()

Inc increments the Gauge value.

func (*StatGaugeWrapper) Load

func (sgw *StatGaugeWrapper) Load() int64

Load atomically loads the wrapped value.

func (*StatGaugeWrapper) Set

func (sgw *StatGaugeWrapper) Set(v int64)

Set stores the value for the given tags.

type StatsTelemetryProvider

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

StatsTelemetryProvider handles stats telemetry and passes it on to a sender

func GetStatsTelemetryProvider

func GetStatsTelemetryProvider() *StatsTelemetryProvider

GetStatsTelemetryProvider gets an instance of the current stats telemetry provider

func NewStatsTelemetryProvider

func NewStatsTelemetryProvider(sender StatsTelemetrySender) *StatsTelemetryProvider

NewStatsTelemetryProvider creates a new instance of StatsTelemetryProvider

func (*StatsTelemetryProvider) Count

func (s *StatsTelemetryProvider) Count(metric string, value float64, tags []string)

Count reports a count metric to the sender

func (*StatsTelemetryProvider) Gauge

func (s *StatsTelemetryProvider) Gauge(metric string, value float64, tags []string)

Gauge reports a gauge metric to the sender

func (*StatsTelemetryProvider) GaugeNoIndex

func (s *StatsTelemetryProvider) GaugeNoIndex(metric string, value float64, tags []string)

GaugeNoIndex reports a gauge metric not indexed to the sender

type StatsTelemetrySender

type StatsTelemetrySender interface {
	Count(metric string, value float64, hostname string, tags []string)
	Gauge(metric string, value float64, hostname string, tags []string)
	GaugeNoIndex(metric string, value float64, hostname string, tags []string)
}

StatsTelemetrySender contains methods needed for sending stats metrics

Jump to

Keyboard shortcuts

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