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

Saved object filter KQL do not work with multiple nested filters #81009

Closed
nchaulet opened this issue Oct 19, 2020 · 14 comments · Fixed by #96292
Closed

Saved object filter KQL do not work with multiple nested filters #81009

nchaulet opened this issue Oct 19, 2020 · 14 comments · Fixed by #96292
Assignees
Labels
bug Fixes for quality problems that affect the customer experience Feature:Saved Objects impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:medium Medium Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@nchaulet
Copy link
Member

Description

I am trying to use nested filter in a saved object filter query using KQL, and it's throwing a validation error if I have multiple items in my nested query

This work

fleet-agents.attributes.inputs:{ package: "endpoint"}

This do not work

fleet-agents.attributes.inputs:{  status: "error" AND package: "endpoint"   }

The error

This key 'status' need to be wrapped by a saved object type like fleet-agents: Bad Request
@nchaulet nchaulet added the bug Fixes for quality problems that affect the customer experience label Oct 19, 2020
@rudolf rudolf added Feature:Saved Objects Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc labels Oct 19, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet pgayvallet self-assigned this Oct 21, 2020
@pgayvallet
Copy link
Contributor

@nchaulet I'm currently looking at the ast validation we are using for SO to try to fix that.

In the meantime, looking at the tests, I think that expanding the query should work?

fleet-agents.attributes.inputs.status: "error" AND fleet-agents.attributes.inputs.package: "endpoint"

Could you confirm that this 'workaround' is correctly working for your case.

@pgayvallet
Copy link
Contributor

pgayvallet commented Oct 27, 2020

So, I can confirm we got an issue in validateFilterKueryNode (src/core/server/saved_objects/service/lib/filter_utils.ts). The function's logic doesn't seem to properly handle 'nested' function-type nodes/arguments, resulting on the AND function inside the nested filter to not being properly parsed/validated.

Note that this seems to only be a validation issue. By removing the validation step, I think the query is executed just fine against the index.

A simple test to reproduce the behavior (in src/core/server/saved_objects/service/lib/filter_utils.test.ts)

    test('Validate multiple items nested filter query through KueryNode', () => {
      const validationObject = validateFilterKueryNode({
        astFilter: esKuery.fromKueryExpression(
          'alert.attributes.actions:{ actionTypeId: ".server-log" AND actionRef: "foo" }'
        ),
        types: ['alert'],
        indexMapping: mockMappings,
        hasNestedKey: true,
      });

      // nodes will have errors in the array
      expect(validationObject).toEqual(...);
    });

@lukasolson (and @elastic/kibana-app-arch in general) I (well, the team in general) kinda lack KQL knowledge to be able to fix this. From what I see, the current validation is rather simple, and totally lack nested functions logic (it only handle the nested type functions), and I fear going 'further' may be quite complicated. Would you mind taking a look to see if there is an obvious way to improve/fix our validation here?

@nchaulet
Copy link
Member Author

@pgayvallet I think the workaround fleet-agents.attributes.inputs.status: "error" AND fleet-agents.attributes.inputs.package: "endpoint" is not going to provide correct results for us

if we have this document `{inputs: [{package: endpoint, status: healthy}, {package: nginx, status: error}]`` it's going to be returned by your workaround but a nested query will not return it.

@pgayvallet
Copy link
Contributor

You are right. Did not thought about inputs being an array...

Waiting on @elastic/kibana-app-arch insight then.

@lukasolson
Copy link
Member

Hmm, yeah this seems like a bug that falls on our team. What's the priority of fixing this?

@pgayvallet
Copy link
Contributor

I'll let @nchaulet answer that, but I think this is required for a feature they are planning for 7.11

@nchaulet
Copy link
Member Author

nchaulet commented Nov 3, 2020

Yes we would like to have this for 7.11 it will allow us a better filtering of Fleet agents

@nchaulet
Copy link
Member Author

Hi some news we will not use that feature on fleet for 7.11, so there is no urgence on our side to fix that

@XavierM
Copy link
Contributor

XavierM commented Nov 24, 2020

This PR should fix it, #64002

@joshdover
Copy link
Contributor

@XavierM would you mind extracting that fix into a dedicated PR?

@joshdover joshdover assigned XavierM and unassigned pgayvallet Dec 3, 2020
@ppisljar ppisljar added impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. triaged labels Mar 1, 2021
@ppisljar ppisljar added the loe:medium Medium Level of Effort label Mar 1, 2021
@Dosant Dosant added the SharedUX/fix-it-week Bugs that have been groomed and queued up for the team's next fix it week label Mar 1, 2021
@lukasolson lukasolson removed their assignment Mar 4, 2021
@lukasolson lukasolson removed SharedUX/fix-it-week Bugs that have been groomed and queued up for the team's next fix it week Feature:KQL KQL Team:AppServices labels Mar 4, 2021
@lukasolson
Copy link
Member

Looked some more at this today, I don't think this is anything relating to KQL itself, and I believe the fix that @XavierM has in the other PR should do the trick.

@pgayvallet
Copy link
Contributor

@XavierM would you mind extracting the fix you performed in #64002 to an isolated PR?

@rudolf
Copy link
Contributor

rudolf commented Apr 16, 2021

Closed by #96292

@rudolf rudolf closed this as completed Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Saved Objects impact:high Addressing this issue will have a high level of impact on the quality/strength of our product. loe:medium Medium Level of Effort Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants