32
32
import java .util .Objects ;
33
33
import java .util .Set ;
34
34
import java .util .TreeSet ;
35
+ import java .util .UUID ;
35
36
import org .opensearch .action .search .SearchType ;
36
37
import org .opensearch .cluster .node .DiscoveryNode ;
37
38
import org .opensearch .common .settings .ClusterSettings ;
54
55
55
56
final public class QueryInsightsTestUtils {
56
57
58
+ static String randomId = UUID .randomUUID ().toString ();
59
+
57
60
public QueryInsightsTestUtils () {}
58
61
62
+ /**
63
+ * Returns list of randomly generated search query records with a specific id
64
+ * @param count number of records
65
+ * @return List of records
66
+ */
67
+ public static List <SearchQueryRecord > generateQueryInsightRecords (int count , String id ) {
68
+ return generateQueryInsightRecords (count , count , System .currentTimeMillis (), 0 , AggregationType .DEFAULT_AGGREGATION_TYPE , id );
69
+ }
70
+
59
71
/**
60
72
* Returns list of randomly generated search query records.
61
73
* @param count number of records
62
74
* @return List of records
63
75
*/
64
76
public static List <SearchQueryRecord > generateQueryInsightRecords (int count ) {
65
- return generateQueryInsightRecords (count , count , System .currentTimeMillis (), 0 , AggregationType .DEFAULT_AGGREGATION_TYPE );
77
+ return generateQueryInsightRecords (count , count , System .currentTimeMillis (), 0 , AggregationType .DEFAULT_AGGREGATION_TYPE , randomId );
66
78
}
67
79
68
80
/**
@@ -77,7 +89,8 @@ public static List<SearchQueryRecord> generateQueryInsightRecords(int count, Sea
77
89
count ,
78
90
System .currentTimeMillis (),
79
91
0 ,
80
- AggregationType .DEFAULT_AGGREGATION_TYPE
92
+ AggregationType .DEFAULT_AGGREGATION_TYPE ,
93
+ randomId
81
94
);
82
95
for (SearchQueryRecord record : records ) {
83
96
record .getAttributes ().put (Attribute .SOURCE , searchSourceBuilder );
@@ -92,14 +105,14 @@ public static List<SearchQueryRecord> generateQueryInsightRecords(int count, Sea
92
105
* @return List of records
93
106
*/
94
107
public static List <SearchQueryRecord > generateQueryInsightRecords (int count , AggregationType aggregationType ) {
95
- return generateQueryInsightRecords (count , count , System .currentTimeMillis (), 0 , aggregationType );
108
+ return generateQueryInsightRecords (count , count , System .currentTimeMillis (), 0 , aggregationType , randomId );
96
109
}
97
110
98
111
/**
99
112
* Creates a List of random Query Insight Records for testing purpose
100
113
*/
101
114
public static List <SearchQueryRecord > generateQueryInsightRecords (int lower , int upper , long startTimeStamp , long interval ) {
102
- return generateQueryInsightRecords (lower , upper , startTimeStamp , interval , AggregationType .NONE );
115
+ return generateQueryInsightRecords (lower , upper , startTimeStamp , interval , AggregationType .NONE , randomId );
103
116
}
104
117
105
118
/**
@@ -110,7 +123,8 @@ public static List<SearchQueryRecord> generateQueryInsightRecords(
110
123
int upper ,
111
124
long startTimeStamp ,
112
125
long interval ,
113
- AggregationType aggregationType
126
+ AggregationType aggregationType ,
127
+ String id
114
128
) {
115
129
List <SearchQueryRecord > records = new ArrayList <>();
116
130
int countOfRecords = randomIntBetween (lower , upper );
@@ -161,7 +175,7 @@ public static List<SearchQueryRecord> generateQueryInsightRecords(
161
175
)
162
176
);
163
177
164
- records .add (new SearchQueryRecord (timestamp , measurements , attributes ));
178
+ records .add (new SearchQueryRecord (timestamp , measurements , attributes , id ));
165
179
timestamp += interval ;
166
180
}
167
181
return records ;
0 commit comments