Skip to content

feat(netdev): support regex DeviceList matching#238

Open
jasen11 wants to merge 1 commit into
ccfos:mainfrom
jasen11:fix-0616
Open

feat(netdev): support regex DeviceList matching#238
jasen11 wants to merge 1 commit into
ccfos:mainfrom
jasen11:fix-0616

Conversation

@jasen11

@jasen11 jasen11 commented Jun 16, 2026

Copy link
Copy Markdown

Problem

DeviceList is documented and used as a whitelist for selected network devices, but several implementations only used exact string matching.

For example, this config could not match eth0:

DeviceList = ["eth[0-9]+"]

The previous behavior was equivalent to:

slices.Contains([]string{"eth[0-9]+"}, "eth0") // false

This made it hard to configure groups of devices such as eth0, eth1, bond0, etc. with regex patterns.

## Problem Reproduction

Before the fix:

current exact match: false
expected regex match: true

The old exact-match call sites were:

- core/events/netdev_events.go
- core/metrics/netdev_hw.go
- core/metrics/netdev_dcb.go

## Fix

This PR adds a shared ListMatcher in internal/matcher.

Behavior:

- Each DeviceList entry is treated as a regular expression.
- Matching is anchored to the full device name.
- Existing exact entries such as "eth0" still match only eth0.
- Regex entries such as "eth[0-9]+" match eth0, eth1, etc.
- Empty DeviceList keeps the existing behavior of matching no devices.

The matcher is applied to:

- EventTracing.Netdev
- MetricCollector.NetdevDCB
- MetricCollector.NetdevHW

The config file and configuration docs were also updated to describe the matching behavior.

## Tests

Added unit coverage for:

- empty list matches nothing
- exact device names still use exact-match behavior
- regex device patterns match expected devices
- invalid regex patterns return an error

Verified with:

go test ./internal/matcher ./core/events ./core/metrics
make build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant