From 27dd6dda38d7d30a3a69fa2e0450e48c7f85d547 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 5 Feb 2020 18:35:40 +0100 Subject: [PATCH] Move lens server to new platform (#56474) --- .../plugins/apm/common/projections/typings.ts | 7 +- .../util/merge_projection/index.ts | 4 +- .../shared/KueryBar/get_bool_filter.ts | 2 +- .../plugins/apm/public/services/rest/ml.ts | 2 +- .../plugins/apm/public/utils/testHelpers.tsx | 2 +- .../lib/errors/distribution/get_buckets.ts | 2 +- .../apm/server/lib/errors/get_error_groups.ts | 2 +- .../get_environment_ui_filter_es.test.ts | 2 +- .../get_environment_ui_filter_es.ts | 2 +- .../convert_ui_filters/get_ui_filters_es.ts | 2 +- .../apm/server/lib/helpers/es_client.ts | 2 +- .../apm/server/lib/helpers/setup_request.ts | 2 +- .../metrics/fetch_and_transform_metrics.ts | 2 +- .../lib/metrics/transform_metrics_chart.ts | 4 +- .../get_service_map_service_node_info.ts | 2 +- .../lib/service_map/get_trace_sample_ids.ts | 2 +- .../server/lib/services/annotations/index.ts | 2 +- .../settings/agent_configuration/search.ts | 2 +- .../server/lib/transaction_groups/fetcher.ts | 2 +- .../__fixtures__/responses.ts | 2 +- .../avg_duration_by_browser/fetcher.ts | 2 +- .../charts/get_timeseries_data/fetcher.ts | 2 +- .../server/lib/ui_filters/get_environments.ts | 2 +- x-pack/legacy/plugins/lens/index.ts | 35 +----- .../plugins/lens/public/app_plugin/plugin.tsx | 2 +- .../embeddable/embeddable_factory.ts | 2 +- .../public/indexpattern_plugin/auto_date.ts | 2 +- .../dimension_panel/dimension_panel.tsx | 2 +- .../public/indexpattern_plugin/field_item.tsx | 2 +- .../lens/public/indexpattern_plugin/loader.ts | 4 +- .../operations/definitions/index.ts | 2 +- .../lens/public/lens_ui_telemetry/factory.ts | 2 +- .../lens/public/register_vis_type_alias.ts | 2 +- x-pack/legacy/plugins/lens/public/types.ts | 2 +- x-pack/legacy/plugins/lens/server/plugin.tsx | 57 --------- .../lib/tasks/visualizations/task_runner.ts | 2 +- .../apm/typings/elasticsearch/aggregations.ts | 30 +---- .../apm/typings/elasticsearch/index.ts | 13 +-- .../{legacy => }/plugins/lens/common/api.ts | 0 .../plugins/lens/common/constants.ts | 0 .../{legacy => }/plugins/lens/common/index.ts | 0 .../{legacy => }/plugins/lens/common/types.ts | 0 x-pack/plugins/lens/kibana.json | 8 ++ .../{legacy => }/plugins/lens/server/index.ts | 6 +- x-pack/plugins/lens/server/plugin.tsx | 62 ++++++++++ .../server/routes/existing_fields.test.ts | 0 .../lens/server/routes/existing_fields.ts | 3 +- .../plugins/lens/server/routes/field_stats.ts | 0 .../plugins/lens/server/routes/index.ts | 13 +-- .../plugins/lens/server/routes/telemetry.ts | 24 +--- .../plugins/lens/server/usage/collectors.ts | 2 +- .../plugins/lens/server/usage/index.ts | 0 .../plugins/lens/server/usage/task.ts | 108 +++++++----------- .../plugins/lens/server/usage/types.ts | 0 .../lens/server/usage/visualization_counts.ts | 18 +-- .../api_integration/apis/lens/telemetry.ts | 19 +-- 56 files changed, 187 insertions(+), 290 deletions(-) delete mode 100644 x-pack/legacy/plugins/lens/server/plugin.tsx rename x-pack/{legacy => }/plugins/apm/typings/elasticsearch/aggregations.ts (91%) rename x-pack/{legacy => }/plugins/apm/typings/elasticsearch/index.ts (84%) rename x-pack/{legacy => }/plugins/lens/common/api.ts (100%) rename x-pack/{legacy => }/plugins/lens/common/constants.ts (100%) rename x-pack/{legacy => }/plugins/lens/common/index.ts (100%) rename x-pack/{legacy => }/plugins/lens/common/types.ts (100%) create mode 100644 x-pack/plugins/lens/kibana.json rename x-pack/{legacy => }/plugins/lens/server/index.ts (55%) create mode 100644 x-pack/plugins/lens/server/plugin.tsx rename x-pack/{legacy => }/plugins/lens/server/routes/existing_fields.test.ts (100%) rename x-pack/{legacy => }/plugins/lens/server/routes/existing_fields.ts (98%) rename x-pack/{legacy => }/plugins/lens/server/routes/field_stats.ts (100%) rename x-pack/{legacy => }/plugins/lens/server/routes/index.ts (59%) rename x-pack/{legacy => }/plugins/lens/server/routes/telemetry.ts (75%) rename x-pack/{legacy => }/plugins/lens/server/usage/collectors.ts (97%) rename x-pack/{legacy => }/plugins/lens/server/usage/index.ts (100%) rename x-pack/{legacy => }/plugins/lens/server/usage/task.ts (62%) rename x-pack/{legacy => }/plugins/lens/server/usage/types.ts (100%) rename x-pack/{legacy => }/plugins/lens/server/usage/visualization_counts.ts (85%) diff --git a/x-pack/legacy/plugins/apm/common/projections/typings.ts b/x-pack/legacy/plugins/apm/common/projections/typings.ts index 2b55395b70c6ba..08a7bee5412a53 100644 --- a/x-pack/legacy/plugins/apm/common/projections/typings.ts +++ b/x-pack/legacy/plugins/apm/common/projections/typings.ts @@ -4,11 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESSearchRequest, ESSearchBody } from '../../typings/elasticsearch'; +import { + ESSearchRequest, + ESSearchBody +} from '../../../../../plugins/apm/typings/elasticsearch'; import { AggregationOptionsByType, AggregationInputMap -} from '../../typings/elasticsearch/aggregations'; +} from '../../../../../plugins/apm/typings/elasticsearch/aggregations'; export type Projection = Omit & { body: Omit & { diff --git a/x-pack/legacy/plugins/apm/common/projections/util/merge_projection/index.ts b/x-pack/legacy/plugins/apm/common/projections/util/merge_projection/index.ts index 6a5089733bb339..ef6089872b786e 100644 --- a/x-pack/legacy/plugins/apm/common/projections/util/merge_projection/index.ts +++ b/x-pack/legacy/plugins/apm/common/projections/util/merge_projection/index.ts @@ -5,11 +5,11 @@ */ import { merge, isPlainObject, cloneDeep } from 'lodash'; import { DeepPartial } from 'utility-types'; -import { AggregationInputMap } from '../../../../typings/elasticsearch/aggregations'; +import { AggregationInputMap } from '../../../../../../../plugins/apm/typings/elasticsearch/aggregations'; import { ESSearchRequest, ESSearchBody -} from '../../../../typings/elasticsearch'; +} from '../../../../../../../plugins/apm/typings/elasticsearch'; import { Projection } from '../../typings'; type PlainObject = Record; diff --git a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts index f4628524cced58..23feeed4b04189 100644 --- a/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts +++ b/x-pack/legacy/plugins/apm/public/components/shared/KueryBar/get_bool_filter.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { TRANSACTION_TYPE, ERROR_GROUP_ID, diff --git a/x-pack/legacy/plugins/apm/public/services/rest/ml.ts b/x-pack/legacy/plugins/apm/public/services/rest/ml.ts index e42b9536362e03..187a051b1b0444 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/ml.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/ml.ts @@ -12,7 +12,7 @@ import { } from '../../../common/elasticsearch_fieldnames'; import { getMlJobId, getMlPrefix } from '../../../common/ml_job_constants'; import { callApi } from './callApi'; -import { ESFilter } from '../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch'; import { createCallApmApi, APMClient } from './createCallApmApi'; interface MlResponseItem { diff --git a/x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx b/x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx index 862c982d6b5ac5..3d34f016c65916 100644 --- a/x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx +++ b/x-pack/legacy/plugins/apm/public/utils/testHelpers.tsx @@ -23,7 +23,7 @@ import { ESFilter, ESSearchResponse, ESSearchRequest -} from '../../typings/elasticsearch'; +} from '../../../../../plugins/apm/typings/elasticsearch'; import { ApmPluginContext, ApmPluginContextValue diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts b/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts index 9274f96d58d83c..0f6ace39aeca30 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts +++ b/x-pack/legacy/plugins/apm/server/lib/errors/distribution/get_buckets.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { ERROR_GROUP_ID, PROCESSOR_EVENT, diff --git a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts b/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts index aaa4ca9fb82230..92ee6a0a71f00e 100644 --- a/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts +++ b/x-pack/legacy/plugins/apm/server/lib/errors/get_error_groups.ts @@ -20,7 +20,7 @@ import { } from '../helpers/setup_request'; import { getErrorGroupsProjection } from '../../../common/projections/errors'; import { mergeProjection } from '../../../common/projections/util/merge_projection'; -import { SortOptions } from '../../../typings/elasticsearch/aggregations'; +import { SortOptions } from '../../../../../../plugins/apm/typings/elasticsearch/aggregations'; export type ErrorGroupListAPIResponse = PromiseReturnType< typeof getErrorGroups diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts index 0f0a11a868d6d7..b5061e303a40dd 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts @@ -7,7 +7,7 @@ import { getEnvironmentUiFilterES } from '../get_environment_ui_filter_es'; import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values'; import { SERVICE_ENVIRONMENT } from '../../../../../common/elasticsearch_fieldnames'; -import { ESFilter } from '../../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../../plugins/apm/typings/elasticsearch'; describe('getEnvironmentUiFilterES', () => { it('should return undefined, when environment is undefined', () => { diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts index 57feaf6a6fd0ed..dcf2334ab4de23 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { ENVIRONMENT_NOT_DEFINED } from '../../../../common/environment_filter_values'; import { SERVICE_ENVIRONMENT } from '../../../../common/elasticsearch_fieldnames'; diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts index a6f6d36ecfc81a..126ee49fd42189 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { UIFilters } from '../../../../typings/ui-filters'; import { getEnvironmentUiFilterES } from './get_environment_ui_filter_es'; import { diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts index 737eeac95516e9..2795c95a500342 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/es_client.ts @@ -18,7 +18,7 @@ import { OBSERVER_VERSION_MAJOR } from '../../../common/elasticsearch_fieldnames import { ESSearchResponse, ESSearchRequest -} from '../../../typings/elasticsearch'; +} from '../../../../../../plugins/apm/typings/elasticsearch'; import { APMRequestHandlerContext } from '../../routes/typings'; import { pickKeys } from '../../../public/utils/pickKeys'; import { getApmIndices } from '../settings/apm_indices/get_apm_indices'; diff --git a/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts b/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts index 56c92558440094..f8946997e6e18b 100644 --- a/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts +++ b/x-pack/legacy/plugins/apm/server/lib/helpers/setup_request.ts @@ -12,7 +12,7 @@ import { getApmIndices, ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; -import { ESFilter } from '../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch'; import { ESClient } from './es_client'; import { getUiFiltersES } from './convert_ui_filters/get_ui_filters_es'; import { APMRequestHandlerContext } from '../../routes/typings'; diff --git a/x-pack/legacy/plugins/apm/server/lib/metrics/fetch_and_transform_metrics.ts b/x-pack/legacy/plugins/apm/server/lib/metrics/fetch_and_transform_metrics.ts index 76460bb40bedb2..410d659a924fdb 100644 --- a/x-pack/legacy/plugins/apm/server/lib/metrics/fetch_and_transform_metrics.ts +++ b/x-pack/legacy/plugins/apm/server/lib/metrics/fetch_and_transform_metrics.ts @@ -15,7 +15,7 @@ import { ChartBase } from './types'; import { transformDataToMetricsChart } from './transform_metrics_chart'; import { getMetricsProjection } from '../../../common/projections/metrics'; import { mergeProjection } from '../../../common/projections/util/merge_projection'; -import { AggregationOptionsByType } from '../../../typings/elasticsearch/aggregations'; +import { AggregationOptionsByType } from '../../../../../../plugins/apm/typings/elasticsearch/aggregations'; interface Aggs { [key: string]: Unionize<{ diff --git a/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts b/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts index 03f21e4f26e7be..8e7c969eec96a7 100644 --- a/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts +++ b/x-pack/legacy/plugins/apm/server/lib/metrics/transform_metrics_chart.ts @@ -9,8 +9,8 @@ import { ChartBase } from './types'; import { ESSearchResponse, ESSearchRequest -} from '../../../typings/elasticsearch'; -import { AggregationOptionsByType } from '../../../typings/elasticsearch/aggregations'; +} from '../../../../../../plugins/apm/typings/elasticsearch'; +import { AggregationOptionsByType } from '../../../../../../plugins/apm/typings/elasticsearch/aggregations'; import { getVizColorForIndex } from '../../../common/viz_colors'; export type GenericMetricsChart = ReturnType< diff --git a/x-pack/legacy/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/legacy/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts index 6c4d540103ceca..cff2d8570349e1 100644 --- a/x-pack/legacy/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts +++ b/x-pack/legacy/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts @@ -5,7 +5,7 @@ */ import { Setup, SetupTimeRange } from '../helpers/setup_request'; -import { ESFilter } from '../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch'; import { rangeFilter } from '../helpers/range_filter'; import { PROCESSOR_EVENT, diff --git a/x-pack/legacy/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts b/x-pack/legacy/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts index acf113b4266081..bb5fcabb6c9d71 100644 --- a/x-pack/legacy/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts +++ b/x-pack/legacy/plugins/apm/server/lib/service_map/get_trace_sample_ids.ts @@ -10,7 +10,7 @@ import { SetupTimeRange } from '../helpers/setup_request'; import { rangeFilter } from '../helpers/range_filter'; -import { ESFilter } from '../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch'; import { PROCESSOR_EVENT, SERVICE_NAME, diff --git a/x-pack/legacy/plugins/apm/server/lib/services/annotations/index.ts b/x-pack/legacy/plugins/apm/server/lib/services/annotations/index.ts index c03746ca220ee4..9c8e4f2281b5e3 100644 --- a/x-pack/legacy/plugins/apm/server/lib/services/annotations/index.ts +++ b/x-pack/legacy/plugins/apm/server/lib/services/annotations/index.ts @@ -5,7 +5,7 @@ */ import { isNumber } from 'lodash'; import { Annotation, AnnotationType } from '../../../../common/annotations'; -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { SERVICE_NAME, SERVICE_ENVIRONMENT, diff --git a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts index 766baead006b6e..3f4225eaf22d67 100644 --- a/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts +++ b/x-pack/legacy/plugins/apm/server/lib/settings/agent_configuration/search.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { ESSearchHit } from '../../../../typings/elasticsearch'; +import { ESSearchHit } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { SERVICE_NAME, SERVICE_ENVIRONMENT diff --git a/x-pack/legacy/plugins/apm/server/lib/transaction_groups/fetcher.ts b/x-pack/legacy/plugins/apm/server/lib/transaction_groups/fetcher.ts index a4885f2884976b..18c61df0cfa7e7 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transaction_groups/fetcher.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transaction_groups/fetcher.ts @@ -13,7 +13,7 @@ import { import { getTransactionGroupsProjection } from '../../../common/projections/transaction_groups'; import { mergeProjection } from '../../../common/projections/util/merge_projection'; import { PromiseReturnType } from '../../../typings/common'; -import { SortOptions } from '../../../typings/elasticsearch/aggregations'; +import { SortOptions } from '../../../../../../plugins/apm/typings/elasticsearch/aggregations'; import { Transaction } from '../../../typings/es_schemas/ui/Transaction'; import { Setup, diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/__fixtures__/responses.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/__fixtures__/responses.ts index 3f0f8a84dc62ff..9a9bfc31c21d45 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/__fixtures__/responses.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/__fixtures__/responses.ts @@ -7,7 +7,7 @@ import { ESSearchResponse, ESSearchRequest -} from '../../../../../typings/elasticsearch'; +} from '../../../../../../../../plugins/apm/typings/elasticsearch'; export const response = ({ hits: { diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/fetcher.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/fetcher.ts index 8a96a25aef50e3..9b0d704dbb43ec 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/fetcher.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/avg_duration_by_browser/fetcher.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { PromiseReturnType } from '../../../../typings/common'; import { PROCESSOR_EVENT, diff --git a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/fetcher.ts b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/fetcher.ts index 8a2e01c9a78911..67b807da59b9b7 100644 --- a/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/fetcher.ts +++ b/x-pack/legacy/plugins/apm/server/lib/transactions/charts/get_timeseries_data/fetcher.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ESFilter } from '../../../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../../../plugins/apm/typings/elasticsearch'; import { PROCESSOR_EVENT, SERVICE_NAME, diff --git a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts index 50c1926d1e4a0b..05985ee95a2075 100644 --- a/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts +++ b/x-pack/legacy/plugins/apm/server/lib/ui_filters/get_environments.ts @@ -12,7 +12,7 @@ import { import { rangeFilter } from '../helpers/range_filter'; import { Setup, SetupTimeRange } from '../helpers/setup_request'; import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values'; -import { ESFilter } from '../../../typings/elasticsearch'; +import { ESFilter } from '../../../../../../plugins/apm/typings/elasticsearch'; export async function getEnvironments( setup: Setup & SetupTimeRange, diff --git a/x-pack/legacy/plugins/lens/index.ts b/x-pack/legacy/plugins/lens/index.ts index a4eb24d4a4de4f..bb0bf9b67ee2c4 100644 --- a/x-pack/legacy/plugins/lens/index.ts +++ b/x-pack/legacy/plugins/lens/index.ts @@ -7,11 +7,12 @@ import * as Joi from 'joi'; import { resolve } from 'path'; import { LegacyPluginInitializer } from 'src/legacy/types'; -import KbnServer, { Server } from 'src/legacy/server/kbn_server'; import mappings from './mappings.json'; -import { PLUGIN_ID, getEditPath, NOT_INTERNATIONALIZED_PRODUCT_NAME } from './common'; -import { lensServerPlugin } from './server'; -import { getTaskManagerSetup, getTaskManagerStart } from '../task_manager/server'; +import { + PLUGIN_ID, + getEditPath, + NOT_INTERNATIONALIZED_PRODUCT_NAME, +} from '../../../plugins/lens/common'; export const lens: LegacyPluginInitializer = kibana => { return new kibana.Plugin({ @@ -51,31 +52,5 @@ export const lens: LegacyPluginInitializer = kibana => { enabled: Joi.boolean().default(true), }).default(); }, - - init(server: Server) { - const kbnServer = (server as unknown) as KbnServer; - - // Set up with the new platform plugin lifecycle API. - const plugin = lensServerPlugin(); - const { usageCollection } = server.newPlatform.setup.plugins; - - plugin.setup(kbnServer.newPlatform.setup.core, { - usageCollection, - // Legacy APIs - savedObjects: server.savedObjects, - config: server.config(), - server, - taskManager: getTaskManagerSetup(server)!, - }); - - plugin.start(kbnServer.newPlatform.start.core, { - server, - taskManager: getTaskManagerStart(server)!, - }); - - server.events.on('stop', () => { - plugin.stop(); - }); - }, }); }; diff --git a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx index f7d9ae5741afbe..5efbd4b613a3ee 100644 --- a/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx @@ -40,7 +40,7 @@ import { stopReportManager, trackUiEvent, } from '../lens_ui_telemetry'; -import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../common'; +import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../../../../plugins/lens/common'; import { KibanaLegacySetup } from '../../../../../../src/plugins/kibana_legacy/public'; import { EditorFrameStart } from '../types'; import { diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts index 03a21a9b364c10..629efdbdb460bb 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable_factory.ts @@ -19,7 +19,7 @@ import { } from '../../../../../../../src/legacy/core_plugins/embeddable_api/public/np_ready/public'; import { Embeddable } from './embeddable'; import { SavedObjectIndexStore, DOC_TYPE } from '../../persistence'; -import { getEditPath } from '../../../common'; +import { getEditPath } from '../../../../../../plugins/lens/common'; export class EmbeddableFactory extends AbstractEmbeddableFactory { type = DOC_TYPE; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts index b62585f5da09ad..7720af8ee90017 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/auto_date.ts @@ -10,7 +10,7 @@ import { ExpressionFunction, KibanaContext, } from '../../../../../../src/plugins/expressions/public'; -import { DateRange } from '../../common'; +import { DateRange } from '../../../../../plugins/lens/common'; interface LensAutoDateProps { aggConfigs: string; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx index dfeb8632d096e0..972c396f93b430 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx @@ -19,7 +19,7 @@ import { changeColumn, deleteColumn } from '../state_helpers'; import { isDraggedField, hasField } from '../utils'; import { IndexPatternPrivateState, IndexPatternField } from '../types'; import { trackUiEvent } from '../../lens_ui_telemetry'; -import { DateRange } from '../../../common'; +import { DateRange } from '../../../../../../plugins/lens/common'; export type IndexPatternDimensionPanelProps = DatasourceDimensionPanelProps & { state: IndexPatternPrivateState; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx index 4a58f0354882a6..2aec28181f02b8 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx @@ -44,7 +44,7 @@ import { import { DraggedField } from './indexpattern'; import { DragDrop } from '../drag_drop'; import { DatasourceDataPanelProps, DataType } from '../types'; -import { BucketedAggregation, FieldStatsResponse } from '../../common'; +import { BucketedAggregation, FieldStatsResponse } from '../../../../../plugins/lens/common'; import { IndexPattern, IndexPatternField } from './types'; import { getColorForDataType, LensFieldIcon } from './lens_field_icon'; import { trackUiEvent } from '../lens_ui_telemetry'; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts index f0692f120f9b5b..e37c5db09ca745 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/loader.ts @@ -17,8 +17,8 @@ import { IndexPatternField, } from './types'; import { updateLayerIndexPattern } from './state_helpers'; -import { DateRange, ExistingFields } from '../../common/types'; -import { BASE_API_URL } from '../../common'; +import { DateRange, ExistingFields } from '../../../../../plugins/lens/common/types'; +import { BASE_API_URL } from '../../../../../plugins/lens/common'; import { documentField } from './document_field'; import { isNestedField, IFieldType, TypeMeta } from '../../../../../../src/plugins/data/public'; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts index 63e4564878e317..f357038be41a49 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts @@ -14,7 +14,7 @@ import { countOperation } from './count'; import { DimensionPriority, StateSetter, OperationMetadata } from '../../../types'; import { BaseIndexPatternColumn } from './column_types'; import { IndexPatternPrivateState, IndexPattern, IndexPatternField } from '../../types'; -import { DateRange } from '../../../../common'; +import { DateRange } from '../../../../../../../plugins/lens/common'; // List of all operation definitions registered to this data source. // If you want to implement a new operation, add it to this array and diff --git a/x-pack/legacy/plugins/lens/public/lens_ui_telemetry/factory.ts b/x-pack/legacy/plugins/lens/public/lens_ui_telemetry/factory.ts index babc65969afb50..73750a65c50b8b 100644 --- a/x-pack/legacy/plugins/lens/public/lens_ui_telemetry/factory.ts +++ b/x-pack/legacy/plugins/lens/public/lens_ui_telemetry/factory.ts @@ -8,7 +8,7 @@ import moment from 'moment'; import { HttpSetup } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; -import { BASE_API_URL } from '../../common'; +import { BASE_API_URL } from '../../../../../plugins/lens/common'; const STORAGE_KEY = 'lens-ui-telemetry'; diff --git a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts index 0c4e6d9f7cb10f..f71796268065b1 100644 --- a/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts +++ b/x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts @@ -6,7 +6,7 @@ import { i18n } from '@kbn/i18n'; import { setup as visualizations } from '../../../../../src/legacy/core_plugins/visualizations/public/np_ready/public/legacy'; -import { getBasePath, getEditPath } from '../common'; +import { getBasePath, getEditPath } from '../../../../plugins/lens/common'; visualizations.types.registerAlias({ aliasUrl: getBasePath(), diff --git a/x-pack/legacy/plugins/lens/public/types.ts b/x-pack/legacy/plugins/lens/public/types.ts index 923e0aff5ae0e8..e2157deb43e499 100644 --- a/x-pack/legacy/plugins/lens/public/types.ts +++ b/x-pack/legacy/plugins/lens/public/types.ts @@ -11,7 +11,7 @@ import { SavedQuery } from 'src/legacy/core_plugins/data/public'; import { KibanaDatatable } from '../../../../../src/plugins/expressions/public'; import { DragContextState } from './drag_drop'; import { Document } from './persistence'; -import { DateRange } from '../common'; +import { DateRange } from '../../../../plugins/lens/common'; import { Query, esFilters } from '../../../../../src/plugins/data/public'; // eslint-disable-next-line diff --git a/x-pack/legacy/plugins/lens/server/plugin.tsx b/x-pack/legacy/plugins/lens/server/plugin.tsx deleted file mode 100644 index f80d52248b4849..00000000000000 --- a/x-pack/legacy/plugins/lens/server/plugin.tsx +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { Server, KibanaConfig } from 'src/legacy/server/kbn_server'; -import { Plugin, CoreSetup, CoreStart, SavedObjectsLegacyService } from 'src/core/server'; -import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { Subject } from 'rxjs'; -import { first } from 'rxjs/operators'; -import { - TaskManagerSetupContract, - TaskManagerStartContract, -} from '../../../../plugins/task_manager/server'; -import { setupRoutes } from './routes'; -import { - registerLensUsageCollector, - initializeLensTelemetry, - scheduleLensTelemetry, -} from './usage'; - -export interface PluginSetupContract { - savedObjects: SavedObjectsLegacyService; - usageCollection: UsageCollectionSetup; - config: KibanaConfig; - server: Server; - taskManager: TaskManagerSetupContract; -} - -export interface PluginStartContract { - server: Server; - taskManager: TaskManagerStartContract; -} - -const taskManagerStartContract$ = new Subject(); - -export class LensServer implements Plugin<{}, {}, {}, {}> { - setup(core: CoreSetup, plugins: PluginSetupContract) { - setupRoutes(core, plugins); - registerLensUsageCollector( - plugins.usageCollection, - taskManagerStartContract$.pipe(first()).toPromise() - ); - initializeLensTelemetry(plugins.server, plugins.taskManager); - return {}; - } - - start(core: CoreStart, plugins: PluginStartContract) { - scheduleLensTelemetry(plugins.server, plugins.taskManager); - taskManagerStartContract$.next(plugins.taskManager); - taskManagerStartContract$.complete(); - return {}; - } - - stop() {} -} diff --git a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts index 0b7b301df12bf8..4c7525645a2c20 100644 --- a/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts +++ b/x-pack/legacy/plugins/oss_telemetry/server/lib/tasks/visualizations/task_runner.ts @@ -9,7 +9,7 @@ import { APICaller, CoreSetup } from 'kibana/server'; import { getNextMidnight } from '../../get_next_midnight'; import { VisState } from '../../../../../../../../src/legacy/core_plugins/visualizations/public'; import { TaskInstance } from '../../../../../../../plugins/task_manager/server'; -import { ESSearchHit } from '../../../../../apm/typings/elasticsearch'; +import { ESSearchHit } from '../../../../../../../plugins/apm/typings/elasticsearch'; import { LegacyConfig } from '../../../plugin'; interface VisSummary { diff --git a/x-pack/legacy/plugins/apm/typings/elasticsearch/aggregations.ts b/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts similarity index 91% rename from x-pack/legacy/plugins/apm/typings/elasticsearch/aggregations.ts rename to x-pack/plugins/apm/typings/elasticsearch/aggregations.ts index 6d3620f11a87b2..2ee8df7b5d1e1a 100644 --- a/x-pack/legacy/plugins/apm/typings/elasticsearch/aggregations.ts +++ b/x-pack/plugins/apm/typings/elasticsearch/aggregations.ts @@ -147,19 +147,13 @@ type BucketSubAggregationResponse< ? AggregationResponseMap : {}; -interface AggregationResponsePart< - TAggregationOptionsMap extends AggregationOptionsMap, - TDocument -> { +interface AggregationResponsePart { terms: { buckets: Array< { doc_count: number; key: string | number; - } & BucketSubAggregationResponse< - TAggregationOptionsMap['aggs'], - TDocument - > + } & BucketSubAggregationResponse >; }; histogram: { @@ -167,10 +161,7 @@ interface AggregationResponsePart< { doc_count: number; key: number; - } & BucketSubAggregationResponse< - TAggregationOptionsMap['aggs'], - TDocument - > + } & BucketSubAggregationResponse >; }; date_histogram: { @@ -179,10 +170,7 @@ interface AggregationResponsePart< doc_count: number; key: number; key_as_string: string; - } & BucketSubAggregationResponse< - TAggregationOptionsMap['aggs'], - TDocument - > + } & BucketSubAggregationResponse >; }; avg: MetricsAggregationResponsePart; @@ -227,10 +215,7 @@ interface AggregationResponsePart< } & AggregationResponseMap; filters: TAggregationOptionsMap extends { filters: { filters: any[] } } ? Array< - { doc_count: number } & AggregationResponseMap< - TAggregationOptionsMap['aggs'], - TDocument - > + { doc_count: number } & AggregationResponseMap > : TAggregationOptionsMap extends { filters: { @@ -264,10 +249,7 @@ interface AggregationResponsePart< { key: Record, number>; doc_count: number; - } & BucketSubAggregationResponse< - TAggregationOptionsMap['aggs'], - TDocument - > + } & BucketSubAggregationResponse >; }; diversified_sampler: { diff --git a/x-pack/legacy/plugins/apm/typings/elasticsearch/index.ts b/x-pack/plugins/apm/typings/elasticsearch/index.ts similarity index 84% rename from x-pack/legacy/plugins/apm/typings/elasticsearch/index.ts rename to x-pack/plugins/apm/typings/elasticsearch/index.ts index 064b684cf9aa6b..e1d4aaeb597e27 100644 --- a/x-pack/legacy/plugins/apm/typings/elasticsearch/index.ts +++ b/x-pack/plugins/apm/typings/elasticsearch/index.ts @@ -31,10 +31,7 @@ export type ESSearchResponse< > = Omit, 'aggregations' | 'hits'> & (TSearchRequest extends { body: { aggs: AggregationInputMap } } ? { - aggregations?: AggregationResponseMap< - TSearchRequest['body']['aggs'], - TDocument - >; + aggregations?: AggregationResponseMap; } : {}) & { hits: Omit['hits'], 'total'> & @@ -52,12 +49,6 @@ export type ESSearchResponse< export interface ESFilter { [key: string]: { - [key: string]: - | string - | string[] - | number - | boolean - | Record - | ESFilter[]; + [key: string]: string | string[] | number | boolean | Record | ESFilter[]; }; } diff --git a/x-pack/legacy/plugins/lens/common/api.ts b/x-pack/plugins/lens/common/api.ts similarity index 100% rename from x-pack/legacy/plugins/lens/common/api.ts rename to x-pack/plugins/lens/common/api.ts diff --git a/x-pack/legacy/plugins/lens/common/constants.ts b/x-pack/plugins/lens/common/constants.ts similarity index 100% rename from x-pack/legacy/plugins/lens/common/constants.ts rename to x-pack/plugins/lens/common/constants.ts diff --git a/x-pack/legacy/plugins/lens/common/index.ts b/x-pack/plugins/lens/common/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/common/index.ts rename to x-pack/plugins/lens/common/index.ts diff --git a/x-pack/legacy/plugins/lens/common/types.ts b/x-pack/plugins/lens/common/types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/common/types.ts rename to x-pack/plugins/lens/common/types.ts diff --git a/x-pack/plugins/lens/kibana.json b/x-pack/plugins/lens/kibana.json new file mode 100644 index 00000000000000..867a7454f0448b --- /dev/null +++ b/x-pack/plugins/lens/kibana.json @@ -0,0 +1,8 @@ +{ + "id": "lens", + "version": "8.0.0", + "kibanaVersion": "kibana", + "server": true, + "ui": false, + "optionalPlugins": ["usageCollection", "taskManager"] +} diff --git a/x-pack/legacy/plugins/lens/server/index.ts b/x-pack/plugins/lens/server/index.ts similarity index 55% rename from x-pack/legacy/plugins/lens/server/index.ts rename to x-pack/plugins/lens/server/index.ts index ae14d1c5a0052e..3b9e94986d2477 100644 --- a/x-pack/legacy/plugins/lens/server/index.ts +++ b/x-pack/plugins/lens/server/index.ts @@ -4,8 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { LensServer } from './plugin'; +import { PluginInitializerContext } from 'kibana/server'; +import { LensServerPlugin } from './plugin'; export * from './plugin'; -export const lensServerPlugin = () => new LensServer(); +export const plugin = (initializerContext: PluginInitializerContext) => + new LensServerPlugin(initializerContext); diff --git a/x-pack/plugins/lens/server/plugin.tsx b/x-pack/plugins/lens/server/plugin.tsx new file mode 100644 index 00000000000000..e805f9f7e0a926 --- /dev/null +++ b/x-pack/plugins/lens/server/plugin.tsx @@ -0,0 +1,62 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Plugin, CoreSetup, CoreStart, PluginInitializerContext, Logger } from 'src/core/server'; +import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; +import { Observable } from 'rxjs'; +import { TaskManagerSetupContract, TaskManagerStartContract } from '../../task_manager/server'; +import { setupRoutes } from './routes'; +import { + registerLensUsageCollector, + initializeLensTelemetry, + scheduleLensTelemetry, +} from './usage'; + +export interface PluginSetupContract { + usageCollection?: UsageCollectionSetup; + taskManager?: TaskManagerSetupContract; +} + +export interface PluginStartContract { + taskManager?: TaskManagerStartContract; +} + +export class LensServerPlugin implements Plugin<{}, {}, {}, {}> { + private readonly kibanaIndexConfig: Observable<{ kibana: { index: string } }>; + private readonly telemetryLogger: Logger; + + constructor(initializerContext: PluginInitializerContext) { + this.kibanaIndexConfig = initializerContext.config.legacy.globalConfig$; + this.telemetryLogger = initializerContext.logger.get('telemetry'); + } + setup(core: CoreSetup, plugins: PluginSetupContract) { + setupRoutes(core); + if (plugins.usageCollection && plugins.taskManager) { + registerLensUsageCollector( + plugins.usageCollection, + core + .getStartServices() + .then(([_, { taskManager }]) => taskManager as TaskManagerStartContract) + ); + initializeLensTelemetry( + this.telemetryLogger, + core, + this.kibanaIndexConfig, + plugins.taskManager + ); + } + return {}; + } + + start(core: CoreStart, plugins: PluginStartContract) { + if (plugins.taskManager) { + scheduleLensTelemetry(this.telemetryLogger, plugins.taskManager); + } + return {}; + } + + stop() {} +} diff --git a/x-pack/legacy/plugins/lens/server/routes/existing_fields.test.ts b/x-pack/plugins/lens/server/routes/existing_fields.test.ts similarity index 100% rename from x-pack/legacy/plugins/lens/server/routes/existing_fields.test.ts rename to x-pack/plugins/lens/server/routes/existing_fields.test.ts diff --git a/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts b/x-pack/plugins/lens/server/routes/existing_fields.ts similarity index 98% rename from x-pack/legacy/plugins/lens/server/routes/existing_fields.ts rename to x-pack/plugins/lens/server/routes/existing_fields.ts index 30ded3572cae70..a059e325859094 100644 --- a/x-pack/legacy/plugins/lens/server/routes/existing_fields.ts +++ b/x-pack/plugins/lens/server/routes/existing_fields.ts @@ -6,11 +6,10 @@ import Boom from 'boom'; import { schema } from '@kbn/config-schema'; -import _ from 'lodash'; import { IScopedClusterClient, SavedObject, RequestHandlerContext } from 'src/core/server'; import { CoreSetup } from 'src/core/server'; import { BASE_API_URL } from '../../common'; -import { IndexPatternsFetcher } from '../../../../../../src/plugins/data/server'; +import { IndexPatternsFetcher } from '../../../../../src/plugins/data/server'; /** * The number of docs to sample to determine field empty status. diff --git a/x-pack/legacy/plugins/lens/server/routes/field_stats.ts b/x-pack/plugins/lens/server/routes/field_stats.ts similarity index 100% rename from x-pack/legacy/plugins/lens/server/routes/field_stats.ts rename to x-pack/plugins/lens/server/routes/field_stats.ts diff --git a/x-pack/legacy/plugins/lens/server/routes/index.ts b/x-pack/plugins/lens/server/routes/index.ts similarity index 59% rename from x-pack/legacy/plugins/lens/server/routes/index.ts rename to x-pack/plugins/lens/server/routes/index.ts index 79690b40395d6b..8bc04a56e16d5e 100644 --- a/x-pack/legacy/plugins/lens/server/routes/index.ts +++ b/x-pack/plugins/lens/server/routes/index.ts @@ -4,20 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { KibanaConfig } from 'src/legacy/server/kbn_server'; -import { CoreSetup, SavedObjectsLegacyService } from 'src/core/server'; +import { CoreSetup } from 'src/core/server'; import { existingFieldsRoute } from './existing_fields'; import { initFieldsRoute } from './field_stats'; import { initLensUsageRoute } from './telemetry'; -export function setupRoutes( - setup: CoreSetup, - plugins: { - savedObjects: SavedObjectsLegacyService; - config: KibanaConfig; - } -) { +export function setupRoutes(setup: CoreSetup) { existingFieldsRoute(setup); initFieldsRoute(setup); - initLensUsageRoute(setup, plugins); + initLensUsageRoute(setup); } diff --git a/x-pack/legacy/plugins/lens/server/routes/telemetry.ts b/x-pack/plugins/lens/server/routes/telemetry.ts similarity index 75% rename from x-pack/legacy/plugins/lens/server/routes/telemetry.ts rename to x-pack/plugins/lens/server/routes/telemetry.ts index 895b77cfa89788..7925416ff5df29 100644 --- a/x-pack/legacy/plugins/lens/server/routes/telemetry.ts +++ b/x-pack/plugins/lens/server/routes/telemetry.ts @@ -5,29 +5,13 @@ */ import Boom from 'boom'; -import { KibanaConfig } from 'src/legacy/server/kbn_server'; -import { CoreSetup, SavedObjectsLegacyService } from 'src/core/server'; +import { CoreSetup } from 'src/core/server'; import { schema } from '@kbn/config-schema'; import { BASE_API_URL } from '../../common'; -export function getSavedObjectsClient( - savedObjects: SavedObjectsLegacyService, - callAsInternalUser: unknown -) { - const { SavedObjectsClient, getSavedObjectsRepository } = savedObjects; - const internalRepository = getSavedObjectsRepository(callAsInternalUser); - return new SavedObjectsClient(internalRepository); -} - // This route is responsible for taking a batch of click events from the browser // and writing them to saved objects -export async function initLensUsageRoute( - setup: CoreSetup, - plugins: { - savedObjects: SavedObjectsLegacyService; - config: KibanaConfig; - } -) { +export async function initLensUsageRoute(setup: CoreSetup) { const router = setup.http.createRouter(); router.post( { @@ -43,12 +27,10 @@ export async function initLensUsageRoute( }, }, async (context, req, res) => { - const { dataClient } = context.core.elasticsearch; - const { events, suggestionEvents } = req.body; try { - const client = getSavedObjectsClient(plugins.savedObjects, dataClient.callAsCurrentUser); + const client = context.core.savedObjects.client; const allEvents: Array<{ type: 'lens-ui-telemetry'; diff --git a/x-pack/legacy/plugins/lens/server/usage/collectors.ts b/x-pack/plugins/lens/server/usage/collectors.ts similarity index 97% rename from x-pack/legacy/plugins/lens/server/usage/collectors.ts rename to x-pack/plugins/lens/server/usage/collectors.ts index 666b3718d5125d..52de0df6fed132 100644 --- a/x-pack/legacy/plugins/lens/server/usage/collectors.ts +++ b/x-pack/plugins/lens/server/usage/collectors.ts @@ -7,7 +7,7 @@ import moment from 'moment'; import { get } from 'lodash'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; -import { TaskManagerStartContract } from '../../../../../plugins/task_manager/server'; +import { TaskManagerStartContract } from '../../../task_manager/server'; import { LensUsage, LensTelemetryState } from './types'; diff --git a/x-pack/legacy/plugins/lens/server/usage/index.ts b/x-pack/plugins/lens/server/usage/index.ts similarity index 100% rename from x-pack/legacy/plugins/lens/server/usage/index.ts rename to x-pack/plugins/lens/server/usage/index.ts diff --git a/x-pack/legacy/plugins/lens/server/usage/task.ts b/x-pack/plugins/lens/server/usage/task.ts similarity index 62% rename from x-pack/legacy/plugins/lens/server/usage/task.ts rename to x-pack/plugins/lens/server/usage/task.ts index 26b44832feaa68..e2462be1497450 100644 --- a/x-pack/legacy/plugins/lens/server/usage/task.ts +++ b/x-pack/plugins/lens/server/usage/task.ts @@ -4,24 +4,17 @@ * you may not use this file except in compliance with the Elastic License. */ +import { APICaller, CoreSetup, Logger } from 'kibana/server'; +import { Observable } from 'rxjs'; import moment from 'moment'; -import KbnServer, { Server } from 'src/legacy/server/kbn_server'; -import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch'; -import { - SearchParams, - DeleteDocumentByQueryParams, - SearchResponse, - DeleteDocumentByQueryResponse, -} from 'elasticsearch'; -import { ESSearchResponse } from '../../../apm/typings/elasticsearch'; -import { XPackMainPlugin } from '../../../xpack_main/server/xpack_main'; import { RunContext, TaskManagerSetupContract, TaskManagerStartContract, -} from '../../../../../plugins/task_manager/server'; +} from '../../../task_manager/server'; import { getVisualizationCounts } from './visualization_counts'; +import { ESSearchResponse } from '../../../apm/typings/elasticsearch'; // This task is responsible for running daily and aggregating all the Lens click event objects // into daily rolled-up documents, which will be used in reporting click stats @@ -30,74 +23,53 @@ const TELEMETRY_TASK_TYPE = 'lens_telemetry'; export const TASK_ID = `Lens-${TELEMETRY_TASK_TYPE}`; -type ClusterSearchType = ( - endpoint: 'search', - params: SearchParams & { - rest_total_hits_as_int: boolean; - }, - options?: CallClusterOptions -) => Promise>; -type ClusterDeleteType = ( - endpoint: 'deleteByQuery', - params: DeleteDocumentByQueryParams, - options?: CallClusterOptions -) => Promise; - -export function initializeLensTelemetry(server: Server, taskManager?: TaskManagerSetupContract) { - if (!taskManager) { - server.log(['debug', 'telemetry'], `Task manager is not available`); - } else { - registerLensTelemetryTask(server, taskManager); - } +export function initializeLensTelemetry( + logger: Logger, + core: CoreSetup, + config: Observable<{ kibana: { index: string } }>, + taskManager: TaskManagerSetupContract +) { + registerLensTelemetryTask(logger, core, config, taskManager); } -export function scheduleLensTelemetry(server: Server, taskManager?: TaskManagerStartContract) { +export function scheduleLensTelemetry(logger: Logger, taskManager?: TaskManagerStartContract) { if (taskManager) { - scheduleTasks(server, taskManager); + scheduleTasks(logger, taskManager); } } -function registerLensTelemetryTask(server: Server, taskManager: TaskManagerSetupContract) { +function registerLensTelemetryTask( + logger: Logger, + core: CoreSetup, + config: Observable<{ kibana: { index: string } }>, + taskManager: TaskManagerSetupContract +) { taskManager.registerTaskDefinitions({ [TELEMETRY_TASK_TYPE]: { title: 'Lens telemetry fetch task', type: TELEMETRY_TASK_TYPE, timeout: '1m', - createTaskRunner: telemetryTaskRunner(server), + createTaskRunner: telemetryTaskRunner(logger, core, config), }, }); } -function scheduleTasks(server: Server, taskManager: TaskManagerStartContract) { - const { kbnServer } = (server.plugins.xpack_main as XPackMainPlugin & { - status: { plugin: { kbnServer: KbnServer } }; - }).status.plugin; - - kbnServer.afterPluginsInit(() => { - // The code block below can't await directly within "afterPluginsInit" - // callback due to circular dependency The server isn't "ready" until - // this code block finishes. Migrations wait for server to be ready before - // executing. Saved objects repository waits for migrations to finish before - // finishing the request. To avoid this, we'll await within a separate - // function block. - (async () => { - try { - await taskManager.ensureScheduled({ - id: TASK_ID, - taskType: TELEMETRY_TASK_TYPE, - state: { byDate: {}, suggestionsByDate: {}, saved: {}, runs: 0 }, - params: {}, - }); - } catch (e) { - server.log(['debug', 'telemetry'], `Error scheduling task, received ${e.message}`); - } - })(); - }); +async function scheduleTasks(logger: Logger, taskManager: TaskManagerStartContract) { + try { + await taskManager.ensureScheduled({ + id: TASK_ID, + taskType: TELEMETRY_TASK_TYPE, + state: { byDate: {}, suggestionsByDate: {}, saved: {}, runs: 0 }, + params: {}, + }); + } catch (e) { + logger.debug(`Error scheduling task, received ${e.message}`); + } } export async function getDailyEvents( kibanaIndex: string, - callCluster: ClusterSearchType & ClusterDeleteType + callCluster: APICaller ): Promise<{ byDate: Record>; suggestionsByDate: Record>; @@ -205,18 +177,22 @@ export async function getDailyEvents( }; } -export function telemetryTaskRunner(server: Server) { +export function telemetryTaskRunner( + logger: Logger, + core: CoreSetup, + config: Observable<{ kibana: { index: string } }> +) { return ({ taskInstance }: RunContext) => { const { state } = taskInstance; - const callCluster = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser; + const callCluster = core.elasticsearch.adminClient.callAsInternalUser; return { async run() { - const kibanaIndex = server.config().get('kibana.index'); + const kibanaIndex = (await config.toPromise()).kibana.index; return Promise.all([ getDailyEvents(kibanaIndex, callCluster), - getVisualizationCounts(callCluster, server.config()), + getVisualizationCounts(callCluster, kibanaIndex), ]) .then(([lensTelemetry, lensVisualizations]) => { return { @@ -229,9 +205,7 @@ export function telemetryTaskRunner(server: Server) { runAt: getNextMidnight(), }; }) - .catch(errMsg => - server.log(['warning'], `Error executing lens telemetry task: ${errMsg}`) - ); + .catch(errMsg => logger.warn(`Error executing lens telemetry task: ${errMsg}`)); }, }; }; diff --git a/x-pack/legacy/plugins/lens/server/usage/types.ts b/x-pack/plugins/lens/server/usage/types.ts similarity index 100% rename from x-pack/legacy/plugins/lens/server/usage/types.ts rename to x-pack/plugins/lens/server/usage/types.ts diff --git a/x-pack/legacy/plugins/lens/server/usage/visualization_counts.ts b/x-pack/plugins/lens/server/usage/visualization_counts.ts similarity index 85% rename from x-pack/legacy/plugins/lens/server/usage/visualization_counts.ts rename to x-pack/plugins/lens/server/usage/visualization_counts.ts index 7c1dc5fca6d856..00b84fe100224e 100644 --- a/x-pack/legacy/plugins/lens/server/usage/visualization_counts.ts +++ b/x-pack/plugins/lens/server/usage/visualization_counts.ts @@ -4,22 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { KibanaConfig } from 'src/legacy/server/kbn_server'; -import { CallClusterOptions } from 'src/legacy/core_plugins/elasticsearch'; -import { SearchParams, SearchResponse } from 'elasticsearch'; +import { APICaller } from 'kibana/server'; import { LensVisualizationUsage } from './types'; -type ClusterSearchType = ( - endpoint: 'search', - params: SearchParams & { - rest_total_hits_as_int: boolean; - }, - options?: CallClusterOptions -) => Promise>; - export async function getVisualizationCounts( - callCluster: ClusterSearchType, - config: KibanaConfig + callCluster: APICaller, + kibanaIndex: string ): Promise { const scriptedMetric = { scripted_metric: { @@ -53,7 +43,7 @@ export async function getVisualizationCounts( }; const results = await callCluster('search', { - index: config.get('kibana.index'), + index: kibanaIndex, rest_total_hits_as_int: true, body: { query: { diff --git a/x-pack/test/api_integration/apis/lens/telemetry.ts b/x-pack/test/api_integration/apis/lens/telemetry.ts index 5e6830c8f4689b..653df453c25602 100644 --- a/x-pack/test/api_integration/apis/lens/telemetry.ts +++ b/x-pack/test/api_integration/apis/lens/telemetry.ts @@ -6,14 +6,13 @@ import moment from 'moment'; import expect from '@kbn/expect'; -import { KibanaConfig } from 'src/legacy/server/kbn_server'; import { Client, SearchParams } from 'elasticsearch'; +import { APICaller } from 'kibana/server'; -import { CallCluster } from 'src/legacy/core_plugins/elasticsearch'; import { FtrProviderContext } from '../../ftr_provider_context'; -import { getDailyEvents } from '../../../../legacy/plugins/lens/server/usage/task'; -import { getVisualizationCounts } from '../../../../legacy/plugins/lens/server/usage/visualization_counts'; +import { getDailyEvents } from '../../../../plugins/lens/server/usage/task'; +import { getVisualizationCounts } from '../../../../plugins/lens/server/usage/visualization_counts'; const COMMON_HEADERS = { 'kbn-xsrf': 'some-xsrf-token', @@ -23,9 +22,9 @@ const COMMON_HEADERS = { export default ({ getService }: FtrProviderContext) => { const supertest = getService('supertest'); const es: Client = getService('legacyEs'); - const callCluster: CallCluster = (((path: 'search', searchParams: SearchParams) => { + const callCluster: APICaller = (((path: 'search', searchParams: SearchParams) => { return es[path].call(es, searchParams); - }) as unknown) as CallCluster; + }) as unknown) as APICaller; async function assertExpectedSavedObjects(num: number) { // Make sure that new/deleted docs are available to search @@ -189,13 +188,7 @@ export default ({ getService }: FtrProviderContext) => { await esArchiver.loadIfNeeded('lens/basic'); - const results = await getVisualizationCounts(callCluster, { - // Fake KibanaConfig service - get() { - return '.kibana'; - }, - has: () => false, - } as KibanaConfig); + const results = await getVisualizationCounts(callCluster, '.kibana'); expect(results).to.have.keys([ 'saved_overall',