Skip to content

Commit

Permalink
[8.x] [Inventory][ECO] Return metadata values (#195204) (#195538)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[Inventory][ECO] Return metadata values
(#195204)](#195204)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Cauê
Marcondes","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T07:43:52Z","message":"[Inventory][ECO]
Return metadata values
(#195204)\n\nhttps://github.com//issues/194131\r\n\r\nUse
`entity.identityFields` instead of host, container and
service\r\nspecific ones. Get the first environment
available.","sha":"9975fd63d38a4a6baa27ec34c32d49dab53ec854","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","v8.16.0"],"title":"[Inventory][ECO]
Return metadata
values","number":195204,"url":"https://github.com/elastic/kibana/pull/195204","mergeCommit":{"message":"[Inventory][ECO]
Return metadata values
(#195204)\n\nhttps://github.com//issues/194131\r\n\r\nUse
`entity.identityFields` instead of host, container and
service\r\nspecific ones. Get the first environment
available.","sha":"9975fd63d38a4a6baa27ec34c32d49dab53ec854"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195204","number":195204,"mergeCommit":{"message":"[Inventory][ECO]
Return metadata values
(#195204)\n\nhttps://github.com//issues/194131\r\n\r\nUse
`entity.identityFields` instead of host, container and
service\r\nspecific ones. Get the first environment
available.","sha":"9975fd63d38a4a6baa27ec34c32d49dab53ec854"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Cauê Marcondes <[email protected]>
  • Loading branch information
kibanamachine and cauemarcondes authored Oct 9, 2024
1 parent 59c3b86 commit 128dcb6
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 128dcb6

Please sign in to comment.