diff --git a/src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java b/src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java index 54d4d86..1c31db2 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java +++ b/src/main/java/org/opensearch/plugin/insights/core/listener/QueryInsightsListener.java @@ -271,6 +271,7 @@ private void constructSearchQueryRecord(final SearchPhaseContext context, final attributes.put(Attribute.PHASE_LATENCY_MAP, searchRequestContext.phaseTookMap()); attributes.put(Attribute.TASK_RESOURCE_USAGES, tasksResourceUsages); attributes.put(Attribute.GROUP_BY, QueryInsightsSettings.DEFAULT_GROUPING_TYPE); + attributes.put(Attribute.NODE_ID, clusterService.localNode().getId()); if (queryInsightsService.isGroupingEnabled() || log.isTraceEnabled()) { // Generate the query shape only if grouping is enabled or trace logging is enabled diff --git a/src/main/java/org/opensearch/plugin/insights/rules/action/top_queries/TopQueriesResponse.java b/src/main/java/org/opensearch/plugin/insights/rules/action/top_queries/TopQueriesResponse.java index 7405b18..3037900 100644 --- a/src/main/java/org/opensearch/plugin/insights/rules/action/top_queries/TopQueriesResponse.java +++ b/src/main/java/org/opensearch/plugin/insights/rules/action/top_queries/TopQueriesResponse.java @@ -81,7 +81,6 @@ protected void writeNodesTo(final StreamOutput out, final List nodes @Override public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { final List results = getNodes(); - postProcess(results); builder.startObject(); toClusterLevelResult(builder, params, results); return builder.endObject(); @@ -100,20 +99,6 @@ public String toString() { } } - /** - * Post process the top queries results to add customized attributes - * - * @param results the top queries results - */ - private void postProcess(final List results) { - for (TopQueries topQueries : results) { - final String nodeId = topQueries.getNode().getId(); - for (SearchQueryRecord record : topQueries.getTopQueriesRecord()) { - record.addAttribute(Attribute.NODE_ID, nodeId); - } - } - } - /** * Merge top n queries results from nodes into cluster level results in XContent format. * diff --git a/src/test/java/org/opensearch/plugin/insights/QueryInsightsTestUtils.java b/src/test/java/org/opensearch/plugin/insights/QueryInsightsTestUtils.java index e27c41b..886238f 100644 --- a/src/test/java/org/opensearch/plugin/insights/QueryInsightsTestUtils.java +++ b/src/test/java/org/opensearch/plugin/insights/QueryInsightsTestUtils.java @@ -155,6 +155,7 @@ public static List generateQueryInsightRecords( attributes.put(Attribute.PHASE_LATENCY_MAP, phaseLatencyMap); attributes.put(Attribute.QUERY_GROUP_HASHCODE, Objects.hashCode(i)); attributes.put(Attribute.GROUP_BY, GroupingType.NONE); + attributes.put(Attribute.NODE_ID, "node_for_top_queries_test"); attributes.put( Attribute.TASK_RESOURCE_USAGES, List.of( @@ -262,6 +263,7 @@ public static SearchQueryRecord createFixedSearchQueryRecord(String id) { Map attributes = new HashMap<>(); attributes.put(Attribute.SEARCH_TYPE, SearchType.QUERY_THEN_FETCH.toString().toLowerCase(Locale.ROOT)); attributes.put(Attribute.PHASE_LATENCY_MAP, phaseLatencyMap); + attributes.put(Attribute.NODE_ID, "node_for_top_queries_test"); attributes.put( Attribute.TASK_RESOURCE_USAGES, List.of(