mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ES|QL] Fix fields are no longer suggested for grok and dissect (#190153)
## Summary Fixes https://github.com/elastic/kibana/issues/190070   ### 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: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
parent
4b0fb8fd58
commit
627c9c41cf
8 changed files with 24 additions and 30 deletions
|
@ -269,11 +269,7 @@ describe('autocomplete', () => {
|
|||
`dissect keywordField ${constantPattern} |`,
|
||||
];
|
||||
for (const subExpression of subExpressions) {
|
||||
// Unskip once https://github.com/elastic/kibana/issues/190070 is fixed
|
||||
testSuggestions.skip(
|
||||
`from a | ${subExpression} grok /`,
|
||||
getFieldNamesByType(ESQL_STRING_TYPES)
|
||||
);
|
||||
testSuggestions(`from a | ${subExpression} grok /`, getFieldNamesByType(ESQL_STRING_TYPES));
|
||||
testSuggestions(`from a | ${subExpression} grok keywordField /`, [constantPattern], ' ');
|
||||
testSuggestions(`from a | ${subExpression} grok keywordField ${constantPattern} /`, ['| ']);
|
||||
}
|
||||
|
@ -1024,8 +1020,7 @@ describe('autocomplete', () => {
|
|||
]);
|
||||
|
||||
// DISSECT field
|
||||
// enable once https://github.com/elastic/kibana/issues/190070 is fixed
|
||||
testSuggestions.skip('FROM index1 | DISSECT b/', getFieldNamesByType(ESQL_STRING_TYPES));
|
||||
testSuggestions('FROM index1 | DISSECT b/', getFieldNamesByType(ESQL_STRING_TYPES));
|
||||
|
||||
// DROP (first field)
|
||||
testSuggestions('FROM index1 | DROP f/', getFieldNamesByType('any'));
|
||||
|
@ -1057,8 +1052,7 @@ describe('autocomplete', () => {
|
|||
]);
|
||||
|
||||
// GROK field
|
||||
// enable once https://github.com/elastic/kibana/issues/190070
|
||||
testSuggestions.skip('FROM index1 | GROK f/', getFieldNamesByType(ESQL_STRING_TYPES));
|
||||
testSuggestions('FROM index1 | GROK f/', getFieldNamesByType(ESQL_STRING_TYPES), undefined);
|
||||
|
||||
// KEEP (first field)
|
||||
testSuggestions('FROM index1 | KEEP f/', getFieldNamesByType('any'));
|
||||
|
|
|
@ -660,7 +660,7 @@ async function getExpressionSuggestionsByType(
|
|||
if ((!nodeArg || isNewExpression) && !endsWithNot) {
|
||||
suggestions.push(
|
||||
...(await getFieldsOrFunctionsSuggestions(
|
||||
[argDef.innerType || 'any'],
|
||||
argDef.innerTypes ?? ['any'],
|
||||
command.name,
|
||||
option?.name,
|
||||
getFieldsByType,
|
||||
|
@ -906,7 +906,7 @@ async function getExpressionSuggestionsByType(
|
|||
}
|
||||
}
|
||||
if (argDef.type === 'source') {
|
||||
if (argDef.innerType === 'policy') {
|
||||
if (argDef.innerTypes?.includes('policy')) {
|
||||
// ... | ENRICH <suggest>
|
||||
const policies = await getPolicies();
|
||||
suggestions.push(...(policies.length ? policies : [buildNoPoliciesAvailableDefinition()]));
|
||||
|
|
|
@ -415,8 +415,7 @@ export const commandDefinitions: CommandDefinition[] = [
|
|||
signature: {
|
||||
multipleParams: false,
|
||||
params: [
|
||||
// innerType: 'string' is interpreted as keyword and text (see columnParamsWithInnerTypes)
|
||||
{ name: 'column', type: 'column', innerType: 'string' },
|
||||
{ name: 'column', type: 'column', innerTypes: ['keyword', 'text'] },
|
||||
{ name: 'pattern', type: 'string', constantOnly: true },
|
||||
],
|
||||
},
|
||||
|
@ -433,8 +432,7 @@ export const commandDefinitions: CommandDefinition[] = [
|
|||
signature: {
|
||||
multipleParams: false,
|
||||
params: [
|
||||
// innerType: 'string' is interpreted as keyword and text (see columnParamsWithInnerTypes)
|
||||
{ name: 'column', type: 'column', innerType: 'string' },
|
||||
{ name: 'column', type: 'column', innerTypes: ['keyword', 'text'] },
|
||||
{ name: 'pattern', type: 'string', constantOnly: true },
|
||||
],
|
||||
},
|
||||
|
@ -449,7 +447,7 @@ export const commandDefinitions: CommandDefinition[] = [
|
|||
modes: [],
|
||||
signature: {
|
||||
multipleParams: false,
|
||||
params: [{ name: 'column', type: 'column', innerType: 'any' }],
|
||||
params: [{ name: 'column', type: 'column', innerTypes: ['any'] }],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -467,7 +465,7 @@ export const commandDefinitions: CommandDefinition[] = [
|
|||
modes: [ENRICH_MODES],
|
||||
signature: {
|
||||
multipleParams: false,
|
||||
params: [{ name: 'policyName', type: 'source', innerType: 'policy' }],
|
||||
params: [{ name: 'policyName', type: 'source', innerTypes: ['policy'] }],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -93,7 +93,7 @@ function printCommandArgument(
|
|||
return param.name || '';
|
||||
}
|
||||
return `${param.name}${param.optional ? ':?' : ':'} ${param.type}${
|
||||
param.innerType ? `{${param.innerType}}` : ''
|
||||
param.innerTypes ? `{${param.innerTypes}}` : ''
|
||||
}`;
|
||||
}
|
||||
|
||||
|
|
|
@ -154,13 +154,13 @@ export interface CommandBaseDefinition {
|
|||
hidden?: boolean;
|
||||
signature: {
|
||||
multipleParams: boolean;
|
||||
// innerType here is useful to drill down the type in case of "column"
|
||||
// innerTypes here is useful to drill down the type in case of "column"
|
||||
// i.e. column of type string
|
||||
params: Array<{
|
||||
name: string;
|
||||
type: string;
|
||||
optional?: boolean;
|
||||
innerType?: string;
|
||||
innerTypes?: string[];
|
||||
values?: string[];
|
||||
valueDescriptions?: string[];
|
||||
constantOnly?: boolean;
|
||||
|
|
|
@ -2685,7 +2685,7 @@
|
|||
{
|
||||
"query": "from a_index | dissect doubleField \"%{firstWord}\"",
|
||||
"error": [
|
||||
"DISSECT only supports string type values, found [doubleField] of type [double]"
|
||||
"DISSECT only supports keyword, text types values, found [doubleField] of type [double]"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
@ -2779,7 +2779,7 @@
|
|||
{
|
||||
"query": "from a_index | grok doubleField \"%{firstWord}\"",
|
||||
"error": [
|
||||
"GROK only supports string type values, found [doubleField] of type [double]"
|
||||
"GROK only supports keyword, text types values, found [doubleField] of type [double]"
|
||||
],
|
||||
"warning": []
|
||||
},
|
||||
|
|
|
@ -701,7 +701,7 @@ describe('validation logic', () => {
|
|||
// Do not try to validate the dissect pattern string
|
||||
testErrorsAndWarnings('from a_index | dissect textField "%{firstWord}"', []);
|
||||
testErrorsAndWarnings('from a_index | dissect doubleField "%{firstWord}"', [
|
||||
'DISSECT only supports string type values, found [doubleField] of type [double]',
|
||||
'DISSECT only supports keyword, text types values, found [doubleField] of type [double]',
|
||||
]);
|
||||
testErrorsAndWarnings('from a_index | dissect textField "%{firstWord}" option ', [
|
||||
"SyntaxError: mismatched input '<EOF>' expecting '='",
|
||||
|
@ -748,11 +748,10 @@ describe('validation logic', () => {
|
|||
testErrorsAndWarnings('from a_index | grok textField %a', [
|
||||
"SyntaxError: mismatched input '%' expecting QUOTED_STRING",
|
||||
]);
|
||||
// @TODO: investigate
|
||||
// Do not try to validate the grok pattern string
|
||||
testErrorsAndWarnings('from a_index | grok textField "%{firstWord}"', []);
|
||||
testErrorsAndWarnings('from a_index | grok doubleField "%{firstWord}"', [
|
||||
'GROK only supports string type values, found [doubleField] of type [double]',
|
||||
'GROK only supports keyword, text types values, found [doubleField] of type [double]',
|
||||
]);
|
||||
testErrorsAndWarnings('from a_index | grok textField "%{firstWord}" | keep firstWord', []);
|
||||
// testErrorsAndWarnings('from a_index | grok s* "%{a}"', [
|
||||
|
|
|
@ -873,18 +873,21 @@ function validateColumnForCommand(
|
|||
if (getColumnExists(column, references)) {
|
||||
const commandDef = getCommandDefinition(commandName);
|
||||
const columnParamsWithInnerTypes = commandDef.signature.params.filter(
|
||||
({ type, innerType }) => type === 'column' && innerType
|
||||
({ type, innerTypes }) => type === 'column' && innerTypes
|
||||
);
|
||||
// this should be guaranteed by the columnCheck above
|
||||
const columnRef = lookupColumn(column, references)!;
|
||||
|
||||
if (columnParamsWithInnerTypes.length) {
|
||||
const hasSomeWrongInnerTypes = columnParamsWithInnerTypes.every(({ innerType }) => {
|
||||
if (innerType === 'string' && isStringType(columnRef.type)) return false;
|
||||
return innerType !== 'any' && innerType !== columnRef.type;
|
||||
const hasSomeWrongInnerTypes = columnParamsWithInnerTypes.every(({ innerTypes }) => {
|
||||
if (innerTypes?.includes('string') && isStringType(columnRef.type)) return false;
|
||||
return innerTypes && !innerTypes.includes('any') && !innerTypes.includes(columnRef.type);
|
||||
});
|
||||
if (hasSomeWrongInnerTypes) {
|
||||
const supportedTypes = columnParamsWithInnerTypes.map(({ innerType }) => innerType);
|
||||
const supportedTypes: string[] = columnParamsWithInnerTypes
|
||||
.map(({ innerTypes }) => innerTypes)
|
||||
.flat()
|
||||
.filter((type) => type !== undefined) as string[];
|
||||
|
||||
messages.push(
|
||||
getMessageFromId({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue