metrics

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package metrics provides a private Prometheus registry and all initial BubbleFish Nexus metrics. Every metric registered here has at least one code path that increments or observes it — permanently-zero metrics are bugs.

INVARIANT: Never use prometheus.DefaultRegisterer. All metrics live exclusively on the private registry returned by New().

Reference: Tech Spec Section 11.3, Phase 0D Behavioral Contract items 1–3.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metrics

type Metrics struct {

	// ── Write path ──────────────────────────────────────────────────────────
	// PayloadProcessingLatency is the end-to-end write path latency, labeled
	// by source. Observed in handleWrite on each accepted payload.
	PayloadProcessingLatency *prometheus.HistogramVec

	// ThroughputPerSource counts successful writes per source.
	// Incremented in handleWrite after WAL + enqueue succeed.
	ThroughputPerSource *prometheus.CounterVec

	// ErrorsTotal counts errors by type label (e.g. "wal_append", "unmarshal").
	// Incremented whenever a write or queue operation fails fatally.
	ErrorsTotal *prometheus.CounterVec

	// ── Read path ────────────────────────────────────────────────────────────
	// ReadLatency is the end-to-end read path latency, labeled by source and
	// endpoint. Observed in handleQuery on each completed read.
	ReadLatency *prometheus.HistogramVec

	// ── Queue ────────────────────────────────────────────────────────────────
	// QueueDepth is the current number of entries buffered in the queue channel.
	// Updated by the daemon's watchdog goroutine and on each enqueue/dequeue.
	QueueDepth prometheus.Gauge

	// QueueProcessingRate counts payloads successfully dequeued and written.
	// Incremented by the queue worker on each successful destination write.
	QueueProcessingRate prometheus.Counter

	// ── WAL ──────────────────────────────────────────────────────────────────
	// WALPendingEntries is the count of WAL entries not yet DELIVERED.
	// Set after replay and updated by the WAL watchdog.
	WALPendingEntries prometheus.Gauge

	// WALDiskBytesFree is the available disk space on the WAL partition.
	// Updated by the WAL watchdog and doctor.
	WALDiskBytesFree prometheus.Gauge

	// WALHealthy is 1 when the WAL watchdog reports healthy, 0 otherwise.
	// Set by the WAL watchdog goroutine.
	WALHealthy prometheus.Gauge

	// WALAppendLatency is the per-Append fsync latency.
	// Observed in handleWrite around each wal.Append call.
	WALAppendLatency prometheus.Histogram

	// WALCRCFailures counts CRC32 mismatches detected during replay.
	// Incremented after replay by syncing WAL.CRCFailures().
	WALCRCFailures prometheus.Counter

	// WALIntegrityFailures counts HMAC mismatches during replay (integrity=mac).
	// Incremented when integrity checking is enabled and a MAC fails.
	WALIntegrityFailures prometheus.Counter

	// ── Replay ───────────────────────────────────────────────────────────────
	// ReplayEntriesTotal counts WAL entries processed during startup replay.
	// Incremented once per PENDING entry in replayWAL.
	ReplayEntriesTotal prometheus.Counter

	// ReplayDurationSeconds records the wall-clock time spent on WAL replay.
	// Set (not incremented) in replayWAL after replay completes.
	ReplayDurationSeconds prometheus.Gauge

	// ── Auth ─────────────────────────────────────────────────────────────────
	// AuthFailuresTotal counts authentication failures by source label.
	// Incremented in authenticate() when no key matches.
	AuthFailuresTotal *prometheus.CounterVec

	// ── Policy ───────────────────────────────────────────────────────────────
	// PolicyDenialsTotal counts policy gate rejections by source and reason.
	// Incremented whenever a policy check denies a request (403).
	// Reference: Tech Spec Section 11.3.
	PolicyDenialsTotal *prometheus.CounterVec

	// ── Rate limit ───────────────────────────────────────────────────────────
	// RateLimitHitsTotal counts rate limit rejections by source label.
	// Incremented in handleWrite and handleQuery when Allow() returns false.
	RateLimitHitsTotal *prometheus.CounterVec

	// ── Admin ────────────────────────────────────────────────────────────────
	// AdminCallsTotal counts admin endpoint calls by endpoint label.
	// Incremented in the admin middleware (requireAdminToken success path).
	AdminCallsTotal *prometheus.CounterVec

	// ── Config ───────────────────────────────────────────────────────────────
	// ConfigLintWarnings is the number of non-fatal config lint warnings.
	// Set after config load and after each hot reload.
	ConfigLintWarnings prometheus.Gauge

	// ── Embedding (Stage 4) ──────────────────────────────────────────────────
	// EmbeddingLatency is the end-to-end embedding provider call duration.
	// Observed in the cascade Stage 4 path on each Embed() call.
	// Reference: Tech Spec Section 11.3.
	EmbeddingLatency prometheus.Histogram

	// ── Temporal Decay (Stage 5) ─────────────────────────────────────────────
	// TemporalDecayApplied counts the number of times temporal decay reranking
	// was applied in Stage 5 (Hybrid Merge + Temporal Decay).
	// Reference: Tech Spec Section 11.3.
	TemporalDecayApplied prometheus.Counter

	// ── Visualization ───────────────────────────────────────────────────────
	// VizEventsDroppedTotal counts pipeline visualization events dropped
	// (channel full). Reference: Tech Spec Section 11.3.
	VizEventsDroppedTotal prometheus.Counter

	// ── Event Sink ──────────────────────────────────────────────────────────
	// EventsDroppedTotal counts event sink events dropped (channel full).
	// Reference: Tech Spec Section 11.3.
	EventsDroppedTotal prometheus.Counter

	// EventsDeliveredTotal counts event sink events successfully delivered.
	// Reference: Tech Spec Section 11.3.
	EventsDeliveredTotal prometheus.Counter

	// EventsFailedTotal counts event sink delivery failures (retries exhausted).
	// Reference: Tech Spec Section 11.3.
	EventsFailedTotal prometheus.Counter

	// ── Consistency ──────────────────────────────────────────────────────────
	// ConsistencyScore is the WAL-to-destination consistency score (0.0–1.0).
	// Set by the consistency checker background goroutine.
	// Reference: Tech Spec Section 11.5.
	ConsistencyScore prometheus.Gauge

	// ── Audit (Interaction Log) ─────────────────────────────────────────────
	// AuditLogErrorsTotal counts audit log write failures by file label
	// (primary or shadow). Incremented when a write or fsync fails.
	// Reference: Update U1.3.
	AuditLogErrorsTotal *prometheus.CounterVec

	// AuditShadowErrorsTotal counts shadow file write failures.
	// Reference: Update U1.7.
	AuditShadowErrorsTotal prometheus.Counter

	// AuditCRCFailuresTotal counts records where both primary and shadow had
	// CRC32 mismatches (unrecoverable corruption).
	// Reference: Update U1.7.
	AuditCRCFailuresTotal prometheus.Counter

	// AuditShadowRecoveriesTotal counts records recovered from shadow after
	// primary corruption.
	// Reference: Update U1.7.
	AuditShadowRecoveriesTotal prometheus.Counter

	// ── Audit (Interaction Log) — API & Emission ───────────────────────────
	// AuditRecordsTotal counts interaction records written, labeled by
	// operation_type and policy_decision.
	// Reference: Tech Spec Addendum Section A2.6.
	AuditRecordsTotal *prometheus.CounterVec

	// AuditLogBytes is the current interaction log file size in bytes.
	// Reference: Tech Spec Addendum Section A2.6.
	AuditLogBytes prometheus.Gauge

	// AuditLogRotationTotal counts interaction log file rotations.
	// Reference: Tech Spec Addendum Section A2.6.
	AuditLogRotationTotal prometheus.Counter

	// AuditQueryLatency is the /api/audit/log query latency.
	// Reference: Tech Spec Addendum Section A2.6.
	AuditQueryLatency prometheus.Histogram

	// ── Retrieval Firewall ──────────────────────────────────────────────────
	// FirewallFilteredTotal counts memories filtered (removed) by the retrieval
	// firewall, labeled by source and label that triggered the filter.
	// Reference: Tech Spec Addendum Section A2.6, A3.8.
	FirewallFilteredTotal *prometheus.CounterVec

	// FirewallDeniedTotal counts queries fully denied by the retrieval firewall,
	// labeled by source.
	// Reference: Tech Spec Addendum Section A2.6, A3.8.
	FirewallDeniedTotal *prometheus.CounterVec

	// FirewallLatency is the retrieval firewall filtering duration, labeled by
	// source. Reference: Tech Spec Addendum Section A3.8.
	FirewallLatency *prometheus.HistogramVec
	// contains filtered or unexported fields
}

Metrics holds the private Prometheus registry and all registered counters, gauges, and histograms. All metric names use the "bubblefish_" prefix.

Initialize with New(). Never embed or copy — pass by pointer.

func New

func New() *Metrics

New creates a Metrics with a private Prometheus registry. All metrics are registered exclusively on this private registry — prometheus.DefaultRegisterer is never touched.

New() never returns an error; MustRegister panics only on programming errors (duplicate names), which cannot occur with a fresh private registry.

func (*Metrics) Registry

func (m *Metrics) Registry() *prometheus.Registry

Registry returns the private Prometheus registry. Pass to promhttp.HandlerFor to serve the /metrics endpoint.

Reference: Tech Spec Section 12 (/metrics endpoint), Phase 0D item 4.

Jump to

Keyboard shortcuts

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