Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Inventory] Fix discover link #198690

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

I pass it as a kuery cause the filter doesn't support pattern linke *

filters,
});

Expand Down