[data views / ES|QL] Set type on esql related data views (#172622)

## Summary

Identify ES|QL data views as such by setting type attribute. Also
creates `data-view-utils` package so dependency annoyances can be
avoided by consumers.

Part of https://github.com/elastic/kibana/issues/168131

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
Matthew Kime 2024-02-07 11:27:25 -06:00 committed by GitHub
parent 8a8cd0025d
commit 6f340bccc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 83 additions and 49 deletions

1
.github/CODEOWNERS vendored
View file

@ -324,6 +324,7 @@ src/plugins/data_view_editor @elastic/kibana-data-discovery
examples/data_view_field_editor_example @elastic/kibana-data-discovery
src/plugins/data_view_field_editor @elastic/kibana-data-discovery
src/plugins/data_view_management @elastic/kibana-data-discovery
packages/kbn-data-view-utils @elastic/kibana-data-discovery
src/plugins/data_views @elastic/kibana-data-discovery
x-pack/plugins/data_visualizer @elastic/ml-ui
x-pack/plugins/dataset_quality @elastic/obs-ux-logs-team

View file

@ -376,6 +376,7 @@
"@kbn/data-view-field-editor-example-plugin": "link:examples/data_view_field_editor_example",
"@kbn/data-view-field-editor-plugin": "link:src/plugins/data_view_field_editor",
"@kbn/data-view-management-plugin": "link:src/plugins/data_view_management",
"@kbn/data-view-utils": "link:packages/kbn-data-view-utils",
"@kbn/data-views-plugin": "link:src/plugins/data_views",
"@kbn/data-visualizer-plugin": "link:x-pack/plugins/data_visualizer",
"@kbn/dataset-quality-plugin": "link:x-pack/plugins/dataset_quality",

View file

@ -0,0 +1,3 @@
# @kbn/data-view-utils
Data View utilities.

View file

@ -0,0 +1,9 @@
/*
* 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.
*/
export * from './src/constants';

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-data-view-utils'],
};

View file

@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/data-view-utils",
"owner": "@elastic/kibana-data-discovery"
}

View file

@ -0,0 +1,7 @@
{
"name": "@kbn/data-view-utils",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false
}

View file

@ -0,0 +1,13 @@
/*
* 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.
*/
/**
* ESQL type constant
*/
export const ESQL_TYPE = 'esql';

View file

@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
},
"include": [
"**/*.ts",
"**/*.tsx",
],
"exclude": [
"target/**/*"
]
}

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { ESQL_TYPE } from '@kbn/data-view-utils';
// uses browser sha256 method with fallback if unavailable
async function sha256(str: string) {
@ -32,6 +33,7 @@ export async function getESQLAdHocDataview(
) {
return await dataViewsService.create({
title: indexPattern,
type: ESQL_TYPE,
id: await sha256(`esql-${indexPattern}`),
});
}

View file

@ -18,5 +18,6 @@
"kbn_references": [
"@kbn/data-views-plugin",
"@kbn/crypto-browser",
"@kbn/data-view-utils",
]
}

View file

@ -13,7 +13,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { firstValueFrom, from } from 'rxjs';
import { getKbnServerError } from '@kbn/kibana-utils-plugin/server';
import { IAsyncSearchRequestParams } from '../..';
import { getKbnSearchError, KbnSearchError } from '../../report_search_error';
import { getKbnSearchError } from '../../report_search_error';
import type { ISearchStrategy, SearchStrategyDependencies } from '../../types';
import type {
IAsyncSearchOptions,
@ -170,14 +170,11 @@ export const enhancedEsSearchStrategyProvider = (
*/
search: (request, options: IAsyncSearchOptions, deps) => {
logger.debug(`search ${JSON.stringify(request.params) || request.id}`);
if (request.indexType && request.indexType !== 'rollup') {
throw new KbnSearchError('Unknown indexType', 400);
}
if (request.indexType === undefined || !deps.rollupsEnabled) {
return asyncSearch(request, options, deps);
} else {
if (request.indexType === 'rollup' && deps.rollupsEnabled) {
return from(rollupSearch(request, options, deps));
} else {
return asyncSearch(request, options, deps);
}
},
/**

View file

@ -642,6 +642,8 @@
"@kbn/data-view-field-editor-plugin/*": ["src/plugins/data_view_field_editor/*"],
"@kbn/data-view-management-plugin": ["src/plugins/data_view_management"],
"@kbn/data-view-management-plugin/*": ["src/plugins/data_view_management/*"],
"@kbn/data-view-utils": ["packages/kbn-data-view-utils"],
"@kbn/data-view-utils/*": ["packages/kbn-data-view-utils/*"],
"@kbn/data-views-plugin": ["src/plugins/data_views"],
"@kbn/data-views-plugin/*": ["src/plugins/data_views/*"],
"@kbn/data-visualizer-plugin": ["x-pack/plugins/data_visualizer"],

View file

@ -269,26 +269,6 @@ export default function ({ getService }: FtrProviderContext) {
verifyErrorResponse(resp.body, 400, 'Request must contain a kbn-xsrf header.');
});
it('should return 400 when unknown index type is provided', async () => {
const resp = await supertest
.post(`/internal/search/ese`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.set('kbn-xsrf', 'foo')
.send({
indexType: 'baad',
params: {
body: {
query: {
match_all: {},
},
},
},
})
.expect(400);
verifyErrorResponse(resp.body, 400, 'Unknown indexType');
});
it('should return 400 if invalid id is provided', async () => {
const resp = await supertest
.post(`/internal/search/ese/123`)

View file

@ -222,28 +222,6 @@ export default function ({ getService }: FtrProviderContext) {
verifyErrorResponse(resp.body, 400, 'Request must contain a kbn-xsrf header.');
});
it('should return 400 when unknown index type is provided', async () => {
const resp = await supertest
.post(`/internal/search/ese`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
// TODO: API requests in Serverless require internal request headers
.set(svlCommonApi.getInternalRequestHeader())
.set('kbn-xsrf', 'foo')
.send({
indexType: 'baad',
params: {
body: {
query: {
match_all: {},
},
},
},
})
.expect(400);
verifyErrorResponse(resp.body, 400, 'Unknown indexType');
});
it('should return 400 if invalid id is provided', async () => {
const resp = await supertest
.post(`/internal/search/ese/123`)

View file

@ -4348,6 +4348,10 @@
version "0.0.0"
uid ""
"@kbn/data-view-utils@link:packages/kbn-data-view-utils":
version "0.0.0"
uid ""
"@kbn/data-views-plugin@link:src/plugins/data_views":
version "0.0.0"
uid ""