diff options
author | Amund Bergland Kvalsvik <akvalsvik@verizonmedia.com> | 2020-06-29 13:45:03 +0200 |
---|---|---|
committer | Amund Bergland Kvalsvik <akvalsvik@verizonmedia.com> | 2020-06-29 13:45:03 +0200 |
commit | 1eb53a6d6cb87750ece9dbb688cbaa9a48eee434 (patch) | |
tree | 070a78236f881bb9ba523b1d5aba8e14160e8448 /container-core | |
parent | c2fbfa9ebf866d9be5ec4826bab056b2f517f8a4 (diff) |
Fixed minor naming errors and throws
Diffstat (limited to 'container-core')
3 files changed, 16 insertions, 12 deletions
diff --git a/container-core/src/main/java/com/yahoo/container/handler/metrics/PrometheusV1Handler.java b/container-core/src/main/java/com/yahoo/container/handler/metrics/PrometheusV1Handler.java index 54207e5c640..23b7a62ffa3 100644 --- a/container-core/src/main/java/com/yahoo/container/handler/metrics/PrometheusV1Handler.java +++ b/container-core/src/main/java/com/yahoo/container/handler/metrics/PrometheusV1Handler.java @@ -15,7 +15,6 @@ import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.CloseableHttpClient; -import org.eclipse.jetty.server.Response; import static com.yahoo.container.handler.metrics.MetricsV2Handler.consumerQuery; import static com.yahoo.jdisc.Response.Status.INTERNAL_SERVER_ERROR; @@ -28,13 +27,13 @@ public class PrometheusV1Handler extends HttpHandlerBase{ private static final int HTTP_CONNECT_TIMEOUT = 5000; private static final int HTTP_SOCKET_TIMEOUT = 30000; - private final String prometheusProxyUri; + private final String metricsProxyUri; private final HttpClient httpClient = createHttpClient(); protected PrometheusV1Handler(Executor executor, MetricsProxyApiConfig config) { super(executor); - prometheusProxyUri = "http://localhost:" + config.metricsPort() + config.prometheusApiPath(); + metricsProxyUri = "http://localhost:" + config.metricsPort() + config.prometheusApiPath(); } @Override @@ -46,11 +45,11 @@ public class PrometheusV1Handler extends HttpHandlerBase{ private HttpResponse valuesResponse(String consumer) { try { - String uri = prometheusProxyUri + consumerQuery(consumer); + String uri = metricsProxyUri + consumerQuery(consumer); String prometheusText = httpClient.execute(new HttpGet(uri), new BasicResponseHandler()); return new StringResponse(prometheusText); } catch (IOException e) { - log.warning("Unable to retrieve metrics from " + prometheusProxyUri + ": " + Exceptions.toMessageString(e)); + log.warning("Unable to retrieve metrics from " + metricsProxyUri + ": " + Exceptions.toMessageString(e)); return new ErrorResponse(INTERNAL_SERVER_ERROR, e.getMessage()); } } diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java index 3f406368f68..9020ed91026 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/MetricsV2HandlerTest.java @@ -133,7 +133,7 @@ public class MetricsV2HandlerTest { } } - public static String getFileContents(String filename) { + static String getFileContents(String filename) { InputStream in = MetricsV2HandlerTest.class.getClassLoader().getResourceAsStream(filename); if (in == null) { throw new RuntimeException("File not found: " + filename); diff --git a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java index 4a94b4a1a7d..389c1e687cc 100644 --- a/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java +++ b/container-core/src/test/java/com/yahoo/container/handler/metrics/PrometheusV1HandlerTest.java @@ -26,6 +26,7 @@ import static com.yahoo.container.handler.metrics.MetricsV2Handler.consumerQuery import static com.yahoo.container.handler.metrics.MetricsV2HandlerTest.getFileContents; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * @author gjoranv @@ -76,7 +77,7 @@ public class PrometheusV1HandlerTest { } @Test - public void v2_response_contains_values_uri() throws Exception { + public void v1_response_contains_values_uri() throws Exception { String response = testDriver.sendRequest(V1_URI).readAll(); JSONObject root = new JSONObject(response); assertTrue(root.has("resources")); @@ -90,17 +91,21 @@ public class PrometheusV1HandlerTest { @Ignore @Test - public void visually_inspect_values_response() throws Exception { + public void visually_inspect_values_response() { String response = testDriver.sendRequest(VALUES_URI).readAll(); System.out.println(response); } @Test - public void invalid_path_yields_error_response() throws Exception { + public void invalid_path_yields_error_response() { String response = testDriver.sendRequest(V1_URI + "/invalid").readAll(); - JSONObject root = new JSONObject(response); - assertTrue(root.has("error")); - assertTrue(root.getString("error" ).startsWith("No content")); + try { + JSONObject root = new JSONObject(response); + assertTrue(root.has("error")); + assertTrue(root.getString("error" ).startsWith("No content")); + } catch (JSONException e) { + fail(); + } } @Test |