-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
New "search alert" type based on ES dsl query and hit count #61313
Comments
Pinging @elastic/kibana-alerting-services (Team:Alerting Services) |
If this alert is going to have a complex input element - eg, query DSL, or perhaps even KQL - I wonder if we'd want to "hide" it in the places we allow customers to create connectors. Only allow it to be created in an app like discover, where we will won't have to deal with validating a complex input object. |
I think we should only allow saved search for this |
@dsztykman Am I right in thinking that by saved search you actually mean saved query? As for limiting this to Saved Queries - what do you see as the value in limiting alerts to a saved query? 🤔 For example, it would force the users to create noise in their saved queries list if they need to define a bunch of alerts. It also means we would create a coupling between a saved query and its underlying alert, which means a user might change the behaviour of an alert when they change a query without even knowing they're having that effect (unless we can somehow make this link explicit in Discover, but not sure how that would be done). Anyway, would love to hear your thoughts. :) |
Looking at how Discover supports both Lucene and KQL I don't see an obvious reason not to support both in the Alert Type. I'm even considering how we can best have the Alert Type mirror Discover (perhaps by building off of the types exposed by Discover so that they are truly linked), though that creates a coupling I'm not yet 100% sure about... bottom line, I think the Alert could, and probably should, support both Lucene and KQL. :) |
KQL is a bit limited in certain usage, and saved queries only apply for KQL, that's why I talked about saved search. |
Had a chat with @dsztykman and here are some notes from his feedback that are definitely worth keeping in mind: David's main concern is that if you don't use a saved search/query as the basis users can't verify that their search actually returns what they want. I explained the plan is to expose this as an action in Discover where you create an Alert based off of the current search, which addresses this. This does bring to light the need to have a chart (like in Index Threshold) that gives the user an idea of how many results their search currently returns. This raises a question worth asking: Do we want to offer the option in the flyout of creating an alert based on a saved search / query? |
Having alerts only on saved searches will be very limited, it is a struggle we have today with export to CSV. This will hide the alerting feature and will create many saved search objects that are not needed. Regarding saved queries, this is rather a new feature that has low usage. Ideally, users have an explicitly create an alert in Discover which is not tied to saved search or saved query. If it helps in the implementation you can maybe create a saved search or query in the background in user transparent way, for the sake of the alert. If saved query/search will be a mandatory step to create an alert I'm concerned we are going through the challenge we have with CSV If I had to choose I would focus on KQL first, since this is the default and close to 90% of the clusters are using KQL |
+1 Seems like this would be much easier for customers to deal with than query DSL anyway. I have an ESSQL based alert I was playing with a while back also - https://github.com/pmuellr/kbn-sample-plugins/blob/master/plugins/alert_type_examples/server/alert_types/essql.ts |
I'm looking into how we can use the underlying The advantage to this approach is that we would get a 1-to-1 match with how Discover runs it's queries, which means that whatever the user sees in the Discover UI, should match what the query in the Alert sees. This means that when the user hits this theoretical "Create Alert from Query" button, they should get a starting point which matches what Discover displays and can then do things like change the time range etc. It also means that changes that are made in Discover in the future, such as changes to the default params, would apply to the underlying Alerts as well and won't go out of sync. In terms of work needed this would mean:
Would love to hear thoughts from @elastic/kibana-alerting-services and @elastic/kibana-app-arch (as I think you own the Example PR of the changes we'd need to make in |
Exposing a scoped data plugin accessor like we do |
It's the plugin used by Discover to query. |
@gmmorris Looking at your PR, what you are describing sounds like what we are already doing here, where we register route handler context to provide scoped search: kibana/src/plugins/data/server/search/search_service.ts Lines 60 to 65 in a3ae104
However, it looks like you need the I wonder if it would be worth us providing an admin-scoped API as well via the router handler context? Or alternatively if we exported Anyway, @lukasolson knows more on our long-term plans for the data search service on the server so he might have a better answer to this question. |
Thanks @lukeelmers, I might not have explained this well enough, let me expand a bit: It's not that we're using the
As we're not using the admin scoped client, but rather a user scoped client that wasn't created via a route handler, this wouldn't help in this case. 😬
The thinking behind exposing the API that I added was that it provides the ability to create a scoped search using precisely the same code that creates it for the context. Using the same code means that even though these are two different entry points, they will always provide the same API and we shouldn't have any divergence in the future. While we could expose Would you still prefer to expose I hope that all makes sense. 😄
I spoke to @lukasolson last week and he generally seemed to support the direction I took, but there's always a chance I missed something. |
Thanks for clarifying @gmmorris! I misunderstood your use case. If you already talked with @lukasolson and he's on board, then no worries on my end 😄 |
… and uptime (#63489) Work on #61313 has revealed that we don't have amock for AlertServices, which creates coupling between us and any solution depending on us, which makes it harder to make changes in our own code. This PR adds mocks and uses them in SIEM, Monitoring and Uptime, so that we can make future changes without having to change outside solutions.
… and uptime (elastic#63489) Work on elastic#61313 has revealed that we don't have amock for AlertServices, which creates coupling between us and any solution depending on us, which makes it harder to make changes in our own code. This PR adds mocks and uses them in SIEM, Monitoring and Uptime, so that we can make future changes without having to change outside solutions.
…toring and uptime (#63489) (#63662) Work on #61313 has revealed that we don't have amock for AlertServices, which creates coupling between us and any solution depending on us, which makes it harder to make changes in our own code. This PR adds mocks and uses them in SIEM, Monitoring and Uptime, so that we can make future changes without having to change outside solutions.
I've spent the day trying to figure out how the pieces can fit together and I think I now have a mental model of what might work well. The direction I've been experimenting with is thus: The ES Query AlertType will essentially be parameterised with the following:
The benefit of this approach is that it should be straight forward to create an Alert directly from within Discover, as the format will match that of Saved Queries, and the matching documents seen in Discover should always match the ones seen in the alert. Imagine going from Discover to Alert and back to Discover, we'd be able to maintain a unified experience there, which I think is how we envisioned the original requirement. I think making additional work on this alert should wait for us to confirm this is the right direction and align with App-Arch to make sure we don't step on their toes with changes we'd need to make in the |
I'm going to try and get my local prototype PR to a stable enough point that it can express, more or less, how this might work. |
@gmmorris That sounds all very reasonable. That part with server side index patterns is really important, since I assume that's a bit larger change (one that has been on the list for a long time), and I agree that we can't proceed with this alert, before we don't have that. So I think it's worth talking to App Arch and clarify with them about planning around this. |
That seems like that could be nice as a way to boil down the query result into some "simple" variables that could then be used in action parameters. We should probably look at all the scripting options available in Watcher as potential candidates for this kind of capability. Eg, https://www.elastic.co/guide/en/elasticsearch/reference/current/transform.html |
🎉 🎉 🎉 🎉 That's awesome, thanks @ppisljar |
We get requests from customers asking for more data in the context variables from the existing alerts. In some cases, this isn't really practical because of the way the alert builds it's queries - and is likely going to be difficult to allow the customer a nice interface to specify what other data they want. The dsl query alert is of course pretty nicely setup for this, since the customer presumably will be able to create open-ended queries. Or at least that's the end goal. The next question is then - how do we make this data available to customers such that it can easily be used as context variables in actions. I'd guess we may need something like issue #77793 in some use cases, as it's hard to imagine doing much more than providing the raw query response in the context, which I'm guessing won't be easily usable within a mustache template. |
Please note Infra's needs over here: https://github.com/elastic/sre/issues/342 |
Watcher QueriesWatcher Search Input type supports:
When a watch is triggered, the input query determines what data is loaded in to the execution context (the payload). This payload is accessible during subsequent watch execution phases like evaluating the condition and firing actions using Watcher ConditionsWatcher allows users to specify conditions that determine whether an alert becomes active (and an action is executed).
|
Security solutions have two rule types that allow for custom KQL or Lucene queries Custom Query Rule TypeCustom Query rule type allows users to specify either a KQL or Lucene query. Both are converted into ES DSL in the alert executor (Lucene query is converted to the query string query). There is no ability to specify aggregations or conditions for this rule type. The implied condition is the existence of documents that match the query. Alerts (or alert instances as they're currently called inside the alerting framework) are the individual documents that match the query and actions are executed (at the specified action interval) when that number of documents exceeds 0. Threshold Rule TypeThreshold rule type builds up on the Custom Query rule type by allowing users to specify a field within the document to threshold against and a threshold value. Alerts (alert instances) are the individual documents that match the query and where the specified field exceeds the specified threshold value. |
There is nothing inherently preventing the usage of Painless scripts within the query DSL. A query like this should work out of the box
In the cited Watcher example, the Watch is using mustache templating to populate the query with user specified (static) metadata values. If we wanted to provide feature parity, we would need to provide a way for a user to specify generic metadata for the query and then template the search query in the alert executor. However, since the metadata fields are static, if we didn't provide this functionality the user would just need to manually inject the metadata into the query when creating the alert. |
I'm thinking something like this for the initial search alert type:
@arisonl @elastic/kibana-alerting-services Do you think this would be sufficient first step to start addressing the use cases you have seen for a search alert type? After this, we could look into adding aggregation support. At this point, we could
|
@ymao1 I gave your proposal a read and it looks good. Great analysis btw! The one piece I can see discussion on is how the alert instances are determined ( Is there potential of leveraging, merging, re-using the alert type(s) from the Security solution? It could be worth starting to merge the similar alert types to avoid having too many types that do the same thing. We could add a user option to chose what type of query (ES DSL, KQL, Lucense) they wants to do. This could give a few more options to the user for free 🙂 and vice-versa in SIEM in the future. |
@mikecote That's a good point that just having Re: re-using alert types/code
|
Gotcha, thanks! That makes sense with possibility of re-using / copying some code but overall we'd create a new alert type due to the other one being under the signals alert type. 👍 |
Correction on how the security solutions threshold rule type works. For this they are generating a single alert instance if the number of (de-duplicated) documents that match the query for the time range exceeds the threshold. In order to get the individual documents that matched, they re-construct the query based on information stored in the alert instance (signal) during the investigation phase. For overlapping alert intervals (for example, an alert that runs every minute, looking back 5 minutes each time, with a threshold of 50), this is what would happen:
|
@ymao1 Thanks for this analysis. Leaving aggregations initially out for the MVP is fine, but I suspect that to the users that are interested in the search alert, aggregations are important, so we should expect that we need to pick it up soon and plan accordingly. A couple of notes that may worth pointing out in this context. Not requirements for this story, rather for your and @mikecote's consideration, as we are thinking through this and its next steps. Users often need to be able to interact with the search result for the purposes of:
|
Follow on issues created:
|
There is value for an alert to be purely working with ES DSL query and alerts on data returned.
Things to investigate:
--examples
flag or POC to integrate with console app--examples
flag or POC to integrate with discover app (see Proof of concept integrating "search alert" with discover #61314)The text was updated successfully, but these errors were encountered: