db

package
v1.42.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Observe

func Observe[T any](r *OperationRecorder, operation string, fn func() (T, error)) (T, error)

Observe runs fn, recording its duration under operation (e.g. "store.BatchUpsert") and a status of "ok" or "error" based on whether fn returned an error.

func ObserveErr

func ObserveErr(r *OperationRecorder, operation string, fn func() error) error

ObserveErr is Observe for operations that return only an error.

func RegisterPoolStats

func RegisterPoolStats(reg prometheus.Registerer, metricName, help string, pools map[string]any) error

RegisterPoolStats registers a collector exporting connection-pool saturation (labeled "pool"/"state") for each named pool. Pools that don't implement PoolStatter (e.g. test fakes) are silently skipped.

Types

type OperationRecorder

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

OperationRecorder times repository/store-level calls into a histogram labeled "operation"/"status". The histogram is lazily created, so Observe/ObserveErr are safe to call even before Init has run.

func NewOperationRecorder

func NewOperationRecorder(name, help string) *OperationRecorder

NewOperationRecorder returns an independent recorder for a DB-operation-duration histogram with the given name/help.

func (*OperationRecorder) Init

Init registers r's histogram with reg. Call once, before serving traffic.

type PoolStatter

type PoolStatter interface {
	PoolStat() (idle, used int32, ok bool)
}

PoolStatter is satisfied by pkg/storage/internal/driver.SqlDB. Declared in terms of primitive values, not a driver-specific stat type, so this package stays driver-agnostic. ok is false if the pool isn't connected yet or has already been closed — an expected state, not an error.

Jump to

Keyboard shortcuts

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