henry3260 opened a new pull request, #11197:
URL: https://github.com/apache/ozone/pull/11197
## 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.Status` is a
JAX-RS enum that
only lists common status codes, and `fromStatusCode()` returns `null` for
any code not in the
enum (e.g. 422, which the Prometheus HTTP API returns when a query
expression cannot be
executed). Calling `.getFamily()` on that `null` throws a
NullPointerException, so Recon
responds 500 with a stack trace instead of setting 502 and proxying the
Prometheus error body
back as intended.
This PR:
- Replaces the check with `Response.Status.Family.familyOf(code)`, which
classifies any status
code by its first digit and never returns null, in `MetricsProxyEndpoint`,
`PrometheusServiceProviderImpl`, and `JmxServiceProviderImpl`.
- Guards against `HttpURLConnection#getErrorStream()` returning `null` (per
its javadoc) in the
error path of `MetricsProxyEndpoint`, which previously caused a second NPE
in
`Channels.newChannel(null)` and in the `finally` close.
## 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 `TestEndpoints` suite, following the
mock pattern of
`testGetMetricsResponse`:
- `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 error
body; verifies no exception and a 502 response.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]