-
Notifications
You must be signed in to change notification settings - Fork 7
/
QueryInsightsSettings.java
301 lines (277 loc) · 9.9 KB
/
QueryInsightsSettings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.plugin.insights.settings;
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.unit.TimeValue;
import org.opensearch.plugin.insights.core.exporter.SinkType;
import org.opensearch.plugin.insights.rules.model.MetricType;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Settings for Query Insights Plugin
*/
public class QueryInsightsSettings {
/**
* Executors settings
*/
public static final String QUERY_INSIGHTS_EXECUTOR = "query_insights_executor";
/**
* Max number of thread
*/
public static final int MAX_THREAD_COUNT = 5;
/**
* Max number of requests for the consumer to collect at one time
*/
public static final int QUERY_RECORD_QUEUE_CAPACITY = 1000;
/**
* Time interval for record queue consumer to run
*/
public static final TimeValue QUERY_RECORD_QUEUE_DRAIN_INTERVAL = new TimeValue(5, TimeUnit.SECONDS);
/**
* Default Values and Settings
*/
public static final TimeValue MAX_WINDOW_SIZE = new TimeValue(1, TimeUnit.DAYS);
/**
* Minimal window size
*/
public static final TimeValue MIN_WINDOW_SIZE = new TimeValue(1, TimeUnit.MINUTES);
/**
* Valid window sizes
*/
public static final Set<TimeValue> VALID_WINDOW_SIZES_IN_MINUTES = new HashSet<>(
Arrays.asList(
new TimeValue(1, TimeUnit.MINUTES),
new TimeValue(5, TimeUnit.MINUTES),
new TimeValue(10, TimeUnit.MINUTES),
new TimeValue(30, TimeUnit.MINUTES)
)
);
/** Default N size for top N queries */
public static final int MAX_N_SIZE = 100;
/** Default window size in seconds to keep the top N queries with latency data in query insight store */
public static final TimeValue DEFAULT_WINDOW_SIZE = new TimeValue(60, TimeUnit.SECONDS);
/** Default top N size to keep the data in query insight store */
public static final int DEFAULT_TOP_N_SIZE = 3;
/**
* Query Insights base uri
*/
public static final String PLUGINS_BASE_URI = "/_insights";
/**
* Settings for Top Queries
*
*/
public static final String TOP_QUERIES_BASE_URI = PLUGINS_BASE_URI + "/top_queries";
/** Default prefix for top N queries feature */
public static final String TOP_N_QUERIES_SETTING_PREFIX = "search.insights.top_queries";
/** Default prefix for top N queries by latency feature */
public static final String TOP_N_LATENCY_QUERIES_PREFIX = TOP_N_QUERIES_SETTING_PREFIX + ".latency";
/** Default prefix for top N queries by cpu feature */
public static final String TOP_N_CPU_QUERIES_PREFIX = TOP_N_QUERIES_SETTING_PREFIX + ".cpu";
/** Default prefix for top N queries by memory feature */
public static final String TOP_N_MEMORY_QUERIES_PREFIX = TOP_N_QUERIES_SETTING_PREFIX + ".memory";
/**
* Boolean setting for enabling top queries by latency.
*/
public static final Setting<Boolean> TOP_N_LATENCY_QUERIES_ENABLED = Setting.boolSetting(
TOP_N_LATENCY_QUERIES_PREFIX + ".enabled",
false,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Int setting to define the top n size for top queries by latency.
*/
public static final Setting<Integer> TOP_N_LATENCY_QUERIES_SIZE = Setting.intSetting(
TOP_N_LATENCY_QUERIES_PREFIX + ".top_n_size",
DEFAULT_TOP_N_SIZE,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Time setting to define the window size in seconds for top queries by latency.
*/
public static final Setting<TimeValue> TOP_N_LATENCY_QUERIES_WINDOW_SIZE = Setting.positiveTimeSetting(
TOP_N_LATENCY_QUERIES_PREFIX + ".window_size",
DEFAULT_WINDOW_SIZE,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);
/**
* Boolean setting for enabling top queries by cpu.
*/
public static final Setting<Boolean> TOP_N_CPU_QUERIES_ENABLED = Setting.boolSetting(
TOP_N_CPU_QUERIES_PREFIX + ".enabled",
false,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Int setting to define the top n size for top queries by cpu.
*/
public static final Setting<Integer> TOP_N_CPU_QUERIES_SIZE = Setting.intSetting(
TOP_N_CPU_QUERIES_PREFIX + ".top_n_size",
DEFAULT_TOP_N_SIZE,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Time setting to define the window size in seconds for top queries by cpu.
*/
public static final Setting<TimeValue> TOP_N_CPU_QUERIES_WINDOW_SIZE = Setting.positiveTimeSetting(
TOP_N_CPU_QUERIES_PREFIX + ".window_size",
DEFAULT_WINDOW_SIZE,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);
/**
* Boolean setting for enabling top queries by memory.
*/
public static final Setting<Boolean> TOP_N_MEMORY_QUERIES_ENABLED = Setting.boolSetting(
TOP_N_MEMORY_QUERIES_PREFIX + ".enabled",
false,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Int setting to define the top n size for top queries by memory.
*/
public static final Setting<Integer> TOP_N_MEMORY_QUERIES_SIZE = Setting.intSetting(
TOP_N_MEMORY_QUERIES_PREFIX + ".top_n_size",
DEFAULT_TOP_N_SIZE,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Time setting to define the window size in seconds for top queries by memory.
*/
public static final Setting<TimeValue> TOP_N_MEMORY_QUERIES_WINDOW_SIZE = Setting.positiveTimeSetting(
TOP_N_MEMORY_QUERIES_PREFIX + ".window_size",
DEFAULT_WINDOW_SIZE,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);
/**
* Config key for exporter type
*/
public static final String EXPORTER_TYPE = "type";
/**
* Config key for export index
*/
public static final String EXPORT_INDEX = "config.index";
/**
* Settings and defaults for top queries exporters
*/
private static final String TOP_N_LATENCY_QUERIES_EXPORTER_PREFIX = TOP_N_LATENCY_QUERIES_PREFIX + ".exporter.";
/**
* Prefix for top n queries by cpu exporters
*/
private static final String TOP_N_CPU_QUERIES_EXPORTER_PREFIX = TOP_N_CPU_QUERIES_PREFIX + ".exporter.";
/**
* Prefix for top n queries by memory exporters
*/
private static final String TOP_N_MEMORY_QUERIES_EXPORTER_PREFIX = TOP_N_MEMORY_QUERIES_PREFIX + ".exporter.";
/**
* Default index pattern of top n queries
*/
public static final String DEFAULT_TOP_N_QUERIES_INDEX_PATTERN = "'top_queries-'YYYY.MM.dd";
/**
* Default exporter type of top queries
*/
public static final String DEFAULT_TOP_QUERIES_EXPORTER_TYPE = SinkType.LOCAL_INDEX.toString();
/**
* Settings for the exporter of top latency queries
*/
public static final Setting<Settings> TOP_N_LATENCY_EXPORTER_SETTINGS = Setting.groupSetting(
TOP_N_LATENCY_QUERIES_EXPORTER_PREFIX,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Settings for the exporter of top cpu queries
*/
public static final Setting<Settings> TOP_N_CPU_EXPORTER_SETTINGS = Setting.groupSetting(
TOP_N_CPU_QUERIES_EXPORTER_PREFIX,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Settings for the exporter of top cpu queries
*/
public static final Setting<Settings> TOP_N_MEMORY_EXPORTER_SETTINGS = Setting.groupSetting(
TOP_N_MEMORY_QUERIES_EXPORTER_PREFIX,
Setting.Property.Dynamic,
Setting.Property.NodeScope
);
/**
* Get the enabled setting based on type
* @param type MetricType
* @return enabled setting
*/
public static Setting<Boolean> getTopNEnabledSetting(MetricType type) {
switch (type) {
case CPU:
return TOP_N_CPU_QUERIES_ENABLED;
case MEMORY:
return TOP_N_MEMORY_QUERIES_ENABLED;
default:
return TOP_N_LATENCY_QUERIES_ENABLED;
}
}
/**
* Get the top n size setting based on type
* @param type MetricType
* @return top n size setting
*/
public static Setting<Integer> getTopNSizeSetting(MetricType type) {
switch (type) {
case CPU:
return TOP_N_CPU_QUERIES_SIZE;
case MEMORY:
return TOP_N_MEMORY_QUERIES_SIZE;
default:
return TOP_N_LATENCY_QUERIES_SIZE;
}
}
/**
* Get the window size setting based on type
* @param type MetricType
* @return top n queries window size setting
*/
public static Setting<TimeValue> getTopNWindowSizeSetting(MetricType type) {
switch (type) {
case CPU:
return TOP_N_CPU_QUERIES_WINDOW_SIZE;
case MEMORY:
return TOP_N_MEMORY_QUERIES_WINDOW_SIZE;
default:
return TOP_N_LATENCY_QUERIES_WINDOW_SIZE;
}
}
/**
* Get the exporter settings based on type
* @param type MetricType
* @return exporter setting
*/
public static Setting<Settings> getExporterSettings(MetricType type) {
switch (type) {
case CPU:
return TOP_N_CPU_EXPORTER_SETTINGS;
case MEMORY:
return TOP_N_MEMORY_EXPORTER_SETTINGS;
default:
return TOP_N_LATENCY_EXPORTER_SETTINGS;
}
}
/**
* Default constructor
*/
public QueryInsightsSettings() {}
}