Skip to content

Commit

Permalink
Move search service code to NP (#55430)
Browse files Browse the repository at this point in the history
* Move get search params into search strategy

* Move search strategy to NP and clean up courier exports

* Move fetch to NP

* Moved search source to NP

* Move shard failure to data/ui folder

* move getflattenedobject to core/utils

* fix discover

* eslint

* fix scss

* fix ts

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Liza Katz and elasticmachine authored Jan 27, 2020
1 parent 1ea175e commit 133c299
Show file tree
Hide file tree
Showing 97 changed files with 196 additions and 450 deletions.
3 changes: 2 additions & 1 deletion src/core/server/legacy/config/get_unused_config_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import { difference, get, set } from 'lodash';
// @ts-ignore
import { getTransform } from '../../../../legacy/deprecation/index';
import { unset, getFlattenedObject } from '../../../../legacy/utils';
import { unset } from '../../../../legacy/utils';
import { getFlattenedObject } from '../../../utils';
import { hasConfigPathIntersection } from '../../config';
import { LegacyPluginSpec, LegacyConfig, LegacyVars } from '../types';

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/core/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ export * from './pick';
export * from './promise';
export * from './url';
export * from './unset';
export * from './get_flattened_object';
export * from './default_app_categories';
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ export function plugin() {

/** @public types */
export { DataStart };
export { EsQuerySortValue, FetchOptions, ISearchSource, SortDirection } from './search/types';
export { SearchSourceFields } from './search/types';
export {
SavedQueryAttributes,
SavedQuery,
Expand Down
38 changes: 15 additions & 23 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
*/

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

import {
setFieldFormats,
setNotifications,
setIndexPatterns,
setQueryService,
setSearchService,
setUiSettings,
setInjectedMetadata,
setHttp,
setFieldFormats,
setSearchService,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../plugins/data/public/services';

Expand All @@ -47,9 +48,7 @@ export interface DataPluginStartDependencies {
*
* @public
*/
export interface DataStart {
search: SearchStart;
}
export interface DataStart {} // eslint-disable-line @typescript-eslint/no-empty-interface

/**
* Data Plugin - public
Expand All @@ -65,29 +64,22 @@ export interface DataStart {

export class DataPlugin
implements Plugin<void, DataStart, DataPluginSetupDependencies, DataPluginStartDependencies> {
private readonly search = new SearchService();

public setup(core: CoreSetup) {
setInjectedMetadata(core.injectedMetadata);

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

public start(core: CoreStart, { data }: DataPluginStartDependencies): DataStart {
// This is required for when Angular code uses Field and FieldList.
setFieldFormats(data.fieldFormats);
setUiSettings(core.uiSettings);
setQueryService(data.query);
setSearchService(data.search);
setIndexPatterns(data.indexPatterns);
setFieldFormats(data.fieldFormats);
setNotifications(core.notifications);
setUiSettings(core.uiSettings);
setHttp(core.http);
setSearchService(data.search);

return {
search: this.search.start(core),
};
return {};
}

public stop() {
this.search.stop();
}
public stop() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
KibanaDatatableColumn,
} from 'src/plugins/expressions/public';
import {
ISearchSource,
SearchSource,
Query,
TimeRange,
esFilters,
Expand All @@ -43,8 +45,7 @@ import { PersistedState } from '../../../../../ui/public/persisted_state';
import { Adapters } from '../../../../../../plugins/inspector/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { getQueryService, getIndexPatterns } from '../../../../../../plugins/data/public/services';
import { ISearchSource, getRequestInspectorStats, getResponseInspectorStats } from '../..';
import { SearchSource } from '../search_source';
import { getRequestInspectorStats, getResponseInspectorStats } from '../..';

export interface RequestHandlerParams {
searchSource: ISearchSource;
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
* under the License.
*/

export { SearchService, SearchSetup, SearchStart } from './search_service';

export { getRequestInspectorStats, getResponseInspectorStats } from './utils';
53 changes: 0 additions & 53 deletions src/legacy/core_plugins/data/public/search/search_service.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/legacy/core_plugins/data/public/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@
* under the License.
*/

export * from './fetch/types';
export * from './search_source/types';
export * from './search_strategy/types';
export * from './utils/types';
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

import { i18n } from '@kbn/i18n';
import { SearchResponse } from 'elasticsearch';
import { ISearchSource, RequestInspectorStats } from '../types';
import { RequestInspectorStats } from '../types';
import { ISearchSource } from '../../../../../../plugins/data/public';

export function getRequestInspectorStats(searchSource: ISearchSource) {
const stats: RequestInspectorStats = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* under the License.
*/

import { SearchSource as SearchSourceClass, ISearchSource } from 'ui/courier';
import { Class } from '@kbn/utility-types';
import { SearchSource as SearchSourceClass, ISearchSource } from '../../../../plugins/data/public';

export { SearchSourceFields } from '../../../../plugins/data/public';

export { Vis, VisParams } from 'ui/vis';
export { VisOptionsProps } from 'ui/vis/editors/default';
export { ValidatedDualRange } from 'ui/validated_range';
export { SearchSourceFields } from '../../data/public';

export type SearchSource = Class<ISearchSource>;
export const SearchSource = SearchSourceClass;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
* under the License.
*/

import { searchSourceMock } from 'ui/courier/search_source/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { searchSourceMock } from '../../../../../../plugins/data/public/search/search_source/mocks';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';

export function getSavedDashboardMock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
* specific language governing permissions and limitations
* under the License.
*/
import { ISearchSource } from 'ui/courier';
import { SavedObject, SavedObjectKibanaServices } from 'ui/saved_objects/types';
import { createSavedObjectClass } from 'ui/saved_objects/saved_object';
import { extractReferences, injectReferences } from './saved_dashboard_references';

import { esFilters, Query, RefreshInterval } from '../../../../../../plugins/data/public';
import {
esFilters,
ISearchSource,
Query,
RefreshInterval,
} from '../../../../../../plugins/data/public';
import { createDashboardEditUrl } from '..';

export interface SavedObjectDashboard extends SavedObject {
Expand Down
16 changes: 6 additions & 10 deletions src/legacy/core_plugins/kibana/public/discover/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,7 @@ export { wrapInI18nContext } from 'ui/i18n';
export { buildVislibDimensions } from '../../../visualizations/public';
// @ts-ignore
export { callAfterBindingsWorkaround } from 'ui/compat';
export {
getRequestInspectorStats,
getResponseInspectorStats,
hasSearchStategyForIndexPattern,
isDefaultTypeIndexPattern,
SearchSource,
EsQuerySortValue,
SortDirection,
ISearchSource,
} from 'ui/courier';
export { getRequestInspectorStats, getResponseInspectorStats } from '../../../data/public';
// @ts-ignore
export { intervalOptions } from 'ui/agg_types/buckets/_interval_options';
// @ts-ignore
Expand All @@ -93,7 +84,12 @@ export {
IIndexPattern,
IndexPattern,
indexPatterns,
hasSearchStategyForIndexPattern,
IFieldType,
SearchSource,
ISearchSource,
EsQuerySortValue,
SortDirection,
} from '../../../../../plugins/data/public';
export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types';
export { Adapters } from 'ui/inspector/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
getServices,
hasSearchStategyForIndexPattern,
intervalOptions,
isDefaultTypeIndexPattern,
migrateLegacyQuery,
RequestAdapter,
showSaveModal,
Expand Down Expand Up @@ -73,7 +72,10 @@ const {
} = getServices();

import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs';
import { generateFilters } from '../../../../../../../plugins/data/public';
import {
generateFilters,
indexPatterns as indexPatternsUtils,
} from '../../../../../../../plugins/data/public';
import { getIndexPatternId } from '../helpers/get_index_pattern_id';
import { FilterStateManager } from '../../../../../data/public';

Expand Down Expand Up @@ -400,7 +402,8 @@ function discoverController(

// searchSource which applies time range
const timeRangeSearchSource = savedSearch.searchSource.create();
if (isDefaultTypeIndexPattern($scope.indexPattern)) {

if (indexPatternsUtils.isDefault($scope.indexPattern)) {
timeRangeSearchSource.setField('filter', () => {
return timefilter.createFilter($scope.indexPattern);
});
Expand Down Expand Up @@ -561,7 +564,8 @@ function discoverController(
$scope.opts = {
// number of records to fetch, then paginate through
sampleSize: config.get('discover:sampleSize'),
timefield: isDefaultTypeIndexPattern($scope.indexPattern) && $scope.indexPattern.timeFieldName,
timefield:
indexPatternsUtils.isDefault($scope.indexPattern) && $scope.indexPattern.timeFieldName,
savedSearch: savedSearch,
indexPatternList: $route.current.locals.savedObjects.ip.list,
};
Expand Down Expand Up @@ -1162,7 +1166,7 @@ function discoverController(
// Block the UI from loading if the user has loaded a rollup index pattern but it isn't
// supported.
$scope.isUnsupportedIndexPattern =
!isDefaultTypeIndexPattern($route.current.locals.savedObjects.ip.loaded) &&
!indexPatternsUtils.isDefault($route.current.locals.savedObjects.ip.loaded) &&
!hasSearchStategyForIndexPattern($route.current.locals.savedObjects.ip.loaded);

if ($scope.isUnsupportedIndexPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { getTableAggs } from 'ui/visualize/loader/pipeline_helpers/utilities';
import { AppState } from 'ui/state_management/app_state';
import { npStart } from 'ui/new_platform';
import { IExpressionLoaderParams } from 'src/plugins/expressions/public';
import { ISearchSource } from 'ui/courier';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
import {
IIndexPattern,
Expand All @@ -38,6 +37,7 @@ import {
onlyDisabledFiltersChanged,
esFilters,
mapAndFlattenFilters,
ISearchSource,
} from '../../../../../plugins/data/public';
import {
EmbeddableInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* under the License.
*/

export { searchSourceMock } from '../../../ui/public/courier/search_source/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { searchSourceMock } from '../../../../plugins/data/public/search/search_source/mocks';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { EuiIcon, EuiSpacer, EuiText } from '@elastic/eui';
import React from 'react';
import { SearchError } from '../../../../../data/public/search/search_strategy';
import { SearchError } from '../../../../../../../plugins/data/public';

interface VisualizationRequestErrorProps {
onInit?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import { cloneDeep, get } from 'lodash';
// @ts-ignore
import moment from 'moment';
import { SerializedFieldFormat } from 'src/plugins/expressions/public';
import { ISearchSource } from 'src/plugins/data/public';
import {
AggConfig,
setBounds,
isDateHistogramBucketAggConfig,
createFormat,
} from '../../../legacy_imports';
// eslint-disable-next-line
import { ISearchSource } from '../../../../../../ui/public/courier/search_source/search_source';
import { Vis, VisParams, VisState } from '..';

interface SchemaConfigParams {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/server/config/override.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';
import explodeBy from './explode_by';
import { getFlattenedObject } from '../../utils';
import { getFlattenedObject } from '../../../core/utils';

export default function(target, source) {
const _target = getFlattenedObject(target);
Expand Down
1 change: 0 additions & 1 deletion src/legacy/ui/public/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@import './accessibility/index';
@import './chrome/index';
@import './courier/index';
@import './collapsible_sidebar/index';
@import './directives/index';
@import './error_auto_create_index/index';
Expand Down
Loading

0 comments on commit 133c299

Please sign in to comment.