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

[Transform] Support for the top_metrics aggregation #101152

Merged
merged 21 commits into from
Jun 4, 2021

Conversation

darnautov
Copy link
Contributor

@darnautov darnautov commented Jun 2, 2021

Summary

Resolves #98127

Adds UI support for the top_metrics aggregation.

Related Elasticsearch PR.

image

Checklist

@darnautov darnautov added release_note:enhancement :ml v8.0.0 Feature:Transforms ML transforms v7.14.0 auto-backport Deprecated - use backport:version if exact versions are needed labels Jun 2, 2021
@darnautov darnautov requested review from walterra and qn895 June 2, 2021 12:19
@darnautov darnautov self-assigned this Jun 2, 2021
@darnautov darnautov requested a review from a team as a code owner June 2, 2021 12:19
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@elastic elastic deleted a comment from kibanamachine Jun 2, 2021

describe('isSpecialSortField', () => {
test('detects special sort field', () => {
expect(isSpecialSortField('_score')).toBe(true);
Copy link
Member

@qn895 qn895 Jun 2, 2021

Choose a reason for hiding this comment

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

nit: would be good to add one or more test cases here to assert they will return false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in a2ae489


const sortDirectionOptions = Object.values(SORT_DIRECTION).map((v) => ({
id: v,
label: v,
Copy link
Member

Choose a reason for hiding this comment

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

Should the labels in these options be internationalized? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't recall seeing asc and desc to be translated in Kibana 🤔

>
<EuiSelect
options={NUMERIC_TYPES_OPTIONS[sortFieldType as KbnNumericType].map((v) => ({
text: v,
Copy link
Member

Choose a reason for hiding this comment

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

Like the options above, should these be internationalized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we should not translate type names

sortDirection = sortDefinition;
}

if (typeof sortDefinition === 'object') {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think we can use isPopulatedObject 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.

Updated in 24b7c6f

@qn895
Copy link
Member

qn895 commented Jun 2, 2021

Gave this a test and functionally it works great. One suggestion is maybe we can either indicate that these sorting fields are required or disable the apply button if these options are not picked?

For example, if I pick the following empty first option and hit Apply I will get an error that's not so easy to understand
Screen Shot 2021-06-02 at 09 19 19

Likewise for the sort direction and sort mode
2021-06-02 at 09 25

Another small consideration that maybe the design team can look at is the pop-up for the settings is getting longer and can sometimes get cut off from the screen. Not a big issue just something we should investigate since we are adding more and more options to the transform configurations in the future.

2021-06-02 at 09 28

@darnautov darnautov requested a review from szabosteve June 3, 2021 12:08
Copy link
Contributor

@szabosteve szabosteve left a comment

Choose a reason for hiding this comment

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

Left one small remark. UI text LGTM, thanks!

@darnautov darnautov requested a review from jgowdyelastic June 3, 2021 13:34
@darnautov
Copy link
Contributor Author

thanks for testing it @qn895! 🙏 I improved the validation so it shouldn't allow applying invalid changes.
Regarding the popover redesign, we decided to keep it as is, because for an advanced configuration with loads of settings users tend to use a JSON editor. In the future, we may consider using a flyout instead, but it should be consistent for all aggregation types.

@darnautov darnautov requested review from qn895 and alvarezmelissa87 and removed request for walterra June 4, 2021 08:15
Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

Added a comment, but generally code LGTM

label: v,
}));

const sortFieldType = fields.find((f) => f.name === aggConfig.sortField)?.type;
Copy link
Member

Choose a reason for hiding this comment

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

should sortFieldOptions, sortDirectionOptions, sortModeOptions and sortFieldType all be wrapped in some useMemo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, merged the PR from my phone and missed this comment. Definitely no harm in useMemo, but I don't expect any performance issues with the current code even with thousands of fields available. Also, this component is only rendered with the popover form is visible.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
transform 225 227 +2

Async chunks

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

id before after diff
transform 918.5KB 928.0KB +9.5KB

History

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

cc @darnautov

@darnautov darnautov merged commit 9810a72 into elastic:master Jun 4, 2021
@darnautov darnautov deleted the transform-98127-top-metrics branch June 4, 2021 14:05
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 4, 2021
* [ML] init top_metrics agg

* [ML] support sort

* [ML] support _score sorting

* [ML] support sort mode

* [ML] support numeric type sorting

* [ML] update field label, hide additional sorting controls

* [ML] preserve advanced config

* [ML] update agg fields after runtime fields edit

* [ML] fix TS issue with EuiButtonGroup

* [ML] fix Field label

* [ML] refactor setUiConfig

* [ML] update unit tests

* [ML] wrap advanced sorting settings with accordion

* [ML] config validation with tests

* [ML] fix preserving of the unsupported config

* [ML] update translation message

* [ML] fix level of the custom config

* [ML] preserve unsupported config for sorting
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Jun 4, 2021
)

* [ML] init top_metrics agg

* [ML] support sort

* [ML] support _score sorting

* [ML] support sort mode

* [ML] support numeric type sorting

* [ML] update field label, hide additional sorting controls

* [ML] preserve advanced config

* [ML] update agg fields after runtime fields edit

* [ML] fix TS issue with EuiButtonGroup

* [ML] fix Field label

* [ML] refactor setUiConfig

* [ML] update unit tests

* [ML] wrap advanced sorting settings with accordion

* [ML] config validation with tests

* [ML] fix preserving of the unsupported config

* [ML] update translation message

* [ML] fix level of the custom config

* [ML] preserve unsupported config for sorting

Co-authored-by: Dima Arnautov <[email protected]>
@lcawl lcawl added release_note:feature Makes this part of the condensed release notes and removed release_note:enhancement labels Jul 6, 2021
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:Transforms ML transforms :ml release_note:feature Makes this part of the condensed release notes v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ML] Transforms: add UI support for top metrics aggregation
7 participants