Skip to content

Commit 695f165

Browse files
author
Kishore Kumaar Natarajan
committed
Removed _cat/plugins
Signed-off-by: Kishore Kumaar Natarajan <[email protected]>
1 parent fbf3bcd commit 695f165

File tree

5 files changed

+71
-93
lines changed

5 files changed

+71
-93
lines changed

cypress/e2e/5_live_queries.cy.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,15 @@ describe('Inflight Queries Dashboard - WLM Enabled', () => {
368368
});
369369

370370
// WLM enabled + workload groups
371-
cy.intercept('GET', '**/api/cat_plugins', {
371+
cy.intercept('GET', '**/api/_wlm/workload_group', {
372+
statusCode: 200,
373+
body: { workload_groups: [] },
374+
}).as('getWlmEnabled');
375+
376+
cy.intercept('GET', '**/api/live_queries', {
372377
statusCode: 200,
373-
body: { hasWlm: true },
374-
}).as('getPluginsEnabled');
378+
body: { response: { live_queries: [] } },
379+
}).as('getQueryInsightsEnabled');
375380

376381
cy.intercept('GET', '**/api/_wlm/workload_group', {
377382
statusCode: 200,
@@ -390,7 +395,7 @@ describe('Inflight Queries Dashboard - WLM Enabled', () => {
390395

391396
it('displays WLM group links when WLM is enabled', () => {
392397
cy.wait('@getWorkloadGroups');
393-
cy.wait('@getPluginsEnabled');
398+
cy.wait('@getWlmEnabled');
394399

395400
cy.get('tbody tr')
396401
.first()

public/pages/InflightQueries/InflightQueries.test.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ describe('InflightQueries', () => {
318318

319319
// Mock WLM detection
320320
(core.http.get as jest.Mock).mockImplementation((url) => {
321-
if (url === '/api/cat_plugins') {
322-
return Promise.resolve({ hasWlm: true });
321+
if (url === '/api/_wlm/workload_group') {
322+
return Promise.resolve({ workload_groups: [] });
323323
}
324324
return Promise.resolve({});
325325
});
@@ -375,7 +375,12 @@ describe('InflightQueries', () => {
375375
(getVersionOnce as jest.Mock).mockResolvedValue('3.3.0');
376376
(isVersion33OrHigher as jest.Mock).mockReturnValue(true);
377377

378-
(core.http.get as jest.Mock).mockResolvedValue({ hasWlm: true });
378+
(core.http.get as jest.Mock).mockImplementation((url) => {
379+
if (url === '/api/_wlm/workload_group') {
380+
return Promise.resolve({ workload_groups: [] });
381+
}
382+
return Promise.resolve({ response: { live_queries: [] } });
383+
});
379384

380385
mockLiveQueries(mockStubLiveQueries);
381386

@@ -509,7 +514,12 @@ describe('InflightQueries', () => {
509514
(getVersionOnce as jest.Mock).mockResolvedValue('3.3.0');
510515
(isVersion33OrHigher as jest.Mock).mockReturnValue(true);
511516

512-
(core.http.get as jest.Mock).mockResolvedValue({ hasWlm: true });
517+
(core.http.get as jest.Mock).mockImplementation((url) => {
518+
if (url === '/api/_wlm/workload_group') {
519+
return Promise.resolve({ workload_groups: [] });
520+
}
521+
return Promise.resolve({ response: { live_queries: [] } });
522+
});
513523

514524
mockLiveQueries({ ok: true, response: { live_queries: [] } });
515525

public/pages/InflightQueries/InflightQueries.tsx

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ export const InflightQueries = ({
126126

127127
try {
128128
const httpQuery = dataSource?.id ? { dataSourceId: dataSource.id } : undefined;
129-
const res = await core.http.get('/api/cat_plugins', { query: httpQuery });
130-
const has = !!res?.hasWlm;
131-
wlmCacheRef.current[cacheKey] = has;
132-
return has;
129+
const res = await core.http.get('/api/_wlm/workload_group', { query: httpQuery });
130+
const hasValidStructure =
131+
res && typeof res === 'object' && Array.isArray(res.workload_groups);
132+
wlmCacheRef.current[cacheKey] = hasValidStructure;
133+
return hasValidStructure;
133134
} catch (e) {
134-
console.warn('[LiveQueries] _cat/plugins detection failed; assuming WLM unavailable', e);
135+
console.warn('[LiveQueries] WLM workload group API failed; assuming WLM unavailable', e);
135136
wlmCacheRef.current[cacheKey] = false;
136137
return false;
137138
}
@@ -141,11 +142,14 @@ export const InflightQueries = ({
141142
const checkWlmSupport = async () => {
142143
try {
143144
const version = await getVersionOnce(dataSource?.id || '');
145+
console.log('[DEBUG] OpenSearch version detected:', version);
144146
const versionSupported = isVersion33OrHigher(version);
147+
console.log('[DEBUG] Version 3.3+ supported:', versionSupported);
145148
setWlmGroupsSupported(versionSupported);
146149

147150
if (versionSupported) {
148151
const hasWlm = await detectWlm();
152+
console.log('[DEBUG] WLM available:', hasWlm);
149153
setWlmAvailable(hasWlm);
150154
} else {
151155
setWlmAvailable(false);
@@ -167,17 +171,15 @@ export const InflightQueries = ({
167171
}>({ total_completions: 0, total_cancellations: 0, total_rejections: 0 });
168172

169173
const fetchActiveWlmGroups = useCallback(async () => {
170-
if (!wlmGroupsSupported) {
171-
setWorkloadGroupStats({ total_completions: 0, total_cancellations: 0, total_rejections: 0 });
172-
setWlmGroupOptions([]);
173-
return {};
174-
}
174+
console.log('[DEBUG] fetchActiveWlmGroups called, wlmGroupsSupported:', wlmGroupsSupported);
175175

176176
const httpQuery = dataSource?.id ? { dataSourceId: dataSource.id } : undefined;
177177
let statsBody: WlmStatsBody = {};
178178
try {
179+
console.log('[DEBUG] Making WLM stats API call to:', API_ENDPOINTS.WLM_STATS);
179180
const statsRes = await core.http.get(API_ENDPOINTS.WLM_STATS, { query: httpQuery });
180-
statsBody = (statsRes as { body?: unknown }).body as WlmStatsBody;
181+
console.log('[DEBUG] WLM stats response:', statsRes);
182+
statsBody = statsRes as WlmStatsBody;
181183
} catch (e) {
182184
console.warn('[LiveQueries] Failed to fetch WLM stats', e);
183185
setWorkloadGroupStats({ total_completions: 0, total_cancellations: 0, total_rejections: 0 });
@@ -229,16 +231,25 @@ export const InflightQueries = ({
229231
}
230232
}
231233

234+
console.log(
235+
'[DEBUG] Parsed stats - completions:',
236+
completions,
237+
'cancellations:',
238+
cancellations,
239+
'rejections:',
240+
rejections
241+
);
242+
232243
setWorkloadGroupStats({
233244
total_completions: completions,
234245
total_cancellations: cancellations,
235246
total_rejections: rejections,
236247
});
237248

238-
// fetch group NAMES only if plugin exists (but do not block the stats)
249+
// fetch group NAMES only if plugin exists and version supported
239250
const idToNameMap: Record<string, string> = {};
240251
try {
241-
if (wlmAvailable) {
252+
if (wlmAvailable && wlmGroupsSupported) {
242253
const groupsRes = await core.http.get(API_ENDPOINTS.WLM_WORKLOAD_GROUP, {
243254
query: httpQuery,
244255
});
@@ -253,10 +264,12 @@ export const InflightQueries = ({
253264
console.warn('[LiveQueries] Failed to fetch workload groups', e);
254265
}
255266

256-
const options = Array.from(activeGroupIds).map((id) => ({ id, name: idToNameMap[id] || id }));
267+
const options = wlmGroupsSupported
268+
? Array.from(activeGroupIds).map((id) => ({ id, name: idToNameMap[id] || id }))
269+
: [];
257270
setWlmGroupOptions(options);
258271
return idToNameMap;
259-
}, [core.http, dataSource?.id, wlmGroupId, wlmAvailable]);
272+
}, [core.http, dataSource?.id, wlmGroupId, wlmGroupsSupported]);
260273

261274
const liveQueries = query?.response?.live_queries ?? [];
262275

@@ -353,13 +366,22 @@ export const InflightQueries = ({
353366
if (isFetching.current) return;
354367
isFetching.current = true;
355368
try {
356-
const budget = Math.max(2000, refreshInterval - 500);
357-
const map = await withTimeout(fetchActiveWlmGroups(), budget).catch(() => undefined);
358-
await fetchLiveQueries(map);
369+
if (wlmGroupsSupported) {
370+
try {
371+
await withTimeout(fetchActiveWlmGroups(), refreshInterval - 500);
372+
} catch (e) {
373+
console.warn('[LiveQueries] fetchActiveWlmGroups timed out or failed', e);
374+
}
375+
}
376+
try {
377+
await withTimeout(fetchLiveQueries(), refreshInterval - 500);
378+
} catch (e) {
379+
console.warn('[LiveQueries] fetchLiveQueries timed out or failed', e);
380+
}
359381
} finally {
360382
isFetching.current = false;
361383
}
362-
}, [refreshInterval, fetchActiveWlmGroups, fetchLiveQueries]);
384+
}, [refreshInterval, fetchActiveWlmGroups, fetchLiveQueries, wlmGroupsSupported]);
363385

364386
useEffect(() => {
365387
void fetchLiveQueriesSafe();
@@ -370,7 +392,7 @@ export const InflightQueries = ({
370392
}, refreshInterval);
371393

372394
return () => clearInterval(interval);
373-
}, [autoRefreshEnabled, refreshInterval, fetchLiveQueriesSafe]);
395+
}, [autoRefreshEnabled, refreshInterval, fetchLiveQueriesSafe, wlmGroupsSupported]);
374396

375397
const [pagination, setPagination] = useState({ pageIndex: 0 });
376398
const [tableQuery, setTableQuery] = useState('');
@@ -574,7 +596,7 @@ export const InflightQueries = ({
574596
<EuiButton
575597
iconType="refresh"
576598
onClick={async () => {
577-
await fetchLiveQueries();
599+
await fetchLiveQueriesSafe();
578600
}}
579601
data-test-subj="live-queries-refresh-button"
580602
>
@@ -906,7 +928,7 @@ export const InflightQueries = ({
906928
key="refresh-button"
907929
iconType="refresh"
908930
onClick={async () => {
909-
await fetchLiveQueries();
931+
await fetchLiveQueriesSafe();
910932
}}
911933
>
912934
Refresh

public/pages/WorkloadManagement/WLMMain/WLMMain.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ export const WorkloadManagementMain = ({
163163
// === API Calls ===
164164
const checkQueryInsightsAvailability = async () => {
165165
try {
166-
const response = await core.http.get('/api/cat_plugins', {
166+
const res = await core.http.get('/api/live_queries', {
167167
query: { dataSourceId: dataSource.id },
168168
});
169-
setIsQueryInsightsAvailable(response.hasQueryInsights || false);
169+
const hasValidStructure =
170+
res && typeof res === 'object' && res.response && Array.isArray(res.response.live_queries);
171+
setIsQueryInsightsAvailable(hasValidStructure);
170172
} catch (error) {
171173
setIsQueryInsightsAvailable(false);
172174
}

server/routes/index.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -280,67 +280,6 @@ export function defineRoutes(router: IRouter, dataSourceEnabled: boolean) {
280280
}
281281
);
282282

283-
router.get(
284-
{
285-
path: '/api/cat_plugins',
286-
validate: {
287-
query: schema.object({
288-
dataSourceId: schema.maybe(schema.string()),
289-
}),
290-
},
291-
},
292-
async (context, request, response) => {
293-
try {
294-
const { dataSourceId } = request.query;
295-
296-
// Always use _cat (JSON) as requested
297-
const catPath = '/_cat/plugins?format=json';
298-
299-
let resp: any;
300-
if (dataSourceEnabled && dataSourceId) {
301-
// Data source-aware client (proxies to the selected cluster)
302-
const dsClient = context.dataSource.opensearch.legacy.getClient(dataSourceId);
303-
resp = await dsClient.callAPI('transport.request', {
304-
method: 'GET',
305-
path: catPath,
306-
});
307-
} else {
308-
// Fallback: core client as current user
309-
const es = context.core.opensearch.client.asCurrentUser;
310-
resp = await es.transport.request({
311-
method: 'GET',
312-
path: catPath,
313-
});
314-
}
315-
316-
const body = resp?.body ?? resp; // legacy/new client normalization
317-
const rows: Array<Record<string, any>> = Array.isArray(body) ? body : [];
318-
319-
// Check for query insights and WLM plugins
320-
const hasQueryInsights = rows.some((p) => {
321-
const s = `${p?.component ?? ''} ${p?.name ?? ''}`.toLowerCase();
322-
return s.includes('query-insights') || s.includes('queryinsights');
323-
});
324-
325-
const hasWlm = rows.some((p) => {
326-
const s = `${p?.component ?? ''} ${p?.name ?? ''}`.toLowerCase();
327-
return s.includes('workload') || s.includes('wlm');
328-
});
329-
330-
return response.ok({ body: { ok: true, hasQueryInsights, hasWlm } });
331-
} catch (err: any) {
332-
return response.ok({
333-
body: {
334-
ok: false,
335-
hasQueryInsights: false,
336-
hasWlm: false,
337-
error: err?.message ?? 'cat plugins failed',
338-
},
339-
});
340-
}
341-
}
342-
);
343-
344283
router.put(
345284
{
346285
path: '/api/update_settings',

0 commit comments

Comments
 (0)