Documentation
¶
Index ¶
- func Observe[T any](r *OperationRecorder, operation string, fn func() (T, error)) (T, error)
- func ObserveErr(r *OperationRecorder, operation string, fn func() error) error
- func RegisterPoolStats(reg prometheus.Registerer, prefix string, pools map[string]any) error
- type OperationRecorder
- type PoolStats
- type PoolStatter
- type QueryTracer
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, prefix string, pools map[string]any) error
RegisterPoolStats registers a collector exporting pool state, the configured bounds and acquisition counters for each named pool, under metric names beginning with prefix. 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 ¶
func (r *OperationRecorder) Init(reg prometheus.Registerer) error
Init registers r's histogram with reg. Call once, before serving traffic.
type PoolStats ¶ added in v1.44.0
PoolStats and PoolStatter are re-exported from pkg/dbstats so callers of this package need not import both. The definitions live there because the storage driver produces them and must not depend on Prometheus to do so.
type PoolStatter ¶
type PoolStatter = dbstats.PoolStatter
PoolStats and PoolStatter are re-exported from pkg/dbstats so callers of this package need not import both. The definitions live there because the storage driver produces them and must not depend on Prometheus to do so.
type QueryTracer ¶ added in v1.100.0
type QueryTracer struct {
// contains filtered or unexported fields
}
QueryTracer is a pgx tracer that records the duration of every statement a pool runs, labeled by operation and status. The operation is the name from the "-- name:" header of the query, or begin, commit or rollback for transaction control. Renaming a query changes its label and breaks dashboards that filter on it. The sample ends when the rows are closed, so it includes the caller's read time. It is stateless, so one tracer can serve several pools.
func NewQueryTracer ¶ added in v1.100.0
func NewQueryTracer(reg prometheus.Registerer, name string) (*QueryTracer, error)
NewQueryTracer registers the duration histogram under name on reg and returns the tracer that records into it.
func (*QueryTracer) TraceQueryEnd ¶ added in v1.100.0
func (t *QueryTracer) TraceQueryEnd(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryEndData)
TraceQueryEnd sees no error for a row QueryRow does not find, because pgx raises ErrNoRows later, in Scan. A miss therefore counts as ok.
func (*QueryTracer) TraceQueryStart ¶ added in v1.100.0
func (t *QueryTracer) TraceQueryStart(ctx context.Context, _ *pgx.Conn, data pgx.TraceQueryStartData) context.Context