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 Posture] fix findings table sort casing bug #148529

Merged
merged 20 commits into from
Jan 15, 2023
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,34 @@ export const showErrorToast = (
else toasts.addDanger(extractErrorMessage(error, SEARCH_FAILED_TEXT));
};

export const getFindingsQuery = ({ query, sort }: UseFindingsOptions) => ({
index: CSP_LATEST_FINDINGS_DATA_VIEW,
body: {
orouz marked this conversation as resolved.
Show resolved Hide resolved
export const getFindingsQuery = ({ query, sort }: UseFindingsOptions) => {
return {
index: CSP_LATEST_FINDINGS_DATA_VIEW,
query,
sort: [{ [sort.field]: sort.direction }],
sort: getSortField(sort),
size: MAX_FINDINGS_TO_LOAD,
aggs: getFindingsCountAggQuery(),
},
ignore_unavailable: false,
});
ignore_unavailable: false,
};
};

const getSortField = (sort: Sort<CspFinding>) => {
if (requiredSortingByPainlessScript.includes(sort.field)) {
return {
_script: {
type: 'string',
order: sort.direction,
script: {
source: `doc["${sort.field}"].value.toLowerCase()`,
lang: 'painless',
},
},
};
}
return { [sort.field]: sort.direction };
};

const requiredSortingByPainlessScript = ['rule.section', 'resource.name', 'resource.type'];
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @ofiriro3,

Forgive me if I need more context here. Would you mind adding a comment about why these fields require such a sorting instead of using a more native Elasticsearch solution like normalizer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @opauloh.

We had a long discussion about how should we solve the sorting problem.
One of the solutions that I suggested was indeed a normalizer, in the end, it was decided to use a painless script.

Long story short, we didn't want to change the schema/mapping.

You are more than welcome to read the discussion ->

ofiriro3 marked this conversation as resolved.
Show resolved Hide resolved

export const useLatestFindings = (options: UseFindingsOptions) => {
const {
Expand Down