Skip to content

Commit

Permalink
[Inventory][ECO] Return metadata values (elastic#195204)
Browse files Browse the repository at this point in the history
elastic#194131

Use `entity.identityFields` instead of host, container and service
specific ones. Get the first environment available.
  • Loading branch information
cauemarcondes authored Oct 9, 2024
1 parent c3c587b commit 9975fd6
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
*/
import { ENTITY_LATEST, entitiesAliasPattern } from '@kbn/entities-schema';
import {
CONTAINER_ID,
HOST_NAME,
AGENT_NAME,
CLOUD_PROVIDER,
CONTAINER_ID,
ENTITY_DEFINITION_ID,
ENTITY_DISPLAY_NAME,
ENTITY_ID,
ENTITY_IDENTITY_FIELDS,
ENTITY_LAST_SEEN,
ENTITY_TYPE,
HOST_NAME,
SERVICE_ENVIRONMENT,
SERVICE_NAME,
} from '@kbn/observability-shared-plugin/common';
Expand Down Expand Up @@ -77,6 +78,7 @@ interface BaseEntity {
[ENTITY_TYPE]: EntityType;
[ENTITY_DISPLAY_NAME]: string;
[ENTITY_DEFINITION_ID]: string;
[ENTITY_IDENTITY_FIELDS]: string[];
}

/**
Expand All @@ -85,7 +87,7 @@ interface BaseEntity {
interface ServiceEntity extends BaseEntity {
[ENTITY_TYPE]: 'service';
[SERVICE_NAME]: string;
[SERVICE_ENVIRONMENT]?: string | null;
[SERVICE_ENVIRONMENT]?: string | string[] | null;
[AGENT_NAME]: string | string[] | null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
* 2.0.
*/

import { EuiLink, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import React, { useCallback } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui';
import {
AssetDetailsLocatorParams,
ASSET_DETAILS_LOCATOR_ID,
ServiceOverviewParams,
ENTITY_TYPE,
AssetDetailsLocatorParams,
ENTITY_DISPLAY_NAME,
ENTITY_IDENTITY_FIELDS,
ENTITY_TYPE,
SERVICE_ENVIRONMENT,
ServiceOverviewParams,
} from '@kbn/observability-shared-plugin/common';
import React, { useCallback } from 'react';
import { Entity } from '../../../../common/entities';
import { useKibana } from '../../../hooks/use_kibana';
import { EntityIcon } from '../../entity_icon';
import { Entity } from '../../../../common/entities';
import { parseServiceParams } from '../../../utils/parse_service_params';

interface EntityNameProps {
entity: Entity;
Expand All @@ -34,23 +35,23 @@ export function EntityName({ entity }: EntityNameProps) {

const getEntityRedirectUrl = useCallback(() => {
const type = entity[ENTITY_TYPE];
// For service, host and container type there is only one identity field
const identityField = entity[ENTITY_IDENTITY_FIELDS][0];

// Any unrecognised types will always return undefined
switch (type) {
case 'host':
case 'container':
return assetDetailsLocator?.getRedirectUrl({
assetId: entity[ENTITY_DISPLAY_NAME],
assetId: identityField,
assetType: type,
});

case 'service':
// For services, the format of the display name is `service.name:service.environment`.
// We just want the first part of the name for the locator.
// TODO: Replace this with a better approach for handling service names. See https://github.com/elastic/kibana/issues/194131
return serviceOverviewLocator?.getRedirectUrl(
parseServiceParams(entity[ENTITY_DISPLAY_NAME])
);
return serviceOverviewLocator?.getRedirectUrl({
serviceName: identityField,
environment: [entity[SERVICE_ENVIRONMENT] || undefined].flat()[0],
});
}
}, [entity, assetDetailsLocator, serviceOverviewLocator]);

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ export const ENTITY_LAST_SEEN = 'entity.lastSeenTimestamp';
export const ENTITY_FIRST_SEEN = 'entity.firstSeenTimestamp';
export const ENTITY_DISPLAY_NAME = 'entity.displayName';
export const ENTITY_DEFINITION_ID = 'entity.definitionId';
export const ENTITY_IDENTITY_FIELDS = 'entity.identityFields';
export const SOURCE_DATA_STREAM_TYPE = 'source_data_stream.type';
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export {
ENTITY_LAST_SEEN,
ENTITY_TYPE,
SOURCE_DATA_STREAM_TYPE,
ENTITY_IDENTITY_FIELDS,
} from './field_names/elasticsearch';

export {
Expand Down

0 comments on commit 9975fd6

Please sign in to comment.