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

[8.17] [Inventory][ECO] Fix asKqlFilter (#200984) #201134

Merged
merged 2 commits into from
Nov 21, 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
21 changes: 18 additions & 3 deletions x-pack/plugins/entity_manager/public/lib/entity_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,22 @@ describe('EntityClient', () => {
};

const result = entityClient.asKqlFilter(entityLatest);
expect(result).toEqual('service.name: my-service');
expect(result).toEqual('service.name: "my-service"');
});

it('should return the kql filter when an indentity field value contain special characters', () => {
const entityLatest: EntityInstance = {
entity: {
...commonEntityFields.entity,
identity_fields: ['host.name', 'foo.bar'],
},
host: {
name: 'my-host:some-value:some-other-value',
},
};

const result = entityClient.asKqlFilter(entityLatest);
expect(result).toEqual('host.name: "my-host:some-value:some-other-value"');
});

it('should return the kql filter when indentity_fields is composed by multiple fields', () => {
Expand All @@ -56,7 +71,7 @@ describe('EntityClient', () => {
};

const result = entityClient.asKqlFilter(entityLatest);
expect(result).toEqual('(service.name: my-service AND service.environment: staging)');
expect(result).toEqual('(service.name: "my-service" AND service.environment: "staging")');
});

it('should ignore fields that are not present in the entity', () => {
Expand All @@ -71,7 +86,7 @@ describe('EntityClient', () => {
};

const result = entityClient.asKqlFilter(entityLatest);
expect(result).toEqual('host.name: my-host');
expect(result).toEqual('host.name: "my-host"');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class EntityClient {
const identityFieldsValue = this.getIdentityFieldsValue(entityInstance);

const nodes: KueryNode[] = Object.entries(identityFieldsValue).map(([identityField, value]) => {
return nodeTypes.function.buildNode('is', identityField, value);
return nodeTypes.function.buildNode('is', identityField, `"${value}"`);
});

if (nodes.length === 0) return '';
Expand Down