internal

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetricTypeCounter   = shared.MetricTypeCounter
	MetricTypeGauge     = shared.MetricTypeGauge
	MetricTypeHistogram = shared.MetricTypeHistogram
	MetricTypeTimer     = shared.MetricTypeTimer
)
View Source
const (
	ExportFormatPrometheus = shared.ExportFormatPrometheus
	ExportFormatJSON       = shared.ExportFormatJSON
	ExportFormatInflux     = shared.ExportFormatInflux
	ExportFormatStatsD     = shared.ExportFormatStatsD
)
View Source
const (
	// MaxLabelsPerMetric limits labels per metric to prevent cardinality explosion.
	MaxLabelsPerMetric = 20

	// MaxLabelKeyLength limits label key length.
	MaxLabelKeyLength = 128

	// MaxLabelValueLength limits label value length.
	MaxLabelValueLength = 256

	// MaxLabelCardinality limits unique label combinations.
	MaxLabelCardinality = 10000
)

Variables

View Source
var DefaultBuckets = []float64{
	0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000,
}

DefaultBuckets provides default histogram buckets Values in seconds for latency measurements.

View Source
var ReservedLabels = map[string]bool{
	"__name__":     true,
	"__instance__": true,
	"__job__":      true,
	"__replica__":  true,
	"__tenant__":   true,
	"job":          true,
	"instance":     true,
	"le":           true,
	"quantile":     true,
}

ReservedLabels are protected system labels.

Functions

func AddCommonLabels

func AddCommonLabels(labels map[string]string, common *CommonLabels) map[string]string

AddCommonLabels adds common production labels to existing labels.

func CopyLabels

func CopyLabels(labels map[string]string) map[string]string

CopyLabels creates a deep copy of labels map.

func FilterReservedLabels

func FilterReservedLabels(tags map[string]string) map[string]string

FilterReservedLabels removes reserved labels from a tag map.

func FormatLabelsInflux

func FormatLabelsInflux(labels map[string]string) string

FormatLabelsInflux formats labels for InfluxDB export.

func FormatLabelsJSON

func FormatLabelsJSON(labels map[string]string) map[string]string

FormatLabelsJSON formats labels for JSON export (no special formatting needed).

func FormatLabelsPrometheus

func FormatLabelsPrometheus(labels map[string]string) string

FormatLabelsPrometheus formats labels for Prometheus export.

func MergeTags

func MergeTags(tagMaps ...map[string]string) map[string]string

MergeTags merges multiple tag maps with validation.

func NormalizeMetricName

func NormalizeMetricName(name string) string

NormalizeMetricName normalizes metric name.

func ParseTags

func ParseTags(tags ...string) map[string]string

ParseTags parses tags from string array.

func SanitizeLabelForInflux

func SanitizeLabelForInflux(key, value string) (string, string)

SanitizeLabelForInflux sanitizes labels for InfluxDB format.

func SanitizeLabelForPrometheus

func SanitizeLabelForPrometheus(key, value string) (string, string)

SanitizeLabelForPrometheus sanitizes labels for Prometheus format.

func SanitizeLabelForStatsD

func SanitizeLabelForStatsD(key, value string) (string, string)

SanitizeLabelForStatsD sanitizes labels for StatsD format.

func SanitizeLabelKey

func SanitizeLabelKey(key string) string

SanitizeLabelKey sanitizes a label key for safe use.

func SanitizeLabelValue

func SanitizeLabelValue(value string) string

SanitizeLabelValue sanitizes a label value for safe use.

func TagsToString

func TagsToString(tags map[string]string) string

TagsToString converts tags map to string representation.

func ValidateAndSanitizeTags

func ValidateAndSanitizeTags(tags map[string]string) (map[string]string, error)

ValidateAndSanitizeTags validates and sanitizes tags for production use.

func ValidateLabelKey

func ValidateLabelKey(key string) error

ValidateLabelKey validates a label key.

func ValidateLabelValue

func ValidateLabelValue(key, value string) error

ValidateLabelValue validates a label value.

func ValidateMetricName

func ValidateMetricName(name string) bool

ValidateMetricName validates metric name format.

Types

type CollectorStats

type CollectorStats = shared.CollectorStats

type CommonLabels

type CommonLabels struct {
	Service     string
	Environment string
	Version     string
	Instance    string
	Region      string
	Zone        string
}

CommonLabels provides standard labels for production metrics.

func (*CommonLabels) ToMap

func (cl *CommonLabels) ToMap() map[string]string

ToMap converts CommonLabels to map.

type Counter

type Counter = shared.Counter

Counter represents a counter metric.

func NewCounter

func NewCounter() Counter

NewCounter creates a new counter.

func NewCounterWithLabels

func NewCounterWithLabels(labels map[string]string) Counter

NewCounterWithLabels creates a new counter with labels.

type CustomCollector

type CustomCollector = shared.CustomCollector

CustomCollector defines interface for custom metrics collectors.

type ExportFormat

type ExportFormat = shared.ExportFormat

ExportFormat represents the format for metrics export.

type Exporter

type Exporter = shared.Exporter

Exporter defines the interface for metrics export.

type Gauge

type Gauge = shared.Gauge

Gauge represents a gauge metric.

func NewGauge

func NewGauge() Gauge

NewGauge creates a new gauge.

func NewGaugeWithLabels

