mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [[Inventory] Typing entities (#194431)](https://github.com/elastic/kibana/pull/194431) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Cauê Marcondes","email":"55978943+cauemarcondes@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-09-30T17:19:19Z","message":"[Inventory] Typing entities (#194431)\n\nAdds typescript to the Entity type.\r\n\r\nIt correctly infers the type based on the entity.type field.\r\n\r\n<img width=\"544\" alt=\"Screenshot 2024-09-30 at 14 03 27\"\r\nsrc=\"https://github.com/user-attachments/assets/c7c6389d-9224-4a7e-8ea6-ec894ea11573\">\r\n<img width=\"534\" alt=\"Screenshot 2024-09-30 at 14 03 37\"\r\nsrc=\"https://github.com/user-attachments/assets/592256f5-d487-45d9-ac97-128ddc4eb2b0\">\r\n<img width=\"895\" alt=\"Screenshot 2024-09-30 at 14 03 49\"\r\nsrc=\"https://github.com/user-attachments/assets/e11f80ed-39e6-4940-9cc1-effd74f71816\">","sha":"c1f72d71cade7423ab5ab5d3ed68f4aa086f5faf","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] Typing entities","number":194431,"url":"https://github.com/elastic/kibana/pull/194431","mergeCommit":{"message":"[Inventory] Typing entities (#194431)\n\nAdds typescript to the Entity type.\r\n\r\nIt correctly infers the type based on the entity.type field.\r\n\r\n<img width=\"544\" alt=\"Screenshot 2024-09-30 at 14 03 27\"\r\nsrc=\"https://github.com/user-attachments/assets/c7c6389d-9224-4a7e-8ea6-ec894ea11573\">\r\n<img width=\"534\" alt=\"Screenshot 2024-09-30 at 14 03 37\"\r\nsrc=\"https://github.com/user-attachments/assets/592256f5-d487-45d9-ac97-128ddc4eb2b0\">\r\n<img width=\"895\" alt=\"Screenshot 2024-09-30 at 14 03 49\"\r\nsrc=\"https://github.com/user-attachments/assets/e11f80ed-39e6-4940-9cc1-effd74f71816\">","sha":"c1f72d71cade7423ab5ab5d3ed68f4aa086f5faf"}},"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/194431","number":194431,"mergeCommit":{"message":"[Inventory] Typing entities (#194431)\n\nAdds typescript to the Entity type.\r\n\r\nIt correctly infers the type based on the entity.type field.\r\n\r\n<img width=\"544\" alt=\"Screenshot 2024-09-30 at 14 03 27\"\r\nsrc=\"https://github.com/user-attachments/assets/c7c6389d-9224-4a7e-8ea6-ec894ea11573\">\r\n<img width=\"534\" alt=\"Screenshot 2024-09-30 at 14 03 37\"\r\nsrc=\"https://github.com/user-attachments/assets/592256f5-d487-45d9-ac97-128ddc4eb2b0\">\r\n<img width=\"895\" alt=\"Screenshot 2024-09-30 at 14 03 49\"\r\nsrc=\"https://github.com/user-attachments/assets/e11f80ed-39e6-4940-9cc1-effd74f71816\">","sha":"c1f72d71cade7423ab5ab5d3ed68f4aa086f5faf"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
This commit is contained in:
parent
ec90e85b1a
commit
f026cdd57d
6 changed files with 50 additions and 19 deletions
|
@ -7,6 +7,19 @@
|
|||
import * as t from 'io-ts';
|
||||
import { ENTITY_LATEST, entitiesAliasPattern } from '@kbn/entities-schema';
|
||||
import { isRight } from 'fp-ts/lib/Either';
|
||||
import {
|
||||
SERVICE_ENVIRONMENT,
|
||||
SERVICE_NAME,
|
||||
CONTAINER_ID,
|
||||
HOST_NAME,
|
||||
} from '@kbn/observability-shared-plugin/common';
|
||||
import {
|
||||
ENTITY_DEFINITION_ID,
|
||||
ENTITY_DISPLAY_NAME,
|
||||
ENTITY_ID,
|
||||
ENTITY_LAST_SEEN,
|
||||
ENTITY_TYPE,
|
||||
} from './es_fields/entities';
|
||||
|
||||
export const entityTypeRt = t.union([
|
||||
t.literal('service'),
|
||||
|
@ -57,3 +70,32 @@ export const entityTypesRt = new t.Type<EntityType[], string, unknown>(
|
|||
},
|
||||
(arr) => arr.join()
|
||||
);
|
||||
|
||||
interface BaseEntity {
|
||||
[ENTITY_LAST_SEEN]: string;
|
||||
[ENTITY_ID]: string;
|
||||
[ENTITY_TYPE]: EntityType;
|
||||
[ENTITY_DISPLAY_NAME]: string;
|
||||
[ENTITY_DEFINITION_ID]: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* These types are based on service, host and container from the built in definition.
|
||||
*/
|
||||
interface ServiceEntity extends BaseEntity {
|
||||
[ENTITY_TYPE]: 'service';
|
||||
[SERVICE_NAME]: string;
|
||||
[SERVICE_ENVIRONMENT]?: string | null;
|
||||
}
|
||||
|
||||
interface HostEntity extends BaseEntity {
|
||||
[ENTITY_TYPE]: 'host';
|
||||
[HOST_NAME]: string;
|
||||
}
|
||||
|
||||
interface ContainerEntity extends BaseEntity {
|
||||
[ENTITY_TYPE]: 'container';
|
||||
[CONTAINER_ID]: string;
|
||||
}
|
||||
|
||||
export type Entity = ServiceEntity | HostEntity | ContainerEntity;
|
||||
|
|
|
@ -40,7 +40,7 @@ export const Example: Story<{}> = () => {
|
|||
);
|
||||
|
||||
return (
|
||||
<EuiFlexGroup>
|
||||
<EuiFlexGroup direction="column">
|
||||
<EuiFlexItem grow={false}>
|
||||
{`Entity filter: ${selectedEntityType || 'N/A'}`}
|
||||
<EuiLink
|
||||
|
|
|
@ -9,7 +9,7 @@ import { APIReturnType } from '../../../api';
|
|||
|
||||
type InventoryEntitiesAPIReturnType = APIReturnType<'GET /internal/inventory/entities'>;
|
||||
|
||||
export const entitiesMock: InventoryEntitiesAPIReturnType['entities'] = [
|
||||
export const entitiesMock = [
|
||||
{
|
||||
'entity.lastSeenTimestamp': '2023-08-20T10:50:06.384Z',
|
||||
'entity.type': 'host',
|
||||
|
@ -3011,4 +3011,4 @@ export const entitiesMock: InventoryEntitiesAPIReturnType['entities'] = [
|
|||
'entity.displayName': 'Troy McClure',
|
||||
'entity.id': '499',
|
||||
},
|
||||
];
|
||||
] as unknown as InventoryEntitiesAPIReturnType['entities'];
|
||||
|
|
|
@ -12,22 +12,10 @@ import {
|
|||
ENTITIES_LATEST_ALIAS,
|
||||
MAX_NUMBER_OF_ENTITIES,
|
||||
type EntityType,
|
||||
Entity,
|
||||
} from '../../../common/entities';
|
||||
import {
|
||||
ENTITY_DISPLAY_NAME,
|
||||
ENTITY_ID,
|
||||
ENTITY_LAST_SEEN,
|
||||
ENTITY_TYPE,
|
||||
} from '../../../common/es_fields/entities';
|
||||
import { getEntityDefinitionIdWhereClause, getEntityTypesWhereClause } from './query_helper';
|
||||
|
||||
export interface LatestEntity {
|
||||
[ENTITY_LAST_SEEN]: string;
|
||||
[ENTITY_TYPE]: string;
|
||||
[ENTITY_DISPLAY_NAME]: string;
|
||||
[ENTITY_ID]: string;
|
||||
}
|
||||
|
||||
export async function getLatestEntities({
|
||||
inventoryEsClient,
|
||||
sortDirection,
|
||||
|
@ -47,8 +35,7 @@ export async function getLatestEntities({
|
|||
| ${getEntityDefinitionIdWhereClause()}
|
||||
| SORT ${sortField} ${sortDirection}
|
||||
| LIMIT ${MAX_NUMBER_OF_ENTITIES}
|
||||
| KEEP ${ENTITY_LAST_SEEN}, ${ENTITY_TYPE}, ${ENTITY_DISPLAY_NAME}, ${ENTITY_ID}
|
||||
`,
|
||||
`,
|
||||
filter: {
|
||||
bool: {
|
||||
filter: [...kqlQuery(kuery)],
|
||||
|
@ -56,5 +43,5 @@ export async function getLatestEntities({
|
|||
},
|
||||
});
|
||||
|
||||
return esqlResultToPlainObjects<LatestEntity>(latestEntitiesEsqlResponse);
|
||||
return esqlResultToPlainObjects<Entity>(latestEntitiesEsqlResponse);
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ export const LABEL_NAME = 'labels.name';
|
|||
|
||||
export const HOST = 'host';
|
||||
export const HOST_HOSTNAME = 'host.hostname';
|
||||
export const HOST_NAME = 'host.name';
|
||||
export const HOST_OS_PLATFORM = 'host.os.platform';
|
||||
export const CONTAINER_ID = 'container.id';
|
||||
export const KUBERNETES = 'kubernetes';
|
||||
|
|
|
@ -98,6 +98,7 @@ export {
|
|||
LABEL_NAME,
|
||||
HOST,
|
||||
HOST_HOSTNAME,
|
||||
HOST_NAME,
|
||||
HOST_OS_PLATFORM,
|
||||
CONTAINER_ID,
|
||||
KUBERNETES,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue