Skip to content

[Security Solution][Sourcerer] Maintain url sync support #221737

Merged
lgestc merged 20 commits intoelastic:mainfrom
lgestc:support_url_sync
Jun 3, 2025
Merged

[Security Solution][Sourcerer] Maintain url sync support #221737
lgestc merged 20 commits intoelastic:mainfrom
lgestc:support_url_sync

Conversation

@lgestc
Copy link
Copy Markdown
Contributor

@lgestc lgestc commented May 28, 2025

Summary

Sourcerer supports url sync for its state, and we should have the same thing working for the new data view picker.
This PR maintains that and makes sure that we are not calling the update logic twice when the feature is off.
It also prevent race conditions - only the last selection will be applied to the picker in case of multiple dispatches within short time frames (eg. during app init).

One known issue: you might see a flash during app init related to data views switching after being restored from the url. This is tracked in a separate ticket.

Testing

With the feature flag on:

xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']

Data View Manager state should be persisted and restored to/from the url the same way it works with Sourcerer.

Eg: navigate to explore pages, change the data view to 'metrics' for example. Refreshing the page should render the metrics data view selected again.

Checklist

@lgestc lgestc requested review from a team as code owners May 28, 2025 08:19
@lgestc lgestc added 9.1 candidate v9.1.0 release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Team:Threat Hunting:Investigations Security Solution Threat Hunting Investigations Team Feature:Sourcerer labels May 28, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-threat-hunting-investigations (Team:Threat Hunting:Investigations)

