Documentation
¶
Overview ¶
Package metrics provides Prometheus metrics helpers for the filterlist plugin.
Index ¶
Constants ¶
const ( // ResultAllowlisted marks a query that matched the allowlist and was forwarded. ResultAllowlisted = "allowlisted" // ResultForwarded marks a query that matched no rule and was forwarded unchanged. ResultForwarded = "forwarded" // ResultBlockedDenylist marks a query blocked by the denylist matcher. ResultBlockedDenylist = "blocked_denylist" // ResultBlockedRFC marks a query blocked by the RFC 1035 / IDNA name check. ResultBlockedRFC = "blocked_rfc" // ResultBlockedUnlisted marks a query blocked by the deny_non_allowlisted policy. ResultBlockedUnlisted = "blocked_unlisted" )
Query outcome label values for the Queries counter.
Each query produces exactly one of these results, so summing the counter over all label values yields the total number of queries handled, and the individual series answer "how many were blocked and why".
const ( // LatencyForwarded labels latency of queries that were forwarded. LatencyForwarded = "forwarded" // LatencyBlocked labels latency of queries that were blocked. LatencyBlocked = "blocked" )
Match latency label values for the MatchDuration histogram.
Latency is split only into the two coarse outcomes that matter for the request path: a forwarded query traverses the full matcher chain, while a blocked query short-circuits as soon as a rule decides the answer.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// Queries counts every handled query, labeled by result (see Result* constants).
Queries *prometheus.CounterVec
// MatchDuration records per-query matching latency, labeled by Latency* constants.
MatchDuration *prometheus.HistogramVec
CompileErrors prometheus.Counter
CompileDuration prometheus.Histogram
AllowlistRules prometheus.Gauge
DenylistRules prometheus.Gauge
AllowlistStates prometheus.Gauge
DenylistStates prometheus.Gauge
LastCompileTimestamp prometheus.Gauge
LastCompileDurationSeconds prometheus.Gauge
}
Registry groups the Prometheus collectors used by filterlist.
The collectors fall into two groups: request-path decisions (Queries, MatchDuration) and ruleset/compile health (the gauges, CompileDuration, and CompileErrors). Callers usually create one Registry per process or per Prometheus registerer and share it across handler instances.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a filterlist metric set on prometheus.DefaultRegisterer.
The returned Registry reuses already-registered collectors when another filterlist instance has already published the same metric names. Use this in CoreDNS plugin setup paths where multiple server blocks may instantiate the plugin within the same process.
func NewRegistryWith ¶
func NewRegistryWith(reg prometheus.Registerer) *Registry
NewRegistryWith creates a filterlist metric set on reg.
The reg parameter selects the Prometheus registerer that should own the metrics. When reg already contains collectors with the same metric descriptors, the existing collectors are reused instead of causing a panic. This keeps repeated setup calls safe while preserving shared metric series.