metrics

package
v0.8.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: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BandwidthMbpsBuckets

func BandwidthMbpsBuckets() []float64

BandwidthMbpsBuckets is for per-request throughput in MiB/s, covering everything from slow long-tail clients (a few MiB/s) up through saturated 10 GbE workstations (~1.2 GiB/s) and into the ~12 GiB/s range of 100 Gbps server NICs. Top bucket leaves headroom past the theoretical max so we can spot misattribution.

func ByteBuckets

func ByteBuckets() []float64

ByteBuckets covers cachew payload sizes, which range from tiny bundles (a few KiB) to multi-GiB snapshot tarballs.

func CacheSource added in v0.8.0

func CacheSource(ctx context.Context) (string, bool)

CacheSource returns the backend reported by ObserveCacheSource, if any.

func ContinueArtifactRequest added in v0.8.0

func ContinueArtifactRequest(ctx, request context.Context) context.Context

ContinueArtifactRequest retains metric attribution without inheriting a request's cancellation.

func FastLatencyBuckets

func FastLatencyBuckets() []float64

FastLatencyBuckets is for operations expected to complete in well under a minute (spool follower waits, ensure-refs round trips).

func HasArtifactRequest added in v0.8.0

func HasArtifactRequest(ctx context.Context) bool

HasArtifactRequest avoids allocating observation wrappers for unrelated cache operations.

func LatencyBuckets

func LatencyBuckets() []float64

LatencyBuckets covers operations that span sub-millisecond cache hits all the way to multi-minute clone/repack/generation work. The default OTel histogram boundaries (0..10 seconds) compress everything beyond 10s into the +Inf bucket, which makes p50/p90/avg unusable for cachew's git path.

func NewHistogram

func NewHistogram(meter metric.Meter, path, unit, description string, buckets []float64) metric.Float64Histogram

NewHistogram creates a Float64Histogram with explicit bucket boundaries. Prefer this over NewMetric for histograms: the OTel SDK default boundaries only go up to 10 seconds, which is far too narrow for most cachew metrics.

func NewMetric

func NewMetric[OM any](meter metric.Meter, path, unit, description string) OM

func ObserveCacheSource added in v0.8.0

func ObserveCacheSource(ctx context.Context, backend string)

ObserveCacheSource reports the backend that answered, after stale and conditional probes are resolved.

func RecordCacheFill added in v0.8.0

func RecordCacheFill(ctx context.Context, result string)

RecordCacheFill records completion rather than assuming an origin 200 was cached.

func RecordCacheWrite added in v0.8.0

func RecordCacheWrite(ctx context.Context, backend string, tier int, result string)

RecordCacheWrite records a terminal outcome for one backend writer.

func SmallCountBuckets

func SmallCountBuckets() []float64

SmallCountBuckets is for low-cardinality integer counts (e.g. number of pack files on a mirror), where the values of interest are mostly in the 1–100 range with a long tail.

func WithCachePurpose added in v0.8.0

func WithCachePurpose(ctx context.Context, purpose string) context.Context

WithCachePurpose distinguishes origin fills from background cache replication.

func WithoutArtifactRequest added in v0.8.0

func WithoutArtifactRequest(ctx context.Context) context.Context

WithoutArtifactRequest detaches ctx from its artifact request, so auxiliary lookups such as release metadata are not counted as origin traffic.

Types

type ArtifactMetrics added in v0.8.0

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

ArtifactMetrics separates origin exchanges from cache publication.

func NewArtifactMetrics added in v0.8.0

func NewArtifactMetrics() *ArtifactMetrics

NewArtifactMetrics uses the same provider as the server's HTTP metrics.

func (*ArtifactMetrics) WithRequest added in v0.8.0

func (m *ArtifactMetrics) WithRequest(ctx context.Context, strategy, registry string, external bool) context.Context

WithRequest scopes observations to a configured strategy and registry, never an artifact URL.

type Client

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

Client provides OpenTelemetry metrics with configurable exporters.

func New

func New(ctx context.Context, cfg Config) (*Client, error)

New creates a new OpenTelemetry metrics client with configurable exporters.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the meter provider.

func (*Client) Handler

func (c *Client) Handler() http.Handler

Handler returns the HTTP handler for the /metrics endpoint.

func (*Client) ServeMetrics

func (c *Client) ServeMetrics(ctx context.Context) error

ServeMetrics starts a dedicated HTTP server for Prometheus metrics scraping. This is only started if Prometheus exporter is enabled.

type Config

type Config struct {
	ServiceName        string `hcl:"service-name" help:"Service name for metrics." default:"cachew"`
	Port               int    `hcl:"port" help:"Port for Prometheus metrics server." default:"9102"`
	EnablePrometheus   bool   `hcl:"enable-prometheus" help:"Enable Prometheus exporter." default:"true"`
	EnableOTLP         bool   `hcl:"enable-otlp" help:"Enable OTLP exporter." default:"false"`
	OTLPEndpoint       string `hcl:"otlp-endpoint" help:"OTLP endpoint URL." default:"http://localhost:4318"`
	OTLPInsecure       bool   `hcl:"otlp-insecure" help:"Use insecure connection for OTLP." default:"false"`
	OTLPExportInterval int    `hcl:"otlp-export-interval" help:"OTLP export interval in seconds." default:"60"`
}

Config holds metrics configuration.

type OriginTransport added in v0.8.0

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

OriginTransport measures the exchanges of artifact requests that reach base. It must sit below any transport that answers without contacting the origin, such as upstream cooldowns, so that those answers are not counted.

func NewOriginTransport added in v0.8.0

func NewOriginTransport(base http.RoundTripper) *OriginTransport

NewOriginTransport measures exchanges sent to base.

func (*OriginTransport) CloseIdleConnections added in v0.8.0

func (t *OriginTransport) CloseIdleConnections()

CloseIdleConnections forwards to base, so http.Client.CloseIdleConnections still works.

func (*OriginTransport) RoundTrip added in v0.8.0

func (t *OriginTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper.

Jump to

Keyboard shortcuts

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