Move legacy/server/index_patterns -> src/plugins/data/server (#46537)
Dismissed @elastic/kibana-app review of import changes. ts-ignored @ts-ignore * Moved files to plugins/data/server. * Renamed IndexPatternsService to IndexPatternsFetcher and created new IndexPatternsService * Set routerPath. * Fixed type error. * Changed beats_management _fields_for_wildcard request with data/public/legacy api. * Fixed changed paths. * Fixes crashes after merge. * Updated path for clarity. * Applied Plugin interface to service. * Fixed test failure caused by non camel case local variable name. * Fixed import to IndexPatternsService to IndexPatternsFetcher.
This commit is contained in:
parent
7cfcc4dfce
commit
3f130ba27f
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { castEsToKbnFieldTypeName } from '../plugins/data/common';
|
||||
// eslint-disable-next-line max-len
|
||||
import { shouldReadFieldFromDocValues } from '../legacy/server/index_patterns/service/lib/field_capabilities/should_read_field_from_doc_values';
|
||||
import { shouldReadFieldFromDocValues } from '../plugins/data/server';
|
||||
|
||||
function stubbedLogstashFields() {
|
||||
return [
|
||||
|
|
|
@ -29,7 +29,7 @@ import { fieldFormats } from 'ui/registry/field_formats';
|
|||
|
||||
import { createIndexPatternCache } from './_pattern_cache';
|
||||
import { IndexPattern } from './index_pattern';
|
||||
import { IndexPatternsApiClient } from './index_patterns_api_client';
|
||||
import { IndexPatternsApiClient, GetFieldsOptions } from './index_patterns_api_client';
|
||||
|
||||
const indexPatternCache = createIndexPatternCache();
|
||||
|
||||
|
@ -93,6 +93,14 @@ export class IndexPatterns {
|
|||
});
|
||||
};
|
||||
|
||||
getFieldsForTimePattern = (options: GetFieldsOptions = {}) => {
|
||||
return this.apiClient.getFieldsForTimePattern(options);
|
||||
};
|
||||
|
||||
getFieldsForWildcard = (options: GetFieldsOptions = {}) => {
|
||||
return this.apiClient.getFieldsForWildcard(options);
|
||||
};
|
||||
|
||||
clearCache = (id?: string) => {
|
||||
this.savedObjectsCache = null;
|
||||
if (id) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { IndexPatternsService } from '../../../../server/index_patterns/service';
|
||||
import { IndexPatternsFetcher } from '../../../../../plugins/data/server/';
|
||||
export const getIndexPatternService = {
|
||||
assign: 'indexPatternsService',
|
||||
method(req) {
|
||||
|
@ -25,6 +25,6 @@ export const getIndexPatternService = {
|
|||
const callDataCluster = (...args) => {
|
||||
return dataCluster.callWithRequest(req, ...args);
|
||||
};
|
||||
return new IndexPatternsService(callDataCluster);
|
||||
return new IndexPatternsFetcher(callDataCluster);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
// @ts-ignore no types
|
||||
export { indexPatternsMixin } from './mixin';
|
||||
export { IndexPatternsService, FieldDescriptor } from './service';
|
||||
export {
|
||||
IndexPatternsFetcher,
|
||||
FieldDescriptor,
|
||||
} from '../../../plugins/data/server/index_patterns/fetcher';
|
||||
export { IndexPatternsServiceFactory } from './mixin';
|
||||
|
|
|
@ -17,11 +17,10 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { IndexPatternsService } from './service';
|
||||
import { IndexPatternsFetcher } from '../../../plugins/data/server';
|
||||
import KbnServer from '../kbn_server';
|
||||
import { APICaller, CallAPIOptions } from '../../../core/server';
|
||||
import { Legacy } from '../../../../kibana';
|
||||
import { registerRoutes } from './routes';
|
||||
|
||||
export function indexPatternsMixin(kbnServer: KbnServer, server: Legacy.Server) {
|
||||
/**
|
||||
|
@ -31,7 +30,7 @@ export function indexPatternsMixin(kbnServer: KbnServer, server: Legacy.Server)
|
|||
* @type {IndexPatternsService}
|
||||
*/
|
||||
server.decorate('server', 'indexPatternsServiceFactory', ({ callCluster }) => {
|
||||
return new IndexPatternsService(callCluster);
|
||||
return new IndexPatternsFetcher(callCluster);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -50,10 +49,8 @@ export function indexPatternsMixin(kbnServer: KbnServer, server: Legacy.Server)
|
|||
) => callWithRequest(request, endpoint, params, options);
|
||||
return server.indexPatternsServiceFactory({ callCluster });
|
||||
});
|
||||
|
||||
registerRoutes(kbnServer.newPlatform.setup.core);
|
||||
}
|
||||
|
||||
export type IndexPatternsServiceFactory = (args: {
|
||||
callCluster: (endpoint: string, clientParams: any, options: any) => Promise<any>;
|
||||
}) => IndexPatternsService;
|
||||
}) => IndexPatternsFetcher;
|
||||
|
|
2
src/legacy/server/kbn_server.d.ts
vendored
2
src/legacy/server/kbn_server.d.ts
vendored
|
@ -150,5 +150,5 @@ export default class KbnServer {
|
|||
export { Server, Request, ResponseToolkit } from 'hapi';
|
||||
|
||||
// Re-export commonly accessed api types.
|
||||
export { IndexPatternsService } from './index_patterns';
|
||||
export { IndexPatternsFetcher as IndexPatternsService } from './index_patterns';
|
||||
export { SavedObjectsLegacyService, SavedObjectsClient } from 'src/core/server';
|
||||
|
|
|
@ -25,6 +25,11 @@ export function plugin(initializerContext: PluginInitializerContext) {
|
|||
}
|
||||
|
||||
export { DataServerPlugin as Plugin };
|
||||
export {
|
||||
IndexPatternsFetcher,
|
||||
FieldDescriptor,
|
||||
shouldReadFieldFromDocValues,
|
||||
} from './index_patterns';
|
||||
|
||||
export * from './search';
|
||||
|
||||
|
|
|
@ -17,4 +17,5 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export * from './index_patterns_service';
|
||||
export * from './index_patterns_fetcher';
|
||||
export { shouldReadFieldFromDocValues } from './lib';
|
|
@ -36,7 +36,7 @@ interface FieldSubType {
|
|||
nested?: { path: string };
|
||||
}
|
||||
|
||||
export class IndexPatternsService {
|
||||
export class IndexPatternsFetcher {
|
||||
private _callDataCluster: APICaller;
|
||||
|
||||
constructor(callDataCluster: APICaller) {
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
import { APICaller } from 'src/core/server';
|
||||
// @ts-ignore
|
||||
import { convertEsError } from './errors';
|
||||
import { FieldCapsResponse } from './field_capabilities';
|
||||
|
|
@ -23,7 +23,7 @@ import { APICaller } from 'src/core/server';
|
|||
import { callFieldCapsApi } from '../es_api';
|
||||
import { FieldCapsResponse, readFieldCapsResponse } from './field_caps_response';
|
||||
import { mergeOverrides } from './overrides';
|
||||
import { FieldDescriptor } from '../../index_patterns_service';
|
||||
import { FieldDescriptor } from '../../index_patterns_fetcher';
|
||||
|
||||
export function concatIfUniq<T>(arr: T[], value: T) {
|
||||
return arr.includes(value) ? arr : arr.concat(value);
|
|
@ -24,7 +24,7 @@ import sinon from 'sinon';
|
|||
import * as shouldReadFieldFromDocValuesNS from './should_read_field_from_doc_values';
|
||||
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
|
||||
|
||||
import { getKbnFieldType } from '../../../../../../plugins/data/common';
|
||||
import { getKbnFieldType } from '../../../../../../data/common';
|
||||
import { readFieldCapsResponse } from './field_caps_response';
|
||||
import esResponse from './__fixtures__/es_field_caps_response.json';
|
||||
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
|
||||
import { uniq } from 'lodash';
|
||||
import { FieldDescriptor } from '../..';
|
||||
import { castEsToKbnFieldTypeName } from '../../../../../common';
|
||||
import { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
|
||||
import { castEsToKbnFieldTypeName } from '../../../../../../plugins/data/common';
|
||||
import { FieldDescriptor } from '../../../fetcher';
|
||||
|
||||
interface FieldCapObject {
|
||||
type: string;
|
|
@ -19,3 +19,4 @@
|
|||
|
||||
export { getFieldCapabilities } from './field_capabilities';
|
||||
export { FieldCapsResponse } from './field_caps_response';
|
||||
export { shouldReadFieldFromDocValues } from './should_read_field_from_doc_values';
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { merge } from 'lodash';
|
||||
import { FieldDescriptor } from '../../index_patterns_service';
|
||||
import { FieldDescriptor } from '../../index_patterns_fetcher';
|
||||
|
||||
const OVERRIDES: Record<string, Partial<FieldDescriptor>> = {
|
||||
_source: { type: '_source' },
|
|
@ -17,8 +17,6 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
export { getFieldCapabilities } from './field_capabilities';
|
||||
// @ts-ignore
|
||||
export { getFieldCapabilities, shouldReadFieldFromDocValues } from './field_capabilities';
|
||||
export { resolveTimePattern } from './resolve_time_pattern';
|
||||
// @ts-ignore
|
||||
export { createNoMatchingIndicesError } from './errors';
|
21
src/plugins/data/server/index_patterns/index.ts
Normal file
21
src/plugins/data/server/index_patterns/index.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
export { IndexPatternsFetcher, FieldDescriptor, shouldReadFieldFromDocValues } from './fetcher';
|
||||
export { IndexPatternsService } from './index_patterns_service';
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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 { CoreSetup } from 'kibana/server';
|
||||
import { Plugin } from '../../../../core/server';
|
||||
import { registerRoutes } from './routes';
|
||||
|
||||
export class IndexPatternsService implements Plugin<void> {
|
||||
public setup({ http, elasticsearch }: CoreSetup) {
|
||||
registerRoutes(http, elasticsearch);
|
||||
}
|
||||
|
||||
public start() {}
|
||||
}
|
|
@ -25,18 +25,18 @@ import {
|
|||
RequestHandlerContext,
|
||||
APICaller,
|
||||
CallAPIOptions,
|
||||
} from '../../../core/server';
|
||||
import { IndexPatternsService } from './service';
|
||||
} from '../../../../core/server';
|
||||
import { IndexPatternsFetcher } from './fetcher';
|
||||
|
||||
export function registerRoutes(core: CoreSetup) {
|
||||
const getIndexPatternsService = async (request: KibanaRequest): Promise<IndexPatternsService> => {
|
||||
const client = await core.elasticsearch.dataClient$.pipe(first()).toPromise();
|
||||
export function registerRoutes(http: CoreSetup['http'], elasticsearch: CoreSetup['elasticsearch']) {
|
||||
const getIndexPatternsService = async (request: KibanaRequest): Promise<IndexPatternsFetcher> => {
|
||||
const client = await elasticsearch.dataClient$.pipe(first()).toPromise();
|
||||
const callCluster: APICaller = (
|
||||
endpoint: string,
|
||||
params?: Record<string, any>,
|
||||
options?: CallAPIOptions
|
||||
) => client.asScoped(request).callAsCurrentUser(endpoint, params, options);
|
||||
return new Promise(resolve => resolve(new IndexPatternsService(callCluster)));
|
||||
return new Promise(resolve => resolve(new IndexPatternsFetcher(callCluster)));
|
||||
};
|
||||
|
||||
const parseMetaFields = (metaFields: string | string[]) => {
|
||||
|
@ -49,7 +49,7 @@ export function registerRoutes(core: CoreSetup) {
|
|||
return parsedFields;
|
||||
};
|
||||
|
||||
const router = core.http.createRouter();
|
||||
const router = http.createRouter();
|
||||
router.get(
|
||||
{
|
||||
path: '/api/index_patterns/_fields_for_wildcard',
|
|
@ -18,19 +18,21 @@
|
|||
*/
|
||||
|
||||
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/server';
|
||||
import { IndexPatternsService } from './index_patterns';
|
||||
import { ISearchSetup } from './search';
|
||||
import { SearchService } from './search/search_service';
|
||||
|
||||
export interface DataPluginSetup {
|
||||
search: ISearchSetup;
|
||||
}
|
||||
|
||||
export class DataServerPlugin implements Plugin<DataPluginSetup> {
|
||||
private readonly searchService: SearchService;
|
||||
private readonly indexPatterns = new IndexPatternsService();
|
||||
constructor(initializerContext: PluginInitializerContext) {
|
||||
this.searchService = new SearchService(initializerContext);
|
||||
}
|
||||
public setup(core: CoreSetup) {
|
||||
this.indexPatterns.setup(core);
|
||||
return {
|
||||
search: this.searchService.setup(core),
|
||||
};
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
createNoMatchingIndicesError,
|
||||
isNoMatchingIndicesError,
|
||||
convertEsError
|
||||
} from '../../../../../src/legacy/server/index_patterns/service/lib/errors';
|
||||
} from '../../../../../src/plugins/data/server/index_patterns/fetcher/lib/errors';
|
||||
|
||||
import {
|
||||
getIndexNotFoundError,
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
import { Legacy } from 'kibana';
|
||||
import { StaticIndexPattern } from 'ui/index_patterns';
|
||||
import { APICaller } from 'src/core/server';
|
||||
import { IndexPatternsService } from '../../../../../../../src/legacy/server/index_patterns/service';
|
||||
import { IndexPatternsFetcher } from '../../../../../../../src/plugins/data/server';
|
||||
import { Setup } from '../helpers/setup_request';
|
||||
|
||||
export const getKueryBarIndexPattern = async ({
|
||||
|
@ -21,7 +21,7 @@ export const getKueryBarIndexPattern = async ({
|
|||
}) => {
|
||||
const { indices } = setup;
|
||||
|
||||
const indexPatternsService = new IndexPatternsService(
|
||||
const indexPatternsFetcher = new IndexPatternsFetcher(
|
||||
(...rest: Parameters<APICaller>) =>
|
||||
request.server.plugins.elasticsearch
|
||||
.getCluster('data')
|
||||
|
@ -40,7 +40,7 @@ export const getKueryBarIndexPattern = async ({
|
|||
|
||||
const configuredIndices = indexNames.map(name => indicesMap[name]);
|
||||
|
||||
const fields = await indexPatternsService.getFieldsForWildcard({
|
||||
const fields = await indexPatternsFetcher.getFieldsForWildcard({
|
||||
pattern: configuredIndices
|
||||
});
|
||||
|
||||
|
|
|
@ -7,16 +7,16 @@
|
|||
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { npStart } from 'ui/new_platform';
|
||||
import { RestAPIAdapter } from '../rest_api/adapter_types';
|
||||
import { ElasticsearchAdapter } from './adapter_types';
|
||||
import { AutocompleteSuggestion } from '../../../../../../../../src/plugins/data/public';
|
||||
import { setup as data } from '../../../../../../../../src/legacy/core_plugins/data/public/legacy';
|
||||
|
||||
const getAutocompleteProvider = (language: string) =>
|
||||
npStart.plugins.data.autocomplete.getProvider(language);
|
||||
|
||||
export class RestElasticsearchAdapter implements ElasticsearchAdapter {
|
||||
private cachedIndexPattern: any = null;
|
||||
constructor(private readonly api: RestAPIAdapter, private readonly indexPatternName: string) {}
|
||||
constructor(private readonly indexPatternName: string) {}
|
||||
|
||||
public isKueryValid(kuery: string): boolean {
|
||||
try {
|
||||
|
@ -65,9 +65,9 @@ export class RestElasticsearchAdapter implements ElasticsearchAdapter {
|
|||
if (this.cachedIndexPattern) {
|
||||
return this.cachedIndexPattern;
|
||||
}
|
||||
const res = await this.api.get<any>(
|
||||
`/api/index_patterns/_fields_for_wildcard?pattern=${this.indexPatternName}`
|
||||
);
|
||||
const res = await data.indexPatterns.indexPatterns.getFieldsForWildcard({
|
||||
pattern: this.indexPatternName,
|
||||
});
|
||||
if (isEmpty(res.fields)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ const onKibanaReady = chrome.dangerouslyGetActiveInjector;
|
|||
|
||||
export function compose(): FrontendLibs {
|
||||
const api = new AxiosRestAPIAdapter(chrome.getXsrfToken(), chrome.getBasePath());
|
||||
const esAdapter = new RestElasticsearchAdapter(api, INDEX_NAMES.BEATS);
|
||||
const esAdapter = new RestElasticsearchAdapter(INDEX_NAMES.BEATS);
|
||||
const elasticsearchLib = new ElasticsearchLib(esAdapter);
|
||||
const configBlocks = new ConfigBlocksLib(
|
||||
new RestConfigBlocksAdapter(api),
|
||||
|
|
|
@ -11,10 +11,7 @@ import _ from 'lodash';
|
|||
import { IScopedClusterClient } from 'src/core/server';
|
||||
import { CoreSetup } from 'src/core/server';
|
||||
import { BASE_API_URL } from '../../common';
|
||||
import {
|
||||
FieldDescriptor,
|
||||
IndexPatternsService,
|
||||
} from '../../../../../../src/legacy/server/index_patterns/service';
|
||||
import { FieldDescriptor, IndexPatternsFetcher } from '../../../../../../src/plugins/data/server';
|
||||
|
||||
/**
|
||||
* The number of docs to sample to determine field empty status.
|
||||
|
@ -42,11 +39,11 @@ export async function existingFieldsRoute(setup: CoreSetup) {
|
|||
async (context, req, res) => {
|
||||
const { indexPatternTitle } = req.params;
|
||||
const requestClient = context.core.elasticsearch.dataClient;
|
||||
const indexPatternsService = new IndexPatternsService(requestClient.callAsCurrentUser);
|
||||
const indexPatternsFetcher = new IndexPatternsFetcher(requestClient.callAsCurrentUser);
|
||||
const { fromDate, toDate, timeFieldName } = req.query;
|
||||
|
||||
try {
|
||||
const fields = await indexPatternsService.getFieldsForWildcard({
|
||||
const fields = await indexPatternsFetcher.getFieldsForWildcard({
|
||||
pattern: indexPatternTitle,
|
||||
// TODO: Pull this from kibana advanced settings
|
||||
metaFields: ['_source', '_id', '_type', '_index', '_score'],
|
||||
|
|
Loading…
Reference in a new issue