Skip to content

Commit

Permalink
Old search strategy cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Mar 6, 2020
1 parent 8fa9962 commit 820a256
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 286 deletions.
10 changes: 1 addition & 9 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
*/

import { CoreSetup, CoreStart, Plugin } from 'kibana/public';
import {
DataPublicPluginStart,
addSearchStrategy,
defaultSearchStrategy,
DataPublicPluginSetup,
} from '../../../../plugins/data/public';
import { DataPublicPluginStart, DataPublicPluginSetup } from '../../../../plugins/data/public';
import { ExpressionsSetup } from '../../../../plugins/expressions/public';

import {
Expand Down Expand Up @@ -111,9 +106,6 @@ export class DataPlugin
public setup(core: CoreSetup, { data, uiActions }: DataPluginSetupDependencies) {
setInjectedMetadata(core.injectedMetadata);

// This is to be deprecated once we switch to the new search service fully
addSearchStrategy(defaultSearchStrategy);

uiActions.attachAction(
SELECT_RANGE_TRIGGER,
selectRangeAction(data.query.filterManager, data.query.timefilter.timefilter)
Expand Down
39 changes: 11 additions & 28 deletions src/plugins/data/public/search/fetch/call_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
* under the License.
*/

import { groupBy } from 'lodash';
import { handleResponse } from './handle_response';
import { FetchOptions, FetchHandlers } from './types';
import { getSearchStrategyForSearchRequest, getSearchStrategyById } from '../search_strategy';
import { defaultSearchStrategy } from '../search_strategy';
import { SearchRequest } from '..';

export function callClient(
Expand All @@ -34,34 +33,18 @@ export function callClient(
FetchOptions
]> = searchRequests.map((request, i) => [request, requestsOptions[i]]);
const requestOptionsMap = new Map<SearchRequest, FetchOptions>(requestOptionEntries);

// Group the requests by the strategy used to search that specific request
const searchStrategyMap = groupBy(searchRequests, (request, i) => {
const searchStrategy = getSearchStrategyForSearchRequest(request, requestsOptions[i]);
return searchStrategy.id;
});

// Execute each search strategy with the group of requests, but return the responses in the same
// order in which they were received. We use a map to correlate the original request with its
// response.
const requestResponseMap = new Map();
Object.keys(searchStrategyMap).forEach(searchStrategyId => {
const searchStrategy = getSearchStrategyById(searchStrategyId);
const requests = searchStrategyMap[searchStrategyId];

// There's no way `searchStrategy` could be undefined here because if we didn't get a matching strategy for this ID
// then an error would have been thrown above
const { searching, abort } = searchStrategy!.search({
searchRequests: requests,
...fetchHandlers,
});
const { searching, abort } = defaultSearchStrategy.search({
searchRequests,
...fetchHandlers,
});

requests.forEach((request, i) => {
const response = searching.then(results => handleResponse(request, results[i]));
const { abortSignal = null } = requestOptionsMap.get(request) || {};
if (abortSignal) abortSignal.addEventListener('abort', abort);
requestResponseMap.set(request, response);
});
}, []);
searchRequests.forEach((request, i) => {
const response = searching.then(results => handleResponse(request, results[i]));
const { abortSignal = null } = requestOptionsMap.get(request) || {};
if (abortSignal) abortSignal.addEventListener('abort', abort);
requestResponseMap.set(request, response);
});
return searchRequests.map(request => requestResponseMap.get(request));
}
2 changes: 0 additions & 2 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ export { IKibanaSearchResponse, IKibanaSearchRequest } from '../../common/search
export { LegacyApiCaller, SearchRequest, SearchResponse } from './es_client';

export {
addSearchStrategy,
hasSearchStategyForIndexPattern,
defaultSearchStrategy,
SearchError,
SearchStrategyProvider,
getSearchErrorType,
Expand Down
7 changes: 1 addition & 6 deletions src/plugins/data/public/search/search_strategy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
* under the License.
*/

export {
addSearchStrategy,
hasSearchStategyForIndexPattern,
getSearchStrategyById,
getSearchStrategyForSearchRequest,
} from './search_strategy_registry';
export { hasSearchStategyForIndexPattern } from './search_strategy_registry';

export { SearchError, getSearchErrorType } from './search_error';

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,7 @@
*/

import { IndexPattern } from '../..';
import { SearchStrategyProvider } from './types';
import { noOpSearchStrategy } from './no_op_search_strategy';
import { SearchResponse } from '..';

export const searchStrategies: SearchStrategyProvider[] = [];

export const addSearchStrategy = (searchStrategy: SearchStrategyProvider) => {
if (searchStrategies.includes(searchStrategy)) {
return;
}

searchStrategies.push(searchStrategy);
};

export const getSearchStrategyByViability = (indexPattern: IndexPattern) => {
return searchStrategies.find(searchStrategy => {
return searchStrategy.isViable(indexPattern);
});
};

export const getSearchStrategyById = (searchStrategyId: string) => {
return [...searchStrategies, noOpSearchStrategy].find(searchStrategy => {
return searchStrategy.id === searchStrategyId;
});
};

export const getSearchStrategyForSearchRequest = (
searchRequest: SearchResponse,
{ searchStrategyId }: { searchStrategyId?: string } = {}
) => {
// Allow the searchSource to declare the correct strategy with which to execute its searches.
if (searchStrategyId != null) {
const strategy = getSearchStrategyById(searchStrategyId);
if (!strategy) throw Error(`No strategy with ID ${searchStrategyId}`);
return strategy;
}

// Otherwise try to match it to a strategy.
const viableSearchStrategy = getSearchStrategyByViability(searchRequest.index);

if (viableSearchStrategy) {
return viableSearchStrategy;
}

// This search strategy automatically rejects with an error.
return noOpSearchStrategy;
};

export const hasSearchStategyForIndexPattern = (indexPattern: IndexPattern) => {
return Boolean(getSearchStrategyByViability(indexPattern));
return true;
};
2 changes: 0 additions & 2 deletions src/plugins/vis_type_timeseries/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export interface VisTypeTimeseriesSetup {
fakeRequest: FakeRequest,
options: GetVisDataOptions
) => ReturnType<GetVisData>;
addSearchStrategy: SearchStrategyRegistry['addStrategy'];
}

export interface Framework {
Expand Down Expand Up @@ -110,7 +109,6 @@ export class VisTypeTimeseriesPlugin implements Plugin<VisTypeTimeseriesSetup> {
) => {
return await getVisData(requestContext, { ...fakeRequest, body: options }, framework);
},
addSearchStrategy: searchStrategyRegistry.addStrategy.bind(searchStrategyRegistry),
};
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/legacy/plugins/rollup/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import { npSetup, npStart } from 'ui/new_platform';
import { aggTypeFilters } from 'ui/agg_types';
import { aggTypeFieldFilters } from 'ui/agg_types';
import { addSearchStrategy } from '../../../../../src/plugins/data/public';
import { RollupPlugin } from './plugin';
import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy';

Expand All @@ -18,7 +17,6 @@ export const setup = plugin.setup(npSetup.core, {
__LEGACY: {
aggTypeFilters,
aggTypeFieldFilters,
addSearchStrategy,
managementLegacy: management,
},
});
Expand Down
4 changes: 1 addition & 3 deletions x-pack/legacy/plugins/rollup/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export interface RollupPluginSetupDependencies {
__LEGACY: {
aggTypeFilters: AggTypeFilters;
aggTypeFieldFilters: AggTypeFieldFilters;
addSearchStrategy: (searchStrategy: SearchStrategyProvider) => void;
managementLegacy: ManagementSetupLegacy;
};
home?: HomePublicPluginSetup;
Expand All @@ -49,7 +48,7 @@ export class RollupPlugin implements Plugin {
setup(
core: CoreSetup,
{
__LEGACY: { aggTypeFilters, aggTypeFieldFilters, addSearchStrategy, managementLegacy },
__LEGACY: { aggTypeFilters, aggTypeFieldFilters, managementLegacy },
home,
management,
indexManagement,
Expand All @@ -67,7 +66,6 @@ export class RollupPlugin implements Plugin {
if (isRollupIndexPatternsEnabled) {
managementLegacy.indexPattern.creation.add(RollupIndexPatternCreationConfig);
managementLegacy.indexPattern.list.add(RollupIndexPatternListConfig);
addSearchStrategy(getRollupSearchStrategy(core.http.fetch));
initAggTypeFilter(aggTypeFilters);
initAggTypeFieldFilter(aggTypeFieldFilters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { registerRollupSearchStrategy } from './register_rollup_search_strategy';
Loading

0 comments on commit 820a256

Please sign in to comment.