[Security Solution][Platform] Standardize & Document methods for updating Global Query State #130068
Labels
chore
enhancement
New value added to drive a business result
Team:Detection Engine
Security Solution Detection Engine Area
Team: SecuritySolution
Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
triage_needed
Summary
As a byproduct of the recent Rule Execution Log work (#128843 (comment)), I needed the ability to store and reload the global query state, which includes the
KQL Bar Query String
,Filter Bar Filters
, and the currentSuperDatePicker
state. (Tangentially, please see this ER for addingQuery History
to the unified search component)This used to be fairly straightforward as all state was managed within Redux and we have a slew of selectors over in store/inputs/selectors.ts and corresponding actions over in store/inputs/actions.ts that could be used for either getting/setting the
Global Security Solution Query State
or any specificTimeline Query State
.In attempting to use these selectors/actions I ran into a few issues, for which this enhancement/chore is intended to improve.
Confusion as when to use the Security Redux selectors/actions vs the
useKibana()
'sfilterManager
,queryString
, andtimefilter
accessors coming from the data plugin's queryService. I originally started using our Redux selectors/actions (as there could be other application hooks listening for changes here) , however I ran into issues with clearing/resettingFilters
via the setSearchBarFilters() action as it wouldn't actually clear theFilters
, but would rather only append them. 🤔 I ended up getting this to work by leveraging thefilterManager
and switching from:to:
Using the
data plugin's queryService
hasn't always been possible, but has become available since we've switched to using the data plugin's query bar sometime in mid7.x
.Since there's no real documentation around these API's, the best way to figure out the most up-to-date methods of using them is from searching through code usages. There has been some change with the introduction of the
useSelector
hook, and now theuseShallowEqualSelector
anduseDeepEqualSelector
wrappers. With no documentation here though, it's not entirely clear when you should use one over the other (presumably primitives vs objects as with any diffing) and what performance consideration you may want to take into account if using theuseDeepEqualSelector
on larger object trees. FWIW, most folks are using thedeepEqual
(120 matches) over theshallowEqual
(29 matches), and there's probably a few uses like this one that could be switched over toshallowEqual
to prevent unnecessary renderings.Additionally, there's inconsistency in how
inputsSelectors
are used as well. Most usages will memoize the inputSelector, however there are some likeinputsSelectors.globalTimeRangeSelector
which are just used as-is wrapped byuseDeepEqualSelector
. Guidance in documentation around usage here would be beneficial in preventing folks from just copying one usage to another without understanding the tradeoffs.Here's example code of what it looks like to initialize all the necessary objects to read/write from these three fields within the Global Query State:
Ideally, some TLC to these Redux actions/selectors, and adding JSDoc's and some corresponding Developer documentation over on docs.elastic.dev would go a long way in helping Security Solution devs discover these API's, and how/when to use them. Please feel free to reach out if there are any questions with the above, happy to go into more details if that's helpful -- thanks! 🙂
The text was updated successfully, but these errors were encountered: