diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetrics.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetrics.java index 64d32951..adbba4af 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetrics.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetrics.java @@ -81,7 +81,8 @@ public static String getCurrentTimeMetric() { } public static String generatePath(long startTime, String... keysPath) { - Path sDevShmLocationPath = Paths.get(sDevShmLocation).resolve(Paths.get(String.valueOf(PerformanceAnalyzerMetrics.getTimeInterval(startTime)), keysPath)); + Path sDevShmLocationPath = Paths.get(sDevShmLocation) + .resolve(Paths.get(String.valueOf(PerformanceAnalyzerMetrics.getTimeInterval(startTime)), keysPath)); return sDevShmLocationPath.toString(); } @@ -163,7 +164,7 @@ private static File writeToTmp(String keyPath, String value) throws Exception { } public static String getMetric(long startTime, String... keysPath) { - return getMetric(generatePath(startTime, keysPath)); + return getMetric(generatePath(startTime, keysPath)); } public static String getMetric(String keyPath) { diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java index f4be281c..87972940 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/rest/QueryMetricsRequestHandler.java @@ -29,17 +29,16 @@ import java.util.Map; import java.util.Set; -import javax.net.ssl.HttpsURLConnection; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.util.Supplier; - import org.jooq.Record; import org.jooq.Result; import com.amazon.opendistro.elasticsearch.performanceanalyzer.PerformanceAnalyzerApp; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PluginSettings; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metricsdb.MetricsDB; import com.amazon.opendistro.elasticsearch.performanceanalyzer.model.MetricAttributes; @@ -47,11 +46,9 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ClusterLevelMetricsReader; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader.ReaderMetricsProcessor; import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.JsonConverter; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatExceptionCode; - import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import javax.net.ssl.HttpsURLConnection; /** * Request handler that supports querying MetricsDB on every EC2 instance. @@ -188,9 +185,10 @@ public boolean validParams(HttpExchange exchange, List metricList, List< } } } - for (String agg : aggList) { + for (String agg : aggList) { if (!MetricsDB.AGG_VALUES.contains(agg)) { - sendResponse(exchange, String.format("{\"error\":\"%s is an invalid aggregation type.\"}", agg), HttpURLConnection.HTTP_BAD_REQUEST); + sendResponse(exchange, String.format("{\"error\":\"%s is an invalid aggregation type.\"}", agg), + HttpURLConnection.HTTP_BAD_REQUEST); return false; } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetricsTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetricsTests.java index da43e982..51a388fc 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetricsTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/metrics/PerformanceAnalyzerMetricsTests.java @@ -15,25 +15,24 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PluginSettings; -import static org.junit.Assert.assertEquals; -import org.junit.Test; import org.junit.Before; -import static org.mockito.Mockito.when; -import org.mockito.Mock; +import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mockito; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.junit.runner.RunWith; import org.powermock.modules.junit4.PowerMockRunner; -@PowerMockIgnore({ "org.apache.logging.log4j.*" }) +import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PluginSettings; +import static org.junit.Assert.assertEquals; + +@PowerMockIgnore({"org.apache.logging.log4j.*"}) @RunWith(PowerMockRunner.class) -@PrepareForTest({ PerformanceAnalyzerMetrics.class, PluginSettings.class }) -@SuppressStaticInitializationFor({ "PluginSettings" }) +@PrepareForTest({PerformanceAnalyzerMetrics.class, PluginSettings.class}) +@SuppressStaticInitializationFor({"PluginSettings"}) public class PerformanceAnalyzerMetricsTests { @Before @@ -59,7 +58,8 @@ public void testBasicMetric() { public void testGeneratePath() { long startTimeInMillis = 1553725339; String generatedPath = PerformanceAnalyzerMetrics.generatePath(startTimeInMillis, "dir1", "id", "dir2"); - String expectedPath = PerformanceAnalyzerMetrics.sDevShmLocation + "/" + String.valueOf(PerformanceAnalyzerMetrics.getTimeInterval(startTimeInMillis)) + "/dir1/id/dir2"; + String expectedPath = PerformanceAnalyzerMetrics.sDevShmLocation + + "/" + PerformanceAnalyzerMetrics.getTimeInterval(startTimeInMillis) + "/dir1/id/dir2"; assertEquals(expectedPath, generatedPath); } }