From 4e7bca86372ec0c68c2bc9169676e91f67e919d0 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 17 Dec 2024 22:00:42 +1100 Subject: [PATCH] [8.x] Revert "[ECO][Inventory v2] Ad hoc data view: Add get entities definition endpoint using sources (#203424) (#204012) (#204025) # Backport This will backport the following commits from `main` to `8.x`: - [Revert "[ECO][Inventory v2] Ad hoc data view: Add get entities definition endpoint using sources (#203424) (#204012)](https://github.com/elastic/kibana/pull/204012) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: jennypavlova Co-authored-by: Irene Blanco --- .../components/entity_actions/index.tsx | 9 ++-- .../public/hooks/use_discover_redirect.ts | 15 +++---- .../hooks/use_fetch_entity_definition.ts | 27 ++++++++++++ ..._fetch_entity_definition_index_patterns.ts | 34 --------------- .../get_entity_definitions.ts | 41 ------------------- .../get_global_inventory_route_repository.ts | 2 - 6 files changed, 39 insertions(+), 89 deletions(-) create mode 100644 x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition.ts delete mode 100644 x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition_index_patterns.ts delete mode 100644 x-pack/plugins/observability_solution/inventory/server/routes/entity_definition/get_entity_definitions.ts diff --git a/x-pack/plugins/observability_solution/inventory/public/components/entity_actions/index.tsx b/x-pack/plugins/observability_solution/inventory/public/components/entity_actions/index.tsx index 6b31f877f10af..691ba4388ac63 100644 --- a/x-pack/plugins/observability_solution/inventory/public/components/entity_actions/index.tsx +++ b/x-pack/plugins/observability_solution/inventory/public/components/entity_actions/index.tsx @@ -24,18 +24,17 @@ export const EntityActions = ({ entity, setShowActions }: Props) => { ? `inventoryEntityActionsButton-${entity.entityDisplayName}` : 'inventoryEntityActionsButton'; - const { getDiscoverEntitiesRedirectUrl, isEntityDefinitionIndexPatternsLoading } = - useDiscoverRedirect(entity); + const { getDiscoverEntitiesRedirectUrl, isEntityDefinitionLoading } = useDiscoverRedirect(entity); const discoverUrl = getDiscoverEntitiesRedirectUrl(); const actions: React.ReactElement[] = []; - if (!discoverUrl && !isEntityDefinitionIndexPatternsLoading) { + if (!discoverUrl && !isEntityDefinitionLoading) { setShowActions(false); return null; } - if (!isEntityDefinitionIndexPatternsLoading) { + if (!isEntityDefinitionLoading) { actions.push( { iconType="boxesHorizontal" color="text" onClick={togglePopover} - isLoading={isEntityDefinitionIndexPatternsLoading} + isLoading={isEntityDefinitionLoading} /> } closePopover={closePopover} diff --git a/x-pack/plugins/observability_solution/inventory/public/hooks/use_discover_redirect.ts b/x-pack/plugins/observability_solution/inventory/public/hooks/use_discover_redirect.ts index 2855df8e4dd3f..dc9f5bf4a4740 100644 --- a/x-pack/plugins/observability_solution/inventory/public/hooks/use_discover_redirect.ts +++ b/x-pack/plugins/observability_solution/inventory/public/hooks/use_discover_redirect.ts @@ -7,22 +7,23 @@ import { useCallback, useMemo } from 'react'; import type { InventoryEntity } from '../../common/entities'; import { useAdHocDataView } from './use_adhoc_data_view'; -import { useFetchEntityDefinitionIndexPattern } from './use_fetch_entity_definition_index_patterns'; +import { useFetchEntityDefinition } from './use_fetch_entity_definition'; import { useKibana } from './use_kibana'; export const useDiscoverRedirect = (entity: InventoryEntity) => { const { services: { share, application, entityManager }, } = useKibana(); - const { entityDefinitionIndexPatterns, isEntityDefinitionIndexPatternsLoading } = - useFetchEntityDefinitionIndexPattern(entity.entityType); + const { entityDefinitions, isEntityDefinitionLoading } = useFetchEntityDefinition( + entity.entityDefinitionId + ); const title = useMemo( () => - !isEntityDefinitionIndexPatternsLoading && (entityDefinitionIndexPatterns ?? []).length > 0 - ? entityDefinitionIndexPatterns[0].join() + !isEntityDefinitionLoading && entityDefinitions && entityDefinitions?.length > 0 + ? entityDefinitions[0]?.indexPatterns?.join(',') : '', - [entityDefinitionIndexPatterns, isEntityDefinitionIndexPatternsLoading] + [entityDefinitions, isEntityDefinitionLoading] ); const { dataView } = useAdHocDataView(title); @@ -53,5 +54,5 @@ export const useDiscoverRedirect = (entity: InventoryEntity) => { entityManager.entityClient, ]); - return { getDiscoverEntitiesRedirectUrl, isEntityDefinitionIndexPatternsLoading }; + return { getDiscoverEntitiesRedirectUrl, isEntityDefinitionLoading }; }; diff --git a/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition.ts b/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition.ts new file mode 100644 index 0000000000000..9f6a0232891b2 --- /dev/null +++ b/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition.ts @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { useAbortableAsync } from '@kbn/observability-utils-browser/hooks/use_abortable_async'; +import { useKibana } from './use_kibana'; + +export const useFetchEntityDefinition = (id: string) => { + const { + services: { entityManager }, + } = useKibana(); + + const { value, loading } = useAbortableAsync( + ({ signal }) => { + return entityManager.entityClient.getEntityDefinition(id); + }, + [entityManager.entityClient, id] + ); + + return { + entityDefinitions: value?.definitions, + isEntityDefinitionLoading: loading, + }; +}; diff --git a/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition_index_patterns.ts b/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition_index_patterns.ts deleted file mode 100644 index 127c95b532749..0000000000000 --- a/x-pack/plugins/observability_solution/inventory/public/hooks/use_fetch_entity_definition_index_patterns.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { useInventoryAbortableAsync } from './use_inventory_abortable_async'; -import { useKibana } from './use_kibana'; - -export const useFetchEntityDefinitionIndexPattern = (type: string) => { - const { - services: { inventoryAPIClient }, - } = useKibana(); - - const { value = { definitionIndexPatterns: [] }, loading } = useInventoryAbortableAsync( - ({ signal }) => { - return inventoryAPIClient.fetch('GET /internal/inventory/entity/definitions/sources', { - params: { - query: { - type, - }, - }, - signal, - }); - }, - [inventoryAPIClient] - ); - - return { - entityDefinitionIndexPatterns: value?.definitionIndexPatterns, - isEntityDefinitionIndexPatternsLoading: loading, - }; -}; diff --git a/x-pack/plugins/observability_solution/inventory/server/routes/entity_definition/get_entity_definitions.ts b/x-pack/plugins/observability_solution/inventory/server/routes/entity_definition/get_entity_definitions.ts deleted file mode 100644 index 7db85de7c460b..0000000000000 --- a/x-pack/plugins/observability_solution/inventory/server/routes/entity_definition/get_entity_definitions.ts +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import * as t from 'io-ts'; -import { createInventoryServerRoute } from '../create_inventory_server_route'; - -export const getEntityDefinitionSourceIndexPatternsByType = createInventoryServerRoute({ - endpoint: 'GET /internal/inventory/entity/definitions/sources', - params: t.type({ - query: t.type({ - type: t.string, - }), - }), - options: { - tags: ['access:inventory'], - }, - async handler({ context, params, request, plugins }) { - const [_coreContext, entityManagerStart] = await Promise.all([ - context.core, - plugins.entityManager.start(), - ]); - const { type } = params.query; - const entityManagerClient = await entityManagerStart.getScopedClient({ request }); - - const entityDefinitionsSource = await entityManagerClient.v2.readSourceDefinitions({ type }); - - return { - definitionIndexPatterns: entityDefinitionsSource.map( - (definition) => definition.index_patterns, - [] - ), - }; - }, -}); - -export const entityDefinitionsRoutes = { - ...getEntityDefinitionSourceIndexPatternsByType, -}; diff --git a/x-pack/plugins/observability_solution/inventory/server/routes/get_global_inventory_route_repository.ts b/x-pack/plugins/observability_solution/inventory/server/routes/get_global_inventory_route_repository.ts index 5a808ea9cc2cb..598b69db90e5a 100644 --- a/x-pack/plugins/observability_solution/inventory/server/routes/get_global_inventory_route_repository.ts +++ b/x-pack/plugins/observability_solution/inventory/server/routes/get_global_inventory_route_repository.ts @@ -6,13 +6,11 @@ */ import { entitiesRoutes } from './entities/route'; -import { entityDefinitionsRoutes } from './entity_definition/get_entity_definitions'; import { hasDataRoutes } from './has_data/route'; export function getGlobalInventoryServerRouteRepository() { return { ...entitiesRoutes, - ...entityDefinitionsRoutes, ...hasDataRoutes, }; }