Skip to content

Commit

Permalink
update PR based on comments
Browse files Browse the repository at this point in the history
Signed-off-by: Chenyang Ji <[email protected]>
  • Loading branch information
ansjcy committed Sep 18, 2024
1 parent 4fd6b0f commit 498ae5d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -449,10 +450,9 @@ protected void doClose() throws IOException {
* @return QueryInsightsHealthStats
*/
public QueryInsightsHealthStats getHealthStats() {
Map<MetricType, TopQueriesHealthStats> topQueriesHealthStatsMap = new HashMap<>();
for (Map.Entry<MetricType, TopQueriesService> entry : topQueriesServices.entrySet()) {
topQueriesHealthStatsMap.put(entry.getKey(), entry.getValue().getHealthStats());
}
Map<MetricType, TopQueriesHealthStats> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
+ "}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 498ae5d

Please sign in to comment.