@eeacms/volto-globalsearch 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.husky/pre-commit +2 -0
- package/CHANGELOG.md +32 -8
- package/DEVELOP.md +6 -8
- package/README.md +5 -2
- package/cypress.config.js +2 -2
- package/docker-compose.yml +5 -1
- package/locales/en/LC_MESSAGES/volto.po +14 -0
- package/package.json +26 -2
- package/src/config/facets.js +1 -1
- package/src/config/filters.js +26 -22
- package/src/config/global-search-config.js +20 -0
- package/src/config/healthcheck.js +285 -45
- package/src/config/healthcheck.test.js +300 -0
- package/src/config/healthcheck_queries/empty_resp.json +18 -0
- package/src/config/healthcheck_queries/failed_scheduled_atempts_since_last_started.json +36 -0
- package/src/config/healthcheck_queries/failed_scheduled_atempts_since_last_started_resp.json +41 -0
- package/src/config/healthcheck_queries/failed_site_since_last_started.json +31 -0
- package/src/config/healthcheck_queries/last_scheduled_indexing.json +28 -0
- package/src/config/healthcheck_queries/last_scheduled_started_indexing.json +29 -0
- package/src/config/healthcheck_queries/last_scheduled_started_indexing_resp.json +41 -0
- package/src/config/healthcheck_queries/last_sync_task_since_last_start.json +36 -0
- package/src/config/healthcheck_queries/last_sync_task_since_last_start_resp.json +63 -0
- package/src/config/healthcheck_queries/latest_tasks_for_site.json +23 -0
- package/src/config/healthcheck_queries/latest_tasks_for_site_resp.json +70 -0
- package/src/config/healthcheck_queries/started_or_finished_site_since_last_started.json +35 -0
- package/src/config/healthcheck_queries/started_or_finished_site_since_last_started_resp.json +36 -0
- package/src/config/index.test.js +16 -0
- /package/src/{utlis.test.js → utils.test.js} +0 -0
|
@@ -1,14 +1,235 @@
|
|
|
1
|
-
import runRequest from '@eeacms/search
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { runRequest, buildRequest } from '@eeacms/search';
|
|
2
|
+
//import getInfo from '@eeacms/search/lib/getIndexInfo';
|
|
3
|
+
|
|
4
|
+
import failed_scheduled_atempts_since_last_started from './healthcheck_queries/failed_scheduled_atempts_since_last_started.json';
|
|
5
|
+
//import failed_site_since_last_started from './healthcheck_queries/failed_site_since_last_started.json';
|
|
6
|
+
//import last_scheduled_indexing from './healthcheck_queries/last_scheduled_indexing.json';
|
|
7
|
+
import last_scheduled_started_indexing from './healthcheck_queries/last_scheduled_started_indexing.json';
|
|
8
|
+
import last_sync_task_since_last_start from './healthcheck_queries/last_sync_task_since_last_start.json';
|
|
9
|
+
import latest_tasks_for_site from './healthcheck_queries/latest_tasks_for_site.json';
|
|
10
|
+
import started_or_finished_site_since_last_started from './healthcheck_queries/started_or_finished_site_since_last_started.json';
|
|
4
11
|
|
|
5
12
|
const default_documentCountThreshold = 60000;
|
|
6
13
|
const default_queryTimeSecondsThreshold_OK = 2;
|
|
7
14
|
const default_queryTimeSecondsThreshold_WARNING = 5;
|
|
8
|
-
const
|
|
9
|
-
const
|
|
15
|
+
const default_failedSyncThreshold_WARNING = 5;
|
|
16
|
+
const default_failedSyncThreshold_OK = 2;
|
|
17
|
+
|
|
18
|
+
export function buildQuery(query, values) {
|
|
19
|
+
let q = JSON.stringify(query);
|
|
20
|
+
Object.keys(values).forEach(function (key, value) {
|
|
21
|
+
q = q.split('<' + key + '>').join(values[key]);
|
|
22
|
+
});
|
|
23
|
+
return JSON.parse(q);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function executeQuery(q, appConfig, params = {}, callback) {
|
|
27
|
+
return new Promise(async (resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
params['index_name'] = 'status_' + appConfig['index_name'];
|
|
30
|
+
const query = buildQuery(q, params);
|
|
31
|
+
//console.log(JSON.stringify(query));
|
|
32
|
+
const resp = await runRequest(query, appConfig);
|
|
33
|
+
// console.log(JSON.stringify(resp.body));
|
|
34
|
+
resolve(callback(resp.body, params));
|
|
35
|
+
} catch (e) {
|
|
36
|
+
reject({ error: e.message });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function getlastandnext_started_execution(body, params = {}) {
|
|
42
|
+
if (body.hits.total.value > 0) {
|
|
43
|
+
return {
|
|
44
|
+
last_started: body.hits.hits[0]._source.start_time_ts,
|
|
45
|
+
next_execution_date: body.hits.hits[0]._source.next_execution_date_ts,
|
|
46
|
+
};
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error('no results');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function getlastfailed_execution(body, params = {}) {
|
|
53
|
+
if (body.hits.total.value > 0) {
|
|
54
|
+
return {
|
|
55
|
+
last_started: body.hits.hits[0]._source.start_time_ts,
|
|
56
|
+
next_execution_date: body.hits.hits[0]._source.next_execution_date_ts,
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
throw new Error('no results');
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getlastsynctaskssincestarted(body, params = {}) {
|
|
64
|
+
if (body.hits.total.value > 0) {
|
|
65
|
+
return {
|
|
66
|
+
sites: body.hits.hits[0]._source.sites,
|
|
67
|
+
};
|
|
68
|
+
} else {
|
|
69
|
+
throw new Error('no results');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getlastsuccessfultasks_for_site(body, params = {}) {
|
|
74
|
+
if (body.hits.total.value > 0) {
|
|
75
|
+
return true;
|
|
76
|
+
} else {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getlatesttasks_for_site(body, params = {}) {
|
|
82
|
+
if (body.hits.total.value > 0) {
|
|
83
|
+
let status = 'OK';
|
|
84
|
+
let i = 0;
|
|
85
|
+
while (true) {
|
|
86
|
+
const doc = body.hits.hits[i]._source;
|
|
87
|
+
if (doc.status === 'Finished') {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
i++;
|
|
91
|
+
if (i === params.THRESHOLD_WARNING) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (i >= params.THRESHOLD_OK && i < params.THRESHOLD_WARNING) {
|
|
96
|
+
status = 'WARNING';
|
|
97
|
+
}
|
|
98
|
+
if (i >= params.THRESHOLD_WARNING) {
|
|
99
|
+
status = 'CRITICAL';
|
|
100
|
+
}
|
|
101
|
+
return status;
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error('Failed to get info');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
10
106
|
|
|
11
|
-
export
|
|
107
|
+
export async function getStatus(appConfig, params) {
|
|
108
|
+
return new Promise(async (resolve, reject) => {
|
|
109
|
+
let resp = 'OK';
|
|
110
|
+
let error = null;
|
|
111
|
+
// console.log('=======================================');
|
|
112
|
+
// console.log('STEP 1');
|
|
113
|
+
const step1 = await executeQuery(
|
|
114
|
+
last_scheduled_started_indexing,
|
|
115
|
+
appConfig,
|
|
116
|
+
{},
|
|
117
|
+
getlastandnext_started_execution,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// console.log(step1);
|
|
121
|
+
|
|
122
|
+
// const last_successful_schedule = step1.last_started;
|
|
123
|
+
let next_schedule = step1.next_execution_date;
|
|
124
|
+
|
|
125
|
+
const now = params.now || Date.now() - 60 * 1000;
|
|
126
|
+
if (now >= next_schedule) {
|
|
127
|
+
try {
|
|
128
|
+
// console.log('=======================================');
|
|
129
|
+
// console.log('STEP 2');
|
|
130
|
+
const step2 = await executeQuery(
|
|
131
|
+
failed_scheduled_atempts_since_last_started,
|
|
132
|
+
appConfig,
|
|
133
|
+
step1,
|
|
134
|
+
getlastfailed_execution,
|
|
135
|
+
);
|
|
136
|
+
next_schedule = step2.next_execution_date;
|
|
137
|
+
// console.log(step2);
|
|
138
|
+
} catch {
|
|
139
|
+
resp = 'CRITICAL';
|
|
140
|
+
error = 'Failed to get status info from elasticsearch';
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (error === null) {
|
|
144
|
+
if (now > next_schedule) {
|
|
145
|
+
resp = 'CRITICAL';
|
|
146
|
+
error = 'Airflow stopped indexing, no new schedules in the queue';
|
|
147
|
+
} else {
|
|
148
|
+
try {
|
|
149
|
+
const step3 = await executeQuery(
|
|
150
|
+
last_sync_task_since_last_start,
|
|
151
|
+
appConfig,
|
|
152
|
+
step1,
|
|
153
|
+
getlastsynctaskssincestarted,
|
|
154
|
+
);
|
|
155
|
+
// console.log(step3.sites);
|
|
156
|
+
const all_sites_status = {};
|
|
157
|
+
for (let i = 0; i < step3.sites.length; i++) {
|
|
158
|
+
try {
|
|
159
|
+
// console.log('=======================================');
|
|
160
|
+
// console.log('STEP 4');
|
|
161
|
+
// const step4 =
|
|
162
|
+
await executeQuery(
|
|
163
|
+
started_or_finished_site_since_last_started,
|
|
164
|
+
appConfig,
|
|
165
|
+
{
|
|
166
|
+
site_name: step3.sites[i],
|
|
167
|
+
last_started: step1['last_started'],
|
|
168
|
+
},
|
|
169
|
+
getlastsuccessfultasks_for_site,
|
|
170
|
+
);
|
|
171
|
+
all_sites_status[step3.sites[i]] = 'OK';
|
|
172
|
+
// console.log(step4);
|
|
173
|
+
} catch {
|
|
174
|
+
// console.log('=======================================');
|
|
175
|
+
// console.log('STEP 5');
|
|
176
|
+
const step5 = await executeQuery(
|
|
177
|
+
latest_tasks_for_site,
|
|
178
|
+
appConfig,
|
|
179
|
+
{
|
|
180
|
+
site_name: step3.sites[i],
|
|
181
|
+
last_started: step1['last_started'],
|
|
182
|
+
THRESHOLD_WARNING: parseInt(
|
|
183
|
+
params.FAILED_SYNC_THRESHOLD_WARNING,
|
|
184
|
+
),
|
|
185
|
+
THRESHOLD_OK: parseInt(params.FAILED_SYNC_THRESHOLD_OK),
|
|
186
|
+
},
|
|
187
|
+
getlatesttasks_for_site,
|
|
188
|
+
);
|
|
189
|
+
all_sites_status[step3.sites[i]] = step5;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
// console.log(all_sites_status);
|
|
193
|
+
const oks = [];
|
|
194
|
+
const warnings = [];
|
|
195
|
+
const criticals = [];
|
|
196
|
+
for (let i = 0; i < step3.sites.length; i++) {
|
|
197
|
+
if (all_sites_status[step3.sites[i]] === 'OK') {
|
|
198
|
+
oks.push(step3.sites[i]);
|
|
199
|
+
}
|
|
200
|
+
if (all_sites_status[step3.sites[i]] === 'WARNING') {
|
|
201
|
+
warnings.push(step3.sites[i]);
|
|
202
|
+
}
|
|
203
|
+
if (all_sites_status[step3.sites[i]] === 'CRITICAL') {
|
|
204
|
+
criticals.push(step3.sites[i]);
|
|
205
|
+
}
|
|
206
|
+
if (criticals.length > 0) {
|
|
207
|
+
error =
|
|
208
|
+
'Clusters with too many fails: ' +
|
|
209
|
+
criticals.concat(warnings).join(', ');
|
|
210
|
+
resp = 'CRITICAL';
|
|
211
|
+
} else {
|
|
212
|
+
if (warnings.length > 0) {
|
|
213
|
+
error =
|
|
214
|
+
'Clusters with too many fails: ' +
|
|
215
|
+
criticals.concat(warnings).join(', ');
|
|
216
|
+
resp = 'WARNING';
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch {
|
|
221
|
+
error = 'Failed to get status info from elasticsearch';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const status = { status: resp };
|
|
226
|
+
if (error !== null) {
|
|
227
|
+
status.error = error;
|
|
228
|
+
}
|
|
229
|
+
resolve(status);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
export default async function healthcheck(appConfig, params) {
|
|
12
233
|
// is index ok?
|
|
13
234
|
// return index update date
|
|
14
235
|
// run default query, see number of results
|
|
@@ -21,9 +242,10 @@ export default async function healthcheck(appConfig, query) {
|
|
|
21
242
|
documentCountThreshold,
|
|
22
243
|
queryTimeSecondsThreshold_OK,
|
|
23
244
|
queryTimeSecondsThreshold_WARNING,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
245
|
+
failedSyncThreshold_OK,
|
|
246
|
+
failedSyncThreshold_WARNING,
|
|
247
|
+
now,
|
|
248
|
+
} = params;
|
|
27
249
|
documentCountThreshold =
|
|
28
250
|
documentCountThreshold || default_documentCountThreshold;
|
|
29
251
|
queryTimeSecondsThreshold_OK =
|
|
@@ -31,17 +253,30 @@ export default async function healthcheck(appConfig, query) {
|
|
|
31
253
|
queryTimeSecondsThreshold_WARNING =
|
|
32
254
|
queryTimeSecondsThreshold_WARNING ||
|
|
33
255
|
default_queryTimeSecondsThreshold_WARNING;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
default_indexUpdatedHoursThreshold_WARNING;
|
|
256
|
+
failedSyncThreshold_OK =
|
|
257
|
+
failedSyncThreshold_OK || default_failedSyncThreshold_OK;
|
|
258
|
+
failedSyncThreshold_WARNING =
|
|
259
|
+
failedSyncThreshold_WARNING || default_failedSyncThreshold_WARNING;
|
|
39
260
|
|
|
40
|
-
const
|
|
261
|
+
const airflow_params = {
|
|
262
|
+
FAILED_SYNC_THRESHOLD_WARNING: failedSyncThreshold_WARNING,
|
|
263
|
+
FAILED_SYNC_THRESHOLD_OK: failedSyncThreshold_OK,
|
|
264
|
+
now: now,
|
|
265
|
+
};
|
|
41
266
|
|
|
267
|
+
///////////////////
|
|
268
|
+
const body_total = buildRequest({ filters: [] }, appConfig);
|
|
269
|
+
//console.log(body_total);
|
|
42
270
|
const resp_total = await runRequest(body_total, appConfig);
|
|
43
271
|
const total = resp_total.body.hits.total.value;
|
|
44
|
-
const total_status =
|
|
272
|
+
const total_status =
|
|
273
|
+
total > documentCountThreshold
|
|
274
|
+
? { status: 'OK' }
|
|
275
|
+
: {
|
|
276
|
+
status: 'CRITICAL',
|
|
277
|
+
error:
|
|
278
|
+
'The number of documents in elasticsearch dropped drastically',
|
|
279
|
+
};
|
|
45
280
|
const body_nlp = buildRequest(
|
|
46
281
|
{ filters: [], searchTerm: 'what is bise?' },
|
|
47
282
|
appConfig,
|
|
@@ -57,42 +292,47 @@ export default async function healthcheck(appConfig, query) {
|
|
|
57
292
|
});
|
|
58
293
|
});
|
|
59
294
|
});
|
|
295
|
+
|
|
60
296
|
const elapsed_status =
|
|
61
297
|
total_elapsed < queryTimeSecondsThreshold_OK
|
|
62
|
-
? 'OK'
|
|
298
|
+
? { status: 'OK' }
|
|
63
299
|
: total_elapsed < queryTimeSecondsThreshold_WARNING
|
|
64
|
-
? 'WARNING'
|
|
65
|
-
: 'CRITICAL';
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
: 'CRITICAL';
|
|
76
|
-
|
|
77
|
-
let status = 'OK';
|
|
78
|
-
if (elapsed_status === 'WARNING' || indexed_status === 'WARNING') {
|
|
79
|
-
status = 'WARNING';
|
|
300
|
+
? { status: 'WARNING', error: 'Slow response from NLP' }
|
|
301
|
+
: { status: 'CRITICAL', error: 'Slow response from NLP' };
|
|
302
|
+
|
|
303
|
+
const airflow_status = await getStatus(appConfig, airflow_params);
|
|
304
|
+
|
|
305
|
+
let status = { status: 'OK' };
|
|
306
|
+
if (
|
|
307
|
+
elapsed_status.status === 'WARNING' ||
|
|
308
|
+
airflow_status.status === 'WARNING'
|
|
309
|
+
) {
|
|
310
|
+
status = { status: 'WARNING' };
|
|
80
311
|
}
|
|
81
312
|
if (
|
|
82
|
-
total_status === 'CRITICAL' ||
|
|
83
|
-
elapsed_status === 'CRITICAL' ||
|
|
84
|
-
|
|
313
|
+
total_status.status === 'CRITICAL' ||
|
|
314
|
+
elapsed_status.status === 'CRITICAL' ||
|
|
315
|
+
airflow_status.status === 'CRITICAL'
|
|
85
316
|
) {
|
|
86
|
-
status = 'CRITICAL';
|
|
317
|
+
status = { status: 'CRITICAL' };
|
|
87
318
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
319
|
+
|
|
320
|
+
const errors_list = [];
|
|
321
|
+
if (total_status.error) {
|
|
322
|
+
errors_list.push(total_status.error);
|
|
323
|
+
}
|
|
324
|
+
if (elapsed_status.error) {
|
|
325
|
+
errors_list.push(elapsed_status.error);
|
|
326
|
+
}
|
|
327
|
+
if (airflow_status.error) {
|
|
328
|
+
errors_list.push(airflow_status.error);
|
|
329
|
+
}
|
|
330
|
+
if (errors_list.length > 0) {
|
|
331
|
+
status.error = errors_list.join('\n');
|
|
332
|
+
}
|
|
333
|
+
resolve(status);
|
|
334
|
+
} catch (e) {
|
|
335
|
+
reject({ status: 'Critical', error: e.message });
|
|
96
336
|
}
|
|
97
337
|
});
|
|
98
338
|
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildQuery,
|
|
3
|
+
getlastfailed_execution,
|
|
4
|
+
getlastandnext_started_execution,
|
|
5
|
+
getlastsynctaskssincestarted,
|
|
6
|
+
getlatesttasks_for_site,
|
|
7
|
+
getlastsuccessfultasks_for_site,
|
|
8
|
+
getStatus,
|
|
9
|
+
} from './healthcheck';
|
|
10
|
+
import healthcheck from './healthcheck';
|
|
11
|
+
|
|
12
|
+
import { runRequest } from '@eeacms/search';
|
|
13
|
+
|
|
14
|
+
import failed_scheduled_atempts_since_last_started_resp from './healthcheck_queries/failed_scheduled_atempts_since_last_started_resp.json';
|
|
15
|
+
import last_scheduled_started_indexing_resp from './healthcheck_queries/last_scheduled_started_indexing_resp.json';
|
|
16
|
+
import last_sync_task_since_last_start_resp from './healthcheck_queries/last_sync_task_since_last_start_resp.json';
|
|
17
|
+
import latest_tasks_for_site_resp from './healthcheck_queries/latest_tasks_for_site_resp.json';
|
|
18
|
+
import started_or_finished_site_since_last_started_resp from './healthcheck_queries/started_or_finished_site_since_last_started_resp.json';
|
|
19
|
+
import empty_resp from './healthcheck_queries/empty_resp.json';
|
|
20
|
+
const SLOTS = [
|
|
21
|
+
'aboveSearchInput',
|
|
22
|
+
'belowSearchInput',
|
|
23
|
+
'aboveResults',
|
|
24
|
+
'belowResults',
|
|
25
|
+
];
|
|
26
|
+
jest.mock('@eeacms/search', () => ({
|
|
27
|
+
SLOTS: SLOTS,
|
|
28
|
+
runRequest: jest.fn(),
|
|
29
|
+
buildRequest: jest.fn(),
|
|
30
|
+
}));
|
|
31
|
+
|
|
32
|
+
const query1 = {
|
|
33
|
+
query: {
|
|
34
|
+
bool: {
|
|
35
|
+
must: [],
|
|
36
|
+
must_not: [],
|
|
37
|
+
should: [],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
from: 0,
|
|
41
|
+
size: 1,
|
|
42
|
+
index: '<index_name>',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const built_query1 = {
|
|
46
|
+
query: {
|
|
47
|
+
bool: {
|
|
48
|
+
must: [],
|
|
49
|
+
must_not: [],
|
|
50
|
+
should: [],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
from: 0,
|
|
54
|
+
size: 1,
|
|
55
|
+
index: 'test_index',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const query2 = {
|
|
59
|
+
query: {
|
|
60
|
+
bool: {
|
|
61
|
+
must: [],
|
|
62
|
+
must_not: [],
|
|
63
|
+
should: [],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
from: 0,
|
|
67
|
+
size: '<size>',
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const built_query2 = {
|
|
71
|
+
query: {
|
|
72
|
+
bool: {
|
|
73
|
+
must: [],
|
|
74
|
+
must_not: [],
|
|
75
|
+
should: [],
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
from: 0,
|
|
79
|
+
size: '10',
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const query3 = {
|
|
83
|
+
query: {
|
|
84
|
+
bool: {
|
|
85
|
+
must: [
|
|
86
|
+
{
|
|
87
|
+
terms: {
|
|
88
|
+
term_field: ['<site_name>'],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
must_not: [],
|
|
93
|
+
should: [],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
from: 0,
|
|
97
|
+
size: '<size>',
|
|
98
|
+
sort: [
|
|
99
|
+
{
|
|
100
|
+
start_time_ts: 'desc',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
index: '<index_name>',
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const built_query3 = {
|
|
107
|
+
query: {
|
|
108
|
+
bool: {
|
|
109
|
+
must: [
|
|
110
|
+
{
|
|
111
|
+
terms: {
|
|
112
|
+
term_field: ['test_site'],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
must_not: [],
|
|
117
|
+
should: [],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
from: 0,
|
|
121
|
+
size: '10',
|
|
122
|
+
sort: [
|
|
123
|
+
{
|
|
124
|
+
start_time_ts: 'desc',
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
index: 'test_index',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
describe('test building the queries', () => {
|
|
131
|
+
it('should replace 1 string variable with the value in the query', () => {
|
|
132
|
+
const params = { index_name: 'test_index' };
|
|
133
|
+
const bQuery = buildQuery(query1, params);
|
|
134
|
+
expect(bQuery).toEqual(built_query1);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should replace 1 numeric variable with the value in the query', () => {
|
|
138
|
+
const params = { size: 10 };
|
|
139
|
+
const bQuery = buildQuery(query2, params);
|
|
140
|
+
expect(bQuery).toEqual(built_query2);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should replace more variables with the values in the query', () => {
|
|
144
|
+
const params = {
|
|
145
|
+
index_name: 'test_index',
|
|
146
|
+
site_name: 'test_site',
|
|
147
|
+
size: 10,
|
|
148
|
+
};
|
|
149
|
+
const bQuery = buildQuery(query3, params);
|
|
150
|
+
expect(bQuery).toEqual(built_query3);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe('test parsing the response from elasticsearch for correct response', () => {
|
|
155
|
+
it('should return last_started and next_execution_date', () => {
|
|
156
|
+
const resp = getlastandnext_started_execution(
|
|
157
|
+
last_scheduled_started_indexing_resp,
|
|
158
|
+
);
|
|
159
|
+
expect(resp).toEqual({
|
|
160
|
+
last_started: 1695732613000,
|
|
161
|
+
next_execution_date: 1695732900000,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should return last_started and next_execution_date of failed task', () => {
|
|
166
|
+
const resp = getlastfailed_execution(
|
|
167
|
+
failed_scheduled_atempts_since_last_started_resp,
|
|
168
|
+
);
|
|
169
|
+
expect(resp).toEqual({
|
|
170
|
+
last_started: 1695732613000,
|
|
171
|
+
next_execution_date: 1695732900000,
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('should return list of clusters', () => {
|
|
176
|
+
const resp = getlastsynctaskssincestarted(
|
|
177
|
+
last_sync_task_since_last_start_resp,
|
|
178
|
+
);
|
|
179
|
+
expect(resp).toEqual({ sites: ['test_site1', 'test_site2'] });
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('if the last task for a site did not fail, return "OK"', async () => {
|
|
183
|
+
const resp = await getlatesttasks_for_site(latest_tasks_for_site_resp);
|
|
184
|
+
expect(resp).toEqual('OK');
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('if the last task for a site was succesful, return true', async () => {
|
|
188
|
+
const resp = getlastsuccessfultasks_for_site(
|
|
189
|
+
started_or_finished_site_since_last_started_resp,
|
|
190
|
+
);
|
|
191
|
+
expect(resp).toEqual(true);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe('test parsing the response from elasticsearch for empty response', () => {
|
|
196
|
+
it('should return no results', () => {
|
|
197
|
+
try {
|
|
198
|
+
getlastandnext_started_execution(empty_resp);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
expect(e.message).toEqual('no results');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should return no results', () => {
|
|
205
|
+
try {
|
|
206
|
+
getlastfailed_execution(empty_resp);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
expect(e.message).toEqual('no results');
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should return list of clusters', () => {
|
|
213
|
+
try {
|
|
214
|
+
getlastsynctaskssincestarted(empty_resp);
|
|
215
|
+
} catch (e) {
|
|
216
|
+
expect(e.message).toEqual('no results');
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('if the last task for a site did not fail, return "OK"', async () => {
|
|
221
|
+
try {
|
|
222
|
+
await getlatesttasks_for_site(empty_resp);
|
|
223
|
+
} catch (e) {
|
|
224
|
+
expect(e.message).toEqual('Failed to get info');
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("if the can't take the status for the last task for a site, return false", async () => {
|
|
229
|
+
const resp = getlastsuccessfultasks_for_site(empty_resp);
|
|
230
|
+
expect(resp).toEqual(false);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('test the status of the index', () => {
|
|
235
|
+
it('test', async () => {
|
|
236
|
+
runRequest
|
|
237
|
+
.mockReturnValueOnce(
|
|
238
|
+
Promise.resolve({ body: last_scheduled_started_indexing_resp }),
|
|
239
|
+
)
|
|
240
|
+
.mockReturnValueOnce(
|
|
241
|
+
Promise.resolve({
|
|
242
|
+
body: failed_scheduled_atempts_since_last_started_resp,
|
|
243
|
+
}),
|
|
244
|
+
)
|
|
245
|
+
.mockReturnValueOnce(
|
|
246
|
+
Promise.resolve({
|
|
247
|
+
body: last_sync_task_since_last_start_resp,
|
|
248
|
+
}),
|
|
249
|
+
// )
|
|
250
|
+
// .mockReturnValueOnce(
|
|
251
|
+
// Promise.resolve({
|
|
252
|
+
// body: started_or_finished_site_since_last_started_resp,
|
|
253
|
+
// }),
|
|
254
|
+
);
|
|
255
|
+
const params = { index_name: 'test_index', now: 1695732000000 };
|
|
256
|
+
const status = await getStatus({}, params);
|
|
257
|
+
expect(status).toEqual({ status: 'OK' });
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('test the healthcheck', () => {
|
|
262
|
+
it('test', async () => {
|
|
263
|
+
runRequest
|
|
264
|
+
.mockReturnValueOnce(
|
|
265
|
+
Promise.resolve({ body: { hits: { total: { value: 60001 } } } }),
|
|
266
|
+
)
|
|
267
|
+
.mockReturnValueOnce(
|
|
268
|
+
Promise.resolve({
|
|
269
|
+
body: {
|
|
270
|
+
elapsed: {
|
|
271
|
+
step1: [{ query: { delta: 0.5 } }],
|
|
272
|
+
step2: [{ query: { delta: 0.6 } }],
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
.mockReturnValueOnce(
|
|
279
|
+
Promise.resolve({ body: last_scheduled_started_indexing_resp }),
|
|
280
|
+
)
|
|
281
|
+
.mockReturnValueOnce(
|
|
282
|
+
Promise.resolve({
|
|
283
|
+
body: failed_scheduled_atempts_since_last_started_resp,
|
|
284
|
+
}),
|
|
285
|
+
)
|
|
286
|
+
.mockReturnValueOnce(
|
|
287
|
+
Promise.resolve({
|
|
288
|
+
body: last_sync_task_since_last_start_resp,
|
|
289
|
+
}),
|
|
290
|
+
)
|
|
291
|
+
.mockReturnValueOnce(
|
|
292
|
+
Promise.resolve({
|
|
293
|
+
body: started_or_finished_site_since_last_started_resp,
|
|
294
|
+
}),
|
|
295
|
+
);
|
|
296
|
+
const params = { index_name: 'test_index', now: 1695732000000 };
|
|
297
|
+
const status = await healthcheck({}, params);
|
|
298
|
+
expect(status).toEqual({ status: 'OK' });
|
|
299
|
+
});
|
|
300
|
+
});
|