prometheus/node_exporter · error
failed to parse device filter flags
Error message
failed to parse device filter flags: %w
What it means
On OpenBSD/amd64 (platform-specific file diskstats_openbsd_amd64.go), NewDiskstatsCollector likewise compiles the device filter regex flags via newDiskstatsDeviceFilter(logger). A regexp.Compile failure in the flags aborts construction with "failed to parse device filter flags: %w".
Solutions
- Inspect the wrapped regexp error (%w) for the exact position of the syntax error and fix the flag value.
- Quote the pattern on the command line: --collector.diskstats.device-exclude='^(wd|sd)\d+$'.
- Validate with a Go RE2-compatible regex tester before deploying.
- Remove the filter flag to confirm the collector otherwise starts, then reintroduce a corrected pattern.
Example fix
// before --collector.diskstats.device-exclude=^(wd|sd\d+$ // after --collector.diskstats.device-exclude='^(wd|sd)\d+$'
Defensive patterns
Strategy: validation
Validate before calling
if _, err := regexp.Compile(deviceExcludeFlag); err != nil {
// reject before passing to NewDiskstatsCollector
} Try / catch
if _, err := NewDiskstatsCollector(logger); err != nil {
if strings.Contains(err.Error(), "failed to parse device filter flags") {
log.Fatalf("fix device filter regex: %v", err)
}
log.Fatalf("diskstats init failed: %v", err)
} Prevention
- Quote flag values containing regex metacharacters.
- Check balanced groups/brackets in every pattern.
- Test patterns with a Go RE2 tester before deployment.
- Keep platform-specific launch configs in version control with flag linting.
When it happens
Trigger: node_exporter startup on OpenBSD amd64 with a device include/exclude flag value that fails regexp.Compile; same for direct invocation of this NewDiskstatsCollector variant.
Common situations: Unquoted regex values altered by the shell, typos creating invalid syntax (e.g. missing closing bracket), or patterns using syntax unsupported by Go's RE2 engine.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse device filter flags
- failed to parse device filter flags
- failed to parse device filter flags
- failed to parse device filter flags
- --collector.diskstats.ignored-devices and…
AI-assisted analysis of prometheus/node_exporter@17ddd77c59 (2026-09-07).
Data as JSON: /api/errors/24717a94e88ec5ae.
Report an issue: GitHub.
Appendix: source
Thrown at collector/diskstats_openbsd_amd64.go:65
rxfer typedDesc
rbytes typedDesc
wxfer typedDesc
wbytes typedDesc
time typedDesc
deviceFilter deviceFilter
logger *slog.Logger
}
func init() {
registerCollector("diskstats", defaultEnabled, NewDiskstatsCollector)
}
// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
}
return &diskstatsCollector{
rxfer: typedDesc{readsCompletedDesc, prometheus.CounterValue},
rbytes: typedDesc{readBytesDesc, prometheus.CounterValue},
wxfer: typedDesc{writesCompletedDesc, prometheus.CounterValue},
wbytes: typedDesc{writtenBytesDesc, prometheus.CounterValue},
time: typedDesc{ioTimeSecondsDesc, prometheus.CounterValue},
deviceFilter: deviceFilter,
logger: logger,
}, nil
}
func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) (err error) {
diskstatsb, err := unix.SysctlRaw("hw.diskstats")
if err != nil {
return errView on GitHub (pinned to 17ddd77c59)