Skip to content

Commit

Permalink
[8.6] [Lens] Fix formula validation issue with non-default locale (#1…
Browse files Browse the repository at this point in the history
…49806) (#149972)

# Backport

This will backport the following commits from `main` to `8.6`:
- [[Lens] Fix formula validation issue with non-default locale
(#149806)](#149806)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco
Liberati","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-01-31T18:39:01Z","message":"[Lens]
Fix formula validation issue with non-default locale (#149806)\n\n##
Summary\r\n\r\nFix #149803 \r\n\r\nThis PR addresses the problem with
i18n validation on formula's content,\r\ncentralising the default node
type into a locale-based type.\r\n\r\nI've also added some i18n
functional tests as suggested by @stratoula :\r\none for this specific
bug and some smokescreen ones for Lens.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Stratoula Kalafateli
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7ac74799c4c4f2f5252cf699560f8e8192210b5a","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Visualizations","Feature:Lens","backport:prev-minor","v8.7.0","v8.6.2"],"number":149806,"url":"https://github.com/elastic/kibana/pull/149806","mergeCommit":{"message":"[Lens]
Fix formula validation issue with non-default locale (#149806)\n\n##
Summary\r\n\r\nFix #149803 \r\n\r\nThis PR addresses the problem with
i18n validation on formula's content,\r\ncentralising the default node
type into a locale-based type.\r\n\r\nI've also added some i18n
functional tests as suggested by @stratoula :\r\none for this specific
bug and some smokescreen ones for Lens.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Stratoula Kalafateli
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7ac74799c4c4f2f5252cf699560f8e8192210b5a"}},"sourceBranch":"main","suggestedTargetBranches":["8.6"],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/149806","number":149806,"mergeCommit":{"message":"[Lens]
Fix formula validation issue with non-default locale (#149806)\n\n##
Summary\r\n\r\nFix #149803 \r\n\r\nThis PR addresses the problem with
i18n validation on formula's content,\r\ncentralising the default node
type into a locale-based type.\r\n\r\nI've also added some i18n
functional tests as suggested by @stratoula :\r\none for this specific
bug and some smokescreen ones for Lens.\r\n\r\n###
Checklist\r\n\r\nDelete any items that are not applicable to this
PR.\r\n\r\n- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] Any UI
touched in this PR is usable by keyboard only (learn more\r\nabout
[keyboard accessibility](https://webaim.org/techniques/keyboard/))\r\n-
[ ] Any UI touched in this PR does not create any new axe
failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[ ] If a plugin configuration key changed, check if it needs to
be\r\nallowlisted in the cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[ ] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n\r\n###
Risk Matrix\r\n\r\nDelete this section if it is not applicable to this
PR.\r\n\r\nBefore closing this PR, invite QA, stakeholders, and other
developers to\r\nidentify risks that should be tested prior to the
change/feature\r\nrelease.\r\n\r\nWhen forming the risk matrix, consider
some of the following examples\r\nand how they may potentially impact
the change:\r\n\r\n| Risk | Probability | Severity | Mitigation/Notes
|\r\n\r\n|---------------------------|-------------|----------|-------------------------|\r\n|
Multiple Spaces&mdash;unexpected behavior in non-default Kibana
Space.\r\n| Low | High | Integration tests will verify that all features
are still\r\nsupported in non-default Kibana Space and when user
switches between\r\nspaces. |\r\n| Multiple nodes&mdash;Elasticsearch
polling might have race conditions\r\nwhen multiple Kibana nodes are
polling for the same tasks. | High | Low\r\n| Tasks are idempotent, so
executing them multiple times will not result\r\nin logical error, but
will degrade performance. To test for this case we\r\nadd plenty of unit
tests around this logic and document manual testing\r\nprocedure. |\r\n|
Code should gracefully handle cases when feature X or plugin Y
are\r\ndisabled. | Medium | High | Unit tests will verify that any
feature flag\r\nor plugin combination still results in our service
operational. |\r\n| [See more potential
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)
|\r\n\r\n\r\n### For maintainers\r\n\r\n- [ ] This was checked for
breaking API changes and was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by:
Stratoula Kalafateli
<[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"7ac74799c4c4f2f5252cf699560f8e8192210b5a"}},{"branch":"8.6","label":"v8.6.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: Marco Liberati <[email protected]>
Co-authored-by: Stratoula Kalafateli <[email protected]>
  • Loading branch information
3 people authored Feb 1, 2023
1 parent 110fd24 commit 9702dad
Show file tree
Hide file tree
Showing 8 changed files with 1,019 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function getOperationParams(
}, {});
}

function getTypeI18n(type: string) {
export function getTypeI18n(type: string) {
if (type === 'number') {
return i18n.translate('xpack.lens.formula.number', { defaultMessage: 'number' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
findMathNodes,
findVariables,
getOperationParams,
getTypeI18n,
getValueOrName,
groupArgsByType,
isMathNode,
Expand Down Expand Up @@ -114,6 +115,8 @@ export interface ErrorWrapper {
severity?: 'error' | 'warning';
}

const DEFAULT_RETURN_TYPE = getTypeI18n('number');

function getNodeLocation(node: TinymathFunction): TinymathLocation[] {
return [node.location].filter(nonNullable);
}
Expand All @@ -124,11 +127,11 @@ function getArgumentType(arg: TinymathAST, operations: Record<string, GenericOpe
}
if (arg.type === 'function') {
if (tinymathFunctions[arg.name]) {
return tinymathFunctions[arg.name].outputType ?? 'number';
return tinymathFunctions[arg.name].outputType ?? DEFAULT_RETURN_TYPE;
}
// Assume it's a number for now
if (operations[arg.name]) {
return 'number';
return DEFAULT_RETURN_TYPE;
}
}
// leave for now other argument types
Expand Down Expand Up @@ -659,7 +662,6 @@ function validateNameArguments(
return errors;
}

const DEFAULT_RETURN_TYPE = 'number';
function checkTopNodeReturnType(ast: TinymathAST): ErrorWrapper[] {
if (
isObject(ast) &&
Expand Down Expand Up @@ -1123,7 +1125,7 @@ export function validateMathNodes(
values: {
operation: node.name,
name: positionalArguments[wrongTypeArgumentIndex].name,
type: getArgumentType(arg, operations) || 'number',
type: getArgumentType(arg, operations) || DEFAULT_RETURN_TYPE,
expectedType: positionalArguments[wrongTypeArgumentIndex].type || '',
},
locations: getNodeLocation(node),
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/localization/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ import type { FtrProviderContext } from '../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('Sanity checks', () => {
loadTestFile(require.resolve('./login_page'));
loadTestFile(require.resolve('./lens'));
});
}
33 changes: 33 additions & 0 deletions x-pack/test/localization/tests/lens/formula.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['visualize', 'lens']);
const elasticChart = getService('elasticChart');

describe('lens formula tests', () => {
it('should allow creation of a lens chart via formula', async () => {
await PageObjects.visualize.navigateToNewVisualization();
await PageObjects.visualize.clickVisType('lens');
await elasticChart.setNewChartUiDebugFlag(true);
await PageObjects.lens.goToTimeRange();

await PageObjects.lens.configureDimension({
dimension: 'lnsXY_yDimensionPanel > lns-empty-dimension',
operation: 'formula',
formula: `count() + average(bytes)`,
});

expect(await PageObjects.lens.getErrorCount()).to.eql(0);
const data = await PageObjects.lens.getCurrentChartDebugState('xyVisChart');
expect(data).to.be.ok();
});
});
}
77 changes: 77 additions & 0 deletions x-pack/test/localization/tests/lens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EsArchiver } from '@kbn/es-archiver';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects, loadTestFile }: FtrProviderContext) {
const PageObjects = getPageObjects(['timePicker']);
const browser = getService('browser');
const config = getService('config');
const log = getService('log');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
let remoteEsArchiver;

describe('lens app', () => {
const esArchive = 'x-pack/test/functional/es_archives/logstash_functional';
const localIndexPatternString = 'logstash-*';
const remoteIndexPatternString = 'ftr-remote:logstash-*';
const localFixtures = {
lensBasic: 'x-pack/test/functional/fixtures/kbn_archiver/lens/lens_basic.json',
lensDefault: 'x-pack/test/functional/fixtures/kbn_archiver/lens/default',
};

const remoteFixtures = {
lensBasic: 'x-pack/test/functional/fixtures/kbn_archiver/lens/ccs/lens_basic.json',
lensDefault: 'x-pack/test/functional/fixtures/kbn_archiver/lens/ccs/default',
};
let esNode: EsArchiver;
let fixtureDirs: {
lensBasic: string;
lensDefault: string;
};
let indexPatternString: string;
before(async () => {
log.debug('Starting lens before method');
await browser.setWindowSize(1280, 1200);
await kibanaServer.savedObjects.cleanStandardList();
try {
config.get('esTestCluster.ccs');
remoteEsArchiver = getService('remoteEsArchiver' as 'esArchiver');
esNode = remoteEsArchiver;
fixtureDirs = remoteFixtures;
indexPatternString = remoteIndexPatternString;
} catch (error) {
esNode = esArchiver;
fixtureDirs = localFixtures;
indexPatternString = localIndexPatternString;
}

await esNode.load(esArchive);
// changing the timepicker default here saves us from having to set it in Discover (~8s)
await PageObjects.timePicker.setDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.uiSettings.update({
defaultIndex: indexPatternString,
'dateFormat:tz': 'UTC',
});
await kibanaServer.importExport.load(fixtureDirs.lensBasic);
await kibanaServer.importExport.load(fixtureDirs.lensDefault);
});

after(async () => {
await esArchiver.unload(esArchive);
await PageObjects.timePicker.resetDefaultAbsoluteRangeViaUiSettings();
await kibanaServer.importExport.unload(fixtureDirs.lensBasic);
await kibanaServer.importExport.unload(fixtureDirs.lensDefault);
await kibanaServer.savedObjects.cleanStandardList();
});

loadTestFile(require.resolve('./smokescreen'));
loadTestFile(require.resolve('./formula'));
});
}
Loading

0 comments on commit 9702dad

Please sign in to comment.