diff --git a/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java b/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java index 41cb8e6..fe6692c 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java +++ b/src/main/java/org/opensearch/plugin/insights/core/service/QueryInsightsService.java @@ -19,6 +19,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.LinkedBlockingQueue; +import java.util.stream.Collectors; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.opensearch.client.Client; @@ -449,10 +451,9 @@ protected void doClose() throws IOException { * @return QueryInsightsHealthStats */ public QueryInsightsHealthStats getHealthStats() { - Map topQueriesHealthStatsMap = new HashMap<>(); - for (Map.Entry entry : topQueriesServices.entrySet()) { - topQueriesHealthStatsMap.put(entry.getKey(), entry.getValue().getHealthStats()); - } + Map topQueriesHealthStatsMap = + topQueriesServices.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getHealthStats())); return new QueryInsightsHealthStats( threadPool.info(QUERY_INSIGHTS_EXECUTOR), this.queryRecordsQueue.size(), diff --git a/src/main/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStats.java b/src/main/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStats.java index 75d955d..b908dd7 100644 --- a/src/main/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStats.java +++ b/src/main/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStats.java @@ -21,8 +21,8 @@ public class QueryGrouperHealthStats implements ToXContentFragment, Writeable { private final int queryGroupCount; private final int queryGroupHeapSize; - private static final String QUERY_GROUP_COUNT = "QueryGroupCount"; - private static final String QUERY_GROUP_HEAP_SIZE = "QueryGroupHeapSize"; + private static final String QUERY_GROUP_COUNT_TOTAL = "QueryGroupCount_Total"; + private static final String QUERY_GROUP_COUNT_MAX_HEAP = "QueryGroupCount_MaxHeap"; /** * Constructor to read QueryGrouperHealthStats from a StreamInput. @@ -67,8 +67,8 @@ public void writeTo(StreamOutput out) throws IOException { */ @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field(QUERY_GROUP_COUNT, queryGroupCount); - builder.field(QUERY_GROUP_HEAP_SIZE, queryGroupHeapSize); + builder.field(QUERY_GROUP_COUNT_TOTAL, queryGroupCount); + builder.field(QUERY_GROUP_COUNT_MAX_HEAP, queryGroupHeapSize); return builder; } diff --git a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStatsTests.java b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStatsTests.java index a4a9ceb..874ac98 100644 --- a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStatsTests.java +++ b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryGrouperHealthStatsTests.java @@ -52,7 +52,7 @@ public void testToXContent() throws IOException { builder.endObject(); String expectedJson = String.format( Locale.ROOT, - "{\"QueryGroupCount\":%d,\"QueryGroupHeapSize\":%d}", + "{\"QueryGroupCount_Total\":%d,\"QueryGroupCount_MaxHeap\":%d}", queryGroupCount, queryGroupHeapSize ); diff --git a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryInsightsHealthStatsTests.java b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryInsightsHealthStatsTests.java index 1677cca..692b29d 100644 --- a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryInsightsHealthStatsTests.java +++ b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/QueryInsightsHealthStatsTests.java @@ -99,8 +99,8 @@ public void testToXContent() throws IOException { + " \"TopQueriesHealthStats\": {\n" + " \"latency\": {\n" + " \"TopQueriesHeapSize\": 10,\n" - + " \"QueryGroupCount\": 20,\n" - + " \"QueryGroupHeapSize\": 15\n" + + " \"QueryGroupCount_Total\": 20,\n" + + " \"QueryGroupCount_MaxHeap\": 15\n" + " }\n" + " }\n" + "}"; diff --git a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/TopQueriesHealthStatsTests.java b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/TopQueriesHealthStatsTests.java index f84d7f0..15e7a19 100644 --- a/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/TopQueriesHealthStatsTests.java +++ b/src/test/java/org/opensearch/plugin/insights/rules/model/healthStats/TopQueriesHealthStatsTests.java @@ -60,7 +60,7 @@ public void testToXContent() throws IOException { builder.endObject(); String expectedJson = String.format( Locale.ROOT, - "{\"TopQueriesHeapSize\":%d,\"QueryGroupCount\":%d,\"QueryGroupHeapSize\":%d}", + "{\"TopQueriesHeapSize\":%d,\"QueryGroupCount_Total\":%d,\"QueryGroupCount_MaxHeap\":%d}", topQueriesHeapSize, queryGrouperHealthStats.getQueryGroupCount(), queryGrouperHealthStats.getQueryGroupHeapSize()