FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[fix][broker] Do not log an error when the tenant does not exist by codelipenghui · Pull Request #26361 · apache/pulsar · GitHub

/ pulsar Public

[fix][broker] Do not log an error when the tenant does not exist - #26361

Merged
poorbarcode merged 1 commit into
apache:masterfrom
codelipenghui:penghui/fix-tenant-not-exist-error-log
Aug 20, 2026
Merged

[fix][broker] Do not log an error when the tenant does not exist#26361
poorbarcode merged 1 commit into
apache:masterfrom
codelipenghui:penghui/fix-tenant-not-exist-error-log

Conversation

Copy link
Copy Markdown
Contributor

Motivation

PulsarAuthorizationProvider#validateTenantAdminAccess throws RestException(404, "Tenant does not exist") from inside thenCompose, and the exceptionally handler chained onto that same stage catches it. That handler only special-cases MetadataStoreException.NotFoundException, so the self-thrown 404 falls through to log.error("Failed to get tenant", cause).

Every request naming a tenant that does not exist therefore produces an ERROR line with a stack trace. A lookup is enough to trigger it, so a single misconfigured client pointed at a cluster that does not host its tenant can flood a healthy broker — roughly 1000 ERROR lines in 10 minutes from one client, on a broker with nothing wrong with it.

A tenant that does not exist is a client error, not a broker fault: any client can trigger it by mistyping a tenant name, and ServerCnx already reports the rejection at its own level.

MultiRolesTokenAuthorizationProvider overrides the method and carries an identical copy of the bug.

Modifications

  • Move the exceptionally handler onto getTenantAsync(), the stage that can actually fail, and perform the presence check after it. The "tenant does not exist" rejection then has no error handler downstream.
  • Map MetadataStoreException.NotFoundException to an empty Optional so both "tenant is missing" paths converge on the same 404.
  • Use FutureUtil.unwrapCompletionException instead of ex.getCause(). Attached directly to getTenantAsync(), the exception is no longer wrapped in a CompletionException.
  • Apply the same change to MultiRolesTokenAuthorizationProvider.

Genuine metadata store failures are still logged at ERROR. Client-visible behaviour is unchanged: the previous code rethrew new RestException(cause), which preserved the 404 response, so the status, message and ErrorData entity are identical.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • Added PulsarAuthorizationProviderTest with three tests: one on validateTenantAdminAccess, one on allowTopicOperationAsync with TopicOperation.LOOKUP (the path an actual lookup takes), and one asserting that a metadata store failure is still logged at ERROR, which guards the fix from over-reaching.
  • Added an equivalent test to MultiRolesTokenAuthorizationProviderTest.
  • Added LogCapture, a Log4j2 appender that captures a single logger's events so the tests can assert on the level a condition is reported at.
  • With the production change reverted, the three "must not be logged at ERROR" tests fail and the metadata-store-failure test still passes.

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

codelipenghui self-assigned this Aug 17, 2026
codelipenghui added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages release/4.2.5 release/4.0.14 labels Aug 17, 2026
codelipenghui added this to the 5.0.0-M2 milestone Aug 17, 2026
codelipenghui requested a balanced review from Copilot August 17, 2026 22:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Prevents missing-tenant authorization requests from producing erroneous broker ERROR logs while preserving 404 responses and genuine metadata-failure logging.

Changes:

  • Limits metadata error handling to tenant retrieval stages.
  • Applies equivalent behavior to both authorization providers.
  • Adds focused logging and authorization tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
PulsarAuthorizationProvider.java Separates missing-tenant rejection from metadata error logging.
MultiRolesTokenAuthorizationProvider.java Applies the same correction for multi-role tokens.
PulsarAuthorizationProviderTest.java Tests 404 behavior and logging levels.
MultiRolesTokenAuthorizationProviderTest.java Tests missing-tenant handling for multi-role authorization.
LogCapture.java Provides scoped Log4j2 event capture for tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

poorbarcode merged commit a25ae29 into apache:master Aug 20, 2026
44 checks passed
codelipenghui deleted the penghui/fix-tenant-not-exist-error-log branch August 21, 2026 02:21
Technoboy- pushed a commit that referenced this pull request Aug 26, 2026
Technoboy- pushed a commit that referenced this pull request Aug 26, 2026
nodece pushed a commit to ascentstream/pulsar that referenced this pull request Aug 28, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/branch-4.0 cherry-picked/branch-4.2 release/4.0.14 release/4.2.5 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL