RockteMQ-AI commented on code in PR #1252:
URL:
https://github.com/apache/rocketmq-dashboard/pull/1252#discussion_r3736926799
##########
server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java:
##########
@@ -97,11 +97,24 @@ public MetricDataVO query(MetricQueryDTO query) {
.headers(this::applyAuthentication)
.body(form)
.exchange((request, clientResponse) -> {
- JsonNode body =
objectMapper.readTree(readResponseBody(clientResponse.getBody()));
+ byte[] rawBody =
readResponseBody(clientResponse.getBody());
+ int upstreamStatus =
responseStatus(clientResponse.getStatusCode());
if (clientResponse.getStatusCode().isError()) {
- throw responseBodyException(body,
responseStatus(clientResponse.getStatusCode()));
+ // Check the status before parsing so a non-JSON
error body (e.g. a proxy
+ // HTML/plain-text page) is not misreported as a
connection failure.
+ try {
+ throw
responseBodyException(objectMapper.readTree(rawBody), upstreamStatus);
+ } catch (IOException nonJsonBody) {
Review Comment:
Consider chaining the `nonJsonBody` exception as the cause in the
`PrometheusException` constructor (there is a 3-arg overload:
`PrometheusException(int, String, Throwable)`). This preserves the original
parse error in the stack trace, which can help when debugging unexpected
upstream responses.
##########
server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java:
##########
@@ -97,11 +97,24 @@ public MetricDataVO query(MetricQueryDTO query) {
.headers(this::applyAuthentication)
.body(form)
.exchange((request, clientResponse) -> {
- JsonNode body =
objectMapper.readTree(readResponseBody(clientResponse.getBody()));
+ byte[] rawBody =
readResponseBody(clientResponse.getBody());
+ int upstreamStatus =
responseStatus(clientResponse.getStatusCode());
if (clientResponse.getStatusCode().isError()) {
- throw responseBodyException(body,
responseStatus(clientResponse.getStatusCode()));
+ // Check the status before parsing so a non-JSON
error body (e.g. a proxy
+ // HTML/plain-text page) is not misreported as a
connection failure.
+ try {
+ throw
responseBodyException(objectMapper.readTree(rawBody), upstreamStatus);
+ } catch (IOException nonJsonBody) {
+ throw new PrometheusException(upstreamStatus,
+ backendLabel() + " query failed (HTTP
" + upstreamStatus + ")");
+ }
+ }
+ try {
+ return objectMapper.readTree(rawBody);
Review Comment:
Minor: including the first ~100 chars of `rawBody` in the error message
(e.g. truncated response preview) could speed up debugging when the upstream
returns an unexpected format. Not blocking.
--
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]