[Security Solution][Detections] Discuss: EQL search strategy#78107
[Security Solution][Detections] Discuss: EQL search strategy#78107rylnd wants to merge 1 commit intoelastic:masterfrom
Conversation
* Attempts to extend ISearchStrategy to allow EQL requests and responses * Since the ES search response is incompatible with the EQL Search response, we can either try to merge them into one generic type, or allow two paths for responses. We're currently on track for the latter. There are several issues here, the most pressing of which is licensing.
| export const isEsResponse = (response: any): response is IEsSearchResponse => | ||
| response && response.rawResponse; | ||
|
|
||
| export interface EqlSearchResponse<T> { |
There was a problem hiding this comment.
I don't believe that this type exists in the elasticsearch package, or at least I couldn't find it: the EQL client is currently typed to return an ApiResponse which makes no assumptions about the response body.
| params?: ISearchRequestParams; | ||
| export interface IEsSearchRequest<T = Record<string, any>, P = ISearchRequestParams<T>> | ||
| extends IKibanaSearchRequest { | ||
| params?: P; |
There was a problem hiding this comment.
This allows us to override params for EqlSearchStrategyRequest below to be those required by the EQL search endpoint.
| import { Timeline } from './timeline/saved_object'; | ||
| import { TLS } from './tls'; | ||
| import { MatrixHistogram } from './matrix_histogram'; | ||
| import { SearchTypes } from './detection_engine/signals/types'; |
There was a problem hiding this comment.
Ignore this file's changes; these new EQL typings are temporarily duplicated in both the security_solution and data plugins.
| }; | ||
|
|
||
| export const securityEqlSearchStrategyProvider = ( | ||
| logger: Logger |
There was a problem hiding this comment.
We're not yet pulling configuration here as I wasn't sure which options (if any) were relevant to EQL queries.
💔 Build Failed
Failed CI StepsTest FailuresX-Pack APM API integration tests (basic).x-pack/test/apm_api_integration/basic/tests/metrics_charts/metrics_charts·ts.APM specs (basic) Metrics when data is loaded for opbeans-node returns metrics data CPU usage has correct series overall valuesStandard OutStack TraceBuild metricsdistributable file count
To update your PR or re-run it, just comment with: |
| rawResponse: { | ||
| ...response.body, | ||
| ...dummyResponseFields, | ||
| }, | ||
| rawEqlResponse: response.body, |
There was a problem hiding this comment.
| rawResponse: { | |
| ...response.body, | |
| ...dummyResponseFields, | |
| }, | |
| rawEqlResponse: response.body, | |
| rawResponse: response.body |
Applying the above change should reveal the incompatibilities between the expected SearchResponse type and our (currently unofficial) EqlSearchResponse type. To name a few, EQL responses are missing _shards, and hits has no max_score. Additionally, hits does not have its own hits field, but instead has either events or sequences depending on the query's syntax.
I've temporarily satisfied typescript by adding these dummy fields to satisfy IEsSearchResponse['rawResponse'], and added another field to hold our "true" EQL response.
We could address this in a few ways: loosen IEsSearchResponse to require the minimal subset of fields (took, timed_out, etc.), give it a conditional type, or diverge from ISearchStrategy entirely. Guidance on a path forward here would be greatly appreciated.
|
|
||
| export const securityEqlSearchStrategyProvider = ( | ||
| logger: Logger | ||
| ): ISearchStrategy<EqlSearchStrategyRequest, EqlSearchStrategyResponse> => { |
There was a problem hiding this comment.
I think this is just an oversight, but one other thing I noticed is that while registerSearchStrategy is generic, getSearchStrategy is not and so consumers of divergent search strategies would have to assert their strategy's typings, lest they get a IEsSearchStrategy<any>
| */ | ||
| isPartial?: boolean; | ||
| rawResponse: SearchResponse<Source>; | ||
| rawResponse: SearchResponse<T>; |
There was a problem hiding this comment.
The only response arguments the search infrastructure cares about are:
id- the async search ID provided by elasticsearchisRunningandisPartialwhich are indicators of the search's execution in ES.tookandtotal_hitsfor telemetry and potentially any additional meta data about the request's execution.
Otherwise, the response can be completely generic, so we could create a new type for rawResponse (EsSearch response is specific to the ES strategy).
| depsStart.data | ||
| ); | ||
|
|
||
| plugins.data.search.registerSearchStrategy(SECURITY_EQL_SEARCH_STRATEGY, eqlSearchStrategy); |
There was a problem hiding this comment.
If the strategy is owned by the data plugin, it should be registered there too
There was a problem hiding this comment.
@lizozom since EQL is only available in x-pack, should this strategy live in the data_enhanced plugin for now?
|
I've made this PR to make the search types more generic. It enables you to define I also added generic typing to both Please let me know if it helps. Maybe you want to rebase this PR on top of that one and give it a try? |
|
@lizozom thanks so much for these improvements, they're working great. I'm probably going to just close this PR since it'll need to be rebased on both your work and my own outstanding PR (#77493). In the meantime, I have a working branch that integrates all three pieces on my fork: rylnd#5. It's currently targeting (a local copy of) your branch, so you can see what the implementation on top of that looks like right now. Since the implementation is pretty straightforward I don't I need any more cursory review at this point (but correct me if you disagree). While I finalize the async search workflow and add the default search configuration, there's one outstanding question we need to answer: Since EQL is only supported in x-pack, can/should this strategy live in the |
|
@rylnd Regarding your question: |
|
Closing this in favor of #78645. |
This adds a basic implementation for an EQL search strategy. This is meant to start a conversation; there are still several issues to address, which I've annotated inline below.
General issues:
SearchResponseprovided by elasticsearch.Checklist
For maintainers