performance

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package performance provides metrics collection for tracking API call durations, configuration operations, and other performance-related data.

Metrics collection is opt-in (disabled by default) for privacy reasons. Users must explicitly enable metrics to begin recording.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordDuration

func RecordDuration(registry *Registry, operation, provider string, fn func() error) error

RecordDuration is a helper that records the duration of an operation function. It wraps the operation with timing and records success/failure. The operation's error is returned after recording.

Types

type OperationMetrics

type OperationMetrics struct {
	Count         int           // total number of operations
	TotalDuration time.Duration // cumulative duration
	MinDuration   time.Duration // minimum duration
	MaxDuration   time.Duration // maximum duration
	FailureCount  int           // number of failed operations
}

OperationMetrics tracks performance data for a specific operation and provider.

type OperationStats

type OperationStats struct {
	Count         int           `json:"count"`
	TotalDuration time.Duration `json:"total_duration_ms"`
	AvgDuration   time.Duration `json:"avg_duration_ms"`
	MinDuration   time.Duration `json:"min_duration_ms"`
	MaxDuration   time.Duration `json:"max_duration_ms"`
	FailureCount  int           `json:"failure_count"`
}

OperationStats is a snapshot of metrics for display.

type Registry

type Registry struct {
	Metrics map[string]map[string]*OperationMetrics // operation -> provider -> metrics
	Enabled bool                                    // metrics are opt-in for privacy
	// contains filtered or unexported fields
}

Registry holds all recorded metrics.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry with metrics disabled by default.

func (*Registry) Disable

func (r *Registry) Disable()

Disable turns off metrics collection.

func (*Registry) Enable

func (r *Registry) Enable()

Enable turns on metrics collection.

func (*Registry) GetStats

func (r *Registry) GetStats() Stats

GetStats returns a snapshot of current metrics.

func (*Registry) RecordOperation

func (r *Registry) RecordOperation(operation, provider string, duration time.Duration, success bool)

RecordOperation records a single operation's performance data. If metrics are disabled, this is a no-op.

func (*Registry) Reset

func (r *Registry) Reset()

Reset clears all recorded metrics.

func (*Registry) ToJSON

func (r *Registry) ToJSON() ([]byte, error)

ToJSON exports metrics as JSON for external tools.

type Stats

type Stats map[string]map[string]OperationStats

Stats is a map of operation names to provider stats.

func (Stats) Summary

func (s Stats) Summary() string

Summary returns a human-readable summary of all stats.

Jump to

Keyboard shortcuts

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