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

[Lens] Add support for decimals in percentiles #165703

Merged
merged 18 commits into from
Sep 12, 2023
Merged

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Sep 5, 2023

Summary

Fixes #98853

This PR adds support for decimals (2 digits) in percentile operation.

percentile_decimals_support

Features:

  • ✨ Add decimals support in percentile
    • πŸ› Fixed aggs optimization to work with decimals
  • πŸ’„ Show Toast for ranking reset when using decimals in both percentile and percentile rank
  • βœ… Extended isValidNumber to support digits check and added unit tests for it
  • ♻️ Added support also to convert to Lens feature

Added both unit and functional tests.

percentile_rank_toast

When trying to add more digits than what is supported then it will show the input as invalid:
Screenshot 2023-09-05 at 12 24 03

Also it works now as custom ranking column:
Screenshot 2023-09-05 at 16 14 25
Screenshot 2023-09-05 at 16 14 20

Notes: need to specify exact digits in percentile (2) because the any step is not supported and need to specify a number. I guess alternatives here are to either extend it to 4 digits or make it a configurable thing.

Checklist

Delete any items that are not applicable to this PR.

@dej611 dej611 added release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens v8.11.0 labels Sep 5, 2023
@dej611 dej611 marked this pull request as ready for review September 8, 2023 13:54
@dej611 dej611 requested a review from a team as a code owner September 8, 2023 13:54
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@stratoula
Copy link
Contributor

stratoula commented Sep 8, 2023

This works great, I just feel that the notification needs some refinement.

image

@MichaelMarcialis @amyjtechwriter can you help us here?

