Skip to content

Commit

Permalink
[ML] Fixes ES|QL field stats showing skewed numeric distribution, dup…
Browse files Browse the repository at this point in the history
…licated examples for string fields, and adds functional tests (elastic#177085)

## Summary

Part of elastic#173301. This PR:
- Fixes ES|QL field stats showing skewed numeric distribution,
duplicated examples for string fields
- Adds functional tests for ES|QL data visualizer view

[Flaky test suite
runner](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5226):
50/50 runs successful ✅

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
qn895 and kibanamachine authored Mar 12, 2024
1 parent bfd6376 commit 2922dd2
Show file tree
Hide file tree
Showing 13 changed files with 412 additions and 22 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/data_visualizer/common/types/field_stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export interface StringFieldStats {
fieldName: string;
isTopValuesSampled: boolean;
topValues: Bucket[];
topValuesSampleSize: number;
topValuesSamplerShardSize: number;
topValuesSampleSize?: number;
topValuesSamplerShardSize?: number;
}

export interface DateFieldStats {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ export const TopValues: FC<Props> = ({ stats, fieldFormat, barColor, compressed,
} = useDataVisualizerKibana();

if (stats === undefined || !stats.topValues) return null;
const { topValues, fieldName, sampleCount } = stats;
const { topValues: originalTopValues, fieldName, sampleCount } = stats;

if (topValues?.length === 0) return null;
if (originalTopValues?.length === 0) return null;
const totalDocuments = stats.totalDocuments ?? sampleCount ?? 0;

const topValues = originalTopValues.map((bucket) => ({
...bucket,
percent:
typeof bucket.percent === 'number' ? bucket.percent : bucket.doc_count / totalDocuments,
}));
const topValuesOtherCountPercent =
1 - (topValues ? topValues.reduce((acc, bucket) => acc + bucket.percent, 0) : 0);
const topValuesOtherCount = Math.floor(topValuesOtherCountPercent * (sampleCount ?? 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,39 @@ import type { ESQLDefaultLimitSizeOption } from '../../../embeddables/grid_embed

const options = [
{
'data-test-subj': 'dvESQLLimitSize-5000',
value: '5000',
text: i18n.translate('xpack.dataVisualizer.searchPanel.esql.limitSizeOptionLabel', {
defaultMessage: '{limit} rows',
values: { limit: '5,000' },
}),
},
{
'data-test-subj': 'dvESQLLimitSize-10000',
value: '10000',
text: i18n.translate('xpack.dataVisualizer.searchPanel.esql.limitSizeOptionLabel', {
defaultMessage: '{limit} rows',
values: { limit: '10,000' },
}),
},
{
'data-test-subj': 'dvESQLLimitSize-100000',
value: '100000',
text: i18n.translate('xpack.dataVisualizer.searchPanel.esql.limitSizeOptionLabel', {
defaultMessage: '{limit} rows',
values: { limit: '100,000' },
}),
},
{
'data-test-subj': 'dvESQLLimitSize-1000000',
value: '1000000',
text: i18n.translate('xpack.dataVisualizer.searchPanel.esql.limitSizeOptionLabel', {
defaultMessage: '{limit} rows',
values: { limit: '1,000,000' },
}),
},
{
'data-test-subj': 'dvESQLLimitSize-none',
value: 'none',
text: i18n.translate('xpack.dataVisualizer.searchPanel.esql.analyzeAll', {
defaultMessage: 'Analyze all',
Expand All @@ -62,6 +67,7 @@ export const ESQLDefaultLimitSizeSelect = ({

return (
<EuiSelect
data-test-subj="dvESQLLimitSizeSelect"
id={basicSelectId}
options={options}
value={limitSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,14 @@ export const getESQLKeywordFieldStats = async ({
if (isFulfilled(resp)) {
const results = resp.value?.rawResponse.values as Array<[BucketCount, BucketTerm]>;
if (results) {
const topValuesSampleSize = results?.reduce((acc: number, row) => acc + row[0], 0);

const terms = results.map((row) => ({
key: row[1],
doc_count: row[0],
percent: row[0] / topValuesSampleSize,
}));

return {
fieldName: field.name,
topValues: terms,
topValuesSampleSize,
topValuesSamplerShardSize: topValuesSampleSize,
isTopValuesSampled: false,
} as StringFieldStats;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getESQLNumericFieldStatsInChunk = async ({
const median = values[startIndex + numericAccessorMap.p50];

const percentiles = values
.slice(startIndex + numericAccessorMap.p0, startIndex + numericAccessorMap.p100)
.slice(startIndex + numericAccessorMap.p5, startIndex + numericAccessorMap.p100 + 1)
.map((value: number) => ({ value }));

const distribution = processDistributionData(percentiles, PERCENTILE_SPACING, min);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const getESQLExampleFieldValues = async ({

if (textFieldsResp) {
return textFields.map((textField, idx) => {
const examples = (textFieldsResp.rawResponse.values as unknown[][]).map(
(row) => row[idx]
);
const examples = [
...new Set((textFieldsResp.rawResponse.values as unknown[][]).map((row) => row[idx])),
];

return {
fieldName: textField.name,
Expand Down
Loading

0 comments on commit 2922dd2

Please sign in to comment.