Skip to content

in_node_exporter_metrics: give each instance its own collectors - #12923

Open
locker95 wants to merge 2 commits into
fluent:masterfrom
locker95:in_ne-per-instance-collectors
Open

locker95 wants to merge 2 commits into
fluent:masterfrom
locker95:in_ne-per-instance-collectors

Conversation

@locker95

@locker95 locker95 commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

The collector descriptors in in_node_exporter_metrics are globals (cpu_collector, meminfo_collector, ...) and in_ne_init() linked their _head straight into ctx->collectors. A second instance links the same nodes into its own list, which breaks the first instance's list, and both end up sharing coll_fd/activated. On shutdown in_ne_pause() walks collectors that belong to the other instance - with two instances fluent-bit hangs or segfaults on SIGTERM, with one it exits fine.

This copies the descriptors into per-instance allocations (freed on exit), so each instance only ever touches its own collectors.

Fixes #12922

Config used (same as in the issue):

service:
  grace: 5
pipeline:
  inputs:
    - name: node_exporter_metrics
      metrics: cpu
    - name: node_exporter_metrics
      metrics: meminfo
  outputs:
    - name: null
      match: '*'

On master the process never exits after SIGTERM; with this change it exits 0. Also checked three instances (cpu / meminfo,loadavg / cpu) with stdout, metrics from all of them still show up.

Added a runtime test (multiple_instances) that starts two instances and stops the engine - it hangs on master and passes with the fix. The whole flb-rt-in_node_exporter_metrics suite passes, and valgrind on the new test reports 0 errors / no leaks.


Testing

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found
  • [N/A] Run local packaging test
  • [N/A] Set ok-package-test label

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue that could affect running multiple node exporter metrics inputs in the same engine. Each input now operates with its own collector state, helping ensure metrics are collected independently.
    • Improved cleanup when an input fails to initialize, preventing partially initialized resources from being left behind.

The collector descriptors are global objects and in_ne_init() linked
them straight into the instance's collector list. With a second
instance the same list nodes got linked into another list, corrupting
the first one, and both instances shared coll_fd and activated for
every collector. On shutdown in_ne_pause() then paused collectors that
belonged to the other instance and Fluent Bit crashed or hung.

Copy the descriptors into per-instance allocations and free them on
exit.

Signed-off-by: Dean Chen <862469039@qq.com>
Signed-off-by: Dean Chen <862469039@qq.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T19:50:06.613129Z fc90e0d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Collector descriptors are now copied into per-instance lists and freed during cleanup. A runtime test configures separate CPU and meminfo instances and checks that the output callback receives records.

Changes: Collector ownership and lifecycle

Layer / File(s) Summary
Instance-owned collector lists and validation
plugins/in_node_exporter_metrics/ne.c, tests/runtime/in_node_exporter_metrics.c
Initialization copies collector templates into per-instance lists and cleans up the lists on initialization failure and exit. The runtime test configures CPU and meminfo instances and checks for at least two output records.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to fc90e

This change lets multiple node_exporter_metrics inputs shut down cleanly and adds a runtime test for it. No merge-blocking issue remains. A small memory leak on rare initialization failures is a possible follow-up.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the plugin (in_node_exporter_metrics) and the main change (each instance gets its own collectors). The raw summary says collector descriptors are now copied per plugin instance instead…
Linked Issues check Passed Issue #12922 requires clean shutdown with multiple node_exporter_metrics instances. The root cause in the issue is that in_ne_init() linked the global collector descriptors (cpu_collector, meminfo_col…
Out of Scope Changes check Passed All changes in the whole-PR diff (merge base 3f82589 to head fc90e0d) are in plugins/in_node_exporter_metrics/ne.c and the runtime test in tests/runtime/in_node_exporter_metrics.c. The ne.c changes …
Full details: Title check

Explanation

The title names the plugin (in_node_exporter_metrics) and the main change (each instance gets its own collectors). The raw summary says collector descriptors are now copied per plugin instance instead of shared globals, and that instance-owned collector nodes are freed on exit. The title matches this main change and does not describe anything absent from the changeset.

Full details: Linked Issues check

Explanation

Issue #12922 requires clean shutdown with multiple node_exporter_metrics instances. The root cause in the issue is that in_ne_init() linked the global collector descriptors (cpu_collector, meminfo_collector, and others) into each instance's ctx->collectors list. The diff at ne.c replaces those direct mk_list_add() calls with collector_add(), which allocates a per-instance copy of each of the 22 collector templates and links the copy. Each instance therefore owns its list nodes, coll_fd, and activated state. collectors_destroy() frees the copies in in_ne_exit() after the exit callbacks run. The template list covers the same 22 collectors that the original code linked, so no collector is dropped. The issue's hwmon second-instance use case (log_level: off) depends on per-instance state, which this change now provides. The added runtime test multiple_instances covers two instances and a clean engine stop. I did not run the test. The PR description reports that it hangs on master and passes with the fix.

Full details: Out of Scope Changes check

Explanation

All changes in the whole-PR diff (merge base 3f82589 to head fc90e0d) are in plugins/in_node_exporter_metrics/ne.c and the runtime test in tests/runtime/in_node_exporter_metrics.c. The ne.c changes add per-instance collector copies, copy-failure cleanup in in_ne_init(), and freeing of the copies in in_ne_exit(). These directly implement the issue fix. The test verifies the reported two-instance scenario. No unrelated changes were identified in the reviewed summary and diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1cee0734-d621-424b-a2b4-de7c130b85db
Commits

Reviewing files that changed from the base of the PR and between 3f82589 and fc90e0d.

Files selected for processing: 2

  • plugins/in_node_exporter_metrics/ne.c
  • tests/runtime/in_node_exporter_metrics.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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.

in_node_exporter_metrics: two instances crash Fluent Bit on shutdown (SIGSEGV in flb_input_plugin_pause)

1 participant