diff --git a/x-pack/plugins/infra/server/lib/adapters/metadata/elasticsearch_metadata_adapter.ts b/x-pack/plugins/infra/server/lib/adapters/metadata/elasticsearch_metadata_adapter.ts index 5c7406339a55..b48ffb18947e 100644 --- a/x-pack/plugins/infra/server/lib/adapters/metadata/elasticsearch_metadata_adapter.ts +++ b/x-pack/plugins/infra/server/lib/adapters/metadata/elasticsearch_metadata_adapter.ts @@ -12,6 +12,7 @@ import { InfraMetadataAggregationResponse, } from '../framework'; import { InfraMetadataAdapter, InfraMetricsAdapterResponse } from './adapter_types'; +import { NAME_FIELDS } from '../../constants'; export class ElasticsearchMetadataAdapter implements InfraMetadataAdapter { private framework: InfraBackendFrameworkAdapter; @@ -40,7 +41,7 @@ export class ElasticsearchMetadataAdapter implements InfraMetadataAdapter { aggs: { nodeName: { terms: { - field: sourceConfiguration.fields[nodeType], + field: NAME_FIELDS[nodeType], size: 1, }, }, @@ -92,7 +93,7 @@ export class ElasticsearchMetadataAdapter implements InfraMetadataAdapter { aggs: { nodeName: { terms: { - field: sourceConfiguration.fields[nodeType], + field: NAME_FIELDS[nodeType], size: 1, }, }, diff --git a/x-pack/plugins/infra/server/lib/constants.ts b/x-pack/plugins/infra/server/lib/constants.ts new file mode 100644 index 000000000000..7925455a36e5 --- /dev/null +++ b/x-pack/plugins/infra/server/lib/constants.ts @@ -0,0 +1,17 @@ +/* + * 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 { InfraNodeType } from '../graphql/types'; + +// Used for metadata and snapshots resolvers to find the field that contains +// a displayable name of a node. +// Intentionally not the same as xpack.infra.sources.default.fields.{host,container,pod}. +// TODO: consider moving this to source configuration too. +export const NAME_FIELDS = { + [InfraNodeType.host]: 'host.name', + [InfraNodeType.pod]: 'kubernetes.pod.name', + [InfraNodeType.container]: 'container.name', +};