From 95f821488425b58e995ba09abefbfd4bc51045ea Mon Sep 17 00:00:00 2001 From: Katerina Date: Fri, 1 Nov 2024 22:21:11 +0200 Subject: [PATCH] [Inventory] Fix discover link (#198690) ## Summary closes #198533 - filter `builtin*` - add simple e2e (cherry picked from commit bc80825cd89029282bfbdd17a916392d99663fa0) --- .../inventory/e2e/cypress/e2e/home.cy.ts | 29 +++++++++++++++++++ .../components/search_bar/discover_button.tsx | 19 ++++-------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts b/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts index 3ca60464d571b..501b6b8078da5 100644 --- a/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts +++ b/x-pack/plugins/observability_solution/inventory/e2e/cypress/e2e/home.cy.ts @@ -121,6 +121,35 @@ describe('Home page', () => { cy.url().should('include', '/app/metrics/detail/host/server1'); }); + it('Navigates to discover with default filter', () => { + cy.intercept('GET', '/internal/entities/managed/enablement', { + fixture: 'eem_enabled.json', + }).as('getEEMStatus'); + cy.visitKibana('/app/inventory'); + cy.wait('@getEEMStatus'); + cy.contains('Open in discover').click(); + cy.url().should( + 'include', + "query:(language:kuery,query:'entity.definition_id%20:%20builtin*" + ); + }); + + it('Navigates to discover with kuery filter', () => { + cy.intercept('GET', '/internal/entities/managed/enablement', { + fixture: 'eem_enabled.json', + }).as('getEEMStatus'); + cy.visitKibana('/app/inventory'); + cy.wait('@getEEMStatus'); + cy.getByTestSubj('queryInput').type('service.name : foo'); + + cy.contains('Update').click(); + cy.contains('Open in discover').click(); + cy.url().should( + 'include', + "query:'service.name%20:%20foo%20AND%20entity.definition_id%20:%20builtin*'" + ); + }); + it('Navigates to infra when clicking on a container type entity', () => { cy.intercept('GET', '/internal/entities/managed/enablement', { fixture: 'eem_enabled.json', diff --git a/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx b/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx index dee05d6f7cdd0..d5ed5b5af8cf9 100644 --- a/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx +++ b/x-pack/plugins/observability_solution/inventory/public/components/search_bar/discover_button.tsx @@ -17,7 +17,7 @@ import { ENTITY_LAST_SEEN, ENTITY_TYPE, } from '@kbn/observability-shared-plugin/common'; -import { ENTITIES_LATEST_ALIAS, EntityColumnIds } from '../../../common/entities'; +import { EntityColumnIds } from '../../../common/entities'; import { useInventoryParams } from '../../hooks/use_inventory_params'; import { useKibana } from '../../hooks/use_kibana'; @@ -38,17 +38,6 @@ export function DiscoverButton({ dataView }: { dataView: DataView }) { const filters: PhrasesFilter[] = []; - const entityDefinitionField = dataView.getFieldByName(ENTITY_DEFINITION_ID); - - if (entityDefinitionField) { - const entityDefinitionFilter = buildPhrasesFilter( - entityDefinitionField!, - [ENTITIES_LATEST_ALIAS], - dataView - ); - filters.push(entityDefinitionFilter); - } - const entityTypeField = dataView.getFieldByName(ENTITY_TYPE); if (entityTypes && entityTypeField) { @@ -56,10 +45,14 @@ export function DiscoverButton({ dataView }: { dataView: DataView }) { filters.push(entityTypeFilter); } + const kueryWithEntityDefinitionFilters = [kuery, `${ENTITY_DEFINITION_ID} : builtin*`] + .filter(Boolean) + .join(' AND '); + const discoverLink = discoverLocator?.getRedirectUrl({ indexPatternId: dataView?.id ?? '', columns: ACTIVE_COLUMNS, - query: { query: kuery ?? '', language: 'kuery' }, + query: { query: kueryWithEntityDefinitionFilters, language: 'kuery' }, filters, });