Skip to content
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

[Security Solution] Adhoc views in sourcerer #208372

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

lgestc
Copy link
Contributor

@lgestc lgestc commented Jan 27, 2025

Summary

Fixes #201847

Up until now, whenever we were not able to identify the Data View to switch sourcerer to based on required patterns,
we would update the Default Security Solution data view with missing patterns, effectively altering the advanced setting.

This PR introduces basic Adhoc Data View fallback for cases like that, where when we are missing the pattern, the in-memory data view is created (not persisted as SO) that has required patterns configured in it.

The user is informed with some badge that this happened, and will be able to pick some other, existing data view instead if they wish.

Screenshot 2025-02-03 at 10 21 40

Testing

  • Create a timeline and save it
  • Update the advanced settings by removing an index pattern.
  • Re-visit the saved timeline and refresh
  • Find the update message saying the dataview needs to be updated with the index pattern that was just removed.
  • Click update, and find that the advanced setting default index has been modified.

In short, any time there is a mismatch between a saved set of index patterns and the advanced setting (as it is would be in any timelines saved prior to the advanced setting change), then it will deem the data view to need an 'update', which when clicked, will then re-add those indices to the default index in the advanced settings.

Alternatively,
To test: save this json as a timelines.ndjson file and upload the timelines to the timelines page in security solution

@lgestc lgestc mentioned this pull request Jan 27, 2025
9 tasks
@lgestc lgestc force-pushed the adhoc_views_in_sourcerer branch from 358ae5f to 36a9386 Compare February 3, 2025 09:29
@lgestc lgestc force-pushed the adhoc_views_in_sourcerer branch from 26e89a9 to 8ab8c15 Compare February 3, 2025 12:32
@elastic elastic deleted a comment from elasticmachine Feb 3, 2025
@elastic elastic deleted a comment from elasticmachine Feb 3, 2025
Copy link
Member

@jbudz jbudz left a comment

Choose a reason for hiding this comment

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

packages/kbn-babel-preset/styled_components_files.js LGTM

@elastic elastic deleted a comment from elasticmachine Feb 5, 2025
Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

Did a code review. Left some thoughts ( not necessary ask for change ) which we can discuss more.

Doing desk testing and will report back.

@@ -62,6 +62,7 @@ export const validateSelectedPatterns = (
const dedupeAllDefaultPatterns = ensurePatternFormat(
(dataView ?? state.defaultDataView).title.split(',')
);
// TODO: If we having missing patterns here, just create a new dataView...don't worry about missingPatterns anymore...
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this is leftover or still to be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I will remove it. thanks

@@ -29,7 +29,7 @@ interface UsePickIndexPatternsProps {
signalIndexName: string | null;
}

export type ModifiedTypes = 'modified' | 'alerts' | 'deprecated' | 'missingPatterns' | '';
export type ModifiedTypes = 'modified' | 'alerts' | 'deprecated' | 'missingPatterns' | 'adhoc' | '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Couldn't it be renamed to be more meaningful. I am not sure what does ModifiedTypes indicate.

Maybe DataviewModificationTypes?

Comment on lines +17 to +20
/**
* Missing patterns that need to be wrapped in an adhoc adhocDataView
*/
missingPatterns: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean these patterns should be included in the adhoc view?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, will update the docs. thank you

const { addError } = useAppToasts();

const createAdhocDataView = useCallback(
async (missingPatterns: string[]): Promise<DataView | null> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Does it makes sense to rename missingPatterns to patterns?

From the perspective of createAdhocDataView, missingPatterns does not mean anything. It only cares about the patterns.

I say this so that useCreateAdhocDataView can also be used in some other context apart from missingPatterns?

expect(onApplyFallbackDataView).toHaveBeenCalledWith('mock', ['pattern1', 'pattern2'], false);
expect(onApplyFallbackDataView).toHaveBeenCalledTimes(1);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider testing onResolveErrorManually as well.

},
};

export const TemporarySourcererComp = React.memo<Props>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please give a little background on what was this TemporarySourcererComp and why is it now removed?

@@ -106,36 +102,36 @@ describe('No data', () => {
});

test('Hide sourcerer - default ', () => {
const wrapper = mount(
render(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for converting this file to RTL ✨ ✨

});
});

