Copilot commented on code in PR #4792:
URL: https://github.com/apache/polaris/pull/4792#discussion_r3421111140
##########
runtime/service/src/test/java/org/apache/polaris/service/test/TestMetricsUtil.java:
##########
@@ -36,23 +37,25 @@
/** Utils for working with metrics in tests */
public class TestMetricsUtil {
- public static Map<String, MetricFamily> fetchMetrics(Client client, URI
baseManagementUri) {
- Response response =
client.target(baseManagementUri.resolve("q/metrics")).request().get();
- if (response.getStatus() == Status.MOVED_PERMANENTLY.getStatusCode()) {
- response = client.target(response.getLocation()).request().get();
+ public static Map<String, MetricFamily> fetchMetrics(URI baseManagementUri) {
+ try (Client client = ClientBuilder.newBuilder().build()) {
+ Response response =
client.target(baseManagementUri.resolve("q/metrics")).request().get();
+ if (response.getStatus() == Status.MOVED_PERMANENTLY.getStatusCode()) {
+ response = client.target(response.getLocation()).request().get();
+ }
Review Comment:
`fetchMetrics` doesn't close the `Response` (and also overwrites it on
redirects), which can leak HTTP connections during Awaitility polling and make
tests flaky. Use try-with-resources for the initial and redirected responses
and parse the body in a helper method.
--
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]