Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Sep 13, 2021
1 parent 7902bd4 commit a9b3b1e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isRumAgentName } from '../../../../common/agent_name';
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
import { useDynamicDataViewFetcher } from '../../../hooks/use_dynamic_data_view';

interface IndexPattern {
interface DataView {
fields: Array<{ name: string; esTypes: string[] }>;
}

Expand Down Expand Up @@ -40,7 +40,7 @@ export function useFieldNames() {
}

function getMatchingFieldNames(
dataView: IndexPattern | undefined,
dataView: DataView | undefined,
inputValue: string
) {
if (!dataView) {
Expand All @@ -55,7 +55,7 @@ function getMatchingFieldNames(
}

function getDefaultFieldNames(
dataView: IndexPattern | undefined,
dataView: DataView | undefined,
isRumAgent: boolean
) {
const labelFields = getMatchingFieldNames(dataView, 'labels.').slice(0, 6);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ 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';
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 @@ -135,7 +135,7 @@ export function KueryBar(props: {
}

try {
const res = convertKueryToEsQuery(inputValue, dataView 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 @@ -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);
Expand All @@ -73,11 +73,11 @@ export async function createAnomalyDetectionJobs(
async function createAnomalyDetectionJob({
ml,
environment,
indexPatternName,
dataViewName,
}: {
ml: Required<Setup>['ml'];
environment: string;
indexPatternName: string;
dataViewName: string;
}) {
return withApmSpan('create_anomaly_detection_job', async () => {
const randomToken = uuid().substr(-4);
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import * as HistoricalAgentData from '../../routes/historical_data/has_historica
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(),
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('createStaticDataView', () => {
.mockResolvedValue(true);

const savedObjectsClient = getMockSavedObjectsClient('apm-*');
const expectedIndexPatternTitle =
const expectedDataViewTitle =
'apm-*-transaction-*,apm-*-span-*,apm-*-error-*,apm-*-metrics-*';

await createStaticDataView({
Expand All @@ -102,7 +102,7 @@ describe('createStaticDataView', () => {
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);
Expand Down
20 changes: 10 additions & 10 deletions x-pack/plugins/apm/server/lib/data_view/create_static_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

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 { getApmDataViewTitle } from './get_apm_data_view_title';

type ApmIndexPatternAttributes = typeof apmIndexPattern.attributes & {
type ApmDataViewAttributes = typeof apmDataView.attributes & {
title: string;
};

Expand Down Expand Up @@ -45,9 +45,9 @@ export async function createStaticDataView({
return false;
}

const apmIndexPatternTitle = getApmDataViewTitle(setup.indices);
const apmDataViewTitle = getApmDataViewTitle(setup.indices);
const forceOverwrite = await getForceOverwrite({
apmIndexPatternTitle,
apmDataViewTitle,
overwrite,
savedObjectsClient,
});
Expand All @@ -57,8 +57,8 @@ export async function createStaticDataView({
savedObjectsClient.create(
'index-pattern',
{
...apmIndexPattern.attributes,
title: apmIndexPatternTitle,
...apmDataView.attributes,
title: apmDataViewTitle,
},
{
id: APM_STATIC_INDEX_PATTERN_ID,
Expand All @@ -83,21 +83,21 @@ export async function createStaticDataView({
async function getForceOverwrite({
savedObjectsClient,
overwrite,
apmIndexPatternTitle,
apmDataViewTitle,
}: {
savedObjectsClient: InternalSavedObjectsClient;
overwrite: boolean;
apmIndexPatternTitle: string;
apmDataViewTitle: string;
}) {
if (!overwrite) {
try {
const existingIndexPattern = await savedObjectsClient.get<ApmIndexPatternAttributes>(
const existingDataView = await savedObjectsClient.get<ApmDataViewAttributes>(
'index-pattern',
APM_STATIC_INDEX_PATTERN_ID
);

// if the existing data view does not matches the new one, force an update
return existingIndexPattern.attributes.title !== apmIndexPatternTitle;
return existingDataView.attributes.title !== apmDataViewTitle;
} catch (e) {
// ignore exception if the data view (saved object) is not found
if (SavedObjectsErrorHelpers.isNotFoundError(e)) {
Expand Down
18 changes: 9 additions & 9 deletions x-pack/plugins/apm/server/lib/data_view/get_dynamic_data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { withApmSpan } from '../../utils/with_apm_span';
import { getApmIndices } from '../settings/apm_indices/get_apm_indices';
import { getApmDataViewTitle } from './get_apm_data_view_title';

export interface IndexPatternTitleAndFields {
export interface DataViewTitleAndFields {
title: string;
timeFieldName: string;
fields: FieldDescriptor[];
Expand All @@ -30,9 +30,9 @@ export const getDynamicDataView = ({
savedObjectsClient: context.core.savedObjects.client,
config,
});
const indexPatternTitle = getApmDataViewTitle(apmIndicies);
const dataViewTitle = getApmDataViewTitle(apmIndicies);

const indexPatternsFetcher = new IndexPatternsFetcher(
const DataViewsFetcher = new IndexPatternsFetcher(
context.core.elasticsearch.client.asCurrentUser
);

Expand All @@ -41,22 +41,22 @@ export const getDynamicDataView = ({
// 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 data view because indices "${indexPatternTitle}" don't exist`
`Could not get dynamic data view because indices "${dataViewTitle}" don't exist`
);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getStats({
kibanaRequest.route.path
}`,
},
indexPattern: {
dataView: {
label: i18n.translate('xpack.apm.inspector.stats.dataViewLabel', {
defaultMessage: 'Data view',
}),
Expand Down
10 changes: 5 additions & 5 deletions x-pack/plugins/apm/server/tutorial/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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:
Expand All @@ -37,15 +37,15 @@ export const tutorialProvider = ({
cloud?: CloudSetup;
isFleetPluginEnabled: boolean;
}) => () => {
const indexPatternTitle = getApmDataViewTitle(apmIndices);
const dataViewTitle = getApmDataViewTitle(apmIndices);

const savedObjects = [
{
...apmIndexPattern,
...apmDataView,
id: APM_STATIC_INDEX_PATTERN_ID,
attributes: {
...apmIndexPattern.attributes,
title: indexPatternTitle,
...apmDataView.attributes,
title: dataViewTitle,
},
},
];
Expand Down

0 comments on commit a9b3b1e

Please sign in to comment.