Skip to content

[ML] Adding additional runtime mapping checks#94760

Merged
jgowdyelastic merged 12 commits intoelastic:masterfrom
jgowdyelastic:adding-additional-runtime-mapping-checks
Mar 24, 2021
Merged

[ML] Adding additional runtime mapping checks#94760
jgowdyelastic merged 12 commits intoelastic:masterfrom
jgowdyelastic:adding-additional-runtime-mapping-checks

Conversation

@jgowdyelastic
Copy link
Copy Markdown
Member

@jgowdyelastic jgowdyelastic commented Mar 16, 2021

Adds runtime mappings to queries used for determining the index's time range.

Corrects the on save runtime mappings filter to also look in the query object as well as the aggregation object for used field names.

Adds some functional tests for the datafeed preview endpoint.

Related to #91534 #91168

@jgowdyelastic
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@jgowdyelastic jgowdyelastic self-assigned this Mar 18, 2021
@jgowdyelastic jgowdyelastic added :ml Feature:Anomaly Detection ML anomaly detection non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes review v7.13.0 v8.0.0 labels Mar 18, 2021
@jgowdyelastic jgowdyelastic marked this pull request as ready for review March 18, 2021 13:01
@jgowdyelastic jgowdyelastic requested a review from a team as a code owner March 18, 2021 13:01
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ml-ui (:ml)

@jgowdyelastic jgowdyelastic requested a review from qn895 March 18, 2021 13:01
@jgowdyelastic
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@jgowdyelastic
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

// return all nested keys in the object
// most will not be fields, but better to catch everything
// and not accidentally remove a used runtime field.
if (typeof val === 'object' && val !== null) {
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.

you can use isPopulatedObject instead

return fields;
}

function findFieldsInQuery(obj: Record<string, any>) {
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 I'm not mistaken we have some Query type provided by the data plugin, but otherwise Record<string, object | null> would be better

Comment on lines +37 to +39
function isLowerCase(str: string) {
return /^[a-z]+$/.test(str);
}
Copy link
Copy Markdown
Contributor

@darnautov darnautov Mar 22, 2021

Choose a reason for hiding this comment

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

If a string contains a number or some special charts it will return false. Have you considered something like example below?

Suggested change
function isLowerCase(str: string) {
return /^[a-z]+$/.test(str);
}
function isLowerCase(str: string) {
return !/[A-Z]+/.test(str)
}

@qn895
Copy link
Copy Markdown
Member

qn895 commented Mar 22, 2021

Tested and LGTM

Copy link
Copy Markdown
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested latest changes and LGTM

@jgowdyelastic jgowdyelastic added the auto-backport Deprecated - use backport:version if exact versions are needed label Mar 22, 2021
Copy link
Copy Markdown
Member

@pheyos pheyos left a comment

Choose a reason for hiding this comment

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

Great to see functional tests coming as part of this PR 🎉

It would be good to add some validation messages, I've left two comments with examples, but they apply to most of the validations.
Also, I'd suggest to add two additional test cases to validate that the users ML_UNAUTHORIZED and ML_VIEWER are not allowed to call this endpoint.

@jgowdyelastic
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Member

@pheyos pheyos left a comment

Choose a reason for hiding this comment

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

Functional tests LGTM

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

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
ml 6.0MB 6.0MB +520.0B

History

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

cc @jgowdyelastic

@jgowdyelastic jgowdyelastic merged commit fdda564 into elastic:master Mar 24, 2021
@jgowdyelastic jgowdyelastic deleted the adding-additional-runtime-mapping-checks branch March 24, 2021 10:29
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Mar 24, 2021
* [ML] Adding additional runtime mapping checks

* adding functional test for datafeed preview

* renaming findFieldsInAgg

* updating query check

* always use runtime mappings if present in agg field exists check

* changes based on review

* updating tests based on review

* fixing permission check on endpoint and test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Backport successful

7.x / #95281

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Mar 24, 2021
* [ML] Adding additional runtime mapping checks

* adding functional test for datafeed preview

* renaming findFieldsInAgg

* updating query check

* always use runtime mappings if present in agg field exists check

* changes based on review

* updating tests based on review

* fixing permission check on endpoint and test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: James Gowdy <jgowdy@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed Feature:Anomaly Detection ML anomaly detection :ml non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes review v7.13.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants