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

[Cloud Security] Filters for Contextual Flyout Datagrid #201708

Merged
merged 12 commits into from
Dec 2, 2024

Conversation

animehart
Copy link
Contributor

@animehart animehart commented Nov 26, 2024

Summary

Screen.Recording.2024-11-26.at.4.52.58.PM.mov

This PR is for adding Filters for Contextual Flytout Datagrid

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

1 similar comment
@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart
Copy link
Contributor Author

/ci

@animehart animehart marked this pull request as ready for review November 27, 2024 23:15
@animehart animehart requested a review from a team as a code owner November 27, 2024 23:15
@animehart animehart added v8.18.0 v9.0.0 Team:Cloud Security Cloud Security team related labels Nov 27, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

@animehart animehart added release_note:skip Skip the PR/issue when compiling release notes backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Nov 27, 2024
@animehart animehart requested a review from opauloh November 27, 2024 23:39
Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

Looks good, I left many comments and would be glad to discuss them if you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

:opinion

We should consider renaming this file to something like queries.ts because all exported functions are related to building queries.

This is a little pet peeve of mine when directories are called utils and files helpers. I've seen this in many cases over time files like this become a kitchen sink of common functions and it becomes hard to reorganize the structure later. This will be especially hard to reorganize if other plugins start to use our shared package.

x-pack/packages/kbn-cloud-security-posture/common/queries.ts

Since this is a shared package everything is by definition common so another suggestion is to remove comment altogether

x-pack/packages/kbn-cloud-security-posture/queries.ts

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmmm you are right that almost all of the helpers functions here are query related and I can see the issue that this might have later in the future

I'm down to do this change but maybe in separate ticket/PR (as this PR is for Filters for the Datagrid, and this suggested change might touch other features thats not related at all with Contextual Flyout)

wdyt ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes please and thank you! Can you open that issue as a tech debt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the link to the tech debt issue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#202242

Lemme know if i missed anything :)

Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

Almost there, just a few things to resolve. 🙏

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

looks good, added some suggestions

@@ -43,7 +43,14 @@ export const buildMutedRulesFilter = (
return mutedRulesFilterQuery;
};

export const buildEntityFlyoutPreviewQuery = (field: string, queryValue?: string) => {
export const buildEntityFlyoutPreviewQuery = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we could create some High Order functions instead:

// Generic function
export const buildGenericEntityFlyoutPreviewQuery = (
  field: string,
  queryValue?: string,
  status?: string,
  queryField?: string
) => {
  return {
    bool: {
      filter: [
        {
          bool: {
            should: [
              {
                term: {
                  [field]: `${queryValue || ''}`,
                },
              },
            ],
            minimum_should_match: 1,
          },
        },
        status && queryField
          ? {
              bool: {
                should: [
                  {
                    term: {
                      [queryField]: status,
                    },
                  },
                ],
                minimum_should_match: 1,
              },
            }
          : undefined,
      ].filter(Boolean),
    },
  };
};

// Higher-order function for Misconfiguration
export const buildMisconfigurationEntityFlyoutPreviewQuery = (
  field: string,
  queryValue?: string,
  status?: string
) => {
  const queryField = 'result.evaluation';
  return buildGenericEntityFlyoutPreviewQuery(field, queryValue, status, queryField);
};

// Higher-order function for Vulnerability
export const buildVulnerabilityEntityFlyoutPreviewQuery = (
  field: string,
  queryValue?: string,
  status?: string
) => {
  const queryField = 'vulnerability.severity';
  return buildGenericEntityFlyoutPreviewQuery(field, queryValue, status, queryField);
};

@@ -50,6 +55,14 @@ export const getVulnerabilityStats = (
),
count: counts.none,
color: getSeverityStatusColor(VULNERABILITIES_SEVERITY.UNKNOWN),
filter: () => {
filterFunction?.('UNKNOWN');
Copy link
Contributor

Choose a reason for hiding this comment

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

let's update to use the constant:

filterFunction?.(VULNERABILITIES_SEVERITY.UNKNOWN);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

woops

@@ -41,6 +47,14 @@ const getFindingsStats = (passedFindingsStats: number, failedFindingsStats: numb
),
count: passedFindingsStats,
color: euiThemeVars.euiColorSuccess,
filter: () => {
filterFunction('passed');
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add 'passed' and 'failed' values to a constant?

@animehart animehart requested a review from a team as a code owner November 29, 2024 01:54
Copy link
Contributor

@janmonschke janmonschke left a comment

Choose a reason for hiding this comment

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

THI changes lgtm

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/cloud-security-posture 89 93 +4
@kbn/cloud-security-posture-common 107 120 +13
total +17

Async chunks

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

id before after diff
securitySolution 14.6MB 14.6MB +2.0KB
Unknown metric groups

API count

id before after diff
@kbn/cloud-security-posture 89 93 +4
@kbn/cloud-security-posture-common 109 122 +13
total +17

History

@animehart animehart merged commit 2f62cde into elastic:main Dec 2, 2024
8 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/12124654067

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 2, 2024
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 2, 2024
… (#202556)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Cloud Security] Filters for Contextual Flyout Datagrid
(#201708)](#201708)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Rickyanto
Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-02T17:26:03Z","message":"[Cloud
Security] Filters for Contextual Flyout Datagrid (#201708)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/59ace35f-62b8-4c08-bf2c-eed200db791d\r\n\r\nThis
PR is for adding Filters for Contextual Flytout
Datagrid","sha":"2f62cdebfcc585689cd266495a82c2049fcc19ad","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud
Security","backport:prev-minor","v8.18.0"],"title":"[Cloud Security]
Filters for Contextual Flyout
Datagrid","number":201708,"url":"https://github.com/elastic/kibana/pull/201708","mergeCommit":{"message":"[Cloud
Security] Filters for Contextual Flyout Datagrid (#201708)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/59ace35f-62b8-4c08-bf2c-eed200db791d\r\n\r\nThis
PR is for adding Filters for Contextual Flytout
Datagrid","sha":"2f62cdebfcc585689cd266495a82c2049fcc19ad"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/201708","number":201708,"mergeCommit":{"message":"[Cloud
Security] Filters for Contextual Flyout Datagrid (#201708)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/59ace35f-62b8-4c08-bf2c-eed200db791d\r\n\r\nThis
PR is for adding Filters for Contextual Flytout
Datagrid","sha":"2f62cdebfcc585689cd266495a82c2049fcc19ad"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Rickyanto Ang <[email protected]>
hop-dev pushed a commit to hop-dev/kibana that referenced this pull request Dec 5, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 9, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants