diff --git a/x-pack/plugins/apm/common/processor_event.ts b/x-pack/plugins/apm/common/processor_event.ts index 57705e7ed4ce0a..a7b0a303b55ae7 100644 --- a/x-pack/plugins/apm/common/processor_event.ts +++ b/x-pack/plugins/apm/common/processor_event.ts @@ -16,7 +16,7 @@ export enum ProcessorEvent { * Processor events that are searchable in the UI via the query bar. * * Some client-sideroutes will define 1 or more processor events that - * will be used to fetch the dynamic index pattern for the query bar. + * will be used to fetch the dynamic data view for the query bar. */ export type UIProcessorEvent = diff --git a/x-pack/plugins/apm/e2e/ci/kibana.e2e.yml b/x-pack/plugins/apm/e2e/ci/kibana.e2e.yml index 19f3f7c8978fa7..5b665a4f9c6b11 100644 --- a/x-pack/plugins/apm/e2e/ci/kibana.e2e.yml +++ b/x-pack/plugins/apm/e2e/ci/kibana.e2e.yml @@ -11,7 +11,7 @@ elasticsearch.hosts: http://localhost:9201 elasticsearch.username: 'kibana_system_user' elasticsearch.password: 'changeme' -# APM index pattern +# APM data view apm_oss.indexPattern: apm-* # APM Indices diff --git a/x-pack/plugins/apm/public/application/application.test.tsx b/x-pack/plugins/apm/public/application/application.test.tsx index 144da47828bf76..54d4388ec3833e 100644 --- a/x-pack/plugins/apm/public/application/application.test.tsx +++ b/x-pack/plugins/apm/public/application/application.test.tsx @@ -18,8 +18,8 @@ import { dataPluginMock } from 'src/plugins/data/public/mocks'; import { embeddablePluginMock } from 'src/plugins/embeddable/public/mocks'; import { ApmPluginStartDeps } from '../plugin'; -jest.mock('../services/rest/index_pattern', () => ({ - createStaticIndexPattern: () => Promise.resolve(undefined), +jest.mock('../services/rest/data_view', () => ({ + createStaticDataView: () => Promise.resolve(undefined), })); describe('renderApp', () => { diff --git a/x-pack/plugins/apm/public/application/index.tsx b/x-pack/plugins/apm/public/application/index.tsx index feb1ff372dc96a..d32fb72bbe3087 100644 --- a/x-pack/plugins/apm/public/application/index.tsx +++ b/x-pack/plugins/apm/public/application/index.tsx @@ -17,7 +17,7 @@ import { } from '../../../../../src/core/public'; import { ApmPluginSetupDeps, ApmPluginStartDeps } from '../plugin'; import { createCallApmApi } from '../services/rest/createCallApmApi'; -import { createStaticIndexPattern } from '../services/rest/index_pattern'; +import { createStaticDataView } from '../services/rest/data_view'; import { setHelpExtension } from '../setHelpExtension'; import { setReadonlyBadge } from '../updateBadge'; import { ApmAppRoot } from '../components/routing/app_root'; @@ -58,10 +58,10 @@ export const renderApp = ({ setReadonlyBadge(coreStart); createCallApmApi(coreStart); - // Automatically creates static index pattern and stores as saved object - createStaticIndexPattern().catch((e) => { + // Automatically creates static data view and stores as saved object + createStaticDataView().catch((e) => { // eslint-disable-next-line no-console - console.log('Error creating static index pattern', e); + console.log('Error creating static data view', e); }); // add .kbnAppWrappers class to root element diff --git a/x-pack/plugins/apm/public/application/uxApp.tsx b/x-pack/plugins/apm/public/application/uxApp.tsx index ddcccf45ccab5e..fd9c11b9a1a01b 100644 --- a/x-pack/plugins/apm/public/application/uxApp.tsx +++ b/x-pack/plugins/apm/public/application/uxApp.tsx @@ -28,7 +28,7 @@ import { UrlParamsProvider } from '../context/url_params_context/url_params_cont import { ConfigSchema } from '../index'; import { ApmPluginSetupDeps, ApmPluginStartDeps } from '../plugin'; import { createCallApmApi } from '../services/rest/createCallApmApi'; -import { createStaticIndexPattern } from '../services/rest/index_pattern'; +import { createStaticDataView } from '../services/rest/data_view'; import { UXActionMenu } from '../components/app/RumDashboard/ActionMenu'; import { redirectTo } from '../components/routing/redirect_to'; import { useBreadcrumbs } from '../../../observability/public'; @@ -160,10 +160,10 @@ export const renderApp = ({ createCallApmApi(core); - // Automatically creates static index pattern and stores as saved object - createStaticIndexPattern().catch((e) => { + // Automatically creates static data view and stores as saved object + createStaticDataView().catch((e) => { // eslint-disable-next-line no-console - console.log('Error creating static index pattern', e); + console.log('Error creating static data view', e); }); ReactDOM.render( diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/index.tsx b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/index.tsx index d6897599f52881..655bf93e4fb934 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/index.tsx +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/index.tsx @@ -31,7 +31,7 @@ import { TRANSACTION_TYPE, } from '../../../../../common/elasticsearch_fieldnames'; import { TRANSACTION_PAGE_LOAD } from '../../../../../common/transaction_types'; -import { useIndexPattern } from './use_index_pattern'; +import { useDataView } from './use_data_view'; import { environmentQuery } from './queries'; import { ENVIRONMENT_ALL } from '../../../../../common/environment_filter_values'; import { useUxUrlParams } from '../../../../context/url_params_context/use_ux_url_params'; @@ -52,7 +52,7 @@ const RUM_DATA_FILTERS = [ ]; function LocalUIFilters() { - const { indexPatternTitle, indexPattern } = useIndexPattern(); + const { dataViewTitle, dataView } = useDataView(); const { filters = [], @@ -108,7 +108,7 @@ function LocalUIFilters() { ); diff --git a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_index_pattern.ts b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts similarity index 50% rename from x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_index_pattern.ts rename to x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts index 8c421aebd17f17..ba997292933683 100644 --- a/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_index_pattern.ts +++ b/x-pack/plugins/apm/public/components/app/RumDashboard/LocalUIFilters/use_data_view.ts @@ -5,31 +5,31 @@ * 2.0. */ -import { useDynamicIndexPatternFetcher } from '../../../../hooks/use_dynamic_index_pattern'; +import { useDynamicDataViewFetcher } from '../../../../hooks/use_dynamic_data_view'; import { - IndexPattern, - IndexPatternSpec, + DataView, + DataViewSpec, } from '../../../../../../../../src/plugins/data/common'; import { useKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { useFetcher } from '../../../../hooks/use_fetcher'; import { DataPublicPluginStart } from '../../../../../../../../src/plugins/data/public'; -export function useIndexPattern() { - const { indexPattern: indexPatternDynamic } = useDynamicIndexPatternFetcher(); +export function useDataView() { + const { dataView } = useDynamicDataViewFetcher(); const { services: { - data: { indexPatterns }, + data: { dataViews }, }, } = useKibana<{ data: DataPublicPluginStart }>(); - const { data } = useFetcher>(async () => { - if (indexPatternDynamic?.title) { - return indexPatterns.create({ - pattern: indexPatternDynamic?.title, - } as IndexPatternSpec); + const { data } = useFetcher>(async () => { + if (dataView?.title) { + return dataViews.create({ + pattern: dataView?.title, + } as DataViewSpec); } - }, [indexPatternDynamic?.title, indexPatterns]); + }, [dataView?.title, dataViews]); - return { indexPatternTitle: indexPatternDynamic?.title, indexPattern: data }; + return { dataViewTitle: dataView?.title, dataView: data }; } diff --git a/x-pack/plugins/apm/public/components/app/Settings/ApmIndices/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/ApmIndices/index.tsx index 2d74187f9d83b9..7780bb9e7fbe82 100644 --- a/x-pack/plugins/apm/public/components/app/Settings/ApmIndices/index.tsx +++ b/x-pack/plugins/apm/public/components/app/Settings/ApmIndices/index.tsx @@ -177,7 +177,7 @@ export function ApmIndices() { <> {i18n.translate('xpack.apm.settings.apmIndices.description', { - defaultMessage: `The APM UI uses index patterns to query your APM indices. If you've customized the index names that APM Server writes events to, you may need to update these patterns for the APM UI to work. Settings here take precedence over those set in kibana.yml.`, + defaultMessage: `The APM UI uses data views to query your APM indices. If you've customized the index names that APM Server writes events to, you may need to update these patterns for the APM UI to work. Settings here take precedence over those set in kibana.yml.`, })} diff --git a/x-pack/plugins/apm/public/components/app/correlations/use_field_names.ts b/x-pack/plugins/apm/public/components/app/correlations/use_field_names.ts index ff88808c51d15a..eb8097fa647474 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/use_field_names.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/use_field_names.ts @@ -9,44 +9,44 @@ import { memoize } from 'lodash'; import { useEffect, useMemo, useState } from 'react'; import { isRumAgentName } from '../../../../common/agent_name'; import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context'; -import { useDynamicIndexPatternFetcher } from '../../../hooks/use_dynamic_index_pattern'; +import { useDynamicDataViewFetcher } from '../../../hooks/use_dynamic_data_view'; -interface IndexPattern { +interface DataView { fields: Array<{ name: string; esTypes: string[] }>; } export function useFieldNames() { const { agentName } = useApmServiceContext(); const isRumAgent = isRumAgentName(agentName); - const { indexPattern } = useDynamicIndexPatternFetcher(); + const { dataView } = useDynamicDataViewFetcher(); const [defaultFieldNames, setDefaultFieldNames] = useState( - getDefaultFieldNames(indexPattern, isRumAgent) + getDefaultFieldNames(dataView, isRumAgent) ); const getSuggestions = useMemo( () => memoize((searchValue: string) => - getMatchingFieldNames(indexPattern, searchValue) + getMatchingFieldNames(dataView, searchValue) ), - [indexPattern] + [dataView] ); useEffect(() => { - setDefaultFieldNames(getDefaultFieldNames(indexPattern, isRumAgent)); - }, [indexPattern, isRumAgent]); + setDefaultFieldNames(getDefaultFieldNames(dataView, isRumAgent)); + }, [dataView, isRumAgent]); return { defaultFieldNames, getSuggestions }; } function getMatchingFieldNames( - indexPattern: IndexPattern | undefined, + dataView: DataView | undefined, inputValue: string ) { - if (!indexPattern) { + if (!dataView) { return []; } - return indexPattern.fields + return dataView.fields .filter( ({ name, esTypes }) => name.startsWith(inputValue) && esTypes[0] === 'keyword' // only show fields of type 'keyword' @@ -55,20 +55,17 @@ function getMatchingFieldNames( } function getDefaultFieldNames( - indexPattern: IndexPattern | undefined, + dataView: DataView | undefined, isRumAgent: boolean ) { - const labelFields = getMatchingFieldNames(indexPattern, 'labels.').slice( - 0, - 6 - ); + const labelFields = getMatchingFieldNames(dataView, 'labels.').slice(0, 6); return isRumAgent ? [ ...labelFields, 'user_agent.name', 'user_agent.os.name', 'url.original', - ...getMatchingFieldNames(indexPattern, 'user.').slice(0, 6), + ...getMatchingFieldNames(dataView, 'user.').slice(0, 6), ] : [...labelFields, 'service.version', 'service.node.name', 'host.ip']; } diff --git a/x-pack/plugins/apm/public/components/app/service_inventory/service_inventory.test.tsx b/x-pack/plugins/apm/public/components/app/service_inventory/service_inventory.test.tsx index 2ff3f2702cb533..cee12fc0028de5 100644 --- a/x-pack/plugins/apm/public/components/app/service_inventory/service_inventory.test.tsx +++ b/x-pack/plugins/apm/public/components/app/service_inventory/service_inventory.test.tsx @@ -21,7 +21,7 @@ import { } from '../../../context/apm_plugin/mock_apm_plugin_context'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; import { clearCache } from '../../../services/rest/callApi'; -import * as useDynamicIndexPatternHooks from '../../../hooks/use_dynamic_index_pattern'; +import * as useDynamicDataViewHooks from '../../../hooks/use_dynamic_data_view'; import { SessionStorageMock } from '../../../services/__mocks__/SessionStorageMock'; import { MockUrlParamsContextProvider } from '../../../context/url_params_context/mock_url_params_context_provider'; import * as hook from '../../../context/anomaly_detection_jobs/use_anomaly_detection_jobs_context'; @@ -85,9 +85,9 @@ describe('ServiceInventory', () => { }); jest - .spyOn(useDynamicIndexPatternHooks, 'useDynamicIndexPatternFetcher') + .spyOn(useDynamicDataViewHooks, 'useDynamicDataViewFetcher') .mockReturnValue({ - indexPattern: undefined, + dataView: undefined, status: FETCH_STATUS.SUCCESS, }); }); diff --git a/x-pack/plugins/apm/public/components/app/service_overview/service_overview.test.tsx b/x-pack/plugins/apm/public/components/app/service_overview/service_overview.test.tsx index b3c1afb32b0fdd..c26f2296e97415 100644 --- a/x-pack/plugins/apm/public/components/app/service_overview/service_overview.test.tsx +++ b/x-pack/plugins/apm/public/components/app/service_overview/service_overview.test.tsx @@ -15,7 +15,7 @@ import { mockApmPluginContextValue, MockApmPluginContextWrapper, } from '../../../context/apm_plugin/mock_apm_plugin_context'; -import * as useDynamicIndexPatternHooks from '../../../hooks/use_dynamic_index_pattern'; +import * as useDynamicDataViewHooks from '../../../hooks/use_dynamic_data_view'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; import * as useAnnotationsHooks from '../../../context/annotations/use_annotations_context'; import * as useTransactionBreakdownHooks from '../../shared/charts/transaction_breakdown_chart/use_transaction_breakdown'; @@ -91,9 +91,9 @@ describe('ServiceOverview', () => { .spyOn(useAnnotationsHooks, 'useAnnotationsContext') .mockReturnValue({ annotations: [] }); jest - .spyOn(useDynamicIndexPatternHooks, 'useDynamicIndexPatternFetcher') + .spyOn(useDynamicDataViewHooks, 'useDynamicDataViewFetcher') .mockReturnValue({ - indexPattern: undefined, + dataView: undefined, status: FETCH_STATUS.SUCCESS, }); diff --git a/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx b/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx index c0417f4a8bbdab..b3a972bcd59e32 100644 --- a/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx @@ -10,15 +10,15 @@ import { i18n } from '@kbn/i18n'; import { uniqueId } from 'lodash'; import React, { useState } from 'react'; import { useHistory, useLocation } from 'react-router-dom'; +import { DataView } from '../../../../../../../src/plugins/data/common'; import { esKuery, - IndexPattern, QuerySuggestion, } from '../../../../../../../src/plugins/data/public'; import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context'; import { useUrlParams } from '../../../context/url_params_context/use_url_params'; import { useApmParams } from '../../../hooks/use_apm_params'; -import { useDynamicIndexPatternFetcher } from '../../../hooks/use_dynamic_index_pattern'; +import { useDynamicDataViewFetcher } from '../../../hooks/use_dynamic_data_view'; import { fromQuery, toQuery } from '../Links/url_helpers'; import { getBoolFilter } from './get_bool_filter'; // @ts-expect-error @@ -30,9 +30,9 @@ interface State { isLoadingSuggestions: boolean; } -function convertKueryToEsQuery(kuery: string, indexPattern: IndexPattern) { +function convertKueryToEsQuery(kuery: string, dataView: DataView) { const ast = esKuery.fromKueryExpression(kuery); - return esKuery.toElasticsearchQuery(ast, indexPattern); + return esKuery.toElasticsearchQuery(ast, dataView); } export function KueryBar(props: { @@ -70,7 +70,7 @@ export function KueryBar(props: { const example = examples[processorEvent || 'defaults']; - const { indexPattern } = useDynamicIndexPatternFetcher(); + const { dataView } = useDynamicDataViewFetcher(); const placeholder = props.placeholder ?? @@ -88,7 +88,7 @@ export function KueryBar(props: { }); async function onChange(inputValue: string, selectionStart: number) { - if (indexPattern == null) { + if (dataView == null) { return; } @@ -101,7 +101,7 @@ export function KueryBar(props: { const suggestions = ( (await data.autocomplete.getQuerySuggestions({ language: 'kuery', - indexPatterns: [indexPattern], + indexPatterns: [dataView], boolFilter: props.boolFilter ?? getBoolFilter({ @@ -130,15 +130,12 @@ export function KueryBar(props: { } function onSubmit(inputValue: string) { - if (indexPattern == null) { + if (dataView == null) { return; } try { - const res = convertKueryToEsQuery( - inputValue, - indexPattern as IndexPattern - ); + const res = convertKueryToEsQuery(inputValue, dataView as DataView); if (!res) { return; } diff --git a/x-pack/plugins/apm/public/hooks/use_dynamic_index_pattern.ts b/x-pack/plugins/apm/public/hooks/use_dynamic_data_view.ts similarity index 75% rename from x-pack/plugins/apm/public/hooks/use_dynamic_index_pattern.ts rename to x-pack/plugins/apm/public/hooks/use_dynamic_data_view.ts index 9c637dc1336add..f6bea37b4ce9a4 100644 --- a/x-pack/plugins/apm/public/hooks/use_dynamic_index_pattern.ts +++ b/x-pack/plugins/apm/public/hooks/use_dynamic_data_view.ts @@ -7,16 +7,16 @@ import { useFetcher } from './use_fetcher'; -export function useDynamicIndexPatternFetcher() { +export function useDynamicDataViewFetcher() { const { data, status } = useFetcher((callApmApi) => { return callApmApi({ - endpoint: 'GET /api/apm/index_pattern/dynamic', + endpoint: 'GET /api/apm/data_view/dynamic', isCachable: true, }); }, []); return { - indexPattern: data?.dynamicIndexPattern, + dataView: data?.dynamicDataView, status, }; } diff --git a/x-pack/plugins/apm/public/services/rest/index_pattern.ts b/x-pack/plugins/apm/public/services/rest/data_view.ts similarity index 77% rename from x-pack/plugins/apm/public/services/rest/index_pattern.ts rename to x-pack/plugins/apm/public/services/rest/data_view.ts index 0bb5839759f64e..75ef67a32b2b77 100644 --- a/x-pack/plugins/apm/public/services/rest/index_pattern.ts +++ b/x-pack/plugins/apm/public/services/rest/data_view.ts @@ -7,9 +7,9 @@ import { callApmApi } from './createCallApmApi'; -export const createStaticIndexPattern = async () => { +export const createStaticDataView = async () => { return await callApmApi({ - endpoint: 'POST /api/apm/index_pattern/static', + endpoint: 'POST /api/apm/data_view/static', signal: null, }); }; diff --git a/x-pack/plugins/apm/public/utils/testHelpers.tsx b/x-pack/plugins/apm/public/utils/testHelpers.tsx index 465155dbf166bc..080e56be48caf1 100644 --- a/x-pack/plugins/apm/public/utils/testHelpers.tsx +++ b/x-pack/plugins/apm/public/utils/testHelpers.tsx @@ -193,7 +193,6 @@ export async function inspectSearchParams( apmAgentConfigurationIndex: 'myIndex', apmCustomLinkIndex: 'myIndex', }, - dynamicIndexPattern: null as any, }; try { response = await fn(mockSetup); diff --git a/x-pack/plugins/apm/scripts/aggregate-latency-metrics/index.ts b/x-pack/plugins/apm/scripts/aggregate-latency-metrics/index.ts index c2d989c1dbf215..3d0f0bd3c3c724 100644 --- a/x-pack/plugins/apm/scripts/aggregate-latency-metrics/index.ts +++ b/x-pack/plugins/apm/scripts/aggregate-latency-metrics/index.ts @@ -40,7 +40,7 @@ import { ESClient, getEsClient } from '../shared/get_es_client'; // - from: start of the date range that should be processed. Should be a valid ISO timestamp. // - to: end of the date range that should be processed. Should be a valid ISO timestamp. // - source: from which transaction documents should be read. Should be location of ES (basic auth -// is supported) plus the index name (or an index pattern). Example: +// is supported) plus the index name (or an data view). Example: // https://foo:bar@apm.elstc.co:9999/apm-8.0.0-transaction // - dest: to which metric documents should be written. If this is not set, no metric documents // will be created.Should be location of ES (basic auth is supported) plus the index name. diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts index 1ea9ae6b65ac53..c8a637b3cb5021 100644 --- a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts +++ b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts @@ -50,10 +50,10 @@ export async function createAnomalyDetectionJobs( `Creating ML anomaly detection jobs for environments: [${uniqueMlJobEnvs}].` ); - const indexPatternName = indices['apm_oss.transactionIndices']; + const dataViewName = indices['apm_oss.transactionIndices']; const responses = await Promise.all( uniqueMlJobEnvs.map((environment) => - createAnomalyDetectionJob({ ml, environment, indexPatternName }) + createAnomalyDetectionJob({ ml, environment, dataViewName }) ) ); const jobResponses = responses.flatMap((response) => response.jobs); @@ -73,11 +73,11 @@ export async function createAnomalyDetectionJobs( async function createAnomalyDetectionJob({ ml, environment, - indexPatternName, + dataViewName, }: { ml: Required['ml']; environment: string; - indexPatternName: string; + dataViewName: string; }) { return withApmSpan('create_anomaly_detection_job', async () => { const randomToken = uuid().substr(-4); @@ -86,7 +86,7 @@ async function createAnomalyDetectionJob({ moduleId: ML_MODULE_ID_APM_TRANSACTION, prefix: `${APM_ML_JOB_GROUP}-${snakeCase(environment)}-${randomToken}-`, groups: [APM_ML_JOB_GROUP], - indexPatternName, + indexPatternName: dataViewName, applyToAllSpaces: true, start: moment().subtract(4, 'weeks').valueOf(), query: { diff --git a/x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.test.ts b/x-pack/plugins/apm/server/lib/data_view/create_static_data_view.test.ts similarity index 78% rename from x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.test.ts rename to x-pack/plugins/apm/server/lib/data_view/create_static_data_view.test.ts index 46596d8ac864ac..93cb45db2db959 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.test.ts +++ b/x-pack/plugins/apm/server/lib/data_view/create_static_data_view.test.ts @@ -6,17 +6,17 @@ */ /* eslint-disable @typescript-eslint/naming-convention */ -import { createStaticIndexPattern } from './create_static_index_pattern'; +import { createStaticDataView } from './create_static_data_view'; import { Setup } from '../helpers/setup_request'; import * as HistoricalAgentData from '../../routes/historical_data/has_historical_agent_data'; import { InternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client'; import { APMConfig } from '../..'; -function getMockSavedObjectsClient(existingIndexPatternTitle: string) { +function getMockSavedObjectsClient(existingDataViewTitle: string) { return ({ get: jest.fn(() => ({ attributes: { - title: existingIndexPatternTitle, + title: existingDataViewTitle, }, })), create: jest.fn(), @@ -32,10 +32,10 @@ const setup = ({ }, } as unknown) as Setup; -describe('createStaticIndexPattern', () => { - it(`should not create index pattern if 'xpack.apm.autocreateApmIndexPattern=false'`, async () => { +describe('createStaticDataView', () => { + it(`should not create data view if 'xpack.apm.autocreateApmIndexPattern=false'`, async () => { const savedObjectsClient = getMockSavedObjectsClient('apm-*'); - await createStaticIndexPattern({ + await createStaticDataView({ setup, config: { 'xpack.apm.autocreateApmIndexPattern': false } as APMConfig, savedObjectsClient, @@ -44,7 +44,7 @@ describe('createStaticIndexPattern', () => { expect(savedObjectsClient.create).not.toHaveBeenCalled(); }); - it(`should not create index pattern if no APM data is found`, async () => { + it(`should not create data view if no APM data is found`, async () => { // does not have APM data jest .spyOn(HistoricalAgentData, 'hasHistoricalAgentData') @@ -52,7 +52,7 @@ describe('createStaticIndexPattern', () => { const savedObjectsClient = getMockSavedObjectsClient('apm-*'); - await createStaticIndexPattern({ + await createStaticDataView({ setup, config: { 'xpack.apm.autocreateApmIndexPattern': true } as APMConfig, savedObjectsClient, @@ -61,7 +61,7 @@ describe('createStaticIndexPattern', () => { expect(savedObjectsClient.create).not.toHaveBeenCalled(); }); - it(`should create index pattern`, async () => { + it(`should create data view`, async () => { // does have APM data jest .spyOn(HistoricalAgentData, 'hasHistoricalAgentData') @@ -69,7 +69,7 @@ describe('createStaticIndexPattern', () => { const savedObjectsClient = getMockSavedObjectsClient('apm-*'); - await createStaticIndexPattern({ + await createStaticDataView({ setup, config: { 'xpack.apm.autocreateApmIndexPattern': true } as APMConfig, savedObjectsClient, @@ -79,17 +79,17 @@ describe('createStaticIndexPattern', () => { expect(savedObjectsClient.create).toHaveBeenCalled(); }); - it(`should overwrite the index pattern if the new index pattern title does not match the old index pattern title`, async () => { + it(`should overwrite the data view if the new data view title does not match the old data view title`, async () => { // does have APM data jest .spyOn(HistoricalAgentData, 'hasHistoricalAgentData') .mockResolvedValue(true); const savedObjectsClient = getMockSavedObjectsClient('apm-*'); - const expectedIndexPatternTitle = + const expectedDataViewTitle = 'apm-*-transaction-*,apm-*-span-*,apm-*-error-*,apm-*-metrics-*'; - await createStaticIndexPattern({ + await createStaticDataView({ setup, config: { 'xpack.apm.autocreateApmIndexPattern': true, @@ -102,13 +102,13 @@ describe('createStaticIndexPattern', () => { expect(savedObjectsClient.create).toHaveBeenCalled(); // @ts-ignore expect(savedObjectsClient.create.mock.calls[0][1].title).toBe( - expectedIndexPatternTitle + expectedDataViewTitle ); // @ts-ignore expect(savedObjectsClient.create.mock.calls[0][2].overwrite).toBe(true); }); - it(`should not overwrite an index pattern if the new index pattern title matches the old index pattern title`, async () => { + it(`should not overwrite an data view if the new data view title matches the old data view title`, async () => { // does have APM data jest .spyOn(HistoricalAgentData, 'hasHistoricalAgentData') @@ -118,7 +118,7 @@ describe('createStaticIndexPattern', () => { 'apm-*-transaction-*,apm-*-span-*,apm-*-error-*,apm-*-metrics-*' ); - await createStaticIndexPattern({ + await createStaticDataView({ setup, config: { 'xpack.apm.autocreateApmIndexPattern': true, diff --git a/x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.ts b/x-pack/plugins/apm/server/lib/data_view/create_static_data_view.ts similarity index 62% rename from x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.ts rename to x-pack/plugins/apm/server/lib/data_view/create_static_data_view.ts index 6fa96de0b9413f..a953bc19b80c8e 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/create_static_index_pattern.ts +++ b/x-pack/plugins/apm/server/lib/data_view/create_static_data_view.ts @@ -7,19 +7,19 @@ import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server'; import { APM_STATIC_INDEX_PATTERN_ID } from '../../../common/index_pattern_constants'; -import apmIndexPattern from '../../tutorial/index_pattern.json'; +import apmDataView from '../../tutorial/index_pattern.json'; import { hasHistoricalAgentData } from '../../routes/historical_data/has_historical_agent_data'; import { Setup } from '../helpers/setup_request'; import { APMRouteHandlerResources } from '../../routes/typings'; import { InternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client.js'; import { withApmSpan } from '../../utils/with_apm_span'; -import { getApmIndexPatternTitle } from './get_apm_index_pattern_title'; +import { getApmDataViewTitle } from './get_apm_data_view_title'; -type ApmIndexPatternAttributes = typeof apmIndexPattern.attributes & { +type ApmDataViewAttributes = typeof apmDataView.attributes & { title: string; }; -export async function createStaticIndexPattern({ +export async function createStaticDataView({ setup, config, savedObjectsClient, @@ -32,22 +32,22 @@ export async function createStaticIndexPattern({ spaceId?: string; overwrite?: boolean; }): Promise { - return withApmSpan('create_static_index_pattern', async () => { - // don't autocreate APM index pattern if it's been disabled via the config + return withApmSpan('create_static_data_view', async () => { + // don't autocreate APM data view if it's been disabled via the config if (!config['xpack.apm.autocreateApmIndexPattern']) { return false; } - // Discover and other apps will throw errors if an index pattern exists without having matching indices. - // The following ensures the index pattern is only created if APM data is found + // Discover and other apps will throw errors if an data view exists without having matching indices. + // The following ensures the data view is only created if APM data is found const hasData = await hasHistoricalAgentData(setup); if (!hasData) { return false; } - const apmIndexPatternTitle = getApmIndexPatternTitle(setup.indices); + const apmDataViewTitle = getApmDataViewTitle(setup.indices); const forceOverwrite = await getForceOverwrite({ - apmIndexPatternTitle, + apmDataViewTitle, overwrite, savedObjectsClient, }); @@ -57,8 +57,8 @@ export async function createStaticIndexPattern({ savedObjectsClient.create( 'index-pattern', { - ...apmIndexPattern.attributes, - title: apmIndexPatternTitle, + ...apmDataView.attributes, + title: apmDataViewTitle, }, { id: APM_STATIC_INDEX_PATTERN_ID, @@ -69,7 +69,7 @@ export async function createStaticIndexPattern({ ); return true; } catch (e) { - // if the index pattern (saved object) already exists a conflict error (code: 409) will be thrown + // if the data view (saved object) already exists a conflict error (code: 409) will be thrown // that error should be silenced if (SavedObjectsErrorHelpers.isConflictError(e)) { return false; @@ -79,27 +79,27 @@ export async function createStaticIndexPattern({ }); } -// force an overwrite of the index pattern if the index pattern has been changed +// force an overwrite of the data view if the data view has been changed async function getForceOverwrite({ savedObjectsClient, overwrite, - apmIndexPatternTitle, + apmDataViewTitle, }: { savedObjectsClient: InternalSavedObjectsClient; overwrite: boolean; - apmIndexPatternTitle: string; + apmDataViewTitle: string; }) { if (!overwrite) { try { - const existingIndexPattern = await savedObjectsClient.get( + const existingDataView = await savedObjectsClient.get( 'index-pattern', APM_STATIC_INDEX_PATTERN_ID ); - // if the existing index pattern does not matches the new one, force an update - return existingIndexPattern.attributes.title !== apmIndexPatternTitle; + // if the existing data view does not matches the new one, force an update + return existingDataView.attributes.title !== apmDataViewTitle; } catch (e) { - // ignore exception if the index pattern (saved object) is not found + // ignore exception if the data view (saved object) is not found if (SavedObjectsErrorHelpers.isNotFoundError(e)) { return false; } diff --git a/x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.test.ts b/x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.test.ts similarity index 77% rename from x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.test.ts rename to x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.test.ts index 81036301575847..19bdaca08d89c0 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.test.ts +++ b/x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.test.ts @@ -8,11 +8,11 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; -import { getApmIndexPatternTitle } from './get_apm_index_pattern_title'; +import { getApmDataViewTitle } from './get_apm_data_view_title'; -describe('getApmIndexPatternTitle', () => { - it('returns an index pattern title by combining existing indicies', () => { - const title = getApmIndexPatternTitle({ +describe('getApmDataViewTitle', () => { + it('returns an data view title by combining existing indicies', () => { + const title = getApmDataViewTitle({ 'apm_oss.transactionIndices': 'apm-*-transaction-*', 'apm_oss.spanIndices': 'apm-*-span-*', 'apm_oss.errorIndices': 'apm-*-error-*', @@ -24,7 +24,7 @@ describe('getApmIndexPatternTitle', () => { }); it('removes duplicates', () => { - const title = getApmIndexPatternTitle({ + const title = getApmDataViewTitle({ 'apm_oss.transactionIndices': 'apm-*', 'apm_oss.spanIndices': 'apm-*', 'apm_oss.errorIndices': 'apm-*', diff --git a/x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.ts b/x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.ts similarity index 88% rename from x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.ts rename to x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.ts index e65f200130e9a4..83fea80efae1f9 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/get_apm_index_pattern_title.ts +++ b/x-pack/plugins/apm/server/lib/data_view/get_apm_data_view_title.ts @@ -8,7 +8,7 @@ import { uniq } from 'lodash'; import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; -export function getApmIndexPatternTitle(apmIndicesConfig: ApmIndicesConfig) { +export function getApmDataViewTitle(apmIndicesConfig: ApmIndicesConfig) { return uniq([ apmIndicesConfig['apm_oss.transactionIndices'], apmIndicesConfig['apm_oss.spanIndices'], diff --git a/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts b/x-pack/plugins/apm/server/lib/data_view/get_dynamic_data_view.ts similarity index 65% rename from x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts rename to x-pack/plugins/apm/server/lib/data_view/get_dynamic_data_view.ts index 19bd801a1f0e1a..24e846cf73ee41 100644 --- a/x-pack/plugins/apm/server/lib/index_pattern/get_dynamic_index_pattern.ts +++ b/x-pack/plugins/apm/server/lib/data_view/get_dynamic_data_view.ts @@ -12,51 +12,51 @@ import { import { APMRouteHandlerResources } from '../../routes/typings'; import { withApmSpan } from '../../utils/with_apm_span'; import { getApmIndices } from '../settings/apm_indices/get_apm_indices'; -import { getApmIndexPatternTitle } from './get_apm_index_pattern_title'; +import { getApmDataViewTitle } from './get_apm_data_view_title'; -export interface IndexPatternTitleAndFields { +export interface DataViewTitleAndFields { title: string; timeFieldName: string; fields: FieldDescriptor[]; } -export const getDynamicIndexPattern = ({ +export const getDynamicDataView = ({ config, context, logger, }: Pick) => { - return withApmSpan('get_dynamic_index_pattern', async () => { + return withApmSpan('get_dynamic_data_view', async () => { const apmIndicies = await getApmIndices({ savedObjectsClient: context.core.savedObjects.client, config, }); - const indexPatternTitle = getApmIndexPatternTitle(apmIndicies); + const dataViewTitle = getApmDataViewTitle(apmIndicies); - const indexPatternsFetcher = new IndexPatternsFetcher( + const DataViewsFetcher = new IndexPatternsFetcher( context.core.elasticsearch.client.asCurrentUser ); - // Since `getDynamicIndexPattern` is called in setup_request (and thus by every endpoint) + // Since `getDynamicDataView` is called in setup_request (and thus by every endpoint) // and since `getFieldsForWildcard` will throw if the specified indices don't exist, // we have to catch errors here to avoid all endpoints returning 500 for users without APM data // (would be a bad first time experience) try { - const fields = await indexPatternsFetcher.getFieldsForWildcard({ - pattern: indexPatternTitle, + const fields = await DataViewsFetcher.getFieldsForWildcard({ + pattern: dataViewTitle, }); - const indexPattern: IndexPatternTitleAndFields = { + const dataView: DataViewTitleAndFields = { fields, timeFieldName: '@timestamp', - title: indexPatternTitle, + title: dataViewTitle, }; - return indexPattern; + return dataView; } catch (e) { const notExists = e.output?.statusCode === 404; if (notExists) { logger.error( - `Could not get dynamic index pattern because indices "${indexPatternTitle}" don't exist` + `Could not get dynamic data view because indices "${dataViewTitle}" don't exist` ); return; } diff --git a/x-pack/plugins/apm/server/lib/helpers/create_es_client/get_inspect_response.ts b/x-pack/plugins/apm/server/lib/helpers/create_es_client/get_inspect_response.ts index ae91daf9d2e0dd..dc8d01f5637946 100644 --- a/x-pack/plugins/apm/server/lib/helpers/create_es_client/get_inspect_response.ts +++ b/x-pack/plugins/apm/server/lib/helpers/create_es_client/get_inspect_response.ts @@ -63,16 +63,16 @@ function getStats({ kibanaRequest.route.path }`, }, - indexPattern: { - label: i18n.translate('xpack.apm.inspector.stats.indexPatternLabel', { - defaultMessage: 'Index pattern', + dataView: { + label: i18n.translate('xpack.apm.inspector.stats.dataViewLabel', { + defaultMessage: 'Data view', }), value: esRequestParams.index, description: i18n.translate( - 'xpack.apm.inspector.stats.indexPatternDescription', + 'xpack.apm.inspector.stats.dataViewDescription', { defaultMessage: - 'The index pattern that connected to the Elasticsearch indices.', + 'The data view that connected to the Elasticsearch indices.', } ), }, diff --git a/x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts b/x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts index 00f3f15786ad61..ef8668d3bc418a 100644 --- a/x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts +++ b/x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts @@ -25,8 +25,8 @@ jest.mock('../settings/apm_indices/get_apm_indices', () => ({ }), })); -jest.mock('../index_pattern/get_dynamic_index_pattern', () => ({ - getDynamicIndexPattern: async () => { +jest.mock('../data_view/get_dynamic_data_view', () => ({ + getDynamicDataView: async () => { return; }, })); diff --git a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.test.ts b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.test.ts index 6c021fcada480a..fc88dd86e29793 100644 --- a/x-pack/plugins/apm/server/lib/transactions/breakdown/index.test.ts +++ b/x-pack/plugins/apm/server/lib/transactions/breakdown/index.test.ts @@ -40,7 +40,6 @@ function getMockSetup(esResponse: any) { ) as APMConfig, uiFilters: {}, indices: mockIndices, - dynamicIndexPattern: null as any, }; } diff --git a/x-pack/plugins/apm/server/routes/index_pattern.ts b/x-pack/plugins/apm/server/routes/data_view.ts similarity index 62% rename from x-pack/plugins/apm/server/routes/index_pattern.ts rename to x-pack/plugins/apm/server/routes/data_view.ts index c957e828bf12a3..dbdd45d11706ff 100644 --- a/x-pack/plugins/apm/server/routes/index_pattern.ts +++ b/x-pack/plugins/apm/server/routes/data_view.ts @@ -5,14 +5,14 @@ * 2.0. */ -import { createStaticIndexPattern } from '../lib/index_pattern/create_static_index_pattern'; +import { createStaticDataView } from '../lib/data_view/create_static_data_view'; import { createApmServerRouteRepository } from './create_apm_server_route_repository'; import { setupRequest } from '../lib/helpers/setup_request'; -import { getDynamicIndexPattern } from '../lib/index_pattern/get_dynamic_index_pattern'; +import { getDynamicDataView } from '../lib/data_view/get_dynamic_data_view'; import { createApmServerRoute } from './create_apm_server_route'; -const staticIndexPatternRoute = createApmServerRoute({ - endpoint: 'POST /api/apm/index_pattern/static', +const staticDataViewRoute = createApmServerRoute({ + endpoint: 'POST /api/apm/data_view/static', options: { tags: ['access:apm'] }, handler: async (resources) => { const { @@ -31,30 +31,30 @@ const staticIndexPatternRoute = createApmServerRoute({ const spaceId = spaces?.setup.spacesService.getSpaceId(request); - const didCreateIndexPattern = await createStaticIndexPattern({ + const didCreateDataView = await createStaticDataView({ setup, config, savedObjectsClient, spaceId, }); - return { created: didCreateIndexPattern }; + return { created: didCreateDataView }; }, }); -const dynamicIndexPatternRoute = createApmServerRoute({ - endpoint: 'GET /api/apm/index_pattern/dynamic', +const dynamicDataViewRoute = createApmServerRoute({ + endpoint: 'GET /api/apm/data_view/dynamic', options: { tags: ['access:apm'] }, handler: async ({ context, config, logger }) => { - const dynamicIndexPattern = await getDynamicIndexPattern({ + const dynamicDataView = await getDynamicDataView({ context, config, logger, }); - return { dynamicIndexPattern }; + return { dynamicDataView }; }, }); -export const indexPatternRouteRepository = createApmServerRouteRepository() - .add(staticIndexPatternRoute) - .add(dynamicIndexPatternRoute); +export const dataViewRouteRepository = createApmServerRouteRepository() + .add(staticDataViewRoute) + .add(dynamicDataViewRoute); diff --git a/x-pack/plugins/apm/server/routes/get_global_apm_server_route_repository.ts b/x-pack/plugins/apm/server/routes/get_global_apm_server_route_repository.ts index 9bc9108da90559..2b18e680b32787 100644 --- a/x-pack/plugins/apm/server/routes/get_global_apm_server_route_repository.ts +++ b/x-pack/plugins/apm/server/routes/get_global_apm_server_route_repository.ts @@ -17,7 +17,7 @@ import { createApmServerRouteRepository } from './create_apm_server_route_reposi import { environmentsRouteRepository } from './environments'; import { errorsRouteRepository } from './errors'; import { apmFleetRouteRepository } from './fleet'; -import { indexPatternRouteRepository } from './index_pattern'; +import { dataViewRouteRepository } from './data_view'; import { metricsRouteRepository } from './metrics'; import { observabilityOverviewRouteRepository } from './observability_overview'; import { rumRouteRepository } from './rum_client'; @@ -37,7 +37,7 @@ import { historicalDataRouteRepository } from './historical_data'; const getTypedGlobalApmServerRouteRepository = () => { const repository = createApmServerRouteRepository() - .merge(indexPatternRouteRepository) + .merge(dataViewRouteRepository) .merge(environmentsRouteRepository) .merge(errorsRouteRepository) .merge(metricsRouteRepository) diff --git a/x-pack/plugins/apm/server/tutorial/index.ts b/x-pack/plugins/apm/server/tutorial/index.ts index 78dd1110e7c624..7226ebf30f6d2d 100644 --- a/x-pack/plugins/apm/server/tutorial/index.ts +++ b/x-pack/plugins/apm/server/tutorial/index.ts @@ -14,11 +14,11 @@ import { } from '../../../../../src/plugins/home/server'; import { CloudSetup } from '../../../cloud/server'; import { APM_STATIC_INDEX_PATTERN_ID } from '../../common/index_pattern_constants'; -import { getApmIndexPatternTitle } from '../lib/index_pattern/get_apm_index_pattern_title'; +import { getApmDataViewTitle } from '../lib/data_view/get_apm_data_view_title'; import { ApmIndicesConfig } from '../lib/settings/apm_indices/get_apm_indices'; import { createElasticCloudInstructions } from './envs/elastic_cloud'; import { onPremInstructions } from './envs/on_prem'; -import apmIndexPattern from './index_pattern.json'; +import apmDataView from './index_pattern.json'; const apmIntro = i18n.translate('xpack.apm.tutorial.introduction', { defaultMessage: @@ -37,15 +37,15 @@ export const tutorialProvider = ({ cloud?: CloudSetup; isFleetPluginEnabled: boolean; }) => () => { - const indexPatternTitle = getApmIndexPatternTitle(apmIndices); + const dataViewTitle = getApmDataViewTitle(apmIndices); const savedObjects = [ { - ...apmIndexPattern, + ...apmDataView, id: APM_STATIC_INDEX_PATTERN_ID, attributes: { - ...apmIndexPattern.attributes, - title: indexPatternTitle, + ...apmDataView.attributes, + title: dataViewTitle, }, }, ]; @@ -111,7 +111,7 @@ It allows you to monitor the performance of thousands of applications in real ti 'xpack.apm.tutorial.specProvider.savedObjectsInstallMsg', { defaultMessage: - 'An APM index pattern is required for some features in the APM UI.', + 'An APM data view is required for some features in the APM UI.', } ), } as TutorialSchema; diff --git a/x-pack/plugins/apm/server/utils/test_helpers.tsx b/x-pack/plugins/apm/server/utils/test_helpers.tsx index e4fabe815d572e..292d83c2a60c9e 100644 --- a/x-pack/plugins/apm/server/utils/test_helpers.tsx +++ b/x-pack/plugins/apm/server/utils/test_helpers.tsx @@ -106,7 +106,6 @@ export async function inspectSearchParams( apmAgentConfigurationIndex: 'myIndex', apmCustomLinkIndex: 'myIndex', }, - dynamicIndexPattern: null as any, }; try { response = await fn(mockSetup);