Skip to content

Commit

Permalink
[Inventory] Fix discover link (#198690)
Browse files Browse the repository at this point in the history
## Summary

closes #198533

- filter `builtin*`
- add simple e2e

(cherry picked from commit bc80825)
  • Loading branch information
kpatticha committed Nov 1, 2024
1 parent d0a6118 commit 95f8214
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -38,28 +38,21 @@ 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) {
const entityTypeFilter = buildPhrasesFilter(entityTypeField, entityTypes, 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,
});

Expand Down

0 comments on commit 95f8214

Please sign in to comment.