describe('Update available', () => {
const state2 = {
describe('Compat mode', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Compat mode does not convey much in terms of what is happening to the data view. Thinking out loud some options can be.

  • Updated
    • Can be accompanied with a call out what Updated means.
  • Adhoc
    • Considering our customers already know what Adhoc dataviews are.
  • Timeline - Most Preferable imo
    • We always create an ad-hoc view with the name Security Solution Dataview (Timeline) which is either copy of the original data view or updated with missing patterns. From user's perspective, it does not matter. It will always be the same.

What do you think? I would like opinion of @michaelolo24 on it as well. It might also make sense to involve design as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't event include Security Solution Dataview as I think that would be too close to what we already have and confuse users into thinking they can modify it in the advanced settings or something. I would be interested to see how Discover handles this problem, but IMO we could do some thing close to what @logeekal mentioned here like:

Timeline Temporary Dataview or Timeline Unpersisted Dataview. I lean towards stating exactly what's happening.

isTriggerDisabled={isTriggerDisabled}
isModified={isModified}
isTriggerDisabled={false}
isModified={modificationStatus}
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was here before but isModified looks like a boolean but is actually a modificationStatus 🤣

Copy link
Contributor

@logeekal logeekal left a comment

Choose a reason for hiding this comment

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

Desk Testing Observations

So I did Desk testing for this and i am encountering 3 issues. I am not sure if I am doing anything wrong here. Below is the demo and my observations

Observations

  1. ✅ Compat Mode appeared as expected when there are some missing patterns in defaultIndex
  2. When in compat mode, field selector keeps spinning and never finds the fields.
  3. There is no dataview selected in the dropdown. IMO we should select the Adhoc dataview and name it as well so that there is no confusion on UX front.
  4. Edited Later - If you notice in the demo video, the unified field list keeps on loading as well.

Demo

Screen.Recording.2025-02-06.at.13.56.07.mov

@lgestc
Copy link
Contributor Author

lgestc commented Feb 7, 2025

Desk Testing Observations

So I did Desk testing for this and i am encountering 3 issues. I am not sure if I am doing anything wrong here. Below is the demo and my observations

Observations

  1. ✅ Compat Mode appeared as expected when there are some missing patterns in defaultIndex
  2. When in compat mode, field selector keeps spinning and never finds the fields.
  3. There is no dataview selected in the dropdown. IMO we should select the Adhoc dataview and name it as well so that there is no confusion on UX front.

Demo

Screen.Recording.2025-02-06.at.13.56.07.mov

Thank you @logeekal , I will look into point #2, as for #3 - there is a change in the making on how we display the dataviews, and it will include proper listing for the adhoc thing - in a separate PR. Reason being this one would end up being 40 files long again. Wording, labels etc - all subject to change. Counting on @michaelolo24 here, also @paulewing - Jatin made some good suggestions about the label we could use insead of "Compat mode", liked the "Timeline" best but not sure if the case for missing patterns is just about the Timeline :D

@lgestc lgestc marked this pull request as draft February 7, 2025 09:24
@elasticmachine
Copy link
Contributor

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!

@logeekal
Copy link
Contributor

logeekal commented Feb 7, 2025

@lgestc ,

Thanks for your comment. In my previous comment, I added a 4th point which I missed earlier.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6695 6692 -3

Async chunks

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

id before after diff
securitySolution 21.4MB 21.4MB -7.8KB

History

@lgestc lgestc force-pushed the adhoc_views_in_sourcerer branch from 3ac12ed to b40c747 Compare February 7, 2025 10:44
@lgestc
Copy link
Contributor Author

lgestc commented Feb 7, 2025

just found an issue, field mapping seems to be missing

);
setIsTriggerDisabled(true);
dispatchChangeDataView(dataView.id, dataView.title?.split(',') || [], false, dataView);
setDataViewId(dataView.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is additional work, but I think we should be pulling the dataViewId from sourcerer state rather than relying on some mix of local and redux state here 🤔. I wonder if we're seeing any bugs because of this...

@michaelolo24
Copy link
Contributor

When testing based on the original logic defined here: #120022 , I noticed a few things (to not re-iterate any of @logeekal 's points)

  1. When loading a timeline with an adhoc dataview, we don't show all available dataviews in the dropdown list, sometimes we don't even show the dataview picker...
image
  1. If sourcerer is in a bad state (i.e. from number # 1 above, then that state is persisted across all timelines opened...) The dropdown selector was missing for timeline templates when I opened them after # 1:
image
  1. When navigating away from the security page with a timeline with an adhoc dv and navigating back, errors are thrown that the dataview can't be found:
image
  1. Clicking show detection only and the unselecting it doesn't return you to the adhoc dataview you were on before, it just resets you to the security default dataview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
9.0 candidate backport:skip This commit does not require backporting Feature:Sourcerer Security Solution Sourcerer feature release_note:enhancement Team:Threat Hunting:Investigations Security Solution Investigations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution][Sourcerer] - Prevent setting update from solution component
6 participants