Skip to content

Commit

Permalink
migrating to new http api
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Aug 2, 2019
1 parent 2947214 commit 0064ac5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 11 deletions.
4 changes: 3 additions & 1 deletion x-pack/legacy/plugins/infra/common/http_api/metadata_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ export type InfraMetadataMachine = rt.TypeOf<typeof InfraMetadataMachineRT>;

export type InfraMetadataHost = rt.TypeOf<typeof InfraMetadataHostRT>;

export type InfraMEtadataOS = rt.TypeOf<typeof InfraMetadataOSRT>;
export type InfraMetadataOS = rt.TypeOf<typeof InfraMetadataOSRT>;

export type InfraMetadataNodeType = rt.TypeOf<typeof InfraMetadataNodeTypeRT>;
14 changes: 4 additions & 10 deletions x-pack/legacy/plugins/infra/server/routes/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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 { 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';
Expand Down Expand Up @@ -55,21 +55,15 @@ export const initMetadataRoute = (libs: InfraBackendLibs) => {
nameToFeature('metrics')
);

// const hasAPMData = await hasAPMData(
// framework,
// req,
// configuration,
// nodeId,
// nodeType
// );
// const apmMetricData = hasAPMData ? [{ name: 'apm.transaction', source: 'apm' }] : [];
const hasAPM = await hasAPMData(framework, req, configuration, nodeId, nodeType);
const apmMetricFeatures = hasAPM ? [{ name: 'apm.transaction', source: 'apm' }] : [];

const id = metricsMetadata.id;
const name = metricsMetadata.name || id;
return InfraMetadataRT.decode({
id,
name,
features: [...metricFeatures, ...cloudMetricsFeatures],
features: [...metricFeatures, ...cloudMetricsFeatures, ...apmMetricFeatures],
info,
}).getOrElseL(throwErrors(Boom.badImplementation));
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 {
InfraFrameworkRequest,
InfraBackendFrameworkAdapter,
} from '../../../lib/adapters/framework';
import { InfraSourceConfiguration } from '../../../lib/sources';
import { getIdFieldName } from './get_id_field_name';

export const hasAPMData = async (
framework: InfraBackendFrameworkAdapter,
req: InfraFrameworkRequest,
sourceConfiguration: InfraSourceConfiguration,
nodeId: string,
nodeType: 'host' | 'pod' | 'container'
) => {
const config = framework.config(req);
const apmIndex = config.get('apm_oss.transactionIndices') || 'apm-*';
// 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' : getIdFieldName(sourceConfiguration, nodeType);
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<{}, {}>(req, 'search', params);
return response.hits.total.value !== 0;
};

0 comments on commit 0064ac5

Please sign in to comment.