Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Change terminology: "index pattern" becomes "data view" #112021

2 changes: 1 addition & 1 deletion x-pack/plugins/apm/common/processor_event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/e2e/ci/kibana.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sqren Should I also change the config key to dataView?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been deprecated so you can just leave that: #111133

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. weren't you going to remove the entire e2e folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will, but in another PR.


# APM Indices
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/public/application/application.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/apm/public/application/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/apm/public/application/uxApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -52,7 +52,7 @@ const RUM_DATA_FILTERS = [
];

function LocalUIFilters() {
const { indexPatternTitle, indexPattern } = useIndexPattern();
const { dataViewTitle, dataView } = useDataView();

const {
filters = [],
Expand Down Expand Up @@ -108,7 +108,7 @@ function LocalUIFilters() {
<FieldValueSuggestions
key={filterName}
sourceField={uxFiltersByName[filterName].fieldName}
indexPatternTitle={indexPatternTitle}
indexPatternTitle={dataViewTitle}
label={uxFiltersByName[filterName].title}
asCombobox={false}
selectedValue={
Expand Down Expand Up @@ -144,7 +144,7 @@ function LocalUIFilters() {
}}
clearValues={clearValues}
invertFilter={invertFilter}
indexPattern={indexPattern}
indexPattern={dataView}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Promise<IndexPattern | undefined>>(async () => {
if (indexPatternDynamic?.title) {
return indexPatterns.create({
pattern: indexPatternDynamic?.title,
} as IndexPatternSpec);
const { data } = useFetcher<Promise<DataView | undefined>>(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 };
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export function ApmIndices() {
<>
<EuiText color="subdued">
{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.`,
})}
</EuiText>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -85,9 +85,9 @@ describe('ServiceInventory', () => {
});

jest
.spyOn(useDynamicIndexPatternHooks, 'useDynamicIndexPatternFetcher')
.spyOn(useDynamicDataViewHooks, 'useDynamicDataViewFetcher')
.mockReturnValue({
indexPattern: undefined,
dataView: undefined,
status: FETCH_STATUS.SUCCESS,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
});

Expand Down
21 changes: 9 additions & 12 deletions x-pack/plugins/apm/public/components/shared/kuery_bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: {
Expand Down Expand Up @@ -70,7 +70,7 @@ export function KueryBar(props: {

const example = examples[processorEvent || 'defaults'];

const { indexPattern } = useDynamicIndexPatternFetcher();
const { dataView } = useDynamicDataViewFetcher();

const placeholder =
props.placeholder ??
Expand All @@ -88,7 +88,7 @@ export function KueryBar(props: {
});

async function onChange(inputValue: string, selectionStart: number) {
if (indexPattern == null) {
if (dataView == null) {
return;
}

Expand All @@ -101,7 +101,7 @@ export function KueryBar(props: {
const suggestions = (
(await data.autocomplete.getQuerySuggestions({
language: 'kuery',
indexPatterns: [indexPattern],
indexPatterns: [dataView],
boolFilter:
props.boolFilter ??
getBoolFilter({
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};
Loading