-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 percentile function #86490
Conversation
Pinging @elastic/kibana-app (Team:KibanaApp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Working as expected, but a few small comments!
x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/percentile.tsx
Outdated
Show resolved
Hide resolved
!Number.isNaN(inputValueAsNumber) && | ||
inputValueAsNumber >= 0 && | ||
inputValueAsNumber <= 100 && | ||
inputValueAsNumber % 1 === 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move some of the basic integer checking into helpers? We're using it in 3 places now.
Also, why is 0 a valid percentile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why is 0 a valid percentile?
Interesting, Elasticsearch treats the 0th percentile as min and 100th percentile as max, but according to wikipedia this is not how it works in general:
Note that in theory the 0th percentile falls at negative infinity and the 100th percentile at positive infinity, although in
many practical applications, such as test results, natural lower and/or upper limits are enforced.
I suggest we follow the common definition of percentile here and make the allowed range 1-99 inclusive, wdyt? I would also be fine with following Elasticsearch
x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/percentile.tsx
Show resolved
Hide resolved
min={0} | ||
max={100} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
min={0} | |
max={100} | |
min={1} | |
max={100} | |
step={1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected. Some code comments left.
I see why you removed the slider, I was about to write to add it :) . Perhaps we can live without unless there's a strong request for it.
lowerBound?: number | ||
) { | ||
const inputValueAsNumber = Number(inputValue); | ||
// an input is value if it's not an empty string, parses to a valid number, is between 0 and 100 (inclusive) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is checked for 0 to 100 inclusiveness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment was outdated, removed it
// on initialization values can be null (from the Infinity serialization), so handle it correctly | ||
// or they will be casted to 0 by the editor ( see #78867 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind this comment was addressing the isValidNumber
implementation here. Probably it needs to be removed
setInputValue(val); | ||
}, []); | ||
return ( | ||
<> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this Fragment
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a leftover, thanks
// and is an integer | ||
const inputValueIsValid = isValidNumber(inputValue, true, 99, 1); | ||
|
||
useDebounce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind that this useDebounce
implementation triggers two times at bootstrap: there's the useDebounceWithOptions
version which can skip the first render
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM
💔 Build Failed
Failed CI Steps
Test FailuresX-Pack Detection Engine API Integration Tests.x-pack/test/detection_engine_api_integration/security_and_spaces/tests/add_actions·ts.detection engine api security and spaces enabled add_actions adding actions should be able to create a new webhook action and attach it to a ruleStandard Out
Stack Trace
X-Pack Detection Engine API Integration Tests.x-pack/test/detection_engine_api_integration/security_and_spaces/tests/add_actions·ts.detection engine api security and spaces enabled add_actions adding actions should be able to create a new webhook action and attach it to a ruleStandard Out
Stack Trace
Chrome X-Pack UI Functional Tests.x-pack/test/functional/apps/api_keys/home_page·ts.API Keys app Home page Loads the appStandard Out
Stack Trace
and 5 more failures, only showing the first 3. Metrics [docs]Module Count
Async chunks
Distributable file count
History
To update your PR or re-run it, just comment with: |
Fixes #74574
Release Notes: Adds percentile to Lens.
Behavior
This PR adds a single level percentile operation. It works very similar to the median operation, including an input to enter the desired percentile. On creating a new column, it defaults to the 95th percentile. The percentile input is a debounced number input. Changes are validated to be a valid integer between 0 and 100 (inclusively). Changing the value also updates the label as long as no custom label has been set. If a top values function is used, it is sorted by a percentile column if available.
Non-integer percentiles are disallowed because Elasticsearch can't order a terms agg by them (elastic/elasticsearch#66677) - in this case it felt more important to me to keep the default sorting behavior we are using for other metrics as well than to allow decimal points in the percentile.
Technical changes
percentile
getEsAggsSuffix
. This is necessary because both the bucket path for sorting the terms agg and the column containing the result of the percentile calculation include a suffix (.<percentile>
, e.g..95
). This is implemented by the percentile operation and used by the terms agg (to set theorderBy
argument) and thetoExpression
function (to map the column correctly). If we implement single value percentile rank at some point, it can use the some logictoEsAggsFn
function - this is required so top values can look up the referenced metric column to get the suffix for building the order by pathConsiderations
I considered using a slider component for the value as the allowed range is known, but I decided against it because IMHO when using percentiles the exact value matters and is known before configuring it. Because of this, it felt strange to me using a slider to configure it.