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][Cases] Re-enable timeline functionality #96496

Merged

Conversation

michaelolo24
Copy link
Contributor

@michaelolo24 michaelolo24 commented Apr 7, 2021

Summary

This PR reintroduces the functionality necessary for inserting timeline into cases via comments as well as encapsulating any UI timeline components. The views that utilize this functionality Create_Case and Case_Details now take in the below optional configuration. This logic will be able to be removed once timeline is moved into it's own plugin and we can import directly from there.

timelineIntegration?: {
	editor_plugins: {
		parsingPlugin,
		processingPluginRenderer,
		uiPlugin,
	},
	hooks: {
		useInsertTimeline,
	},
	ui?: {
		renderInvestigateInTimelineActionComponent,
		renderTimelineDetailsPanel,
	}

Checklist

@michaelolo24 michaelolo24 added v8.0.0 release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting Security Solution Threat Hunting Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.14.0 Theme: rac label obsolete Feature:Cases-RAC-UI labels Apr 7, 2021
@michaelolo24 michaelolo24 requested a review from a team as a code owner April 7, 2021 20:04
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@michaelolo24 michaelolo24 changed the title [Security Solution][Cases]add timeline functionality [Security Solution][Cases] Re-enable timeline functionality Apr 7, 2021
useInsertTimeline: jest.fn(),
},
ui: {
renderInvestigateInTimelineActionComponent: (alertIds: string[]) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

alertIds does not appear to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed, gracias

export interface CursorPosition {
start: number;
end: number;
}

export type TemporaryProcessingPluginsType = [
Copy link
Contributor

Choose a reason for hiding this comment

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

ohh i see weird

@cnasikas
Copy link
Member

cnasikas commented Apr 12, 2021

@michaelolo24 @stephmilovic @XavierM I am wondering why we need to pass the UI markdown plugins as a prop in this PR? Shouldn't cases handle all the markdown plugins internally? If we need other plugins to define their own markdown plugins in cases, then I think we need to provide a markdown plugin registry as the actions plugin does with their connectors. An advantage of this approach is that cases do not have to define any plugin dependency (such as lens) in kibana.json and in the StartPlugins inside plugin.ts A disadvantaged of allowing other plugins to register their own markdown plugins is SDH support handling. Who gonna own the markdown plugin and who gonna support it? Cases or the plugin that registered it?

@XavierM
Copy link
Contributor

XavierM commented Apr 12, 2021

@michaelolo24 @stephmilovic @XavierM I am wondering why we need to pass the UI markdown plugins as a prop in this PR? Shouldn't cases handle all the markdown plugins internally? If we need other plugins to define their own markdown plugins in cases, then I think we need to provide a markdown plugin registry as the actions plugin does with their connectors. An advantage of this approach is that cases do not have to define any plugin dependency (such as lens) in kibana.json and in the StartPlugins inside plugin.ts A disadvantaged of allowing other plugins to register their own markdown plugins is SDH support handling. Who gonna own the markdown plugin and who gonna support it? Cases or the plugin that registered it?

Let's discuss it, Also see another drawback with the registry that each time a plugin want to use case they will have to register an action for the EUI markdown, I think that will be annoying. I think for now I agree that cases should handle the markdown internally and maybe we should only pass props from security solution to have the functionality to attach a timeline.

@michaelolo24
Copy link
Contributor Author

@michaelolo24 @stephmilovic @XavierM I am wondering why we need to pass the UI markdown plugins as a prop in this PR? Shouldn't cases handle all the markdown plugins internally? If we need other plugins to define their own markdown plugins in cases, then I think we need to provide a markdown plugin registry as the actions plugin does with their connectors. An advantage of this approach is that cases do not have to define any plugin dependency (such as lens) in kibana.json and in the StartPlugins inside plugin.ts A disadvantaged of allowing other plugins to register their own markdown plugins is SDH support handling. Who gonna own the markdown plugin and who gonna support it? Cases or the plugin that registered it?

Let's discuss it, Also see another drawback with the registry that each time a plugin want to use case they will have to register an action for the EUI markdown, I think that will be annoying. I think for now I agree that cases should handle the markdown internally and maybe we should only pass props from security solution to have the functionality to attach a timeline.

Thanks @cnasikas & @XavierM, I'll update it to just pass down the timeline specific parts, rather than the whole plugins. Definitely cleaner that way. 👍🏾

@michaelolo24 michaelolo24 force-pushed the finish_timeline_integration branch from e205b8b to fb6d973 Compare April 12, 2021 20:53
useFetchAlertData={useFetchAlertData}
userCanCrud={userCanCrud}
/>
<CasesTimelineIntegrationProvider timelineIntegration={timelineIntegration}>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should only render the CasesTimelineIntegrationProvider if timelineIntegration exists? I know you have the logic further down the line, but why go further down the line if we know timelineIntegration does not exist?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because InsertTimeline always needs it? should we have a boolean where InsertTimeline is to render it or not depending on the timelineIntegration props? or is it simpler just to keep it as is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it would still work without the provider since all the useTimelineContext()'s can be the default value of null. So I could do something like below and it would still work, but nothing would really be functionally different. The only difference would be CasesTimelineIntegrationContext not showing up in the tree anymore. It may be simpler to just keep it as is for now?

CasesTimelineIntegrationProvider = ({ children, timelineIntegration }) => {
  const [activeTimelineIntegration] = useState(timelineIntegration ?? null);

  return activeTimelineIntegration ? (
    <CasesTimelineIntegrationContext.Provider value={activeTimelineIntegration}>
      {children}
    </CasesTimelineIntegrationContext.Provider>
  ) : (
    <>{children}</>
  );
};

useTimelineContext is used for InsertTimeline, but also all the editor plugin stuff, and the renderInvestigateInTimeline and renderTimelineDetailsPanel logic. Ideally once the timeline plugin is done we can just nuke all of that stuff. You can test it out by just setting the useState here to null:

https://github.com/elastic/kibana/pull/96496/files/94a75a11d4240237d5225db9ea8d1fb81591996d#diff-9610a1614eed5937c6929340eb693370c84e283a021bf51217b49bc477e1ffecR58

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i went in an passed null from create to see. im good w this

export const usePlugins = () => {
const timelinePlugins = useTimelineContext()?.editor_plugins;

return useMemo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if we should use useMemo here or not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can get rid of the useMemo, I'd just need to move all the getDefault* references out of the hook so a new reference isn't created every single time the hook is called because that caused an infinite loop to happen before 😂. I initially wanted to avoid mutating them as singleton's to guard against any weird bugs that may come up. For example, if someone was to navigate from the cases in one app instance that does have timeline enabled directly to cases in another app instance that doesn't have it enabled. New plugin instances would probably be created in that scenario depending on how navigation happens, but wanted to avoid potential bugs there.

Copy link
Contributor

Choose a reason for hiding this comment

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

then leave it, i dont want a bug! lol

Copy link
Contributor

@stephmilovic stephmilovic left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for your work on this one, I was definitely avoiding it 😂 rock n roll woohoo 🎸 🥁 🎺

@kibanamachine
Copy link
Contributor

💛 Build succeeded, but was flaky


Test Failures

Kibana Pipeline / general / Creates and activates a new EQL rule with a sequence.Detection rules, sequence EQL Creates and activates a new EQL rule with a sequence

Link to Jenkins

Stack Trace

Failed Tests Reporter:
  - Test has failed 7 times on tracked branches: https://github.com/elastic/kibana/issues/85691

AssertionError: Timed out retrying after 60000ms: Expected <span.euiLoadingContent> not to exist in the DOM, but it was continuously found.
    at Object.waitForAlertsPanelToBeLoaded (http://localhost:6121/__cypress/tests?p=cypress/integration/detection_rules/event_correlation_rule.spec.ts:21254:43)
    at Context.eval (http://localhost:6121/__cypress/tests?p=cypress/integration/detection_rules/event_correlation_rule.spec.ts:20314:18)

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [d2eaf3b]

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@michaelolo24 michaelolo24 merged commit 636524a into elastic:cases_rac_ui Apr 13, 2021
@michaelolo24 michaelolo24 deleted the finish_timeline_integration branch April 13, 2021 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting Security Solution Threat Hunting Team Theme: rac label obsolete v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants