Skip to content

[NC | NSFS | GLACIER] Add disk usage info to nsfs metrics #9094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tangledbytes
Copy link
Member

@tangledbytes tangledbytes commented Jun 12, 2025

Explain the Changes

This PR adds support for NooBaa reporting disk_usage as part of NSFS stats if enabled. This feature was requested by a customer.

Example:

{"nsfs_counters":{"noobaa_nsfs_io_read_count":0,"noobaa_nsfs_io_write_count":0,"noobaa_nsfs_io_read_bytes":0,"noobaa_nsfs_io_write_bytes":0},"op_stats_counters":{},"fs_worker_stats_counters":{},"disk_usage":"0.79"}

Issues: Fixed #xxx / Gap #xxx

Testing Instructions:

  • Doc added/updated
  • Tests added

Summary by CodeRabbit

  • New Features
    • Introduced periodic reporting of filesystem disk usage metrics for a configurable path in NSFS Glacier metrics.
    • Added new configuration options to specify the path for disk usage monitoring and the refresh interval.
    • Disk usage statistics are now included in Prometheus NSFS metrics endpoints when configured.

Copy link

coderabbitai bot commented Jun 12, 2025

Walkthrough

Two new configuration parameters were introduced to enable periodic reporting of filesystem statistics from a specified path. The Prometheus metrics reporting service was updated to periodically collect, cache, and include disk usage statistics from this path in its metrics output. These changes are conditional on configuration settings and do not alter existing logic.

Changes

File(s) Change Summary
config.js Added NSFS_GLACIER_METRICS_STATFS_PATH and NSFS_GLACIER_METRICS_STATFS_INTERVAL configuration options.
src/server/analytic_services/prometheus_reporting.js Added periodic statfs collection, caching, and reporting of disk usage in NSFS metrics endpoints.

Sequence Diagram(s)

sequenceDiagram
    participant Config as config.js
    participant Prometheus as prometheus_reporting.js
    participant FS as Filesystem

    Config->>Prometheus: Provide statfs path & interval config
    loop Every interval (if path is set)
        Prometheus->>FS: statfs(path)
        FS-->>Prometheus: statfs data
        Prometheus->>Prometheus: Cache statfs data
    end
    User->>Prometheus: Request /metrics/nsfs_stats
    Prometheus->>Prometheus: Retrieve cached statfs data
    Prometheus-->>User: Respond with NSFS metrics (includes disk usage)
Loading

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-16T10_11_46_845Z-debug-0.log


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a51abc8 and 207cf6d.

📒 Files selected for processing (2)
  • config.js (1 hunks)
  • src/server/analytic_services/prometheus_reporting.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • config.js
  • src/server/analytic_services/prometheus_reporting.js
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: run-jest-unit-tests
  • GitHub Check: build-noobaa-image
  • GitHub Check: run-package-lock-validation
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tangledbytes tangledbytes force-pushed the utkarsh/feat/add-disk-cache-metrics branch from e37ada3 to e305c57 Compare June 12, 2025 13:00
Copy link

@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

♻️ Duplicate comments (1)
src/server/analytic_services/prometheus_reporting.js (1)

237-239: Mirror the fix in the non-fork stats handler
Same remark as above—once get_disk_usage is made robust & numeric, this path stays consistent.

🧹 Nitpick comments (4)
config.js (1)

957-961: Comment/doc typo & naming inconsistency
The comment says STAT_PATH while the actual key is NSFS_GLACIER_METRICS_STATFS_PATH. Minor, but it trips up grepping and future maintenance.

-// NSFS_GLACIER_METRICS_STAT_PATH if set NooBaa will start reporting the statfs info of that
+// NSFS_GLACIER_METRICS_STATFS_PATH – if set, NooBaa will start reporting statfs info for that
src/server/analytic_services/prometheus_reporting.js (3)

16-17: Lazily require heavy native modules
nb_native() spins up native bindings; there’s no need to load it when the feature is disabled (default path is empty). Re-require only inside the if (config.NSFS_GLACIER_METRICS_STATFS_PATH) block to save startup time and avoid an unnecessary dependency cycle.

-const nb_native = require('../../util/nb_native');
-const { get_process_fs_context } = require('../../util/native_fs_utils');
+let nb_native;
+let get_process_fs_context;

and inside the if:

if (!nb_native) {
    nb_native = require('../../util/nb_native');
    ({ get_process_fs_context } = require('../../util/native_fs_utils'));
}

81-93: Prime the cache before the first scrape
On process start the first /metrics/nsfs_stats request will likely return disk_usage: undefined/NaN until the interval fires. Call the same statfs fetch once immediately after the if block (or reuse the helper suggested above) to avoid the “blank metric” on the very first scrape.


105-106: Return numeric disk_usage to match Prometheus expectations
Prometheus treats JSON values as numbers/strings strictly. After fixing get_disk_usage, ensure the value here is numeric; otherwise clients will have to special-case the type.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c247ca1 and e305c57.

📒 Files selected for processing (2)
  • config.js (1 hunks)
  • src/server/analytic_services/prometheus_reporting.js (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/server/analytic_services/prometheus_reporting.js (4)
src/sdk/bucketspace_fs.js (6)
  • nb_native (12-12)
  • require (15-23)
  • require (24-24)
  • require (25-25)
  • config (9-9)
  • dbg (37-37)
config.js (2)
  • require (17-17)
  • config (7-7)
src/sdk/namespace_fs.js (1)
  • statfs (465-465)
src/util/http_utils.js (2)
  • config (19-19)
  • dbg (18-18)

@tangledbytes tangledbytes force-pushed the utkarsh/feat/add-disk-cache-metrics branch 2 times, most recently from b58fed7 to a51abc8 Compare June 16, 2025 06:36
@tangledbytes
Copy link
Member Author

@coderabbitai review

Copy link

coderabbitai bot commented Jun 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>

missed committing config.js

Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>

fix stupid coderrabit AI suggestion

Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>

change ratio to percentage

Signed-off-by: Utkarsh Srivastava <srivastavautkarsh8097@gmail.com>
@tangledbytes tangledbytes force-pushed the utkarsh/feat/add-disk-cache-metrics branch from a51abc8 to 207cf6d Compare June 16, 2025 10:10
@@ -68,6 +79,21 @@ async function start_server(
if (!config.PROMETHEUS_ENABLED) {
return;
}

if (config.NSFS_GLACIER_METRICS_STATFS_PATH) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you move the internal logic to a function?

@romayalon
Copy link
Contributor

@tangledbytes A general question, since we can have buckets on different mounts/file systems, shouldn't we receive it as a parameter instead of setting a single path as a config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants