Skip to content

Commit 2580790

Browse files
author
Kishore Kumaar Natarajan
committed
hide live queries in 3.3 below
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
1 parent 695f165 commit 2580790

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

public/pages/WorkloadManagement/WLMMain/WLMMain.test.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WorkloadManagementMain } from './WLMMain';
1111
import { CoreStart } from 'opensearch-dashboards/public';
1212
import userEvent from '@testing-library/user-event';
1313
import { DataSourceContext } from '../WorkloadManagement';
14+
import * as versionUtils from '../../../utils/version-utils';
1415

1516
jest.mock('echarts-for-react', () => () => <div data-testid="MockedChart">Mocked Chart</div>);
1617
jest.mock('../../../components/PageHeader', () => ({
@@ -63,6 +64,10 @@ beforeEach(() => {
6364
jest.clearAllMocks();
6465
capturedOptions.length = 0;
6566

67+
// Mock version utils
68+
jest.spyOn(versionUtils, 'getVersionOnce').mockResolvedValue('3.3.0');
69+
jest.spyOn(versionUtils, 'isVersion33OrHigher').mockReturnValue(true);
70+
6671
// Restore the data source menu mock after reset
6772
mockDataSourceManagement.ui.getDataSourceMenu.mockReturnValue(MockDataSourceMenu);
6873

@@ -76,6 +81,11 @@ beforeEach(() => {
7681
],
7782
});
7883
}
84+
if (url === '/api/live_queries') {
85+
return Promise.resolve({
86+
response: { live_queries: [] }
87+
});
88+
}
7989
if (url === '/api/_wlm/stats') {
8090
return Promise.resolve({
8191
node1: {
@@ -116,6 +126,12 @@ beforeEach(() => {
116126
},
117127
});
118128
}
129+
if (url === '/api/_wlm/thresholds') {
130+
return Promise.resolve({
131+
cpuRejectionThreshold: 0.8,
132+
memoryRejectionThreshold: 0.8
133+
});
134+
}
119135
});
120136
});
121137

@@ -502,4 +518,26 @@ describe('WorkloadManagementMain', () => {
502518
expect(screen.getByPlaceholderText(/search workload groups/i)).toBeInTheDocument();
503519
});
504520
});
521+
522+
it('does not call Query Insights API when version < 3.3', async () => {
523+
jest.spyOn(versionUtils, 'isVersion33OrHigher').mockReturnValue(false);
524+
525+
renderComponent();
526+
527+
await waitFor(() => {
528+
expect(mockCore.http.get).not.toHaveBeenCalledWith('/api/live_queries', expect.any(Object));
529+
});
530+
});
531+
532+
it('calls Query Insights API when version >= 3.3', async () => {
533+
jest.spyOn(versionUtils, 'isVersion33OrHigher').mockReturnValue(true);
534+
535+
renderComponent();
536+
537+
await waitFor(() => {
538+
expect(mockCore.http.get).toHaveBeenCalledWith('/api/live_queries', expect.objectContaining({
539+
query: { dataSourceId: 'default' }
540+
}));
541+
});
542+
});
505543
});

public/pages/WorkloadManagement/WLMMain/WLMMain.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { WLM_CREATE } from '../WorkloadManagement';
2828
import { DataSourceContext } from '../WorkloadManagement';
2929
import { WLMDataSourceMenu } from '../../../components/DataSourcePicker';
3030
import { getDataSourceEnabledUrl } from '../../../utils/datasource-utils';
31+
import { getVersionOnce, isVersion33OrHigher } from '../../../utils/version-utils';
3132

3233
export const WLM = '/workloadManagement';
3334

@@ -160,9 +161,14 @@ export const WorkloadManagementMain = ({
160161
}
161162
};
162163

163-
// === API Calls ===
164164
const checkQueryInsightsAvailability = async () => {
165165
try {
166+
const version = await getVersionOnce(dataSource?.id || '');
167+
if (!isVersion33OrHigher(version)) {
168+
setIsQueryInsightsAvailable(false);
169+
return;
170+
}
171+
166172
const res = await core.http.get('/api/live_queries', {
167173
query: { dataSourceId: dataSource.id },
168174
});

0 commit comments

Comments
 (0)