From ad99ca84e53644ee9e059912151d88840aa2652a Mon Sep 17 00:00:00 2001 From: Chris Cowan Date: Tue, 5 May 2020 05:31:19 -0700 Subject: [PATCH] [Metrics UI] Remove APM Hard Dependency (#64952) * [Metrics UI] Remove APM Hard Dependency * removing unused variable Co-authored-by: Elastic Machine --- x-pack/plugins/infra/kibana.json | 1 - .../infra/server/routes/metadata/index.ts | 6 +-- .../routes/metadata/lib/has_apm_data.ts | 54 ------------------- .../api_integration/apis/infra/metadata.ts | 41 -------------- 4 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts diff --git a/x-pack/plugins/infra/kibana.json b/x-pack/plugins/infra/kibana.json index a15465a0cde66..ea66ae7a46d4e 100644 --- a/x-pack/plugins/infra/kibana.json +++ b/x-pack/plugins/infra/kibana.json @@ -4,7 +4,6 @@ "kibanaVersion": "kibana", "requiredPlugins": [ "features", - "apm", "usageCollection", "spaces", "home", diff --git a/x-pack/plugins/infra/server/routes/metadata/index.ts b/x-pack/plugins/infra/server/routes/metadata/index.ts index fe142aa93dcda..7e3a30e1e6918 100644 --- a/x-pack/plugins/infra/server/routes/metadata/index.ts +++ b/x-pack/plugins/infra/server/routes/metadata/index.ts @@ -18,7 +18,6 @@ import { import { InfraBackendLibs } from '../../lib/infra_types'; import { getMetricMetadata } from './lib/get_metric_metadata'; import { pickFeatureName } from './lib/pick_feature_name'; -import { hasAPMData } from './lib/has_apm_data'; import { getCloudMetricsMetadata } from './lib/get_cloud_metric_metadata'; import { getNodeInfo } from './lib/get_node_info'; import { throwErrors } from '../../../common/runtime_types'; @@ -74,16 +73,13 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => { const cloudMetricsFeatures = pickFeatureName(cloudMetricsMetadata.buckets).map( nameToFeature('metrics') ); - const hasAPM = await hasAPMData(framework, requestContext, configuration, nodeId, nodeType); - const apmMetricFeatures = hasAPM ? [{ name: 'apm.transaction', source: 'apm' }] : []; - const id = metricsMetadata.id; const name = metricsMetadata.name || id; return response.ok({ body: InfraMetadataRT.encode({ id, name, - features: [...metricFeatures, ...cloudMetricsFeatures, ...apmMetricFeatures], + features: [...metricFeatures, ...cloudMetricsFeatures], info, }), }); diff --git a/x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts b/x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts deleted file mode 100644 index 1f8029db80d86..0000000000000 --- a/x-pack/plugins/infra/server/routes/metadata/lib/has_apm_data.ts +++ /dev/null @@ -1,54 +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 { RequestHandlerContext } from 'src/core/server'; - -import { KibanaFramework } from '../../../lib/adapters/framework/kibana_framework_adapter'; -import { InfraSourceConfiguration } from '../../../lib/sources'; -import { findInventoryFields } from '../../../../common/inventory_models'; -import { InventoryItemType } from '../../../../common/inventory_models/types'; - -export const hasAPMData = async ( - framework: KibanaFramework, - requestContext: RequestHandlerContext, - sourceConfiguration: InfraSourceConfiguration, - nodeId: string, - nodeType: InventoryItemType -) => { - const apmIndices = await framework.plugins.apm.getApmIndices(); - const apmIndex = apmIndices['apm_oss.transactionIndices'] || 'apm-*'; - const fields = findInventoryFields(nodeType, sourceConfiguration.fields); - - // There is a bug in APM ECS data where host.name is not set. - // This will fixed with: https://github.com/elastic/apm-server/issues/2502 - const nodeFieldName = nodeType === 'host' ? 'host.hostname' : fields.id; - const params = { - allowNoIndices: true, - ignoreUnavailable: true, - terminateAfter: 1, - index: apmIndex, - body: { - size: 0, - query: { - bool: { - filter: [ - { - match: { [nodeFieldName]: nodeId }, - }, - { - exists: { field: 'service.name' }, - }, - { - exists: { field: 'transaction.type' }, - }, - ], - }, - }, - }, - }; - const response = await framework.callWithRequest<{}, {}>(requestContext, 'search', params); - return response.hits.total.value !== 0; -}; diff --git a/x-pack/test/api_integration/apis/infra/metadata.ts b/x-pack/test/api_integration/apis/infra/metadata.ts index 5187cc5e3ec26..d3551a139bf17 100644 --- a/x-pack/test/api_integration/apis/infra/metadata.ts +++ b/x-pack/test/api_integration/apis/infra/metadata.ts @@ -29,11 +29,6 @@ const timeRange800withAws = { to: DATES[`8.0.0`].logs_and_metrics_with_aws.max, }; -const timeRange800 = { - from: DATES['8.0.0'].logs_and_metrics.min, - to: DATES[`8.0.0`].logs_and_metrics.max, -}; - export default function({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const supertest = getService('supertest'); @@ -269,42 +264,6 @@ export default function({ getService }: FtrProviderContext) { } }); }); - describe('APM metrics', () => { - const archiveName = 'infra/8.0.0/metrics_and_apm'; - before(() => esArchiver.load(archiveName)); - after(() => esArchiver.unload(archiveName)); - - it('host without APM data', async () => { - const metadata = await fetchMetadata({ - sourceId: 'default', - nodeId: 'gke-observability-8--observability-8--bc1afd95-f0zc', - nodeType: 'host', - timeRange: timeRange800, - }); - if (metadata) { - expect( - metadata.features.some(f => f.name === 'apm.transaction' && f.source === 'apm') - ).to.be(false); - } else { - throw new Error('Metadata should never be empty'); - } - }); - it('pod with APM data', async () => { - const metadata = await fetchMetadata({ - sourceId: 'default', - nodeId: 'c1031331-9ae0-11e9-9a96-42010a84004d', - nodeType: 'pod', - timeRange: timeRange800, - }); - if (metadata) { - expect( - metadata.features.some(f => f.name === 'apm.transaction' && f.source === 'apm') - ).to.be(true); - } else { - throw new Error('Metadata should never be empty'); - } - }); - }); }); }); }