[
https://issues.apache.org/jira/browse/HDDS-16379?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated HDDS-16379:
----------------------------------
Labels: pull-request-available (was: )
> Recon returns 500 NPE instead of proxying error when metrics endpoint
> responds with a non-enum status code (e.g. Prometheus 422)
> --------------------------------------------------------------------------------------------------------------------------------
>
> Key: HDDS-16379
> URL: https://issues.apache.org/jira/browse/HDDS-16379
> Project: Apache Ozone
> Issue Type: Bug
> Components: Ozone Recon
> Reporter: Henry Chen
> Assignee: Henry Chen
> Priority: Major
> Labels: pull-request-available
>
> Recon's metrics proxy and metrics service providers check the upstream HTTP
> status like this:
> {code:java}
> if (Response.Status.fromStatusCode(connection.getResponseCode())
> .getFamily() == Response.Status.Family.SUCCESSFUL) {
> {code}
> {\{Response.Status}} is a JAX-RS enum that only lists common status codes, and
> {\{fromStatusCode()}} returns *null* for any code not in the enum. The
> jakarta.ws.rs-api 2.1.6 used by Ozone has no 422 entry, while the Prometheus
> HTTP API returns *422 Unprocessable Entity* when a query expression cannot be
> executed (e.g. a syntax error).
> *Reproduce:* with Prometheus configured, call
> {\{GET /api/v1/metrics/query?query=<invalid expression>}} on Recon.
> {\{fromStatusCode(422)}} returns null, \{{.getFamily()}} throws
> NullPointerException, and Recon responds 500 with a stack trace instead of
> setting 502 and proxying the Prometheus error body back as intended.
> *Affected locations (same pattern):*
> - MetricsProxyEndpoint#getMetricsResponse
> - PrometheusServiceProviderImpl#getMetrics
> - JmxServiceProviderImpl (same check; harder to trigger since JMX returns
> standard codes)
> *Proposed fix:*
> # Replace the check with
> \{{Response.Status.Family.familyOf(connection.getResponseCode())}}, which
> classifies by the first digit and never returns null.
> # In the error path of MetricsProxyEndpoint, guard against
> \{{connection.getErrorStream()}} returning null (per HttpURLConnection
> javadoc), which currently causes a second NPE in
> \{{Channels.newChannel(inputStream)}} and again in \{{finally {
> inputStream.close(); }}}.
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]