Skip to content

[Security Solution][Attacks/Alerts][Attacks page] KQL section (#232592)#242772

Closed
e40pud wants to merge 2 commits intoelastic:mainfrom
e40pud:security/attack-alerts-alignment/232592-kql-bar
Closed

[Security Solution][Attacks/Alerts][Attacks page] KQL section (#232592)#242772
e40pud wants to merge 2 commits intoelastic:mainfrom
e40pud:security/attack-alerts-alignment/232592-kql-bar

Conversation

@e40pud
Copy link
Copy Markdown
Contributor

@e40pud e40pud commented Nov 12, 2025

Summary

Epic: #232569
Closes #232592

These changes add a KQL search bar to the new Attacks page.

NOTE: at the moment the seqch bar connectoed to the SourcererScopeName.detections data view and will be updated to SourcererScopeName.attacks in a separate PR #242475.

Feature Flag

Note

The feature is hidden behind the feature flag (in kibana.dev.yml):

feature_flags.overrides:
  securitySolution.attacksAlertsAlignment: true

Other changes

  • SearchBarSection is now a shared component placed in the detections/components/common folder. It is used on both Alerts and Attacks pages.
  • DetectionsWrapper a new shared component to wrap page loading, error handling and data view fetching logic. It is used on both Alerts and Attacks pages.
  • useDetectionsDataView a new hook to encapsulate data view and runtime fields retrieval logic by the scope name. It is used on both Alerts and Attacks pages via the DetectionsWrapper component.

Testing

Steps:

  1. Navigate to the "Attacks" page /app/security/attacks
  2. Write kibana.alert.attack_discovery in the search bar

Expected: You will see bunch of Attack discovery fields.

Screenshot 2025-11-12 at 21 38 08

@e40pud e40pud self-assigned this Nov 12, 2025
@e40pud e40pud added the release_note:skip Skip the PR/issue when compiling release notes label Nov 12, 2025
@e40pud e40pud requested a review from a team as a code owner November 12, 2025 20:50
@e40pud e40pud added the backport:skip This PR does not require backporting label Nov 12, 2025
@e40pud e40pud requested a review from a team as a code owner November 12, 2025 20:50
@e40pud e40pud added Team:Threat Hunting Security Solution Threat Hunting Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Threat Hunting:Investigations Security Solution Threat Hunting Investigations Team labels Nov 12, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

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

@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 8335 8337 +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 11.0MB 11.0MB +343.0B

Page load bundle

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

id before after diff
securitySolution 107.1KB 107.1KB -1.0B

cc @e40pud

Copy link
Copy Markdown
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

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

I feel like this PR could have been the right now to do the dataview scope changes you did in #242475.

I left a few comments, but they are all subjective so I'm not blocking the PR, as the functionality works as expected.
I'll let you discuss with @NicholasPeretti and @agusruidiazgd and you guys can make a decision on which route to take!

import { useIsExperimentalFeatureEnabled } from '../../common/hooks/use_experimental_features';
import { useDataView } from '../../data_view_manager/hooks/use_data_view';

export const useDetectionsDataView = (scope: SourcererScopeName) => {
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.

I have a couple of small problems with this hook:

  • while it's nice to extract this logic into a hook, it will make the cleanup later on a bit more complex, in the sense that when we remove all the old sourcerer code (see [Security Solution] remove newDataViewPickerEnabled feature flag #238549) we will then have to put back some of the code in the actual components , as it won't make much sense to have a hook to to fetch the dataview from another hook.
  • You don't actually need to extract this into a separate hook as you only care about the new dataview picker in the attacks page.

I'm not fully opposed to this. All my arguments are very subjective, but it feels like to me like it's a too early extraction. This is a scenario where we don't have to follow a DRY pattern, and it's fine to have a little bit of duplication of code in the components.

This PR could have been modifying half of the files. After all, the only thing you need on the attacks page is:

const { dataView, status } = useDataView(SourcererScopeName.attacks);

const isLoading: boolean = useMemo(() => status === 'loading' || status === 'pristine', [status]);

const isDataViewInvalid: boolean = useMemo(
  () =>
    status === 'error' ||
      (status === 'ready' && !status.hasMatchedIndices()),
  [dataView, status]
);

You don't need runtimeMappings, oldSourcererDataViewSpec or even the newDataViewPickerEnabled feature flag.

@@ -26,7 +26,7 @@ export interface SearchBarSectionProps {
}
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.

Why not making the sourcererDataViewSpec optional here? We don't have to worry about sourcerer on the attacks page.

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.

Since it is also reused on Alerts page and it is required there. This will be different for the separate search bar component on the Attacks page.

* UI section of the alerts page that renders the global search bar.
* UI section of the detections page (alerts and attacks) that renders the global search bar.
*/
export const SearchBarSection = memo(
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.

Same for this file, while I see a small advantage in making this component reusable, I don't think it makes sense as part of this PR. Why using this new component on the alerts and attacks pages, but not in any of the other pages in Security Solution (like the entity analytics details, hosts, network, users, rule details...) which are also using the same code.

I think this should be done in a separate PR and touch a bigger scope.

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.

If you want to keep this anyway, I think we should add a new prop to be able to prefix the dataTestSubj

/**
 * Optional data test subject string
 */
'data-test-subj'?: string;

{...}

({ dataView, sourcererDataViewSpec, 'data-test-subj': dataTestSubj }: SearchBarSectionProps)

{...}

<SiemSearchBar
  dataTestSubj={`${dataTestSubj}-${SEARCH_BAR_TEST_ID}`}

That way we're guaranteed to have unique ids in Security Solution.

* Shows a loading skeleton while retrieving.
* Shows an error message if the dataView is invalid.
*/
export const DetectionsWrapper = React.memo<DetectionsWrapperProps>(
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.

I feel like using these kind of wrappers are always more confusing to me. They're a black box and it's hard to understand what's happening in the components where they're used.

Also the name Detections_Wrapper doesn't really mean much... I had a similar issue when I refactored the alerts page and ended up creating a wrapper component but I wasn't happy about it. And now we'd have multiple wrapper components?

What do you think about creating a component that just does the <EuiSkeletonLoading>...</EuiSkeletonLoading> instead? That way it could be used as a normal component in the alerts an attacks pages.

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.

Yes, we can discuss what component makes sense to make generic for all pages in detections.

@e40pud
Copy link
Copy Markdown
Contributor Author

e40pud commented Nov 13, 2025

Thanks for the review @PhilippeOberti!

I see points in your concerns. Even though I see some benefits of reusing those components and hooks, I agree that need more thoughts on how to make it work well in detections.

I will add KQL bar to my another PR with the attacks data view scope and will close this one in favour of it. We can sync on possible options to restructure and reuse some of the existing alerts components.

@e40pud
Copy link
Copy Markdown
Contributor Author

e40pud commented Nov 13, 2025

Closing this PR in favour of #242475 where I added a KQL search bar. We will extract and reuse common components in a separate PR.

@e40pud e40pud closed this Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting 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:Investigations Security Solution Threat Hunting Investigations Team Team:Threat Hunting Security Solution Threat Hunting Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security Solution][Attacks/Alerts][Attacks page] KQL section

3 participants