sink

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sink is the write side every collector module uses. The agent's OTLP exporter satisfies it; tests use a recorder.

Index

Constants

View Source
const (
	QueueDepth = "messaging.queue.depth"
	QueueAge   = "messaging.queue.oldest_age_seconds"
	QueueLag   = "messaging.consumer.lag_seconds"
)

The Queues area (APM-009) reads one metric contract whatever the broker: messaging.queue.depth {queue, framework, state}, messaging.queue.oldest_age_seconds and messaging.consumer.lag_seconds. QueueContract wraps a Sink and, for each broker metric in queueMaps, also writes that contract series, so every collector (RabbitMQ, ActiveMQ and Artemis, NATS JetStream, Pulsar, Kafka, Redis streams, SQS, Kinesis, Service Bus, Pub/Sub) feeds the data-streams view without changing its own native series. A point without a queue name is skipped.

View Source
const ResourcePrefix = "resource."

ResourcePrefix marks, inside the modules that Hoist, an attribute that belongs on the OTLP resource. The exporter itself never reads it: Hoist (applied only by trusted modules: Kubernetes, virtualization, cloud and docker, whose values come from an API and not from scraped input) turns the prefixed keys into explicit resource arguments, so a scraped label or any other module's attribute can never name the resource. Keys must not be `wt.*` (ingest deletes them).

Variables

This section is empty.

Functions

func Backoff

func Backoff(attempt int, r float64) time.Duration

Backoff is the wait before retry number attempt (0 is the first): 1 s doubling to 5 min, with a random 20% either way. r is a uniform value in [0,1) (pass rand.Float64()).

func Res

func Res(attrs map[string]string) map[string]string

Res returns attrs with every key addressed to the resource.

func SplitRes

func SplitRes(attrs map[string]string) (res, rest map[string]string)

SplitRes separates ResourcePrefix keys (prefix removed) from the rest. With none it returns (nil, attrs) unchanged.

func Strip

func Strip(attrs map[string]string) map[string]string

Strip returns attrs without ResourcePrefix keys (a copy only when one is present). Modules that copy outside input into attributes use it.

func Truncate

func Truncate(s string, n int) string

Truncate cuts s to at most n bytes without splitting a UTF-8 sequence.

func With

func With(attrs map[string]string, kv ...string) map[string]string

With copies attrs and adds the key/value pairs in kv on top; it never mutates attrs.

Types

type Delivering

type Delivering interface {
	// Flush exports everything buffered now (and waits for an export already in flight).
	Flush(ctx context.Context) error
	// Buffered is the estimated number of bytes waiting to be exported.
	Buffered() int
}

Delivering is implemented by a sink that can confirm delivery. A collector that reads from a source with offsets (Kafka, Event Hubs) commits them only after Flush returns nil, and pauses its reads while Buffered is above its high-water mark, so a slow or failing export never makes the sink drop what the source already considers delivered.

type Recorder

type Recorder struct {
	Samples []Sample
	// contains filtered or unexported fields
}

Recorder is a Sink that keeps everything it is given (for tests).

func (*Recorder) Gauge

func (r *Recorder) Gauge(name, _ string, v float64, a map[string]string, _ time.Time)

Gauge records a gauge point.

func (*Recorder) Log

func (r *Recorder) Log(sev, body string, a map[string]string, _ time.Time)

Log records a log record.

func (*Recorder) Names

func (r *Recorder) Names() map[string]bool

Names returns the distinct metric names recorded.

func (*Recorder) Snapshot

func (r *Recorder) Snapshot() []Sample

Snapshot returns a copy of what was recorded so far (safe while collectors still write).

func (*Recorder) Sum

func (r *Recorder) Sum(name, unit string, v float64, a map[string]string, at time.Time)

Sum records a counter point.

type ResourceSink

type ResourceSink interface {
	GaugeRes(name, unit string, value float64, res, attrs map[string]string, at time.Time)
	SumRes(name, unit string, value float64, res, attrs map[string]string, at time.Time)
	LogRes(severity, body string, res, attrs map[string]string, at time.Time)
}

ResourceSink is a Sink that also accepts resource attributes as a separate argument.

type Sample

type Sample struct {
	Name  string
	Value float64
	Attrs map[string]string
	Body  string
	Sev   string
}

Sample is one recorded point or log record.

type Sink

type Sink interface {
	Gauge(name, unit string, value float64, attrs map[string]string, at time.Time)
	// Sum is a cumulative monotonic counter.
	Sum(name, unit string, value float64, attrs map[string]string, at time.Time)
	Log(severity, body string, attrs map[string]string, at time.Time)
}

Sink receives samples and log records.

func Hoist

func Hoist(out Sink) Sink

Hoist wraps out so ResourcePrefix keys become resource attributes. It is used only by the Kubernetes modules; out is returned unchanged when it cannot take resource attributes (then the prefixed keys stay ordinary attributes).

func QueueContract added in v0.3.1

func QueueContract(out Sink) Sink

QueueContract returns out with the Queues-area series added next to the broker's own.

Jump to

Keyboard shortcuts

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