This notification appears in the following scenario. I have a percentile with an integer value and a top values dimension with rank by the metric(percentiles) and then go back to the metric and change the percentile from an integer to a decima value. At this point we want to notify the users that we changed automatically the rank by to alphabetical (ES limitation elastic/elasticsearch#66677)

export function isValidNumber(
inputValue: string | number | null | undefined,
integer?: boolean,
upperBound?: number,
lowerBound?: number
lowerBound?: number,
digits: number = 2
Copy link
Member

Choose a reason for hiding this comment

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

why are we limiting it to 2 decimals? I could imagine an SRE wanting up to 4.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I agree with that comment, do we need a limit?

Copy link
Contributor Author

@dej611 dej611 Sep 12, 2023

Choose a reason for hiding this comment

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

I see what you mean. It's a simple constant change, so I'll update.

Yes I agree with that comment, do we need a limit?

Unfortunately yes. I've asked to add the support to any but it is not coming in Range components: elastic/eui#5703

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.

defaultMessage: 'Top values ranking reset',
}),
text: i18n.translate('xpack.lens.uiInfo.rankingResetToAlphabetical', {
defaultMessage: 'The use of decimals for this function is not supported for ranking.',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like "Ranking reset to alphabetical rank. Please only use whole numbers to rank by percentile."

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 with latest suggestions by @gchaps

@timductive
Copy link
Member

When trying to add more digits than what is supported then it will show the input as invalid:
Screenshot 2023-09-05 at 12 24 03

This message could also use some help. Can we override the text here to say something closer to "Please limit to 2 decimal places"

@gchaps
Copy link
Contributor

gchaps commented Sep 11, 2023

Here are some suggestions for the two messages.

Suggestions for the ranking message

Ranking changed to alphabetical
To rank by percentile, use whole numbers only.

Suggestions for the decimal place meesage:

Only 2 numbers allowed after the decimal point.
Only 2 decimal places allowed.

@MichaelMarcialis
Copy link
Contributor

MichaelMarcialis commented Sep 11, 2023

When trying to add more digits than what is supported then it will show the input as invalid:

@dej611: Rather than showing the input as invalid (and asking that the user manually fix the problem themselves), would it be better for us to round to the nearest valid decimal on blur for the user? For example, if user enters 99.568180, the value automatically changes to 99.57 on blur. I feel like that may be a better user experience.

This notification appears in the following scenario. I have a percentile with an integer value and a top values dimension with rank by the metric(percentiles) and then go back to the metric and change the percentile from an integer to a decima value. At this point we want to notify the users that we changed automatically the rank by to alphabetical (ES limitation elastic/elasticsearch#66677)

@dej611, @stratoula, @timductive: Are we absolutely certain we want to automatically change the top value dimension ranking when the user attempts to enter a decimal value for the metric percentile? I'm not an expert on these more advanced aggregations, but to my mind that feels backwards. I think it may make more sense and be less destructive to simply not allow users to enter a percentile with a decimal value if/when a top value dimension ranking is set to rank by metric. Per my comment above, could we not simply round any decimal entered to the nearest whole number automatically on blur (as well as conditionally add help text below the form element when it is detected that a top value dimension is ranked by metric and indicate to users that decimals are not supported)?

In that case, we wouldn't need this toast at all.

@stratoula
Copy link
Contributor

Per my comment above, could we not simply round any decimal entered to the nearest whole number automatically on blur (as well as conditionally add help text below the form element when it is detected that a top value dimension is ranked by metric and indicate to users that decimals are not supported)?

Not sure how it will work on blur because if I am not mistaken the request will be sent in ES and it will fail. Except from that we could not allow decimals if a top values breakdown rank by metric is detected. The problem I see in this approach is that the users need to go then to top values, fix the ranking and then change the decimals. With the current approach we do it automatically. Decimals are important in percentiles and percentiles ranks. If a user wants 99.9 they are not going to be happy with 99. We are already doing this in percentile ranks btw and we didn't have any complain afaik.

@dej611
Copy link
Contributor Author

dej611 commented Sep 12, 2023

why are we limiting it to 2 decimals? I could imagine an SRE wanting up to 4.

Latest changes raised the limit to 4 decimals. (Note while testing inline: there's currently an EUI bug with integer check and 8 digits: elastic/eui#7180 )
The generic invalid message has also been updated:
Screenshot 2023-09-12 at 10 36 15

This message could also use some help. Can we override the text here to say something closer to "Please limit to 2 decimal places"

Updated:
Screenshot 2023-09-12 at 10 36 06

Here are some suggestions for the two messages.
Suggestions for the ranking message

Ranking changed to alphabetical
To rank by percentile, use whole numbers only.

Done
Screenshot 2023-09-12 at 10 35 55

@dej611
Copy link
Contributor Author

dej611 commented Sep 12, 2023

The problem I see in this approach is that the users need to go then to top values, fix the ranking and then change the decimals. With the current approach we do it automatically.

Also the other way around (decimals => integer) will automagically update the ranking logic (this has always been like that in Lens).

@kibana-ci
Copy link
Collaborator

πŸ’š 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
lens 1.4MB 1.4MB +1.7KB
visDefaultEditor 141.0KB 141.0KB +39.0B
visualizations 264.7KB 264.7KB +79.0B
total +1.8KB

History

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

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

LGTM, this works great! I tested the new changes in Chrome, I really like the new message!

@dej611 dej611 merged commit b796f13 into elastic:main Sep 12, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Sep 12, 2023
@MichaelMarcialis
Copy link
Contributor

Not sure how it will work on blur because if I am not mistaken the request will be sent in ES and it will fail.

@stratoula: Are we completely unable to intercept and check the value before it is sent to ES?

The problem I see in this approach is that the users need to go then to top values, fix the ranking and then change the decimals. With the current approach we do it automatically. Decimals are important in percentiles and percentiles ranks. If a user wants 99.9 they are not going to be happy with 99.

@stratoula: I can understand that desire to make the process as automated as possible. But personally, I'd rather be notified of what needs to change in this case rather than having that ranking change forced upon me. I don't believe use of a decimal percentile is a valid indicator that the user also wishes to change their top value ranking. I think it's more likely that the user simply isn't aware of the limitation that they can't use decimal percentiles in that specific scenario.

@stratoula
Copy link
Contributor

stratoula commented Sep 12, 2023

I don't believe use of a decimal percentile is a valid indicator that the user also wishes to change their top value ranking. I think it's more likely that the user simply isn't aware of the limitation that they can't use decimal percentiles in that specific scenario.

Absolutely, you are def right here. I guess it depends on the user and what they want to do after all. We are using this kind of automations on other places too.

We can go with the current experience as is the same with the one we have on percentile ranks and if we get any complains we can adjust.

@timductive @ninoslavmiskovic wdyt ?

@ninoslavmiskovic
Copy link
Contributor

I like the automated approach and believe this would be sufficient for the user. The granularity is important in this case and I'm not sure the user would take the round trip based on a toast, if we prompt the user, but rather be unsatisfied.

So I am ++ on automation and nice with the 4 digits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Allow decimal percentiles like 99.5
9 participants