This is an automated email from the ASF dual-hosted git repository.

hong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new b2231dac38a [FLINK-37601] Remove Unirest dependency in 
PrometheusReporterTest (#26387)
b2231dac38a is described below

commit b2231dac38aaf6c4e6fa6e000502b2e7ede92aea
Author: r-sidd <[email protected]>
AuthorDate: Mon Apr 7 21:50:21 2025 +0530

    [FLINK-37601] Remove Unirest dependency in PrometheusReporterTest (#26387)
    
    
    * [FLINK-37601] remove Unirest dependency and use default HTTP library
---
 flink-metrics/flink-metrics-prometheus/pom.xml     |  6 ----
 .../PrometheusReporterTaskScopeTest.java           |  7 ++--
 .../metrics/prometheus/PrometheusReporterTest.java | 42 +++++++++++++---------
 3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/flink-metrics/flink-metrics-prometheus/pom.xml 
b/flink-metrics/flink-metrics-prometheus/pom.xml
index 2cfda44ddd5..d273638aa6b 100644
--- a/flink-metrics/flink-metrics-prometheus/pom.xml
+++ b/flink-metrics/flink-metrics-prometheus/pom.xml
@@ -100,12 +100,6 @@ under the License.
                        <artifactId>flink-test-utils-junit</artifactId>
                </dependency>
 
-               <dependency>
-                       <groupId>com.mashape.unirest</groupId>
-                       <artifactId>unirest-java</artifactId>
-                       <version>1.4.9</version>
-                       <scope>test</scope>
-               </dependency>
        </dependencies>
 
        <build>
diff --git 
a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTaskScopeTest.java
 
b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTaskScopeTest.java
index bb5b0f3556a..354d0b9ebd8 100644
--- 
a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTaskScopeTest.java
+++ 
b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTaskScopeTest.java
@@ -27,11 +27,11 @@ import org.apache.flink.metrics.util.TestHistogram;
 import org.apache.flink.metrics.util.TestMeter;
 import org.apache.flink.util.PortRange;
 
-import com.mashape.unirest.http.exceptions.UnirestException;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
 import java.util.Arrays;
 
 import static 
org.apache.flink.metrics.prometheus.PrometheusReporterTest.pollMetrics;
@@ -126,7 +126,8 @@ class PrometheusReporterTaskScopeTest {
     }
 
     @Test
-    void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels() throws 
UnirestException {
+    void histogramsCanBeAddedSeveralTimesIfTheyDifferInLabels()
+            throws IOException, InterruptedException {
         TestHistogram histogram1 = new TestHistogram();
         histogram1.setCount(1);
         TestHistogram histogram2 = new TestHistogram();
@@ -135,7 +136,7 @@ class PrometheusReporterTaskScopeTest {
         reporter.notifyOfAddedMetric(histogram1, METRIC_NAME, metricGroup1);
         reporter.notifyOfAddedMetric(histogram2, METRIC_NAME, metricGroup2);
 
-        final String exportedMetrics = 
pollMetrics(reporter.getPort()).getBody();
+        final String exportedMetrics = pollMetrics(reporter.getPort()).body();
         assertThat(exportedMetrics).contains("label2=\"value1_2\",} 1.0");
         assertThat(exportedMetrics).contains("label2=\"value2_2\",} 2.0");
 
diff --git 
a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
 
b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
index 4c8da70a10f..8491dc0b834 100644
--- 
a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
+++ 
b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
@@ -29,13 +29,15 @@ import org.apache.flink.metrics.util.TestHistogram;
 import org.apache.flink.metrics.util.TestMeter;
 import org.apache.flink.util.PortRange;
 
-import com.mashape.unirest.http.HttpResponse;
-import com.mashape.unirest.http.Unirest;
-import com.mashape.unirest.http.exceptions.UnirestException;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
@@ -58,6 +60,7 @@ class PrometheusReporterTest {
     private static final String DEFAULT_LABELS = "{" + DIMENSIONS + ",}";
     private static final String SCOPE_PREFIX =
             PrometheusReporter.SCOPE_PREFIX + LOGICAL_SCOPE + 
PrometheusReporter.SCOPE_SEPARATOR;
+    private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient();
 
     private static final PortRangeProvider portRangeProvider = new 
PortRangeProvider();
 
@@ -85,10 +88,11 @@ class PrometheusReporterTest {
      * {@link io.prometheus.client.Counter} may not decrease, so report {@link 
Counter} as {@link
      * io.prometheus.client.Gauge}.
      *
-     * @throws UnirestException Might be thrown on HTTP problems.
+     * @throws IOException Might be thrown on I/O problems.
+     * @throws InterruptedException Might be thrown if the thread is 
interrupted.
      */
     @Test
-    void counterIsReportedAsPrometheusGauge() throws UnirestException {
+    void counterIsReportedAsPrometheusGauge() throws IOException, 
InterruptedException {
         Counter testCounter = new SimpleCounter();
         testCounter.inc(7);
 
@@ -96,34 +100,34 @@ class PrometheusReporterTest {
     }
 
     @Test
-    void gaugeIsReportedAsPrometheusGauge() throws UnirestException {
+    void gaugeIsReportedAsPrometheusGauge() throws IOException, 
InterruptedException {
         Gauge<Integer> testGauge = () -> 1;
 
         assertThatGaugeIsExported(testGauge, "testGauge", "1.0");
     }
 
     @Test
-    void nullGaugeDoesNotBreakReporter() throws UnirestException {
+    void nullGaugeDoesNotBreakReporter() throws IOException, 
InterruptedException {
         Gauge<Integer> testGauge = () -> null;
 
         assertThatGaugeIsExported(testGauge, "testGauge", "0.0");
     }
 
     @Test
-    void meterRateIsReportedAsPrometheusGauge() throws UnirestException {
+    void meterRateIsReportedAsPrometheusGauge() throws IOException, 
InterruptedException {
         Meter testMeter = new TestMeter();
 
         assertThatGaugeIsExported(testMeter, "testMeter", "5.0");
     }
 
     private void assertThatGaugeIsExported(Metric metric, String name, String 
expectedValue)
-            throws UnirestException {
+            throws IOException, InterruptedException {
         assertThat(addMetricAndPollResponse(metric, name))
                 .contains(createExpectedPollResponse(name, "", "gauge", 
expectedValue));
     }
 
     @Test
-    void histogramIsReportedAsPrometheusSummary() throws UnirestException {
+    void histogramIsReportedAsPrometheusSummary() throws IOException, 
InterruptedException {
         Histogram testHistogram = new TestHistogram();
 
         String histogramName = "testHistogram";
@@ -152,7 +156,8 @@ class PrometheusReporterTest {
      * name still exist.
      */
     @Test
-    void metricIsRemovedWhileOtherMetricsWithSameNameExist() throws 
UnirestException {
+    void metricIsRemovedWhileOtherMetricsWithSameNameExist()
+            throws IOException, InterruptedException {
         String metricName = "metric";
 
         Counter metric1 = new SimpleCounter();
@@ -168,7 +173,7 @@ class PrometheusReporterTest {
         reporter.notifyOfAddedMetric(metric2, metricName, metricGroup2);
         reporter.notifyOfRemovedMetric(metric1, metricName, metricGroup);
 
-        String response = pollMetrics(reporter.getPort()).getBody();
+        String response = pollMetrics(reporter.getPort()).body();
 
         
assertThat(response).contains("some_value").doesNotContain(labelValueThatShouldBeRemoved);
     }
@@ -239,13 +244,18 @@ class PrometheusReporterTest {
     }
 
     private String addMetricAndPollResponse(Metric metric, String metricName)
-            throws UnirestException {
+            throws IOException, InterruptedException {
         reporter.notifyOfAddedMetric(metric, metricName, metricGroup);
-        return pollMetrics(reporter.getPort()).getBody();
+        return pollMetrics(reporter.getPort()).body();
     }
 
-    static HttpResponse<String> pollMetrics(int port) throws UnirestException {
-        return Unirest.get("http://localhost:"; + port + "/metrics").asString();
+    static HttpResponse<String> pollMetrics(int port) throws IOException, 
InterruptedException {
+        HttpRequest request =
+                HttpRequest.newBuilder()
+                        .uri(URI.create("http://localhost:"; + port + 
"/metrics"))
+                        .GET()
+                        .build();
+        return HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
     }
 
     private static String createExpectedPollResponse(

Reply via email to