Skip to content

[Feature] Initial Live Queries Dashboard #199

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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
36 changes: 32 additions & 4 deletions common/utils/QueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SearchQueryRecord } from '../../types/types';
import { SearchQueryRecord, LiveSearchQueryResponse } from '../../types/types';
import { API_ENDPOINTS } from './apiendpoints';

// Utility function to fetch query by id and time range
export const retrieveQueryById = async (
core: { http: { get: (endpoint: string, params: any) => Promise<any> } },

Check warning on line 11 in common/utils/QueryUtils.ts

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected any. Specify a different type

Check warning on line 11 in common/utils/QueryUtils.ts

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected any. Specify a different type
dataSourceId: string,
start: string | null,
end: string | null,
id: string | null,
verbose: boolean
id: string | null
): Promise<SearchQueryRecord | null> => {
const nullResponse = { response: { top_queries: [] } };
const params = {
Expand All @@ -21,7 +21,6 @@
from: start,
to: end,
id,
verbose,
},
};

Expand Down Expand Up @@ -63,3 +62,32 @@
return null;
}
};

export const retrieveLiveQueries = async (core: {
http: { get: (endpoint: string) => Promise<any> };

Check warning on line 67 in common/utils/QueryUtils.ts

View workflow job for this annotation

GitHub Actions / Run lint

Unexpected any. Specify a different type
}): Promise<LiveSearchQueryResponse> => {
const nullResponse: LiveSearchQueryResponse = {
ok: true,
response: { live_queries: [] },
};

const errorResponse: LiveSearchQueryResponse = {
ok: false,
response: { live_queries: [] },
};

try {
const response: LiveSearchQueryResponse = await core.http.get(API_ENDPOINTS.LIVE_QUERIES);
const liveQueries = response?.response?.live_queries;

if (Array.isArray(liveQueries)) {
return response;
} else {
console.warn('No live queries found in response');
return nullResponse;
}
} catch (error) {
console.error('Error retrieving live queries:', error);
return errorResponse;
}
};
9 changes: 9 additions & 0 deletions common/utils/apiendpoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export const API_ENDPOINTS = {
LIVE_QUERIES: '/api/live_queries',
CANCEL_TASK: (taskId: string) => `/api/tasks/${taskId}/cancel`,
};
3 changes: 2 additions & 1 deletion cypress/e2e/3_configurations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ describe('Query Insights Configurations Page', () => {
cy.get('h1').contains('Query insights - Configuration').should('be.visible');
// Validate the tabs
cy.get('.euiTabs').should('be.visible');
cy.get('.euiTab').should('have.length', 2); // Two tabs: 'Top N queries' and 'Configuration'
cy.get('.euiTab').should('have.length', 3); // Three tabs: 'Top N queries', 'Live queries' and 'Configuration'
cy.contains('button', 'Top N queries').should('be.visible');
cy.contains('button', 'Live queries').should('be.visible');
cy.contains('button', 'Configuration').should('have.class', 'euiTab-isSelected');
// Validate the panels
// 6 panels: Settings, Status, Group Settings, Group Status, Delete After Settings, Delete After Status
Expand Down
Loading
Loading