You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
in_node_exporter_metrics: give each instance its own collectors - #12923
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.
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>
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
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
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The collector descriptors in in_node_exporter_metrics are globals (
cpu_collector,meminfo_collector, ...) andin_ne_init()linked their_headstraight intoctx->collectors. A second instance links the same nodes into its own list, which breaks the first instance's list, and both end up sharingcoll_fd/activated. On shutdownin_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):
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 wholeflb-rt-in_node_exporter_metricssuite passes, and valgrind on the new test reports 0 errors / no leaks.Testing
ok-package-testlabelDocumentation
Backporting
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