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] [Detections] amends useFetchIndex hook to accept data view id in addition to array of index names #160079

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Jun 20, 2023

Summary

Please read for more background on motivations for this PR -> #154968

updates useFetchIndex hook to accept a data view id in addition to an array of index names and updates useRuleIndexPattern hook to pass in data view id to useFetchIndex.

@dhurley14 dhurley14 self-assigned this Jun 22, 2023
@dhurley14 dhurley14 changed the title updates useFetchIndex hook to accept a data view id in addition to an… [Security Solution] [Detections] amends useFetchIndex hook to accept data view id in addition to array of index names Jun 22, 2023
@dhurley14 dhurley14 added review release_note:skip Skip the PR/issue when compiling release notes Team:Security Solution Platform Security Solution Platform Team Team:Detection Engine Security Solution Detection Engine Area v8.10.0 labels Jun 22, 2023
@dhurley14 dhurley14 marked this pull request as ready for review June 22, 2023 19:13
@dhurley14 dhurley14 requested review from a team as code owners June 22, 2023 19:13
@dhurley14 dhurley14 requested a review from dplumlee June 22, 2023 19:13
@e40pud e40pud self-requested a review June 23, 2023 09:17
// * @deprecated use DataViewSpec from @kbn/data-views-plugin/common
// * or DataView if absolutely necessary
// */
// export type DataViewBase = DataViewBase;
Copy link
Contributor

Choose a reason for hiding this comment

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

noticed commented code in few places. Can it be removed?

pick(key, schema),
filterManager,
license,
dataViewInstance as DataViewBase
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 possible to avoid type castings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kind of the same situation as above except this is due to the unified search team's component FilterBadgeGroup needing a DataViewBase type to be passed to it, which the dataViewInstance is compatible with. Until that changes, we'll need the casting unfortunately.

const dataViewInstance = useMemo(() => {
if (indexPattern != null) {
const dv = new DataView({ spec: indexPattern, fieldFormats });
return { ...dv, fields: Object.values(indexPattern.fields ?? {}) } as DataView;
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 possible to avoid type castings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a great question - I kept these type castings because until we also update all the exceptions code to accept the DataViewSpec type, we can't update the child component FieldComponent, so once that work is completed we can remove the type castings all together which will be great. I'll add a todo to the code.

const dv = new DataView({ spec: threatIndexPatterns, fieldFormats });
return { ...dv, fields: Object.values(threatIndexPatterns.fields ?? {}) } as DataView;
}
return [];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: separate transform function can be added to DataView instance from index and fields formats. dataViewInstance and threatDataViewInstance look indentical


previousIndexesName.current = dv.getIndexPattern().split(',');
const { browserFields } = getDataViewStateFromIndexFields(iNames, dataView.fields);
previousIndexesNameOrId.current = dataView?.title?.split(',');
Copy link
Contributor

Choose a reason for hiding this comment

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

should not this previousIndexesNameOrId.current = dataView?.title?.split(','); be within previous else branch? it will always override line 136

acc.keywordFields.push({ label: field.name });
} else if (field.type === 'date') {
acc.dateFields.push({ label: field.name });
} else if (field.type !== 'date') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be just } else {?

@dhurley14
Copy link
Contributor Author

cypress tests were failing because of a missing dependency here: #160445 once that is merged I'll update this PR and hopefully that fixes a few of the failures.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Jun 24, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Security Solution Tests #6 / Detections : Page Filters Alert list is updated when the alerts are updated
  • [job] [logs] Security Solution Tests #6 / Detections : Page Filters Impact of inputs should recover from invalide kql Query result
  • [job] [logs] Security Solution Tests #5 / EQL rules Detection rules, EQL Creates and enables a new EQL rule
  • [job] [logs] Security Solution Tests #5 / EQL rules Detection rules, EQL Creates and enables a new EQL rule
  • [job] [logs] Defend Workflows Cypress Tests #1 / Response console suspend-process command "after all" hook for "should suspend process from response console"

Metrics [docs]

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 +3.5KB

Page load bundle

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

id before after diff
securitySolution 52.2KB 52.3KB +139.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 14 16 +2
securitySolution 416 420 +4
total +6

References to deprecated APIs

id before after diff
securitySolution 614 605 -9

Total ESLint disabled count

id before after diff
enterpriseSearch 15 17 +2
securitySolution 497 501 +4
total +6

History

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

cc @dhurley14

}

/**
* Independent index fields hook/request
* returns state directly, no redux
*/
export const useFetchIndex = (
indexNames: string[],
indexNamesOrDvId: string | string[],
Copy link
Contributor

@dplumlee dplumlee Jun 30, 2023

Choose a reason for hiding this comment

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

If we're trying to move away from the indexNames pattern, would it be better to just construct a new param structure and separate these two arguments instead of delineating on isArray? I understand that would cause a lot of refactor since we use this hook everywhere, but just wondering what your thoughts were. Having multiple variables in this function logic with "or" in the name reads a bit confusing

@PhilippeOberti
Copy link
Contributor

@dhurley14 is this PR still being worked on or can it be closed?

2 similar comments
@PhilippeOberti
Copy link
Contributor

@dhurley14 is this PR still being worked on or can it be closed?

@PhilippeOberti
Copy link
Contributor

@dhurley14 is this PR still being worked on or can it be closed?

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 review Team:Detection Engine Security Solution Detection Engine Area Team:Security Solution Platform Security Solution Platform Team v8.10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants