Documentation
¶
Overview ¶
Package observability exports hotload activity as prometheus metrics.
Hotload v3's core has no metrics dependency; it emits events through hotload.Hooks. This module adapts those events to prometheus collectors that preserve the metric names of hotload v1, so existing dashboards keep working. Unlike v1, registration is explicit:
import "github.com/infobloxopen/hotload/observability"
func main() {
observability.MustEnablePrometheus(nil) // nil = prometheus.DefaultRegisterer
...
}
With a nil registerer the call is idempotent, so a library and its caller can both enable metrics without coordinating.
Index ¶
Constants ¶
const ( GRPCMethodKey = "grpc_method" GRPCServiceKey = "grpc_service" StatementKey = "stmt" // either exec or query ExecStatement = "exec" QueryStatement = "query" StrategyKey = "strategy" PathKey = "path" UrlKey = "url" )
Label keys and values, identical to hotload v1's metrics package.
const ( SqlStmtsSummaryName = "transaction_sql_stmts" HotloadChangeTotalName = "hotload_change_total" HotloadLastChangedTimestampSecondsName = "hotload_last_changed_timestamp_seconds" HotloadModtimeLatencyHistogramName = "hotload_modtime_latency_histogram" )
Metric names, identical to hotload v1.
const HotloadPathChksumTimestampSecondsName = "hotload_path_chksum_timestamp_seconds"
HotloadPathChksumTimestampSecondsName is the metric name, identical to hotload v1.
const PathChksumMetricsEnableEnvVar = "HOTLOAD_PATH_CHKSUM_METRICS_ENABLE"
PathChksumMetricsEnableEnvVar gates checksum collection: hashing every watched file on each scrape is not free, so it is opt-in, exactly as in hotload v1.
Variables ¶
var HotloadModtimeLatencyHistogramDefBuckets = []float64{900, 1800, 2700, 3600, 4500, 5400, 7200, 10800, 14400, 28800, 86400}
HotloadModtimeLatencyHistogramDefBuckets are the default buckets (seconds) of the modtime latency histogram, identical to hotload v1.
Functions ¶
func DefaultFileHasher ¶
DefaultFileHasher hashes file contents using CRC64.
Types ¶
type Collectors ¶
type Collectors struct {
// SqlStmtsSummary tracks the number of sql statements per transaction
// by statement type and the grpc service/method labels carried by the
// transaction context (see hotload.ContextWithExecLabels).
SqlStmtsSummary *prometheus.SummaryVec
// HotloadChangeTotal counts config changes per hotload DSN.
HotloadChangeTotal *prometheus.CounterVec
// HotloadLastChangedTimestampSeconds is the unix timestamp of the last
// config change per hotload DSN.
HotloadLastChangedTimestampSeconds *prometheus.GaugeVec
// HotloadModtimeLatencyHistogram tracks how stale watched files are,
// fed by the modtime monitor.
HotloadModtimeLatencyHistogram *prometheus.HistogramVec
// HotloadPathChksumTimestampSeconds reports when each watched file's
// content checksum last changed, computed at scrape time. Gated by the
// HOTLOAD_PATH_CHKSUM_METRICS_ENABLE environment variable.
HotloadPathChksumTimestampSeconds *PathChksumCollector
}
Collectors bundles the prometheus collectors fed by hotload hooks.
func EnablePrometheus ¶
func EnablePrometheus(reg prometheus.Registerer) (*Collectors, error)
EnablePrometheus creates the collectors, registers them with reg, and registers the hooks that feed them with hotload. Call it during program initialization, before opening hotload connections.
When reg is nil (or prometheus.DefaultRegisterer) the call is idempotent: the first call registers collectors and hooks with the default registerer and later calls return that same *Collectors — so an application and a library it uses can both enable hotload metrics defensively without tripping duplicate-registration errors. Calls with any other registerer create and register fresh collectors every time; managing their lifetime is the caller's job (this is the path tests use with throwaway registries).
func MustEnablePrometheus ¶
func MustEnablePrometheus(reg prometheus.Registerer) *Collectors
MustEnablePrometheus is EnablePrometheus, panicking on registration errors.
func NewCollectors ¶
func NewCollectors() *Collectors
NewCollectors creates unregistered collectors with hotload v1's metric names.
func (*Collectors) All ¶
func (c *Collectors) All() []prometheus.Collector
All returns every collector, for manual registration.
func (*Collectors) Hooks ¶
func (c *Collectors) Hooks() hotload.Hooks
Hooks returns the hotload hooks that feed the collectors. Register them with hotload.RegisterHooks (EnablePrometheus does this for you).
type FileHasher ¶
FileHasher hashes a file's contents; replaceable for unit tests.
type PathChksumCollector ¶
type PathChksumCollector struct {
// contains filtered or unexported fields
}
PathChksumCollector is a prometheus.Collector reporting, per watched path, the unix timestamp at which the file's content checksum last changed. The checksum is computed at scrape time, so the metric stays accurate without a background poller. It replaces hotload v1's gaugefuncvec-based implementation.
func NewPathChksumCollector ¶
func NewPathChksumCollector(hasher FileHasher) *PathChksumCollector
NewPathChksumCollector creates a collector using hasher (DefaultFileHasher when nil). Collection is enabled by PathChksumMetricsEnableEnvVar.
func (*PathChksumCollector) AddPath ¶
func (p *PathChksumCollector) AddPath(pathStr string)
AddPath starts reporting the checksum timestamp of pathStr, which must be a local file path. Duplicate adds are ignored. Fed automatically for fsnotify watches when the collector is wired through Collectors.Hooks; custom file-backed strategies should call it directly.
func (*PathChksumCollector) Collect ¶
func (p *PathChksumCollector) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector. Each watched file is hashed; a changed checksum bumps the path's last-changed timestamp.
func (*PathChksumCollector) Describe ¶
func (p *PathChksumCollector) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.