Skip to content

Commit

Permalink
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
Browse files Browse the repository at this point in the history
…-use-breadcrumbs
  • Loading branch information
jennypavlova authored Sep 27, 2022
2 parents 4e2fd39 + f336734 commit a801588
Show file tree
Hide file tree
Showing 232 changed files with 3,683 additions and 1,418 deletions.
2 changes: 2 additions & 0 deletions docs/api/data-views/update.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ the data view is updated. The default is `false`.
You can partially update the following fields:

* `title`
* `name`
* `timeFieldName`
* `fields`
* `sourceFilters`
Expand Down Expand Up @@ -93,6 +94,7 @@ $ curl -X POST api/data_views/data-view/my-view
{
"data_view": {
"title": "...",
"name": "...",
"timeFieldName": "...",
"sourceFilters": [],
"fieldFormats": {},
Expand Down
2 changes: 2 additions & 0 deletions docs/api/index-patterns/update.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ the index pattern is updated. The default is `false`.
You can partially update the following fields:

* `title`
* `name`
* `timeFieldName`
* `fields`
* `sourceFilters`
Expand Down Expand Up @@ -90,6 +91,7 @@ $ curl -X POST api/index_patterns/index-pattern/my-pattern
{
"index_pattern": {
"title": "...",
"name": "...",
"timeFieldName": "...",
"sourceFilters": [],
"fieldFormats": {},
Expand Down
22 changes: 4 additions & 18 deletions scripts/archive_migration_functions.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
#!/bin/bash

# ??? Should we migrate
# x-pack/test/functional/es_archives/logstash/example_pipelines
# !!! No, we've found 0 saved objects that are listed in the standard_list
# !!! It contains the following saved object(s)
# config
# space

standard_list="url,index-pattern,query,graph-workspace,tag,visualization,canvas-element,canvas-workpad,dashboard,search,lens,map,cases,uptime-dynamic-settings,osquery-saved-query,osquery-pack,infrastructure-ui-source,metrics-explorer-view,inventory-view,infrastructure-monitoring-log-view,apm-indices"

orig_archive="x-pack/test/functional/es_archives/spaces/multi_space"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/spaces/multi_space"
orig_archive="x-pack/test/functional/es_archives/banners/multispace"
new_archive="x-pack/test/functional/fixtures/kbn_archiver/banners/multi_space"

# newArchives=("x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_space")
# newArchives+=("x-pack/test/functional/fixtures/kbn_archiver/dashboard/session_in_another_space")

testFiles=("x-pack/test/functional/apps/discover/preserve_url.ts")
testFiles+=("x-pack/test/functional/apps/visualize/preserve_url.ts")
testFiles+=("x-pack/test/functional/apps/dashboard/group1/preserve_url.ts")
# testFiles=("x-pack/test/functional/apps/discover/preserve_url.ts")

test_config="x-pack/test/functional/apps/dashboard/group1/config.ts"
# test_config="x-pack/test/functional/apps/discover/config.ts"
# test_config="x-pack/test/functional/apps/visualize/config.ts"
test_config="x-pack/test/banners_functional/config.ts"

list_stragglers() {

Expand Down
2 changes: 1 addition & 1 deletion src/dev/build/tasks/bin/scripts/kibana
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ if [ -f "${CONFIG_DIR}/node.options" ]; then
KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)"
fi
NODE_OPTIONS="--no-warnings --max-http-header-size=65536 $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli/dist" ${@}
NODE_OPTIONS="--no-warnings --max-http-header-size=65536 $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli/dist" "${@}"
3 changes: 2 additions & 1 deletion src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export {
getTime,
isQuery,
isTimeRange,
queryStateToExpressionAst,
textBasedQueryStateToAstWithValidation,
textBasedQueryStateToExpressionAst,
} from './query';
export type { QueryState } from './query';
export * from './search';
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data/common/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './timefilter';
export * from './types';
export * from './is_query';
export * from './query_state';
export { queryStateToExpressionAst } from './to_expression_ast';
export { textBasedQueryStateToAstWithValidation } from './text_based_query_state_to_ast_with_validation';
export { textBasedQueryStateToExpressionAst } from './text_based_query_state_to_ast';
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { DataViewsContract } from '@kbn/data-views-plugin/common';
import { queryStateToExpressionAst } from './to_expression_ast';
import { textBasedQueryStateToExpressionAst } from './text_based_query_state_to_ast';

describe('queryStateToExpressionAst', () => {
describe('textBasedQueryStateToExpressionAst', () => {
it('returns an object with the correct structure', async () => {
const dataViewsService = {} as unknown as DataViewsContract;
const actual = await queryStateToExpressionAst({
const actual = await textBasedQueryStateToExpressionAst({
filters: [],
query: { language: 'lucene', query: '' },
time: {
from: 'now',
to: 'now+7d',
},
dataViewsService,
});

expect(actual).toHaveProperty(
Expand All @@ -33,31 +30,13 @@ describe('queryStateToExpressionAst', () => {
});

it('returns an object with the correct structure for an SQL query', async () => {
const dataViewsService = {
getIdsWithTitle: jest.fn(() => {
return [
{
title: 'foo',
id: 'bar',
},
];
}),
get: jest.fn(() => {
return {
title: 'foo',
id: 'bar',
timeFieldName: 'baz',
};
}),
} as unknown as DataViewsContract;
const actual = await queryStateToExpressionAst({
const actual = await textBasedQueryStateToExpressionAst({
filters: [],
query: { sql: 'SELECT * FROM foo' },
time: {
from: 'now',
to: 'now+7d',
},
dataViewsService,
});

expect(actual).toHaveProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import {
isOfAggregateQueryType,
getAggregateQueryMode,
getIndexPatternFromSQLQuery,
Query,
} from '@kbn/es-query';
import { isOfAggregateQueryType, getAggregateQueryMode, Query } from '@kbn/es-query';
import { buildExpression, buildExpressionFunction } from '@kbn/expressions-plugin/common';
import type { DataViewsContract } from '@kbn/data-views-plugin/common';
import {
ExpressionFunctionKibana,
ExpressionFunctionKibanaContext,
Expand All @@ -24,7 +18,7 @@ import {
} from '..';

interface Args extends QueryState {
dataViewsService: DataViewsContract;
timeFieldName?: string;
inputQuery?: Query;
}

Expand All @@ -34,12 +28,12 @@ interface Args extends QueryState {
* @param query kibana query or aggregate query
* @param time kibana time range
*/
export async function queryStateToExpressionAst({
export function textBasedQueryStateToExpressionAst({
filters,
query,
inputQuery,
time,
dataViewsService,
timeFieldName,
}: Args) {
const kibana = buildExpressionFunction<ExpressionFunctionKibana>('kibana', {});
let q;
Expand All @@ -52,24 +46,15 @@ export async function queryStateToExpressionAst({
filters: filters && filtersToAst(filters),
});
const ast = buildExpression([kibana, kibanaContext]).toAst();

if (query && isOfAggregateQueryType(query)) {
const mode = getAggregateQueryMode(query);
// sql query
if (mode === 'sql' && 'sql' in query) {
const idxPattern = getIndexPatternFromSQLQuery(query.sql);
const idsTitles = await dataViewsService.getIdsWithTitle();
const dataViewIdTitle = idsTitles.find(({ title }) => title === idxPattern);

if (dataViewIdTitle) {
const dataView = await dataViewsService.get(dataViewIdTitle.id);
const timeFieldName = dataView.timeFieldName;
const essql = aggregateQueryToAst(query, timeFieldName);
const essql = aggregateQueryToAst(query, timeFieldName);

if (essql) {
ast.chain.push(essql);
}
} else {
throw new Error(`No data view found for index pattern ${idxPattern}`);
if (essql) {
ast.chain.push(essql);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import { DataViewsContract } from '@kbn/data-views-plugin/common';
import { textBasedQueryStateToAstWithValidation } from './text_based_query_state_to_ast_with_validation';

describe('textBasedQueryStateToAstWithValidation', () => {
it('returns undefined for a non text based query', async () => {
const dataViewsService = {} as unknown as DataViewsContract;
const actual = await textBasedQueryStateToAstWithValidation({
filters: [],
query: { language: 'lucene', query: '' },
time: {
from: 'now',
to: 'now+7d',
},
dataViewsService,
});

expect(actual).toBeUndefined();
});

it('returns an object with the correct structure for an SQL query with existing dataview', async () => {
const dataViewsService = {
getIdsWithTitle: jest.fn(() => {
return [
{
title: 'foo',
id: 'bar',
},
];
}),
get: jest.fn(() => {
return {
title: 'foo',
id: 'bar',
timeFieldName: 'baz',
};
}),
} as unknown as DataViewsContract;
const actual = await textBasedQueryStateToAstWithValidation({
filters: [],
query: { sql: 'SELECT * FROM foo' },
time: {
from: 'now',
to: 'now+7d',
},
dataViewsService,
});

expect(actual).toHaveProperty(
'chain.1.arguments.timeRange.0.chain.0.arguments',
expect.objectContaining({
from: ['now'],
to: ['now+7d'],
})
);

expect(actual).toHaveProperty(
'chain.2.arguments',
expect.objectContaining({
query: ['SELECT * FROM foo'],
})
);
});

it('returns an error for text based language with non existing dataview', async () => {
const dataViewsService = {
getIdsWithTitle: jest.fn(() => {
return [
{
title: 'foo',
id: 'bar',
},
];
}),
get: jest.fn(() => {
return {
title: 'foo',
id: 'bar',
timeFieldName: 'baz',
};
}),
} as unknown as DataViewsContract;

await expect(
textBasedQueryStateToAstWithValidation({
filters: [],
query: { sql: 'SELECT * FROM another_dataview' },
time: {
from: 'now',
to: 'now+7d',
},
dataViewsService,
})
).rejects.toThrow('No data view found for index pattern another_dataview');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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 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 or the Server
* Side Public License, v 1.
*/
import {
isOfAggregateQueryType,
getIndexPatternFromSQLQuery,
Query,
AggregateQuery,
} from '@kbn/es-query';
import type { DataViewsContract } from '@kbn/data-views-plugin/common';
import type { QueryState } from '..';
import { textBasedQueryStateToExpressionAst } from './text_based_query_state_to_ast';

interface Args extends QueryState {
dataViewsService: DataViewsContract;
inputQuery?: Query;
}

const getIndexPatternFromAggregateQuery = (query: AggregateQuery) => {
if ('sql' in query) {
return getIndexPatternFromSQLQuery(query.sql);
}
};

/**
* Converts QueryState to expression AST
* @param filters array of kibana filters
* @param query kibana query or aggregate query
* @param time kibana time range
*/
export async function textBasedQueryStateToAstWithValidation({
filters,
query,
inputQuery,
time,
dataViewsService,
}: Args) {
let ast;
if (query && isOfAggregateQueryType(query)) {
// sql query
const idxPattern = getIndexPatternFromAggregateQuery(query);
const idsTitles = await dataViewsService.getIdsWithTitle();
const dataViewIdTitle = idsTitles.find(({ title }) => title === idxPattern);

if (dataViewIdTitle) {
const dataView = await dataViewsService.get(dataViewIdTitle.id);
const timeFieldName = dataView.timeFieldName;

ast = textBasedQueryStateToExpressionAst({
filters,
query,
inputQuery,
time,
timeFieldName,
});
} else {
throw new Error(`No data view found for index pattern ${idxPattern}`);
}
}
return ast;
}
Loading

0 comments on commit a801588

Please sign in to comment.