Skip to content

Return empty metrics list instead of 404 for known brokers - #1959

Open
alilxxey wants to merge 1 commit into
kafbat:mainfrom
alilxxey:bugfix/broker_metrics_empty_404
Open

alilxxey wants to merge 1 commit into
kafbat:mainfrom
alilxxey:bugfix/broker_metrics_empty_404

Conversation

@alilxxey

@alilxxey alilxxey commented Aug 24, 2026

Copy link
Copy Markdown
  • Breaking change? (if so, please describe the impact and migration path for existing application instances)

What changes did you make? (Give an overview)

Resolves #1958 and #1942

GET /api/clusters/{clusterName}/brokers/{id}/metrics returned 404 for every broker when the cluster has no metrics section configured (and for brokers whose scrape yielded nothing), which crashes the frontend Metrics tab into a blank page (useSuspenseQuery throws, the Brokers route has no error boundary). This is a regression from the metrics rework #1208: up to v1.3.0 MetricsCollector kept an entry per live node (empty list when nothing was collected), so the endpoint returned 200 {"metrics":[]}.

This PR restores those semantics at the service layer:

No frontend changes needed: with a valid 200 response the Metrics tab renders the JSON as before.

Is there anything you'd like reviewers to focus on?

The chosen semantics: 404 is now reserved for unknown broker ids; a known broker always gets 200 with whatever has been scraped (possibly empty). An alternative was to populate per-node empty entries in MetricsScraper#scrapeBrokers, but the service-layer guard also covers scrape gaps for configured clusters.

How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)

  • No need to
  • Manually (please, describe, if necessary)
  • Unit checks
  • Integration checks
  • Covered by existing automation

Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. ENVIRONMENT VARIABLES)
  • My changes generate no new warnings (e.g. Sonar is happy)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Check out Contributing and Code of Conduct

Summary by CodeRabbit

  • Bug Fixes

    • Broker metrics requests now clearly report when the selected broker does not exist.
    • Metrics for valid brokers continue to load, including when no metrics are available.
  • Tests

    • Added coverage for available metrics, empty results, and unknown broker requests.

@alilxxey
alilxxey requested a review from a team as a code owner August 24, 2026 15:35
@kapybro kapybro Bot added status/triage/manual Manual triage in progress and removed status/triage/manual Manual triage in progress labels Aug 24, 2026
@kapybro

kapybro Bot commented Aug 24, 2026

Copy link
Copy Markdown

AI Summary

The metrics endpoint incorrectly returns a 404 for valid brokers without configured metrics or collected data, causing frontend crashes. This PR resolves the issue by returning a 200 status code with an empty metrics list for known brokers, while reserving 404 responses strictly for unknown broker IDs.

@kapybro kapybro Bot changed the title BE: Return empty metrics list instead of 404 for known brokers withou… Return empty metrics list instead of 404 for known brokers Aug 24, 2026
@kapybro kapybro Bot added area/brokers Broker / broker configs related issues scope/backend Related to backend changes type/regression Something that has been previously fixed but got broken again labels Aug 24, 2026
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8be99df7-e835-4f9d-a1d4-fde2ecdc331a

📥 Commits

Reviewing files that changed from the base of the PR and between d91acc2 and 80b1bd4.

📒 Files selected for processing (2)
  • api/src/main/java/io/kafbat/ui/service/BrokerService.java
  • api/src/test/java/io/kafbat/ui/service/BrokerServiceMetricsTest.java

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


📝 Walkthrough

Walkthrough

getBrokerMetrics now validates broker existence before retrieving metrics. Existing brokers return scraped metrics or an empty list. Unit tests cover empty results, successful retrieval, and unknown broker errors.

Changes

Broker metrics retrieval

Layer / File(s) Summary
Metrics validation and retrieval tests
api/src/main/java/io/kafbat/ui/service/BrokerService.java, api/src/test/java/io/kafbat/ui/service/BrokerServiceMetricsTest.java
getBrokerMetrics validates cluster membership, returns NotFoundException for unknown brokers, and returns an empty list for existing brokers without metrics. Tests cover all three outcomes.

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

Merge Risk: ⚪ Minimal · up to 80b1b

This localized change makes known brokers return an empty metrics list instead of 404 while preserving 404 responses for unknown brokers; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: alexeyzavyalov

Poem

I’m a rabbit checking brokers tonight,
Empty metrics now render just right.
Unknown ones get a clear 404,
Scraped results pass through the door.
Hop, hop—the tests shine bright!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation returns empty metrics for existing brokers, preserves 404 for unknown brokers, and adds relevant unit coverage for issue #1958.
Out of Scope Changes check ✅ Passed The changes are limited to broker metrics behavior and targeted unit tests, with no unrelated modifications.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main behavior change: known brokers now return an empty metrics list instead of a 404 response.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi alilxxey! 👋

Welcome, and thank you for opening your first PR in the repo!

Please wait for triaging by our maintainers.

Please take a look at our contributing guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/brokers Broker / broker configs related issues scope/backend Related to backend changes type/regression Something that has been previously fixed but got broken again

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broker Metrics tab crashes with blank page when metrics are not configured

1 participant