Skip to content

Commit

Permalink
Merge branch 'main' into prevent-updating-non-customizable-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Oct 10, 2024
2 parents 50a3b0c + 8d1bc50 commit 7ef6f2c
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 159 deletions.
6 changes: 4 additions & 2 deletions .buildkite/ftr_oblt_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ disabled:
- x-pack/test_serverless/functional/test_suites/observability/cypress/config_headless.ts
- x-pack/test_serverless/functional/test_suites/observability/cypress/config_runner.ts

# serverless config files that run deployment-agnostic tests
# Failing https://github.com/elastic/kibana/issues/195811
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts

defaultQueue: 'n2-4-spot'
enabled:
- x-pack/test_serverless/api_integration/test_suites/observability/config.ts
Expand All @@ -25,5 +29,3 @@ enabled:
- x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group5.ts
- x-pack/test_serverless/functional/test_suites/observability/common_configs/config.group6.ts
- x-pack/test_serverless/functional/test_suites/observability/config.screenshots.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/oblt.serverless.config.ts
6 changes: 4 additions & 2 deletions .buildkite/ftr_search_serverless_configs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
disabled:
# Base config files, only necessary to inform config finding script

# serverless config files that run deployment-agnostic tests
# Failing https://github.com/elastic/kibana/issues/195811
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.serverless.config.ts

defaultQueue: 'n2-4-spot'
enabled:
- x-pack/test_serverless/api_integration/test_suites/search/config.ts
Expand All @@ -18,5 +22,3 @@ enabled:
- x-pack/test_serverless/functional/test_suites/search/common_configs/config.group4.ts
- x-pack/test_serverless/functional/test_suites/search/common_configs/config.group5.ts
- x-pack/test_serverless/functional/test_suites/search/common_configs/config.group6.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/search.serverless.config.ts
6 changes: 4 additions & 2 deletions .buildkite/ftr_security_serverless_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ disabled:
- x-pack/test_serverless/functional/config.base.ts
- x-pack/test_serverless/shared/config.base.ts

# serverless config files that run deployment-agnostic tests
# Failing https://github.com/elastic/kibana/issues/195811
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.serverless.config.ts