export const URL_PARAM_KEY = {
appQuery: 'query',
/** @deprecated */
eventFlyout: 'eventFlyout', // TODO remove when we assume it's been long enough that all users should use the newer `flyout` key
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhilippeOberti,do we have telemetry?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm I know we added telemetry when users open the flyout, but I don't think it logs what's in the url. Can't we just retrieve url information from Kibana telemetry? We should be able to query and see if any of the url we log contain the eventFlyout param?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR I think but I can remove it if you want.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, unrelated, but didn't want this to stay in forever. No need to remove here, just wanted to call attention to it so we could remove it later


// Select data view for specific scope, based on the UrlParam.
(Object.keys(initialState) as SourcererScopeName[]).forEach((scope) => {
// NOTE: looks like this is about skipping the init when the active page is detections
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not just detections, but the explore pages as well. If it helps, I believe this was to account for timeline as the sourcerer state for that would've been handled in the timeline slice of useUrlState.

This is how the code was: https://github.com/elastic/kibana/blob/8.2/x-pack/plugins/security_solution/public/common/components/url_state/helpers.ts

And this is an old example of how it was structured: #123617

@michaelolo24
Copy link
Copy Markdown
Contributor

The PR looks good for the most part, only a couple things:

  1. It looks like the persisted dataview selection for timeline is being overridden. So if you save a timeline with a different dataview selected (i.e. metrics-*), when you go to a new tab with that same url, the timeline opens with the default dataview selected. That might not have to do with the changes you've made here though.

  2. Less crucial, but this error is showing up in the console, but most likely due to the logic for sourcerer still running

image

@lgestc
Copy link
Copy Markdown
Contributor Author

lgestc commented May 30, 2025

The PR looks good for the most part, only a couple things:

  1. It looks like the persisted dataview selection for timeline is being overridden. So if you save a timeline with a different dataview selected (i.e. metrics-*), when you go to a new tab with that same url, the timeline opens with the default dataview selected. That might not have to do with the changes you've made here though.
  2. Less crucial, but this error is showing up in the console, but most likely due to the logic for sourcerer still running
image

looks like I have fixed the first thing, as for the 2nd one, this is just a warning and we cannot do anything about it yet. will go away after we only do a single init vs two :)

@lgestc
Copy link
Copy Markdown
Contributor Author

lgestc commented Jun 2, 2025

The PR looks good for the most part, only a couple things:

  1. It looks like the persisted dataview selection for timeline is being overridden. So if you save a timeline with a different dataview selected (i.e. metrics-*), when you go to a new tab with that same url, the timeline opens with the default dataview selected. That might not have to do with the changes you've made here though.
  2. Less crucial, but this error is showing up in the console, but most likely due to the logic for sourcerer still running
image

@michaelolo24 data view manager uses url sourced state first, with default selections applied as fallback. race conditions should not be possible after the changes.

@elastic elastic deleted a comment from elasticmachine Jun 2, 2025
(id: string, indexPattern: string = '') => {
selectDataView({ id, scope });

if (isDefaultSourcerer) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but defaultSourcerer is vague, but I'm not sure what to rename it to or how to classify the other scopes of timeline,analyzer, and the detections page 🤔 . Anyways, just wanted to bring it up for discussion separately

expect(initDataViewSelection).not.toHaveBeenCalled();
});

it('should call initDataViewSelection for each scope if newDataViewPickerEnabled is true', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, but I would have this map over all of the available scopes, rather than just 2

// Select data view for specific scope, based on the UrlParam.
const urlBasedSelection = (Object.keys(initialState) as SourcererScopeName[])
.map((scope) => {
// NOTE: looks like this is about skipping the init when the active page is detections
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾

}

// Cancel effects running for the current scope to prevent race conditions
listenerApi.cancelActiveListeners();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾 Thanks

}
},
init: (state) => {
init: (state, _action: PayloadAction<SelectDataViewAsyncPayload[]>) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the _action reference here necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is where the type information is sourced from, but made it shorter.

Copy link
Copy Markdown
Contributor

@michaelolo24 michaelolo24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good and the race conditions seem to be resolved, but will do additional testing over the next few weeks off of main. Had a few more comments here, but all in all the PR looks good. Nice work! 👍🏾

@lgestc lgestc enabled auto-merge (squash) June 3, 2025 06:41
@lgestc lgestc merged commit f8ad8a3 into elastic:main Jun 3, 2025
10 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 7453 7455 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 9.2MB 9.2MB +1.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 88.5KB 88.5KB +2.0B
Unknown metric groups

References to deprecated APIs

id before after diff
securitySolution 337 339 +2

History

zacharyparikh pushed a commit to zacharyparikh/kibana that referenced this pull request Jun 4, 2025
)

## Summary

Sourcerer supports url sync for its state, and we should have the same
thing working for the new data view picker.
This PR maintains that and makes sure that we are not calling the update
logic twice when the feature is off.

One known issue: you might see a flash during app init related to data
views switching after being restored from the url. This is tracked in a
separate ticket.

## Testing

With the feature flag on:

```
xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']
```

Data View Manager state should be persisted and restored to/from the url
the same way it works with Sourcerer.

Eg: navigate to explore pages, change the data view to 'metrics' for
example. Refreshing the page should render the metrics data view
selected again.


### Checklist
- [x] [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
christineweng pushed a commit to christineweng/kibana that referenced this pull request Jun 6, 2025
)

## Summary

Sourcerer supports url sync for its state, and we should have the same
thing working for the new data view picker.
This PR maintains that and makes sure that we are not calling the update
logic twice when the feature is off.

One known issue: you might see a flash during app init related to data
views switching after being restored from the url. This is tracked in a
separate ticket.

## Testing

With the feature flag on:

```
xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']
```

Data View Manager state should be persisted and restored to/from the url
the same way it works with Sourcerer.

Eg: navigate to explore pages, change the data view to 'metrics' for
example. Refreshing the page should render the metrics data view
selected again.


### Checklist
- [x] [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
christineweng added a commit that referenced this pull request Jun 10, 2025
… Data View Picker (#210585) (#223044)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Security Solution][Sourcerer] Replace Sourcerer with Discover Data
View Picker (#210585)](#210585)
- [[Security Solution] Rename use_data_view to use_data_view_spec
#216461](#216461)
- [[Security Solution] Rename use full data view hook
#216614](#216614)
- [[Security Solution] Replace sourcerer in global header
#216685](#216685)
- [[Security Solution] Remove .title use in use_selected_patterns
#216994](#216994)
- [[Security Solution] Render default security solution data view with
managed label #216961](#216961)
- [[Security Solution] Replace sourcerer in analyzer
#218183](#218183)
- [[Security Solution] Replace use_sourcerer_data_view
#216997](#216997)
- [[Security Solution] Replace sourcerer in EQL tab with dataview picker
#218897](#218897)
- [[Security Solution][Sourcerer] replace use get scoped data view
#220196](#220196)
- [[Security Solution] renaming dataView to dataViewSpec and adding
types for clarity
#220718](#220718)
- [[Security Solution][Sourcerer] Maintain url sync support
#221737](#221737)
- [[Security Solution][Data View Manager] Allow passing data view to
query bar #220585](#220585)
- [[Security Solution] Fix data view picker privilege
#222122](#222122)



<!--- Backport version: 10.0.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Luke
Gmys","email":"11671118+lgestc@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-31T12:12:57Z","message":"[Security
Solution][Sourcerer] Replace Sourcerer with Discover Data View Picker
(#210585)\n\n# Unified Data View Picker: Phase 1 Implementation\nPart of
https://github.com/elastic/security-team/issues/11959\n\n## What This PR
Does\nThis PR represents the first step in our transition from the
current\nSourcerer component to the new unified Data View Picker.
Specifically,\nthis implementation:\n- Creates a new Data View Picker
component\n- Implements feature flag protection for all changes\n-
Handles asynchronous effects through Redux listener middleware\n-
Establishes a new Redux store architecture to support ad hoc data\nviews
infrastructure\n- Utilizes ad hoc data views to handle legacy patterns
from series 7\n(replacing the previous upgrade data view flow)\n\nSee
the readme for more info:
\n```x-pack/solutions/security/plugins/security_solution/public/data_view_manager/readme.md```\n\n##
What This PR Does NOT Cover\n- Does not affect screens other than
Timelines\n- Does not modify the existing Sourcerer component in any
way\n- Does not fully support all URL/local storage patterns\n\n##
Implementation Notes\nWe've made several accommodations to support both
Sourcerer and the new Data View Picker simultaneously during this
transition period, including:\n- Some interfaces might look odd,
especially the hooks that return the data view or patterns - this is
intentional to support existing use cases\n- There are feature
flag-based conditional statements throughout the code that will be
removed once the transition is complete\n\n## Testing Instructions\n1.
Add the following feature flag to your configuration:\n ```\n
xpack.securitySolution.enableExperimental:
['newDataViewPickerEnabled']\n ```\n2. Navigate to the Timelines
interface\n3. Test interactions with the new Data View
Picker\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9679f2941550856d75e00c1faadd8c9669afe917","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","backport:skip","Team:
SecuritySolution","Team:Threat
Hunting:Investigations","Feature:Sourcerer","9.1
candidate","v9.1.0"],"title":"[Security Solution][Sourcerer] Replace
Sourcerer with Discover Data View
Picker","number":210585,"url":"https://github.com/elastic/kibana/pull/210585","mergeCommit":{"message":"[Security
Solution][Sourcerer] Replace Sourcerer with Discover Data View Picker
(#210585)\n\n# Unified Data View Picker: Phase 1 Implementation\nPart of
https://github.com/elastic/security-team/issues/11959\n\n## What This PR
Does\nThis PR represents the first step in our transition from the
current\nSourcerer component to the new unified Data View Picker.
Specifically,\nthis implementation:\n- Creates a new Data View Picker
component\n- Implements feature flag protection for all changes\n-
Handles asynchronous effects through Redux listener middleware\n-
Establishes a new Redux store architecture to support ad hoc data\nviews
infrastructure\n- Utilizes ad hoc data views to handle legacy patterns
from series 7\n(replacing the previous upgrade data view flow)\n\nSee
the readme for more info:
\n```x-pack/solutions/security/plugins/security_solution/public/data_view_manager/readme.md```\n\n##
What This PR Does NOT Cover\n- Does not affect screens other than
Timelines\n- Does not modify the existing Sourcerer component in any
way\n- Does not fully support all URL/local storage patterns\n\n##
Implementation Notes\nWe've made several accommodations to support both
Sourcerer and the new Data View Picker simultaneously during this
transition period, including:\n- Some interfaces might look odd,
especially the hooks that return the data view or patterns - this is
intentional to support existing use cases\n- There are feature
flag-based conditional statements throughout the code that will be
removed once the transition is complete\n\n## Testing Instructions\n1.
Add the following feature flag to your configuration:\n ```\n
xpack.securitySolution.enableExperimental:
['newDataViewPickerEnabled']\n ```\n2. Navigate to the Timelines
interface\n3. Test interactions with the new Data View
Picker\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9679f2941550856d75e00c1faadd8c9669afe917"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210585","number":210585,"mergeCommit":{"message":"[Security
Solution][Sourcerer] Replace Sourcerer with Discover Data View Picker
(#210585)\n\n# Unified Data View Picker: Phase 1 Implementation\nPart of
https://github.com/elastic/security-team/issues/11959\n\n## What This PR
Does\nThis PR represents the first step in our transition from the
current\nSourcerer component to the new unified Data View Picker.
Specifically,\nthis implementation:\n- Creates a new Data View Picker
component\n- Implements feature flag protection for all changes\n-
Handles asynchronous effects through Redux listener middleware\n-
Establishes a new Redux store architecture to support ad hoc data\nviews
infrastructure\n- Utilizes ad hoc data views to handle legacy patterns
from series 7\n(replacing the previous upgrade data view flow)\n\nSee
the readme for more info:
\n```x-pack/solutions/security/plugins/security_solution/public/data_view_manager/readme.md```\n\n##
What This PR Does NOT Cover\n- Does not affect screens other than
Timelines\n- Does not modify the existing Sourcerer component in any
way\n- Does not fully support all URL/local storage patterns\n\n##
Implementation Notes\nWe've made several accommodations to support both
Sourcerer and the new Data View Picker simultaneously during this
transition period, including:\n- Some interfaces might look odd,
especially the hooks that return the data view or patterns - this is
intentional to support existing use cases\n- There are feature
flag-based conditional statements throughout the code that will be
removed once the transition is complete\n\n## Testing Instructions\n1.
Add the following feature flag to your configuration:\n ```\n
xpack.securitySolution.enableExperimental:
['newDataViewPickerEnabled']\n ```\n2. Navigate to the Timelines
interface\n3. Test interactions with the new Data View
Picker\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"9679f2941550856d75e00c1faadd8c9669afe917"}}]}]
BACKPORT-->

---------

Co-authored-by: Luke Gmys <11671118+lgestc@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Philippe Oberti <philippe.oberti@elastic.co>
nickpeihl pushed a commit to nickpeihl/kibana that referenced this pull request Jun 12, 2025
)

## Summary

Sourcerer supports url sync for its state, and we should have the same
thing working for the new data view picker.
This PR maintains that and makes sure that we are not calling the update
logic twice when the feature is off.

One known issue: you might see a flash during app init related to data
views switching after being restored from the url. This is tracked in a
separate ticket.

## Testing

With the feature flag on:

```
xpack.securitySolution.enableExperimental: ['newDataViewPickerEnabled']
```

Data View Manager state should be persisted and restored to/from the url
the same way it works with Sourcerer.

Eg: navigate to explore pages, change the data view to 'metrics' for
example. Refreshing the page should render the metrics data view
selected again.


### Checklist
- [x] [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

9.1 candidate backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Investigations Security Solution Threat Hunting Investigations Team v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants