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

[Reporting/Discover/Search Sessions] Only use relative time filter when generating share data #112588

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export const getTopNavLinks = ({
const sharingData = await getSharingData(
searchSource,
state.appStateContainer.getState(),
services.uiSettings
indexPattern,
services
);

services.share.toggleShareContextMenu({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* Side Public License, v 1.
*/

import type { Capabilities, IUiSettingsClient } from 'kibana/public';
import { ISearchSource } from '../../../../../../data/common';
import type { Capabilities } from 'kibana/public';
import type { IndexPattern, ISearchSource } from 'src/plugins/data/common';
import { DOC_HIDE_TIME_COLUMN_SETTING, SORT_DEFAULT_ORDER_SETTING } from '../../../../../common';
import type { DiscoverServices } from '../../../../build_services';
import type { SavedSearch, SortOrder } from '../../../../saved_searches/types';
import { getSortForSearchSource } from '../components/doc_table';
import { AppState } from '../services/discover_state';
Expand All @@ -19,15 +20,22 @@ import { AppState } from '../services/discover_state';
export async function getSharingData(
currentSearchSource: ISearchSource,
state: AppState | SavedSearch,
config: IUiSettingsClient
indexPattern: IndexPattern,
services: DiscoverServices
) {
const { uiSettings: config, data } = services;
const searchSource = currentSearchSource.createCopy();
const index = searchSource.getField('index')!;

searchSource.setField(
'sort',
getSortForSearchSource(state.sort as SortOrder[], index, config.get(SORT_DEFAULT_ORDER_SETTING))
);
// When sharing externally we preserve relative time values
searchSource.setField(
'filter',
data.query.timefilter.timefilter.createRelativeFilter(indexPattern)
);
searchSource.removeField('highlight');
searchSource.removeField('highlightAll');
searchSource.removeField('aggs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ export function updateSearchSource(

// this is not the default index pattern, it determines that it's not of type rollup
if (indexPatternsUtils.isDefault(indexPattern)) {
searchSource.setField(
'filter',
data.query.timefilter.timefilter.createRelativeFilter(indexPattern)
);
// Set the date range filter fields from timeFilter using the absolute format. Search sessions requires that it be converted from a relative range
searchSource.setField('filter', data.query.timefilter.timefilter.createFilter(indexPattern));
jloleysens marked this conversation as resolved.
Show resolved Hide resolved
}

if (useNewFieldsApi) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function SearchSessionsPageProvider({ getService, getPageObjects }: FtrPr
mainUrl: $.findTestSubject('sessionManagementNameCol').text(),
created: $.findTestSubject('sessionManagementCreatedCol').text(),
expires: $.findTestSubject('sessionManagementExpiresCol').text(),
searchesCount: Number($.findTestSubject('sessionManagementNumSearchesCol').text()),
app: $.findTestSubject('sessionManagementAppIcon').attr('data-test-app-id'),
view: async () => {
log.debug('management ui: view the session');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const searchSessions = getService('searchSessions');
const retry = getService('retry');
const kibanaServer = getService('kibanaServer');
const toasts = getService('toasts');

describe('discover async search', () => {
before(async () => {
Expand Down Expand Up @@ -112,12 +113,20 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

// load URL to restore a saved session
await PageObjects.searchSessionsManagement.goTo();
const searchSessionList = await PageObjects.searchSessionsManagement.getList();
const searchSessionListBeforeRestore = await PageObjects.searchSessionsManagement.getList();
const searchesCountBeforeRestore = searchSessionListBeforeRestore[0].searchesCount;
// navigate to Discover
await searchSessionList[0].view();
await searchSessionListBeforeRestore[0].view();
await PageObjects.header.waitUntilLoadingHasFinished();
await searchSessions.expectState('restored');
expect(await PageObjects.discover.hasNoResults()).to.be(true);
expect(await toasts.getToastCount()).to.be(0); // no session restoration related warnings

await PageObjects.searchSessionsManagement.goTo();
const searchSessionListAfterRestore = await PageObjects.searchSessionsManagement.getList();
const searchesCountAfterRestore = searchSessionListAfterRestore[0].searchesCount;

expect(searchesCountBeforeRestore).to.be(searchesCountAfterRestore); // no new searches started during restore
});
});

Expand Down