Skip to content

cleanup: improve error message when inode map is full#729

Merged
Molter73 merged 1 commit into
mainfrom
mauro/cleanup/improve-inode-limit-error
May 28, 2026
Merged

cleanup: improve error message when inode map is full#729
Molter73 merged 1 commit into
mainfrom
mauro/cleanup/improve-inode-limit-error

Conversation

@Molter73
Copy link
Copy Markdown
Collaborator

@Molter73 Molter73 commented May 28, 2026

Description

When reaching the maximum number of inodes that can be tracked, attempting to insert a new entry in the kernel map will produce an error message pointing the user to increase the value via:

  • The bpf.inodes_max configuration value.
  • The FACT_INODES_MAX environment variable.
  • The --inodes-max argument.

There is also a minor cleanup on the name of the environment variable for consistency among all the configuration options.

This change will need to be backported to the release-0.3 branch.

Checklist

  • Patch has a change log entry OR does not need one.
  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

Monitored a directory with lots of files and limited the amount to track with --inodes-max 64.

Without the change fact crashes with the message:

Error: Failed to update entry for /etc/***
Caused by:
    0: Failed to insert kernel entry for /etc/***
    1: `bpf_map_update_elem` failed
    2: Argument list too long (os error 7)

With the change:

Error: Failed to update entry for /etc/***

Caused by:
    Reached maximum number of inodes to track.
    You can increase this limit with:
    * The bpf.inodes_max configuration value.
    * The FACT_INODES_MAX environment variable.
    * The --inodes-max argument.

Summary by CodeRabbit

  • Chores

    • Environment variable for maximum tracked inodes renamed to FACT_INODES_MAX
  • Bug Fixes

    • Enhanced error messaging when inode tracking capacity is exceeded, with clear instructions on how to increase the limit

Review Change Stack

When reaching the maximum number of inodes that can be tracked,
attempting to insert a new entry in the kernel map will produce an error
message pointing the user to increase the value via:
* The bpf.inodes_max configuration value.
* The FACT_INODES_MAX environment variable.
* The --inodes-max argument.

There is also a minor cleanup on the name of the environment variable
for consistency among all the configuration options.
@Molter73 Molter73 requested a review from a team as a code owner May 28, 2026 14:39
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

📝 Walkthrough

Walkthrough

A small PR that updates the environment variable binding for inode tracking configuration from FACT_INODE_MAX to FACT_INODES_MAX, and enhances kernel map insertion error handling to detect and report ArgumentListTooLong errors with specific guidance on increasing the tracking limit.

Changes

Inode Tracking Configuration and Error Handling

Layer / File(s) Summary
Environment variable binding update
fact/src/config/mod.rs
CLI environment variable for inode tracking maximum is renamed from FACT_INODE_MAX to FACT_INODES_MAX in the clap attribute.
Inode map insertion error handling
fact/src/host_scanner.rs
Imports are extended with std::io and Aya error types (MapError, SyscallError). Kernel inode map insertion errors are matched to detect ArgumentListTooLong syscall errors and emit a dedicated message directing users to increase the limit; other failures retain contextual error reporting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 The rabbits hop with joy today,
Env vars trimmed the config way,
With INODES_MAX now pristine and bright,
And error whispers guide the light!
When limits burst, we tell you true—
Just increase, and you'll break through! 🌱

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: improving the error message when the inode map reaches capacity.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description check ✅ Passed The PR description includes a clear explanation of changes, completed checklist items, and detailed testing performed with before/after output.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mauro/cleanup/improve-inode-limit-error

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

Copy link
Copy Markdown
Contributor

@ovalenti ovalenti left a comment

Choose a reason for hiding this comment

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

LGTM ! 👍

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fact/src/config/mod.rs`:
- Line 523: Add unit tests that set the FACT_INODES_MAX environment variable and
assert it populates the bpf.inodes_max config value: in the test module that
exercises configuration parsing (fact/src/config/tests.rs) create a test (e.g.,
test_env_var_inodes_max) which uses std::env::set_var("FACT_INODES_MAX",
"<value>"), invokes the same config parsing/constructor used in existing tests
(the Config builder/parse function that produces the struct with
bpf.inodes_max), then assert config.bpf.inodes_max == <value>. Also include a
test for the old name if desired and ensure tests clear/reset the env var after
running to avoid cross-test pollution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: e1e17999-f511-4442-9d3a-10129c2892eb

📥 Commits

Reviewing files that changed from the base of the PR and between 48780fb and 9ba9015.

📒 Files selected for processing (2)
  • fact/src/config/mod.rs
  • fact/src/host_scanner.rs

Comment thread fact/src/config/mod.rs
/// Going over this limit will prevent fact from tracking and
/// filling in the host path correctly in events.
#[arg(long, short, env = "FACT_INODE_MAX")]
#[arg(long, short, env = "FACT_INODES_MAX")]
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 28, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify that tests exist covering the renamed FACT_INODES_MAX environment variable

# Search for tests referencing the new environment variable name
rg -n "FACT_INODES_MAX" fact/src/config/tests.rs

# Also check for any tests covering inodes_max CLI parsing
rg -nC5 "inodes_max" fact/src/config/tests.rs

Repository: stackrox/fact

Length of output: 4987


Add/adjust unit tests to cover the FACT_INODE_MAXFACT_INODES_MAX env-var rename.
fact/src/config/tests.rs currently covers parsing/validation of the bpf.inodes_max field from config strings (e.g., inodes_max: 64/16384 and related type/validation cases), but there’s no evidence of tests asserting the environment variable binding for FACT_INODES_MAX (or the old name). Add unit tests that set the env var and verify it populates the inodes_max config value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fact/src/config/mod.rs` at line 523, Add unit tests that set the
FACT_INODES_MAX environment variable and assert it populates the bpf.inodes_max
config value: in the test module that exercises configuration parsing
(fact/src/config/tests.rs) create a test (e.g., test_env_var_inodes_max) which
uses std::env::set_var("FACT_INODES_MAX", "<value>"), invokes the same config
parsing/constructor used in existing tests (the Config builder/parse function
that produces the struct with bpf.inodes_max), then assert config.bpf.inodes_max
== <value>. Also include a test for the old name if desired and ensure tests
clear/reset the env var after running to avoid cross-test pollution.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@coderabbitai there are currently no unit tests for environment variables, they pose a few issues with how Rust execute tests (all tests run under the same process on parallel threads, so setting environment variables could mess with the tests in unforeseen ways). I can try to figure out a way to test this properly, but I suggest we leave that for a follow up PR.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Molter73, that's a fair point — std::env::set_var is process-global and inherently racy when tests run in parallel, making it tricky to test env-var bindings reliably without extra infrastructure (e.g., serializing those tests with a mutex or running them with --test-threads=1). Deferring to a follow-up PR makes sense.

Would you like me to open a GitHub issue to track adding env-var coverage for FACT_INODES_MAX (and potentially other env-var bindings) in a future PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@coderabbitai, please do open the issue.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
gh issue create \
  --repo stackrox/fact \
  --title "test: add unit tests for environment variable bindings (e.g. FACT_INODES_MAX)" \
  --body "## Summary

Add unit tests that verify environment variable bindings correctly populate the corresponding configuration values.

Currently there are no tests covering env-var bindings for CLI arguments such as \`FACT_INODES_MAX\`, \`FACT_INODE_MAX\` (old name), and other env-vars mapped in \`FactCli\`. These were deferred because \`std::env::set_var\` is process-global and inherently racy when tests run in parallel under the same process.

## Motivation

The rename of \`FACT_INODE_MAX\`\`FACT_INODES_MAX\` in `#729` highlighted the lack of test coverage for env-var bindings. A regression here (wrong env-var name in the \`#[arg(env = ...)]\` attribute) would not be caught by existing tests.

## Suggested approach

- Serialize env-var tests using a shared \`Mutex\` (or the \`serial_test\` crate) so they don't interfere with parallel tests.
- Alternatively, scope tests to run with \`RUST_TEST_THREADS=1\` or via a dedicated test binary target.
- At minimum, add coverage for \`FACT_INODES_MAX\` populating \`bpf.inodes_max\`, and consider covering other env-var bindings in \`FactCli\`.
- Ensure each test cleans up the env var (e.g., via \`std::env::remove_var\`) to prevent cross-test pollution.

## References

- PR: https://github.com/stackrox/fact/pull/729
- Comment: https://github.com/stackrox/fact/pull/729#discussion_r3318634169

/cc `@Molter73`" \
  --assignee Molter73

Length of output: 1633



@Molter73, done! I've opened #730 to track adding env-var unit test coverage (including FACT_INODES_MAX) in a follow-up PR, assigned to you.

@Molter73 Molter73 enabled auto-merge (squash) May 28, 2026 15:03
@Molter73 Molter73 merged commit eebb192 into main May 28, 2026
25 of 27 checks passed
@Molter73 Molter73 deleted the mauro/cleanup/improve-inode-limit-error branch May 28, 2026 15:16
Molter73 added a commit that referenced this pull request May 28, 2026
When reaching the maximum number of inodes that can be tracked,
attempting to insert a new entry in the kernel map will produce an error
message pointing the user to increase the value via:
* The bpf.inodes_max configuration value.
* The FACT_INODES_MAX environment variable.
* The --inodes-max argument.

There is also a minor cleanup on the name of the environment variable
for consistency among all the configuration options.
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.

2 participants