Skip to content

Commit

Permalink
[7.x] [SEARCH] Cleanup fetch soon (#63320) (#63983)
Browse files Browse the repository at this point in the history
* move old code to legacy folder

* Use search service directly from search source

* Move get search params to fetch folder

* Delete search strategy folder

* Doc update

* Minor cleanups

* Moved es client to legacy folder

* Clean up some unused code (isViable, old search function)

* Updated tests

* strings update

* Fix jest test

* re-arrange runSearch function

* re-arrange runSearch function

* fix jest tests

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Liza Katz <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Apr 20, 2020
1 parent 164c483 commit 37e9dce
Show file tree
Hide file tree
Showing 37 changed files with 276 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
| [SavedQuery](./kibana-plugin-plugins-data-public.savedquery.md) | |
| [SavedQueryService](./kibana-plugin-plugins-data-public.savedqueryservice.md) | |
| [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | |
| [SearchStrategyProvider](./kibana-plugin-plugins-data-public.searchstrategyprovider.md) | |
| [TabbedAggColumn](./kibana-plugin-plugins-data-public.tabbedaggcolumn.md) | \* |
| [TabbedTable](./kibana-plugin-plugins-data-public.tabbedtable.md) | \* |
| [TimeRange](./kibana-plugin-plugins-data-public.timerange.md) | |
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { getIndices } from './get_indices';
import { IndexPatternCreationConfig } from '../../../../../../../../../plugins/index_pattern_management/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { LegacyApiCaller } from '../../../../../../../../../plugins/data/public/search';
import { LegacyApiCaller } from '../../../../../../../../../plugins/data/public/search/legacy';

export const successfulResponse = {
hits: {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ export {
SearchRequest,
SearchResponse,
SearchError,
SearchStrategyProvider,
ISearchSource,
SearchSource,
createSearchSource,
Expand Down
45 changes: 15 additions & 30 deletions src/plugins/data/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1736,21 +1736,6 @@ export interface SearchSourceFields {
version?: boolean;
}

// Warning: (ae-missing-release-tag) "SearchStrategyProvider" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface SearchStrategyProvider {
// (undocumented)
id: string;
// (undocumented)
isViable: (indexPattern: IndexPattern) => boolean;
// Warning: (ae-forgotten-export) The symbol "SearchStrategySearchParams" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "SearchStrategyResponse" needs to be exported by the entry point index.d.ts
//
// (undocumented)
search: (params: SearchStrategySearchParams) => SearchStrategyResponse;
}

// Warning: (ae-missing-release-tag) "SortDirection" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
Expand Down Expand Up @@ -1901,21 +1886,21 @@ export type TSearchStrategyProvider<T extends TStrategyTypes> = (context: ISearc
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "flattenHitWrapper" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "getRoutes" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:234:27 - (ae-forgotten-export) The symbol "formatHitProvider" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:383:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:389:1 - (ae-forgotten-export) The symbol "convertDateRangeToString" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:391:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:400:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:402:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:406:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:410:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:413:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:382:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:387:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:388:1 - (ae-forgotten-export) The symbol "convertDateRangeToString" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:390:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:399:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:400:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:401:1 - (ae-forgotten-export) The symbol "isDateHistogramBucketAggConfig" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:404:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:405:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:408:1 - (ae-forgotten-export) The symbol "parseInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:409:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:412:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:33:33 - (ae-forgotten-export) The symbol "FilterStateStore" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/query/state_sync/connect_to_query_state.ts:37:1 - (ae-forgotten-export) The symbol "QueryStateChange" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/types.ts:52:5 - (ae-forgotten-export) The symbol "createFiltersFromEvent" needs to be exported by the entry point index.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { dataPluginMock } from '../../../../public/mocks';
import { coreMock } from '../../../../../../core/public/mocks';
import { dataPluginMock } from '../../../mocks';
import {
setFieldFormats,
setIndexPatterns,
Expand All @@ -29,7 +29,7 @@ import {
setQueryService,
setSearchService,
setUiSettings,
} from '../../../../public/services';
} from '../../../services';

/**
* Testing helper which calls all of the service setters used in the
Expand All @@ -49,4 +49,9 @@ export function mockDataServices() {
setQueryService(data.query);
setSearchService(data.search);
setUiSettings(core.uiSettings);

return {
core,
data,
};
}
70 changes: 70 additions & 0 deletions src/plugins/data/public/search/fetch/get_search_params.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { getSearchParams } from './get_search_params';
import { IUiSettingsClient } from 'kibana/public';

function getConfigStub(config: any = {}) {
return {
get: key => config[key],
} as IUiSettingsClient;
}

describe('getSearchParams', () => {
test('includes rest_total_hits_as_int', () => {
const config = getConfigStub();
const searchParams = getSearchParams(config);
expect(searchParams.rest_total_hits_as_int).toBe(true);
});

test('includes ignore_unavailable', () => {
const config = getConfigStub();
const searchParams = getSearchParams(config);
expect(searchParams.ignore_unavailable).toBe(true);
});

test('includes ignore_throttled according to search:includeFrozen', () => {
let config = getConfigStub({ 'search:includeFrozen': true });
let searchParams = getSearchParams(config);
expect(searchParams.ignore_throttled).toBe(false);

config = getConfigStub({ 'search:includeFrozen': false });
searchParams = getSearchParams(config);
expect(searchParams.ignore_throttled).toBe(true);
});

test('includes max_concurrent_shard_requests according to courier:maxConcurrentShardRequests', () => {
let config = getConfigStub({ 'courier:maxConcurrentShardRequests': 0 });
let searchParams = getSearchParams(config);
expect(searchParams.max_concurrent_shard_requests).toBe(undefined);

config = getConfigStub({ 'courier:maxConcurrentShardRequests': 5 });
searchParams = getSearchParams(config);
expect(searchParams.max_concurrent_shard_requests).toBe(5);
});

test('includes timeout according to esShardTimeout if greater than 0', () => {
const config = getConfigStub();
let searchParams = getSearchParams(config, 0);
expect(searchParams.timeout).toBe(undefined);

searchParams = getSearchParams(config, 100);
expect(searchParams.timeout).toBe('100ms');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,10 @@
* under the License.
*/

import { IUiSettingsClient } from '../../../../../core/public';
import { IUiSettingsClient } from 'kibana/public';

const sessionId = Date.now();

export function getMSearchParams(config: IUiSettingsClient) {
return {
rest_total_hits_as_int: true,
ignore_throttled: getIgnoreThrottled(config),
max_concurrent_shard_requests: getMaxConcurrentShardRequests(config),
};
}

export function getSearchParams(config: IUiSettingsClient, esShardTimeout: number = 0) {
return {
rest_total_hits_as_int: true,
Expand All @@ -40,11 +32,11 @@ export function getSearchParams(config: IUiSettingsClient, esShardTimeout: numbe
};
}

function getIgnoreThrottled(config: IUiSettingsClient) {
export function getIgnoreThrottled(config: IUiSettingsClient) {
return !config.get('search:includeFrozen');
}

function getMaxConcurrentShardRequests(config: IUiSettingsClient) {
export function getMaxConcurrentShardRequests(config: IUiSettingsClient) {
const maxConcurrentShardRequests = config.get('courier:maxConcurrentShardRequests');
return maxConcurrentShardRequests > 0 ? maxConcurrentShardRequests : undefined;
}
Expand Down
13 changes: 11 additions & 2 deletions src/plugins/data/public/search/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
*/

export * from './types';
export { fetchSoon } from './fetch_soon';
export { RequestFailure } from './errors';
export {
getSearchParams,
getPreference,
getTimeout,
getIgnoreThrottled,
getMaxConcurrentShardRequests,
} from './get_search_params';

export { SearchError, getSearchErrorType } from './search_error';
export { RequestFailure } from './request_error';
export { handleResponse } from './handle_response';
3 changes: 3 additions & 0 deletions src/plugins/data/public/search/fetch/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import { IUiSettingsClient } from '../../../../../core/public';
import { ISearchStart } from '../types';

export type SearchRequest = any;
export type SearchResponse = any;

export interface FetchOptions {
abortSignal?: AbortSignal;
searchStrategyId?: string;
Expand Down
12 changes: 7 additions & 5 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export { esSearchStrategyProvider, getEsPreference } from './es_search';

export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search';

export { LegacyApiCaller, SearchRequest, SearchResponse } from './es_client';

export { SearchError, SearchStrategyProvider, getSearchErrorType } from './search_strategy';
export {
SearchError,
FetchOptions,
SearchRequest,
SearchResponse,
getSearchErrorType,
} from './fetch';

export {
ISearchSource,
Expand All @@ -59,5 +63,3 @@ export {

export { SearchInterceptor } from './search_interceptor';
export { RequestTimeoutError } from './request_timeout_error';

export { FetchOptions } from './fetch';
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
*/

import { callClient } from './call_client';
import { handleResponse } from './handle_response';
import { FetchHandlers } from './types';
import { SearchStrategySearchParams, defaultSearchStrategy } from '../search_strategy';
import { SearchStrategySearchParams } from './types';
import { defaultSearchStrategy } from './default_search_strategy';
import { FetchHandlers } from '../fetch';
import { handleResponse } from '../fetch/handle_response';

const mockAbortFn = jest.fn();
jest.mock('./handle_response', () => ({
jest.mock('../fetch/handle_response', () => ({
handleResponse: jest.fn((request, response) => response),
}));

jest.mock('../search_strategy', () => {
jest.mock('./default_search_strategy', () => {
return {
defaultSearchStrategy: {
search: jest.fn(({ searchRequests }: SearchStrategySearchParams) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
* under the License.
*/

import { handleResponse } from './handle_response';
import { FetchOptions, FetchHandlers } from './types';
import { defaultSearchStrategy } from '../search_strategy';
import { SearchRequest } from '..';
import { FetchOptions, FetchHandlers, handleResponse } from '../fetch';
import { defaultSearchStrategy } from './default_search_strategy';
import { SearchRequest } from '../index';

export function callClient(
searchRequests: SearchRequest[],
Expand Down
Loading

0 comments on commit 37e9dce

Please sign in to comment.