func NewGaugeWithLabels(labels map[string]string) Gauge

NewGaugeWithLabels creates a new gauge with labels.

type Histogram

type Histogram = shared.Histogram

Histogram represents a histogram metric.

func NewHistogram

func NewHistogram() Histogram

NewHistogram creates a new histogram with default buckets.

func NewHistogramWithBuckets

func NewHistogramWithBuckets(buckets []float64) Histogram

NewHistogramWithBuckets creates a new histogram with custom buckets.

func NewHistogramWithLabels

func NewHistogramWithLabels(labels map[string]string, buckets []float64) Histogram

NewHistogramWithLabels creates a new histogram with labels.

type HistogramSample

type HistogramSample struct {
	Name      string             `json:"name"`
	Count     uint64             `json:"count"`
	Sum       float64            `json:"sum"`
	Buckets   map[float64]uint64 `json:"buckets"`
	Tags      map[string]string  `json:"tags"`
	Timestamp time.Time          `json:"timestamp"`
}

HistogramSample represents a histogram sample.

type LabelCardinality

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

LabelCardinality tracks label cardinality to prevent metric explosion.

func NewLabelCardinality

func NewLabelCardinality(maxCardinality int) *LabelCardinality

NewLabelCardinality creates a new label cardinality tracker.

func (*LabelCardinality) Check

func (lc *LabelCardinality) Check(metricName string, labels map[string]string) bool

Check checks if adding this label combination would exceed cardinality limits.

func (*LabelCardinality) GetCardinality

func (lc *LabelCardinality) GetCardinality() int

GetCardinality returns current cardinality count.

func (*LabelCardinality) Record

func (lc *LabelCardinality) Record(metricName string, labels map[string]string) error

Record records a label combination.

func (*LabelCardinality) Reset

func (lc *LabelCardinality) Reset()

Reset resets the cardinality tracker.

type LabelMetadata

type LabelMetadata struct {
	Key               string    `json:"key"`
	ValueCount        int       `json:"value_count"`         // Number of unique values seen
	LastSeen          time.Time `json:"last_seen"`           // Last time this label was used
	IsHighCardinality bool      `json:"is_high_cardinality"` // Flag if cardinality > threshold
	SampleValues      []string  `json:"sample_values"`       // Sample of values for debugging
}

LabelMetadata tracks metadata about labels for production observability.

type LabelRegistry

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

LabelRegistry tracks label usage for production monitoring.

func NewLabelRegistry

func NewLabelRegistry() *LabelRegistry

NewLabelRegistry creates a new label registry.

func (*LabelRegistry) GetHighCardinalityLabels

func (lr *LabelRegistry) GetHighCardinalityLabels() []string

GetHighCardinalityLabels returns labels with high cardinality.

func (*LabelRegistry) GetLabelStats

func (lr *LabelRegistry) GetLabelStats() map[string]*LabelMetadata

GetLabelStats returns statistics about labels.

func (*LabelRegistry) RecordLabel

func (lr *LabelRegistry) RecordLabel(key, value string)

RecordLabel records usage of a label.

type LabelValidationError

type LabelValidationError struct {
	Label  string
	Reason string
	Value  string
}

LabelValidationError represents a label validation error.

func (*LabelValidationError) Error

func (e *LabelValidationError) Error() string

type MetricMetadata

type MetricMetadata struct {
	Name        string            `json:"name"`
	Type        MetricType        `json:"type"`
	Description string            `json:"description"`
	Tags        map[string]string `json:"tags"`
	Unit        string            `json:"unit"`
	Created     time.Time         `json:"created"`
	Updated     time.Time         `json:"updated"`
}

MetricMetadata contains metadata about a metric.

type MetricSample

type MetricSample struct {
	Name      string            `json:"name"`
	Type      MetricType        `json:"type"`
	Value     float64           `json:"value"`
	Tags      map[string]string `json:"tags"`
	Timestamp time.Time         `json:"timestamp"`
	Unit      string            `json:"unit"`
}

MetricSample represents a single metric sample.

type MetricType

type MetricType = shared.MetricType

MetricType represents the type of metric.

type MetricValue

type MetricValue struct {
	Metadata  *MetricMetadata `json:"metadata"`
	Value     any             `json:"value"`
	Timestamp time.Time       `json:"timestamp"`
}

MetricValue represents a metric value with metadata.

type Metrics

type Metrics = shared.Metrics

type MetricsConfig

type MetricsConfig = shared.MetricsConfig

type Timer

type Timer = shared.Timer

Timer represents a timer metric.

func NewTimer

func NewTimer() Timer

NewTimer creates a new timer.

func NewTimerWithLabels

func NewTimerWithLabels(labels map[string]string) Timer

NewTimerWithLabels creates a new timer with labels.

type TimerSample

type TimerSample struct {
	Name      string            `json:"name"`
	Count     uint64            `json:"count"`
	Mean      time.Duration     `json:"mean"`
	Min       time.Duration     `json:"min"`
	Max       time.Duration     `json:"max"`
	P50       time.Duration     `json:"p50"`
	P95       time.Duration     `json:"p95"`
	P99       time.Duration     `json:"p99"`
	Tags      map[string]string `json:"tags"`
	Timestamp time.Time         `json:"timestamp"`
}

TimerSample represents a timer sample.

Jump to

Keyboard shortcuts

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