[ResponseOps] Automatically copy source data into the alerts-as-data documents for other ES Query rule types#230010
Conversation
…xi/kibana into update/copy-es-query-source-data
…xi/kibana into update/copy-es-query-source-data
…xi/kibana into update/copy-es-query-source-data
|
Pinging @elastic/response-ops (Team:ResponseOps) |
|
|
||
| expect(resp.hits.hits[0]._source).property('host.name', 'host-0'); | ||
| expect(resp.hits.hits[0]._source).property('host.name'); | ||
| expect(get(resp.hits.hits[0]._source, 'host.name')).eql(['host-0', 'host-0', 'host-0']); |
There was a problem hiding this comment.
Why it an array of the 3 of the same value here when previously it was the single host-0?
There was a problem hiding this comment.
They aren't deduped anymore bc we aren't doing an aggregation for these fields. We are just parsing them out of the hits similar to how to this works for the ES|QL query type
There was a problem hiding this comment.
This seems a little problematic. At least for this field, I'd think we'd want to collapse to a single string, since host.name is considered a non-array in ECS. But in the case where the values are NOT the same, what would we do? Pick the first one? I'm guessing this could get more complicated for other fields.
I know we suggest folks access the .alerts documents via fields, I think partially because we sometimes write out the full field name instead of using nested objects. But it also means that technically having a three element host.name array value shouldn't cause any kind of issue.
But it does seem odd.
One thing I'm wondering is if it would make sense to throw these values in a Set to remove dups - can we do that with all the fields? I guess probably just fields that aren't already ECS array values (since they may expect dups). Then we'd only see the multi-element arrays when there aren't dups.
There was a problem hiding this comment.
Yeah that's fair! We can do a set to remove dupes
There was a problem hiding this comment.
We had a discussion on this when I first made the change to write ECS fields to the alert doc for ES|QL
There was a problem hiding this comment.
@mikecote thoughts? I guess the problem with de-duping (see discussion link in previous comment) is going to be that the values won't "line up" anymore, if some fields have dup'd values vs not. But I'm not sure there's much value there anyway, not clear that the values would end up "lining up" after making it into ES and then out again (through Kibana).
I'm more concerned that the "source" version won't validate against an ECS-based mapping anymore. And that there's probably an expectation that "fields" which aren't supposed to be arrays, actually have multiple elements. But I guess we don't really support "source" for these anyway?
I guess I'm kind of thinking that the current code - not deduping - is probably the easiest thing for people to understand. And I guess it makes sense if folks are filtering on these fields.
There was a problem hiding this comment.
Yeah it appears the idea of not de-dupping was to have the same count of values in all the arrays so they line up. I don't have a strong opinion on whether we should de-dup or not, given it will still function for it's main purpose which is conditional actions and maintenance windows.
I recall communicating the oddity of arrays to stakeholders when we first did this and it didn't appear to be a concern for anyone at that time.
There was a problem hiding this comment.
Ya, I think I'm fine with not de-dup'ing then. I'm worried that we'll run into problems like this one: #221252 (comment) , where somewhere in our code we assume an arity that is wrong when we run.
…query-source-data
…xi/kibana into update/copy-es-query-source-data
Resolved in this commit, a324cdb |
|
If I set the so I guess it is dependent on the query returning hits to copy over in the source fields to work correctly? |
Ah sorry, I will fix this. Yeah we won't copy over data if there aren't any hits Resolved in this commit, b47b3c1 |
|
@doakalexi, it looks like you're updating the parameters for a rule type! Please review the guidelines for making additive changes to rule type parameters and determine if your changes require an intermediate release. |
ymao1
left a comment
There was a problem hiding this comment.
LGTM! Verified works as described and updating a rule with a previously set source fields param continues to work. The copying of the source fields into an array with possible repeated values does seem a little funky but it looks like it's working the same way as ES|QL rules and we haven't gotten any complaints from that department so seems fine.
I think we need a doc issue to add this behavior to the docs and to specify that the size field needs to be > 0 in order for any source fields to get copied.
pmuellr
left a comment
There was a problem hiding this comment.
LGTM, that getSourceFields() test is ... interesting! :-) We'll see how it pans out over time.
| it('should generate the correct source fields', async () => { | ||
| const sourceFields = getSourceFields(); | ||
| expect(sourceFields).toMatchInlineSnapshot(` | ||
| Array [ |
There was a problem hiding this comment.
Oh wow. I wonder how well this will work over time? :-)
There was a problem hiding this comment.
Thanks for reviewing! Do you think I should change anything? I kinda just did a check of the fields
There was a problem hiding this comment.
Nah, I'm interested to see how this plays out. If it's causes too much churn, I think we can just remove it ... or maybe someone would want the snapshot stored in an external file or something.
We'll see!
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
|
…documents for other ES Query rule types (elastic#230010) Resolves elastic#190947 ## Summary This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - I liked to use the sample data to test this. You can add it on the homepage ( The sample data logs will have a couple fields that will get written to the doc like message) - Create ES Query KQL and DSL rules. - Go to [dev tools](http://localhost:5601/app/dev_tools#/console) and run the query below to verify that the query results that are also ecs fields are written to the alert doc. ``` GET .internal.alerts-stack.alerts-default*/_search ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…documents for other ES Query rule types (elastic#230010) Resolves elastic#190947 ## Summary This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - I liked to use the sample data to test this. You can add it on the homepage ( The sample data logs will have a couple fields that will get written to the doc like message) - Create ES Query KQL and DSL rules. - Go to [dev tools](http://localhost:5601/app/dev_tools#/console) and run the query below to verify that the query results that are also ecs fields are written to the alert doc. ``` GET .internal.alerts-stack.alerts-default*/_search ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…documents for other ES Query rule types (elastic#230010) Resolves elastic#190947 ## Summary This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - I liked to use the sample data to test this. You can add it on the homepage ( The sample data logs will have a couple fields that will get written to the doc like message) - Create ES Query KQL and DSL rules. - Go to [dev tools](http://localhost:5601/app/dev_tools#/console) and run the query below to verify that the query results that are also ecs fields are written to the alert doc. ``` GET .internal.alerts-stack.alerts-default*/_search ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…documents for other ES Query rule types (#230010) Resolves #190947 ## Summary This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - I liked to use the sample data to test this. You can add it on the homepage ( The sample data logs will have a couple fields that will get written to the doc like message) - Create ES Query KQL and DSL rules. - Go to [dev tools](http://localhost:5601/app/dev_tools#/console) and run the query below to verify that the query results that are also ecs fields are written to the alert doc. ``` GET .internal.alerts-stack.alerts-default*/_search ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
… in the current alert (#235854) Follow on from #190947 ## Summary We noticed while testing this [PR](#230010), that we don't clear out source data when there are no hits returned in the next rule execution. This can happen when a user edits the ES Query rule size to be 0. This PR adds a new function to overwrite fields that aren't in the new payload with empty arrays if they were populated in the existing alert. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify 1. Use sample data or data that contains ECS fields 2. Create a KQL of DSL ES Query rule 3. Let the rule run and verify that the source data is populated in the alert doc. You can run this query below: ``` GET /.alerts-stack.alerts-default/_search ``` 4. Edit the rule and set the size to 0 5. Let the rule run again and verify that the source fields are set to empty arrays. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…documents for other ES Query rule types (elastic#230010) Resolves elastic#190947 ## Summary This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI. ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify - I liked to use the sample data to test this. You can add it on the homepage ( The sample data logs will have a couple fields that will get written to the doc like message) - Create ES Query KQL and DSL rules. - Go to [dev tools](http://localhost:5601/app/dev_tools#/console) and run the query below to verify that the query results that are also ecs fields are written to the alert doc. ``` GET .internal.alerts-stack.alerts-default*/_search ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
… in the current alert (elastic#235854) Follow on from elastic#190947 ## Summary We noticed while testing this [PR](elastic#230010), that we don't clear out source data when there are no hits returned in the next rule execution. This can happen when a user edits the ES Query rule size to be 0. This PR adds a new function to overwrite fields that aren't in the new payload with empty arrays if they were populated in the existing alert. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### To verify 1. Use sample data or data that contains ECS fields 2. Create a KQL of DSL ES Query rule 3. Let the rule run and verify that the source data is populated in the alert doc. You can run this query below: ``` GET /.alerts-stack.alerts-default/_search ``` 4. Edit the rule and set the size to 0 5. Let the rule run again and verify that the source fields are set to empty arrays. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Resolves #190947
Summary
This PR updates the all the es query rule types to automatically copy source data into the alerts-as-data documents, instead of asking the customer to select fields in the UI. This PR also removes the option to select source fields in the rule form UI.
Checklist
To verify