Skip to content

in_node_exporter_metrics: add netdev ignore regex#11819

Open
stondo wants to merge 1 commit into
fluent:masterfrom
stondo:in_node_exporter_metrics-netdev-ignore-regex
Open

in_node_exporter_metrics: add netdev ignore regex#11819
stondo wants to merge 1 commit into
fluent:masterfrom
stondo:in_node_exporter_metrics-netdev-ignore-regex

Conversation

@stondo
Copy link
Copy Markdown

@stondo stondo commented May 18, 2026

Summary

Add netdev.ignore_device_regex to the node_exporter_metrics input so Linux network device metrics can be filtered by regular expression before samples are emitted.

This mirrors the existing regex filtering model used by the diskstats and filesystem collectors, and covers dynamic interface names such as veth0, veth1, etc. Exact label deletion after collection is not enough for this case because the interface names are runtime-generated.

Example configuration

[INPUT]
    Name                       node_exporter_metrics
    Tag                        node.metrics
    Scrape_Interval            1
    Metrics                    netdev
    netdev.ignore_device_regex ^(lo|podman|veth.*)$

With this configuration, node_network_*{device="lo"}, device="podman", and dynamic device="veth*" series are skipped while physical or host-relevant interfaces continue to be emitted.

Testing

  • Example configuration file for the change
  • Debug log output from testing the change
  • [N/A] Attached Valgrind output that shows no leaks or memory corruption was found

Build verification:

cmake -S . -B build -DFLB_CONFIG_YAML=Off -DFLB_TESTS_RUNTIME=Off -DFLB_TESTS_INTERNAL=Off -DFLB_EXAMPLES=Off
cmake --build build -j8 --target flb-plugin-in_node_exporter_metrics fluent-bit-bin

Local runtime smoke test on Linux:

[SERVICE]
    Flush     1
    Log_Level info

[INPUT]
    Name                       node_exporter_metrics
    Tag                        node.metrics
    Scrape_Interval            1
    Metrics                    netdev
    netdev.ignore_device_regex ^lo$

[OUTPUT]
    Name  prometheus_exporter
    Match *
    Host  127.0.0.1
    Port  9927

Smoke test result from http://127.0.0.1:9927/metrics:

node_network_total=32
lo_count=0

Sample retained host interfaces:

node_network_receive_bytes_total{device="wlp0s20f3"} 2269105625
node_network_receive_bytes_total{device="zcctun0"} 3550762101
node_network_receive_packets_total{device="wlp0s20f3"} 2971213
node_network_receive_packets_total{device="zcctun0"} 5405127

Log excerpt from the same smoke test:

[ info] [input:node_exporter_metrics:node_exporter_metrics.0] initializing
[ info] [input:node_exporter_metrics:node_exporter_metrics.0] storage_strategy='memory' (memory only)
[ info] [input:node_exporter_metrics:node_exporter_metrics.0] path.rootfs = /
[ info] [input:node_exporter_metrics:node_exporter_metrics.0] path.procfs = /proc
[ info] [input:node_exporter_metrics:node_exporter_metrics.0] path.sysfs  = /sys
[ info] [input:node_exporter_metrics:node_exporter_metrics.0] thread instance initialized

Embedded-device validation was also done with a downstream Yocto build on an ARM64 Linux device. With netdev.ignore_device_regex: "^(lo|podman|veth.*)$":

node_network_total=80
lo_count=0
podman_count=0
veth_count=0
eth0_count=16
wan0_count=16
br_lan_count=16

Documentation

  • Documentation required for this feature

The plugin documentation is maintained in fluent/fluent-bit-docs. I can open a follow-up docs PR for this new option if the feature shape is accepted.

Backporting

  • Backport to latest stable release.

No backport requested yet. This is a small additive configuration option and should be low risk if maintainers want it on a stable branch.

Summary by CodeRabbit

  • New Features
    • Added netdev.ignore_device_regex configuration option for the node exporter metrics plugin. Users can now filter out network device metrics using regular expression patterns.

Review Change Stack

Add netdev.ignore_device_regex so Linux network device metrics can be skipped by regular expression before metric samples are emitted.

This mirrors the existing regex filtering model used by diskstats and filesystem collectors, and covers dynamic interface names such as veth0 where exact label deletion is not sufficient.

Tested with:

cmake -S . -B build -DFLB_CONFIG_YAML=Off -DFLB_TESTS_RUNTIME=Off -DFLB_TESTS_INTERNAL=Off -DFLB_EXAMPLES=Off

cmake --build build -j8 --target flb-plugin-in_node_exporter_metrics fluent-bit-bin

Also smoke-tested locally with node_exporter_metrics netdev collection and netdev.ignore_device_regex ^lo$, confirming device="lo" was absent while other network interfaces remained present.

Signed-off-by: Stefano Tondo <stondo@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f67ff21c-69a5-4648-b81c-11bd8fc06bf5

📥 Commits

Reviewing files that changed from the base of the PR and between 6474297 and 7773cbd.

📒 Files selected for processing (3)
  • plugins/in_node_exporter_metrics/ne.c
  • plugins/in_node_exporter_metrics/ne.h
  • plugins/in_node_exporter_metrics/ne_netdev_linux.c

📝 Walkthrough

Walkthrough

This PR extends the node exporter metrics plugin with a new optional configuration option netdev.ignore_device_regex that allows filtering out network device metrics using a compiled regular expression pattern. The feature adds struct fields to store both the configuration text and compiled regex, registers the config option, and implements filtering logic within the netdev update loop.

Changes

Network device regex filtering in node exporter metrics

Layer / File(s) Summary
Data structure and configuration contract
plugins/in_node_exporter_metrics/ne.h, plugins/in_node_exporter_metrics/ne.c
struct flb_ne gains two new fields for storing the ignore regex (compiled pointer and text form). Configuration map registers the netdev.ignore_device_regex option with NULL default, mapped to netdev_regex_skip_devices_text.
Device filtering implementation and lifecycle
plugins/in_node_exporter_metrics/ne_netdev_linux.c
New netdev_skip_device helper function checks whether a device name matches the configured ignore regex. ne_netdev_init compiles the regex pattern from config text (failing initialization if regex compilation fails). netdev_update sanitizes device names and skips metric collection for devices matching the regex. ne_netdev_exit destroys the compiled regex during cleanup.

Sequence Diagram

sequenceDiagram
  participant Init as ne_netdev_init()
  participant Helper as netdev_skip_device()
  participant Update as netdev_update()
  participant Exit as ne_netdev_exit()
  Init->>Init: Compile regex from config text
  Update->>Helper: Check if device matches regex
  Helper-->>Update: Skip device flag
  Update->>Update: Continue if device matched
  Exit->>Exit: Destroy compiled regex
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

docs-required

Suggested reviewers

  • edsiper
  • cosmo0920

Poem

🐰 A device filter hops in with regex grace,
Skipping network names with a patterned face,
Config, compilation, and cleanup so neat—
Now metrics dance to a selective beat! 📊

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the primary change: adding a netdev ignore regex feature to the in_node_exporter_metrics plugin.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7773cbde1e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

"could not initialize regex pattern for ignored "
"network devices: '%s'",
ctx->netdev_regex_skip_devices_text);
return -1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid arming netdev collector after regex init failure

When netdev.ignore_device_regex is syntactically invalid, this early return -1 happens after activate_collector() has already registered the netdev update callback, and in_ne_init() only logs the activation failure and continues. That leaves the timer armed without netdev_configure() initializing ctx->netdev_ht; on the next scrape netdev_hash_get() calls flb_hash_table_get() with a NULL hash table and can crash the input instead of just rejecting the bad configuration cleanly.

Useful? React with 👍 / 👎.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant