Skip to content

Commit

Permalink
Merge branch 'opensearch-project:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
KishoreKicha14 authored Jan 16, 2025
2 parents 081250b + 9810982 commit fee6dfc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void constructSearchQueryRecord(final SearchPhaseContext context, final
// Add hashcode attribute when grouping is enabled
if (queryInsightsService.isGroupingEnabled()) {
String hashcode = queryShapeGenerator.getShapeHashCodeAsString(queryShape);
attributes.put(Attribute.QUERY_HASHCODE, hashcode);
attributes.put(Attribute.ID, hashcode);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ int numberOfTopGroups() {
private String getGroupingId(final SearchQueryRecord searchQueryRecord) {
switch (groupingType) {
case SIMILARITY:
return searchQueryRecord.getAttributes().get(Attribute.QUERY_HASHCODE).toString();
return searchQueryRecord.getAttributes().get(Attribute.ID).toString();
case NONE:
throw new IllegalArgumentException("Should not try to group queries if grouping type is NONE");
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public enum Attribute {
*/
LABELS,
/**
* Unique hashcode used to group similar queries
* Query Group hashcode or query hashcode representing a unique identifier for the query/group
*/
QUERY_HASHCODE,
ID,
/**
* Grouping type of the query record (none, similarity)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

package org.opensearch.plugin.insights.rules.model;

import static org.opensearch.plugin.insights.rules.model.Attribute.GROUP_BY;

import java.io.IOException;
import java.util.*;

Expand Down Expand Up @@ -98,6 +96,11 @@ public class SearchQueryRecord implements ToXContentObject, Writeable {
*/
public static final String GROUP_BY = "group_by";

/**
* Query Group hashcode or query hashcode representing a unique identifier for the query/group
*/
public static final String ID = "id";

public static final String MEASUREMENTS = "measurements";
private String groupingId;

Expand Down Expand Up @@ -188,6 +191,9 @@ public static SearchQueryRecord fromXContent(XContentParser parser) throws IOExc
case GROUP_BY:
attributes.put(Attribute.GROUP_BY, parser.text());
break;
case ID:
attributes.put(Attribute.ID, parser.text());
break;
case SOURCE:
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser);
attributes.put(Attribute.SOURCE, SearchSourceBuilder.fromXContent(parser, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static List<SearchQueryRecord> generateQueryInsightRecords(
attributes.put(Attribute.TOTAL_SHARDS, randomIntBetween(1, 100));
attributes.put(Attribute.INDICES, randomArray(1, 3, Object[]::new, () -> randomAlphaOfLengthBetween(5, 10)));
attributes.put(Attribute.PHASE_LATENCY_MAP, phaseLatencyMap);
attributes.put(Attribute.QUERY_HASHCODE, Objects.hashCode(i));
attributes.put(Attribute.ID, Objects.hashCode(i));
attributes.put(Attribute.GROUP_BY, GroupingType.NONE);
attributes.put(
Attribute.TASK_RESOURCE_USAGES,
Expand Down Expand Up @@ -200,13 +200,13 @@ public static List<List<SearchQueryRecord>> generateMultipleQueryInsightsRecords

public static void populateSameQueryHashcodes(List<SearchQueryRecord> searchQueryRecords) {
for (SearchQueryRecord record : searchQueryRecords) {
record.getAttributes().put(Attribute.QUERY_HASHCODE, 1);
record.getAttributes().put(Attribute.ID, 1);
}
}

public static void populateHashcode(List<SearchQueryRecord> searchQueryRecords, int hash) {
for (SearchQueryRecord record : searchQueryRecords) {
record.getAttributes().put(Attribute.QUERY_HASHCODE, hash);
record.getAttributes().put(Attribute.ID, hash);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testWithAllDifferentHashcodes() {
Set<Integer> hashcodeSet = new HashSet<>();
for (SearchQueryRecord record : records) {
groupedRecord = minMaxHeapQueryGrouper.add(record);
int hashcode = (int) groupedRecord.getAttributes().get(Attribute.QUERY_HASHCODE);
int hashcode = (int) groupedRecord.getAttributes().get(Attribute.ID);
hashcodeSet.add(hashcode);
}
assertEquals(numOfRecords, hashcodeSet.size());
Expand All @@ -58,7 +58,7 @@ public void testWithAllSameHashcodes() {
Set<Integer> hashcodeSet = new HashSet<>();
for (SearchQueryRecord record : records) {
groupedRecord = minMaxHeapQueryGrouper.add(record);
int hashcode = (int) groupedRecord.getAttributes().get(Attribute.QUERY_HASHCODE);
int hashcode = (int) groupedRecord.getAttributes().get(Attribute.ID);
hashcodeSet.add(hashcode);
}
assertEquals(1, hashcodeSet.size());
Expand Down

0 comments on commit fee6dfc

Please sign in to comment.