|
8 | 8 | import { act } from 'react-dom/test-utils'; |
9 | 9 |
|
10 | 10 | import { API_BASE_PATH } from '../../../common/constants'; |
11 | | -import type { MlAction } from '../../../common/types'; |
| 11 | +import type { |
| 12 | + ESUpgradeStatus, |
| 13 | + EnrichedDeprecationInfo, |
| 14 | + MlAction, |
| 15 | + ReindexAction, |
| 16 | + UnfreezeAction, |
| 17 | +} from '../../../common/types'; |
12 | 18 | import { setupEnvironment } from '../helpers'; |
13 | 19 | import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers'; |
14 | 20 | import { |
@@ -310,4 +316,234 @@ describe('ES deprecations table', () => { |
310 | 316 | ); |
311 | 317 | }); |
312 | 318 | }); |
| 319 | + |
| 320 | + describe('recommended actions for indices', () => { |
| 321 | + it('recommends set unfreeze if index is frozen', async () => { |
| 322 | + httpRequestsMockHelpers.setLoadEsDeprecationsResponse({ |
| 323 | + ...esDeprecationsMockResponse, |
| 324 | + migrationsDeprecations: esDeprecationsMockResponse.migrationsDeprecations.map( |
| 325 | + (deprecation) => |
| 326 | + deprecation === esDeprecationsMockResponse.migrationsDeprecations[3] |
| 327 | + ? ({ |
| 328 | + level: 'critical', |
| 329 | + resolveDuringUpgrade: false, |
| 330 | + type: 'index_settings', |
| 331 | + message: 'Index created before 7.0', |
| 332 | + details: 'deprecation details', |
| 333 | + url: 'doc_url', |
| 334 | + index: 'reindex_index', |
| 335 | + correctiveAction: { |
| 336 | + type: 'unfreeze', |
| 337 | + metadata: { |
| 338 | + isClosedIndex: false, |
| 339 | + isFrozenIndex: true, |
| 340 | + isInDataStream: false, |
| 341 | + }, |
| 342 | + } as UnfreezeAction, |
| 343 | + } as EnrichedDeprecationInfo) |
| 344 | + : deprecation |
| 345 | + ), |
| 346 | + } as ESUpgradeStatus); |
| 347 | + |
| 348 | + await act(async () => { |
| 349 | + testBed = await setupElasticsearchPage(httpSetup); |
| 350 | + }); |
| 351 | + testBed.component.update(); |
| 352 | + |
| 353 | + const { find } = testBed; |
| 354 | + |
| 355 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 356 | + expect(find('reindexTableCell-correctiveAction').text()).toContain('Recommended: unfreeze'); |
| 357 | + }); |
| 358 | + it('recommends set as read-only if index is a follower index', async () => { |
| 359 | + httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', { |
| 360 | + reindexOp: null, |
| 361 | + warnings: [], |
| 362 | + hasRequiredPrivileges: true, |
| 363 | + meta: { |
| 364 | + indexName: 'follower-index', |
| 365 | + reindexName: 'reindexed-follower-index', |
| 366 | + aliases: [], |
| 367 | + isFrozen: false, |
| 368 | + isReadonly: false, |
| 369 | + isInDataStream: false, |
| 370 | + isFollowerIndex: true, |
| 371 | + }, |
| 372 | + }); |
| 373 | + |
| 374 | + await act(async () => { |
| 375 | + testBed = await setupElasticsearchPage(httpSetup); |
| 376 | + }); |
| 377 | + |
| 378 | + testBed.component.update(); |
| 379 | + |
| 380 | + const { find } = testBed; |
| 381 | + |
| 382 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 383 | + expect(find('reindexTableCell-correctiveAction').text()).toContain( |
| 384 | + 'Recommended: set to read-only' |
| 385 | + ); |
| 386 | + }); |
| 387 | + |
| 388 | + it('recommends set as read-only if index is bigger than 1GB', async () => { |
| 389 | + httpRequestsMockHelpers.setLoadEsDeprecationsResponse({ |
| 390 | + ...esDeprecationsMockResponse, |
| 391 | + migrationsDeprecations: esDeprecationsMockResponse.migrationsDeprecations.map( |
| 392 | + (deprecation) => |
| 393 | + deprecation === esDeprecationsMockResponse.migrationsDeprecations[3] |
| 394 | + ? ({ |
| 395 | + level: 'critical', |
| 396 | + resolveDuringUpgrade: false, |
| 397 | + type: 'index_settings', |
| 398 | + message: 'Index created before 7.0', |
| 399 | + details: 'deprecation details', |
| 400 | + url: 'doc_url', |
| 401 | + index: 'reindex_index', |
| 402 | + correctiveAction: { |
| 403 | + type: 'reindex', |
| 404 | + indexSizeInBytes: 1173741824, // > 1GB |
| 405 | + metadata: { |
| 406 | + isClosedIndex: false, |
| 407 | + isFrozenIndex: false, |
| 408 | + isInDataStream: false, |
| 409 | + }, |
| 410 | + } as ReindexAction, |
| 411 | + } as EnrichedDeprecationInfo) |
| 412 | + : deprecation |
| 413 | + ), |
| 414 | + } as ESUpgradeStatus); |
| 415 | + |
| 416 | + httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', { |
| 417 | + reindexOp: null, |
| 418 | + warnings: [], |
| 419 | + hasRequiredPrivileges: true, |
| 420 | + meta: { |
| 421 | + indexName: 'large-index', |
| 422 | + reindexName: 'reindexed-large-index', |
| 423 | + aliases: [], |
| 424 | + isFrozen: false, |
| 425 | + isReadonly: false, |
| 426 | + isInDataStream: false, |
| 427 | + isFollowerIndex: false, |
| 428 | + }, |
| 429 | + }); |
| 430 | + |
| 431 | + await act(async () => { |
| 432 | + testBed = await setupElasticsearchPage(httpSetup); |
| 433 | + }); |
| 434 | + testBed.component.update(); |
| 435 | + |
| 436 | + const { find } = testBed; |
| 437 | + |
| 438 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 439 | + expect(find('reindexTableCell-correctiveAction').text()).toContain( |
| 440 | + 'Recommended: set to read-only' |
| 441 | + ); |
| 442 | + }); |
| 443 | + |
| 444 | + it('recommends reindexing if index is already read-only', async () => { |
| 445 | + httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', { |
| 446 | + reindexOp: null, |
| 447 | + warnings: [], |
| 448 | + hasRequiredPrivileges: true, |
| 449 | + meta: { |
| 450 | + indexName: 'readonly-index', |
| 451 | + reindexName: 'reindexed-readonly-index', |
| 452 | + aliases: [], |
| 453 | + isFrozen: false, |
| 454 | + isReadonly: true, |
| 455 | + isInDataStream: false, |
| 456 | + isFollowerIndex: false, |
| 457 | + }, |
| 458 | + }); |
| 459 | + |
| 460 | + await act(async () => { |
| 461 | + testBed = await setupElasticsearchPage(httpSetup); |
| 462 | + }); |
| 463 | + |
| 464 | + testBed.component.update(); |
| 465 | + |
| 466 | + const { find } = testBed; |
| 467 | + |
| 468 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 469 | + expect(find('reindexTableCell-correctiveAction').text()).toContain('Recommended: reindex'); |
| 470 | + }); |
| 471 | + |
| 472 | + it('recommends set as read-only if reindexing is excluded', async () => { |
| 473 | + httpRequestsMockHelpers.setLoadEsDeprecationsResponse({ |
| 474 | + ...esDeprecationsMockResponse, |
| 475 | + migrationsDeprecations: esDeprecationsMockResponse.migrationsDeprecations.map( |
| 476 | + (deprecation) => |
| 477 | + deprecation === esDeprecationsMockResponse.migrationsDeprecations[3] |
| 478 | + ? ({ |
| 479 | + level: 'critical', |
| 480 | + resolveDuringUpgrade: false, |
| 481 | + type: 'index_settings', |
| 482 | + message: 'Index created before 7.0', |
| 483 | + details: 'deprecation details', |
| 484 | + url: 'doc_url', |
| 485 | + index: 'reindex_index', |
| 486 | + correctiveAction: { |
| 487 | + type: 'reindex', |
| 488 | + excludedActions: ['readOnly'], |
| 489 | + metadata: { |
| 490 | + isClosedIndex: false, |
| 491 | + isFrozenIndex: false, |
| 492 | + isInDataStream: false, |
| 493 | + }, |
| 494 | + } as ReindexAction, |
| 495 | + } as EnrichedDeprecationInfo) |
| 496 | + : deprecation |
| 497 | + ), |
| 498 | + } as ESUpgradeStatus); |
| 499 | + |
| 500 | + httpRequestsMockHelpers.setReindexStatusResponse('reindex_index', { |
| 501 | + reindexOp: null, |
| 502 | + warnings: [], |
| 503 | + hasRequiredPrivileges: true, |
| 504 | + meta: { |
| 505 | + indexName: 'excluded-index', |
| 506 | + reindexName: 'reindexed-excluded-index', |
| 507 | + aliases: [], |
| 508 | + isFrozen: false, |
| 509 | + isReadonly: false, |
| 510 | + isInDataStream: false, |
| 511 | + isFollowerIndex: false, |
| 512 | + }, |
| 513 | + }); |
| 514 | + |
| 515 | + await act(async () => { |
| 516 | + testBed = await setupElasticsearchPage(httpSetup); |
| 517 | + }); |
| 518 | + testBed.component.update(); |
| 519 | + |
| 520 | + const { find } = testBed; |
| 521 | + |
| 522 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 523 | + expect(find('reindexTableCell-correctiveAction').text()).toContain('Recommended: reindex'); |
| 524 | + }); |
| 525 | + |
| 526 | + it('recommends reindexing by default', async () => { |
| 527 | + const { find } = testBed; |
| 528 | + expect(find('reindexTableCell-correctiveAction').length).toBe(1); |
| 529 | + expect(find('reindexTableCell-correctiveAction').text()).toContain('Recommended: reindex'); |
| 530 | + }); |
| 531 | + }); |
| 532 | + describe('recommended actions for data streams', () => { |
| 533 | + it('recommends read-only by default', async () => { |
| 534 | + const { find } = testBed; |
| 535 | + |
| 536 | + expect(find('dataStreamReindexTableCell-correctiveAction').at(0).text()).toContain( |
| 537 | + 'Recommended: set to read-only' |
| 538 | + ); |
| 539 | + }); |
| 540 | + |
| 541 | + it('recommends reindexing if read-only is excluded', async () => { |
| 542 | + const { find } = testBed; |
| 543 | + |
| 544 | + expect(find('dataStreamReindexTableCell-correctiveAction').at(1).text()).toContain( |
| 545 | + 'Recommended: reindex' |
| 546 | + ); |
| 547 | + }); |
| 548 | + }); |
313 | 549 | }); |
0 commit comments