dongjoon-hyun opened a new pull request, #947:
URL: https://github.com/apache/spark-kubernetes-operator/pull/947

   ### What changes were proposed in this pull request?
   
   This PR aims to fix two robustness bugs of `KubernetesMetricsInterceptor`.
   
   - `parseNamespaceScopedResource` returns `Optional.empty()` unless the 
request path has `namespaces/<namespace>/<resource>` segments. It matches the 
`namespaces` path segment instead of the first `namespaces` substring.
   - `updateResponseMetrics` marks a response code group meter, `1xx` to `5xx`, 
only when the response code belongs to one of them.
   
   ### Why are the changes needed?
   
   `parseNamespaceScopedResource` assumes that `<namespace>/<resource>` always 
follows the first `namespaces` substring of the path. It throws for the 
following paths.
   
   | Path | Request | Exception |
   | --- | --- | --- |
   | `/api/v1/namespaces` | List or watch of namespaces | 
`StringIndexOutOfBoundsException` |
   | `/api/v1/namespaces/spark-system` | Get of a namespace | 
`ArrayIndexOutOfBoundsException` |
   | `/apis/rbac.authorization.k8s.io/v1/clusterroles/namespaces-reader` | Get 
of a cluster-scoped resource whose name contains `namespaces` | 
`ArrayIndexOutOfBoundsException` |
   
   Since fabric8 7.8.0 `StandardHttpClient` calls `Interceptor.before(...)` 
synchronously, the exception fails the request itself before it is sent, e.g. 
`client.namespaces().list()` throws `StringIndexOutOfBoundsException`. The 
operator does not call these APIs today, so this bug is latent.
   
   `updateResponseMetrics` uses `response.code() / 100 - 1` as the index of the 
group meters. Netty accepts any non-negative status code, e.g. `HTTP/1.1 999` 
from a proxy, and fabric8 passes it to `Interceptor.after(...)`. For a code 
outside of `100` to `599`, `responseCodeGroupMeters.get(...)` throws 
`IndexOutOfBoundsException` on the Vert.x event loop. fabric8 calls 
`after(...)` of all interceptors in one loop of a `thenAccept` callback whose 
future it drops, so the exception silently skips `after(...)` of the 
interceptors registered after this one.
   
   Both bugs exist in the latest release.
   - https://github.com/apache/spark-kubernetes-operator/releases/tag/1.0.0 
(2026-07-26)
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. The metrics of the requests which the operator sends are unchanged. For 
a response code outside of `100` to `599`, `kubernetes.client.http.response` 
and `kubernetes.client.http.response.<code>` are recorded as before, without 
the exception.
   
   ### How was this patch tested?
   
   Pass the CIs with the newly added test cases. Without this fix, 
`testParseNamespaceScopedResource` fails with `StringIndexOutOfBoundsException` 
and `testResponseCodeGroups` fails with `IndexOutOfBoundsException`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5


-- 
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]

Reply via email to