Skip to content

Commit

Permalink
Fix bug on node_id missing in local index (#207)
Browse files Browse the repository at this point in the history
Signed-off-by: Chenyang Ji <[email protected]>
(cherry picked from commit bd6debd)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jan 24, 2025
1 parent 3cf81f2 commit 7c934ab
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.xcontent.ToXContentFragment;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.plugin.insights.rules.model.Attribute;
import org.opensearch.plugin.insights.rules.model.MetricType;
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord;

Expand Down Expand Up @@ -81,7 +80,6 @@ protected void writeNodesTo(final StreamOutput out, final List<TopQueries> nodes
@Override
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
final List<TopQueries> results = getNodes();
postProcess(results);
builder.startObject();
toClusterLevelResult(builder, params, results);
return builder.endObject();
Expand All @@ -100,20 +98,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<TopQueries> 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static List<SearchQueryRecord> 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(
Expand Down Expand Up @@ -262,6 +263,7 @@ public static SearchQueryRecord createFixedSearchQueryRecord(String id) {
Map<Attribute, Object> 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(
Expand Down

0 comments on commit 7c934ab

Please sign in to comment.