-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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 specific IP and Range/Interval sorting to datatable #87006
Conversation
Explored the option to embed this code into the |
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.
Overall I think this code is simple and makes sense. Left a comment about the behavior of IP sorting which I think we should change, but LGTM.
it(`should provide the IP criteria for IP values (mixed values with invalid "Other" field) - ${direction}`, () => { | ||
testSorting({ | ||
input: ['fc00::123', '192.168.1.50', '10.0.1.76', '8.8.8.8', '::1', 'Other'], | ||
output: ['Other', '::1', '8.8.8.8', '10.0.1.76', '192.168.1.50', 'fc00::123'], |
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.
I noticed that Other
was sorted to the beginning of the list- I kind of expected it to be sorted in a special way, always being at the end of the list regardless of the sort order. What do you think?
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.
Possible, sure.
It's really up to us to decide a value out of the range I guess: the current implementation, as I saw it, mimics the "blank" values on numeric fields, which are casted to 0
.
Putting it at last should be straightforward as it knows already the direction.
if (!ipaddr.isValid(ip)) { | ||
// for non valid IPs have the same behaviour as for now (we assume it's only the "Other" string) | ||
// create a mock object which has all -Infinity values to be the last item | ||
return { parts: Array(8).fill(-Infinity) }; |
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.
I think the result of this is that Other is always shown at the beginning of the list. Can we push it to the end instead, since I would want to show IPs in ascending order?
diff = ipA.parts[i] - ipB.parts[i]; | ||
} | ||
|
||
// in case of same address but written in different styles, sort by string length |
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.
Nice!
Hi, I'm taking a look at the changes. In the meantime, the PR description needs a clearly written Release Note since this is an enhancement :) |
Hi @tsullivan, Kibana doesn't support |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
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.
Tested and works as expected, LGTM. Left one small nit about the code
} | ||
// use a string sorter for the rest | ||
return (rowA: Record<string, unknown>, rowB: Record<string, unknown>) => { | ||
const aString = formatter?.convert(rowA[sortBy]); |
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.
Is it possible there is no formatter? The types indicate otherwise, so if the will always be a formatter, we can remove the optional chaining - if it can actually be undefined, we should do something like this: aString = formatter ? formatter.convert(rowA[sortBy]) : rowA[sortBy]
, otherwise it will just compare undefined with undefined
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 formatFactory
should ensure each column has a formatter:
kibana/x-pack/plugins/lens/public/datatable_visualization/expression.tsx
Lines 128 to 130 in c545b32
firstTable.columns.forEach((column) => { | |
formatters[column.id] = formatFactory(column.meta?.params); | |
}); |
I'll remove the optional chaining here.
@elasticmachine merge upstream |
…ana into feature/lens/table-ip-sorting
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
…ic#87006) Co-authored-by: Kibana Machine <[email protected]>
…87006) (#87975) Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
Summary
Fixes: #85431, enhances #84435
This PR adds a specific logic to sort IP and Range type of data into the custom datatable sorting.
The previous sorting function has been rewritten for performance reason: the
lodash
orderBy
was using only a single field per time and to perform an IP sorting logic it should have accepted 8 functions (one per IPv6 part/block) or perform some hacky manipulation.Some initial unit testing has been added for the sorting logic, with particular focus on IP and ranges.
How Range sorting works
The range sorting algorithm works as follow:
{gte: 1}
=>{gte: 1, lt: Infinity}
)gte
gte
is identical then compare thelt
valueHow IP sorting works
In order to achieve the IP sorting a new dependency was added (
ipaddr.js
- note that was already a subdependency ofwebpack-web-server
), to support IPv6 parsing in its multiple form.The IP sorting algorithm works as follow:
Other
value) (opinion)diff = 0
for each part/block) then compare the string length: the shorter form should be considered "smaller" than the longer form ( opinion )Checklist