Skip to content
Merged
Changes from all commits
Commits
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
22 changes: 14 additions & 8 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,22 @@ export function defineRoutes(router: IRouter, dataSourceEnabled: boolean) {
wlmGroupId?: string;
};

const client =
!dataSourceEnabled || !dataSourceId
? context.queryInsights_plugin.queryInsightsClient.asScoped(request).callAsCurrentUser
: context.dataSource.opensearch.legacy.getClient(dataSourceId);

// Call the appropriate API based on whether wlm_group is provided
const hasGroup = typeof wlmGroup === 'string' && wlmGroup.trim().length > 0;
const res = hasGroup
? await client('queryInsights.getLiveQueriesWLMGroup', { wlmGroupId: wlmGroup })
: await client('queryInsights.getLiveQueries');
let res;

if (!dataSourceEnabled || !dataSourceId) {
const client = context.queryInsights_plugin.queryInsightsClient.asScoped(request)
.callAsCurrentUser;
res = hasGroup
? await client('queryInsights.getLiveQueriesWLMGroup', { wlmGroupId: wlmGroup })
: await client('queryInsights.getLiveQueries');
} else {
const client = context.dataSource.opensearch.legacy.getClient(dataSourceId);
res = hasGroup
? await client.callAPI('queryInsights.getLiveQueriesWLMGroup', { wlmGroupId: wlmGroup })
: await client.callAPI('queryInsights.getLiveQueries', {});
}

if (!res || res.ok === false) {
throw new Error(res?.error || 'Query Insights service returned an error');
Expand Down
Loading