Documentation
¶
Index ¶
- func AndroidTarget() string
- func DefaultLabels() map[string]string
- func IsDaemon() bool
- func Register(name string, factory ProviderFactory)
- func SetDaemon(daemon bool)
- func SetInstanceName(name string)
- func SetProvider(p Provider)
- type Backend
- type Counter
- type Gauge
- type Histogram
- type LazyProvider
- func (l *LazyProvider) Close(ctx context.Context) error
- func (l *LazyProvider) NewCounter(name, help string, labels []string) Counter
- func (l *LazyProvider) NewGauge(name, help string, labels []string) Gauge
- func (l *LazyProvider) NewHistogram(name, help string, buckets []float64, labels []string) Histogram
- func (l *LazyProvider) NewTimer(name, help string, buckets []float64, labels []string) *Timer
- func (l *LazyProvider) Push(ctx context.Context) error
- type Provider
- type ProviderFactory
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AndroidTarget ¶
func AndroidTarget() string
AndroidTarget returns the combined target product and build variant from environment variables, e.g. "product-variant", or "unknown" if they are missing.
func DefaultLabels ¶
DefaultLabels returns a map of standard environmental labels that should be applied to all metrics across the ABFS fleet, regardless of the backend provider.
func Register ¶
func Register(name string, factory ProviderFactory)
Register registers a metrics provider factory by name.
func SetInstanceName ¶
func SetInstanceName(name string)
func SetProvider ¶
func SetProvider(p Provider)
Types ¶
type Backend ¶
type Backend interface {
// NewCounter must return a thread-safe Counter implementation native to the backend.
NewCounter(name, help string, labels []string) Counter
// NewGauge must return a thread-safe Gauge implementation native to the backend.
NewGauge(name, help string, labels []string) Gauge
// NewHistogram must return a thread-safe Histogram implementation native to the backend.
// The implementation should map the provided bucket boundaries to the backend's native
// histogram structure.
NewHistogram(name, help string, buckets []float64, labels []string) Histogram
// Push should implement the logic to push metrics to a remote aggregator.
// If the backend operates on a purely pull-based model,
// this can safely be implemented as a no-op returning nil.
Push(ctx context.Context) error
// Close should gracefully flush any in-memory buffers, stop background synchronization loops (if any),
// and close open connections to the metrics sink (if any).
Close(ctx context.Context) error
}
Backend is the engine API. Implementers (e.g., Prometheus) only need to implement these methods.
type Counter ¶
type Counter interface {
// Inc increase the counter by 1.
Inc(labelValues ...string)
// Add adds the given value to the counter. It panics if the value is < 0.
Add(val float64, labelValues ...string)
}
Counter represents a metric that only goes up.
type Gauge ¶
type Gauge interface {
// Set forces the Gauge to a specific value.
Set(val float64, labelValues ...string)
// Add applies a relative adjustment to the Gauge.
// Unlike Counter, Gauge allows negative value to be passed to Add.
Add(val float64, labelValues ...string)
}
Gauge represents a metric that can go up and down.
type Histogram ¶
type Histogram interface {
// Observe records a single data point (e.g., the time taken to process
// a request) into the histogram's underlying buckets.
Observe(val float64, labelValues ...string)
}
Histogram represents a metric that samples observations.
type LazyProvider ¶
type LazyProvider struct {
// contains filtered or unexported fields
}
LazyProvider delays the creation of the underlying provider until it's actually used.
func (*LazyProvider) NewCounter ¶
func (l *LazyProvider) NewCounter(name, help string, labels []string) Counter
func (*LazyProvider) NewGauge ¶
func (l *LazyProvider) NewGauge(name, help string, labels []string) Gauge
func (*LazyProvider) NewHistogram ¶
func (l *LazyProvider) NewHistogram(name, help string, buckets []float64, labels []string) Histogram
type Provider ¶
type Provider interface {
// NewCounter creates a new metric that strictly increases (e.g., number of requests served,
// errors encountered, or tasks completed).
NewCounter(name, help string, labels []string) Counter
// NewGauge creates a new metric that can arbitrarily go up and down (e.g., current memory usage,
// number of active connections, or queue size).
NewGauge(name, help string, labels []string) Gauge
// NewHistogram creates a new metric that samples observations (usually request durations or response sizes)
// and counts them in configurable buckets.
NewHistogram(name, help string, buckets []float64, labels []string) Histogram
// NewTimer creates a specialized component specifically designed for measuring durations.
// It wraps an underlying Histogram and provides a convenient Stop() method to record elapsed time.
NewTimer(name, help string, buckets []float64, labels []string) *Timer
// Push forces the underlying metrics to be sent to the remote backend immediately.
// This is typically used in batch jobs, ephemeral processes, or when using a push-based
// architecture.
Push(ctx context.Context) error
// Close flushes pending metrics.
Close(ctx context.Context) error
}
Provider is the unified factory for creating metrics. Clients use this interface to create all metrics, including Timers
func GetProvider ¶
func GetProvider() Provider
func NewLazyProvider ¶
NewLazyProvider creates a provider that delays calling the factory until a metric is created.
func NewNoopProvider ¶
func NewNoopProvider() Provider
NewNoopProvider returns a non-operational metrics provider.
func NewProvider ¶
NewProvider instantiates a metrics provider by name. If not found, it prints a warning and returns a Noop provider.
func WrapBackend ¶
WrapBackend takes a bare Backend and wraps it with default implementations (like Timer).