Skip to content

Conversation

@aayushchouhan09
Copy link
Member

@aayushchouhan09 aayushchouhan09 commented Sep 3, 2025

Describe the Problem

Currently, we have not exposed any metrics to show current object, max objects and max size set for bucket in quota.

Explain the Changes

  1. We have added metrics - bucket_object_count, bucket_max_objects_quota and bucket_max_bytes_quota.
Screenshot from 2025-09-16 15-05-41

Issues: Fixed #xxx / Gap #xxx

  1. Fixed: https://issues.redhat.com/browse/RHSTOR-6943

Testing Instructions:

  1. Run below commands, and verify the implemented metrics after setting quota in the bucket:

$ JWT_TOKEN=$(kubectl get secret/noobaa-metrics-auth-secret -o jsonpath={.data.metrics_token} | base64 -d)
$ kubectl exec -it noobaa-core-0 -- curl -k -H "Authorization: Bearer ${JWT_TOKEN}" http://localhost:8080/metrics/web_server | grep -E 'bucket_object_count|quota'

  • Doc added/updated
  • Tests added

Summary by CodeRabbit

  • New Features
    • Added per-bucket Prometheus metrics for object count and quota limits (max objects, max bytes) and ensured they are reset and updated per-bucket.
    • Bucket statistics now include object_count plus quota limit fields (max objects, max bytes) in addition to existing usage percentages.

@coderabbitai
Copy link

coderabbitai bot commented Sep 3, 2025

Walkthrough

Adds per-bucket object count and quota limit metrics to Prometheus reporting and surfaces quota caps and object counts in bucket stats via a new helper in stats_aggregator; Prometheus gauges are reset and set per-bucket for these new fields.

Changes

Cohort / File(s) Summary
Prometheus Report Metrics
src/server/analytic_services/prometheus_reports/noobaa_core_report.js
Added three Gauge metrics: bucket_object_count, bucket_max_objects_quota, and bucket_max_bytes_quota (label: bucket_name). Updated set_bucket_status to reset these gauges and set them per-bucket from `bucket_info.object_count
Stats Aggregator Quota Helper & Payload
src/server/system_services/stats_aggregator.js
Added private helper _get_bucket_quota_info(bucket) returning { size_used_percent, quantity_used_percent, quota_max_objects, quota_max_bytes }. Replaced direct Quota usage with this helper. Extended _partial_buckets_info to include quota_max_objects, quota_max_bytes, and object_count (from `bucket_info.num_objects.value

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant SA as StatsAggregator
  participant QH as _get_bucket_quota_info
  participant PR as PrometheusReport

  rect rgba(230,245,255,0.6)
  note over SA,QH: Compute quota usage percentages and caps
  SA->>QH: request quota usages & caps (bucket)
  QH-->>SA: size_used%, quantity_used%, quota_max_bytes, quota_max_objects
  SA-->>SA: include quota_max_* and object_count in bucket payload
  end

  rect rgba(235,255,235,0.6)
  note over PR: Reset and set per-bucket Prometheus gauges
  PR->>PR: reset bucket_object_count, bucket_max_objects_quota, bucket_max_bytes_quota
  PR->>PR: set bucket_object_count[bucket_name] = object_count
  PR->>PR: set bucket_max_objects_quota[bucket_name] = quota_max_objects
  PR->>PR: set bucket_max_bytes_quota[bucket_name] = quota_max_bytes
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • liranmauda
  • tangledbytes
  • naveenpaul1

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Added metrics - object count, max_objects and max_size for quota" concisely and accurately summarizes the primary change: adding per-bucket metrics for object counts and quota limits, which matches the added metrics in the changeset. It is specific, focused, and avoids vague phrasing or noise, so a reviewer scanning history will understand the main intent of the PR.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94d3da8 and 0e4f273.

📒 Files selected for processing (2)
  • src/server/analytic_services/prometheus_reports/noobaa_core_report.js (3 hunks)
  • src/server/system_services/stats_aggregator.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/server/analytic_services/prometheus_reports/noobaa_core_report.js
  • src/server/system_services/stats_aggregator.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Noobaa Image
  • GitHub Check: run-package-lock-validation
  • GitHub Check: run-jest-unit-tests

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

@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: 0

🧹 Nitpick comments (3)
src/server/system_services/stats_aggregator.js (2)

421-433: Deduplicate quota getter calls; keep numeric conversion explicit and cheap.

Avoid calling get_quota_by_size/quantity twice and prefer a single parse step. Functionality unchanged, a bit cleaner and marginally faster.

