-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathindices_spec.js
More file actions
722 lines (614 loc) · 21.7 KB
/
Copy pathindices_spec.js
File metadata and controls
722 lines (614 loc) · 21.7 KB
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import {
BASE_PATH,
IM_PLUGIN_NAME,
BACKEND_BASE_PATH,
} from '../../../utils/constants';
import samplePolicy from '../../../fixtures/plugins/index-management-dashboards-plugin/sample_policy';
const POLICY_ID = 'test_policy_id';
const SAMPLE_INDEX = 'sample_index';
describe('Indices', () => {
beforeEach(() => {
// Set welcome screen tracking to false
localStorage.setItem('home:welcome:show', 'false');
// Visit ISM OSD
cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/indices`);
// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains('Rows per page', { timeout: 60000 });
});
describe('can be searched', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.deleteIMJobs();
// Create 20+ indices that can be sorted alphabetically by using letters a-z
for (let i = 97; i < 123; i++) {
const char = String.fromCharCode(i);
cy.createIndex(`index_${char}`);
}
});
it('successfully', () => {
// Get the index table header and click it to sort
cy.get('thead > tr > th').contains('Index').click({ force: true });
// Confirm we have index_a in view and not index_z
cy.contains('index_a');
cy.contains('index_z').should('not.exist');
// Type in index_z in search input
cy.get(`input[type="search"]`).focus().type('index_z');
// Confirm we only see index_z in table
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
expect($tr, 'item').to.contain('index_z');
});
});
});
describe('can show data stream indices', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.deleteDataStreams('*');
cy.createIndexTemplate('logs-template', {
index_patterns: ['logs-*'],
data_stream: {},
});
// Create sample regular indices.
cy.createIndex('index-1');
cy.createIndex('index-2');
// Create sample data streams.
cy.createDataStream('logs-nginx');
cy.createDataStream('logs-haproxy');
cy.createDataStream('logs-redis');
cy.rollover('logs-redis');
});
it('successfully', () => {
cy.get('[data-test-subj="tablePaginationPopoverButton"]').click();
cy.get('.euiContextMenuItem__text').contains('50 rows').click();
// Confirm that the regular indices are shown.
cy.contains('index-1');
cy.contains('index-2');
// Confirm that the data stream indices are not shown by default.
cy.contains('.ds-logs-nginx-000001').should('not.exist');
cy.contains('.ds-logs-haproxy-000001').should('not.exist');
// Confirm that "Show data stream indices" toggle switch works.
cy.get(`[data-test-subj="toggleShowDataStreams"]`).click({ force: true });
cy.contains('.ds-logs-nginx-000001');
cy.contains('.ds-logs-haproxy-000001');
// Confirm that data stream indices can be searched.
cy.get(`input[type="search"]`).focus().type('logs-redis');
cy.get('tbody > tr').should(($tr) => {
expect($tr, '2 rows').to.have.length(2);
expect($tr, 'item').to.contain('.ds-logs-redis-000001');
expect($tr, 'item').to.contain('.ds-logs-redis-000002');
});
cy.get(`button[aria-label="Clear input"]`).first().click({ force: true });
// Confirm that data streams can be selected from dropdown.
cy.get(`span[data-text="Data streams"]`).first().click({ force: true });
cy.get('.euiFilterSelect__items').should(($tr) => {
expect($tr, 'item').to.contain('logs-nginx');
expect($tr, 'item').to.contain('logs-haproxy');
expect($tr, 'item').to.contain('logs-redis');
});
// Select data streams from the list.
cy.get('.euiFilterSelect__items')
.contains('logs-nginx')
.click({ force: true });
cy.get('.euiFilterSelect__items')
.contains('logs-haproxy')
.click({ force: true });
cy.get(`span[data-text="Data streams"]`).first().click({ force: true });
cy.get('tbody > tr').should(($tr) => {
expect($tr, '2 rows').to.have.length(2);
expect($tr, 'item').to.contain('.ds-logs-nginx-000001');
expect($tr, 'item').to.contain('.ds-logs-haproxy-000001');
});
});
});
describe('can have policies applied', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createPolicy(POLICY_ID, samplePolicy);
cy.createIndex(SAMPLE_INDEX);
});
it('successfully', () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
// Confirm our initial index is not currently managed
cy.get(`tbody > tr:contains("${SAMPLE_INDEX}") > td`)
.filter(`:nth-child(4)`)
.contains('No');
// Select checkbox for our index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({
force: true,
});
// Click apply policy button
cy.get('[data-test-subj="moreAction"]').click();
cy.get(`[data-test-subj="Apply policyButton"]`).click({ force: true });
cy.get(`input[data-test-subj="comboBoxSearchInput"]`)
.click()
.type(POLICY_ID);
// Click the policy option
cy.get(`button[role="option"]`).first().click({ force: true });
cy.contains('A simple description');
cy.get(`[data-test-subj="applyPolicyModalEditButton"]`).click({
force: true,
});
// Wait some time for apply policy to execute before reload
cy.wait(3000).reload();
cy.contains(SAMPLE_INDEX, { timeout: 20000 });
// Confirm our index is now being managed
cy.get(`tbody > tr:contains("${SAMPLE_INDEX}") > td`)
.filter(`:nth-child(4)`)
.contains('Yes');
// Confirm the information shows in detail modal
cy.get(
`[data-test-subj="viewIndexDetailButton-${SAMPLE_INDEX}"]`
).click();
cy.get(
`[data-test-subj="indexDetailOverviewItem-Managed by policy"] .euiDescriptionList__description a`
).contains(POLICY_ID);
});
});
describe('can make indices deleted', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createIndex(SAMPLE_INDEX);
});
it('successfully', () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
// Click actions button
cy.get('[data-test-subj="moreAction"]').click();
// Delete btn should be disabled if no items selected
cy.get('[data-test-subj="deleteAction"]').should(
'have.class',
'euiContextMenuItem-isDisabled'
);
// click any where to hide actions
cy.get('#_selection_column_sample_index-checkbox').click();
cy.get('[data-test-subj="deleteAction"]').should('not.exist');
// Click actions button
cy.get('[data-test-subj="moreAction"]').click();
// Delete btn should be enabled
cy.get('[data-test-subj="deleteAction"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// The confirm button should be disabled
cy.get('[data-test-subj="Delete Confirm button"]').should(
'have.class',
'euiButton-isDisabled'
);
cy.wait(1000);
// type delete
cy.get('[placeholder="delete"]').type('delete');
cy.get('[data-test-subj="Delete Confirm button"]').should(
'not.have.class',
'euiContextMenuItem-isDisabled'
);
// click to delete
cy.get('[data-test-subj="Delete Confirm button"]').click();
// the sample_index should not exist
cy.wait(500);
cy.get('#_selection_column_sample_index-checkbox').should('not.exist');
});
});
describe('shows detail of a index when click the item', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createIndex(SAMPLE_INDEX);
});
it('successfully', () => {
cy.get(
`[data-test-subj="viewIndexDetailButton-${SAMPLE_INDEX}"]`
).click();
cy.get(
`[data-test-subj="indexDetailOverviewItem-Index name"] .euiDescriptionList__description > span`
).should('have.text', SAMPLE_INDEX);
});
});
describe('can search with reindex & recovery status', () => {
const reindexedIndex = `${Date.now()}_reindex_sample_data_ecommerce`;
const splittedIndex = 'split_opensearch_dashboards_sample_data_logs';
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
// Visit ISM OSD
cy.visit(`${BASE_PATH}/app/${IM_PLUGIN_NAME}#/indices`);
// Common text to wait for to confirm page loaded, give up to 60 seconds for initial load
cy.contains('Rows per page', { timeout: 60000 });
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/sample_data/ecommerce`,
headers: {
'osd-xsrf': true,
},
}).then((response) => {
expect(response.status).equal(200);
});
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/sample_data/logs`,
headers: {
'osd-xsrf': true,
},
}).then((response) => {
expect(response.status).equal(200);
});
cy.request({
method: 'PUT',
url: `${BACKEND_BASE_PATH}/${splittedIndex}/_settings`,
body: {
'index.blocks.read_only': false,
},
failOnStatusCode: false,
});
cy.request({
method: 'DELETE',
url: `${BACKEND_BASE_PATH}/${reindexedIndex}`,
failOnStatusCode: false,
});
cy.request({
method: 'DELETE',
url: `${BACKEND_BASE_PATH}/${splittedIndex}`,
failOnStatusCode: false,
});
});
it('Successfully', () => {
cy.request({
method: 'PUT',
url: `${BACKEND_BASE_PATH}/${reindexedIndex}`,
body: {
settings: {
index: {
number_of_shards: 1,
number_of_replicas: '0',
},
},
},
});
// do a simple reindex
cy.request(
'POST',
`${BACKEND_BASE_PATH}/_reindex?wait_for_completion=false`,
{
source: {
index: 'opensearch_dashboards_sample_data_ecommerce',
},
dest: {
index: reindexedIndex,
},
}
);
cy.get('[placeholder="Search"]').type('o');
// do a simple split
cy.request(
'PUT',
`${BACKEND_BASE_PATH}/opensearch_dashboards_sample_data_logs/_settings`,
{
'index.blocks.write': true,
}
);
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/ism/apiCaller`,
headers: {
'osd-xsrf': true,
},
body: {
endpoint: 'indices.split',
data: {
index: 'opensearch_dashboards_sample_data_logs',
target: splittedIndex,
body: {
settings: {
index: {
number_of_shards: 2,
},
},
},
},
},
});
cy.get('[placeholder="Search"]').type('p');
});
after(() => {
cy.request({
method: 'DELETE',
url: `${BACKEND_BASE_PATH}/${reindexedIndex}`,
failOnStatusCode: false,
});
cy.request({
method: 'DELETE',
url: `${BACKEND_BASE_PATH}/${splittedIndex}`,
failOnStatusCode: false,
});
});
});
describe('can shrink an index', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createIndex(SAMPLE_INDEX, null, {
settings: {
'index.blocks.write': true,
'index.number_of_shards': 2,
'index.number_of_replicas': 0,
},
});
});
it('successfully shrink an index', () => {
// Type in SAMPLE_INDEX in search input
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);
cy.wait(1000).get('.euiTableRow').should('have.length', 1);
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
cy.get('[data-test-subj="moreAction"]').click();
// Shrink btn should be disabled if no items selected
cy.get('[data-test-subj="Shrink Action"]').should(
'have.class',
'euiContextMenuItem-isDisabled'
);
// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({
force: true,
});
cy.get('[data-test-subj="moreAction"]').click();
// Shrink btn should be enabled
cy.get('[data-test-subj="Shrink Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for Shrink page
cy.contains('Shrink index');
// Enter target index name
cy.get(`input[data-test-subj="targetIndexNameInput"]`).type(
`${SAMPLE_INDEX}_shrunken`
);
// Click shrink index button
cy.get('button').contains('Shrink').click({ force: true });
// Check for success toast
cy.contains(
`Successfully started shrinking ${SAMPLE_INDEX}. The shrunken index will be named ${SAMPLE_INDEX}_shrunken.`
);
});
});
describe('can close and open an index', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createIndex(SAMPLE_INDEX);
});
it('successfully close an index', () => {
cy.contains(SAMPLE_INDEX);
cy.get('[data-test-subj="moreAction"]').click();
// Close btn should be disabled if no items selected
cy.get('[data-test-subj="Close Action"]').should(
'have.class',
'euiContextMenuItem-isDisabled'
);
// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({
force: true,
});
cy.get('[data-test-subj="moreAction"]').click();
// Close btn should be enabled
cy.get('[data-test-subj="Close Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for close index modal
cy.contains('Close');
// Close confirm button should be disabled
cy.get('[data-test-subj="Close Confirm button"]').should(
'have.class',
'euiButton-isDisabled'
);
// type close
cy.get('[placeholder="close"]').type('close');
cy.get('[data-test-subj="Close Confirm button"]').should(
'not.have.class',
'euiContextMenuItem-isDisabled'
);
// Click close confirm button
cy.get('[data-test-subj="Close Confirm button"]').click();
// Check for success toast
cy.contains('Close [sample_index] successfully');
// Confirm the index is closed
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
expect($tr, 'item').to.contain('close');
});
});
it('successfully open an index', () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
cy.get('[data-test-subj="moreAction"]').click();
// Open btn should be disabled if no items selected
cy.get('[data-test-subj="Open Action"]').should(
'have.class',
'euiContextMenuItem-isDisabled'
);
// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({
force: true,
});
cy.get('[data-test-subj="moreAction"]').click();
// Open btn should be enabled
cy.get('[data-test-subj="Open Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for open index modal
cy.contains('Open');
cy.get('[data-test-subj="Open Confirm button"]').click();
// Check for success toast
cy.contains(/sample_index have been opened/);
// Confirm the index is open
cy.get(`input[type="search"]`).focus().type(SAMPLE_INDEX);
cy.get('tbody > tr').should(($tr) => {
expect($tr, '1 row').to.have.length(1);
expect($tr, 'item').to.contain('open');
});
});
});
describe('can clear cache for indexes', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
for (let i = 100; i < 105; i++) {
const char = String.fromCharCode(i);
cy.createIndex(`index_${char}`);
}
});
it('successfully clear cache for multiple indexes', () => {
// Select multiple indexes
cy.get(`[data-test-subj="checkboxSelectRow-index_d"]`).check({
force: true,
});
cy.get(`[data-test-subj="checkboxSelectRow-index_e"]`).check({
force: true,
});
cy.get('[data-test-subj="moreAction"]').click();
// Clear cache btn should be enabled
cy.get('[data-test-subj="Clear cache Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for clear cache index modal
cy.contains('Clear cache');
// Click clear cache confirm button
cy.get('[data-test-subj="ClearCacheConfirmButton"]').click();
// Check for success toast
cy.contains(
'Cache for 2 indexes [index_d, index_e] have been successfully cleared.'
);
});
it('successfully clear cache for all indexes', () => {
cy.get('[data-test-subj="moreAction"]').click();
// Clear cache btn should be enabled
cy.get('[data-test-subj="Clear cache Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for clear cache index modal
cy.contains('Clear cache');
// Click clear cache confirm button
cy.get('[data-test-subj="ClearCacheConfirmButton"]').click();
// Check for success toast
cy.contains('Cache for all open indexes have been successfully cleared.');
});
});
describe('can flush index', () => {
before(() => {
cy.deleteAllIndices();
cy.deleteIMJobs();
cy.createIndex(SAMPLE_INDEX);
});
it('successfully flush an index', () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
// index a test doc
cy.request({
method: 'POST',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_doc`,
headers: {
'content-type': 'application/json;charset=UTF-8',
},
body: { test: 'test' },
});
// confirm uncommitted_operations is 1 after indexing doc
cy.request({
method: 'GET',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_stats/translog`,
}).then((response) => {
let response_obj = JSON.parse(
response['allRequestResponses'][0]['Response Body']
);
let num =
response_obj['_all']['total']['translog']['uncommitted_operations'];
expect(num).to.equal(1);
});
// Select an index
cy.get(`[data-test-subj="checkboxSelectRow-${SAMPLE_INDEX}"]`).check({
force: true,
});
cy.get('[data-test-subj="moreAction"]').click();
// Flush btn should be enabled
cy.get('[data-test-subj="Flush Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for flush index modal
cy.contains('Flush indexes');
cy.get('[data-test-subj="flushConfirmButton"]').click();
// Check for success toast
cy.contains(`The index ${SAMPLE_INDEX} has been successfully flushed.`);
// confirm uncommitted_operations is 0 after flush
cy.request({
method: 'GET',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_stats/translog`,
}).then((response) => {
let response_obj = JSON.parse(
response['allRequestResponses'][0]['Response Body']
);
let num =
response_obj['_all']['total']['translog']['uncommitted_operations'];
expect(num).to.equal(0);
});
});
it('successfully flush all index', () => {
// Confirm we have our initial index
cy.contains(SAMPLE_INDEX);
// index a test doc
cy.request({
method: 'POST',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_doc`,
headers: {
'content-type': 'application/json;charset=UTF-8',
},
body: { test: 'test' },
});
// confirm uncommitted_operations is 1 after indexing doc
cy.request({
method: 'GET',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_stats/translog`,
}).then((response) => {
let response_obj = JSON.parse(
response['allRequestResponses'][0]['Response Body']
);
let num =
response_obj['_all']['total']['translog']['uncommitted_operations'];
expect(num).to.equal(1);
});
cy.get('[data-test-subj="moreAction"]').click();
cy.get('[data-test-subj="Flush Action"]')
.should('exist')
.should('not.have.class', 'euiContextMenuItem-isDisabled')
.click();
// Check for flush index modal
cy.contains('Flush indexes');
cy.get('[data-test-subj="flushConfirmButton"]').click();
// Check for success toast
cy.contains(`All open indexes have been successfully flushed.`);
// confirm uncommitted_operations is 0 after flush
cy.request({
method: 'GET',
url: `${Cypress.env('openSearchUrl')}/${SAMPLE_INDEX}/_stats/translog`,
}).then((response) => {
let response_obj = JSON.parse(
response['allRequestResponses'][0]['Response Body']
);
let num =
response_obj['_all']['total']['translog']['uncommitted_operations'];
expect(num).to.equal(0);
});
});
});
});