obs

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package obs wires Prometheus metrics for docsiq. One registry per process (exposed via obs.Default). Metric families are grouped by subject (HTTP, pipeline, embed, LLM, workq, build-info) so handlers record through a thin typed API — callers never touch raw collectors.

Index

Constants

This section is empty.

Variables

View Source
var (
	Default = prometheus.NewRegistry()

	HTTP     *HTTPMetrics
	Pipeline *PipelineMetrics
	Embed    *EmbedMetrics
	LLM      *LLMMetrics
	Workq    *WorkqMetrics
	Build    *BuildInfoMetric
)

Default is the process-wide registry. Tests construct their own prometheus.NewRegistry() to avoid Register-twice panics.

Functions

func Init

func Init()

func NewProductionHandler

func NewProductionHandler(inner slog.Handler) slog.Handler

NewProductionHandler wraps an inner slog.Handler and strips a leading emoji + trailing space from each record's Message. docsiq uses emoji prefixes (OK KO WARN etc.) as visual cues in dev text format; in JSON these collide with log-aggregator indexing (Elasticsearch tokeniser, fluentd grep rules) and obscure the actual message string. The handler mutates only Message — attrs pass through.

Types

type BuildInfoMetric

type BuildInfoMetric struct {
	Info *prometheus.GaugeVec
}

BuildInfoMetric wraps the docsiq_build_info gauge used for {version, commit} labels on dashboards.

func NewBuildInfoMetric

func NewBuildInfoMetric(reg prometheus.Registerer) *BuildInfoMetric

NewBuildInfoMetric constructs + registers the build-info gauge.

func (*BuildInfoMetric) Set

func (m *BuildInfoMetric) Set(version, commit string)

Set publishes the current build metadata. Subsequent Set calls overwrite rather than accumulate labels.

type EmbedMetrics

type EmbedMetrics struct {
	Latency *prometheus.HistogramVec
}

EmbedMetrics bundles the embed-latency histogram.

func NewEmbedMetrics

func NewEmbedMetrics(reg prometheus.Registerer) *EmbedMetrics

NewEmbedMetrics constructs + registers the embed-latency family.

func (*EmbedMetrics) Observe

func (m *EmbedMetrics) Observe(provider string, d time.Duration)

Observe records a single embed-batch call duration.

type HTTPMetrics

type HTTPMetrics struct {
	Requests *prometheus.CounterVec
	Duration *prometheus.HistogramVec
}

HTTPMetrics bundles the request counter + duration histogram.

func NewHTTPMetrics

func NewHTTPMetrics(reg prometheus.Registerer) *HTTPMetrics

NewHTTPMetrics constructs and registers the HTTP metric family on reg.

func (*HTTPMetrics) Observe

func (m *HTTPMetrics) Observe(route, method string, status int, d time.Duration)

Observe records one request. `route` MUST be the pattern (e.g. "GET /api/documents/{id}"), not r.URL.Path — raw paths have unbounded cardinality and will explode the scrape database.

type LLMMetrics

type LLMMetrics struct {
	Tokens *prometheus.CounterVec
}

LLMMetrics bundles the token-counter family.

func NewLLMMetrics

func NewLLMMetrics(reg prometheus.Registerer) *LLMMetrics

NewLLMMetrics constructs + registers the LLM-tokens family.

func (*LLMMetrics) RecordTokens

func (m *LLMMetrics) RecordTokens(provider, kind string, n int)

RecordTokens increments the counter by n. Use kind="prompt", "completion", or "total" (when the provider cannot split usage). Non-positive n is ignored so callers don't have to guard.

type PipelineMetrics

type PipelineMetrics struct {
	StageDuration *prometheus.HistogramVec
}

PipelineMetrics bundles the pipeline-stage histogram.

func NewPipelineMetrics

func NewPipelineMetrics(reg prometheus.Registerer) *PipelineMetrics

NewPipelineMetrics constructs + registers the pipeline-stage family.

func (*PipelineMetrics) TimeStage

func (m *PipelineMetrics) TimeStage(stage string, fn func() error) error

TimeStage measures the wall-clock duration of fn and records it against the given stage label. The error from fn is propagated.

type WorkqMetrics

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

WorkqMetrics wraps the workq gauges/counters; the actual values are read via a late-bound provider function so the pool can be swapped in after registration without re-registering collectors.

func NewWorkqMetrics

func NewWorkqMetrics(reg prometheus.Registerer) *WorkqMetrics

NewWorkqMetrics registers the workq collectors. The provider is a no-op until BindStatsProvider is called; Prometheus scrapes before binding will see Depth=0, Rejected=0 (safe defaults).

func (*WorkqMetrics) BindStatsProvider

func (m *WorkqMetrics) BindStatsProvider(p WorkqStatsProvider)

BindStatsProvider wires a live snapshot source. Call from cmd/serve.go after the pool is created, before starting the HTTP server.

type WorkqStats

type WorkqStats struct {
	Depth    int64
	Rejected int64
}

WorkqStats is the snapshot surface the obs layer needs from workq. Workq owns the concrete Pool.Stats() method; obs only reads.

type WorkqStatsProvider

type WorkqStatsProvider func() WorkqStats

WorkqStatsProvider is a closure over pool.Stats(). Injected from cmd/serve.go after the pool is constructed, so the obs package does not take a hard dep on internal/workq (keeps the import DAG acyclic).

Jump to

Keyboard shortcuts

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