-    const { size_used_percent, quantity_used_percent } = quota.get_bucket_quota_usages_percent(bucket);
-    const quota_max_objects = quota.get_quota_by_quantity() === '0' ? 0 : parseInt(quota.get_quota_by_quantity(), 10);
-    const quota_max_bytes = quota.get_quota_by_size() === '0' ? 0 : size_utils.json_to_bigint(quota.get_quota_by_size()).toJSNumber();
+    const { size_used_percent, quantity_used_percent } = quota.get_bucket_quota_usages_percent(bucket);
+    const quantity_raw = quota.get_quota_by_quantity();
+    const size_raw = quota.get_quota_by_size();
+    const quota_max_objects = quantity_raw === '0' ? 0 : Number(quantity_raw);
+    const quota_max_bytes = size_raw === '0' ? 0 : size_utils.json_to_bigint(size_raw).toJSNumber();

530-543: Make bucket_used_bytes conversion explicit (and resilient).

valueOf() relies on implicit coercion. Use toJSNumber() for consistency with the rest of this file and guard if storage_stats is missing.

-                bucket_used_bytes: bucket_used.valueOf(),
+                bucket_used_bytes: bucket_used ? bucket_used.toJSNumber() : 0,
src/server/analytic_services/prometheus_reports/noobaa_core_report.js (1)

311-325: Clarify metric help strings (units and unlimited semantics).

Make it obvious that 0 means “unlimited”, and specify units for bytes.

-        configuration: {
-            help: 'Bucket Maximum Objects Quota',
+        configuration: {
+            help: 'Bucket Maximum Objects Quota (0 = unlimited)',
             labelNames: ['bucket_name']
         }
     }, {
         type: 'Gauge',
         name: 'bucket_max_bytes_quota',
         configuration: {
-            help: 'Bucket Maximum Bytes Quota',
+            help: 'Bucket Maximum Bytes Quota (bytes; 0 = unlimited)',
             labelNames: ['bucket_name']
         }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4071d5d and 1a4750f.

📒 Files selected for processing (2)
  • src/server/analytic_services/prometheus_reports/noobaa_core_report.js (3 hunks)
  • src/server/system_services/stats_aggregator.js (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/server/analytic_services/prometheus_reports/noobaa_core_report.js (1)
src/server/system_services/stats_aggregator.js (1)
  • bucket_info (461-461)
src/server/system_services/stats_aggregator.js (1)
src/server/system_services/bucket_server.js (23)
  • bucket (343-343)
  • bucket (357-357)
  • bucket (376-376)
  • bucket (394-394)
  • bucket (419-419)
  • bucket (431-431)
  • bucket (446-446)
  • bucket (482-482)
  • bucket (491-491)
  • bucket (504-504)
  • bucket (513-513)
  • bucket (539-539)
  • bucket (558-558)
  • bucket (572-572)
  • bucket (590-590)
  • bucket (604-604)
  • quota (753-753)
  • quota (862-862)
  • quota (1617-1617)
  • quota (1676-1676)
  • Quota (39-39)
  • size_utils (21-21)
  • bucket_used (1651-1651)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build Noobaa Image
  • GitHub Check: run-jest-unit-tests
  • GitHub Check: run-package-lock-validation
🔇 Additional comments (2)
src/server/analytic_services/prometheus_reports/noobaa_core_report.js (2)

580-582: Resetting new gauges is correct.

Ensures no stale series remain between scrapes. LGTM.


593-595: Use nullish coalescing for quota defaults

Replace || 0 with ?? 0 so only null/undefined fall back, not all falsy values:

-    this._metrics.bucket_max_objects_quota.set({ bucket_name: bucket_info.bucket_name }, bucket_info.quota_max_objects || 0);
-    this._metrics.bucket_max_bytes_quota.set({ bucket_name: bucket_info.bucket_name }, bucket_info.quota_max_bytes || 0);
+    this._metrics.bucket_max_objects_quota.set({ bucket_name: bucket_info.bucket_name }, bucket_info.quota_max_objects ?? 0);
+    this._metrics.bucket_max_bytes_quota.set({ bucket_name: bucket_info.bucket_name }, bucket_info.quota_max_bytes ?? 0);

Please verify these gauges are exposed correctly at runtime.

@aayushchouhan09 aayushchouhan09 requested review from a team and tangledbytes and removed request for a team September 3, 2025 10:56
…t_max_size_quota for quota

Signed-off-by: Aayush Chouhan <[email protected]>
@aayushchouhan09 aayushchouhan09 changed the title Added metrics max_objects and max_size for quota Added metrics - object count, max_objects and max_size for quota Sep 16, 2025
@aayushchouhan09 aayushchouhan09 merged commit b4e2f4d into noobaa:master Sep 16, 2025
18 of 19 checks passed
@aayushchouhan09 aayushchouhan09 deleted the quota-met branch September 18, 2025 07:56
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