Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Acceleration components' data implementation #1521

Merged
merged 37 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
8abb624
1st commit of acc details connection
RyanL1997 Mar 11, 2024
a83db79
Update the snapshot
RyanL1997 Mar 11, 2024
39e3c8d
Fix the interface naming
RyanL1997 Mar 12, 2024
029d99a
Fix the status
RyanL1997 Mar 12, 2024
af82830
Add the index health
RyanL1997 Mar 12, 2024
79bd943
Add change the field name into action
RyanL1997 Mar 12, 2024
ffeaff0
Wired up schema tab
RyanL1997 Mar 12, 2024
c3a5480
Cache is working 0 with max depth exceeding issue
RyanL1997 Mar 12, 2024
d2f9aca
update snapshots
RyanL1997 Mar 12, 2024
b348d61
Fix the infinite loop and apply the status check correctly
RyanL1997 Mar 12, 2024
59f84ec
Implement the refresh button
RyanL1997 Mar 13, 2024
0f070ea
Rebase after apply new interface 1
RyanL1997 Mar 13, 2024
862588f
Rebase after apply new interface 2 + finalize the design of refreshin…
RyanL1997 Mar 13, 2024
a1603bb
refactor some comments
RyanL1997 Mar 13, 2024
00344af
Fix table type column
RyanL1997 Mar 13, 2024
0eb1367
Fix empty item with replacement of unredered -
RyanL1997 Mar 13, 2024
1cacffb
Fix the destination index column
RyanL1997 Mar 13, 2024
d0dbf84
Fix status
RyanL1997 Mar 13, 2024
3f35684
Fix the skip index name
RyanL1997 Mar 13, 2024
69b96ac
Fix the destination index column behavior when it is skip index
RyanL1997 Mar 13, 2024
2ace166
Correct the render behavior for skip index flyout
RyanL1997 Mar 13, 2024
5361670
Fix the table loading infinite loop
RyanL1997 Mar 13, 2024
21719c1
Modify the behavior of getting this refreh interval and type for skip…
RyanL1997 Mar 13, 2024
c9a44a3
Fix the data source at the flyout details tab
RyanL1997 Mar 13, 2024
a0c1110
Swtich the data connection tabs back to default order and update snap…
RyanL1997 Mar 13, 2024
037dc39
Add refresh time for refreshing
RyanL1997 Mar 14, 2024
aeed334
Add loading panel 0
RyanL1997 Mar 14, 2024
d083ea5
Fix loading state for table
RyanL1997 Mar 14, 2024
b655691
Add the refresh type column to acceleration table
RyanL1997 Mar 14, 2024
03ec8a6
Add acceleration table test
RyanL1997 Mar 14, 2024
1a005da
Add acceleration table test 2
RyanL1997 Mar 14, 2024
fae047e
Add refresh field to flyout
RyanL1997 Mar 14, 2024
2dfdd4f
Fix some comments
RyanL1997 Mar 14, 2024
9bb4b4d
Fix some comments 2
RyanL1997 Mar 14, 2024
1a29564
Add null/undefined check for flintIndexName
RyanL1997 Mar 14, 2024
e5597d7
remove console logs
RyanL1997 Mar 14, 2024
ac69e52
Add eslint-dsiable for export in dsl
RyanL1997 Mar 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const DSL_BASE = '/api/dsl';
export const DSL_SEARCH = '/search';
export const DSL_CAT = '/cat.indices';
export const DSL_MAPPING = '/indices.getFieldMapping';
export const DSL_SETTINGS = '/indices.getFieldSettings';
export const OBSERVABILITY_BASE = '/api/observability';
export const INTEGRATIONS_BASE = '/api/integrations';
export const JOBS_BASE = '/query/jobs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,7 @@ exports[`Panels View Component renders panel view container with visualizations
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -1754,6 +1755,7 @@ exports[`Panels View Component renders panel view container with visualizations
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -3520,6 +3522,7 @@ exports[`Panels View Component renders panel view container without visualizatio
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down Expand Up @@ -3985,6 +3988,7 @@ exports[`Panels View Component renders panel view container without visualizatio
"fetch": [Function],
"fetchFields": [Function],
"fetchIndices": [Function],
"fetchSettings": [Function],
"http": [MockFunction],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { mount, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { AccelerationDetailsFlyout } from '../manage/accelerations/acceleration_details_flyout';
import * as coreRefsModule from '../../../../framework/core_refs';

jest.mock('../../../../framework/core_refs', () => {
const actualModule = jest.requireActual('../../../../framework/core_refs');
return {
coreRefs: {
...actualModule.coreRefs,
dslService: {
fetchFields: jest.fn().mockResolvedValue({ data: 'mockFieldData' }),
fetchSettings: jest.fn().mockResolvedValue({ data: 'mockSettingsData' }),
fetchIndices: jest.fn().mockResolvedValue({ data: 'mockIndexData' }),
},
},
};
});

jest.mock('../../../../framework/core_refs', () => {
return {
coreRefs: {
dslService: {
fetchFields: jest.fn().mockResolvedValue({ data: 'mockFieldData' }),
fetchSettings: jest.fn().mockResolvedValue({ data: 'mockSettingsData' }),
fetchIndices: jest.fn().mockResolvedValue({
status: 'fulfilled',
action: 'getIndexInfo',
data: [
{
health: 'yellow',
status: 'open',
index: 'flint_mys3_default_http_count_view',
uuid: 'VImREbK4SMqJ-i6hSB84eQ',
pri: '1',
rep: '1',
'docs.count': '0',
'docs.deleted': '0',
'store.size': '208b',
'pri.store.size': '208b',
},
],
}),
},
},
};
});

const mockAcceleration = {
index: 'mockIndex',
dataSourceName: 'mockDataSource',
acceleration: {
flintIndexName: 'testIndex',
},
};

configure({ adapter: new Adapter() });

describe('AccelerationDetailsFlyout Component Tests', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('fetches acceleration details on mount', async () => {
mount(<AccelerationDetailsFlyout acceleration={mockAcceleration} />);

expect(coreRefsModule.coreRefs.dslService!.fetchFields).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchSettings).toHaveBeenCalledWith('testIndex');
expect(coreRefsModule.coreRefs.dslService!.fetchIndices).toHaveBeenCalledWith('testIndex');
});

it('switches tabs correctly', async () => {
const wrapper = mount(<AccelerationDetailsFlyout acceleration={mockAcceleration} />);
await new Promise(setImmediate);
wrapper.update();

const schemaTabExists = wrapper.find('EuiTab').someWhere((node) => node.text() === 'Schema');
expect(schemaTabExists).toBeTruthy();

const schemaTab = wrapper.find('EuiTab').filterWhere((node) => node.text() === 'Schema');
schemaTab.simulate('click');
await new Promise(setImmediate);
wrapper.update();

expect(wrapper.find('AccelerationSchemaTab').exists()).toBe(true);

// TODO: SQL DEFINATION TAB CHECK
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { mount, configure } from 'enzyme';
import { EuiLoadingSpinner } from '@elastic/eui';
import { AccelerationTable } from '../manage/accelerations/acceleration_table';
import { act } from 'react-dom/test-utils';
import Adapter from 'enzyme-adapter-react-16';
import { ACC_LOADING_MSG } from '../manage/accelerations/utils/acceleration_utils';
import { ReactWrapper } from 'enzyme';

const accelerationCache = {
accelerations: [
{
flintIndexName: 'flint_mys3_default_http_count_view',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_count_view',
autoRefresh: true,
status: 'refreshing',
},
{
flintIndexName: 'flint_mys3_default_http_count_view_alt',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_count_view_alt',
autoRefresh: true,
status: 'refreshing',
},
{
flintIndexName: 'flint_mys3_default_http_logs',
type: 'materialized',
database: 'default',
table: null,
indexName: 'http_logs',
autoRefresh: true,
status: 'deleted',
},
{
flintIndexName: 'flint_mys3_default_http_logs_skipping_index',
type: 'skipping',
database: 'default',
table: 'http_logs',
indexName: null,
autoRefresh: false,
status: 'active',
},
{
flintIndexName: 'flint_mys3_other_http_count_view',
type: 'materialized',
database: 'other',
table: null,
indexName: 'http_count_view',
autoRefresh: true,
status: 'refreshing',
},
],
lastUpdated: 'Thu, 14 Mar 2024 04:05:53 GMT',
status: 'Updated',
};

jest.mock('../../../../framework/catalog_cache/cache_manager', () => ({
CatalogCacheManager: {
getOrCreateAccelerationsByDataSource: jest.fn().mockReturnValue(accelerationCache),
},
}));

jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'success',
startLoading: jest.fn(),
})),
}));

jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() => jest.fn()),
}));

describe('AccelerationTable Component', () => {
configure({ adapter: new Adapter() });

it('renders without crashing', () => {
const wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
expect(wrapper).toBeDefined();
});

it('shows loading spinner when refreshing accelerations', async () => {
jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'loading',
startLoading: jest.fn(),
})),
}));

let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});

wrapper!.update();

await act(async () => {
wrapper!.find('[data-test-subj="refreshButton"]').simulate('click');
});
wrapper!.update();

expect(wrapper!.find(EuiLoadingSpinner).exists()).toBe(true);
expect(wrapper!.text()).toContain(ACC_LOADING_MSG);

jest.restoreAllMocks();
});

it('correctly displays accelerations in the table', async () => {
let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});
wrapper!.update();

const tableRows = wrapper!.find('EuiTableRow');
expect(tableRows.length).toBe(accelerationCache.accelerations.length);
});

it('filters rows based on active status correctly', async () => {
jest.mock('../../../../framework/catalog_cache/cache_loader', () => ({
useLoadAccelerationsToCache: jest.fn(() => ({
loadStatus: 'loading',
startLoading: jest.fn(),
})),
}));

let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
await new Promise((resolve) => setTimeout(resolve, 0));
wrapper!.update();
});

const activeStatusRows = wrapper!.find('tr.euiTableRow').filterWhere((node) => {
return node.find('.euiFlexItem').someWhere((subNode) => subNode.text() === 'active');
});

expect(activeStatusRows.length).toBe(
accelerationCache.accelerations.filter((acc) => acc.status === 'active').length
);
jest.restoreAllMocks();
});

it('displays updated time correctly', async () => {
let wrapper: ReactWrapper;
await act(async () => {
wrapper = mount(<AccelerationTable dataSourceName="testDataSource" />);
});
wrapper!.update();

expect(wrapper!.text()).toContain(accelerationCache.lastUpdated);
});
});
Loading
Loading