HDDS-16379. Recon returns 500 NPE instead of proxying error when metrics endpoint responds with a non-enum status code - #11197
Open
henry3260 wants to merge 1 commit into
Open
HDDS-16379. Recon returns 500 NPE instead of proxying error when metrics endpoint responds with a non-enum status code#11197henry3260 wants to merge 1 commit into
henry3260 wants to merge 1 commit into
Conversation
…ics endpoint responds with a non-enum status code
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped to robust HTTP status/error-stream handling and is covered by targeted regression unit tests for the reported failure modes.
Pull request overview
This PR fixes an error-handling bug in Recon’s metrics proxy/service providers where certain upstream HTTP status codes (eg, 422 from the Prometheus API) could trigger a NullPointerException, causing Recon to return a 500 instead of a 502 while proxying the upstream error body.
Changes:
- Replace
Response.Status.fromStatusCode(code).getFamily()withResponse.Status.Family.familyOf(code)to correctly classify non-enum HTTP status codes without returning null. - Add a null-guard for
HttpURLConnection#getErrorStream()inMetricsProxyEndpointto avoid NPEs when the upstream returns an error with no body. - Add unit tests in
TestEndpointscovering both non-enum status codes with an error body and error responses with a null error stream.
File summaries
| File | Description |
|---|---|
| hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/api/MetricsProxyEndpoint.java | Makes status-family checks null-safe for non-enum codes and avoids NPEs when error bodies are missing. |
| hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/PrometheusServiceProviderImpl.java | Uses status-family classification that works for any valid HTTP status code. |
| hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/JmxServiceProviderImpl.java | Uses status-family classification that works for any valid HTTP status code. |
| hadoop-ozone/recon/src/test/java/org/apache/hadoop/ozone/recon/api/TestEndpoints.java | Adds regression tests for the prior NPE path and for null error bodies. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
chihsuan
approved these changes
Sep 3, 2026
chihsuan
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the patch! +1 LGTM
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Recon's metrics proxy and metrics service providers checked the upstream HTTP status with
Response.Status.fromStatusCode(code).getFamily().Response.Statusis a JAX-RS enum thatonly lists common status codes, and
fromStatusCode()returnsnullfor any code not in theenum (e.g. 422, which the Prometheus HTTP API returns when a query expression cannot be
executed). Calling
.getFamily()on thatnullthrows a NullPointerException, so Reconresponds 500 with a stack trace instead of setting 502 and proxying the Prometheus error body
back as intended.
This PR:
Response.Status.Family.familyOf(code), which classifies any statuscode by its first digit and never returns null, in
MetricsProxyEndpoint,PrometheusServiceProviderImpl, andJmxServiceProviderImpl.HttpURLConnection#getErrorStream()returningnull(per its javadoc) in theerror path of
MetricsProxyEndpoint, which previously caused a second NPE inChannels.newChannel(null)and in thefinallyclose.What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-16379
How was this patch tested?
Added two unit tests to the existing
TestEndpointssuite, following the mock pattern oftestGetMetricsResponse:testGetMetricsResponseWithNonEnumStatusCode: upstream returns 422 with an error body;verifies Recon sets 502 and proxies the body back (the path that previously threw NPE).
testGetMetricsResponseWithNullErrorStream: upstream returns an error status with no errorbody; verifies no exception and a 502 response.