defaultQueue: 'n2-4-spot'
enabled:
- x-pack/test_serverless/api_integration/test_suites/security/config.ts
Expand Down Expand Up @@ -100,5 +104,3 @@ enabled:
- x-pack/test/security_solution_api_integration/test_suites/edr_workflows/response_actions/trial_license_complete_tier/configs/serverless.config.ts
- x-pack/test/security_solution_endpoint/configs/serverless.endpoint.config.ts
- x-pack/test/security_solution_endpoint/configs/serverless.integrations.config.ts
# serverless config files that run deployment-agnostic tests
- x-pack/test/api_integration/deployment_agnostic/configs/serverless/security.serverless.config.ts
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/cloud/build_and_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fi
if is_pr_with_label "ci:cloud-redeploy"; then
echo "--- Shutdown Previous Deployment"
CLOUD_DEPLOYMENT_ID=$(ecctl deployment list --output json | jq -r '.deployments[] | select(.name == "'$CLOUD_DEPLOYMENT_NAME'") | .id')
if [ -z "${CLOUD_DEPLOYMENT_ID}" ]; then
if [ -z "${CLOUD_DEPLOYMENT_ID}" ] || [ "${CLOUD_DEPLOYMENT_ID}" == "null" ]; then
echo "No deployment to remove"
else
echo "Shutting down previous deployment..."
Expand Down
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/serverless/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ deploy() {

PROJECT_ID=$(jq -r '[.items[] | select(.name == "'$PROJECT_NAME'")] | .[0].id' $PROJECT_EXISTS_LOGS)
if is_pr_with_label "ci:project-redeploy"; then
if [ -z "${PROJECT_ID}" ]; then
if [ -z "${PROJECT_ID}" ] || [ "${PROJECT_ID}" == "null" ]; then
echo "No project to remove"
else
echo "Shutting down previous project..."
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {
isQueryWrappedByPipes,
retrieveMetadataColumns,
getQueryColumnsFromESQLQuery,
isESQLColumnSortable,
TextBasedLanguages,
} from './src';

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export {
getStartEndParams,
hasStartEndParams,
} from './utils/run_query';
export { isESQLColumnSortable } from './utils/esql_fields_utils';
66 changes: 66 additions & 0 deletions packages/kbn-esql-utils/src/utils/esql_fields_utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { DatatableColumn } from '@kbn/expressions-plugin/common';
import { isESQLColumnSortable } from './esql_fields_utils';

describe('esql fields helpers', () => {
describe('isESQLColumnSortable', () => {
it('returns false for geo fields', () => {
const geoField = {
id: 'geo.coordinates',
name: 'geo.coordinates',
meta: {
type: 'geo_point',
esType: 'geo_point',
},
isNull: false,
} as DatatableColumn;
expect(isESQLColumnSortable(geoField)).toBeFalsy();
});

it('returns false for source fields', () => {
const sourceField = {
id: '_source',
name: '_source',
meta: {
type: '_source',
esType: '_source',
},
isNull: false,
} as DatatableColumn;
expect(isESQLColumnSortable(sourceField)).toBeFalsy();
});

it('returns false for counter fields', () => {
const tsdbField = {
id: 'tsbd_counter',
name: 'tsbd_counter',
meta: {
type: 'number',
esType: 'counter_long',
},
isNull: false,
} as DatatableColumn;
expect(isESQLColumnSortable(tsdbField)).toBeFalsy();
});

it('returns true for everything else', () => {
const keywordField = {
id: 'sortable',
name: 'sortable',
meta: {
type: 'string',
esType: 'keyword',
},
isNull: false,
} as DatatableColumn;
expect(isESQLColumnSortable(keywordField)).toBeTruthy();
});
});
});
40 changes: 40 additions & 0 deletions packages/kbn-esql-utils/src/utils/esql_fields_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { DatatableColumn } from '@kbn/expressions-plugin/common';

const SPATIAL_FIELDS = ['geo_point', 'geo_shape', 'point', 'shape'];
const SOURCE_FIELD = '_source';
const TSDB_COUNTER_FIELDS_PREFIX = 'counter_';

/**
* Check if a column is sortable.
*
* @param column The DatatableColumn of the field.
* @returns True if the column is sortable, false otherwise.
*/

export const isESQLColumnSortable = (column: DatatableColumn): boolean => {
// We don't allow sorting on spatial fields
if (SPATIAL_FIELDS.includes(column.meta?.type)) {
return false;
}

// we don't allow sorting on the _source field
if (column.meta?.type === SOURCE_FIELD) {
return false;
}

// we don't allow sorting on tsdb counter fields
if (column.meta?.esType && column.meta?.esType?.indexOf(TSDB_COUNTER_FIELDS_PREFIX) !== -1) {
return false;
}

return true;
};
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,23 @@ describe('autocomplete', () => {
'```````````````````````````````round(doubleField) + 1```````````````` + 1```````` + 1```` + 1`` + 1`',
]
);

it('should not suggest already-used fields and variables', async () => {
const { suggest: suggestTest } = await setup();
const getSuggestions = async (query: string) =>
(await suggestTest(query)).map((value) => value.text);

expect(await getSuggestions('from a_index | EVAL foo = 1 | KEEP /')).toContain('foo');
expect(await getSuggestions('from a_index | EVAL foo = 1 | KEEP foo, /')).not.toContain(
'foo'
);
expect(await getSuggestions('from a_index | EVAL foo = 1 | KEEP /')).toContain(
'doubleField'
);
expect(
await getSuggestions('from a_index | EVAL foo = 1 | KEEP doubleField, /')
).not.toContain('doubleField');
});
});
}

Expand Down Expand Up @@ -1111,11 +1128,14 @@ describe('autocomplete', () => {
]);
});

describe('KEEP <field>', () => {
describe.each(['KEEP', 'DROP'])('%s <field>', (commandName) => {
// KEEP field
testSuggestions('FROM a | KEEP /', getFieldNamesByType('any').map(attachTriggerCommand));
testSuggestions(
'FROM a | KEEP d/',
`FROM a | ${commandName} /`,
getFieldNamesByType('any').map(attachTriggerCommand)
);
testSuggestions(
`FROM a | ${commandName} d/`,
getFieldNamesByType('any')
.map<PartialSuggestionWithText>((text) => ({
text,
Expand All @@ -1124,11 +1144,11 @@ describe('autocomplete', () => {
.map(attachTriggerCommand)
);
testSuggestions(
'FROM a | KEEP doubleFiel/',
`FROM a | ${commandName} doubleFiel/`,
getFieldNamesByType('any').map(attachTriggerCommand)
);
testSuggestions(
'FROM a | KEEP doubleField/',
`FROM a | ${commandName} doubleField/`,
['doubleField, ', 'doubleField | ']
.map((text) => ({
text,
Expand All @@ -1141,7 +1161,7 @@ describe('autocomplete', () => {

// Let's get funky with the field names
testSuggestions(
'FROM a | KEEP @timestamp/',
`FROM a | ${commandName} @timestamp/`,
['@timestamp, ', '@timestamp | ']
.map((text) => ({
text,
Expand All @@ -1150,10 +1170,15 @@ describe('autocomplete', () => {
}))
.map(attachTriggerCommand),
undefined,
[[{ name: '@timestamp', type: 'date' }]]
[
[
{ name: '@timestamp', type: 'date' },
{ name: 'utc_stamp', type: 'date' },
],
]
);
testSuggestions(
'FROM a | KEEP foo.bar/',
`FROM a | ${commandName} foo.bar/`,
['foo.bar, ', 'foo.bar | ']
.map((text) => ({
text,
Expand All @@ -1162,39 +1187,63 @@ describe('autocomplete', () => {
}))
.map(attachTriggerCommand),
undefined,
[[{ name: 'foo.bar', type: 'double' }]]
[
[
{ name: 'foo.bar', type: 'double' },
{ name: 'baz', type: 'date' },
],
]
);

describe('escaped field names', () => {
// This isn't actually the behavior we want, but this test is here
// to make sure no weird suggestions start cropping up in this case.
testSuggestions('FROM a | KEEP `foo.bar`/', ['foo.bar'], undefined, [
testSuggestions(`FROM a | ${commandName} \`foo.bar\`/`, ['foo.bar'], undefined, [
[{ name: 'foo.bar', type: 'double' }],
]);
// @todo re-enable these tests when we can use AST to support this case
testSuggestions.skip('FROM a | KEEP `foo.bar`/', ['foo.bar, ', 'foo.bar | '], undefined, [
[{ name: 'foo.bar', type: 'double' }],
]);
testSuggestions.skip(
'FROM a | KEEP `foo`.`bar`/',
`FROM a | ${commandName} \`foo.bar\`/`,
['foo.bar, ', 'foo.bar | '],
undefined,
[[{ name: 'foo.bar', type: 'double' }]]
);
testSuggestions.skip('FROM a | KEEP `any#Char$Field`/', [
testSuggestions.skip(
`FROM a | ${commandName} \`foo\`.\`bar\`/`,
['foo.bar, ', 'foo.bar | '],
undefined,
[[{ name: 'foo.bar', type: 'double' }]]
);
testSuggestions.skip(`FROM a | ${commandName} \`any#Char$Field\`/`, [
'`any#Char$Field`, ',
'`any#Char$Field` | ',
]);
});

// Subsequent fields
testSuggestions(
'FROM a | KEEP doubleField, dateFiel/',
`FROM a | ${commandName} doubleField, dateFiel/`,
getFieldNamesByType('any')
.filter((s) => s !== 'doubleField')
.map(attachTriggerCommand)
);
testSuggestions('FROM a | KEEP doubleField, dateField/', ['dateField, ', 'dateField | ']);
testSuggestions(`FROM a | ${commandName} doubleField, dateField/`, [
'dateField, ',
'dateField | ',
]);

// out of fields
testSuggestions(
`FROM a | ${commandName} doubleField, dateField/`,
['dateField | '],
undefined,
[
[
{ name: 'doubleField', type: 'double' },
{ name: 'dateField', type: 'date' },
],
]
);
});
});
});
Expand Down
Loading

0 comments on commit 7ef6f2c

Please sign in to comment.