diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index dea2c12756b08..9e31bd31b4037 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -66,6 +66,7 @@
# APM
/x-pack/plugins/apm/ @elastic/apm-ui
/x-pack/test/functional/apps/apm/ @elastic/apm-ui
+/x-pack/test/apm_api_integration/ @elastic/apm-ui
/src/plugins/apm_oss/ @elastic/apm-ui
/src/apm.js @elastic/kibana-core @vigneshshanmugam
/packages/kbn-apm-config-loader/ @elastic/kibana-core @vigneshshanmugam
@@ -80,6 +81,7 @@
/x-pack/plugins/apm/server/lib/rum_client @elastic/uptime
/x-pack/plugins/apm/server/routes/rum_client.ts @elastic/uptime
/x-pack/plugins/apm/server/projections/rum_page_load_transactions.ts @elastic/uptime
+/x-pack/test/apm_api_integration/tests/csm/ @elastic/uptime
# Beats
/x-pack/plugins/beats_management/ @elastic/beats
@@ -99,7 +101,7 @@
# Observability UIs
/x-pack/plugins/infra/ @elastic/logs-metrics-ui
-/x-pack/plugins/fleet/ @elastic/ingest-management
+/x-pack/plugins/fleet/ @elastic/fleet
/x-pack/plugins/observability/ @elastic/observability-ui
/x-pack/plugins/monitoring/ @elastic/stack-monitoring-ui
/x-pack/plugins/uptime @elastic/uptime
diff --git a/.github/paths-labeller.yml b/.github/paths-labeller.yml
index f74870578ecb1..81d57be9b2d95 100644
--- a/.github/paths-labeller.yml
+++ b/.github/paths-labeller.yml
@@ -10,7 +10,7 @@
- "src/plugins/bfetch/**/*.*"
- "Team:apm":
- "x-pack/plugins/apm/**/*.*"
- - "Team:Ingest Management":
+ - "Team:Fleet":
- "x-pack/plugins/fleet/**/*.*"
- "x-pack/test/fleet_api_integration/**/*.*"
- "Team:uptime":
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createindexaliasnotfounderror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createindexaliasnotfounderror.md
new file mode 100644
index 0000000000000..2b897db7bba4c
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createindexaliasnotfounderror.md
@@ -0,0 +1,22 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [createIndexAliasNotFoundError](./kibana-plugin-core-server.savedobjectserrorhelpers.createindexaliasnotfounderror.md)
+
+## SavedObjectsErrorHelpers.createIndexAliasNotFoundError() method
+
+Signature:
+
+```typescript
+static createIndexAliasNotFoundError(alias: string): DecoratedError;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| alias | string
| |
+
+Returns:
+
+`DecoratedError`
+
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decorateindexaliasnotfounderror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decorateindexaliasnotfounderror.md
new file mode 100644
index 0000000000000..c7e10fc42ead1
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decorateindexaliasnotfounderror.md
@@ -0,0 +1,23 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [decorateIndexAliasNotFoundError](./kibana-plugin-core-server.savedobjectserrorhelpers.decorateindexaliasnotfounderror.md)
+
+## SavedObjectsErrorHelpers.decorateIndexAliasNotFoundError() method
+
+Signature:
+
+```typescript
+static decorateIndexAliasNotFoundError(error: Error, alias: string): DecoratedError;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| error | Error
| |
+| alias | string
| |
+
+Returns:
+
+`DecoratedError`
+
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.isgeneralerror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.isgeneralerror.md
new file mode 100644
index 0000000000000..4b4ede2f77a7e
--- /dev/null
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.isgeneralerror.md
@@ -0,0 +1,22 @@
+
+
+[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [isGeneralError](./kibana-plugin-core-server.savedobjectserrorhelpers.isgeneralerror.md)
+
+## SavedObjectsErrorHelpers.isGeneralError() method
+
+Signature:
+
+```typescript
+static isGeneralError(error: Error | DecoratedError): boolean;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| error | Error | DecoratedError
| |
+
+Returns:
+
+`boolean`
+
diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md
index 9b69012ed5f12..2dc78f2df3a83 100644
--- a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md
+++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md
@@ -18,6 +18,7 @@ export declare class SavedObjectsErrorHelpers
| [createBadRequestError(reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.createbadrequesterror.md) | static
| |
| [createConflictError(type, id, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.createconflicterror.md) | static
| |
| [createGenericNotFoundError(type, id)](./kibana-plugin-core-server.savedobjectserrorhelpers.creategenericnotfounderror.md) | static
| |
+| [createIndexAliasNotFoundError(alias)](./kibana-plugin-core-server.savedobjectserrorhelpers.createindexaliasnotfounderror.md) | static
| |
| [createInvalidVersionError(versionInput)](./kibana-plugin-core-server.savedobjectserrorhelpers.createinvalidversionerror.md) | static
| |
| [createTooManyRequestsError(type, id)](./kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md) | static
| |
| [createUnsupportedTypeError(type)](./kibana-plugin-core-server.savedobjectserrorhelpers.createunsupportedtypeerror.md) | static
| |
@@ -27,6 +28,7 @@ export declare class SavedObjectsErrorHelpers
| [decorateEsUnavailableError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorateesunavailableerror.md) | static
| |
| [decorateForbiddenError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorateforbiddenerror.md) | static
| |
| [decorateGeneralError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorategeneralerror.md) | static
| |
+| [decorateIndexAliasNotFoundError(error, alias)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorateindexaliasnotfounderror.md) | static
| |
| [decorateNotAuthorizedError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratenotauthorizederror.md) | static
| |
| [decorateRequestEntityTooLargeError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoraterequestentitytoolargeerror.md) | static
| |
| [decorateTooManyRequestsError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md) | static
| |
@@ -35,6 +37,7 @@ export declare class SavedObjectsErrorHelpers
| [isEsCannotExecuteScriptError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isescannotexecutescripterror.md) | static
| |
| [isEsUnavailableError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isesunavailableerror.md) | static
| |
| [isForbiddenError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isforbiddenerror.md) | static
| |
+| [isGeneralError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isgeneralerror.md) | static
| |
| [isInvalidVersionError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isinvalidversionerror.md) | static
| |
| [isNotAuthorizedError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isnotauthorizederror.md) | static
| |
| [isNotFoundError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isnotfounderror.md) | static
| |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchinterceptor.handlesearcherror.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchinterceptor.handlesearcherror.md
index b5ac4a4e53887..5f8966f0227ac 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchinterceptor.handlesearcherror.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchinterceptor.handlesearcherror.md
@@ -7,14 +7,14 @@
Signature:
```typescript
-protected handleSearchError(e: any, timeoutSignal: AbortSignal, options?: ISearchOptions): Error;
+protected handleSearchError(e: KibanaServerError | AbortError, timeoutSignal: AbortSignal, options?: ISearchOptions): Error;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
-| e | any
| |
+| e | KibanaServerError | AbortError
| |
| timeoutSignal | AbortSignal
| |
| options | ISearchOptions
| |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch.md
index 8fd17e6b1a1d9..e96fe8b8e08dc 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch.md
@@ -4,8 +4,12 @@
## SearchSource.fetch() method
-Fetch this source and reject the returned Promise on error
+> Warning: This API is now obsolete.
+>
+> Use fetch$ instead
+>
+Fetch this source and reject the returned Promise on error
Signature:
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch_.md
new file mode 100644
index 0000000000000..bcf220a9a27e6
--- /dev/null
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.fetch_.md
@@ -0,0 +1,24 @@
+
+
+[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [SearchSource](./kibana-plugin-plugins-data-public.searchsource.md) > [fetch$](./kibana-plugin-plugins-data-public.searchsource.fetch_.md)
+
+## SearchSource.fetch$() method
+
+Fetch this source from Elasticsearch, returning an observable over the response(s)
+
+Signature:
+
+```typescript
+fetch$(options?: ISearchOptions): import("rxjs").Observable>;
+```
+
+## Parameters
+
+| Parameter | Type | Description |
+| --- | --- | --- |
+| options | ISearchOptions
| |
+
+Returns:
+
+`import("rxjs").Observable>`
+
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.md
index df302e9f3b0d3..2af9cc14e3668 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchsource.md
@@ -33,6 +33,7 @@ export declare class SearchSource
| [createCopy()](./kibana-plugin-plugins-data-public.searchsource.createcopy.md) | | creates a copy of this search source (without its children) |
| [destroy()](./kibana-plugin-plugins-data-public.searchsource.destroy.md) | | Completely destroy the SearchSource. {undefined} |
| [fetch(options)](./kibana-plugin-plugins-data-public.searchsource.fetch.md) | | Fetch this source and reject the returned Promise on error |
+| [fetch$(options)](./kibana-plugin-plugins-data-public.searchsource.fetch_.md) | | Fetch this source from Elasticsearch, returning an observable over the response(s) |
| [getField(field, recurse)](./kibana-plugin-plugins-data-public.searchsource.getfield.md) | | Gets a single field from the fields |
| [getFields()](./kibana-plugin-plugins-data-public.searchsource.getfields.md) | | returns all search source fields |
| [getId()](./kibana-plugin-plugins-data-public.searchsource.getid.md) | | returns search source id |
diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchtimeouterror._constructor_.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchtimeouterror._constructor_.md
index 1c6370c7d0356..b4eecca665e82 100644
--- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchtimeouterror._constructor_.md
+++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.searchtimeouterror._constructor_.md
@@ -9,13 +9,13 @@ Constructs a new instance of the `SearchTimeoutError` class
Signature:
```typescript
-constructor(err: Error, mode: TimeoutErrorMode);
+constructor(err: Record, mode: TimeoutErrorMode);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
-| err | Error
| |
+| err | Record<string, any>
| |
| mode | TimeoutErrorMode
| |
diff --git a/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts b/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
index 56c75c5aca419..6272d6ba00ee8 100644
--- a/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
+++ b/packages/kbn-es-archiver/src/actions/empty_kibana_index.ts
@@ -25,5 +25,6 @@ export async function emptyKibanaIndexAction({
await cleanKibanaIndices({ client, stats, log, kibanaPluginIds });
await migrateKibanaIndex({ client, kbnClient });
- return stats;
+ stats.createdIndex('.kibana');
+ return stats.toJSON();
}
diff --git a/packages/kbn-es-archiver/src/es_archiver.ts b/packages/kbn-es-archiver/src/es_archiver.ts
index f101c5d6867f1..8601dedad0e27 100644
--- a/packages/kbn-es-archiver/src/es_archiver.ts
+++ b/packages/kbn-es-archiver/src/es_archiver.ts
@@ -155,7 +155,7 @@ export class EsArchiver {
* @return Promise
*/
async emptyKibanaIndex() {
- await emptyKibanaIndexAction({
+ return await emptyKibanaIndexAction({
client: this.client,
log: this.log,
kbnClient: this.kbnClient,
diff --git a/packages/kbn-es-archiver/src/lib/indices/kibana_index.ts b/packages/kbn-es-archiver/src/lib/indices/kibana_index.ts
index 0459a4301cf6b..91c0bd8343a36 100644
--- a/packages/kbn-es-archiver/src/lib/indices/kibana_index.ts
+++ b/packages/kbn-es-archiver/src/lib/indices/kibana_index.ts
@@ -76,7 +76,9 @@ export async function migrateKibanaIndex({
*/
async function fetchKibanaIndices(client: Client) {
const kibanaIndices = await client.cat.indices({ index: '.kibana*', format: 'json' });
- const isKibanaIndex = (index: string) => /^\.kibana(:?_\d*)?$/.test(index);
+ const isKibanaIndex = (index: string) =>
+ /^\.kibana(:?_\d*)?$/.test(index) ||
+ /^\.kibana(_task_manager)?_(pre)?\d+\.\d+\.\d+/.test(index);
return kibanaIndices.map((x: { index: string }) => x.index).filter(isKibanaIndex);
}
@@ -103,7 +105,7 @@ export async function cleanKibanaIndices({
while (true) {
const resp = await client.deleteByQuery({
- index: `.kibana`,
+ index: `.kibana,.kibana_task_manager`,
body: {
query: {
bool: {
@@ -115,7 +117,7 @@ export async function cleanKibanaIndices({
},
},
},
- ignore: [409],
+ ignore: [404, 409],
});
if (resp.total !== resp.deleted) {
diff --git a/packages/kbn-legacy-logging/src/setup_logging.test.ts b/packages/kbn-legacy-logging/src/setup_logging.test.ts
new file mode 100644
index 0000000000000..6386b400329b9
--- /dev/null
+++ b/packages/kbn-legacy-logging/src/setup_logging.test.ts
@@ -0,0 +1,35 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { Server } from '@hapi/hapi';
+import { reconfigureLogging, setupLogging } from './setup_logging';
+import { LegacyLoggingConfig } from './schema';
+
+describe('reconfigureLogging', () => {
+ test(`doesn't throw an error`, () => {
+ const server = new Server();
+ const config: LegacyLoggingConfig = {
+ silent: false,
+ quiet: false,
+ verbose: true,
+ events: {},
+ dest: '/tmp/foo',
+ filter: {},
+ json: true,
+ rotate: {
+ enabled: false,
+ everyBytes: 0,
+ keepFiles: 0,
+ pollingInterval: 0,
+ usePolling: false,
+ },
+ };
+ setupLogging(server, config, 10);
+ reconfigureLogging(server, { ...config, dest: '/tmp/bar' }, 0);
+ });
+});
diff --git a/packages/kbn-legacy-logging/src/setup_logging.ts b/packages/kbn-legacy-logging/src/setup_logging.ts
index 4370e4ab77d68..ffe3be558f366 100644
--- a/packages/kbn-legacy-logging/src/setup_logging.ts
+++ b/packages/kbn-legacy-logging/src/setup_logging.ts
@@ -37,5 +37,5 @@ export function reconfigureLogging(
opsInterval: number
) {
const loggingOptions = getLoggingConfiguration(config, opsInterval);
- (server.plugins as any)['@elastic/good'].reconfigure(loggingOptions);
+ (server.plugins as any).good.reconfigure(loggingOptions);
}
diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml
index a13976d148738..794503656ba04 100644
--- a/packages/kbn-optimizer/limits.yml
+++ b/packages/kbn-optimizer/limits.yml
@@ -34,7 +34,7 @@ pageLoadAssetSize:
indexLifecycleManagement: 107090
indexManagement: 140608
indexPatternManagement: 154222
- infra: 197873
+ infra: 204800
fleet: 415829
ingestPipelines: 58003
inputControlVis: 172675
diff --git a/src/core/server/saved_objects/migrationsv2/model.test.ts b/src/core/server/saved_objects/migrationsv2/model.test.ts
index d5ab85c54a728..a9aa69960b1c2 100644
--- a/src/core/server/saved_objects/migrationsv2/model.test.ts
+++ b/src/core/server/saved_objects/migrationsv2/model.test.ts
@@ -182,6 +182,21 @@ describe('migrations v2 model', () => {
versionAlias: '.kibana_7.11.0',
versionIndex: '.kibana_7.11.0_001',
};
+ const mappingsWithUnknownType = {
+ properties: {
+ disabled_saved_object_type: {
+ properties: {
+ value: { type: 'keyword' },
+ },
+ },
+ },
+ _meta: {
+ migrationMappingPropertyHashes: {
+ disabled_saved_object_type: '7997cf5a56cc02bdc9c93361bde732b0',
+ },
+ },
+ };
+
test('INIT -> OUTDATED_DOCUMENTS_SEARCH if .kibana is already pointing to the target index', () => {
const res: ResponseType<'INIT'> = Either.right({
'.kibana_7.11.0_001': {
@@ -189,38 +204,27 @@ describe('migrations v2 model', () => {
'.kibana': {},
'.kibana_7.11.0': {},
},
- mappings: {
- properties: {
- disabled_saved_object_type: {
- properties: {
- value: { type: 'keyword' },
- },
- },
- },
- _meta: {
- migrationMappingPropertyHashes: {
- disabled_saved_object_type: '7997cf5a56cc02bdc9c93361bde732b0',
- },
- },
- },
+ mappings: mappingsWithUnknownType,
settings: {},
},
});
const newState = model(initState, res);
expect(newState.controlState).toEqual('OUTDATED_DOCUMENTS_SEARCH');
+ // This snapshot asserts that we merge the
+ // migrationMappingPropertyHashes of the existing index, but we leave
+ // the mappings for the disabled_saved_object_type untouched. There
+ // might be another Kibana instance that knows about this type and
+ // needs these mappings in place.
expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
Object {
"_meta": Object {
"migrationMappingPropertyHashes": Object {
+ "disabled_saved_object_type": "7997cf5a56cc02bdc9c93361bde732b0",
"new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
},
},
"properties": Object {
- "disabled_saved_object_type": Object {
- "dynamic": false,
- "properties": Object {},
- },
"new_saved_object_type": Object {
"properties": Object {
"value": Object {
@@ -271,7 +275,7 @@ describe('migrations v2 model', () => {
'.kibana': {},
'.kibana_7.12.0': {},
},
- mappings: { properties: {}, _meta: { migrationMappingPropertyHashes: {} } },
+ mappings: mappingsWithUnknownType,
settings: {},
},
'.kibana_7.11.0_001': {
@@ -288,12 +292,37 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('.kibana_7.invalid.0_001'),
targetIndex: '.kibana_7.11.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
});
test('INIT -> SET_SOURCE_WRITE_BLOCK when migrating from a v2 migrations index (>= 7.11.0)', () => {
const res: ResponseType<'INIT'> = Either.right({
'.kibana_7.11.0_001': {
aliases: { '.kibana': {}, '.kibana_7.11.0': {} },
- mappings: { properties: {}, _meta: { migrationMappingPropertyHashes: {} } },
+ mappings: mappingsWithUnknownType,
settings: {},
},
'.kibana_3': {
@@ -319,6 +348,31 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('.kibana_7.11.0_001'),
targetIndex: '.kibana_7.12.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
@@ -328,7 +382,7 @@ describe('migrations v2 model', () => {
aliases: {
'.kibana': {},
},
- mappings: { properties: {}, _meta: { migrationMappingPropertyHashes: {} } },
+ mappings: mappingsWithUnknownType,
settings: {},
},
});
@@ -339,6 +393,31 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('.kibana_3'),
targetIndex: '.kibana_7.11.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
@@ -346,7 +425,7 @@ describe('migrations v2 model', () => {
const res: ResponseType<'INIT'> = Either.right({
'.kibana': {
aliases: {},
- mappings: { properties: {}, _meta: {} },
+ mappings: mappingsWithUnknownType,
settings: {},
},
});
@@ -357,6 +436,31 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('.kibana_pre6.5.0_001'),
targetIndex: '.kibana_7.11.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
@@ -366,7 +470,7 @@ describe('migrations v2 model', () => {
aliases: {
'my-saved-objects': {},
},
- mappings: { properties: {}, _meta: { migrationMappingPropertyHashes: {} } },
+ mappings: mappingsWithUnknownType,
settings: {},
},
});
@@ -386,6 +490,31 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('my-saved-objects_3'),
targetIndex: 'my-saved-objects_7.11.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
@@ -395,7 +524,7 @@ describe('migrations v2 model', () => {
aliases: {
'my-saved-objects': {},
},
- mappings: { properties: {}, _meta: { migrationMappingPropertyHashes: {} } },
+ mappings: mappingsWithUnknownType,
settings: {},
},
});
@@ -416,6 +545,31 @@ describe('migrations v2 model', () => {
sourceIndex: Option.some('my-saved-objects_7.11.0'),
targetIndex: 'my-saved-objects_7.12.0_001',
});
+ // This snapshot asserts that we disable the unknown saved object
+ // type. Because it's mappings are disabled, we also don't copy the
+ // `_meta.migrationMappingPropertyHashes` for the disabled type.
+ expect(newState.targetIndexMappings).toMatchInlineSnapshot(`
+ Object {
+ "_meta": Object {
+ "migrationMappingPropertyHashes": Object {
+ "new_saved_object_type": "4a11183eee21e6fbad864f7a30b39ad0",
+ },
+ },
+ "properties": Object {
+ "disabled_saved_object_type": Object {
+ "dynamic": false,
+ "properties": Object {},
+ },
+ "new_saved_object_type": Object {
+ "properties": Object {
+ "value": Object {
+ "type": "text",
+ },
+ },
+ },
+ },
+ }
+ `);
expect(newState.retryCount).toEqual(0);
expect(newState.retryDelay).toEqual(0);
});
diff --git a/src/core/server/saved_objects/migrationsv2/model.ts b/src/core/server/saved_objects/migrationsv2/model.ts
index 1119edde8e268..3556bb611bb67 100644
--- a/src/core/server/saved_objects/migrationsv2/model.ts
+++ b/src/core/server/saved_objects/migrationsv2/model.ts
@@ -60,13 +60,13 @@ function throwBadResponse(state: State, res: any): never {
* Merge the _meta.migrationMappingPropertyHashes mappings of an index with
* the given target mappings.
*
- * @remarks Mapping updates are commutative (deeply merged) by Elasticsearch,
- * except for the _meta key. The source index we're migrating from might
- * contain documents created by a plugin that is disabled in the Kibana
- * instance performing this migration. We merge the
- * _meta.migrationMappingPropertyHashes mappings from the source index into
- * the targetMappings to ensure that any `migrationPropertyHashes` for
- * disabled plugins aren't lost.
+ * @remarks When another instance already completed a migration, the existing
+ * target index might contain documents and mappings created by a plugin that
+ * is disabled in the current Kibana instance performing this migration.
+ * Mapping updates are commutative (deeply merged) by Elasticsearch, except
+ * for the `_meta` key. By merging the `_meta.migrationMappingPropertyHashes`
+ * mappings from the existing target index index into the targetMappings we
+ * ensure that any `migrationPropertyHashes` for disabled plugins aren't lost.
*
* Right now we don't use these `migrationPropertyHashes` but it could be used
* in the future to detect if mappings were changed. If mappings weren't
@@ -209,7 +209,7 @@ export const model = (currentState: State, resW: ResponseType):
// index
sourceIndex: Option.none,
targetIndex: `${stateP.indexPrefix}_${stateP.kibanaVersion}_001`,
- targetIndexMappings: disableUnknownTypeMappingFields(
+ targetIndexMappings: mergeMigrationMappingPropertyHashes(
stateP.targetIndexMappings,
indices[aliases[stateP.currentAlias]].mappings
),
@@ -242,7 +242,7 @@ export const model = (currentState: State, resW: ResponseType):
controlState: 'SET_SOURCE_WRITE_BLOCK',
sourceIndex: Option.some(source) as Option.Some,
targetIndex: target,
- targetIndexMappings: mergeMigrationMappingPropertyHashes(
+ targetIndexMappings: disableUnknownTypeMappingFields(
stateP.targetIndexMappings,
indices[source].mappings
),
@@ -279,7 +279,7 @@ export const model = (currentState: State, resW: ResponseType):
controlState: 'LEGACY_SET_WRITE_BLOCK',
sourceIndex: Option.some(legacyReindexTarget) as Option.Some,
targetIndex: target,
- targetIndexMappings: mergeMigrationMappingPropertyHashes(
+ targetIndexMappings: disableUnknownTypeMappingFields(
stateP.targetIndexMappings,
indices[stateP.legacyIndex].mappings
),
diff --git a/src/core/server/saved_objects/routes/bulk_create.ts b/src/core/server/saved_objects/routes/bulk_create.ts
index 6d57eaa3777e6..b85747985e523 100644
--- a/src/core/server/saved_objects/routes/bulk_create.ts
+++ b/src/core/server/saved_objects/routes/bulk_create.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -44,7 +45,7 @@ export const registerBulkCreateRoute = (router: IRouter, { coreUsageData }: Rout
),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { overwrite } = req.query;
const usageStatsClient = coreUsageData.getClient();
diff --git a/src/core/server/saved_objects/routes/bulk_get.ts b/src/core/server/saved_objects/routes/bulk_get.ts
index a260301633668..580bf26a4e529 100644
--- a/src/core/server/saved_objects/routes/bulk_get.ts
+++ b/src/core/server/saved_objects/routes/bulk_get.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -28,7 +29,7 @@ export const registerBulkGetRoute = (router: IRouter, { coreUsageData }: RouteDe
),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkGet({ request: req }).catch(() => {});
diff --git a/src/core/server/saved_objects/routes/bulk_update.ts b/src/core/server/saved_objects/routes/bulk_update.ts
index f9b8d4a2f567f..e592adc72a244 100644
--- a/src/core/server/saved_objects/routes/bulk_update.ts
+++ b/src/core/server/saved_objects/routes/bulk_update.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -39,7 +40,7 @@ export const registerBulkUpdateRoute = (router: IRouter, { coreUsageData }: Rout
),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const usageStatsClient = coreUsageData.getClient();
usageStatsClient.incrementSavedObjectsBulkUpdate({ request: req }).catch(() => {});
diff --git a/src/core/server/saved_objects/routes/create.ts b/src/core/server/saved_objects/routes/create.ts
index fd256abac3526..f6043ca96398d 100644
--- a/src/core/server/saved_objects/routes/create.ts
+++ b/src/core/server/saved_objects/routes/create.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -43,7 +44,7 @@ export const registerCreateRoute = (router: IRouter, { coreUsageData }: RouteDep
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { type, id } = req.params;
const { overwrite } = req.query;
const {
diff --git a/src/core/server/saved_objects/routes/delete.ts b/src/core/server/saved_objects/routes/delete.ts
index a7846c3dc845b..b127f64b74a0c 100644
--- a/src/core/server/saved_objects/routes/delete.ts
+++ b/src/core/server/saved_objects/routes/delete.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -28,7 +29,7 @@ export const registerDeleteRoute = (router: IRouter, { coreUsageData }: RouteDep
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { type, id } = req.params;
const { force } = req.query;
diff --git a/src/core/server/saved_objects/routes/export.ts b/src/core/server/saved_objects/routes/export.ts
index 9b40855afec2e..f064cf1ca0ec1 100644
--- a/src/core/server/saved_objects/routes/export.ts
+++ b/src/core/server/saved_objects/routes/export.ts
@@ -18,7 +18,7 @@ import {
SavedObjectsExportByObjectOptions,
SavedObjectsExportError,
} from '../export';
-import { validateTypes, validateObjects } from './utils';
+import { validateTypes, validateObjects, catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
config: SavedObjectConfig;
@@ -163,7 +163,7 @@ export const registerExportRoute = (
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const cleaned = cleanOptions(req.body);
const supportedTypes = context.core.savedObjects.typeRegistry
.getImportableAndExportableTypes()
diff --git a/src/core/server/saved_objects/routes/find.ts b/src/core/server/saved_objects/routes/find.ts
index 747070e54e5ad..c814fd310dc52 100644
--- a/src/core/server/saved_objects/routes/find.ts
+++ b/src/core/server/saved_objects/routes/find.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -49,7 +50,7 @@ export const registerFindRoute = (router: IRouter, { coreUsageData }: RouteDepen
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const query = req.query;
const namespaces =
diff --git a/src/core/server/saved_objects/routes/get.ts b/src/core/server/saved_objects/routes/get.ts
index c66a11dcf0cdd..2dd812f35cefd 100644
--- a/src/core/server/saved_objects/routes/get.ts
+++ b/src/core/server/saved_objects/routes/get.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -25,7 +26,7 @@ export const registerGetRoute = (router: IRouter, { coreUsageData }: RouteDepend
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { type, id } = req.params;
const usageStatsClient = coreUsageData.getClient();
diff --git a/src/core/server/saved_objects/routes/import.ts b/src/core/server/saved_objects/routes/import.ts
index 6c4c759460ce3..5fd132acafbed 100644
--- a/src/core/server/saved_objects/routes/import.ts
+++ b/src/core/server/saved_objects/routes/import.ts
@@ -13,7 +13,7 @@ import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
import { SavedObjectConfig } from '../saved_objects_config';
import { SavedObjectsImportError } from '../import';
-import { createSavedObjectsStreamFromNdJson } from './utils';
+import { catchAndReturnBoomErrors, createSavedObjectsStreamFromNdJson } from './utils';
interface RouteDependencies {
config: SavedObjectConfig;
@@ -61,7 +61,7 @@ export const registerImportRoute = (
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { overwrite, createNewCopies } = req.query;
const usageStatsClient = coreUsageData.getClient();
diff --git a/src/core/server/saved_objects/routes/migrate.ts b/src/core/server/saved_objects/routes/migrate.ts
index 8b347d4725b08..7c2f4bfb06710 100644
--- a/src/core/server/saved_objects/routes/migrate.ts
+++ b/src/core/server/saved_objects/routes/migrate.ts
@@ -8,6 +8,7 @@
import { IRouter } from '../../http';
import { IKibanaMigrator } from '../migrations';
+import { catchAndReturnBoomErrors } from './utils';
export const registerMigrateRoute = (
router: IRouter,
@@ -21,7 +22,7 @@ export const registerMigrateRoute = (
tags: ['access:migrateSavedObjects'],
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const migrator = await migratorPromise;
await migrator.runMigrations({ rerun: true });
return res.ok({
diff --git a/src/core/server/saved_objects/routes/resolve_import_errors.ts b/src/core/server/saved_objects/routes/resolve_import_errors.ts
index 0cf976c30b311..6f0a3d028baf9 100644
--- a/src/core/server/saved_objects/routes/resolve_import_errors.ts
+++ b/src/core/server/saved_objects/routes/resolve_import_errors.ts
@@ -13,8 +13,7 @@ import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
import { SavedObjectConfig } from '../saved_objects_config';
import { SavedObjectsImportError } from '../import';
-import { createSavedObjectsStreamFromNdJson } from './utils';
-
+import { catchAndReturnBoomErrors, createSavedObjectsStreamFromNdJson } from './utils';
interface RouteDependencies {
config: SavedObjectConfig;
coreUsageData: CoreUsageDataSetup;
@@ -69,7 +68,7 @@ export const registerResolveImportErrorsRoute = (
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { createNewCopies } = req.query;
const usageStatsClient = coreUsageData.getClient();
diff --git a/src/core/server/saved_objects/routes/update.ts b/src/core/server/saved_objects/routes/update.ts
index 17cfd438d47bf..dbc69f743df76 100644
--- a/src/core/server/saved_objects/routes/update.ts
+++ b/src/core/server/saved_objects/routes/update.ts
@@ -9,6 +9,7 @@
import { schema } from '@kbn/config-schema';
import { IRouter } from '../../http';
import { CoreUsageDataSetup } from '../../core_usage_data';
+import { catchAndReturnBoomErrors } from './utils';
interface RouteDependencies {
coreUsageData: CoreUsageDataSetup;
@@ -38,7 +39,7 @@ export const registerUpdateRoute = (router: IRouter, { coreUsageData }: RouteDep
}),
},
},
- router.handleLegacyErrors(async (context, req, res) => {
+ catchAndReturnBoomErrors(async (context, req, res) => {
const { type, id } = req.params;
const { attributes, version, references } = req.body;
const options = { version, references };
diff --git a/src/core/server/saved_objects/routes/utils.test.ts b/src/core/server/saved_objects/routes/utils.test.ts
index ade7b03f6a8c2..1d7e86e288b18 100644
--- a/src/core/server/saved_objects/routes/utils.test.ts
+++ b/src/core/server/saved_objects/routes/utils.test.ts
@@ -9,6 +9,15 @@
import { createSavedObjectsStreamFromNdJson, validateTypes, validateObjects } from './utils';
import { Readable } from 'stream';
import { createPromiseFromStreams, createConcatStream } from '@kbn/utils';
+import { catchAndReturnBoomErrors } from './utils';
+import Boom from '@hapi/boom';
+import {
+ KibanaRequest,
+ RequestHandler,
+ RequestHandlerContext,
+ KibanaResponseFactory,
+ kibanaResponseFactory,
+} from '../../';
async function readStreamToCompletion(stream: Readable) {
return createPromiseFromStreams([stream, createConcatStream([])]);
@@ -143,3 +152,69 @@ describe('validateObjects', () => {
).toBeUndefined();
});
});
+
+describe('catchAndReturnBoomErrors', () => {
+ let context: RequestHandlerContext;
+ let request: KibanaRequest;
+ let response: KibanaResponseFactory;
+
+ const createHandler = (handler: () => any): RequestHandler => () => {
+ return handler();
+ };
+
+ beforeEach(() => {
+ context = {} as any;
+ request = {} as any;
+ response = kibanaResponseFactory;
+ });
+
+ it('should pass-though call parameters to the handler', async () => {
+ const handler = jest.fn();
+ const wrapped = catchAndReturnBoomErrors(handler);
+ await wrapped(context, request, response);
+ expect(handler).toHaveBeenCalledWith(context, request, response);
+ });
+
+ it('should pass-though result from the handler', async () => {
+ const handler = createHandler(() => {
+ return 'handler-response';
+ });
+ const wrapped = catchAndReturnBoomErrors(handler);
+ const result = await wrapped(context, request, response);
+ expect(result).toBe('handler-response');
+ });
+
+ it('should intercept and convert thrown Boom errors', async () => {
+ const handler = createHandler(() => {
+ throw Boom.notFound('not there');
+ });
+ const wrapped = catchAndReturnBoomErrors(handler);
+ const result = await wrapped(context, request, response);
+ expect(result.status).toBe(404);
+ expect(result.payload).toEqual({
+ error: 'Not Found',
+ message: 'not there',
+ statusCode: 404,
+ });
+ });
+
+ it('should re-throw non-Boom errors', async () => {
+ const handler = createHandler(() => {
+ throw new Error('something went bad');
+ });
+ const wrapped = catchAndReturnBoomErrors(handler);
+ await expect(wrapped(context, request, response)).rejects.toMatchInlineSnapshot(
+ `[Error: something went bad]`
+ );
+ });
+
+ it('should re-throw Boom internal/500 errors', async () => {
+ const handler = createHandler(() => {
+ throw Boom.internal();
+ });
+ const wrapped = catchAndReturnBoomErrors(handler);
+ await expect(wrapped(context, request, response)).rejects.toMatchInlineSnapshot(
+ `[Error: Internal Server Error]`
+ );
+ });
+});
diff --git a/src/core/server/saved_objects/routes/utils.ts b/src/core/server/saved_objects/routes/utils.ts
index b9e7df48a4b4c..269f3f0698561 100644
--- a/src/core/server/saved_objects/routes/utils.ts
+++ b/src/core/server/saved_objects/routes/utils.ts
@@ -7,7 +7,11 @@
*/
import { Readable } from 'stream';
-import { SavedObject, SavedObjectsExportResultDetails } from 'src/core/server';
+import {
+ RequestHandlerWrapper,
+ SavedObject,
+ SavedObjectsExportResultDetails,
+} from 'src/core/server';
import {
createSplitStream,
createMapStream,
@@ -16,6 +20,7 @@ import {
createListStream,
createConcatStream,
} from '@kbn/utils';
+import Boom from '@hapi/boom';
export async function createSavedObjectsStreamFromNdJson(ndJsonStream: Readable) {
const savedObjects = await createPromiseFromStreams([
@@ -52,3 +57,30 @@ export function validateObjects(
.join(', ')}`;
}
}
+
+/**
+ * Catches errors thrown by saved object route handlers and returns an error
+ * with the payload and statusCode of the boom error.
+ *
+ * This is very close to the core `router.handleLegacyErrors` except that it
+ * throws internal errors (statusCode: 500) so that the internal error's
+ * message get logged by Core.
+ *
+ * TODO: Remove once https://github.com/elastic/kibana/issues/65291 is fixed.
+ */
+export const catchAndReturnBoomErrors: RequestHandlerWrapper = (handler) => {
+ return async (context, request, response) => {
+ try {
+ return await handler(context, request, response);
+ } catch (e) {
+ if (Boom.isBoom(e) && e.output.statusCode !== 500) {
+ return response.customError({
+ body: e.output.payload,
+ statusCode: e.output.statusCode,
+ headers: e.output.headers as { [key: string]: string },
+ });
+ }
+ throw e;
+ }
+ };
+};
diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
index cc497ca6348b8..da1ebec2c0f7d 100644
--- a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
+++ b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts
@@ -109,6 +109,27 @@ describe('savedObjectsClient/decorateEsError', () => {
expect(SavedObjectsErrorHelpers.isNotFoundError(genericError)).toBe(true);
});
+ it('if saved objects index does not exist makes NotFound a SavedObjectsClient/generalError', () => {
+ const error = new esErrors.ResponseError(
+ elasticsearchClientMock.createApiResponse({
+ statusCode: 404,
+ body: {
+ error: {
+ reason:
+ 'no such index [.kibana_8.0.0] and [require_alias] request flag is [true] and [.kibana_8.0.0] is not an alias',
+ },
+ },
+ })
+ );
+ expect(SavedObjectsErrorHelpers.isGeneralError(error)).toBe(false);
+ const genericError = decorateEsError(error);
+ expect(genericError.message).toEqual(
+ `Saved object index alias [.kibana_8.0.0] not found: Response Error`
+ );
+ expect(genericError.output.statusCode).toBe(500);
+ expect(SavedObjectsErrorHelpers.isGeneralError(error)).toBe(true);
+ });
+
it('makes BadRequest a SavedObjectsClient/BadRequest error', () => {
const error = new esErrors.ResponseError(
elasticsearchClientMock.createApiResponse({ statusCode: 400 })
diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.ts
index 40f18c9c94c25..aabca2d602cb3 100644
--- a/src/core/server/saved_objects/service/lib/decorate_es_error.ts
+++ b/src/core/server/saved_objects/service/lib/decorate_es_error.ts
@@ -63,6 +63,12 @@ export function decorateEsError(error: EsErrors) {
}
if (responseErrors.isNotFound(error.statusCode)) {
+ const match = error?.meta?.body?.error?.reason?.match(
+ /no such index \[(.+)\] and \[require_alias\] request flag is \[true\] and \[.+\] is not an alias/
+ );
+ if (match?.length > 0) {
+ return SavedObjectsErrorHelpers.decorateIndexAliasNotFoundError(error, match[1]);
+ }
return SavedObjectsErrorHelpers.createGenericNotFoundError();
}
diff --git a/src/core/server/saved_objects/service/lib/errors.ts b/src/core/server/saved_objects/service/lib/errors.ts
index f216e72efbcf8..c348196aaba21 100644
--- a/src/core/server/saved_objects/service/lib/errors.ts
+++ b/src/core/server/saved_objects/service/lib/errors.ts
@@ -135,6 +135,19 @@ export class SavedObjectsErrorHelpers {
return decorate(Boom.notFound(), CODE_NOT_FOUND, 404);
}
+ public static createIndexAliasNotFoundError(alias: string) {
+ return SavedObjectsErrorHelpers.decorateIndexAliasNotFoundError(Boom.internal(), alias);
+ }
+
+ public static decorateIndexAliasNotFoundError(error: Error, alias: string) {
+ return decorate(
+ error,
+ CODE_GENERAL_ERROR,
+ 500,
+ `Saved object index alias [${alias}] not found`
+ );
+ }
+
public static isNotFoundError(error: Error | DecoratedError) {
return isSavedObjectsClientError(error) && error[code] === CODE_NOT_FOUND;
}
@@ -185,4 +198,8 @@ export class SavedObjectsErrorHelpers {
public static decorateGeneralError(error: Error, reason?: string) {
return decorate(error, CODE_GENERAL_ERROR, 500, reason);
}
+
+ public static isGeneralError(error: Error | DecoratedError) {
+ return isSavedObjectsClientError(error) && error[code] === CODE_GENERAL_ERROR;
+ }
}
diff --git a/src/core/server/saved_objects/service/lib/repository.test.js b/src/core/server/saved_objects/service/lib/repository.test.js
index 216e1c4bd2d3c..68fdea0f9eb25 100644
--- a/src/core/server/saved_objects/service/lib/repository.test.js
+++ b/src/core/server/saved_objects/service/lib/repository.test.js
@@ -18,6 +18,7 @@ import { DocumentMigrator } from '../../migrations/core/document_migrator';
import { mockKibanaMigrator } from '../../migrations/kibana/kibana_migrator.mock';
import { elasticsearchClientMock } from '../../../elasticsearch/client/mocks';
import { esKuery } from '../../es_query';
+import { errors as EsErrors } from '@elastic/elasticsearch';
const { nodeTypes } = esKuery;
jest.mock('./search_dsl/search_dsl', () => ({ getSearchDsl: jest.fn() }));
@@ -4341,8 +4342,14 @@ describe('SavedObjectsRepository', () => {
});
it(`throws when ES is unable to find the document during update`, async () => {
+ const notFoundError = new EsErrors.ResponseError(
+ elasticsearchClientMock.createApiResponse({
+ statusCode: 404,
+ body: { error: { type: 'es_type', reason: 'es_reason' } },
+ })
+ );
client.update.mockResolvedValueOnce(
- elasticsearchClientMock.createSuccessTransportRequestPromise({}, { statusCode: 404 })
+ elasticsearchClientMock.createErrorTransportRequestPromise(notFoundError)
);
await expectNotFoundError(type, id);
expect(client.update).toHaveBeenCalledTimes(1);
diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts
index 2993d4234bd2e..da80971635a93 100644
--- a/src/core/server/saved_objects/service/lib/repository.ts
+++ b/src/core/server/saved_objects/service/lib/repository.ts
@@ -299,6 +299,7 @@ export class SavedObjectsRepository {
refresh,
body: raw._source,
...(overwrite && version ? decodeRequestVersion(version) : {}),
+ require_alias: true,
};
const { body } =
@@ -469,6 +470,7 @@ export class SavedObjectsRepository {
const bulkResponse = bulkCreateParams.length
? await this.client.bulk({
refresh,
+ require_alias: true,
body: bulkCreateParams,
})
: undefined;
@@ -1117,8 +1119,8 @@ export class SavedObjectsRepository {
...(Array.isArray(references) && { references }),
};
- const { body, statusCode } = await this.client.update(
- {
+ const { body } = await this.client
+ .update({
id: this._serializer.generateRawId(namespace, type, id),
index: this.getIndexForType(type),
...getExpectedVersionProperties(version, preflightResult),
@@ -1128,14 +1130,15 @@ export class SavedObjectsRepository {
doc,
},
_source_includes: ['namespace', 'namespaces', 'originId'],
- },
- { ignore: [404] }
- );
-
- if (statusCode === 404) {
- // see "404s from missing index" above
- throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
- }
+ require_alias: true,
+ })
+ .catch((err) => {
+ if (SavedObjectsErrorHelpers.isNotFoundError(err)) {
+ // see "404s from missing index" above
+ throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
+ }
+ throw err;
+ });
const { originId } = body.get._source;
let namespaces = [];
@@ -1496,6 +1499,7 @@ export class SavedObjectsRepository {
refresh,
body: bulkUpdateParams,
_source_includes: ['originId'],
+ require_alias: true,
})
: undefined;
@@ -1712,6 +1716,7 @@ export class SavedObjectsRepository {
id: raw._id,
index: this.getIndexForType(type),
refresh,
+ require_alias: true,
_source: 'true',
body: {
script: {
@@ -1933,12 +1938,18 @@ export class SavedObjectsRepository {
}
}
-function getBulkOperationError(error: { type: string; reason?: string }, type: string, id: string) {
+function getBulkOperationError(
+ error: { type: string; reason?: string; index?: string },
+ type: string,
+ id: string
+) {
switch (error.type) {
case 'version_conflict_engine_exception':
return errorContent(SavedObjectsErrorHelpers.createConflictError(type, id));
case 'document_missing_exception':
return errorContent(SavedObjectsErrorHelpers.createGenericNotFoundError(type, id));
+ case 'index_not_found_exception':
+ return errorContent(SavedObjectsErrorHelpers.createIndexAliasNotFoundError(error.index!));
default:
return {
message: error.reason || JSON.stringify(error),
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index aadd16bde0ee6..9d5114e645f6e 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -2336,6 +2336,8 @@ export class SavedObjectsErrorHelpers {
// (undocumented)
static createGenericNotFoundError(type?: string | null, id?: string | null): DecoratedError;
// (undocumented)
+ static createIndexAliasNotFoundError(alias: string): DecoratedError;
+ // (undocumented)
static createInvalidVersionError(versionInput?: string): DecoratedError;
// (undocumented)
static createTooManyRequestsError(type: string, id: string): DecoratedError;
@@ -2354,6 +2356,8 @@ export class SavedObjectsErrorHelpers {
// (undocumented)
static decorateGeneralError(error: Error, reason?: string): DecoratedError;
// (undocumented)
+ static decorateIndexAliasNotFoundError(error: Error, alias: string): DecoratedError;
+ // (undocumented)
static decorateNotAuthorizedError(error: Error, reason?: string): DecoratedError;
// (undocumented)
static decorateRequestEntityTooLargeError(error: Error, reason?: string): DecoratedError;
@@ -2370,6 +2374,8 @@ export class SavedObjectsErrorHelpers {
// (undocumented)
static isForbiddenError(error: Error | DecoratedError): boolean;
// (undocumented)
+ static isGeneralError(error: Error | DecoratedError): boolean;
+ // (undocumented)
static isInvalidVersionError(error: Error | DecoratedError): boolean;
// (undocumented)
static isNotAuthorizedError(error: Error | DecoratedError): boolean;
diff --git a/src/core/server/ui_settings/integration_tests/doc_exists.ts b/src/core/server/ui_settings/integration_tests/doc_exists.ts
index aa6f98ddf2d03..d100b89af9609 100644
--- a/src/core/server/ui_settings/integration_tests/doc_exists.ts
+++ b/src/core/server/ui_settings/integration_tests/doc_exists.ts
@@ -8,7 +8,7 @@
import { getServices, chance } from './lib';
-export function docExistsSuite() {
+export const docExistsSuite = (savedObjectsIndex: string) => () => {
async function setup(options: any = {}) {
const { initialSettings } = options;
@@ -16,7 +16,7 @@ export function docExistsSuite() {
// delete the kibana index to ensure we start fresh
await callCluster('deleteByQuery', {
- index: kbnServer.config.get('kibana.index'),
+ index: savedObjectsIndex,
body: {
conflicts: 'proceed',
query: { match_all: {} },
@@ -212,4 +212,4 @@ export function docExistsSuite() {
});
});
});
-}
+};
diff --git a/src/core/server/ui_settings/integration_tests/doc_missing.ts b/src/core/server/ui_settings/integration_tests/doc_missing.ts
index 501976e3823f1..822ffe398b87d 100644
--- a/src/core/server/ui_settings/integration_tests/doc_missing.ts
+++ b/src/core/server/ui_settings/integration_tests/doc_missing.ts
@@ -8,7 +8,7 @@
import { getServices, chance } from './lib';
-export function docMissingSuite() {
+export const docMissingSuite = (savedObjectsIndex: string) => () => {
// ensure the kibana index has no documents
beforeEach(async () => {
const { kbnServer, callCluster } = getServices();
@@ -22,7 +22,7 @@ export function docMissingSuite() {
// delete all docs from kibana index to ensure savedConfig is not found
await callCluster('deleteByQuery', {
- index: kbnServer.config.get('kibana.index'),
+ index: savedObjectsIndex,
body: {
query: { match_all: {} },
},
@@ -136,4 +136,4 @@ export function docMissingSuite() {
});
});
});
-}
+};
diff --git a/src/core/server/ui_settings/integration_tests/doc_missing_and_index_read_only.ts b/src/core/server/ui_settings/integration_tests/doc_missing_and_index_read_only.ts
index b2ff1b2f1d4ab..997d51e36abdc 100644
--- a/src/core/server/ui_settings/integration_tests/doc_missing_and_index_read_only.ts
+++ b/src/core/server/ui_settings/integration_tests/doc_missing_and_index_read_only.ts
@@ -8,7 +8,7 @@
import { getServices, chance } from './lib';
-export function docMissingAndIndexReadOnlySuite() {
+export const docMissingAndIndexReadOnlySuite = (savedObjectsIndex: string) => () => {
// ensure the kibana index has no documents
beforeEach(async () => {
const { kbnServer, callCluster } = getServices();
@@ -22,7 +22,7 @@ export function docMissingAndIndexReadOnlySuite() {
// delete all docs from kibana index to ensure savedConfig is not found
await callCluster('deleteByQuery', {
- index: kbnServer.config.get('kibana.index'),
+ index: savedObjectsIndex,
body: {
query: { match_all: {} },
},
@@ -30,7 +30,7 @@ export function docMissingAndIndexReadOnlySuite() {
// set the index to read only
await callCluster('indices.putSettings', {
- index: kbnServer.config.get('kibana.index'),
+ index: savedObjectsIndex,
body: {
index: {
blocks: {
@@ -42,11 +42,11 @@ export function docMissingAndIndexReadOnlySuite() {
});
afterEach(async () => {
- const { kbnServer, callCluster } = getServices();
+ const { callCluster } = getServices();
// disable the read only block
await callCluster('indices.putSettings', {
- index: kbnServer.config.get('kibana.index'),
+ index: savedObjectsIndex,
body: {
index: {
blocks: {
@@ -142,4 +142,4 @@ export function docMissingAndIndexReadOnlySuite() {
});
});
});
-}
+};
diff --git a/src/core/server/ui_settings/integration_tests/index.test.ts b/src/core/server/ui_settings/integration_tests/index.test.ts
index f415f1d73de7d..e27e6c4e46874 100644
--- a/src/core/server/ui_settings/integration_tests/index.test.ts
+++ b/src/core/server/ui_settings/integration_tests/index.test.ts
@@ -6,20 +6,25 @@
* Public License, v 1.
*/
+import { Env } from '@kbn/config';
+import { REPO_ROOT } from '@kbn/dev-utils';
+import { getEnvOptions } from '@kbn/config/target/mocks';
import { startServers, stopServers } from './lib';
-
import { docExistsSuite } from './doc_exists';
import { docMissingSuite } from './doc_missing';
import { docMissingAndIndexReadOnlySuite } from './doc_missing_and_index_read_only';
+const kibanaVersion = Env.createDefault(REPO_ROOT, getEnvOptions()).packageInfo.version;
+const savedObjectIndex = `.kibana_${kibanaVersion}_001`;
+
describe('uiSettings/routes', function () {
jest.setTimeout(10000);
beforeAll(startServers);
/* eslint-disable jest/valid-describe */
- describe('doc missing', docMissingSuite);
- describe('doc missing and index readonly', docMissingAndIndexReadOnlySuite);
- describe('doc exists', docExistsSuite);
+ describe('doc missing', docMissingSuite(savedObjectIndex));
+ describe('doc missing and index readonly', docMissingAndIndexReadOnlySuite(savedObjectIndex));
+ describe('doc exists', docExistsSuite(savedObjectIndex));
/* eslint-enable jest/valid-describe */
afterAll(stopServers);
});
diff --git a/src/core/server/ui_settings/integration_tests/lib/servers.ts b/src/core/server/ui_settings/integration_tests/lib/servers.ts
index b5198b19007d0..f181272030ae1 100644
--- a/src/core/server/ui_settings/integration_tests/lib/servers.ts
+++ b/src/core/server/ui_settings/integration_tests/lib/servers.ts
@@ -37,9 +37,6 @@ export async function startServers() {
adjustTimeout: (t) => jest.setTimeout(t),
settings: {
kbn: {
- migrations: {
- enableV2: false,
- },
uiSettings: {
overrides: {
foo: 'bar',
diff --git a/src/core/test_helpers/kbn_server.ts b/src/core/test_helpers/kbn_server.ts
index 0007e1fcca0a5..6fe6819a0981a 100644
--- a/src/core/test_helpers/kbn_server.ts
+++ b/src/core/test_helpers/kbn_server.ts
@@ -40,7 +40,7 @@ const DEFAULTS_SETTINGS = {
},
logging: { silent: true },
plugins: {},
- migrations: { skip: true },
+ migrations: { skip: false },
};
const DEFAULT_SETTINGS_WITH_CORE_PLUGINS = {
diff --git a/src/plugins/dashboard/public/application/dashboard_app.tsx b/src/plugins/dashboard/public/application/dashboard_app.tsx
index 7ea181715717b..6955365ebca3f 100644
--- a/src/plugins/dashboard/public/application/dashboard_app.tsx
+++ b/src/plugins/dashboard/public/application/dashboard_app.tsx
@@ -265,6 +265,13 @@ export function DashboardApp({
};
}, [dashboardStateManager, dashboardContainer, onAppLeave, embeddable]);
+ // clear search session when leaving dashboard route
+ useEffect(() => {
+ return () => {
+ data.search.session.clear();
+ };
+ }, [data.search.session]);
+
return (
{savedDashboard && dashboardStateManager && dashboardContainer && viewMode && (
diff --git a/src/plugins/dashboard/server/index.ts b/src/plugins/dashboard/server/index.ts
index cc784f5f81c9e..4bd43d1cd64a9 100644
--- a/src/plugins/dashboard/server/index.ts
+++ b/src/plugins/dashboard/server/index.ts
@@ -25,3 +25,4 @@ export function plugin(initializerContext: PluginInitializerContext) {
}
export { DashboardPluginSetup, DashboardPluginStart } from './types';
+export { findByValueEmbeddables } from './usage/find_by_value_embeddables';
diff --git a/src/plugins/dashboard/server/usage/find_by_value_embeddables.test.ts b/src/plugins/dashboard/server/usage/find_by_value_embeddables.test.ts
new file mode 100644
index 0000000000000..3da6a8050f14c
--- /dev/null
+++ b/src/plugins/dashboard/server/usage/find_by_value_embeddables.test.ts
@@ -0,0 +1,60 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { SavedDashboardPanel730ToLatest } from '../../common';
+import { findByValueEmbeddables } from './find_by_value_embeddables';
+
+const visualizationByValue = ({
+ embeddableConfig: {
+ value: 'visualization-by-value',
+ },
+ type: 'visualization',
+} as unknown) as SavedDashboardPanel730ToLatest;
+
+const mapByValue = ({
+ embeddableConfig: {
+ value: 'map-by-value',
+ },
+ type: 'map',
+} as unknown) as SavedDashboardPanel730ToLatest;
+
+const embeddableByRef = ({
+ panelRefName: 'panel_ref_1',
+} as unknown) as SavedDashboardPanel730ToLatest;
+
+describe('findByValueEmbeddables', () => {
+ it('finds the by value embeddables for the given type', async () => {
+ const savedObjectsResult = {
+ saved_objects: [
+ {
+ attributes: {
+ panelsJSON: JSON.stringify([visualizationByValue, mapByValue, embeddableByRef]),
+ },
+ },
+ {
+ attributes: {
+ panelsJSON: JSON.stringify([embeddableByRef, mapByValue, visualizationByValue]),
+ },
+ },
+ ],
+ };
+ const savedObjectClient = { find: jest.fn().mockResolvedValue(savedObjectsResult) };
+
+ const maps = await findByValueEmbeddables(savedObjectClient, 'map');
+
+ expect(maps.length).toBe(2);
+ expect(maps[0]).toEqual(mapByValue.embeddableConfig);
+ expect(maps[1]).toEqual(mapByValue.embeddableConfig);
+
+ const visualizations = await findByValueEmbeddables(savedObjectClient, 'visualization');
+
+ expect(visualizations.length).toBe(2);
+ expect(visualizations[0]).toEqual(visualizationByValue.embeddableConfig);
+ expect(visualizations[1]).toEqual(visualizationByValue.embeddableConfig);
+ });
+});
diff --git a/src/plugins/dashboard/server/usage/find_by_value_embeddables.ts b/src/plugins/dashboard/server/usage/find_by_value_embeddables.ts
new file mode 100644
index 0000000000000..0ae14cdcf7197
--- /dev/null
+++ b/src/plugins/dashboard/server/usage/find_by_value_embeddables.ts
@@ -0,0 +1,34 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { ISavedObjectsRepository, SavedObjectAttributes } from 'kibana/server';
+import { SavedDashboardPanel730ToLatest } from '../../common';
+
+export const findByValueEmbeddables = async (
+ savedObjectClient: Pick
,
+ embeddableType: string
+) => {
+ const dashboards = await savedObjectClient.find({
+ type: 'dashboard',
+ });
+
+ return dashboards.saved_objects
+ .map((dashboard) => {
+ try {
+ return (JSON.parse(
+ dashboard.attributes.panelsJSON as string
+ ) as unknown) as SavedDashboardPanel730ToLatest[];
+ } catch (exception) {
+ return [];
+ }
+ })
+ .flat()
+ .filter((panel) => (panel as Record).panelRefName === undefined)
+ .filter((panel) => panel.type === embeddableType)
+ .map((panel) => panel.embeddableConfig);
+};
diff --git a/src/plugins/data/common/search/search_source/mocks.ts b/src/plugins/data/common/search/search_source/mocks.ts
index 328f05fac8594..08fe2b07096bb 100644
--- a/src/plugins/data/common/search/search_source/mocks.ts
+++ b/src/plugins/data/common/search/search_source/mocks.ts
@@ -6,7 +6,7 @@
* Public License, v 1.
*/
-import { BehaviorSubject } from 'rxjs';
+import { BehaviorSubject, of } from 'rxjs';
import type { MockedKeys } from '@kbn/utility-types/jest';
import { uiSettingsServiceMock } from '../../../../../core/public/mocks';
@@ -27,6 +27,7 @@ export const searchSourceInstanceMock: MockedKeys = {
createChild: jest.fn().mockReturnThis(),
setParent: jest.fn(),
getParent: jest.fn().mockReturnThis(),
+ fetch$: jest.fn().mockReturnValue(of({})),
fetch: jest.fn().mockResolvedValue({}),
onRequestStart: jest.fn(),
getSearchRequestBody: jest.fn(),
diff --git a/src/plugins/data/common/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts
index 6d7654c6659f2..c2a4beb9b61a5 100644
--- a/src/plugins/data/common/search/search_source/search_source.test.ts
+++ b/src/plugins/data/common/search/search_source/search_source.test.ts
@@ -51,7 +51,14 @@ describe('SearchSource', () => {
let searchSource: SearchSource;
beforeEach(() => {
- mockSearchMethod = jest.fn().mockReturnValue(of({ rawResponse: '' }));
+ mockSearchMethod = jest
+ .fn()
+ .mockReturnValue(
+ of(
+ { rawResponse: { isPartial: true, isRunning: true } },
+ { rawResponse: { isPartial: false, isRunning: false } }
+ )
+ );
searchSourceDependencies = {
getConfig: jest.fn(),
@@ -564,6 +571,34 @@ describe('SearchSource', () => {
await searchSource.fetch(options);
expect(mockSearchMethod).toBeCalledTimes(1);
});
+
+ test('should return partial results', (done) => {
+ searchSource = new SearchSource({ index: indexPattern }, searchSourceDependencies);
+ const options = {};
+
+ const next = jest.fn();
+ const complete = () => {
+ expect(next).toBeCalledTimes(2);
+ expect(next.mock.calls[0]).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "isPartial": true,
+ "isRunning": true,
+ },
+ ]
+ `);
+ expect(next.mock.calls[1]).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "isPartial": false,
+ "isRunning": false,
+ },
+ ]
+ `);
+ done();
+ };
+ searchSource.fetch$(options).subscribe({ next, complete });
+ });
});
describe('#serialize', () => {
diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts
index 554e8385881f2..bb60f0d7b4ad4 100644
--- a/src/plugins/data/common/search/search_source/search_source.ts
+++ b/src/plugins/data/common/search/search_source/search_source.ts
@@ -60,7 +60,8 @@
import { setWith } from '@elastic/safer-lodash-set';
import { uniqueId, keyBy, pick, difference, omit, isObject, isFunction } from 'lodash';
-import { map } from 'rxjs/operators';
+import { map, switchMap, tap } from 'rxjs/operators';
+import { defer, from } from 'rxjs';
import { normalizeSortRequest } from './normalize_sort_request';
import { fieldWildcardFilter } from '../../../../kibana_utils/common';
import { IIndexPattern } from '../../index_patterns';
@@ -244,30 +245,35 @@ export class SearchSource {
}
/**
- * Fetch this source and reject the returned Promise on error
- *
- * @async
+ * Fetch this source from Elasticsearch, returning an observable over the response(s)
+ * @param options
*/
- async fetch(options: ISearchOptions = {}) {
+ fetch$(options: ISearchOptions = {}) {
const { getConfig } = this.dependencies;
- await this.requestIsStarting(options);
-
- const searchRequest = await this.flatten();
- this.history = [searchRequest];
-
- let response;
- if (getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)) {
- response = await this.legacyFetch(searchRequest, options);
- } else {
- response = await this.fetchSearch(searchRequest, options);
- }
-
- // TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved
- if ((response as any).error) {
- throw new RequestFailure(null, response);
- }
+ return defer(() => this.requestIsStarting(options)).pipe(
+ switchMap(() => {
+ const searchRequest = this.flatten();
+ this.history = [searchRequest];
+
+ return getConfig(UI_SETTINGS.COURIER_BATCH_SEARCHES)
+ ? from(this.legacyFetch(searchRequest, options))
+ : this.fetchSearch$(searchRequest, options);
+ }),
+ tap((response) => {
+ // TODO: Remove casting when https://github.com/elastic/elasticsearch-js/issues/1287 is resolved
+ if ((response as any).error) {
+ throw new RequestFailure(null, response);
+ }
+ })
+ );
+ }
- return response;
+ /**
+ * Fetch this source and reject the returned Promise on error
+ * @deprecated Use fetch$ instead
+ */
+ fetch(options: ISearchOptions = {}) {
+ return this.fetch$(options).toPromise();
}
/**
@@ -305,16 +311,16 @@ export class SearchSource {
* Run a search using the search service
* @return {Promise>}
*/
- private fetchSearch(searchRequest: SearchRequest, options: ISearchOptions) {
+ private fetchSearch$(searchRequest: SearchRequest, options: ISearchOptions) {
const { search, getConfig, onResponse } = this.dependencies;
const params = getSearchParamsFromRequest(searchRequest, {
getConfig,
});
- return search({ params, indexType: searchRequest.indexType }, options)
- .pipe(map(({ rawResponse }) => onResponse(searchRequest, rawResponse)))
- .toPromise();
+ return search({ params, indexType: searchRequest.indexType }, options).pipe(
+ map(({ rawResponse }) => onResponse(searchRequest, rawResponse))
+ );
}
/**
diff --git a/src/plugins/data/common/search/test_data/illegal_argument_exception.json b/src/plugins/data/common/search/test_data/illegal_argument_exception.json
new file mode 100644
index 0000000000000..ae48468abc209
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/illegal_argument_exception.json
@@ -0,0 +1,14 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "illegal_argument_exception",
+ "reason" : "failed to parse setting [timeout] with value [1] as a time value: unit is missing or unrecognized"
+ }
+ ],
+ "type" : "illegal_argument_exception",
+ "reason" : "failed to parse setting [timeout] with value [1] as a time value: unit is missing or unrecognized"
+ },
+ "status" : 400
+ }
+
\ No newline at end of file
diff --git a/src/plugins/data/common/search/test_data/index_not_found_exception.json b/src/plugins/data/common/search/test_data/index_not_found_exception.json
new file mode 100644
index 0000000000000..dc892d95ae397
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/index_not_found_exception.json
@@ -0,0 +1,21 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "index_not_found_exception",
+ "reason" : "no such index [poop]",
+ "resource.type" : "index_or_alias",
+ "resource.id" : "poop",
+ "index_uuid" : "_na_",
+ "index" : "poop"
+ }
+ ],
+ "type" : "index_not_found_exception",
+ "reason" : "no such index [poop]",
+ "resource.type" : "index_or_alias",
+ "resource.id" : "poop",
+ "index_uuid" : "_na_",
+ "index" : "poop"
+ },
+ "status" : 404
+}
diff --git a/src/plugins/data/common/search/test_data/json_e_o_f_exception.json b/src/plugins/data/common/search/test_data/json_e_o_f_exception.json
new file mode 100644
index 0000000000000..88134e1c6ea03
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/json_e_o_f_exception.json
@@ -0,0 +1,14 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "json_e_o_f_exception",
+ "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 1])\n at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 2]"
+ }
+ ],
+ "type" : "json_e_o_f_exception",
+ "reason" : "Unexpected end-of-input: expected close marker for Object (start marker at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 1])\n at [Source: (org.elasticsearch.common.io.stream.InputStreamStreamInput); line: 1, column: 2]"
+ },
+ "status" : 400
+ }
+
\ No newline at end of file
diff --git a/src/plugins/data/common/search/test_data/parsing_exception.json b/src/plugins/data/common/search/test_data/parsing_exception.json
new file mode 100644
index 0000000000000..725a847aa0e3f
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/parsing_exception.json
@@ -0,0 +1,17 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "parsing_exception",
+ "reason" : "[terms] query does not support [ohno]",
+ "line" : 4,
+ "col" : 17
+ }
+ ],
+ "type" : "parsing_exception",
+ "reason" : "[terms] query does not support [ohno]",
+ "line" : 4,
+ "col" : 17
+ },
+ "status" : 400
+}
diff --git a/src/plugins/data/common/search/test_data/resource_not_found_exception.json b/src/plugins/data/common/search/test_data/resource_not_found_exception.json
new file mode 100644
index 0000000000000..7f2a3b2e6e143
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/resource_not_found_exception.json
@@ -0,0 +1,13 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "resource_not_found_exception",
+ "reason" : "FlZlSXp6dkd3UXdHZjhsalVtVHBnYkEdYjNIWDhDOTZRN3ExemdmVkx4RXNQQToxMjc2ODk="
+ }
+ ],
+ "type" : "resource_not_found_exception",
+ "reason" : "FlZlSXp6dkd3UXdHZjhsalVtVHBnYkEdYjNIWDhDOTZRN3ExemdmVkx4RXNQQToxMjc2ODk="
+ },
+ "status" : 404
+}
diff --git a/src/plugins/data/common/search/test_data/search_phase_execution_exception.json b/src/plugins/data/common/search/test_data/search_phase_execution_exception.json
new file mode 100644
index 0000000000000..ff6879f2b8960
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/search_phase_execution_exception.json
@@ -0,0 +1,52 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "script_exception",
+ "reason" : "compile error",
+ "script_stack" : [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script" : "invalid",
+ "lang" : "painless",
+ "position" : {
+ "offset" : 0,
+ "start" : 0,
+ "end" : 7
+ }
+ }
+ ],
+ "type" : "search_phase_execution_exception",
+ "reason" : "all shards failed",
+ "phase" : "query",
+ "grouped" : true,
+ "failed_shards" : [
+ {
+ "shard" : 0,
+ "index" : ".kibana_11",
+ "node" : "b3HX8C96Q7q1zgfVLxEsPA",
+ "reason" : {
+ "type" : "script_exception",
+ "reason" : "compile error",
+ "script_stack" : [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script" : "invalid",
+ "lang" : "painless",
+ "position" : {
+ "offset" : 0,
+ "start" : 0,
+ "end" : 7
+ },
+ "caused_by" : {
+ "type" : "illegal_argument_exception",
+ "reason" : "cannot resolve symbol [invalid]"
+ }
+ }
+ }
+ ]
+ },
+ "status" : 400
+}
diff --git a/src/plugins/data/common/search/test_data/x_content_parse_exception.json b/src/plugins/data/common/search/test_data/x_content_parse_exception.json
new file mode 100644
index 0000000000000..cd6e1cb2c5977
--- /dev/null
+++ b/src/plugins/data/common/search/test_data/x_content_parse_exception.json
@@ -0,0 +1,17 @@
+{
+ "error" : {
+ "root_cause" : [
+ {
+ "type" : "x_content_parse_exception",
+ "reason" : "[5:13] [script] failed to parse object"
+ }
+ ],
+ "type" : "x_content_parse_exception",
+ "reason" : "[5:13] [script] failed to parse object",
+ "caused_by" : {
+ "type" : "json_parse_exception",
+ "reason" : "Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.elasticsearch.common.bytes.AbstractBytesReference$BytesReferenceStreamInput); line: 5, column: 24]"
+ }
+ },
+ "status" : 400
+}
diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md
index 9e493f46b0781..f533af2db9672 100644
--- a/src/plugins/data/public/public.api.md
+++ b/src/plugins/data/public/public.api.md
@@ -2282,8 +2282,11 @@ export class SearchInterceptor {
protected readonly deps: SearchInterceptorDeps;
// (undocumented)
protected getTimeoutMode(): TimeoutErrorMode;
+ // Warning: (ae-forgotten-export) The symbol "KibanaServerError" needs to be exported by the entry point index.d.ts
+ // Warning: (ae-forgotten-export) The symbol "AbortError" needs to be exported by the entry point index.d.ts
+ //
// (undocumented)
- protected handleSearchError(e: any, timeoutSignal: AbortSignal, options?: ISearchOptions): Error;
+ protected handleSearchError(e: KibanaServerError | AbortError, timeoutSignal: AbortSignal, options?: ISearchOptions): Error;
// @internal
protected pendingCount$: BehaviorSubject;
// @internal (undocumented)
@@ -2360,6 +2363,8 @@ export class SearchSource {
createChild(options?: {}): SearchSource;
createCopy(): SearchSource;
destroy(): void;
+ fetch$(options?: ISearchOptions): import("rxjs").Observable>;
+ // @deprecated
fetch(options?: ISearchOptions): Promise>;
getField(field: K, recurse?: boolean): SearchSourceFields[K];
getFields(): {
@@ -2451,7 +2456,7 @@ export interface SearchSourceFields {
//
// @public
export class SearchTimeoutError extends KbnError {
- constructor(err: Error, mode: TimeoutErrorMode);
+ constructor(err: Record, mode: TimeoutErrorMode);
// (undocumented)
getErrorMessage(application: ApplicationStart): JSX.Element;
// (undocumented)
@@ -2601,7 +2606,7 @@ export const UI_SETTINGS: {
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:138:7 - (ae-forgotten-export) The symbol "FieldAttrSet" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/index_patterns/index_patterns/index_pattern.ts:169:7 - (ae-forgotten-export) The symbol "RuntimeField" needs to be exported by the entry point index.d.ts
// src/plugins/data/common/search/aggs/types.ts:139:51 - (ae-forgotten-export) The symbol "AggTypesRegistryStart" needs to be exported by the entry point index.d.ts
-// src/plugins/data/common/search/search_source/search_source.ts:186:7 - (ae-forgotten-export) The symbol "SearchFieldValue" needs to be exported by the entry point index.d.ts
+// src/plugins/data/common/search/search_source/search_source.ts:187:7 - (ae-forgotten-export) The symbol "SearchFieldValue" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/field_formats/field_formats_service.ts:56:3 - (ae-forgotten-export) The symbol "FormatFactory" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:55:23 - (ae-forgotten-export) The symbol "FILTERS" needs to be exported by the entry point index.d.ts
// src/plugins/data/public/index.ts:55:23 - (ae-forgotten-export) The symbol "getDisplayValueFromFilter" needs to be exported by the entry point index.d.ts
diff --git a/src/plugins/data/public/search/errors/es_error.test.tsx b/src/plugins/data/public/search/errors/es_error.test.tsx
index adb422c1d18e7..6a4cb9c494b4f 100644
--- a/src/plugins/data/public/search/errors/es_error.test.tsx
+++ b/src/plugins/data/public/search/errors/es_error.test.tsx
@@ -7,23 +7,22 @@
*/
import { EsError } from './es_error';
-import { IEsError } from './types';
describe('EsError', () => {
it('contains the same body as the wrapped error', () => {
const error = {
- body: {
- attributes: {
- error: {
- type: 'top_level_exception_type',
- reason: 'top-level reason',
- },
+ statusCode: 500,
+ message: 'nope',
+ attributes: {
+ error: {
+ type: 'top_level_exception_type',
+ reason: 'top-level reason',
},
},
- } as IEsError;
+ } as any;
const esError = new EsError(error);
- expect(typeof esError.body).toEqual('object');
- expect(esError.body).toEqual(error.body);
+ expect(typeof esError.attributes).toEqual('object');
+ expect(esError.attributes).toEqual(error.attributes);
});
});
diff --git a/src/plugins/data/public/search/errors/es_error.tsx b/src/plugins/data/public/search/errors/es_error.tsx
index fff06d2e1bfb6..d241eecfd8d5d 100644
--- a/src/plugins/data/public/search/errors/es_error.tsx
+++ b/src/plugins/data/public/search/errors/es_error.tsx
@@ -11,19 +11,19 @@ import { EuiCodeBlock, EuiSpacer } from '@elastic/eui';
import { ApplicationStart } from 'kibana/public';
import { KbnError } from '../../../../kibana_utils/common';
import { IEsError } from './types';
-import { getRootCause, getTopLevelCause } from './utils';
+import { getRootCause } from './utils';
export class EsError extends KbnError {
- readonly body: IEsError['body'];
+ readonly attributes: IEsError['attributes'];
constructor(protected readonly err: IEsError) {
super('EsError');
- this.body = err.body;
+ this.attributes = err.attributes;
}
public getErrorMessage(application: ApplicationStart) {
const rootCause = getRootCause(this.err)?.reason;
- const topLevelCause = getTopLevelCause(this.err)?.reason;
+ const topLevelCause = this.attributes?.reason;
const cause = rootCause ?? topLevelCause;
return (
diff --git a/src/plugins/data/public/search/errors/painless_error.test.tsx b/src/plugins/data/public/search/errors/painless_error.test.tsx
new file mode 100644
index 0000000000000..929f25e234a60
--- /dev/null
+++ b/src/plugins/data/public/search/errors/painless_error.test.tsx
@@ -0,0 +1,42 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { coreMock } from '../../../../../core/public/mocks';
+const startMock = coreMock.createStart();
+
+import { mount } from 'enzyme';
+import { PainlessError } from './painless_error';
+import { findTestSubject } from '@elastic/eui/lib/test';
+import * as searchPhaseException from '../../../common/search/test_data/search_phase_execution_exception.json';
+
+describe('PainlessError', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('Should show reason and code', () => {
+ const e = new PainlessError({
+ statusCode: 400,
+ message: 'search_phase_execution_exception',
+ attributes: searchPhaseException.error,
+ });
+ const component = mount(e.getErrorMessage(startMock.application));
+
+ const scriptElem = findTestSubject(component, 'painlessScript').getDOMNode();
+
+ const failedShards = e.attributes?.failed_shards![0];
+ const script = failedShards!.reason.script;
+ expect(scriptElem.textContent).toBe(`Error executing Painless script: '${script}'`);
+
+ const stackTraceElem = findTestSubject(component, 'painlessStackTrace').getDOMNode();
+ const stackTrace = failedShards!.reason.script_stack!.join('\n');
+ expect(stackTraceElem.textContent).toBe(stackTrace);
+
+ expect(component.find('EuiButton').length).toBe(1);
+ });
+});
diff --git a/src/plugins/data/public/search/errors/painless_error.tsx b/src/plugins/data/public/search/errors/painless_error.tsx
index 8a4248e48185b..6d11f3a16b09e 100644
--- a/src/plugins/data/public/search/errors/painless_error.tsx
+++ b/src/plugins/data/public/search/errors/painless_error.tsx
@@ -33,10 +33,12 @@ export class PainlessError extends EsError {
return (
<>
- {i18n.translate('data.painlessError.painlessScriptedFieldErrorMessage', {
- defaultMessage: "Error executing Painless script: '{script}'.",
- values: { script: rootCause?.script },
- })}
+
+ {i18n.translate('data.painlessError.painlessScriptedFieldErrorMessage', {
+ defaultMessage: "Error executing Painless script: '{script}'",
+ values: { script: rootCause?.script },
+ })}
+
{painlessStack ? (
diff --git a/src/plugins/data/public/search/errors/timeout_error.tsx b/src/plugins/data/public/search/errors/timeout_error.tsx
index ee2703b888bf1..6b9ce1b422481 100644
--- a/src/plugins/data/public/search/errors/timeout_error.tsx
+++ b/src/plugins/data/public/search/errors/timeout_error.tsx
@@ -24,7 +24,7 @@ export enum TimeoutErrorMode {
*/
export class SearchTimeoutError extends KbnError {
public mode: TimeoutErrorMode;
- constructor(err: Error, mode: TimeoutErrorMode) {
+ constructor(err: Record, mode: TimeoutErrorMode) {
super(`Request timeout: ${JSON.stringify(err?.message)}`);
this.mode = mode;
}
diff --git a/src/plugins/data/public/search/errors/types.ts b/src/plugins/data/public/search/errors/types.ts
index d62cb311bf6a4..5806ef8676b9b 100644
--- a/src/plugins/data/public/search/errors/types.ts
+++ b/src/plugins/data/public/search/errors/types.ts
@@ -6,57 +6,47 @@
* Public License, v 1.
*/
+import { KibanaServerError } from '../../../../kibana_utils/common';
+
export interface FailedShard {
shard: number;
index: string;
node: string;
- reason: {
+ reason: Reason;
+}
+
+export interface Reason {
+ type: string;
+ reason: string;
+ script_stack?: string[];
+ position?: {
+ offset: number;
+ start: number;
+ end: number;
+ };
+ lang?: string;
+ script?: string;
+ caused_by?: {
type: string;
reason: string;
- script_stack: string[];
- script: string;
- lang: string;
- position: {
- offset: number;
- start: number;
- end: number;
- };
- caused_by: {
- type: string;
- reason: string;
- };
};
}
-export interface IEsError {
- body: {
- statusCode: number;
- error: string;
- message: string;
- attributes?: {
- error?: {
- root_cause?: [
- {
- lang: string;
- script: string;
- }
- ];
- type: string;
- reason: string;
- failed_shards: FailedShard[];
- caused_by: {
- type: string;
- reason: string;
- phase: string;
- grouped: boolean;
- failed_shards: FailedShard[];
- script_stack: string[];
- };
- };
- };
- };
+export interface IEsErrorAttributes {
+ type: string;
+ reason: string;
+ root_cause?: Reason[];
+ failed_shards?: FailedShard[];
}
+export type IEsError = KibanaServerError;
+
+/**
+ * Checks if a given errors originated from Elasticsearch.
+ * Those params are assigned to the attributes property of an error.
+ *
+ * @param e
+ */
export function isEsError(e: any): e is IEsError {
- return !!e.body?.attributes;
+ return !!e.attributes;
}
diff --git a/src/plugins/data/public/search/errors/utils.ts b/src/plugins/data/public/search/errors/utils.ts
index d140e713f9440..7d303543a0c57 100644
--- a/src/plugins/data/public/search/errors/utils.ts
+++ b/src/plugins/data/public/search/errors/utils.ts
@@ -6,19 +6,15 @@
* Public License, v 1.
*/
-import { IEsError } from './types';
+import { FailedShard } from './types';
+import { KibanaServerError } from '../../../../kibana_utils/common';
-export function getFailedShards(err: IEsError) {
- const failedShards =
- err.body?.attributes?.error?.failed_shards ||
- err.body?.attributes?.error?.caused_by?.failed_shards;
+export function getFailedShards(err: KibanaServerError): FailedShard | undefined {
+ const errorInfo = err.attributes;
+ const failedShards = errorInfo?.failed_shards || errorInfo?.caused_by?.failed_shards;
return failedShards ? failedShards[0] : undefined;
}
-export function getTopLevelCause(err: IEsError) {
- return err.body?.attributes?.error;
-}
-
-export function getRootCause(err: IEsError) {
+export function getRootCause(err: KibanaServerError) {
return getFailedShards(err)?.reason;
}
diff --git a/src/plugins/data/public/search/search_interceptor.test.ts b/src/plugins/data/public/search/search_interceptor.test.ts
index 5ae01eccdd920..bfd73951c31c4 100644
--- a/src/plugins/data/public/search/search_interceptor.test.ts
+++ b/src/plugins/data/public/search/search_interceptor.test.ts
@@ -12,12 +12,15 @@ import { coreMock } from '../../../../core/public/mocks';
import { IEsSearchRequest } from '../../common/search';
import { SearchInterceptor } from './search_interceptor';
import { AbortError } from '../../../kibana_utils/public';
-import { SearchTimeoutError, PainlessError, TimeoutErrorMode } from './errors';
+import { SearchTimeoutError, PainlessError, TimeoutErrorMode, EsError } from './errors';
import { searchServiceMock } from './mocks';
import { ISearchStart, ISessionService } from '.';
import { bfetchPluginMock } from '../../../bfetch/public/mocks';
import { BfetchPublicSetup } from 'src/plugins/bfetch/public';
+import * as searchPhaseException from '../../common/search/test_data/search_phase_execution_exception.json';
+import * as resourceNotFoundException from '../../common/search/test_data/resource_not_found_exception.json';
+
let searchInterceptor: SearchInterceptor;
let mockCoreSetup: MockedKeys;
let bfetchSetup: jest.Mocked;
@@ -64,15 +67,9 @@ describe('SearchInterceptor', () => {
test('Renders a PainlessError', async () => {
searchInterceptor.showError(
new PainlessError({
- body: {
- attributes: {
- error: {
- failed_shards: {
- reason: 'bananas',
- },
- },
- },
- } as any,
+ statusCode: 400,
+ message: 'search_phase_execution_exception',
+ attributes: searchPhaseException.error,
})
);
expect(mockCoreSetup.notifications.toasts.addDanger).toBeCalledTimes(1);
@@ -161,10 +158,8 @@ describe('SearchInterceptor', () => {
describe('Should handle Timeout errors', () => {
test('Should throw SearchTimeoutError on server timeout AND show toast', async () => {
const mockResponse: any = {
- result: 500,
- body: {
- message: 'Request timed out',
- },
+ statusCode: 500,
+ message: 'Request timed out',
};
fetchMock.mockRejectedValueOnce(mockResponse);
const mockRequest: IEsSearchRequest = {
@@ -177,10 +172,8 @@ describe('SearchInterceptor', () => {
test('Timeout error should show multiple times if not in a session', async () => {
const mockResponse: any = {
- result: 500,
- body: {
- message: 'Request timed out',
- },
+ statusCode: 500,
+ message: 'Request timed out',
};
fetchMock.mockRejectedValue(mockResponse);
const mockRequest: IEsSearchRequest = {
@@ -198,10 +191,8 @@ describe('SearchInterceptor', () => {
test('Timeout error should show once per each session', async () => {
const mockResponse: any = {
- result: 500,
- body: {
- message: 'Request timed out',
- },
+ statusCode: 500,
+ message: 'Request timed out',
};
fetchMock.mockRejectedValue(mockResponse);
const mockRequest: IEsSearchRequest = {
@@ -219,10 +210,8 @@ describe('SearchInterceptor', () => {
test('Timeout error should show once in a single session', async () => {
const mockResponse: any = {
- result: 500,
- body: {
- message: 'Request timed out',
- },
+ statusCode: 500,
+ message: 'Request timed out',
};
fetchMock.mockRejectedValue(mockResponse);
const mockRequest: IEsSearchRequest = {
@@ -240,22 +229,9 @@ describe('SearchInterceptor', () => {
test('Should throw Painless error on server error with OSS format', async () => {
const mockResponse: any = {
- result: 500,
- body: {
- attributes: {
- error: {
- failed_shards: [
- {
- reason: {
- lang: 'painless',
- script_stack: ['a', 'b'],
- reason: 'banana',
- },
- },
- ],
- },
- },
- },
+ statusCode: 400,
+ message: 'search_phase_execution_exception',
+ attributes: searchPhaseException.error,
};
fetchMock.mockRejectedValueOnce(mockResponse);
const mockRequest: IEsSearchRequest = {
@@ -265,6 +241,20 @@ describe('SearchInterceptor', () => {
await expect(response.toPromise()).rejects.toThrow(PainlessError);
});
+ test('Should throw ES error on ES server error', async () => {
+ const mockResponse: any = {
+ statusCode: 400,
+ message: 'resource_not_found_exception',
+ attributes: resourceNotFoundException.error,
+ };
+ fetchMock.mockRejectedValueOnce(mockResponse);
+ const mockRequest: IEsSearchRequest = {
+ params: {},
+ };
+ const response = searchInterceptor.search(mockRequest);
+ await expect(response.toPromise()).rejects.toThrow(EsError);
+ });
+
test('Observable should fail if user aborts (test merged signal)', async () => {
const abortController = new AbortController();
fetchMock.mockImplementationOnce((options: any) => {
diff --git a/src/plugins/data/public/search/search_interceptor.ts b/src/plugins/data/public/search/search_interceptor.ts
index f6ca9ef1a993d..6dfc8faea769e 100644
--- a/src/plugins/data/public/search/search_interceptor.ts
+++ b/src/plugins/data/public/search/search_interceptor.ts
@@ -6,7 +6,7 @@
* Public License, v 1.
*/
-import { get, memoize } from 'lodash';
+import { memoize } from 'lodash';
import { BehaviorSubject, throwError, timer, defer, from, Observable, NEVER } from 'rxjs';
import { catchError, finalize } from 'rxjs/operators';
import { PublicMethodsOf } from '@kbn/utility-types';
@@ -25,7 +25,11 @@ import {
getHttpError,
} from './errors';
import { toMountPoint } from '../../../kibana_react/public';
-import { AbortError, getCombinedAbortSignal } from '../../../kibana_utils/public';
+import {
+ AbortError,
+ getCombinedAbortSignal,
+ KibanaServerError,
+} from '../../../kibana_utils/public';
import { ISessionService } from './session';
export interface SearchInterceptorDeps {
@@ -87,8 +91,12 @@ export class SearchInterceptor {
* @returns `Error` a search service specific error or the original error, if a specific error can't be recognized.
* @internal
*/
- protected handleSearchError(e: any, timeoutSignal: AbortSignal, options?: ISearchOptions): Error {
- if (timeoutSignal.aborted || get(e, 'body.message') === 'Request timed out') {
+ protected handleSearchError(
+ e: KibanaServerError | AbortError,
+ timeoutSignal: AbortSignal,
+ options?: ISearchOptions
+ ): Error {
+ if (timeoutSignal.aborted || e.message === 'Request timed out') {
// Handle a client or a server side timeout
const err = new SearchTimeoutError(e, this.getTimeoutMode());
@@ -96,7 +104,7 @@ export class SearchInterceptor {
// The timeout error is shown any time a request times out, or once per session, if the request is part of a session.
this.showTimeoutError(err, options?.sessionId);
return err;
- } else if (options?.abortSignal?.aborted) {
+ } else if (e instanceof AbortError) {
// In the case an application initiated abort, throw the existing AbortError.
return e;
} else if (isEsError(e)) {
@@ -106,12 +114,13 @@ export class SearchInterceptor {
return new EsError(e);
}
} else {
- return e;
+ return e instanceof Error ? e : new Error(e.message);
}
}
/**
* @internal
+ * @throws `AbortError` | `ErrorLike`
*/
protected runSearch(
request: IKibanaSearchRequest,
@@ -234,7 +243,7 @@ export class SearchInterceptor {
});
this.pendingCount$.next(this.pendingCount$.getValue() + 1);
return from(this.runSearch(request, { ...options, abortSignal: combinedSignal })).pipe(
- catchError((e: Error) => {
+ catchError((e: Error | AbortError) => {
return throwError(this.handleSearchError(e, timeoutSignal, options));
}),
finalize(() => {
diff --git a/src/plugins/data/server/search/es_search/es_search_strategy.test.ts b/src/plugins/data/server/search/es_search/es_search_strategy.test.ts
index 8e66729825e39..eeef46381732e 100644
--- a/src/plugins/data/server/search/es_search/es_search_strategy.test.ts
+++ b/src/plugins/data/server/search/es_search/es_search_strategy.test.ts
@@ -6,37 +6,56 @@
* Public License, v 1.
*/
+import {
+ elasticsearchClientMock,
+ MockedTransportRequestPromise,
+ // eslint-disable-next-line @kbn/eslint/no-restricted-paths
+} from '../../../../../core/server/elasticsearch/client/mocks';
import { pluginInitializerContextConfigMock } from '../../../../../core/server/mocks';
import { esSearchStrategyProvider } from './es_search_strategy';
import { SearchStrategyDependencies } from '../types';
+import * as indexNotFoundException from '../../../common/search/test_data/index_not_found_exception.json';
+import { ElasticsearchClientError, ResponseError } from '@elastic/elasticsearch/lib/errors';
+import { KbnServerError } from '../../../../kibana_utils/server';
+
describe('ES search strategy', () => {
+ const successBody = {
+ _shards: {
+ total: 10,
+ failed: 1,
+ skipped: 2,
+ successful: 7,
+ },
+ };
+ let mockedApiCaller: MockedTransportRequestPromise;
+ let mockApiCaller: jest.Mock<() => MockedTransportRequestPromise>;
const mockLogger: any = {
debug: () => {},
};
- const mockApiCaller = jest.fn().mockResolvedValue({
- body: {
- _shards: {
- total: 10,
- failed: 1,
- skipped: 2,
- successful: 7,
- },
- },
- });
- const mockDeps = ({
- uiSettingsClient: {
- get: () => {},
- },
- esClient: { asCurrentUser: { search: mockApiCaller } },
- } as unknown) as SearchStrategyDependencies;
+ function getMockedDeps(err?: Record) {
+ mockApiCaller = jest.fn().mockImplementation(() => {
+ if (err) {
+ mockedApiCaller = elasticsearchClientMock.createErrorTransportRequestPromise(err);
+ } else {
+ mockedApiCaller = elasticsearchClientMock.createSuccessTransportRequestPromise(
+ successBody,
+ { statusCode: 200 }
+ );
+ }
+ return mockedApiCaller;
+ });
- const mockConfig$ = pluginInitializerContextConfigMock({}).legacy.globalConfig$;
+ return ({
+ uiSettingsClient: {
+ get: () => {},
+ },
+ esClient: { asCurrentUser: { search: mockApiCaller } },
+ } as unknown) as SearchStrategyDependencies;
+ }
- beforeEach(() => {
- mockApiCaller.mockClear();
- });
+ const mockConfig$ = pluginInitializerContextConfigMock({}).legacy.globalConfig$;
it('returns a strategy with `search`', async () => {
const esSearch = await esSearchStrategyProvider(mockConfig$, mockLogger);
@@ -48,7 +67,7 @@ describe('ES search strategy', () => {
const params = { index: 'logstash-*' };
await esSearchStrategyProvider(mockConfig$, mockLogger)
- .search({ params }, {}, mockDeps)
+ .search({ params }, {}, getMockedDeps())
.subscribe(() => {
expect(mockApiCaller).toBeCalled();
expect(mockApiCaller.mock.calls[0][0]).toEqual({
@@ -64,7 +83,7 @@ describe('ES search strategy', () => {
const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
await esSearchStrategyProvider(mockConfig$, mockLogger)
- .search({ params }, {}, mockDeps)
+ .search({ params }, {}, getMockedDeps())
.subscribe(() => {
expect(mockApiCaller).toBeCalled();
expect(mockApiCaller.mock.calls[0][0]).toEqual({
@@ -82,13 +101,109 @@ describe('ES search strategy', () => {
params: { index: 'logstash-*' },
},
{},
- mockDeps
+ getMockedDeps()
)
.subscribe((data) => {
expect(data.isRunning).toBe(false);
expect(data.isPartial).toBe(false);
expect(data).toHaveProperty('loaded');
expect(data).toHaveProperty('rawResponse');
+ expect(mockedApiCaller.abort).not.toBeCalled();
done();
}));
+
+ it('can be aborted', async () => {
+ const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
+
+ const abortController = new AbortController();
+ abortController.abort();
+
+ await esSearchStrategyProvider(mockConfig$, mockLogger)
+ .search({ params }, { abortSignal: abortController.signal }, getMockedDeps())
+ .toPromise();
+
+ expect(mockApiCaller).toBeCalled();
+ expect(mockApiCaller.mock.calls[0][0]).toEqual({
+ ...params,
+ track_total_hits: true,
+ });
+ expect(mockedApiCaller.abort).toBeCalled();
+ });
+
+ it('throws normalized error if ResponseError is thrown', async (done) => {
+ const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
+ const errResponse = new ResponseError({
+ body: indexNotFoundException,
+ statusCode: 404,
+ headers: {},
+ warnings: [],
+ meta: {} as any,
+ });
+
+ try {
+ await esSearchStrategyProvider(mockConfig$, mockLogger)
+ .search({ params }, {}, getMockedDeps(errResponse))
+ .toPromise();
+ } catch (e) {
+ expect(mockApiCaller).toBeCalled();
+ expect(e).toBeInstanceOf(KbnServerError);
+ expect(e.statusCode).toBe(404);
+ expect(e.message).toBe(errResponse.message);
+ expect(e.errBody).toBe(indexNotFoundException);
+ done();
+ }
+ });
+
+ it('throws normalized error if ElasticsearchClientError is thrown', async (done) => {
+ const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
+ const errResponse = new ElasticsearchClientError('This is a general ESClient error');
+
+ try {
+ await esSearchStrategyProvider(mockConfig$, mockLogger)
+ .search({ params }, {}, getMockedDeps(errResponse))
+ .toPromise();
+ } catch (e) {
+ expect(mockApiCaller).toBeCalled();
+ expect(e).toBeInstanceOf(KbnServerError);
+ expect(e.statusCode).toBe(500);
+ expect(e.message).toBe(errResponse.message);
+ expect(e.errBody).toBe(undefined);
+ done();
+ }
+ });
+
+ it('throws normalized error if ESClient throws unknown error', async (done) => {
+ const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
+ const errResponse = new Error('ESClient error');
+
+ try {
+ await esSearchStrategyProvider(mockConfig$, mockLogger)
+ .search({ params }, {}, getMockedDeps(errResponse))
+ .toPromise();
+ } catch (e) {
+ expect(mockApiCaller).toBeCalled();
+ expect(e).toBeInstanceOf(KbnServerError);
+ expect(e.statusCode).toBe(500);
+ expect(e.message).toBe(errResponse.message);
+ expect(e.errBody).toBe(undefined);
+ done();
+ }
+ });
+
+ it('throws KbnServerError for unknown index type', async (done) => {
+ const params = { index: 'logstash-*', ignore_unavailable: false, timeout: '1000ms' };
+
+ try {
+ await esSearchStrategyProvider(mockConfig$, mockLogger)
+ .search({ indexType: 'banana', params }, {}, getMockedDeps())
+ .toPromise();
+ } catch (e) {
+ expect(mockApiCaller).not.toBeCalled();
+ expect(e).toBeInstanceOf(KbnServerError);
+ expect(e.message).toBe('Unsupported index pattern type banana');
+ expect(e.statusCode).toBe(400);
+ expect(e.errBody).toBe(undefined);
+ done();
+ }
+ });
});
diff --git a/src/plugins/data/server/search/es_search/es_search_strategy.ts b/src/plugins/data/server/search/es_search/es_search_strategy.ts
index a11bbe11f3f95..c176a50627b92 100644
--- a/src/plugins/data/server/search/es_search/es_search_strategy.ts
+++ b/src/plugins/data/server/search/es_search/es_search_strategy.ts
@@ -15,13 +15,20 @@ import type { SearchUsage } from '../collectors';
import { getDefaultSearchParams, getShardTimeout, shimAbortSignal } from './request_utils';
import { toKibanaSearchResponse } from './response_utils';
import { searchUsageObserver } from '../collectors/usage';
-import { KbnServerError } from '../../../../kibana_utils/server';
+import { getKbnServerError, KbnServerError } from '../../../../kibana_utils/server';
export const esSearchStrategyProvider = (
config$: Observable,
logger: Logger,
usage?: SearchUsage
): ISearchStrategy => ({
+ /**
+ * @param request
+ * @param options
+ * @param deps
+ * @throws `KbnServerError`
+ * @returns `Observable>`
+ */
search: (request, { abortSignal }, { esClient, uiSettingsClient }) => {
// Only default index pattern type is supported here.
// See data_enhanced for other type support.
@@ -30,15 +37,19 @@ export const esSearchStrategyProvider = (
}
const search = async () => {
- const config = await config$.pipe(first()).toPromise();
- const params = {
- ...(await getDefaultSearchParams(uiSettingsClient)),
- ...getShardTimeout(config),
- ...request.params,
- };
- const promise = esClient.asCurrentUser.search>(params);
- const { body } = await shimAbortSignal(promise, abortSignal);
- return toKibanaSearchResponse(body);
+ try {
+ const config = await config$.pipe(first()).toPromise();
+ const params = {
+ ...(await getDefaultSearchParams(uiSettingsClient)),
+ ...getShardTimeout(config),
+ ...request.params,
+ };
+ const promise = esClient.asCurrentUser.search>(params);
+ const { body } = await shimAbortSignal(promise, abortSignal);
+ return toKibanaSearchResponse(body);
+ } catch (e) {
+ throw getKbnServerError(e);
+ }
};
return from(search()).pipe(tap(searchUsageObserver(logger, usage)));
diff --git a/src/plugins/data/server/search/routes/bsearch.ts b/src/plugins/data/server/search/routes/bsearch.ts
new file mode 100644
index 0000000000000..e30b7bdaa8402
--- /dev/null
+++ b/src/plugins/data/server/search/routes/bsearch.ts
@@ -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
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import { catchError, first, map } from 'rxjs/operators';
+import { CoreStart, KibanaRequest } from 'src/core/server';
+import { BfetchServerSetup } from 'src/plugins/bfetch/server';
+import {
+ IKibanaSearchRequest,
+ IKibanaSearchResponse,
+ ISearchClient,
+ ISearchOptions,
+} from '../../../common/search';
+import { shimHitsTotal } from './shim_hits_total';
+
+type GetScopedProider = (coreStart: CoreStart) => (request: KibanaRequest) => ISearchClient;
+
+export function registerBsearchRoute(
+ bfetch: BfetchServerSetup,
+ coreStartPromise: Promise<[CoreStart, {}, {}]>,
+ getScopedProvider: GetScopedProider
+): void {
+ bfetch.addBatchProcessingRoute<
+ { request: IKibanaSearchRequest; options?: ISearchOptions },
+ IKibanaSearchResponse
+ >('/internal/bsearch', (request) => {
+ return {
+ /**
+ * @param requestOptions
+ * @throws `KibanaServerError`
+ */
+ onBatchItem: async ({ request: requestData, options }) => {
+ const coreStart = await coreStartPromise;
+ const search = getScopedProvider(coreStart[0])(request);
+ return search
+ .search(requestData, options)
+ .pipe(
+ first(),
+ map((response) => {
+ return {
+ ...response,
+ ...{
+ rawResponse: shimHitsTotal(response.rawResponse),
+ },
+ };
+ }),
+ catchError((err) => {
+ // Re-throw as object, to get attributes passed to the client
+ // eslint-disable-next-line no-throw-literal
+ throw {
+ message: err.message,
+ statusCode: err.statusCode,
+ attributes: err.errBody?.error,
+ };
+ })
+ )
+ .toPromise();
+ },
+ };
+ });
+}
diff --git a/src/plugins/data/server/search/routes/call_msearch.ts b/src/plugins/data/server/search/routes/call_msearch.ts
index 6578774f65a3c..fc30e2f29c3ef 100644
--- a/src/plugins/data/server/search/routes/call_msearch.ts
+++ b/src/plugins/data/server/search/routes/call_msearch.ts
@@ -8,12 +8,12 @@
import { Observable } from 'rxjs';
import { first } from 'rxjs/operators';
-import { ApiResponse } from '@elastic/elasticsearch';
import { SearchResponse } from 'elasticsearch';
import { IUiSettingsClient, IScopedClusterClient, SharedGlobalConfig } from 'src/core/server';
import type { MsearchRequestBody, MsearchResponse } from '../../../common/search/search_source';
import { shimHitsTotal } from './shim_hits_total';
+import { getKbnServerError } from '../../../../kibana_utils/server';
import { getShardTimeout, getDefaultSearchParams, shimAbortSignal } from '..';
/** @internal */
@@ -48,6 +48,9 @@ interface CallMsearchDependencies {
* @internal
*/
export function getCallMsearch(dependencies: CallMsearchDependencies) {
+ /**
+ * @throws KbnServerError
+ */
return async (params: {
body: MsearchRequestBody;
signal?: AbortSignal;
@@ -61,28 +64,29 @@ export function getCallMsearch(dependencies: CallMsearchDependencies) {
// trackTotalHits is not supported by msearch
const { track_total_hits: _, ...defaultParams } = await getDefaultSearchParams(uiSettings);
- const body = convertRequestBody(params.body, timeout);
-
- const promise = shimAbortSignal(
- esClient.asCurrentUser.msearch(
+ try {
+ const promise = esClient.asCurrentUser.msearch(
{
- body,
+ body: convertRequestBody(params.body, timeout),
},
{
querystring: defaultParams,
}
- ),
- params.signal
- );
- const response = (await promise) as ApiResponse<{ responses: Array> }>;
+ );
+ const response = await shimAbortSignal(promise, params.signal);
- return {
- body: {
- ...response,
+ return {
body: {
- responses: response.body.responses?.map((r: SearchResponse) => shimHitsTotal(r)),
+ ...response,
+ body: {
+ responses: response.body.responses?.map((r: SearchResponse) =>
+ shimHitsTotal(r)
+ ),
+ },
},
- },
- };
+ };
+ } catch (e) {
+ throw getKbnServerError(e);
+ }
};
}
diff --git a/src/plugins/data/server/search/routes/msearch.test.ts b/src/plugins/data/server/search/routes/msearch.test.ts
index 02f200d5435dd..a847931a49123 100644
--- a/src/plugins/data/server/search/routes/msearch.test.ts
+++ b/src/plugins/data/server/search/routes/msearch.test.ts
@@ -24,6 +24,8 @@ import { convertRequestBody } from './call_msearch';
import { registerMsearchRoute } from './msearch';
import { DataPluginStart } from '../../plugin';
import { dataPluginMock } from '../../mocks';
+import * as jsonEofException from '../../../common/search/test_data/json_e_o_f_exception.json';
+import { ResponseError } from '@elastic/elasticsearch/lib/errors';
describe('msearch route', () => {
let mockDataStart: MockedKeys;
@@ -76,15 +78,52 @@ describe('msearch route', () => {
});
});
- it('handler throws an error if the search throws an error', async () => {
- const response = {
- message: 'oh no',
- body: {
- error: 'oops',
+ it('handler returns an error response if the search throws an error', async () => {
+ const rejectedValue = Promise.reject(
+ new ResponseError({
+ body: jsonEofException,
+ statusCode: 400,
+ meta: {} as any,
+ headers: [],
+ warnings: [],
+ })
+ );
+ const mockClient = {
+ msearch: jest.fn().mockReturnValue(rejectedValue),
+ };
+ const mockContext = {
+ core: {
+ elasticsearch: { client: { asCurrentUser: mockClient } },
+ uiSettings: { client: { get: jest.fn() } },
},
};
+ const mockBody = { searches: [{ header: {}, body: {} }] };
+ const mockQuery = {};
+ const mockRequest = httpServerMock.createKibanaRequest({
+ body: mockBody,
+ query: mockQuery,
+ });
+ const mockResponse = httpServerMock.createResponseFactory();
+
+ registerMsearchRoute(mockCoreSetup.http.createRouter(), { getStartServices, globalConfig$ });
+
+ const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
+ const handler = mockRouter.post.mock.calls[0][1];
+ await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse);
+
+ expect(mockClient.msearch).toBeCalledTimes(1);
+ expect(mockResponse.customError).toBeCalled();
+
+ const error: any = mockResponse.customError.mock.calls[0][0];
+ expect(error.statusCode).toBe(400);
+ expect(error.body.message).toBe('json_e_o_f_exception');
+ expect(error.body.attributes).toBe(jsonEofException.error);
+ });
+
+ it('handler returns an error response if the search throws a general error', async () => {
+ const rejectedValue = Promise.reject(new Error('What happened?'));
const mockClient = {
- msearch: jest.fn().mockReturnValue(Promise.reject(response)),
+ msearch: jest.fn().mockReturnValue(rejectedValue),
};
const mockContext = {
core: {
@@ -106,11 +145,12 @@ describe('msearch route', () => {
const handler = mockRouter.post.mock.calls[0][1];
await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse);
- expect(mockClient.msearch).toBeCalled();
+ expect(mockClient.msearch).toBeCalledTimes(1);
expect(mockResponse.customError).toBeCalled();
const error: any = mockResponse.customError.mock.calls[0][0];
- expect(error.body.message).toBe('oh no');
- expect(error.body.attributes.error).toBe('oops');
+ expect(error.statusCode).toBe(500);
+ expect(error.body.message).toBe('What happened?');
+ expect(error.body.attributes).toBe(undefined);
});
});
diff --git a/src/plugins/data/server/search/routes/search.test.ts b/src/plugins/data/server/search/routes/search.test.ts
index f47a42cf9d82b..2cde6d19e4c18 100644
--- a/src/plugins/data/server/search/routes/search.test.ts
+++ b/src/plugins/data/server/search/routes/search.test.ts
@@ -12,11 +12,27 @@ import { CoreSetup, RequestHandlerContext } from 'src/core/server';
import { coreMock, httpServerMock } from '../../../../../../src/core/server/mocks';
import { registerSearchRoute } from './search';
import { DataPluginStart } from '../../plugin';
+import * as searchPhaseException from '../../../common/search/test_data/search_phase_execution_exception.json';
+import * as indexNotFoundException from '../../../common/search/test_data/index_not_found_exception.json';
+import { KbnServerError } from '../../../../kibana_utils/server';
describe('Search service', () => {
let mockCoreSetup: MockedKeys>;
+ function mockEsError(message: string, statusCode: number, attributes?: Record) {
+ return new KbnServerError(message, statusCode, attributes);
+ }
+
+ async function runMockSearch(mockContext: any, mockRequest: any, mockResponse: any) {
+ registerSearchRoute(mockCoreSetup.http.createRouter());
+
+ const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
+ const handler = mockRouter.post.mock.calls[0][1];
+ await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse);
+ }
+
beforeEach(() => {
+ jest.clearAllMocks();
mockCoreSetup = coreMock.createSetup();
});
@@ -54,11 +70,7 @@ describe('Search service', () => {
});
const mockResponse = httpServerMock.createResponseFactory();
- registerSearchRoute(mockCoreSetup.http.createRouter());
-
- const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
- const handler = mockRouter.post.mock.calls[0][1];
- await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse);
+ await runMockSearch(mockContext, mockRequest, mockResponse);
expect(mockContext.search.search).toBeCalled();
expect(mockContext.search.search.mock.calls[0][0]).toStrictEqual(mockBody);
@@ -68,14 +80,9 @@ describe('Search service', () => {
});
});
- it('handler throws an error if the search throws an error', async () => {
+ it('handler returns an error response if the search throws a painless error', async () => {
const rejectedValue = from(
- Promise.reject({
- message: 'oh no',
- body: {
- error: 'oops',
- },
- })
+ Promise.reject(mockEsError('search_phase_execution_exception', 400, searchPhaseException))
);
const mockContext = {
@@ -84,25 +91,69 @@ describe('Search service', () => {
},
};
- const mockBody = { id: undefined, params: {} };
- const mockParams = { strategy: 'foo' };
const mockRequest = httpServerMock.createKibanaRequest({
- body: mockBody,
- params: mockParams,
+ body: { id: undefined, params: {} },
+ params: { strategy: 'foo' },
});
const mockResponse = httpServerMock.createResponseFactory();
- registerSearchRoute(mockCoreSetup.http.createRouter());
+ await runMockSearch(mockContext, mockRequest, mockResponse);
- const mockRouter = mockCoreSetup.http.createRouter.mock.results[0].value;
- const handler = mockRouter.post.mock.calls[0][1];
- await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse);
+ // verify error
+ expect(mockResponse.customError).toBeCalled();
+ const error: any = mockResponse.customError.mock.calls[0][0];
+ expect(error.statusCode).toBe(400);
+ expect(error.body.message).toBe('search_phase_execution_exception');
+ expect(error.body.attributes).toBe(searchPhaseException.error);
+ });
+
+ it('handler returns an error response if the search throws an index not found error', async () => {
+ const rejectedValue = from(
+ Promise.reject(mockEsError('index_not_found_exception', 404, indexNotFoundException))
+ );
+
+ const mockContext = {
+ search: {
+ search: jest.fn().mockReturnValue(rejectedValue),
+ },
+ };
+
+ const mockRequest = httpServerMock.createKibanaRequest({
+ body: { id: undefined, params: {} },
+ params: { strategy: 'foo' },
+ });
+ const mockResponse = httpServerMock.createResponseFactory();
+
+ await runMockSearch(mockContext, mockRequest, mockResponse);
+
+ expect(mockResponse.customError).toBeCalled();
+ const error: any = mockResponse.customError.mock.calls[0][0];
+ expect(error.statusCode).toBe(404);
+ expect(error.body.message).toBe('index_not_found_exception');
+ expect(error.body.attributes).toBe(indexNotFoundException.error);
+ });
+
+ it('handler returns an error response if the search throws a general error', async () => {
+ const rejectedValue = from(Promise.reject(new Error('This is odd')));
+
+ const mockContext = {
+ search: {
+ search: jest.fn().mockReturnValue(rejectedValue),
+ },
+ };
+
+ const mockRequest = httpServerMock.createKibanaRequest({
+ body: { id: undefined, params: {} },
+ params: { strategy: 'foo' },
+ });
+ const mockResponse = httpServerMock.createResponseFactory();
+
+ await runMockSearch(mockContext, mockRequest, mockResponse);
- expect(mockContext.search.search).toBeCalled();
- expect(mockContext.search.search.mock.calls[0][0]).toStrictEqual(mockBody);
expect(mockResponse.customError).toBeCalled();
const error: any = mockResponse.customError.mock.calls[0][0];
- expect(error.body.message).toBe('oh no');
- expect(error.body.attributes.error).toBe('oops');
+ expect(error.statusCode).toBe(500);
+ expect(error.body.message).toBe('This is odd');
+ expect(error.body.attributes).toBe(undefined);
});
});
diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts
index f1a6fc09ee21f..63593bbe84a08 100644
--- a/src/plugins/data/server/search/search_service.ts
+++ b/src/plugins/data/server/search/search_service.ts
@@ -6,7 +6,7 @@
* Public License, v 1.
*/
-import { BehaviorSubject, Observable } from 'rxjs';
+import { BehaviorSubject, Observable, throwError } from 'rxjs';
import { pick } from 'lodash';
import {
CoreSetup,
@@ -18,7 +18,7 @@ import {
SharedGlobalConfig,
StartServicesAccessor,
} from 'src/core/server';
-import { catchError, first, map } from 'rxjs/operators';
+import { first } from 'rxjs/operators';
import { BfetchServerSetup } from 'src/plugins/bfetch/server';
import { ExpressionsServerSetup } from 'src/plugins/expressions/server';
import type {
@@ -64,6 +64,7 @@ import { aggShardDelay } from '../../common/search/aggs/buckets/shard_delay_fn';
import { ConfigSchema } from '../../config';
import { SessionService, IScopedSessionService, ISessionService } from './session';
import { KbnServerError } from '../../../kibana_utils/server';
+import { registerBsearchRoute } from './routes/bsearch';
type StrategyMap = Record>;
@@ -137,43 +138,7 @@ export class SearchService implements Plugin {
)
);
- bfetch.addBatchProcessingRoute<
- { request: IKibanaSearchResponse; options?: ISearchOptions },
- any
- >('/internal/bsearch', (request) => {
- const search = this.asScopedProvider(this.coreStart!)(request);
-
- return {
- onBatchItem: async ({ request: requestData, options }) => {
- return search
- .search(requestData, options)
- .pipe(
- first(),
- map((response) => {
- return {
- ...response,
- ...{
- rawResponse: shimHitsTotal(response.rawResponse),
- },
- };
- }),
- catchError((err) => {
- // eslint-disable-next-line no-throw-literal
- throw {
- statusCode: err.statusCode || 500,
- body: {
- message: err.message,
- attributes: {
- error: err.body?.error || err.message,
- },
- },
- };
- })
- )
- .toPromise();
- },
- };
- });
+ registerBsearchRoute(bfetch, core.getStartServices(), this.asScopedProvider);
core.savedObjects.registerType(searchTelemetry);
if (usageCollection) {
@@ -285,10 +250,14 @@ export class SearchService implements Plugin {
options: ISearchOptions,
deps: SearchStrategyDependencies
) => {
- const strategy = this.getSearchStrategy(
- options.strategy
- );
- return session.search(strategy, request, options, deps);
+ try {
+ const strategy = this.getSearchStrategy(
+ options.strategy
+ );
+ return session.search(strategy, request, options, deps);
+ } catch (e) {
+ return throwError(e);
+ }
};
private cancel = (id: string, options: ISearchOptions, deps: SearchStrategyDependencies) => {
diff --git a/src/plugins/data/tsconfig.json b/src/plugins/data/tsconfig.json
index 81bcb3b02e100..21560b1328840 100644
--- a/src/plugins/data/tsconfig.json
+++ b/src/plugins/data/tsconfig.json
@@ -7,7 +7,7 @@
"declaration": true,
"declarationMap": true
},
- "include": ["common/**/*", "public/**/*", "server/**/*", "config.ts"],
+ "include": ["common/**/*", "public/**/*", "server/**/*", "config.ts", "common/**/*.json"],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../bfetch/tsconfig.json" },
diff --git a/src/plugins/input_control_vis/tsconfig.json b/src/plugins/input_control_vis/tsconfig.json
new file mode 100644
index 0000000000000..bef7bc394a6cc
--- /dev/null
+++ b/src/plugins/input_control_vis/tsconfig.json
@@ -0,0 +1,21 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "composite": true,
+ "outDir": "./target/types",
+ "emitDeclarationOnly": true,
+ "declaration": true,
+ "declarationMap": true
+ },
+ "include": [
+ "public/**/*",
+ "server/**/*",
+ ],
+ "references": [
+ { "path": "../kibana_react/tsconfig.json" },
+ { "path": "../data/tsconfig.json"},
+ { "path": "../expressions/tsconfig.json" },
+ { "path": "../visualizations/tsconfig.json" },
+ { "path": "../vis_default_editor/tsconfig.json" },
+ ]
+}
diff --git a/src/plugins/kibana_utils/common/errors/index.ts b/src/plugins/kibana_utils/common/errors/index.ts
index 354cf1d504b28..f859e0728269a 100644
--- a/src/plugins/kibana_utils/common/errors/index.ts
+++ b/src/plugins/kibana_utils/common/errors/index.ts
@@ -7,3 +7,4 @@
*/
export * from './errors';
+export * from './types';
diff --git a/src/plugins/kibana_utils/common/errors/types.ts b/src/plugins/kibana_utils/common/errors/types.ts
new file mode 100644
index 0000000000000..89e83586dc115
--- /dev/null
+++ b/src/plugins/kibana_utils/common/errors/types.ts
@@ -0,0 +1,12 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+export interface KibanaServerError {
+ statusCode: number;
+ message: string;
+ attributes?: T;
+}
diff --git a/src/plugins/kibana_utils/server/index.ts b/src/plugins/kibana_utils/server/index.ts
index f95ffe5c3d7b6..821118ea4640d 100644
--- a/src/plugins/kibana_utils/server/index.ts
+++ b/src/plugins/kibana_utils/server/index.ts
@@ -18,4 +18,4 @@ export {
url,
} from '../common';
-export { KbnServerError, reportServerError } from './report_server_error';
+export { KbnServerError, reportServerError, getKbnServerError } from './report_server_error';
diff --git a/src/plugins/kibana_utils/server/report_server_error.ts b/src/plugins/kibana_utils/server/report_server_error.ts
index 664f34ca7ad51..01e80cfc7184d 100644
--- a/src/plugins/kibana_utils/server/report_server_error.ts
+++ b/src/plugins/kibana_utils/server/report_server_error.ts
@@ -6,23 +6,42 @@
* Public License, v 1.
*/
+import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { KibanaResponseFactory } from 'kibana/server';
import { KbnError } from '../common';
export class KbnServerError extends KbnError {
- constructor(message: string, public readonly statusCode: number) {
+ public errBody?: Record;
+ constructor(message: string, public readonly statusCode: number, errBody?: Record) {
super(message);
+ this.errBody = errBody;
}
}
-export function reportServerError(res: KibanaResponseFactory, err: any) {
+/**
+ * Formats any error thrown into a standardized `KbnServerError`.
+ * @param e `Error` or `ElasticsearchClientError`
+ * @returns `KbnServerError`
+ */
+export function getKbnServerError(e: Error) {
+ return new KbnServerError(
+ e.message ?? 'Unknown error',
+ e instanceof ResponseError ? e.statusCode : 500,
+ e instanceof ResponseError ? e.body : undefined
+ );
+}
+
+/**
+ *
+ * @param res Formats a `KbnServerError` into a server error response
+ * @param err
+ */
+export function reportServerError(res: KibanaResponseFactory, err: KbnServerError) {
return res.customError({
statusCode: err.statusCode ?? 500,
body: {
message: err.message,
- attributes: {
- error: err.body?.error || err.message,
- },
+ attributes: err.errBody?.error,
},
});
}
diff --git a/src/plugins/legacy_export/tsconfig.json b/src/plugins/legacy_export/tsconfig.json
new file mode 100644
index 0000000000000..ec006d492499e
--- /dev/null
+++ b/src/plugins/legacy_export/tsconfig.json
@@ -0,0 +1,16 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "composite": true,
+ "outDir": "./target/types",
+ "emitDeclarationOnly": true,
+ "declaration": true,
+ "declarationMap": true
+ },
+ "include": [
+ "server/**/*",
+ ],
+ "references": [
+ { "path": "../../core/tsconfig.json" }
+ ]
+}
diff --git a/src/plugins/saved_objects_management/common/index.ts b/src/plugins/saved_objects_management/common/index.ts
index a8395e602979c..8850899e38958 100644
--- a/src/plugins/saved_objects_management/common/index.ts
+++ b/src/plugins/saved_objects_management/common/index.ts
@@ -6,4 +6,11 @@
* Public License, v 1.
*/
-export { SavedObjectRelation, SavedObjectWithMetadata, SavedObjectMetadata } from './types';
+export {
+ SavedObjectWithMetadata,
+ SavedObjectMetadata,
+ SavedObjectRelation,
+ SavedObjectRelationKind,
+ SavedObjectInvalidRelation,
+ SavedObjectGetRelationshipsResponse,
+} from './types';
diff --git a/src/plugins/saved_objects_management/common/types.ts b/src/plugins/saved_objects_management/common/types.ts
index 8618cf4332acf..e100dfc6b23e6 100644
--- a/src/plugins/saved_objects_management/common/types.ts
+++ b/src/plugins/saved_objects_management/common/types.ts
@@ -28,12 +28,26 @@ export type SavedObjectWithMetadata = SavedObject & {
meta: SavedObjectMetadata;
};
+export type SavedObjectRelationKind = 'child' | 'parent';
+
/**
* Represents a relation between two {@link SavedObject | saved object}
*/
export interface SavedObjectRelation {
id: string;
type: string;
- relationship: 'child' | 'parent';
+ relationship: SavedObjectRelationKind;
meta: SavedObjectMetadata;
}
+
+export interface SavedObjectInvalidRelation {
+ id: string;
+ type: string;
+ relationship: SavedObjectRelationKind;
+ error: string;
+}
+
+export interface SavedObjectGetRelationshipsResponse {
+ relations: SavedObjectRelation[];
+ invalidRelations: SavedObjectInvalidRelation[];
+}
diff --git a/src/plugins/saved_objects_management/public/lib/get_relationships.test.ts b/src/plugins/saved_objects_management/public/lib/get_relationships.test.ts
index b609fac67dac1..4454907f530fe 100644
--- a/src/plugins/saved_objects_management/public/lib/get_relationships.test.ts
+++ b/src/plugins/saved_objects_management/public/lib/get_relationships.test.ts
@@ -6,6 +6,7 @@
* Public License, v 1.
*/
+import { SavedObjectGetRelationshipsResponse } from '../types';
import { httpServiceMock } from '../../../../core/public/mocks';
import { getRelationships } from './get_relationships';
@@ -22,13 +23,17 @@ describe('getRelationships', () => {
});
it('should handle successful responses', async () => {
- httpMock.get.mockResolvedValue([1, 2]);
+ const serverResponse: SavedObjectGetRelationshipsResponse = {
+ relations: [],
+ invalidRelations: [],
+ };
+ httpMock.get.mockResolvedValue(serverResponse);
const response = await getRelationships(httpMock, 'dashboard', '1', [
'search',
'index-pattern',
]);
- expect(response).toEqual([1, 2]);
+ expect(response).toEqual(serverResponse);
});
it('should handle errors', async () => {
diff --git a/src/plugins/saved_objects_management/public/lib/get_relationships.ts b/src/plugins/saved_objects_management/public/lib/get_relationships.ts
index 0eb97e1052fa4..69aeb6fbf580b 100644
--- a/src/plugins/saved_objects_management/public/lib/get_relationships.ts
+++ b/src/plugins/saved_objects_management/public/lib/get_relationships.ts
@@ -8,19 +8,19 @@
import { HttpStart } from 'src/core/public';
import { get } from 'lodash';
-import { SavedObjectRelation } from '../types';
+import { SavedObjectGetRelationshipsResponse } from '../types';
export async function getRelationships(
http: HttpStart,
type: string,
id: string,
savedObjectTypes: string[]
-): Promise {
+): Promise {
const url = `/api/kibana/management/saved_objects/relationships/${encodeURIComponent(
type
)}/${encodeURIComponent(id)}`;
try {
- return await http.get(url, {
+ return await http.get(url, {
query: {
savedObjectTypes,
},
diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/relationships.test.tsx.snap b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/relationships.test.tsx.snap
index 15e5cb89b622c..c39263f304249 100644
--- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/relationships.test.tsx.snap
+++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/__snapshots__/relationships.test.tsx.snap
@@ -28,133 +28,131 @@ exports[`Relationships should render dashboards normally 1`] = `
-
-
-
- Here are the saved objects related to MyDashboard. Deleting this dashboard affects its parent objects, but not its children.
-
-
-
-
+
+ Here are the saved objects related to MyDashboard. Deleting this dashboard affects its parent objects, but not its children.
+
+
+
+
-
+ }
+ tableLayout="fixed"
+ />
`;
@@ -231,138 +229,315 @@ exports[`Relationships should render index patterns normally 1`] = `
-
-
-
- Here are the saved objects related to MyIndexPattern*. Deleting this index-pattern affects its parent objects, but not its children.
-
-
-
-
+
+ Here are the saved objects related to MyIndexPattern*. Deleting this index-pattern affects its parent objects, but not its children.
+
+
+
+
+
+
+`;
+
+exports[`Relationships should render invalid relations 1`] = `
+
+
+
+
+
+
+
+
+ MyIndexPattern*
+
+
+
+
+
+
+
+
+
+
+ Here are the saved objects related to MyIndexPattern*. Deleting this index-pattern affects its parent objects, but not its children.
+
+
+
+
-
+ }
+ tableLayout="fixed"
+ />
`;
@@ -395,138 +570,136 @@ exports[`Relationships should render searches normally 1`] = `
-
-
-
- Here are the saved objects related to MySearch. Deleting this search affects its parent objects, but not its children.
-
-
-
-
+
+ Here are the saved objects related to MySearch. Deleting this search affects its parent objects, but not its children.
+
+
+
+
-
+ }
+ tableLayout="fixed"
+ />
`;
@@ -559,133 +732,131 @@ exports[`Relationships should render visualizations normally 1`] = `
-
-
-
- Here are the saved objects related to MyViz. Deleting this visualization affects its parent objects, but not its children.
-
-
-
-
+
+ Here are the saved objects related to MyViz. Deleting this visualization affects its parent objects, but not its children.
+
+
+
+
-
+ }
+ tableLayout="fixed"
+ />
`;
diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx
index 72a4b0f2788fa..e590520193bba 100644
--- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx
+++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.test.tsx
@@ -25,36 +25,39 @@ describe('Relationships', () => {
goInspectObject: () => {},
canGoInApp: () => true,
basePath: httpServiceMock.createSetupContract().basePath,
- getRelationships: jest.fn().mockImplementation(() => [
- {
- type: 'search',
- id: '1',
- relationship: 'parent',
- meta: {
- editUrl: '/management/kibana/objects/savedSearches/1',
- icon: 'search',
- inAppUrl: {
- path: '/app/discover#//1',
- uiCapabilitiesPath: 'discover.show',
+ getRelationships: jest.fn().mockImplementation(() => ({
+ relations: [
+ {
+ type: 'search',
+ id: '1',
+ relationship: 'parent',
+ meta: {
+ editUrl: '/management/kibana/objects/savedSearches/1',
+ icon: 'search',
+ inAppUrl: {
+ path: '/app/discover#//1',
+ uiCapabilitiesPath: 'discover.show',
+ },
+ title: 'My Search Title',
},
- title: 'My Search Title',
},
- },
- {
- type: 'visualization',
- id: '2',
- relationship: 'parent',
- meta: {
- editUrl: '/management/kibana/objects/savedVisualizations/2',
- icon: 'visualizeApp',
- inAppUrl: {
- path: '/app/visualize#/edit/2',
- uiCapabilitiesPath: 'visualize.show',
+ {
+ type: 'visualization',
+ id: '2',
+ relationship: 'parent',
+ meta: {
+ editUrl: '/management/kibana/objects/savedVisualizations/2',
+ icon: 'visualizeApp',
+ inAppUrl: {
+ path: '/app/visualize#/edit/2',
+ uiCapabilitiesPath: 'visualize.show',
+ },
+ title: 'My Visualization Title',
},
- title: 'My Visualization Title',
},
- },
- ]),
+ ],
+ invalidRelations: [],
+ })),
savedObject: {
id: '1',
type: 'index-pattern',
@@ -92,36 +95,39 @@ describe('Relationships', () => {
goInspectObject: () => {},
canGoInApp: () => true,
basePath: httpServiceMock.createSetupContract().basePath,
- getRelationships: jest.fn().mockImplementation(() => [
- {
- type: 'index-pattern',
- id: '1',
- relationship: 'child',
- meta: {
- editUrl: '/management/kibana/indexPatterns/patterns/1',
- icon: 'indexPatternApp',
- inAppUrl: {
- path: '/app/management/kibana/indexPatterns/patterns/1',
- uiCapabilitiesPath: 'management.kibana.indexPatterns',
+ getRelationships: jest.fn().mockImplementation(() => ({
+ relations: [
+ {
+ type: 'index-pattern',
+ id: '1',
+ relationship: 'child',
+ meta: {
+ editUrl: '/management/kibana/indexPatterns/patterns/1',
+ icon: 'indexPatternApp',
+ inAppUrl: {
+ path: '/app/management/kibana/indexPatterns/patterns/1',
+ uiCapabilitiesPath: 'management.kibana.indexPatterns',
+ },
+ title: 'My Index Pattern',
},
- title: 'My Index Pattern',
},
- },
- {
- type: 'visualization',
- id: '2',
- relationship: 'parent',
- meta: {
- editUrl: '/management/kibana/objects/savedVisualizations/2',
- icon: 'visualizeApp',
- inAppUrl: {
- path: '/app/visualize#/edit/2',
- uiCapabilitiesPath: 'visualize.show',
+ {
+ type: 'visualization',
+ id: '2',
+ relationship: 'parent',
+ meta: {
+ editUrl: '/management/kibana/objects/savedVisualizations/2',
+ icon: 'visualizeApp',
+ inAppUrl: {
+ path: '/app/visualize#/edit/2',
+ uiCapabilitiesPath: 'visualize.show',
+ },
+ title: 'My Visualization Title',
},
- title: 'My Visualization Title',
},
- },
- ]),
+ ],
+ invalidRelations: [],
+ })),
savedObject: {
id: '1',
type: 'search',
@@ -159,36 +165,39 @@ describe('Relationships', () => {
goInspectObject: () => {},
canGoInApp: () => true,
basePath: httpServiceMock.createSetupContract().basePath,
- getRelationships: jest.fn().mockImplementation(() => [
- {
- type: 'dashboard',
- id: '1',
- relationship: 'parent',
- meta: {
- editUrl: '/management/kibana/objects/savedDashboards/1',
- icon: 'dashboardApp',
- inAppUrl: {
- path: '/app/kibana#/dashboard/1',
- uiCapabilitiesPath: 'dashboard.show',
+ getRelationships: jest.fn().mockImplementation(() => ({
+ relations: [
+ {
+ type: 'dashboard',
+ id: '1',
+ relationship: 'parent',
+ meta: {
+ editUrl: '/management/kibana/objects/savedDashboards/1',
+ icon: 'dashboardApp',
+ inAppUrl: {
+ path: '/app/kibana#/dashboard/1',
+ uiCapabilitiesPath: 'dashboard.show',
+ },
+ title: 'My Dashboard 1',
},
- title: 'My Dashboard 1',
},
- },
- {
- type: 'dashboard',
- id: '2',
- relationship: 'parent',
- meta: {
- editUrl: '/management/kibana/objects/savedDashboards/2',
- icon: 'dashboardApp',
- inAppUrl: {
- path: '/app/kibana#/dashboard/2',
- uiCapabilitiesPath: 'dashboard.show',
+ {
+ type: 'dashboard',
+ id: '2',
+ relationship: 'parent',
+ meta: {
+ editUrl: '/management/kibana/objects/savedDashboards/2',
+ icon: 'dashboardApp',
+ inAppUrl: {
+ path: '/app/kibana#/dashboard/2',
+ uiCapabilitiesPath: 'dashboard.show',
+ },
+ title: 'My Dashboard 2',
},
- title: 'My Dashboard 2',
},
- },
- ]),
+ ],
+ invalidRelations: [],
+ })),
savedObject: {
id: '1',
type: 'visualization',
@@ -226,36 +235,39 @@ describe('Relationships', () => {
goInspectObject: () => {},
canGoInApp: () => true,
basePath: httpServiceMock.createSetupContract().basePath,
- getRelationships: jest.fn().mockImplementation(() => [
- {
- type: 'visualization',
- id: '1',
- relationship: 'child',
- meta: {
- editUrl: '/management/kibana/objects/savedVisualizations/1',
- icon: 'visualizeApp',
- inAppUrl: {
- path: '/app/visualize#/edit/1',
- uiCapabilitiesPath: 'visualize.show',
+ getRelationships: jest.fn().mockImplementation(() => ({
+ relations: [
+ {
+ type: 'visualization',
+ id: '1',
+ relationship: 'child',
+ meta: {
+ editUrl: '/management/kibana/objects/savedVisualizations/1',
+ icon: 'visualizeApp',
+ inAppUrl: {
+ path: '/app/visualize#/edit/1',
+ uiCapabilitiesPath: 'visualize.show',
+ },
+ title: 'My Visualization Title 1',
},
- title: 'My Visualization Title 1',
},
- },
- {
- type: 'visualization',
- id: '2',
- relationship: 'child',
- meta: {
- editUrl: '/management/kibana/objects/savedVisualizations/2',
- icon: 'visualizeApp',
- inAppUrl: {
- path: '/app/visualize#/edit/2',
- uiCapabilitiesPath: 'visualize.show',
+ {
+ type: 'visualization',
+ id: '2',
+ relationship: 'child',
+ meta: {
+ editUrl: '/management/kibana/objects/savedVisualizations/2',
+ icon: 'visualizeApp',
+ inAppUrl: {
+ path: '/app/visualize#/edit/2',
+ uiCapabilitiesPath: 'visualize.show',
+ },
+ title: 'My Visualization Title 2',
},
- title: 'My Visualization Title 2',
},
- },
- ]),
+ ],
+ invalidRelations: [],
+ })),
savedObject: {
id: '1',
type: 'dashboard',
@@ -324,4 +336,49 @@ describe('Relationships', () => {
expect(props.getRelationships).toHaveBeenCalled();
expect(component).toMatchSnapshot();
});
+
+ it('should render invalid relations', async () => {
+ const props: RelationshipsProps = {
+ goInspectObject: () => {},
+ canGoInApp: () => true,
+ basePath: httpServiceMock.createSetupContract().basePath,
+ getRelationships: jest.fn().mockImplementation(() => ({
+ relations: [],
+ invalidRelations: [
+ {
+ id: '1',
+ type: 'dashboard',
+ relationship: 'child',
+ error: 'Saved object [dashboard/1] not found',
+ },
+ ],
+ })),
+ savedObject: {
+ id: '1',
+ type: 'index-pattern',
+ attributes: {},
+ references: [],
+ meta: {
+ title: 'MyIndexPattern*',
+ icon: 'indexPatternApp',
+ editUrl: '#/management/kibana/indexPatterns/patterns/1',
+ inAppUrl: {
+ path: '/management/kibana/indexPatterns/patterns/1',
+ uiCapabilitiesPath: 'management.kibana.indexPatterns',
+ },
+ },
+ },
+ close: jest.fn(),
+ };
+
+ const component = shallowWithI18nProvider();
+
+ // Ensure all promises resolve
+ await new Promise((resolve) => process.nextTick(resolve));
+ // Ensure the state changes are reflected
+ component.update();
+
+ expect(props.getRelationships).toHaveBeenCalled();
+ expect(component).toMatchSnapshot();
+ });
});
diff --git a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.tsx b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.tsx
index 2d62699b6f1f2..aee61f7bc9c7a 100644
--- a/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.tsx
+++ b/src/plugins/saved_objects_management/public/management_section/objects_table/components/relationships.tsx
@@ -26,11 +26,17 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { IBasePath } from 'src/core/public';
import { getDefaultTitle, getSavedObjectLabel } from '../../../lib';
-import { SavedObjectWithMetadata, SavedObjectRelation } from '../../../types';
+import {
+ SavedObjectWithMetadata,
+ SavedObjectRelationKind,
+ SavedObjectRelation,
+ SavedObjectInvalidRelation,
+ SavedObjectGetRelationshipsResponse,
+} from '../../../types';
export interface RelationshipsProps {
basePath: IBasePath;
- getRelationships: (type: string, id: string) => Promise;
+ getRelationships: (type: string, id: string) => Promise;
savedObject: SavedObjectWithMetadata;
close: () => void;
goInspectObject: (obj: SavedObjectWithMetadata) => void;
@@ -38,17 +44,47 @@ export interface RelationshipsProps {
}
export interface RelationshipsState {
- relationships: SavedObjectRelation[];
+ relations: SavedObjectRelation[];
+ invalidRelations: SavedObjectInvalidRelation[];
isLoading: boolean;
error?: string;
}
+const relationshipColumn = {
+ field: 'relationship',
+ name: i18n.translate('savedObjectsManagement.objectsTable.relationships.columnRelationshipName', {
+ defaultMessage: 'Direct relationship',
+ }),
+ dataType: 'string',
+ sortable: false,
+ width: '125px',
+ 'data-test-subj': 'directRelationship',
+ render: (relationship: SavedObjectRelationKind) => {
+ return (
+
+ {relationship === 'parent' ? (
+
+ ) : (
+
+ )}
+
+ );
+ },
+};
+
export class Relationships extends Component {
constructor(props: RelationshipsProps) {
super(props);
this.state = {
- relationships: [],
+ relations: [],
+ invalidRelations: [],
isLoading: false,
error: undefined,
};
@@ -70,8 +106,11 @@ export class Relationships extends Component
+
+
+ ({
+ 'data-test-subj': `invalidRelationshipsTableRow`,
+ })}
+ />
+
+ >
+ );
+ }
+
+ renderRelationshipsTable() {
+ const { goInspectObject, basePath, savedObject } = this.props;
+ const { relations, isLoading, error } = this.state;
if (error) {
return this.renderError();
@@ -137,39 +250,7 @@ export class Relationships extends Component {
- if (relationship === 'parent') {
- return (
-
-
-
- );
- }
- if (relationship === 'child') {
- return (
-
-
-
- );
- }
- },
- },
+ relationshipColumn,
{
field: 'meta.title',
name: i18n.translate('savedObjectsManagement.objectsTable.relationships.columnTitleName', {
@@ -224,7 +305,7 @@ export class Relationships extends Component [
+ relations.map((relationship) => [
relationship.type,
{
value: relationship.type,
@@ -277,7 +358,7 @@ export class Relationships extends Component
+ <>
{i18n.translate(
@@ -296,7 +377,7 @@ export class Relationships extends Component
-
+ >
);
}
@@ -328,8 +409,10 @@ export class Relationships extends Component
-
- {this.renderRelationships()}
+
+ {this.renderInvalidRelationship()}
+ {this.renderRelationshipsTable()}
+
);
}
diff --git a/src/plugins/saved_objects_management/public/types.ts b/src/plugins/saved_objects_management/public/types.ts
index 37f239227475d..cdfa3c43e5af2 100644
--- a/src/plugins/saved_objects_management/public/types.ts
+++ b/src/plugins/saved_objects_management/public/types.ts
@@ -6,4 +6,11 @@
* Public License, v 1.
*/
-export { SavedObjectMetadata, SavedObjectWithMetadata, SavedObjectRelation } from '../common';
+export {
+ SavedObjectMetadata,
+ SavedObjectWithMetadata,
+ SavedObjectRelationKind,
+ SavedObjectRelation,
+ SavedObjectInvalidRelation,
+ SavedObjectGetRelationshipsResponse,
+} from '../common';
diff --git a/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts b/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts
index 631faf0c23c98..416be7d7e7426 100644
--- a/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts
+++ b/src/plugins/saved_objects_management/server/lib/find_relationships.test.ts
@@ -6,10 +6,35 @@
* Public License, v 1.
*/
+import type { SavedObject, SavedObjectError } from 'src/core/types';
+import type { SavedObjectsFindResponse } from 'src/core/server';
import { findRelationships } from './find_relationships';
import { managementMock } from '../services/management.mock';
import { savedObjectsClientMock } from '../../../../core/server/mocks';
+const createObj = (parts: Partial>): SavedObject => ({
+ id: 'id',
+ type: 'type',
+ attributes: {},
+ references: [],
+ ...parts,
+});
+
+const createFindResponse = (objs: SavedObject[]): SavedObjectsFindResponse => ({
+ saved_objects: objs.map((obj) => ({ ...obj, score: 1 })),
+ total: objs.length,
+ per_page: 20,
+ page: 1,
+});
+
+const createError = (parts: Partial): SavedObjectError => ({
+ error: 'error',
+ message: 'message',
+ metadata: {},
+ statusCode: 404,
+ ...parts,
+});
+
describe('findRelationships', () => {
let savedObjectsClient: ReturnType;
let managementService: ReturnType;
@@ -19,7 +44,7 @@ describe('findRelationships', () => {
managementService = managementMock.create();
});
- it('returns the child and parent references of the object', async () => {
+ it('calls the savedObjectClient APIs with the correct parameters', async () => {
const type = 'dashboard';
const id = 'some-id';
const references = [
@@ -36,46 +61,35 @@ describe('findRelationships', () => {
];
const referenceTypes = ['some-type', 'another-type'];
- savedObjectsClient.get.mockResolvedValue({
- id,
- type,
- attributes: {},
- references,
- });
-
+ savedObjectsClient.get.mockResolvedValue(
+ createObj({
+ id,
+ type,
+ references,
+ })
+ );
savedObjectsClient.bulkGet.mockResolvedValue({
saved_objects: [
- {
+ createObj({
type: 'some-type',
id: 'ref-1',
- attributes: {},
- references: [],
- },
- {
+ }),
+ createObj({
type: 'another-type',
id: 'ref-2',
- attributes: {},
- references: [],
- },
+ }),
],
});
-
- savedObjectsClient.find.mockResolvedValue({
- saved_objects: [
- {
+ savedObjectsClient.find.mockResolvedValue(
+ createFindResponse([
+ createObj({
type: 'parent-type',
id: 'parent-id',
- attributes: {},
- score: 1,
- references: [],
- },
- ],
- total: 1,
- per_page: 20,
- page: 1,
- });
+ }),
+ ])
+ );
- const relationships = await findRelationships({
+ await findRelationships({
type,
id,
size: 20,
@@ -101,8 +115,63 @@ describe('findRelationships', () => {
perPage: 20,
type: referenceTypes,
});
+ });
+
+ it('returns the child and parent references of the object', async () => {
+ const type = 'dashboard';
+ const id = 'some-id';
+ const references = [
+ {
+ type: 'some-type',
+ id: 'ref-1',
+ name: 'ref 1',
+ },
+ {
+ type: 'another-type',
+ id: 'ref-2',
+ name: 'ref 2',
+ },
+ ];
+ const referenceTypes = ['some-type', 'another-type'];
+
+ savedObjectsClient.get.mockResolvedValue(
+ createObj({
+ id,
+ type,
+ references,
+ })
+ );
+ savedObjectsClient.bulkGet.mockResolvedValue({
+ saved_objects: [
+ createObj({
+ type: 'some-type',
+ id: 'ref-1',
+ }),
+ createObj({
+ type: 'another-type',
+ id: 'ref-2',
+ }),
+ ],
+ });
+ savedObjectsClient.find.mockResolvedValue(
+ createFindResponse([
+ createObj({
+ type: 'parent-type',
+ id: 'parent-id',
+ }),
+ ])
+ );
+
+ const { relations, invalidRelations } = await findRelationships({
+ type,
+ id,
+ size: 20,
+ client: savedObjectsClient,
+ referenceTypes,
+ savedObjectsManagement: managementService,
+ });
- expect(relationships).toEqual([
+ expect(relations).toEqual([
{
id: 'ref-1',
relationship: 'child',
@@ -122,6 +191,70 @@ describe('findRelationships', () => {
meta: expect.any(Object),
},
]);
+ expect(invalidRelations).toHaveLength(0);
+ });
+
+ it('returns the invalid relations', async () => {
+ const type = 'dashboard';
+ const id = 'some-id';
+ const references = [
+ {
+ type: 'some-type',
+ id: 'ref-1',
+ name: 'ref 1',
+ },
+ {
+ type: 'another-type',
+ id: 'ref-2',
+ name: 'ref 2',
+ },
+ ];
+ const referenceTypes = ['some-type', 'another-type'];
+
+ savedObjectsClient.get.mockResolvedValue(
+ createObj({
+ id,
+ type,
+ references,
+ })
+ );
+ const ref1Error = createError({ message: 'Not found' });
+ savedObjectsClient.bulkGet.mockResolvedValue({
+ saved_objects: [
+ createObj({
+ type: 'some-type',
+ id: 'ref-1',
+ error: ref1Error,
+ }),
+ createObj({
+ type: 'another-type',
+ id: 'ref-2',
+ }),
+ ],
+ });
+ savedObjectsClient.find.mockResolvedValue(createFindResponse([]));
+
+ const { relations, invalidRelations } = await findRelationships({
+ type,
+ id,
+ size: 20,
+ client: savedObjectsClient,
+ referenceTypes,
+ savedObjectsManagement: managementService,
+ });
+
+ expect(relations).toEqual([
+ {
+ id: 'ref-2',
+ relationship: 'child',
+ type: 'another-type',
+ meta: expect.any(Object),
+ },
+ ]);
+
+ expect(invalidRelations).toEqual([
+ { type: 'some-type', id: 'ref-1', relationship: 'child', error: ref1Error.message },
+ ]);
});
it('uses the management service to consolidate the relationship objects', async () => {
@@ -144,32 +277,24 @@ describe('findRelationships', () => {
uiCapabilitiesPath: 'uiCapabilitiesPath',
});
- savedObjectsClient.get.mockResolvedValue({
- id,
- type,
- attributes: {},
- references,
- });
-
+ savedObjectsClient.get.mockResolvedValue(
+ createObj({
+ id,
+ type,
+ references,
+ })
+ );
savedObjectsClient.bulkGet.mockResolvedValue({
saved_objects: [
- {
+ createObj({
type: 'some-type',
id: 'ref-1',
- attributes: {},
- references: [],
- },
+ }),
],
});
+ savedObjectsClient.find.mockResolvedValue(createFindResponse([]));
- savedObjectsClient.find.mockResolvedValue({
- saved_objects: [],
- total: 0,
- per_page: 20,
- page: 1,
- });
-
- const relationships = await findRelationships({
+ const { relations } = await findRelationships({
type,
id,
size: 20,
@@ -183,7 +308,7 @@ describe('findRelationships', () => {
expect(managementService.getEditUrl).toHaveBeenCalledTimes(1);
expect(managementService.getInAppUrl).toHaveBeenCalledTimes(1);
- expect(relationships).toEqual([
+ expect(relations).toEqual([
{
id: 'ref-1',
relationship: 'child',
diff --git a/src/plugins/saved_objects_management/server/lib/find_relationships.ts b/src/plugins/saved_objects_management/server/lib/find_relationships.ts
index 0ceef484196a3..bc6568e73c4e2 100644
--- a/src/plugins/saved_objects_management/server/lib/find_relationships.ts
+++ b/src/plugins/saved_objects_management/server/lib/find_relationships.ts
@@ -9,7 +9,11 @@
import { SavedObjectsClientContract } from 'src/core/server';
import { injectMetaAttributes } from './inject_meta_attributes';
import { ISavedObjectsManagement } from '../services';
-import { SavedObjectRelation, SavedObjectWithMetadata } from '../types';
+import {
+ SavedObjectInvalidRelation,
+ SavedObjectWithMetadata,
+ SavedObjectGetRelationshipsResponse,
+} from '../types';
export async function findRelationships({
type,
@@ -25,17 +29,19 @@ export async function findRelationships({
client: SavedObjectsClientContract;
referenceTypes: string[];
savedObjectsManagement: ISavedObjectsManagement;
-}): Promise {
+}): Promise {
const { references = [] } = await client.get(type, id);
// Use a map to avoid duplicates, it does happen but have a different "name" in the reference
- const referencedToBulkGetOpts = new Map(
- references.map((ref) => [`${ref.type}:${ref.id}`, { id: ref.id, type: ref.type }])
- );
+ const childrenReferences = [
+ ...new Map(
+ references.map((ref) => [`${ref.type}:${ref.id}`, { id: ref.id, type: ref.type }])
+ ).values(),
+ ];
const [childReferencesResponse, parentReferencesResponse] = await Promise.all([
- referencedToBulkGetOpts.size > 0
- ? client.bulkGet([...referencedToBulkGetOpts.values()])
+ childrenReferences.length > 0
+ ? client.bulkGet(childrenReferences)
: Promise.resolve({ saved_objects: [] }),
client.find({
hasReference: { type, id },
@@ -44,28 +50,37 @@ export async function findRelationships({
}),
]);
- return childReferencesResponse.saved_objects
- .map((obj) => injectMetaAttributes(obj, savedObjectsManagement))
- .map(extractCommonProperties)
- .map(
- (obj) =>
- ({
- ...obj,
- relationship: 'child',
- } as SavedObjectRelation)
- )
- .concat(
- parentReferencesResponse.saved_objects
- .map((obj) => injectMetaAttributes(obj, savedObjectsManagement))
- .map(extractCommonProperties)
- .map(
- (obj) =>
- ({
- ...obj,
- relationship: 'parent',
- } as SavedObjectRelation)
- )
- );
+ const invalidRelations: SavedObjectInvalidRelation[] = childReferencesResponse.saved_objects
+ .filter((obj) => Boolean(obj.error))
+ .map((obj) => ({
+ id: obj.id,
+ type: obj.type,
+ relationship: 'child',
+ error: obj.error!.message,
+ }));
+
+ const relations = [
+ ...childReferencesResponse.saved_objects
+ .filter((obj) => !obj.error)
+ .map((obj) => injectMetaAttributes(obj, savedObjectsManagement))
+ .map(extractCommonProperties)
+ .map((obj) => ({
+ ...obj,
+ relationship: 'child' as const,
+ })),
+ ...parentReferencesResponse.saved_objects
+ .map((obj) => injectMetaAttributes(obj, savedObjectsManagement))
+ .map(extractCommonProperties)
+ .map((obj) => ({
+ ...obj,
+ relationship: 'parent' as const,
+ })),
+ ];
+
+ return {
+ relations,
+ invalidRelations,
+ };
}
function extractCommonProperties(savedObject: SavedObjectWithMetadata) {
diff --git a/src/plugins/saved_objects_management/server/routes/relationships.ts b/src/plugins/saved_objects_management/server/routes/relationships.ts
index 3a52c973fde8d..5417ff2926120 100644
--- a/src/plugins/saved_objects_management/server/routes/relationships.ts
+++ b/src/plugins/saved_objects_management/server/routes/relationships.ts
@@ -38,7 +38,7 @@ export const registerRelationshipsRoute = (
? req.query.savedObjectTypes
: [req.query.savedObjectTypes];
- const relations = await findRelationships({
+ const findRelationsResponse = await findRelationships({
type,
id,
client,
@@ -48,7 +48,7 @@ export const registerRelationshipsRoute = (
});
return res.ok({
- body: relations,
+ body: findRelationsResponse,
});
})
);
diff --git a/src/plugins/saved_objects_management/server/types.ts b/src/plugins/saved_objects_management/server/types.ts
index 710bb5db7d1cb..562970d2d2dcd 100644
--- a/src/plugins/saved_objects_management/server/types.ts
+++ b/src/plugins/saved_objects_management/server/types.ts
@@ -12,4 +12,11 @@ export interface SavedObjectsManagementPluginSetup {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SavedObjectsManagementPluginStart {}
-export { SavedObjectMetadata, SavedObjectWithMetadata, SavedObjectRelation } from '../common';
+export {
+ SavedObjectMetadata,
+ SavedObjectWithMetadata,
+ SavedObjectRelationKind,
+ SavedObjectRelation,
+ SavedObjectInvalidRelation,
+ SavedObjectGetRelationshipsResponse,
+} from '../common';
diff --git a/test/accessibility/apps/kibana_overview.ts b/test/accessibility/apps/kibana_overview.ts
index c26a042b10e72..eb0b54ad07aa7 100644
--- a/test/accessibility/apps/kibana_overview.ts
+++ b/test/accessibility/apps/kibana_overview.ts
@@ -16,7 +16,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
before(async () => {
- await esArchiver.load('empty_kibana');
+ await esArchiver.emptyKibanaIndex();
await PageObjects.common.navigateToApp('kibanaOverview');
});
@@ -25,7 +25,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
useActualUrl: true,
});
await PageObjects.home.removeSampleDataSet('flights');
- await esArchiver.unload('empty_kibana');
});
it('Getting started view', async () => {
diff --git a/test/api_integration/apis/home/sample_data.ts b/test/api_integration/apis/home/sample_data.ts
index 042aff1375267..ebda93b12dc20 100644
--- a/test/api_integration/apis/home/sample_data.ts
+++ b/test/api_integration/apis/home/sample_data.ts
@@ -11,11 +11,15 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
const es = getService('es');
const MILLISECOND_IN_WEEK = 1000 * 60 * 60 * 24 * 7;
describe('sample data apis', () => {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ });
describe('list', () => {
it('should return list of sample data sets with installed status', async () => {
const resp = await supertest.get(`/api/sample_data`).set('kbn-xsrf', 'kibana').expect(200);
diff --git a/test/api_integration/apis/saved_objects/bulk_create.ts b/test/api_integration/apis/saved_objects/bulk_create.ts
index a548172365b07..d7cdee16214a8 100644
--- a/test/api_integration/apis/saved_objects/bulk_create.ts
+++ b/test/api_integration/apis/saved_objects/bulk_create.ts
@@ -97,10 +97,11 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
- it('should return 200 with individual responses', async () =>
+ it('should return 200 with errors', async () => {
+ await new Promise((resolve) => setTimeout(resolve, 2000));
await supertest
.post('/api/saved_objects/_bulk_create')
.send(BULK_REQUESTS)
@@ -109,38 +110,27 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.body).to.eql({
saved_objects: [
{
- type: 'visualization',
- id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
- updated_at: resp.body.saved_objects[0].updated_at,
- version: resp.body.saved_objects[0].version,
- attributes: {
- title: 'An existing visualization',
- },
- references: [],
- namespaces: ['default'],
- migrationVersion: {
- visualization: resp.body.saved_objects[0].migrationVersion.visualization,
+ id: BULK_REQUESTS[0].id,
+ type: BULK_REQUESTS[0].type,
+ error: {
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
+ statusCode: 500,
},
- coreMigrationVersion: KIBANA_VERSION, // updated from 1.2.3 to the latest kibana version
},
{
- type: 'dashboard',
- id: 'a01b2f57-fcfd-4864-b735-09e28f0d815e',
- updated_at: resp.body.saved_objects[1].updated_at,
- version: resp.body.saved_objects[1].version,
- attributes: {
- title: 'A great new dashboard',
- },
- references: [],
- namespaces: ['default'],
- migrationVersion: {
- dashboard: resp.body.saved_objects[1].migrationVersion.dashboard,
+ id: BULK_REQUESTS[1].id,
+ type: BULK_REQUESTS[1].type,
+ error: {
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
+ statusCode: 500,
},
- coreMigrationVersion: KIBANA_VERSION,
},
],
});
- }));
+ });
+ });
});
});
}
diff --git a/test/api_integration/apis/saved_objects/bulk_get.ts b/test/api_integration/apis/saved_objects/bulk_get.ts
index 46631225f8e8a..b9536843d30c9 100644
--- a/test/api_integration/apis/saved_objects/bulk_get.ts
+++ b/test/api_integration/apis/saved_objects/bulk_get.ts
@@ -108,7 +108,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return 200 with individual responses', async () =>
diff --git a/test/api_integration/apis/saved_objects/bulk_update.ts b/test/api_integration/apis/saved_objects/bulk_update.ts
index 5a2496b6dde81..2cf3ade406a93 100644
--- a/test/api_integration/apis/saved_objects/bulk_update.ts
+++ b/test/api_integration/apis/saved_objects/bulk_update.ts
@@ -235,10 +235,10 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
- it('should return generic 404', async () => {
+ it('should return 200 with errors', async () => {
const response = await supertest
.put(`/api/saved_objects/_bulk_update`)
.send([
@@ -267,9 +267,9 @@ export default function ({ getService }: FtrProviderContext) {
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
type: 'visualization',
error: {
- statusCode: 404,
- error: 'Not Found',
- message: 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] not found',
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
},
});
@@ -277,9 +277,9 @@ export default function ({ getService }: FtrProviderContext) {
id: 'be3733a0-9efe-11e7-acb3-3dab96693fab',
type: 'dashboard',
error: {
- statusCode: 404,
- error: 'Not Found',
- message: 'Saved object [dashboard/be3733a0-9efe-11e7-acb3-3dab96693fab] not found',
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
},
});
});
diff --git a/test/api_integration/apis/saved_objects/create.ts b/test/api_integration/apis/saved_objects/create.ts
index 551e082630e8f..833cb127d0023 100644
--- a/test/api_integration/apis/saved_objects/create.ts
+++ b/test/api_integration/apis/saved_objects/create.ts
@@ -82,10 +82,10 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
- it('should return 200 and create kibana index', async () => {
+ it('should return 500 and not auto-create saved objects index', async () => {
await supertest
.post(`/api/saved_objects/visualization`)
.send({
@@ -93,50 +93,16 @@ export default function ({ getService }: FtrProviderContext) {
title: 'My favorite vis',
},
})
- .expect(200)
+ .expect(500)
.then((resp) => {
- // loose uuid validation
- expect(resp.body)
- .to.have.property('id')
- .match(/^[0-9a-f-]{36}$/);
-
- // loose ISO8601 UTC time with milliseconds validation
- expect(resp.body)
- .to.have.property('updated_at')
- .match(/^[\d-]{10}T[\d:\.]{12}Z$/);
-
expect(resp.body).to.eql({
- id: resp.body.id,
- type: 'visualization',
- migrationVersion: resp.body.migrationVersion,
- coreMigrationVersion: KIBANA_VERSION,
- updated_at: resp.body.updated_at,
- version: resp.body.version,
- attributes: {
- title: 'My favorite vis',
- },
- references: [],
- namespaces: ['default'],
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred.',
+ statusCode: 500,
});
- expect(resp.body.migrationVersion).to.be.ok();
});
- expect((await es.indices.exists({ index: '.kibana' })).body).to.be(true);
- });
-
- it('result should have the latest coreMigrationVersion', async () => {
- await supertest
- .post(`/api/saved_objects/visualization`)
- .send({
- attributes: {
- title: 'My favorite vis',
- },
- coreMigrationVersion: '1.2.3',
- })
- .expect(200)
- .then((resp) => {
- expect(resp.body.coreMigrationVersion).to.eql(KIBANA_VERSION);
- });
+ expect((await es.indices.exists({ index: '.kibana' })).body).to.be(false);
});
});
});
diff --git a/test/api_integration/apis/saved_objects/delete.ts b/test/api_integration/apis/saved_objects/delete.ts
index 9ba51b4b91468..d2dd4454bdf1e 100644
--- a/test/api_integration/apis/saved_objects/delete.ts
+++ b/test/api_integration/apis/saved_objects/delete.ts
@@ -44,7 +44,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('returns generic 404 when kibana index is missing', async () =>
diff --git a/test/api_integration/apis/saved_objects/export.ts b/test/api_integration/apis/saved_objects/export.ts
index a45191f24d872..c0d5430070951 100644
--- a/test/api_integration/apis/saved_objects/export.ts
+++ b/test/api_integration/apis/saved_objects/export.ts
@@ -534,7 +534,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return empty response', async () => {
diff --git a/test/api_integration/apis/saved_objects/find.ts b/test/api_integration/apis/saved_objects/find.ts
index 7aa4de86baa69..5f549dc6c5780 100644
--- a/test/api_integration/apis/saved_objects/find.ts
+++ b/test/api_integration/apis/saved_objects/find.ts
@@ -40,7 +40,7 @@ export default function ({ getService }: FtrProviderContext) {
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
- version: 'WzIsMV0=',
+ version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
@@ -137,7 +137,7 @@ export default function ({ getService }: FtrProviderContext) {
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
- version: 'WzIsMV0=',
+ version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
@@ -174,7 +174,7 @@ export default function ({ getService }: FtrProviderContext) {
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
- version: 'WzIsMV0=',
+ version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
@@ -209,7 +209,7 @@ export default function ({ getService }: FtrProviderContext) {
score: 0,
type: 'visualization',
updated_at: '2017-09-21T18:51:23.794Z',
- version: 'WzYsMV0=',
+ version: 'WzIyLDJd',
},
],
});
@@ -256,7 +256,7 @@ export default function ({ getService }: FtrProviderContext) {
migrationVersion: resp.body.saved_objects[0].migrationVersion,
coreMigrationVersion: KIBANA_VERSION,
updated_at: '2017-09-21T18:51:23.794Z',
- version: 'WzIsMV0=',
+ version: 'WzE4LDJd',
},
],
});
@@ -426,11 +426,11 @@ export default function ({ getService }: FtrProviderContext) {
}));
});
- describe.skip('without kibana index', () => {
+ describe('without kibana index', () => {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return 200 with empty response', async () =>
diff --git a/test/api_integration/apis/saved_objects/get.ts b/test/api_integration/apis/saved_objects/get.ts
index ff47b9df218dc..9bb6e32004c81 100644
--- a/test/api_integration/apis/saved_objects/get.ts
+++ b/test/api_integration/apis/saved_objects/get.ts
@@ -78,7 +78,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return basic 404 without mentioning index', async () =>
diff --git a/test/api_integration/apis/saved_objects/resolve_import_errors.ts b/test/api_integration/apis/saved_objects/resolve_import_errors.ts
index 3686c46b229b1..042741476bb8e 100644
--- a/test/api_integration/apis/saved_objects/resolve_import_errors.ts
+++ b/test/api_integration/apis/saved_objects/resolve_import_errors.ts
@@ -13,6 +13,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
+ const es = getService('legacyEs');
describe('resolve_import_errors', () => {
// mock success results including metadata
@@ -34,7 +35,14 @@ export default function ({ getService }: FtrProviderContext) {
describe('without kibana index', () => {
// Cleanup data that got created in import
- after(() => esArchiver.unload('saved_objects/basic'));
+ before(
+ async () =>
+ // just in case the kibana server has recreated it
+ await es.indices.delete({
+ index: '.kibana*',
+ ignore: [404],
+ })
+ );
it('should return 200 and import nothing when empty parameters are passed in', async () => {
await supertest
@@ -51,7 +59,7 @@ export default function ({ getService }: FtrProviderContext) {
});
});
- it('should return 200 and import everything when overwrite parameters contains all objects', async () => {
+ it('should return 200 with internal server errors', async () => {
await supertest
.post('/api/saved_objects/_resolve_import_errors')
.field(
@@ -78,12 +86,42 @@ export default function ({ getService }: FtrProviderContext) {
.expect(200)
.then((resp) => {
expect(resp.body).to.eql({
- success: true,
- successCount: 3,
- successResults: [
- { ...indexPattern, overwrite: true },
- { ...visualization, overwrite: true },
- { ...dashboard, overwrite: true },
+ successCount: 0,
+ success: false,
+ errors: [
+ {
+ ...indexPattern,
+ ...{ title: indexPattern.meta.title },
+ overwrite: true,
+ error: {
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
+ type: 'unknown',
+ },
+ },
+ {
+ ...visualization,
+ ...{ title: visualization.meta.title },
+ overwrite: true,
+ error: {
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
+ type: 'unknown',
+ },
+ },
+ {
+ ...dashboard,
+ ...{ title: dashboard.meta.title },
+ overwrite: true,
+ error: {
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred',
+ type: 'unknown',
+ },
+ },
],
warnings: [],
});
diff --git a/test/api_integration/apis/saved_objects/update.ts b/test/api_integration/apis/saved_objects/update.ts
index d5346e82ce98c..da7285a430fdd 100644
--- a/test/api_integration/apis/saved_objects/update.ts
+++ b/test/api_integration/apis/saved_objects/update.ts
@@ -121,10 +121,10 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
- it('should return generic 404', async () =>
+ it('should return 500', async () =>
await supertest
.put(`/api/saved_objects/visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab`)
.send({
@@ -132,13 +132,12 @@ export default function ({ getService }: FtrProviderContext) {
title: 'My second favorite vis',
},
})
- .expect(404)
+ .expect(500)
.then((resp) => {
expect(resp.body).eql({
- statusCode: 404,
- error: 'Not Found',
- message:
- 'Saved object [visualization/dd7caf20-9efd-11e7-acb3-3dab96693fab] not found',
+ statusCode: 500,
+ error: 'Internal Server Error',
+ message: 'An internal server error occurred.',
});
}));
});
diff --git a/test/api_integration/apis/saved_objects_management/find.ts b/test/api_integration/apis/saved_objects_management/find.ts
index acc01c73de674..8453b542903a4 100644
--- a/test/api_integration/apis/saved_objects_management/find.ts
+++ b/test/api_integration/apis/saved_objects_management/find.ts
@@ -42,7 +42,7 @@ export default function ({ getService }: FtrProviderContext) {
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
- version: 'WzIsMV0=',
+ version: 'WzE4LDJd',
attributes: {
title: 'Count of requests',
},
@@ -184,7 +184,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return 200 with empty response', async () =>
diff --git a/test/api_integration/apis/saved_objects_management/get.ts b/test/api_integration/apis/saved_objects_management/get.ts
index bc05d7e392bb9..70e1faa9fd22b 100644
--- a/test/api_integration/apis/saved_objects_management/get.ts
+++ b/test/api_integration/apis/saved_objects_management/get.ts
@@ -45,7 +45,7 @@ export default function ({ getService }: FtrProviderContext) {
before(
async () =>
// just in case the kibana server has recreated it
- await es.indices.delete({ index: '.kibana' }, { ignore: [404] })
+ await es.indices.delete({ index: '.kibana*' }, { ignore: [404] })
);
it('should return 404 for object that no longer exists', async () =>
diff --git a/test/api_integration/apis/saved_objects_management/relationships.ts b/test/api_integration/apis/saved_objects_management/relationships.ts
index 185c6ded01de4..6dea461f790e8 100644
--- a/test/api_integration/apis/saved_objects_management/relationships.ts
+++ b/test/api_integration/apis/saved_objects_management/relationships.ts
@@ -14,23 +14,32 @@ export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');
- const responseSchema = schema.arrayOf(
- schema.object({
- id: schema.string(),
- type: schema.string(),
- relationship: schema.oneOf([schema.literal('parent'), schema.literal('child')]),
- meta: schema.object({
- title: schema.string(),
- icon: schema.string(),
- editUrl: schema.string(),
- inAppUrl: schema.object({
- path: schema.string(),
- uiCapabilitiesPath: schema.string(),
- }),
- namespaceType: schema.string(),
+ const relationSchema = schema.object({
+ id: schema.string(),
+ type: schema.string(),
+ relationship: schema.oneOf([schema.literal('parent'), schema.literal('child')]),
+ meta: schema.object({
+ title: schema.string(),
+ icon: schema.string(),
+ editUrl: schema.string(),
+ inAppUrl: schema.object({
+ path: schema.string(),
+ uiCapabilitiesPath: schema.string(),
}),
- })
- );
+ namespaceType: schema.string(),
+ }),
+ });
+ const invalidRelationSchema = schema.object({
+ id: schema.string(),
+ type: schema.string(),
+ relationship: schema.oneOf([schema.literal('parent'), schema.literal('child')]),
+ error: schema.string(),
+ });
+
+ const responseSchema = schema.object({
+ relations: schema.arrayOf(relationSchema),
+ invalidRelations: schema.arrayOf(invalidRelationSchema),
+ });
describe('relationships', () => {
before(async () => {
@@ -64,7 +73,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(relationshipsUrl('search', '960372e0-3224-11e8-a572-ffca06da1357'))
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '8963ca30-3224-11e8-a572-ffca06da1357',
type: 'index-pattern',
@@ -108,7 +117,7 @@ export default function ({ getService }: FtrProviderContext) {
)
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '8963ca30-3224-11e8-a572-ffca06da1357',
type: 'index-pattern',
@@ -145,8 +154,7 @@ export default function ({ getService }: FtrProviderContext) {
]);
});
- // TODO: https://github.com/elastic/kibana/issues/19713 causes this test to fail.
- it.skip('should return 404 if search finds no results', async () => {
+ it('should return 404 if search finds no results', async () => {
await supertest
.get(relationshipsUrl('search', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))
.expect(404);
@@ -169,7 +177,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(relationshipsUrl('dashboard', 'b70c7ae0-3224-11e8-a572-ffca06da1357'))
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: 'add810b0-3224-11e8-a572-ffca06da1357',
type: 'visualization',
@@ -210,7 +218,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(relationshipsUrl('dashboard', 'b70c7ae0-3224-11e8-a572-ffca06da1357', ['search']))
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: 'add810b0-3224-11e8-a572-ffca06da1357',
type: 'visualization',
@@ -246,8 +254,7 @@ export default function ({ getService }: FtrProviderContext) {
]);
});
- // TODO: https://github.com/elastic/kibana/issues/19713 causes this test to fail.
- it.skip('should return 404 if dashboard finds no results', async () => {
+ it('should return 404 if dashboard finds no results', async () => {
await supertest
.get(relationshipsUrl('dashboard', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'))
.expect(404);
@@ -270,7 +277,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(relationshipsUrl('visualization', 'a42c0580-3224-11e8-a572-ffca06da1357'))
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
@@ -313,7 +320,7 @@ export default function ({ getService }: FtrProviderContext) {
)
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
@@ -356,7 +363,7 @@ export default function ({ getService }: FtrProviderContext) {
.get(relationshipsUrl('index-pattern', '8963ca30-3224-11e8-a572-ffca06da1357'))
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
@@ -399,7 +406,7 @@ export default function ({ getService }: FtrProviderContext) {
)
.expect(200);
- expect(resp.body).to.eql([
+ expect(resp.body.relations).to.eql([
{
id: '960372e0-3224-11e8-a572-ffca06da1357',
type: 'search',
@@ -425,5 +432,48 @@ export default function ({ getService }: FtrProviderContext) {
.expect(404);
});
});
+
+ describe('invalid references', () => {
+ it('should validate the response schema', async () => {
+ const resp = await supertest.get(relationshipsUrl('dashboard', 'invalid-refs')).expect(200);
+
+ expect(() => {
+ responseSchema.validate(resp.body);
+ }).not.to.throwError();
+ });
+
+ it('should return the invalid relations', async () => {
+ const resp = await supertest.get(relationshipsUrl('dashboard', 'invalid-refs')).expect(200);
+
+ expect(resp.body).to.eql({
+ invalidRelations: [
+ {
+ error: 'Saved object [visualization/invalid-vis] not found',
+ id: 'invalid-vis',
+ relationship: 'child',
+ type: 'visualization',
+ },
+ ],
+ relations: [
+ {
+ id: 'add810b0-3224-11e8-a572-ffca06da1357',
+ meta: {
+ editUrl:
+ '/management/kibana/objects/savedVisualizations/add810b0-3224-11e8-a572-ffca06da1357',
+ icon: 'visualizeApp',
+ inAppUrl: {
+ path: '/app/visualize#/edit/add810b0-3224-11e8-a572-ffca06da1357',
+ uiCapabilitiesPath: 'visualize.show',
+ },
+ namespaceType: 'single',
+ title: 'Visualization',
+ },
+ relationship: 'child',
+ type: 'visualization',
+ },
+ ],
+ });
+ });
+ });
});
}
diff --git a/test/api_integration/apis/search/bsearch.ts b/test/api_integration/apis/search/bsearch.ts
new file mode 100644
index 0000000000000..504680d28bf83
--- /dev/null
+++ b/test/api_integration/apis/search/bsearch.ts
@@ -0,0 +1,172 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import expect from '@kbn/expect';
+import request from 'superagent';
+import { FtrProviderContext } from '../../ftr_provider_context';
+import { painlessErrReq } from './painless_err_req';
+import { verifyErrorResponse } from './verify_error';
+
+function parseBfetchResponse(resp: request.Response): Array> {
+ return resp.text
+ .trim()
+ .split('\n')
+ .map((item) => JSON.parse(item));
+}
+
+export default function ({ getService }: FtrProviderContext) {
+ const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
+
+ describe('bsearch', () => {
+ describe('post', () => {
+ it('should return 200 a single response', async () => {
+ const resp = await supertest.post(`/internal/bsearch`).send({
+ batch: [
+ {
+ request: {
+ params: {
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ },
+ },
+ ],
+ });
+
+ const jsonBody = JSON.parse(resp.text);
+
+ expect(resp.status).to.be(200);
+ expect(jsonBody.id).to.be(0);
+ expect(jsonBody.result.isPartial).to.be(false);
+ expect(jsonBody.result.isRunning).to.be(false);
+ expect(jsonBody.result).to.have.property('rawResponse');
+ });
+
+ it('should return a batch of successful resposes', async () => {
+ const resp = await supertest.post(`/internal/bsearch`).send({
+ batch: [
+ {
+ request: {
+ params: {
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ },
+ },
+ {
+ request: {
+ params: {
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ },
+ },
+ ],
+ });
+
+ expect(resp.status).to.be(200);
+ const parsedResponse = parseBfetchResponse(resp);
+ expect(parsedResponse).to.have.length(2);
+ parsedResponse.forEach((responseJson) => {
+ expect(responseJson.result.isPartial).to.be(false);
+ expect(responseJson.result.isRunning).to.be(false);
+ expect(responseJson.result).to.have.property('rawResponse');
+ });
+ });
+
+ it('should return error for not found strategy', async () => {
+ const resp = await supertest.post(`/internal/bsearch`).send({
+ batch: [
+ {
+ request: {
+ params: {
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ },
+ options: {
+ strategy: 'wtf',
+ },
+ },
+ ],
+ });
+
+ expect(resp.status).to.be(200);
+ parseBfetchResponse(resp).forEach((responseJson, i) => {
+ expect(responseJson.id).to.be(i);
+ verifyErrorResponse(responseJson.error, 404, 'Search strategy wtf not found');
+ });
+ });
+
+ it('should return 400 when index type is provided in OSS', async () => {
+ const resp = await supertest.post(`/internal/bsearch`).send({
+ batch: [
+ {
+ request: {
+ indexType: 'baad',
+ params: {
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ },
+ },
+ ],
+ });
+
+ expect(resp.status).to.be(200);
+ parseBfetchResponse(resp).forEach((responseJson, i) => {
+ expect(responseJson.id).to.be(i);
+ verifyErrorResponse(responseJson.error, 400, 'Unsupported index pattern type baad');
+ });
+ });
+
+ describe('painless', () => {
+ before(async () => {
+ await esArchiver.loadIfNeeded(
+ '../../../functional/fixtures/es_archiver/logstash_functional'
+ );
+ });
+
+ after(async () => {
+ await esArchiver.unload('../../../functional/fixtures/es_archiver/logstash_functional');
+ });
+ it('should return 400 for Painless error', async () => {
+ const resp = await supertest.post(`/internal/bsearch`).send({
+ batch: [
+ {
+ request: painlessErrReq,
+ },
+ ],
+ });
+
+ expect(resp.status).to.be(200);
+ parseBfetchResponse(resp).forEach((responseJson, i) => {
+ expect(responseJson.id).to.be(i);
+ verifyErrorResponse(responseJson.error, 400, 'search_phase_execution_exception', true);
+ });
+ });
+ });
+ });
+ });
+}
diff --git a/test/api_integration/apis/search/index.ts b/test/api_integration/apis/search/index.ts
index 2f21825d6902f..6e90bf0f22c51 100644
--- a/test/api_integration/apis/search/index.ts
+++ b/test/api_integration/apis/search/index.ts
@@ -11,6 +11,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ loadTestFile }: FtrProviderContext) {
describe('search', () => {
loadTestFile(require.resolve('./search'));
+ loadTestFile(require.resolve('./bsearch'));
loadTestFile(require.resolve('./msearch'));
});
}
diff --git a/test/api_integration/apis/search/painless_err_req.ts b/test/api_integration/apis/search/painless_err_req.ts
new file mode 100644
index 0000000000000..6fbf6565d7a9e
--- /dev/null
+++ b/test/api_integration/apis/search/painless_err_req.ts
@@ -0,0 +1,44 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+export const painlessErrReq = {
+ params: {
+ index: 'log*',
+ body: {
+ size: 500,
+ fields: ['*'],
+ script_fields: {
+ invalid_scripted_field: {
+ script: {
+ source: 'invalid',
+ lang: 'painless',
+ },
+ },
+ },
+ stored_fields: ['*'],
+ query: {
+ bool: {
+ filter: [
+ {
+ match_all: {},
+ },
+ {
+ range: {
+ '@timestamp': {
+ gte: '2015-01-19T12:27:55.047Z',
+ lte: '2021-01-19T12:27:55.047Z',
+ format: 'strict_date_optional_time',
+ },
+ },
+ },
+ ],
+ },
+ },
+ },
+ },
+};
diff --git a/test/api_integration/apis/search/search.ts b/test/api_integration/apis/search/search.ts
index fc13189a40753..e43c449309306 100644
--- a/test/api_integration/apis/search/search.ts
+++ b/test/api_integration/apis/search/search.ts
@@ -8,11 +8,22 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
+import { painlessErrReq } from './painless_err_req';
+import { verifyErrorResponse } from './verify_error';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
describe('search', () => {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ await esArchiver.loadIfNeeded('../../../functional/fixtures/es_archiver/logstash_functional');
+ });
+
+ after(async () => {
+ await esArchiver.unload('../../../functional/fixtures/es_archiver/logstash_functional');
+ });
describe('post', () => {
it('should return 200 when correctly formatted searches are provided', async () => {
const resp = await supertest
@@ -28,13 +39,37 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(200);
+ expect(resp.status).to.be(200);
expect(resp.body.isPartial).to.be(false);
expect(resp.body.isRunning).to.be(false);
expect(resp.body).to.have.property('rawResponse');
});
- it('should return 404 when if no strategy is provided', async () =>
- await supertest
+ it('should return 200 if terminated early', async () => {
+ const resp = await supertest
+ .post(`/internal/search/es`)
+ .send({
+ params: {
+ terminateAfter: 1,
+ index: 'log*',
+ size: 1000,
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ })
+ .expect(200);
+
+ expect(resp.status).to.be(200);
+ expect(resp.body.isPartial).to.be(false);
+ expect(resp.body.isRunning).to.be(false);
+ expect(resp.body.rawResponse.terminated_early).to.be(true);
+ });
+
+ it('should return 404 when if no strategy is provided', async () => {
+ const resp = await supertest
.post(`/internal/search`)
.send({
body: {
@@ -43,7 +78,10 @@ export default function ({ getService }: FtrProviderContext) {
},
},
})
- .expect(404));
+ .expect(404);
+
+ verifyErrorResponse(resp.body, 404);
+ });
it('should return 404 when if unknown strategy is provided', async () => {
const resp = await supertest
@@ -56,6 +94,8 @@ export default function ({ getService }: FtrProviderContext) {
},
})
.expect(404);
+
+ verifyErrorResponse(resp.body, 404);
expect(resp.body.message).to.contain('banana not found');
});
@@ -74,11 +114,33 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(400);
+ verifyErrorResponse(resp.body, 400);
+
expect(resp.body.message).to.contain('Unsupported index pattern');
});
+ it('should return 400 with illegal ES argument', async () => {
+ const resp = await supertest
+ .post(`/internal/search/es`)
+ .send({
+ params: {
+ timeout: 1, // This should be a time range string!
+ index: 'log*',
+ size: 1000,
+ body: {
+ query: {
+ match_all: {},
+ },
+ },
+ },
+ })
+ .expect(400);
+
+ verifyErrorResponse(resp.body, 400, 'illegal_argument_exception', true);
+ });
+
it('should return 400 with a bad body', async () => {
- await supertest
+ const resp = await supertest
.post(`/internal/search/es`)
.send({
params: {
@@ -89,16 +151,26 @@ export default function ({ getService }: FtrProviderContext) {
},
})
.expect(400);
+
+ verifyErrorResponse(resp.body, 400, 'parsing_exception', true);
+ });
+
+ it('should return 400 for a painless error', async () => {
+ const resp = await supertest.post(`/internal/search/es`).send(painlessErrReq).expect(400);
+
+ verifyErrorResponse(resp.body, 400, 'search_phase_execution_exception', true);
});
});
describe('delete', () => {
it('should return 404 when no search id provided', async () => {
- await supertest.delete(`/internal/search/es`).send().expect(404);
+ const resp = await supertest.delete(`/internal/search/es`).send().expect(404);
+ verifyErrorResponse(resp.body, 404);
});
it('should return 400 when trying a delete on a non supporting strategy', async () => {
const resp = await supertest.delete(`/internal/search/es/123`).send().expect(400);
+ verifyErrorResponse(resp.body, 400);
expect(resp.body.message).to.contain("Search strategy es doesn't support cancellations");
});
});
diff --git a/test/api_integration/apis/search/verify_error.ts b/test/api_integration/apis/search/verify_error.ts
new file mode 100644
index 0000000000000..a5754ff47973e
--- /dev/null
+++ b/test/api_integration/apis/search/verify_error.ts
@@ -0,0 +1,27 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import expect from '@kbn/expect';
+
+export const verifyErrorResponse = (
+ r: any,
+ expectedCode: number,
+ message?: string,
+ shouldHaveAttrs?: boolean
+) => {
+ expect(r.statusCode).to.be(expectedCode);
+ if (message) {
+ expect(r.message).to.be(message);
+ }
+ if (shouldHaveAttrs) {
+ expect(r).to.have.property('attributes');
+ expect(r.attributes).to.have.property('root_cause');
+ } else {
+ expect(r).not.to.have.property('attributes');
+ }
+};
diff --git a/test/api_integration/apis/telemetry/opt_in.ts b/test/api_integration/apis/telemetry/opt_in.ts
index f03b33e61965e..ba5f46c38211f 100644
--- a/test/api_integration/apis/telemetry/opt_in.ts
+++ b/test/api_integration/apis/telemetry/opt_in.ts
@@ -14,10 +14,13 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function optInTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
+ const esArchiver = getService('esArchiver');
+
describe('/api/telemetry/v2/optIn API', () => {
let defaultAttributes: TelemetrySavedObjectAttributes;
let kibanaVersion: any;
before(async () => {
+ await esArchiver.emptyKibanaIndex();
const kibanaVersionAccessor = kibanaServer.version;
kibanaVersion = await kibanaVersionAccessor.get();
defaultAttributes =
diff --git a/test/api_integration/apis/telemetry/telemetry_local.ts b/test/api_integration/apis/telemetry/telemetry_local.ts
index 25d29a807bdad..650846015a4a2 100644
--- a/test/api_integration/apis/telemetry/telemetry_local.ts
+++ b/test/api_integration/apis/telemetry/telemetry_local.ts
@@ -177,6 +177,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('basic behaviour', () => {
let savedObjectIds: string[] = [];
before('create application usage entries', async () => {
+ await esArchiver.emptyKibanaIndex();
savedObjectIds = await Promise.all([
createSavedObject(),
createSavedObject('appView1'),
diff --git a/test/api_integration/apis/ui_counters/ui_counters.ts b/test/api_integration/apis/ui_counters/ui_counters.ts
index 1cf16fe433bf9..8d60c79c9698d 100644
--- a/test/api_integration/apis/ui_counters/ui_counters.ts
+++ b/test/api_integration/apis/ui_counters/ui_counters.ts
@@ -13,6 +13,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
const es = getService('es');
const createUiCounterEvent = (eventName: string, type: UiCounterMetricType, count = 1) => ({
@@ -23,6 +24,10 @@ export default function ({ getService }: FtrProviderContext) {
});
describe('UI Counters API', () => {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ });
+
const dayDate = moment().format('DDMMYYYY');
it('stores ui counter events in savedObjects', async () => {
diff --git a/test/api_integration/apis/ui_metric/ui_metric.ts b/test/api_integration/apis/ui_metric/ui_metric.ts
index d330cb037d1a1..e3b3b2ec4c542 100644
--- a/test/api_integration/apis/ui_metric/ui_metric.ts
+++ b/test/api_integration/apis/ui_metric/ui_metric.ts
@@ -13,6 +13,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
const es = getService('es');
const createStatsMetric = (
@@ -34,6 +35,10 @@ export default function ({ getService }: FtrProviderContext) {
});
describe('ui_metric savedObject data', () => {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ });
+
it('increments the count field in the document defined by the {app}/{action_type} path', async () => {
const reportManager = new ReportManager();
const uiStatsMetric = createStatsMetric('myEvent');
diff --git a/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json b/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json
new file mode 100644
index 0000000000000..21d84c4b55e55
--- /dev/null
+++ b/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json
@@ -0,0 +1,190 @@
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "timelion-sheet:190f3e90-2ec3-11e8-ba48-69fc4e41e1f6",
+ "source": {
+ "type": "timelion-sheet",
+ "updated_at": "2018-03-23T17:53:30.872Z",
+ "timelion-sheet": {
+ "title": "New TimeLion Sheet",
+ "hits": 0,
+ "description": "",
+ "timelion_sheet": [
+ ".es(*)"
+ ],
+ "timelion_interval": "auto",
+ "timelion_chart_height": 275,
+ "timelion_columns": 2,
+ "timelion_rows": 2,
+ "version": 1
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "index-pattern:8963ca30-3224-11e8-a572-ffca06da1357",
+ "source": {
+ "type": "index-pattern",
+ "updated_at": "2018-03-28T01:08:34.290Z",
+ "index-pattern": {
+ "title": "saved_objects*",
+ "fields": "[{\"name\":\"_id\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_index\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"_score\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_source\",\"type\":\"_source\",\"count\":0,\"scripted\":false,\"searchable\":false,\"aggregatable\":false,\"readFromDocValues\":false},{\"name\":\"_type\",\"type\":\"string\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":false},{\"name\":\"id\",\"type\":\"number\",\"count\":0,\"scripted\":false,\"searchable\":true,\"aggregatable\":true,\"readFromDocValues\":true}]"
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "config:7.0.0-alpha1",
+ "source": {
+ "type": "config",
+ "updated_at": "2018-03-28T01:08:39.248Z",
+ "config": {
+ "buildNum": 8467,
+ "telemetry:optIn": false,
+ "defaultIndex": "8963ca30-3224-11e8-a572-ffca06da1357"
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "search:960372e0-3224-11e8-a572-ffca06da1357",
+ "source": {
+ "type": "search",
+ "updated_at": "2018-03-28T01:08:55.182Z",
+ "search": {
+ "title": "OneRecord",
+ "description": "",
+ "hits": 0,
+ "columns": [
+ "_source"
+ ],
+ "sort": [
+ "_score",
+ "desc"
+ ],
+ "version": 1,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{\"index\":\"8963ca30-3224-11e8-a572-ffca06da1357\",\"highlightAll\":true,\"version\":true,\"query\":{\"query\":\"id:3\",\"language\":\"lucene\"},\"filter\":[]}"
+ }
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "visualization:a42c0580-3224-11e8-a572-ffca06da1357",
+ "source": {
+ "type": "visualization",
+ "updated_at": "2018-03-28T01:09:18.936Z",
+ "visualization": {
+ "title": "VisualizationFromSavedSearch",
+ "visState": "{\"title\":\"VisualizationFromSavedSearch\",\"type\":\"table\",\"params\":{\"perPage\":10,\"showPartialRows\":false,\"showMeticsAtAllLevels\":false,\"sort\":{\"columnIndex\":null,\"direction\":null},\"showTotal\":false,\"totalFunc\":\"sum\"},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}}]}",
+ "uiStateJSON": "{\"vis\":{\"params\":{\"sort\":{\"columnIndex\":null,\"direction\":null}}}}",
+ "description": "",
+ "savedSearchId": "960372e0-3224-11e8-a572-ffca06da1357",
+ "version": 1,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}"
+ }
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "visualization:add810b0-3224-11e8-a572-ffca06da1357",
+ "source": {
+ "type": "visualization",
+ "updated_at": "2018-03-28T01:09:35.163Z",
+ "visualization": {
+ "title": "Visualization",
+ "visState": "{\"title\":\"Visualization\",\"type\":\"metric\",\"params\":{\"addTooltip\":true,\"addLegend\":false,\"type\":\"metric\",\"metric\":{\"percentageMode\":false,\"useRanges\":false,\"colorSchema\":\"Green to Red\",\"metricColorMode\":\"None\",\"colorsRange\":[{\"from\":0,\"to\":10000}],\"labels\":{\"show\":true},\"invertColors\":false,\"style\":{\"bgFill\":\"#000\",\"bgColor\":false,\"labelColor\":false,\"subText\":\"\",\"fontSize\":60}}},\"aggs\":[{\"id\":\"1\",\"enabled\":true,\"type\":\"count\",\"schema\":\"metric\",\"params\":{}}]}",
+ "uiStateJSON": "{}",
+ "description": "",
+ "version": 1,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{\"index\":\"8963ca30-3224-11e8-a572-ffca06da1357\",\"filter\":[],\"query\":{\"query\":\"\",\"language\":\"lucene\"}}"
+ }
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "dashboard:b70c7ae0-3224-11e8-a572-ffca06da1357",
+ "source": {
+ "type": "dashboard",
+ "updated_at": "2018-03-28T01:09:50.606Z",
+ "dashboard": {
+ "title": "Dashboard",
+ "hits": 0,
+ "description": "",
+ "panelsJSON": "[{\"gridData\":{\"w\":24,\"h\":15,\"x\":0,\"y\":0,\"i\":\"1\"},\"version\":\"7.0.0-alpha1\",\"panelIndex\":\"1\",\"type\":\"visualization\",\"id\":\"add810b0-3224-11e8-a572-ffca06da1357\",\"embeddableConfig\":{}},{\"gridData\":{\"w\":24,\"h\":15,\"x\":24,\"y\":0,\"i\":\"2\"},\"version\":\"7.0.0-alpha1\",\"panelIndex\":\"2\",\"type\":\"visualization\",\"id\":\"a42c0580-3224-11e8-a572-ffca06da1357\",\"embeddableConfig\":{}}]",
+ "optionsJSON": "{\"darkTheme\":false,\"useMargins\":true,\"hidePanelTitles\":false}",
+ "version": 1,
+ "timeRestore": false,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{\"query\":{\"query\":\"\",\"language\":\"lucene\"},\"filter\":[],\"highlightAll\":true,\"version\":true}"
+ }
+ }
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "id": "dashboard:invalid-refs",
+ "source": {
+ "type": "dashboard",
+ "updated_at": "2018-03-28T01:09:50.606Z",
+ "dashboard": {
+ "title": "Dashboard",
+ "hits": 0,
+ "description": "",
+ "panelsJSON": "[]",
+ "optionsJSON": "{}",
+ "version": 1,
+ "timeRestore": false,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{}"
+ }
+ },
+ "references": [
+ {
+ "type":"visualization",
+ "id": "add810b0-3224-11e8-a572-ffca06da1357",
+ "name": "valid-ref"
+ },
+ {
+ "type":"visualization",
+ "id": "invalid-vis",
+ "name": "missing-ref"
+ }
+ ]
+ }
+ }
+}
diff --git a/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json.gz b/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json.gz
deleted file mode 100644
index 0834567abb66b..0000000000000
Binary files a/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/data.json.gz and /dev/null differ
diff --git a/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/mappings.json b/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/mappings.json
index c670508247b1a..6dd4d198e0f67 100644
--- a/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/mappings.json
+++ b/test/api_integration/fixtures/es_archiver/management/saved_objects/relationships/mappings.json
@@ -12,6 +12,20 @@
"mappings": {
"dynamic": "strict",
"properties": {
+ "references": {
+ "properties": {
+ "id": {
+ "type": "keyword"
+ },
+ "name": {
+ "type": "keyword"
+ },
+ "type": {
+ "type": "keyword"
+ }
+ },
+ "type": "nested"
+ },
"config": {
"dynamic": "true",
"properties": {
@@ -280,4 +294,4 @@
}
}
}
-}
\ No newline at end of file
+}
diff --git a/test/common/config.js b/test/common/config.js
index b6d12444b7017..8a42e6c87b214 100644
--- a/test/common/config.js
+++ b/test/common/config.js
@@ -61,8 +61,6 @@ export default function () {
...(!!process.env.CODE_COVERAGE
? [`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'coverage')}`]
: []),
- // Disable v2 migrations in tests for now
- '--migrations.enableV2=false',
],
},
services,
diff --git a/test/common/services/kibana_server/extend_es_archiver.js b/test/common/services/kibana_server/extend_es_archiver.js
index 5390b43a87187..1d76bc4473767 100644
--- a/test/common/services/kibana_server/extend_es_archiver.js
+++ b/test/common/services/kibana_server/extend_es_archiver.js
@@ -6,7 +6,7 @@
* Public License, v 1.
*/
-const ES_ARCHIVER_LOAD_METHODS = ['load', 'loadIfNeeded', 'unload'];
+const ES_ARCHIVER_LOAD_METHODS = ['load', 'loadIfNeeded', 'unload', 'emptyKibanaIndex'];
const KIBANA_INDEX = '.kibana';
export function extendEsArchiver({ esArchiver, kibanaServer, retry, defaults }) {
@@ -25,7 +25,7 @@ export function extendEsArchiver({ esArchiver, kibanaServer, retry, defaults })
const statsKeys = Object.keys(stats);
const kibanaKeys = statsKeys.filter(
// this also matches stats keys like '.kibana_1' and '.kibana_2,.kibana_1'
- (key) => key.includes(KIBANA_INDEX) && (stats[key].created || stats[key].deleted)
+ (key) => key.includes(KIBANA_INDEX) && stats[key].created
);
// if the kibana index was created by the esArchiver then update the uiSettings
diff --git a/test/functional/apps/management/_import_objects.ts b/test/functional/apps/management/_import_objects.ts
index 754406938e47b..e18f2a7485444 100644
--- a/test/functional/apps/management/_import_objects.ts
+++ b/test/functional/apps/management/_import_objects.ts
@@ -27,9 +27,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe.skip('import objects', function describeIndexTests() {
describe('.ndjson file', () => {
beforeEach(async function () {
+ await esArchiver.load('management');
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
- await esArchiver.load('management');
await PageObjects.settings.clickKibanaSavedObjects();
});
@@ -213,10 +213,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('.json file', () => {
beforeEach(async function () {
- // delete .kibana index and then wait for Kibana to re-create it
+ await esArchiver.load('saved_objects_imports');
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
- await esArchiver.load('saved_objects_imports');
await PageObjects.settings.clickKibanaSavedObjects();
});
diff --git a/test/functional/apps/management/_index_pattern_filter.js b/test/functional/apps/management/_index_pattern_filter.js
index eae53682b6ccf..91ea13348d611 100644
--- a/test/functional/apps/management/_index_pattern_filter.js
+++ b/test/functional/apps/management/_index_pattern_filter.js
@@ -12,10 +12,11 @@ export default function ({ getService, getPageObjects }) {
const kibanaServer = getService('kibanaServer');
const retry = getService('retry');
const PageObjects = getPageObjects(['settings']);
+ const esArchiver = getService('esArchiver');
describe('index pattern filter', function describeIndexTests() {
before(async function () {
- // delete .kibana index and then wait for Kibana to re-create it
+ await esArchiver.emptyKibanaIndex();
await kibanaServer.uiSettings.replace({});
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaIndexPatterns();
diff --git a/test/functional/apps/management/_index_patterns_empty.ts b/test/functional/apps/management/_index_patterns_empty.ts
index 3b89e05d4b582..4e86de6d70653 100644
--- a/test/functional/apps/management/_index_patterns_empty.ts
+++ b/test/functional/apps/management/_index_patterns_empty.ts
@@ -19,7 +19,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
describe('index pattern empty view', () => {
before(async () => {
- await esArchiver.load('empty_kibana');
+ await esArchiver.emptyKibanaIndex();
await esArchiver.unload('logstash_functional');
await esArchiver.unload('makelogs');
await kibanaServer.uiSettings.replace({});
@@ -27,7 +27,6 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
after(async () => {
- await esArchiver.unload('empty_kibana');
await esArchiver.loadIfNeeded('makelogs');
// @ts-expect-error
await es.transport.request({
diff --git a/test/functional/apps/management/_mgmt_import_saved_objects.js b/test/functional/apps/management/_mgmt_import_saved_objects.js
index 45a18d5932764..87eca2c7a5a65 100644
--- a/test/functional/apps/management/_mgmt_import_saved_objects.js
+++ b/test/functional/apps/management/_mgmt_import_saved_objects.js
@@ -18,14 +18,13 @@ export default function ({ getService, getPageObjects }) {
describe('mgmt saved objects', function describeIndexTests() {
beforeEach(async function () {
- await esArchiver.load('empty_kibana');
+ await esArchiver.emptyKibanaIndex();
await esArchiver.load('discover');
await PageObjects.settings.navigateTo();
});
afterEach(async function () {
await esArchiver.unload('discover');
- await esArchiver.load('empty_kibana');
});
it('should import saved objects mgmt', async function () {
diff --git a/test/functional/apps/management/_test_huge_fields.js b/test/functional/apps/management/_test_huge_fields.js
index 2ab619276d2b9..c1fca31e695cb 100644
--- a/test/functional/apps/management/_test_huge_fields.js
+++ b/test/functional/apps/management/_test_huge_fields.js
@@ -20,6 +20,7 @@ export default function ({ getService, getPageObjects }) {
const EXPECTED_FIELD_COUNT = '10006';
before(async function () {
await security.testUser.setRoles(['kibana_admin', 'test_testhuge_reader']);
+ await esArchiver.emptyKibanaIndex();
await esArchiver.loadIfNeeded('large_fields');
await PageObjects.settings.createIndexPattern('testhuge', 'date');
});
diff --git a/test/functional/apps/management/index.ts b/test/functional/apps/management/index.ts
index ca89853875027..06e652f9f3e59 100644
--- a/test/functional/apps/management/index.ts
+++ b/test/functional/apps/management/index.ts
@@ -14,13 +14,11 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
describe('management', function () {
before(async () => {
await esArchiver.unload('logstash_functional');
- await esArchiver.load('empty_kibana');
await esArchiver.loadIfNeeded('makelogs');
});
after(async () => {
await esArchiver.unload('makelogs');
- await esArchiver.unload('empty_kibana');
});
describe('', function () {
diff --git a/test/functional/apps/saved_objects_management/index.ts b/test/functional/apps/saved_objects_management/index.ts
index 9491661de73ef..5e4eaefb7e9d1 100644
--- a/test/functional/apps/saved_objects_management/index.ts
+++ b/test/functional/apps/saved_objects_management/index.ts
@@ -12,5 +12,6 @@ export default function savedObjectsManagementApp({ loadTestFile }: FtrProviderC
describe('saved objects management', function savedObjectsManagementAppTestSuite() {
this.tags('ciGroup7');
loadTestFile(require.resolve('./edit_saved_object'));
+ loadTestFile(require.resolve('./show_relationships'));
});
}
diff --git a/test/functional/apps/saved_objects_management/show_relationships.ts b/test/functional/apps/saved_objects_management/show_relationships.ts
new file mode 100644
index 0000000000000..6f3fb5a4973e2
--- /dev/null
+++ b/test/functional/apps/saved_objects_management/show_relationships.ts
@@ -0,0 +1,52 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * and the Server Side Public License, v 1; you may not use this file except in
+ * compliance with, at your election, the Elastic License or the Server Side
+ * Public License, v 1.
+ */
+
+import expect from '@kbn/expect';
+import { FtrProviderContext } from '../../ftr_provider_context';
+
+export default function ({ getPageObjects, getService }: FtrProviderContext) {
+ const esArchiver = getService('esArchiver');
+ const PageObjects = getPageObjects(['common', 'settings', 'savedObjects']);
+
+ describe('saved objects relationships flyout', () => {
+ beforeEach(async () => {
+ await esArchiver.load('saved_objects_management/show_relationships');
+ });
+
+ afterEach(async () => {
+ await esArchiver.unload('saved_objects_management/show_relationships');
+ });
+
+ it('displays the invalid references', async () => {
+ await PageObjects.settings.navigateTo();
+ await PageObjects.settings.clickKibanaSavedObjects();
+
+ const objects = await PageObjects.savedObjects.getRowTitles();
+ expect(objects.includes('Dashboard with missing refs')).to.be(true);
+
+ await PageObjects.savedObjects.clickRelationshipsByTitle('Dashboard with missing refs');
+
+ const invalidRelations = await PageObjects.savedObjects.getInvalidRelations();
+
+ expect(invalidRelations).to.eql([
+ {
+ error: 'Saved object [visualization/missing-vis-ref] not found',
+ id: 'missing-vis-ref',
+ relationship: 'Child',
+ type: 'visualization',
+ },
+ {
+ error: 'Saved object [dashboard/missing-dashboard-ref] not found',
+ id: 'missing-dashboard-ref',
+ relationship: 'Child',
+ type: 'dashboard',
+ },
+ ]);
+ });
+ });
+}
diff --git a/test/functional/apps/timelion/_expression_typeahead.js b/test/functional/apps/timelion/_expression_typeahead.js
index 744f8de15e767..3db5cb48dd38b 100644
--- a/test/functional/apps/timelion/_expression_typeahead.js
+++ b/test/functional/apps/timelion/_expression_typeahead.js
@@ -75,18 +75,18 @@ export default function ({ getPageObjects }) {
await PageObjects.timelion.updateExpression(',split');
await PageObjects.timelion.clickSuggestion();
const suggestions = await PageObjects.timelion.getSuggestionItemsText();
- expect(suggestions.length).to.eql(51);
+ expect(suggestions.length).not.to.eql(0);
expect(suggestions[0].includes('@message.raw')).to.eql(true);
- await PageObjects.timelion.clickSuggestion(10, 2000);
+ await PageObjects.timelion.clickSuggestion(10);
});
it('should show field suggestions for metric argument when index pattern set', async () => {
await PageObjects.timelion.updateExpression(',metric');
await PageObjects.timelion.clickSuggestion();
await PageObjects.timelion.updateExpression('avg:');
- await PageObjects.timelion.clickSuggestion(0, 2000);
+ await PageObjects.timelion.clickSuggestion(0);
const suggestions = await PageObjects.timelion.getSuggestionItemsText();
- expect(suggestions.length).to.eql(2);
+ expect(suggestions.length).not.to.eql(0);
expect(suggestions[0].includes('avg:bytes')).to.eql(true);
});
});
diff --git a/test/functional/apps/visualize/input_control_vis/input_control_range.ts b/test/functional/apps/visualize/input_control_vis/input_control_range.ts
index 9b48e78246b37..613b1a162eb63 100644
--- a/test/functional/apps/visualize/input_control_vis/input_control_range.ts
+++ b/test/functional/apps/visualize/input_control_vis/input_control_range.ts
@@ -12,7 +12,6 @@ import { FtrProviderContext } from '../../../ftr_provider_context';
export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
- const kibanaServer = getService('kibanaServer');
const find = getService('find');
const security = getService('security');
const { visualize, visEditor } = getPageObjects(['visualize', 'visEditor']);
@@ -53,7 +52,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await esArchiver.loadIfNeeded('logstash_functional');
await esArchiver.loadIfNeeded('long_window_logstash');
await esArchiver.load('visualize');
- await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-*' });
await security.testUser.restoreDefaults();
});
});
diff --git a/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/data.json b/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/data.json
new file mode 100644
index 0000000000000..4d5b969a3c931
--- /dev/null
+++ b/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/data.json
@@ -0,0 +1,36 @@
+{
+ "type": "doc",
+ "value": {
+ "index": ".kibana",
+ "type": "doc",
+ "id": "dashboard:dash-with-missing-refs",
+ "source": {
+ "dashboard": {
+ "title": "Dashboard with missing refs",
+ "hits": 0,
+ "description": "",
+ "panelsJSON": "[]",
+ "optionsJSON": "{}",
+ "version": 1,
+ "timeRestore": false,
+ "kibanaSavedObjectMeta": {
+ "searchSourceJSON": "{}"
+ }
+ },
+ "type": "dashboard",
+ "references": [
+ {
+ "type": "visualization",
+ "id": "missing-vis-ref",
+ "name": "some missing ref"
+ },
+ {
+ "type": "dashboard",
+ "id": "missing-dashboard-ref",
+ "name": "some other missing ref"
+ }
+ ],
+ "updated_at": "2019-01-22T19:32:47.232Z"
+ }
+ }
+}
diff --git a/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/mappings.json b/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/mappings.json
new file mode 100644
index 0000000000000..d53e6c96e883e
--- /dev/null
+++ b/test/functional/fixtures/es_archiver/saved_objects_management/show_relationships/mappings.json
@@ -0,0 +1,473 @@
+{
+ "type": "index",
+ "value": {
+ "index": ".kibana",
+ "settings": {
+ "index": {
+ "number_of_shards": "1",
+ "auto_expand_replicas": "0-1",
+ "number_of_replicas": "0"
+ }
+ },
+ "mappings": {
+ "dynamic": "strict",
+ "properties": {
+ "references": {
+ "properties": {
+ "id": {
+ "type": "keyword"
+ },
+ "name": {
+ "type": "keyword"
+ },
+ "type": {
+ "type": "keyword"
+ }
+ },
+ "type": "nested"
+ },
+ "apm-telemetry": {
+ "properties": {
+ "has_any_services": {
+ "type": "boolean"
+ },
+ "services_per_agent": {
+ "properties": {
+ "go": {
+ "type": "long",
+ "null_value": 0
+ },
+ "java": {
+ "type": "long",
+ "null_value": 0
+ },
+ "js-base": {
+ "type": "long",
+ "null_value": 0
+ },
+ "nodejs": {
+ "type": "long",
+ "null_value": 0
+ },
+ "python": {
+ "type": "long",
+ "null_value": 0
+ },
+ "ruby": {
+ "type": "long",
+ "null_value": 0
+ }
+ }
+ }
+ }
+ },
+ "canvas-workpad": {
+ "dynamic": "false",
+ "properties": {
+ "@created": {
+ "type": "date"
+ },
+ "@timestamp": {
+ "type": "date"
+ },
+ "id": {
+ "type": "text",
+ "index": false
+ },
+ "name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword"
+ }
+ }
+ }
+ }
+ },
+ "config": {
+ "dynamic": "true",
+ "properties": {
+ "accessibility:disableAnimations": {
+ "type": "boolean"
+ },
+ "buildNum": {
+ "type": "keyword"
+ },
+ "dateFormat:tz": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "defaultIndex": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "telemetry:optIn": {
+ "type": "boolean"
+ }
+ }
+ },
+ "dashboard": {
+ "properties": {
+ "description": {
+ "type": "text"
+ },
+ "hits": {
+ "type": "integer"
+ },
+ "kibanaSavedObjectMeta": {
+ "properties": {
+ "searchSourceJSON": {
+ "type": "text"
+ }
+ }
+ },
+ "optionsJSON": {
+ "type": "text"
+ },
+ "panelsJSON": {
+ "type": "text"
+ },
+ "refreshInterval": {
+ "properties": {
+ "display": {
+ "type": "keyword"
+ },
+ "pause": {
+ "type": "boolean"
+ },
+ "section": {
+ "type": "integer"
+ },
+ "value": {
+ "type": "integer"
+ }
+ }
+ },
+ "timeFrom": {
+ "type": "keyword"
+ },
+ "timeRestore": {
+ "type": "boolean"
+ },
+ "timeTo": {
+ "type": "keyword"
+ },
+ "title": {
+ "type": "text"
+ },
+ "uiStateJSON": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ }
+ }
+ },
+ "map": {
+ "properties": {
+ "bounds": {
+ "type": "geo_shape",
+ "tree": "quadtree"
+ },
+ "description": {
+ "type": "text"
+ },
+ "layerListJSON": {
+ "type": "text"
+ },
+ "mapStateJSON": {
+ "type": "text"
+ },
+ "title": {
+ "type": "text"
+ },
+ "uiStateJSON": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ }
+ }
+ },
+ "graph-workspace": {
+ "properties": {
+ "description": {
+ "type": "text"
+ },
+ "kibanaSavedObjectMeta": {
+ "properties": {
+ "searchSourceJSON": {
+ "type": "text"
+ }
+ }
+ },
+ "numLinks": {
+ "type": "integer"
+ },
+ "numVertices": {
+ "type": "integer"
+ },
+ "title": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ },
+ "wsState": {
+ "type": "text"
+ }
+ }
+ },
+ "index-pattern": {
+ "properties": {
+ "fieldFormatMap": {
+ "type": "text"
+ },
+ "fields": {
+ "type": "text"
+ },
+ "intervalName": {
+ "type": "keyword"
+ },
+ "notExpandable": {
+ "type": "boolean"
+ },
+ "sourceFilters": {
+ "type": "text"
+ },
+ "timeFieldName": {
+ "type": "keyword"
+ },
+ "title": {
+ "type": "text"
+ },
+ "type": {
+ "type": "keyword"
+ },
+ "typeMeta": {
+ "type": "keyword"
+ }
+ }
+ },
+ "kql-telemetry": {
+ "properties": {
+ "optInCount": {
+ "type": "long"
+ },
+ "optOutCount": {
+ "type": "long"
+ }
+ }
+ },
+ "migrationVersion": {
+ "dynamic": "true",
+ "properties": {
+ "index-pattern": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "space": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ }
+ }
+ },
+ "namespace": {
+ "type": "keyword"
+ },
+ "search": {
+ "properties": {
+ "columns": {
+ "type": "keyword"
+ },
+ "description": {
+ "type": "text"
+ },
+ "hits": {
+ "type": "integer"
+ },
+ "kibanaSavedObjectMeta": {
+ "properties": {
+ "searchSourceJSON": {
+ "type": "text"
+ }
+ }
+ },
+ "sort": {
+ "type": "keyword"
+ },
+ "title": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ }
+ }
+ },
+ "server": {
+ "properties": {
+ "uuid": {
+ "type": "keyword"
+ }
+ }
+ },
+ "space": {
+ "properties": {
+ "_reserved": {
+ "type": "boolean"
+ },
+ "color": {
+ "type": "keyword"
+ },
+ "description": {
+ "type": "text"
+ },
+ "disabledFeatures": {
+ "type": "keyword"
+ },
+ "initials": {
+ "type": "keyword"
+ },
+ "name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 2048
+ }
+ }
+ }
+ }
+ },
+ "spaceId": {
+ "type": "keyword"
+ },
+ "telemetry": {
+ "properties": {
+ "enabled": {
+ "type": "boolean"
+ }
+ }
+ },
+ "timelion-sheet": {
+ "properties": {
+ "description": {
+ "type": "text"
+ },
+ "hits": {
+ "type": "integer"
+ },
+ "kibanaSavedObjectMeta": {
+ "properties": {
+ "searchSourceJSON": {
+ "type": "text"
+ }
+ }
+ },
+ "timelion_chart_height": {
+ "type": "integer"
+ },
+ "timelion_columns": {
+ "type": "integer"
+ },
+ "timelion_interval": {
+ "type": "keyword"
+ },
+ "timelion_other_interval": {
+ "type": "keyword"
+ },
+ "timelion_rows": {
+ "type": "integer"
+ },
+ "timelion_sheet": {
+ "type": "text"
+ },
+ "title": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ }
+ }
+ },
+ "type": {
+ "type": "keyword"
+ },
+ "updated_at": {
+ "type": "date"
+ },
+ "url": {
+ "properties": {
+ "accessCount": {
+ "type": "long"
+ },
+ "accessDate": {
+ "type": "date"
+ },
+ "createDate": {
+ "type": "date"
+ },
+ "url": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 2048
+ }
+ }
+ }
+ }
+ },
+ "visualization": {
+ "properties": {
+ "description": {
+ "type": "text"
+ },
+ "kibanaSavedObjectMeta": {
+ "properties": {
+ "searchSourceJSON": {
+ "type": "text"
+ }
+ }
+ },
+ "savedSearchId": {
+ "type": "keyword"
+ },
+ "title": {
+ "type": "text"
+ },
+ "uiStateJSON": {
+ "type": "text"
+ },
+ "version": {
+ "type": "integer"
+ },
+ "visState": {
+ "type": "text"
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/test/functional/page_objects/management/saved_objects_page.ts b/test/functional/page_objects/management/saved_objects_page.ts
index 1cdf76ad58ef0..cf162f12df9d9 100644
--- a/test/functional/page_objects/management/saved_objects_page.ts
+++ b/test/functional/page_objects/management/saved_objects_page.ts
@@ -257,6 +257,22 @@ export function SavedObjectsPageProvider({ getService, getPageObjects }: FtrProv
});
}
+ async getInvalidRelations() {
+ const rows = await testSubjects.findAll('invalidRelationshipsTableRow');
+ return mapAsync(rows, async (row) => {
+ const objectType = await row.findByTestSubject('relationshipsObjectType');
+ const objectId = await row.findByTestSubject('relationshipsObjectId');
+ const relationship = await row.findByTestSubject('directRelationship');
+ const error = await row.findByTestSubject('relationshipsError');
+ return {
+ type: await objectType.getVisibleText(),
+ id: await objectId.getVisibleText(),
+ relationship: await relationship.getVisibleText(),
+ error: await error.getVisibleText(),
+ };
+ });
+ }
+
async getTableSummary() {
const table = await testSubjects.find('savedObjectsTable');
const $ = await table.parseDomContent();
diff --git a/test/functional/services/common/browser.ts b/test/functional/services/common/browser.ts
index 635fde6dad720..4a7e82d5b42c0 100644
--- a/test/functional/services/common/browser.ts
+++ b/test/functional/services/common/browser.ts
@@ -289,13 +289,13 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
}
const origin = document.querySelector(arguments[0]);
- const target = document.querySelector(arguments[1]);
const dragStartEvent = createEvent('dragstart');
dispatchEvent(origin, dragStartEvent);
setTimeout(() => {
const dropEvent = createEvent('drop');
+ const target = document.querySelector(arguments[1]);
dispatchEvent(target, dropEvent, dragStartEvent.dataTransfer);
const dragEndEvent = createEvent('dragend');
dispatchEvent(origin, dragEndEvent, dropEvent.dataTransfer);
diff --git a/test/plugin_functional/test_suites/core_plugins/applications.ts b/test/plugin_functional/test_suites/core_plugins/applications.ts
index e72d032f63469..52924d8c93280 100644
--- a/test/plugin_functional/test_suites/core_plugins/applications.ts
+++ b/test/plugin_functional/test_suites/core_plugins/applications.ts
@@ -19,6 +19,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
const find = getService('find');
const retry = getService('retry');
const deployment = getService('deployment');
+ const esArchiver = getService('esArchiver');
const loadingScreenNotShown = async () =>
expect(await testSubjects.exists('kbnLoadingMessage')).to.be(false);
@@ -50,6 +51,7 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
describe('ui applications', function describeIndexTests() {
before(async () => {
+ await esArchiver.emptyKibanaIndex();
await PageObjects.common.navigateToApp('foo');
});
diff --git a/test/plugin_functional/test_suites/data_plugin/index_patterns.ts b/test/plugin_functional/test_suites/data_plugin/index_patterns.ts
index ba12e2df16d41..0cd53a5e1b764 100644
--- a/test/plugin_functional/test_suites/data_plugin/index_patterns.ts
+++ b/test/plugin_functional/test_suites/data_plugin/index_patterns.ts
@@ -12,8 +12,12 @@ import '../../plugins/core_provider_plugin/types';
export default function ({ getService }: PluginFunctionalProviderContext) {
const supertest = getService('supertest');
+ const esArchiver = getService('esArchiver');
describe('index patterns', function () {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ });
let indexPatternId = '';
it('can create an index pattern', async () => {
diff --git a/test/plugin_functional/test_suites/saved_objects_management/import_warnings.ts b/test/plugin_functional/test_suites/saved_objects_management/import_warnings.ts
index 71663b19b35cb..b60e4b4a1d8b7 100644
--- a/test/plugin_functional/test_suites/saved_objects_management/import_warnings.ts
+++ b/test/plugin_functional/test_suites/saved_objects_management/import_warnings.ts
@@ -10,10 +10,15 @@ import path from 'path';
import expect from '@kbn/expect';
import { PluginFunctionalProviderContext } from '../../services';
-export default function ({ getPageObjects }: PluginFunctionalProviderContext) {
+export default function ({ getPageObjects, getService }: PluginFunctionalProviderContext) {
const PageObjects = getPageObjects(['common', 'settings', 'header', 'savedObjects']);
+ const esArchiver = getService('esArchiver');
describe('import warnings', () => {
+ before(async () => {
+ await esArchiver.emptyKibanaIndex();
+ });
+
beforeEach(async () => {
await PageObjects.settings.navigateTo();
await PageObjects.settings.clickKibanaSavedObjects();
diff --git a/test/security_functional/insecure_cluster_warning.ts b/test/security_functional/insecure_cluster_warning.ts
index 181c4cf2b46b7..2f7656b743a51 100644
--- a/test/security_functional/insecure_cluster_warning.ts
+++ b/test/security_functional/insecure_cluster_warning.ts
@@ -31,6 +31,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
await browser.setLocalStorageItem('insecureClusterWarningVisibility', '');
await esArchiver.unload('hamlet');
+ await esArchiver.emptyKibanaIndex();
});
it('should not warn when the cluster contains no user data', async () => {
diff --git a/test/tsconfig.json b/test/tsconfig.json
index c8e6e69586ca0..4df74f526077e 100644
--- a/test/tsconfig.json
+++ b/test/tsconfig.json
@@ -4,7 +4,12 @@
"incremental": false,
"types": ["node", "flot"]
},
- "include": ["**/*", "../typings/elastic__node_crypto.d.ts", "typings/**/*", "../packages/kbn-test/types/ftr_globals/**/*"],
+ "include": [
+ "**/*",
+ "../typings/elastic__node_crypto.d.ts",
+ "typings/**/*",
+ "../packages/kbn-test/types/ftr_globals/**/*"
+ ],
"exclude": ["plugin_functional/plugins/**/*", "interpreter_functional/plugins/**/*"],
"references": [
{ "path": "../src/core/tsconfig.json" },
@@ -34,5 +39,6 @@
{ "path": "../src/plugins/ui_actions/tsconfig.json" },
{ "path": "../src/plugins/url_forwarding/tsconfig.json" },
{ "path": "../src/plugins/usage_collection/tsconfig.json" },
+ { "path": "../src/plugins/legacy_export/tsconfig.json" }
]
}
diff --git a/tsconfig.json b/tsconfig.json
index 2647ac9a9d75e..ee46e075f2df1 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -21,11 +21,13 @@
"src/plugins/es_ui_shared/**/*",
"src/plugins/expressions/**/*",
"src/plugins/home/**/*",
+ "src/plugins/input_control_vis/**/*",
"src/plugins/inspector/**/*",
"src/plugins/kibana_legacy/**/*",
"src/plugins/kibana_react/**/*",
"src/plugins/kibana_usage_collection/**/*",
"src/plugins/kibana_utils/**/*",
+ "src/plugins/legacy_export/**/*",
"src/plugins/management/**/*",
"src/plugins/maps_legacy/**/*",
"src/plugins/navigation/**/*",
@@ -84,6 +86,7 @@
{ "path": "./src/plugins/kibana_react/tsconfig.json" },
{ "path": "./src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "./src/plugins/kibana_utils/tsconfig.json" },
+ { "path": "./src/plugins/legacy_export/tsconfig.json" },
{ "path": "./src/plugins/management/tsconfig.json" },
{ "path": "./src/plugins/maps_legacy/tsconfig.json" },
{ "path": "./src/plugins/navigation/tsconfig.json" },
diff --git a/tsconfig.refs.json b/tsconfig.refs.json
index fa1b533a3dd38..16c5b6c116998 100644
--- a/tsconfig.refs.json
+++ b/tsconfig.refs.json
@@ -2,12 +2,12 @@
"include": [],
"references": [
{ "path": "./src/core/tsconfig.json" },
- { "path": "./src/plugins/telemetry_management_section/tsconfig.json" },
{ "path": "./src/plugins/advanced_settings/tsconfig.json" },
{ "path": "./src/plugins/apm_oss/tsconfig.json" },
{ "path": "./src/plugins/bfetch/tsconfig.json" },
{ "path": "./src/plugins/charts/tsconfig.json" },
{ "path": "./src/plugins/console/tsconfig.json" },
+ { "path": "./src/plugins/dashboard/tsconfig.json" },
{ "path": "./src/plugins/data/tsconfig.json" },
{ "path": "./src/plugins/dev_tools/tsconfig.json" },
{ "path": "./src/plugins/discover/tsconfig.json" },
@@ -15,27 +15,27 @@
{ "path": "./src/plugins/es_ui_shared/tsconfig.json" },
{ "path": "./src/plugins/expressions/tsconfig.json" },
{ "path": "./src/plugins/home/tsconfig.json" },
- { "path": "./src/plugins/dashboard/tsconfig.json" },
- { "path": "./src/plugins/dev_tools/tsconfig.json" },
{ "path": "./src/plugins/inspector/tsconfig.json" },
{ "path": "./src/plugins/kibana_legacy/tsconfig.json" },
{ "path": "./src/plugins/kibana_react/tsconfig.json" },
{ "path": "./src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "./src/plugins/kibana_utils/tsconfig.json" },
+ { "path": "./src/plugins/legacy_export/tsconfig.json" },
{ "path": "./src/plugins/management/tsconfig.json" },
{ "path": "./src/plugins/maps_legacy/tsconfig.json" },
{ "path": "./src/plugins/navigation/tsconfig.json" },
{ "path": "./src/plugins/newsfeed/tsconfig.json" },
+ { "path": "./src/plugins/presentation_util/tsconfig.json" },
{ "path": "./src/plugins/region_map/tsconfig.json" },
- { "path": "./src/plugins/saved_objects/tsconfig.json" },
{ "path": "./src/plugins/saved_objects_management/tsconfig.json" },
{ "path": "./src/plugins/saved_objects_tagging_oss/tsconfig.json" },
- { "path": "./src/plugins/presentation_util/tsconfig.json" },
+ { "path": "./src/plugins/saved_objects/tsconfig.json" },
{ "path": "./src/plugins/security_oss/tsconfig.json" },
{ "path": "./src/plugins/share/tsconfig.json" },
{ "path": "./src/plugins/spaces_oss/tsconfig.json" },
- { "path": "./src/plugins/telemetry/tsconfig.json" },
{ "path": "./src/plugins/telemetry_collection_manager/tsconfig.json" },
+ { "path": "./src/plugins/telemetry_management_section/tsconfig.json" },
+ { "path": "./src/plugins/telemetry/tsconfig.json" },
{ "path": "./src/plugins/tile_map/tsconfig.json" },
{ "path": "./src/plugins/timelion/tsconfig.json" },
{ "path": "./src/plugins/ui_actions/tsconfig.json" },
@@ -52,6 +52,6 @@
{ "path": "./src/plugins/vis_type_vega/tsconfig.json" },
{ "path": "./src/plugins/vis_type_xy/tsconfig.json" },
{ "path": "./src/plugins/visualizations/tsconfig.json" },
- { "path": "./src/plugins/visualize/tsconfig.json" },
+ { "path": "./src/plugins/visualize/tsconfig.json" }
]
}
diff --git a/vars/kibanaPipeline.groovy b/vars/kibanaPipeline.groovy
index 93cb7a719bbe8..3032d88c26d98 100644
--- a/vars/kibanaPipeline.groovy
+++ b/vars/kibanaPipeline.groovy
@@ -130,6 +130,8 @@ def functionalTestProcess(String name, String script) {
def ossCiGroupProcess(ciGroup) {
return functionalTestProcess("ciGroup" + ciGroup) {
+ sleep((ciGroup-1)*30) // smooth out CPU spikes from ES startup
+
withEnv([
"CI_GROUP=${ciGroup}",
"JOB=kibana-ciGroup${ciGroup}",
@@ -143,6 +145,7 @@ def ossCiGroupProcess(ciGroup) {
def xpackCiGroupProcess(ciGroup) {
return functionalTestProcess("xpack-ciGroup" + ciGroup) {
+ sleep((ciGroup-1)*30) // smooth out CPU spikes from ES startup
withEnv([
"CI_GROUP=${ciGroup}",
"JOB=xpack-kibana-ciGroup${ciGroup}",
@@ -444,16 +447,31 @@ def withTasks(Map params = [worker: [:]], Closure closure) {
}
def allCiTasks() {
- withTasks {
- tasks.check()
- tasks.lint()
- tasks.test()
- tasks.functionalOss()
- tasks.functionalXpack()
- }
+ parallel([
+ general: {
+ withTasks {
+ tasks.check()
+ tasks.lint()
+ tasks.test()
+ tasks.functionalOss()
+ tasks.functionalXpack()
+ }
+ },
+ jest: {
+ workers.ci(name: 'jest', size: 'c2-8', ramDisk: true) {
+ scriptTask('Jest Unit Tests', 'test/scripts/test/jest_unit.sh')()
+ }
+ },
+ xpackJest: {
+ workers.ci(name: 'xpack-jest', size: 'c2-8', ramDisk: true) {
+ scriptTask('X-Pack Jest Unit Tests', 'test/scripts/test/xpack_jest_unit.sh')()
+ }
+ },
+ ])
}
def pipelineLibraryTests() {
+ return
whenChanged(['vars/', '.ci/pipeline-library/']) {
workers.base(size: 'flyweight', bootstrapped: false, ramDisk: false) {
dir('.ci/pipeline-library') {
diff --git a/vars/tasks.groovy b/vars/tasks.groovy
index 3493a95f0bdce..6c4f897691136 100644
--- a/vars/tasks.groovy
+++ b/vars/tasks.groovy
@@ -30,12 +30,9 @@ def lint() {
def test() {
tasks([
- // These 2 tasks require isolation because of hard-coded, conflicting ports and such, so let's use Docker here
+ // This task requires isolation because of hard-coded, conflicting ports and such, so let's use Docker here
kibanaPipeline.scriptTaskDocker('Jest Integration Tests', 'test/scripts/test/jest_integration.sh'),
-
- kibanaPipeline.scriptTask('Jest Unit Tests', 'test/scripts/test/jest_unit.sh'),
kibanaPipeline.scriptTask('API Integration Tests', 'test/scripts/test/api_integration.sh'),
- kibanaPipeline.scriptTask('X-Pack Jest Unit Tests', 'test/scripts/test/xpack_jest_unit.sh'),
])
}
diff --git a/vars/workers.groovy b/vars/workers.groovy
index dd634f3c25a32..e1684f7aadb43 100644
--- a/vars/workers.groovy
+++ b/vars/workers.groovy
@@ -19,6 +19,8 @@ def label(size) {
return 'docker && tests-xl-highmem'
case 'xxl':
return 'docker && tests-xxl && gobld/machineType:custom-64-270336'
+ case 'c2-8':
+ return 'docker && linux && immutable && gobld/machineType:c2-standard-8'
}
error "unknown size '${size}'"
diff --git a/x-pack/build_chromium/README.md b/x-pack/build_chromium/README.md
index 9934d06a9d96a..39382620775ad 100644
--- a/x-pack/build_chromium/README.md
+++ b/x-pack/build_chromium/README.md
@@ -6,50 +6,65 @@ to accept a commit hash from the Chromium repository, and initialize the build
environments and run the build on Mac, Windows, and Linux.
## Before you begin
+
If you wish to use a remote VM to build, you'll need access to our GCP account,
which is where we have two machines provisioned for the Linux and Windows
builds. Mac builds can be achieved locally, and are a great place to start to
gain familiarity.
+**NOTE:** Linux builds should be done in Ubuntu on x86 architecture. ARM builds
+are created in x86. CentOS is not supported for building Chromium.
+
1. Login to our GCP instance [here using your okta credentials](https://console.cloud.google.com/).
2. Click the "Compute Engine" tab.
-3. Ensure that `chromium-build-linux` and `chromium-build-windows-12-beefy` are there.
-4. If #3 fails, you'll have to spin up new instances. Generally, these need `n1-standard-8` types or 8 vCPUs/30 GB memory.
-5. Ensure that there's enough room left on the disk: 100GB is required. `ncdu` is a good linux util to verify what's claming space.
-
-## Usage
+3. Find `chromium-build-linux` or `chromium-build-windows-12-beefy` and start the instance.
+4. Install [Google Cloud SDK](https://cloud.google.com/sdk) locally to ssh into the GCP instance
+5. System dependencies:
+ - 8 CPU
+ - 30GB memory
+ - 80GB free space on disk (Try `ncdu /home` to see where space is used.)
+ - git
+ - python2 (`python` must link to `python2`)
+ - lsb_release
+ - tmux is recommended in case your ssh session is interrupted
+6. Copy the entire `build_chromium` directory into a GCP storage bucket, so you can copy the scripts into the instance and run them.
+
+## Build Script Usage
```
+# Allow our scripts to use depot_tools commands
export PATH=$HOME/chromium/depot_tools:$PATH
+
# Create a dedicated working directory for this directory of Python scripts.
mkdir ~/chromium && cd ~/chromium
+
# Copy the scripts from the Kibana repo to use them conveniently in the working directory
-cp -r ~/path/to/kibana/x-pack/build_chromium .
-# Install the OS packages, configure the environment, download the chromium source
+gsutil cp -r gs://my-bucket/build_chromium .
+
+# Install the OS packages, configure the environment, download the chromium source (25GB)
python ./build_chromium/init.sh [arch_name]
# Run the build script with the path to the chromium src directory, the git commit id
-python ./build_chromium/build.py
+python ./build_chromium/build.py x86
-# You can add an architecture flag for ARM
+# OR You can build for ARM
python ./build_chromium/build.py arm64
```
+**NOTE:** The `init.py` script updates git config to make it more possible for
+the Chromium repo to be cloned successfully. If checking out the Chromium fails
+with "early EOF" errors, the instance could be low on memory or disk space.
+
## Getting the Commit ID
-Getting `` can be tricky. The best technique seems to be:
+The `build.py` script requires a commit ID of the Chromium repo. Getting `` can be tricky. The best technique seems to be:
1. Create a temporary working directory and intialize yarn
2. `yarn add puppeteer # install latest puppeter`
-3. Look through puppeteer's node module files to find the "chromium revision" (a custom versioning convention for Chromium).
+3. Look through Puppeteer documentation and Changelogs to find information
+about where the "chromium revision" is located in the Puppeteer code. The code
+containing it might not be distributed in the node module.
+ - Example: https://github.com/puppeteer/puppeteer/blob/b549256/src/revisions.ts
4. Use `https://crrev.com` and look up the revision and find the git commit info.
-
-The official Chromium build process is poorly documented, and seems to have
-breaking changes fairly regularly. The build pre-requisites, and the build
-flags change over time, so it is likely that the scripts in this directory will
-be out of date by the time we have to do another Chromium build.
-
-This document is an attempt to note all of the gotchas we've come across while
-building, so that the next time we have to tinker here, we'll have a good
-starting point.
+ - Example: http://crrev.com/818858 leads to the git commit e62cb7e3fc7c40548cef66cdf19d270535d9350b
## Build args
@@ -115,8 +130,8 @@ The more cores the better, as the build makes effective use of each. For Linux,
- Linux:
- SSH in using [gcloud](https://cloud.google.com/sdk/)
- - Get the ssh command in the [GCP console](https://console.cloud.google.com/) -> VM instances -> your-vm-name -> SSH -> gcloud
- - Their in-browser UI is kinda sluggish, so use the commandline tool
+ - Get the ssh command in the [GCP console](https://console.cloud.google.com/) -> VM instances -> your-vm-name -> SSH -> "View gcloud command"
+ - Their in-browser UI is kinda sluggish, so use the commandline tool (Google Cloud SDK is required)
- Windows:
- Install Microsoft's Remote Desktop tools
diff --git a/x-pack/build_chromium/build.py b/x-pack/build_chromium/build.py
index 8622f4a9d4c0b..0064f48ae973f 100644
--- a/x-pack/build_chromium/build.py
+++ b/x-pack/build_chromium/build.py
@@ -33,10 +33,10 @@
base_version = source_version[:7].strip('.')
# Set to "arm" to build for ARM on Linux
-arch_name = sys.argv[2] if len(sys.argv) >= 3 else 'x64'
+arch_name = sys.argv[2] if len(sys.argv) >= 3 else 'unknown'
if arch_name != 'x64' and arch_name != 'arm64':
- raise Exception('Unexpected architecture: ' + arch_name)
+ raise Exception('Unexpected architecture: ' + arch_name + '. `x64` and `arm64` are supported.')
print('Building Chromium ' + source_version + ' for ' + arch_name + ' from ' + src_path)
print('src path: ' + src_path)
diff --git a/x-pack/build_chromium/init.py b/x-pack/build_chromium/init.py
index c0dd60f1cfcb0..3a2e28a884b09 100644
--- a/x-pack/build_chromium/init.py
+++ b/x-pack/build_chromium/init.py
@@ -8,18 +8,19 @@
# call this once the platform-specific initialization has completed.
# Set to "arm" to build for ARM on Linux
-arch_name = sys.argv[1] if len(sys.argv) >= 2 else 'x64'
+arch_name = sys.argv[1] if len(sys.argv) >= 2 else 'undefined'
build_path = path.abspath(os.curdir)
src_path = path.abspath(path.join(build_path, 'chromium', 'src'))
if arch_name != 'x64' and arch_name != 'arm64':
- raise Exception('Unexpected architecture: ' + arch_name)
+ raise Exception('Unexpected architecture: ' + arch_name + '. `x64` and `arm64` are supported.')
# Configure git
print('Configuring git globals...')
runcmd('git config --global core.autocrlf false')
runcmd('git config --global core.filemode false')
runcmd('git config --global branch.autosetuprebase always')
+runcmd('git config --global core.compression 0')
# Grab Chromium's custom build tools, if they aren't already installed
# (On Windows, they are installed before this Python script is run)
@@ -35,13 +36,14 @@
runcmd('git pull origin master')
os.chdir(original_dir)
-configure_environment(arch_name, build_path, src_path)
-
# Fetch the Chromium source code
chromium_dir = path.join(build_path, 'chromium')
if not path.isdir(chromium_dir):
mkdir(chromium_dir)
os.chdir(chromium_dir)
- runcmd('fetch chromium')
+ runcmd('fetch chromium --nohooks=1 --no-history=1')
else:
print('Directory exists: ' + chromium_dir + '. Skipping chromium fetch.')
+
+# This depends on having the chromium/src directory with the complete checkout
+configure_environment(arch_name, build_path, src_path)
diff --git a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/CustomLinkMenuSection/index.tsx b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/CustomLinkMenuSection/index.tsx
index ae22718af8b57..43f566a93a89d 100644
--- a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/CustomLinkMenuSection/index.tsx
+++ b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/CustomLinkMenuSection/index.tsx
@@ -107,7 +107,6 @@ export function CustomLinkMenuSection({
-
{i18n.translate(
'xpack.apm.transactionActionMenu.customLink.subtitle',
diff --git a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.test.tsx b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.test.tsx
index 48c863b460482..3141dc7a5f3c6 100644
--- a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.test.tsx
+++ b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.test.tsx
@@ -52,7 +52,7 @@ const renderTransaction = async (transaction: Record) => {
}
);
- fireEvent.click(rendered.getByText('Actions'));
+ fireEvent.click(rendered.getByText('Investigate'));
return rendered;
};
@@ -289,7 +289,7 @@ describe('TransactionActionMenu component', () => {
});
const component = renderTransactionActionMenuWithLicense(license);
act(() => {
- fireEvent.click(component.getByText('Actions'));
+ fireEvent.click(component.getByText('Investigate'));
});
expectTextsNotInDocument(component, ['Custom Links']);
});
@@ -313,7 +313,7 @@ describe('TransactionActionMenu component', () => {
{ wrapper: Wrapper }
);
act(() => {
- fireEvent.click(component.getByText('Actions'));
+ fireEvent.click(component.getByText('Investigate'));
});
expectTextsNotInDocument(component, ['Custom Links']);
});
@@ -330,7 +330,7 @@ describe('TransactionActionMenu component', () => {
});
const component = renderTransactionActionMenuWithLicense(license);
act(() => {
- fireEvent.click(component.getByText('Actions'));
+ fireEvent.click(component.getByText('Investigate'));
});
expectTextsInDocument(component, ['Custom Links']);
});
@@ -347,7 +347,7 @@ describe('TransactionActionMenu component', () => {
});
const component = renderTransactionActionMenuWithLicense(license);
act(() => {
- fireEvent.click(component.getByText('Actions'));
+ fireEvent.click(component.getByText('Investigate'));
});
expectTextsInDocument(component, ['Custom Links']);
});
@@ -364,7 +364,7 @@ describe('TransactionActionMenu component', () => {
});
const component = renderTransactionActionMenuWithLicense(license);
act(() => {
- fireEvent.click(component.getByText('Actions'));
+ fireEvent.click(component.getByText('Investigate'));
});
expectTextsInDocument(component, ['Custom Links']);
act(() => {
diff --git a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx
index 312513db80886..22fa25f93b212 100644
--- a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx
+++ b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/TransactionActionMenu.tsx
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { EuiButtonEmpty } from '@elastic/eui';
+import { EuiButton } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
@@ -30,11 +30,11 @@ interface Props {
function ActionMenuButton({ onClick }: { onClick: () => void }) {
return (
-
+
{i18n.translate('xpack.apm.transactionActionMenu.actionsButtonLabel', {
- defaultMessage: 'Actions',
+ defaultMessage: 'Investigate',
})}
-
+
);
}
diff --git a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/__snapshots__/TransactionActionMenu.test.tsx.snap b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/__snapshots__/TransactionActionMenu.test.tsx.snap
index fa6db645d28a8..ea33fb3c3df08 100644
--- a/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/__snapshots__/TransactionActionMenu.test.tsx.snap
+++ b/x-pack/plugins/apm/public/components/shared/TransactionActionMenu/__snapshots__/TransactionActionMenu.test.tsx.snap
@@ -10,20 +10,20 @@ exports[`TransactionActionMenu component matches the snapshot 1`] = `
class="euiPopover__anchor"
>
diff --git a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
index fae43ef148cfa..f6ddb15cbffa9 100644
--- a/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
+++ b/x-pack/plugins/apm/server/lib/alerts/chart_preview/get_transaction_error_rate.ts
@@ -44,9 +44,7 @@ export async function getTransactionErrorRateChartPreview({
},
};
- const outcomes = getOutcomeAggregation({
- searchAggregatedTransactions: false,
- });
+ const outcomes = getOutcomeAggregation();
const { intervalString } = getBucketSize({ start, end, numBuckets: 20 });
diff --git a/x-pack/plugins/apm/server/lib/correlations/get_correlations_for_failed_transactions/index.ts b/x-pack/plugins/apm/server/lib/correlations/get_correlations_for_failed_transactions/index.ts
index 64d9ebb192eb3..9ecf201ede1b7 100644
--- a/x-pack/plugins/apm/server/lib/correlations/get_correlations_for_failed_transactions/index.ts
+++ b/x-pack/plugins/apm/server/lib/correlations/get_correlations_for_failed_transactions/index.ts
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { isEmpty, omit } from 'lodash';
+import { isEmpty, omit, merge } from 'lodash';
import { EventOutcome } from '../../../../common/event_outcome';
import {
processSignificantTermAggs,
@@ -134,8 +134,7 @@ export async function getErrorRateTimeSeries({
extended_bounds: { min: start, max: end },
},
aggs: {
- // TODO: add support for metrics
- outcomes: getOutcomeAggregation({ searchAggregatedTransactions: false }),
+ outcomes: getOutcomeAggregation(),
},
};
@@ -147,13 +146,12 @@ export async function getErrorRateTimeSeries({
};
return acc;
},
- {} as Record<
- string,
- {
+ {} as {
+ [key: string]: {
filter: AggregationOptionsByType['filter'];
aggs: { timeseries: typeof timeseriesAgg };
- }
- >
+ };
+ }
);
const params = {
@@ -162,32 +160,25 @@ export async function getErrorRateTimeSeries({
body: {
size: 0,
query: { bool: { filter: backgroundFilters } },
- aggs: {
- // overall aggs
- timeseries: timeseriesAgg,
-
- // per term aggs
- ...perTermAggs,
- },
+ aggs: merge({ timeseries: timeseriesAgg }, perTermAggs),
},
};
const response = await apmEventClient.search(params);
- type Agg = NonNullable;
+ const { aggregations } = response;
- if (!response.aggregations) {
+ if (!aggregations) {
return {};
}
return {
overall: {
timeseries: getTransactionErrorRateTimeSeries(
- response.aggregations.timeseries.buckets
+ aggregations.timeseries.buckets
),
},
significantTerms: topSigTerms.map((topSig, index) => {
- // @ts-expect-error
- const agg = response.aggregations[`term_${index}`] as Agg;
+ const agg = aggregations[`term_${index}`]!;
return {
...topSig,
diff --git a/x-pack/plugins/apm/server/lib/helpers/transaction_error_rate.ts b/x-pack/plugins/apm/server/lib/helpers/transaction_error_rate.ts
index 876fc6b822213..2d041006e0e27 100644
--- a/x-pack/plugins/apm/server/lib/helpers/transaction_error_rate.ts
+++ b/x-pack/plugins/apm/server/lib/helpers/transaction_error_rate.ts
@@ -10,40 +10,21 @@ import {
AggregationOptionsByType,
AggregationResultOf,
} from '../../../../../typings/elasticsearch/aggregations';
-import { getTransactionDurationFieldForAggregatedTransactions } from './aggregated_transactions';
-export function getOutcomeAggregation({
- searchAggregatedTransactions,
-}: {
- searchAggregatedTransactions: boolean;
-}) {
- return {
- terms: {
- field: EVENT_OUTCOME,
- include: [EventOutcome.failure, EventOutcome.success],
- },
- aggs: {
- // simply using the doc count to get the number of requests is not possible for transaction metrics (histograms)
- // to work around this we get the number of transactions by counting the number of latency values
- count: {
- value_count: {
- field: getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- ),
- },
- },
- },
- };
-}
+export const getOutcomeAggregation = () => ({
+ terms: {
+ field: EVENT_OUTCOME,
+ include: [EventOutcome.failure, EventOutcome.success],
+ },
+});
+
+type OutcomeAggregation = ReturnType;
export function calculateTransactionErrorPercentage(
- outcomeResponse: AggregationResultOf<
- ReturnType,
- {}
- >
+ outcomeResponse: AggregationResultOf
) {
const outcomes = Object.fromEntries(
- outcomeResponse.buckets.map(({ key, count }) => [key, count.value])
+ outcomeResponse.buckets.map(({ key, doc_count: count }) => [key, count])
);
const failedTransactions = outcomes[EventOutcome.failure] ?? 0;
@@ -56,7 +37,7 @@ export function getTransactionErrorRateTimeSeries(
buckets: AggregationResultOf<
{
date_histogram: AggregationOptionsByType['date_histogram'];
- aggs: { outcomes: ReturnType };
+ aggs: { outcomes: OutcomeAggregation };
},
{}
>['buckets']
diff --git a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts
index 5531944fc7180..fa4bf6144fb6f 100644
--- a/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts
+++ b/x-pack/plugins/apm/server/lib/observability_overview/get_transaction_coordinates.ts
@@ -11,10 +11,7 @@
import { rangeFilter } from '../../../common/utils/range_filter';
import { Coordinates } from '../../../../observability/typings/common';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
-import {
- getProcessorEventForAggregatedTransactions,
- getTransactionDurationFieldForAggregatedTransactions,
-} from '../helpers/aggregated_transactions';
+import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
export async function getTransactionCoordinates({
setup,
@@ -49,15 +46,6 @@ export async function getTransactionCoordinates({
fixed_interval: bucketSize,
min_doc_count: 0,
},
- aggs: {
- count: {
- value_count: {
- field: getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- ),
- },
- },
- },
},
},
},
@@ -68,7 +56,7 @@ export async function getTransactionCoordinates({
return (
aggregations?.distribution.buckets.map((bucket) => ({
x: bucket.key,
- y: bucket.count.value / deltaAsMinutes,
+ y: bucket.doc_count / deltaAsMinutes,
})) || []
);
}
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.test.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.test.ts
index f7ca40ef1052c..173de796d47e4 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.test.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.test.ts
@@ -52,8 +52,10 @@ describe('getServiceMapServiceNodeInfo', () => {
apmEventClient: {
search: () =>
Promise.resolve({
+ hits: {
+ total: { value: 1 },
+ },
aggregations: {
- count: { value: 1 },
duration: { value: null },
avgCpuUsage: { value: null },
avgMemoryUsage: { value: null },
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
index 82d339686f7ec..4fe9a1a75d43f 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
@@ -162,19 +162,12 @@ async function getTransactionStats({
),
},
},
- count: {
- value_count: {
- field: getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- ),
- },
- },
},
},
};
const response = await apmEventClient.search(params);
- const totalRequests = response.aggregations?.count.value ?? 0;
+ const totalRequests = response.hits.total.value;
return {
avgTransactionDuration: response.aggregations?.duration.value ?? null,
diff --git a/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap b/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap
index 21402e4c8dac0..239b909e1572c 100644
--- a/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap
+++ b/x-pack/plugins/apm/server/lib/services/__snapshots__/queries.test.ts.snap
@@ -122,13 +122,6 @@ Array [
},
},
"outcomes": Object {
- "aggs": Object {
- "count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
- },
"terms": Object {
"field": "event.outcome",
"include": Array [
@@ -137,11 +130,6 @@ Array [
],
},
},
- "real_document_count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
"timeseries": Object {
"aggs": Object {
"avg_duration": Object {
@@ -150,13 +138,6 @@ Array [
},
},
"outcomes": Object {
- "aggs": Object {
- "count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
- },
"terms": Object {
"field": "event.outcome",
"include": Array [
@@ -165,11 +146,6 @@ Array [
],
},
},
- "real_document_count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
},
"date_histogram": Object {
"extended_bounds": Object {
@@ -184,9 +160,6 @@ Array [
},
"terms": Object {
"field": "transaction.type",
- "order": Object {
- "real_document_count": "desc",
- },
},
},
},
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts
index 5880b5cbc9546..c5e5269c4409e 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_instances/get_service_instance_transaction_stats.ts
@@ -30,18 +30,17 @@ export async function getServiceInstanceTransactionStats({
}: ServiceInstanceParams) {
const { apmEventClient, start, end, esFilter } = setup;
- const { intervalString } = getBucketSize({ start, end, numBuckets });
+ const { intervalString, bucketSize } = getBucketSize({
+ start,
+ end,
+ numBuckets,
+ });
const field = getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
);
const subAggs = {
- count: {
- value_count: {
- field,
- },
- },
avg_transaction_duration: {
avg: {
field,
@@ -53,13 +52,6 @@ export async function getServiceInstanceTransactionStats({
[EVENT_OUTCOME]: EventOutcome.failure,
},
},
- aggs: {
- count: {
- value_count: {
- field,
- },
- },
- },
},
};
@@ -113,12 +105,13 @@ export async function getServiceInstanceTransactionStats({
});
const deltaAsMinutes = (end - start) / 60 / 1000;
+ const bucketSizeInMinutes = bucketSize / 60;
return (
response.aggregations?.[SERVICE_NODE_NAME].buckets.map(
(serviceNodeBucket) => {
const {
- count,
+ doc_count: count,
avg_transaction_duration: avgTransactionDuration,
key,
failures,
@@ -128,17 +121,17 @@ export async function getServiceInstanceTransactionStats({
return {
serviceNodeName: String(key),
errorRate: {
- value: failures.count.value / count.value,
+ value: failures.doc_count / count,
timeseries: timeseries.buckets.map((dateBucket) => ({
x: dateBucket.key,
- y: dateBucket.failures.count.value / dateBucket.count.value,
+ y: dateBucket.failures.doc_count / dateBucket.doc_count,
})),
},
throughput: {
- value: count.value / deltaAsMinutes,
+ value: count / deltaAsMinutes,
timeseries: timeseries.buckets.map((dateBucket) => ({
x: dateBucket.key,
- y: dateBucket.count.value / deltaAsMinutes,
+ y: dateBucket.doc_count / bucketSizeInMinutes,
})),
},
latency: {
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_timeseries_data_for_transaction_groups.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_timeseries_data_for_transaction_groups.ts
index 937155bc31602..745535f261673 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_timeseries_data_for_transaction_groups.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_timeseries_data_for_transaction_groups.ts
@@ -17,6 +17,7 @@ import {
import { ESFilter } from '../../../../../../typings/elasticsearch';
import {
+ getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
getTransactionDurationFieldForAggregatedTransactions,
} from '../../helpers/aggregated_transactions';
@@ -76,6 +77,9 @@ export async function getTimeseriesDataForTransactionGroups({
{ term: { [SERVICE_NAME]: serviceName } },
{ term: { [TRANSACTION_TYPE]: transactionType } },
{ range: rangeFilter(start, end) },
+ ...getDocumentTypeFilterForAggregatedTransactions(
+ searchAggregatedTransactions
+ ),
...esFilter,
],
},
@@ -99,10 +103,8 @@ export async function getTimeseriesDataForTransactionGroups({
},
aggs: {
...getLatencyAggregation(latencyAggregationType, field),
- transaction_count: { value_count: { field } },
[EVENT_OUTCOME]: {
filter: { term: { [EVENT_OUTCOME]: EventOutcome.failure } },
- aggs: { transaction_count: { value_count: { field } } },
},
},
},
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts
index ccccf946512dd..400c896e380b4 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts
@@ -99,10 +99,8 @@ export async function getTransactionGroupsForPage({
},
aggs: {
...getLatencyAggregation(latencyAggregationType, field),
- transaction_count: { value_count: { field } },
[EVENT_OUTCOME]: {
filter: { term: { [EVENT_OUTCOME]: EventOutcome.failure } },
- aggs: { transaction_count: { value_count: { field } } },
},
},
},
@@ -113,9 +111,8 @@ export async function getTransactionGroupsForPage({
const transactionGroups =
response.aggregations?.transaction_groups.buckets.map((bucket) => {
const errorRate =
- bucket.transaction_count.value > 0
- ? (bucket[EVENT_OUTCOME].transaction_count.value ?? 0) /
- bucket.transaction_count.value
+ bucket.doc_count > 0
+ ? bucket[EVENT_OUTCOME].doc_count / bucket.doc_count
: null;
return {
@@ -124,7 +121,7 @@ export async function getTransactionGroupsForPage({
latencyAggregationType,
aggregation: bucket.latency,
}),
- throughput: bucket.transaction_count.value / deltaAsMinutes,
+ throughput: bucket.doc_count / deltaAsMinutes,
errorRate,
};
}) ?? [];
diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts
index a8794e3c09a40..b0b1cb09dd784 100644
--- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts
@@ -52,18 +52,14 @@ export function mergeTransactionGroupData({
...acc.throughput,
timeseries: acc.throughput.timeseries.concat({
x: point.key,
- y: point.transaction_count.value / deltaAsMinutes,
+ y: point.doc_count / deltaAsMinutes,
}),
},
errorRate: {
...acc.errorRate,
timeseries: acc.errorRate.timeseries.concat({
x: point.key,
- y:
- point.transaction_count.value > 0
- ? (point[EVENT_OUTCOME].transaction_count.value ?? 0) /
- point.transaction_count.value
- : null,
+ y: point[EVENT_OUTCOME].doc_count / point.doc_count,
}),
},
};
diff --git a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
index 0ee7080dc0834..efbc30169d178 100644
--- a/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
+++ b/x-pack/plugins/apm/server/lib/services/get_services/get_service_transaction_stats.ts
@@ -51,16 +51,9 @@ export async function getServiceTransactionStats({
}: AggregationParams) {
const { apmEventClient, start, end, esFilter } = setup;
- const outcomes = getOutcomeAggregation({ searchAggregatedTransactions });
+ const outcomes = getOutcomeAggregation();
const metrics = {
- real_document_count: {
- value_count: {
- field: getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- ),
- },
- },
avg_duration: {
avg: {
field: getTransactionDurationFieldForAggregatedTransactions(
@@ -102,7 +95,6 @@ export async function getServiceTransactionStats({
transactionType: {
terms: {
field: TRANSACTION_TYPE,
- order: { real_document_count: 'desc' },
},
aggs: {
...metrics,
@@ -180,14 +172,14 @@ export async function getServiceTransactionStats({
},
transactionsPerMinute: {
value: calculateAvgDuration({
- value: topTransactionTypeBucket.real_document_count.value,
+ value: topTransactionTypeBucket.doc_count,
deltaAsMinutes,
}),
timeseries: topTransactionTypeBucket.timeseries.buckets.map(
(dateBucket) => ({
x: dateBucket.key,
y: calculateAvgDuration({
- value: dateBucket.real_document_count.value,
+ value: dateBucket.doc_count,
deltaAsMinutes,
}),
})
diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/__snapshots__/queries.test.ts.snap b/x-pack/plugins/apm/server/lib/transaction_groups/__snapshots__/queries.test.ts.snap
index c678e7db711b6..89069d74bacf8 100644
--- a/x-pack/plugins/apm/server/lib/transaction_groups/__snapshots__/queries.test.ts.snap
+++ b/x-pack/plugins/apm/server/lib/transaction_groups/__snapshots__/queries.test.ts.snap
@@ -12,11 +12,6 @@ Array [
"aggs": Object {
"transaction_groups": Object {
"aggs": Object {
- "count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
"transaction_type": Object {
"top_hits": Object {
"_source": Array [
@@ -226,11 +221,6 @@ Array [
"aggs": Object {
"transaction_groups": Object {
"aggs": Object {
- "count": Object {
- "value_count": Object {
- "field": "transaction.duration.us",
- },
- },
"transaction_type": Object {
"top_hits": Object {
"_source": Array [
diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts b/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
index dfd11203b87f1..a2388dddc7fd4 100644
--- a/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
+++ b/x-pack/plugins/apm/server/lib/transaction_groups/get_error_rate.ts
@@ -14,7 +14,10 @@ import {
} from '../../../common/elasticsearch_fieldnames';
import { EventOutcome } from '../../../common/event_outcome';
import { rangeFilter } from '../../../common/utils/range_filter';
-import { getProcessorEventForAggregatedTransactions } from '../helpers/aggregated_transactions';
+import {
+ getDocumentTypeFilterForAggregatedTransactions,
+ getProcessorEventForAggregatedTransactions,
+} from '../helpers/aggregated_transactions';
import { getBucketSize } from '../helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../helpers/setup_request';
import {
@@ -55,12 +58,15 @@ export async function getErrorRate({
{
terms: { [EVENT_OUTCOME]: [EventOutcome.failure, EventOutcome.success] },
},
+ ...getDocumentTypeFilterForAggregatedTransactions(
+ searchAggregatedTransactions
+ ),
...transactionNamefilter,
...transactionTypefilter,
...esFilter,
];
- const outcomes = getOutcomeAggregation({ searchAggregatedTransactions });
+ const outcomes = getOutcomeAggregation();
const params = {
apm: {
diff --git a/x-pack/plugins/apm/server/lib/transaction_groups/get_transaction_group_stats.ts b/x-pack/plugins/apm/server/lib/transaction_groups/get_transaction_group_stats.ts
index cfd3540446172..dba58cecad79b 100644
--- a/x-pack/plugins/apm/server/lib/transaction_groups/get_transaction_group_stats.ts
+++ b/x-pack/plugins/apm/server/lib/transaction_groups/get_transaction_group_stats.ts
@@ -66,13 +66,6 @@ export async function getCounts({
searchAggregatedTransactions,
}: MetricParams) {
const params = mergeRequestWithAggs(request, {
- count: {
- value_count: {
- field: getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- ),
- },
- },
transaction_type: {
top_hits: {
size: 1,
@@ -92,7 +85,7 @@ export async function getCounts({
return {
key: bucket.key as BucketKey,
- count: bucket.count.value,
+ count: bucket.doc_count,
transactionType: source.transaction.type,
};
});
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
index be374ccfe3400..8dfb0a9f65878 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/index.ts
@@ -15,7 +15,6 @@ import { rangeFilter } from '../../../../common/utils/range_filter';
import {
getDocumentTypeFilterForAggregatedTransactions,
getProcessorEventForAggregatedTransactions,
- getTransactionDurationFieldForAggregatedTransactions,
} from '../../../lib/helpers/aggregated_transactions';
import { getBucketSize } from '../../../lib/helpers/get_bucket_size';
import { Setup, SetupTimeRange } from '../../../lib/helpers/setup_request';
@@ -56,10 +55,6 @@ async function searchThroughput({
filter.push({ term: { [TRANSACTION_NAME]: transactionName } });
}
- const field = getTransactionDurationFieldForAggregatedTransactions(
- searchAggregatedTransactions
- );
-
const params = {
apm: {
events: [
@@ -82,7 +77,6 @@ async function searchThroughput({
min_doc_count: 0,
extended_bounds: { min: start, max: end },
},
- aggs: { count: { value_count: { field } } },
},
},
},
diff --git a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts
index a12e36c0e9de4..7e43a0d76f70a 100644
--- a/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/get_throughput_charts/transform.ts
@@ -25,7 +25,7 @@ export function getThroughputBuckets({
return {
x: bucket.key,
// divide by minutes
- y: bucket.count.value / (bucketSize / 60),
+ y: bucket.doc_count / (bucketSize / 60),
};
});
@@ -34,7 +34,7 @@ export function getThroughputBuckets({
resultKey === '' ? NOT_AVAILABLE_LABEL : (resultKey as string);
const docCountTotal = timeseries.buckets
- .map((bucket) => bucket.count.value)
+ .map((bucket) => bucket.doc_count)
.reduce((a, b) => a + b, 0);
// calculate average throughput
diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/get_demo_rows.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/get_demo_rows.ts
index 58a2354b5cf38..ff5a4506ab82a 100644
--- a/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/get_demo_rows.ts
+++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/server/demodata/get_demo_rows.ts
@@ -5,8 +5,10 @@
*/
import { cloneDeep } from 'lodash';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import ci from './ci.json';
import { DemoRows } from './demo_rows_types';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import shirts from './shirts.json';
import { getFunctionErrors } from '../../../../i18n';
diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/error/index.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/error/index.tsx
index a9296bd9a1241..238b2edc3bd6d 100644
--- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/error/index.tsx
+++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/error/index.tsx
@@ -12,7 +12,7 @@ import { Popover } from '../../../public/components/popover';
import { RendererStrings } from '../../../i18n';
import { RendererFactory } from '../../../types';
-interface Config {
+export interface Config {
error: Error;
}
diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/filters/dropdown_filter/index.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/filters/dropdown_filter/index.tsx
index bfc36932a8a07..6c1dd086c8667 100644
--- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/filters/dropdown_filter/index.tsx
+++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/filters/dropdown_filter/index.tsx
@@ -15,7 +15,7 @@ import { RendererStrings } from '../../../../i18n';
const { dropdownFilter: strings } = RendererStrings;
-interface Config {
+export interface Config {
/** The column to use within the exactly function */
column: string;
/**
diff --git a/x-pack/plugins/canvas/canvas_plugin_src/renderers/table.tsx b/x-pack/plugins/canvas/canvas_plugin_src/renderers/table.tsx
index ada159e07f6ae..4933b1b4ba51d 100644
--- a/x-pack/plugins/canvas/canvas_plugin_src/renderers/table.tsx
+++ b/x-pack/plugins/canvas/canvas_plugin_src/renderers/table.tsx
@@ -12,7 +12,7 @@ import { RendererFactory, Style, Datatable } from '../../types';
const { dropdownFilter: strings } = RendererStrings;
-interface TableArguments {
+export interface TableArguments {
font?: Style;
paginate: boolean;
perPage: number;
diff --git a/x-pack/plugins/canvas/public/apps/export/export/export_app.component.tsx b/x-pack/plugins/canvas/public/apps/export/export/export_app.component.tsx
index 03121e749d0dc..f26408b1200f1 100644
--- a/x-pack/plugins/canvas/public/apps/export/export/export_app.component.tsx
+++ b/x-pack/plugins/canvas/public/apps/export/export/export_app.component.tsx
@@ -13,7 +13,7 @@ import { WorkpadPage } from '../../../components/workpad_page';
import { Link } from '../../../components/link';
import { CanvasWorkpad } from '../../../../types';
-interface Props {
+export interface Props {
workpad: CanvasWorkpad;
selectedPageIndex: number;
initializeWorkpad: () => void;
diff --git a/x-pack/plugins/canvas/public/apps/home/home_app/home_app.component.tsx b/x-pack/plugins/canvas/public/apps/home/home_app/home_app.component.tsx
index 3c2e989cc8e51..7fbdc24c112a1 100644
--- a/x-pack/plugins/canvas/public/apps/home/home_app/home_app.component.tsx
+++ b/x-pack/plugins/canvas/public/apps/home/home_app/home_app.component.tsx
@@ -11,7 +11,7 @@ import { WorkpadManager } from '../../../components/workpad_manager';
// @ts-expect-error untyped local
import { setDocTitle } from '../../../lib/doc_title';
-interface Props {
+export interface Props {
onLoad: () => void;
}
diff --git a/x-pack/plugins/canvas/public/apps/workpad/workpad_app/workpad_telemetry.tsx b/x-pack/plugins/canvas/public/apps/workpad/workpad_app/workpad_telemetry.tsx
index 981334ff8d9f2..3697d5dad2dae 100644
--- a/x-pack/plugins/canvas/public/apps/workpad/workpad_app/workpad_telemetry.tsx
+++ b/x-pack/plugins/canvas/public/apps/workpad/workpad_app/workpad_telemetry.tsx
@@ -46,7 +46,7 @@ interface ResolvedArgs {
[keys: string]: any;
}
-interface ElementsLoadedTelemetryProps extends PropsFromRedux {
+export interface ElementsLoadedTelemetryProps extends PropsFromRedux {
workpad: Workpad;
}
diff --git a/x-pack/plugins/canvas/public/components/asset_manager/asset.component.tsx b/x-pack/plugins/canvas/public/components/asset_manager/asset.component.tsx
index ed000741bc542..d94802bf2a772 100644
--- a/x-pack/plugins/canvas/public/components/asset_manager/asset.component.tsx
+++ b/x-pack/plugins/canvas/public/components/asset_manager/asset.component.tsx
@@ -28,7 +28,7 @@ import { ComponentStrings } from '../../../i18n';
const { Asset: strings } = ComponentStrings;
-interface Props {
+export interface Props {
/** The asset to be rendered */
asset: AssetType;
/** The function to execute when the user clicks 'Create' */
diff --git a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.component.tsx b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.component.tsx
index 98f3d8b48829d..6c1b546b49aa1 100644
--- a/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.component.tsx
+++ b/x-pack/plugins/canvas/public/components/asset_manager/asset_manager.component.tsx
@@ -33,7 +33,7 @@ import { ComponentStrings } from '../../../i18n';
const { AssetManager: strings } = ComponentStrings;
-interface Props {
+export interface Props {
/** The assets to display within the modal */
assets: AssetType[];
/** Function to invoke when the modal is closed */
diff --git a/x-pack/plugins/canvas/public/components/confirm_modal/confirm_modal.tsx b/x-pack/plugins/canvas/public/components/confirm_modal/confirm_modal.tsx
index 31a75acbba4ec..9d0a5e0a9f51d 100644
--- a/x-pack/plugins/canvas/public/components/confirm_modal/confirm_modal.tsx
+++ b/x-pack/plugins/canvas/public/components/confirm_modal/confirm_modal.tsx
@@ -8,7 +8,7 @@ import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
-interface Props {
+export interface Props {
isOpen: boolean;
title?: string;
message: string;
diff --git a/x-pack/plugins/canvas/public/components/page_preview/page_preview.component.tsx b/x-pack/plugins/canvas/public/components/page_preview/page_preview.component.tsx
index fd1dc869d60ec..da1fe8473e36d 100644
--- a/x-pack/plugins/canvas/public/components/page_preview/page_preview.component.tsx
+++ b/x-pack/plugins/canvas/public/components/page_preview/page_preview.component.tsx
@@ -10,7 +10,7 @@ import { DomPreview } from '../dom_preview';
import { PageControls } from './page_controls';
import { CanvasPage } from '../../../types';
-interface Props {
+export interface Props {
isWriteable: boolean;
page: Pick;
height: number;
diff --git a/x-pack/plugins/canvas/public/components/toolbar/toolbar.component.tsx b/x-pack/plugins/canvas/public/components/toolbar/toolbar.component.tsx
index 7151e72a44780..d33ba57050d4b 100644
--- a/x-pack/plugins/canvas/public/components/toolbar/toolbar.component.tsx
+++ b/x-pack/plugins/canvas/public/components/toolbar/toolbar.component.tsx
@@ -31,7 +31,7 @@ const { Toolbar: strings } = ComponentStrings;
type TrayType = 'pageManager' | 'expression';
-interface Props {
+export interface Props {
isWriteable: boolean;
selectedElement?: CanvasElement;
selectedPageNumber: number;
diff --git a/x-pack/plugins/canvas/public/components/workpad_config/workpad_config.component.tsx b/x-pack/plugins/canvas/public/components/workpad_config/workpad_config.component.tsx
index a7424882f1072..4068272bbaf11 100644
--- a/x-pack/plugins/canvas/public/components/workpad_config/workpad_config.component.tsx
+++ b/x-pack/plugins/canvas/public/components/workpad_config/workpad_config.component.tsx
@@ -30,7 +30,7 @@ import { ComponentStrings } from '../../../i18n';
const { WorkpadConfig: strings } = ComponentStrings;
-interface Props {
+export interface Props {
size: {
height: number;
width: number;
diff --git a/x-pack/plugins/canvas/public/components/workpad_header/refresh_control/refresh_control.component.tsx b/x-pack/plugins/canvas/public/components/workpad_header/refresh_control/refresh_control.component.tsx
index d651e649128f9..023d87c7c3565 100644
--- a/x-pack/plugins/canvas/public/components/workpad_header/refresh_control/refresh_control.component.tsx
+++ b/x-pack/plugins/canvas/public/components/workpad_header/refresh_control/refresh_control.component.tsx
@@ -12,7 +12,7 @@ import { ToolTipShortcut } from '../../tool_tip_shortcut';
import { ComponentStrings } from '../../../../i18n';
const { WorkpadHeaderRefreshControlSettings: strings } = ComponentStrings;
-interface Props {
+export interface Props {
doRefresh: MouseEventHandler;
inFlight: boolean;
}
diff --git a/x-pack/plugins/canvas/public/functions/filters.ts b/x-pack/plugins/canvas/public/functions/filters.ts
index fdb5d69d35515..70120ccad6f54 100644
--- a/x-pack/plugins/canvas/public/functions/filters.ts
+++ b/x-pack/plugins/canvas/public/functions/filters.ts
@@ -15,7 +15,7 @@ import { ExpressionValueFilter } from '../../types';
import { getFunctionHelp } from '../../i18n';
import { InitializeArguments } from '.';
-interface Arguments {
+export interface Arguments {
group: string[];
ungrouped: boolean;
}
diff --git a/x-pack/plugins/canvas/public/functions/pie.ts b/x-pack/plugins/canvas/public/functions/pie.ts
index ab3f1b932dc3c..e7cf153b9cd0f 100644
--- a/x-pack/plugins/canvas/public/functions/pie.ts
+++ b/x-pack/plugins/canvas/public/functions/pie.ts
@@ -61,7 +61,7 @@ export interface Pie {
options: PieOptions;
}
-interface Arguments {
+export interface Arguments {
palette: PaletteOutput;
seriesStyle: SeriesStyle[];
radius: number | 'auto';
diff --git a/x-pack/plugins/canvas/public/functions/plot/index.ts b/x-pack/plugins/canvas/public/functions/plot/index.ts
index a4661dc3401df..79aa11cfa2d80 100644
--- a/x-pack/plugins/canvas/public/functions/plot/index.ts
+++ b/x-pack/plugins/canvas/public/functions/plot/index.ts
@@ -17,7 +17,7 @@ import { getTickHash } from './get_tick_hash';
import { getFunctionHelp } from '../../../i18n';
import { AxisConfig, PointSeries, Render, SeriesStyle, Legend } from '../../../types';
-interface Arguments {
+export interface Arguments {
seriesStyle: SeriesStyle[];
defaultStyle: SeriesStyle;
palette: PaletteOutput;
diff --git a/x-pack/plugins/canvas/public/functions/timelion.ts b/x-pack/plugins/canvas/public/functions/timelion.ts
index 947972fa310c9..3018540e5bf8e 100644
--- a/x-pack/plugins/canvas/public/functions/timelion.ts
+++ b/x-pack/plugins/canvas/public/functions/timelion.ts
@@ -15,7 +15,7 @@ import { Datatable, ExpressionValueFilter } from '../../types';
import { getFunctionHelp } from '../../i18n';
import { InitializeArguments } from './';
-interface Arguments {
+export interface Arguments {
query: string;
interval: string;
from: string;
diff --git a/x-pack/plugins/canvas/public/functions/to.ts b/x-pack/plugins/canvas/public/functions/to.ts
index 36b2d3f9f04c6..c8ac4f714e5c4 100644
--- a/x-pack/plugins/canvas/public/functions/to.ts
+++ b/x-pack/plugins/canvas/public/functions/to.ts
@@ -10,7 +10,7 @@ import { ExpressionFunctionDefinition } from 'src/plugins/expressions/public';
import { getFunctionHelp, getFunctionErrors } from '../../i18n';
import { InitializeArguments } from '.';
-interface Arguments {
+export interface Arguments {
type: string[];
}
diff --git a/x-pack/plugins/canvas/public/lib/template_from_react_component.tsx b/x-pack/plugins/canvas/public/lib/template_from_react_component.tsx
index f4e715b1bbc49..95225cf13ff3b 100644
--- a/x-pack/plugins/canvas/public/lib/template_from_react_component.tsx
+++ b/x-pack/plugins/canvas/public/lib/template_from_react_component.tsx
@@ -11,7 +11,7 @@ import { I18nProvider } from '@kbn/i18n/react';
import { ErrorBoundary } from '../components/enhance/error_boundary';
import { ArgumentHandlers } from '../../types/arguments';
-interface Props {
+export interface Props {
renderError: Function;
}
diff --git a/x-pack/plugins/canvas/server/sample_data/index.ts b/x-pack/plugins/canvas/server/sample_data/index.ts
index 212d9f5132831..9c9ecb718fd5f 100644
--- a/x-pack/plugins/canvas/server/sample_data/index.ts
+++ b/x-pack/plugins/canvas/server/sample_data/index.ts
@@ -3,9 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import ecommerceSavedObjects from './ecommerce_saved_objects.json';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import flightsSavedObjects from './flights_saved_objects.json';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import webLogsSavedObjects from './web_logs_saved_objects.json';
import { loadSampleData } from './load_sample_data';
diff --git a/x-pack/plugins/canvas/shareable_runtime/context/actions.ts b/x-pack/plugins/canvas/shareable_runtime/context/actions.ts
index 8c88afbadfd9e..a36435688505d 100644
--- a/x-pack/plugins/canvas/shareable_runtime/context/actions.ts
+++ b/x-pack/plugins/canvas/shareable_runtime/context/actions.ts
@@ -17,7 +17,7 @@ export enum CanvasShareableActions {
SET_TOOLBAR_AUTOHIDE = 'SET_TOOLBAR_AUTOHIDE',
}
-interface FluxAction {
+export interface FluxAction {
type: T;
payload: P;
}
diff --git a/x-pack/plugins/canvas/shareable_runtime/test/index.ts b/x-pack/plugins/canvas/shareable_runtime/test/index.ts
index 288dd0dc3a5be..f0d2ebcc20128 100644
--- a/x-pack/plugins/canvas/shareable_runtime/test/index.ts
+++ b/x-pack/plugins/canvas/shareable_runtime/test/index.ts
@@ -4,8 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import hello from './workpads/hello.json';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import austin from './workpads/austin.json';
+// @ts-ignore this file is too large for TypeScript, so it is excluded from our project config
import test from './workpads/test.json';
export * from './utils';
diff --git a/x-pack/plugins/canvas/tsconfig.json b/x-pack/plugins/canvas/tsconfig.json
new file mode 100644
index 0000000000000..3e3986082e207
--- /dev/null
+++ b/x-pack/plugins/canvas/tsconfig.json
@@ -0,0 +1,52 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "composite": true,
+ "outDir": "./target/types",
+ "emitDeclarationOnly": true,
+ "declaration": true,
+ "declarationMap": true
+ },
+ "include": [
+ "../../../typings/**/*",
+ "__fixtures__/**/*",
+ "canvas_plugin_src/**/*",
+ "common/**/*",
+ "i18n/**/*",
+ "public/**/*",
+ "server/**/*",
+ "shareable_runtime/**/*",
+ "storybook/**/*",
+ "tasks/mocks/*",
+ "types/**/*",
+ "**/*.json",
+ ],
+ "exclude": [
+ // these files are too large and upset tsc, so we exclude them
+ "server/sample_data/*.json",
+ "canvas_plugin_src/functions/server/demodata/*.json",
+ "shareable_runtime/test/workpads/*.json",
+ ],
+ "references": [
+ { "path": "../../../src/core/tsconfig.json" },
+ { "path": "../../../src/plugins/bfetch/tsconfig.json"},
+ { "path": "../../../src/plugins/charts/tsconfig.json" },
+ { "path": "../../../src/plugins/data/tsconfig.json"},
+ { "path": "../../../src/plugins/discover/tsconfig.json" },
+ { "path": "../../../src/plugins/embeddable/tsconfig.json" },
+ { "path": "../../../src/plugins/expressions/tsconfig.json" },
+ { "path": "../../../src/plugins/home/tsconfig.json" },
+ { "path": "../../../src/plugins/inspector/tsconfig.json" },
+ { "path": "../../../src/plugins/kibana_legacy/tsconfig.json" },
+ { "path": "../../../src/plugins/kibana_react/tsconfig.json" },
+ { "path": "../../../src/plugins/kibana_utils/tsconfig.json" },
+ { "path": "../../../src/plugins/saved_objects/tsconfig.json" },
+ { "path": "../../../src/plugins/ui_actions/tsconfig.json" },
+ { "path": "../../../src/plugins/usage_collection/tsconfig.json" },
+ { "path": "../../../src/plugins/visualizations/tsconfig.json" },
+ { "path": "../features/tsconfig.json" },
+ { "path": "../lens/tsconfig.json" },
+ { "path": "../maps/tsconfig.json" },
+ { "path": "../reporting/tsconfig.json" },
+ ]
+}
diff --git a/x-pack/plugins/canvas/types/state.ts b/x-pack/plugins/canvas/types/state.ts
index 03bb931dc9b26..33f913563daac 100644
--- a/x-pack/plugins/canvas/types/state.ts
+++ b/x-pack/plugins/canvas/types/state.ts
@@ -52,7 +52,7 @@ type ExpressionType =
| Style
| Range;
-interface ExpressionRenderable {
+export interface ExpressionRenderable {
state: 'ready' | 'pending';
value: Render | null;
error: null;
diff --git a/x-pack/plugins/case/common/api/cases/configure.ts b/x-pack/plugins/case/common/api/cases/configure.ts
index b82c6de8fc363..398f73f2721a6 100644
--- a/x-pack/plugins/case/common/api/cases/configure.ts
+++ b/x-pack/plugins/case/common/api/cases/configure.ts
@@ -6,11 +6,12 @@
import * as rt from 'io-ts';
-import { ActionResult } from '../../../../actions/common';
+import { ActionResult, ActionType } from '../../../../actions/common';
import { UserRT } from '../user';
import { CaseConnectorRt, ConnectorMappingsRt, ESCaseConnector } from '../connectors';
export type ActionConnector = ActionResult;
+export type ActionTypeConnector = ActionType;
// TODO: we will need to add this type rt.literal('close-by-third-party')
const ClosureTypeRT = rt.union([rt.literal('close-by-user'), rt.literal('close-by-pushing')]);
diff --git a/x-pack/plugins/case/server/routes/api/__fixtures__/route_contexts.ts b/x-pack/plugins/case/server/routes/api/__fixtures__/route_contexts.ts
index 40911496d6494..3a12b50cf8f68 100644
--- a/x-pack/plugins/case/server/routes/api/__fixtures__/route_contexts.ts
+++ b/x-pack/plugins/case/server/routes/api/__fixtures__/route_contexts.ts
@@ -14,13 +14,15 @@ import {
CaseConfigureService,
ConnectorMappingsService,
} from '../../../services';
-import { getActions } from '../__mocks__/request_responses';
+import { getActions, getActionTypes } from '../__mocks__/request_responses';
import { authenticationMock } from '../__fixtures__';
import type { CasesRequestHandlerContext } from '../../../types';
export const createRouteContext = async (client: any, badAuth = false) => {
const actionsMock = actionsClientMock.create();
actionsMock.getAll.mockImplementation(() => Promise.resolve(getActions()));
+ actionsMock.listTypes.mockImplementation(() => Promise.resolve(getActionTypes()));
+
const log = loggingSystemMock.create().get('case');
const esClientMock = elasticsearchServiceMock.createClusterClient();
diff --git a/x-pack/plugins/case/server/routes/api/__mocks__/request_responses.ts b/x-pack/plugins/case/server/routes/api/__mocks__/request_responses.ts
index efc3b6044a804..236deb9c7462c 100644
--- a/x-pack/plugins/case/server/routes/api/__mocks__/request_responses.ts
+++ b/x-pack/plugins/case/server/routes/api/__mocks__/request_responses.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import {
+ ActionTypeConnector,
CasePostRequest,
CasesConfigureRequest,
ConnectorTypes,
@@ -73,6 +74,49 @@ export const getActions = (): FindActionResult[] => [
},
];
+export const getActionTypes = (): ActionTypeConnector[] => [
+ {
+ id: '.email',
+ name: 'Email',
+ minimumLicenseRequired: 'gold',
+ enabled: true,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+ {
+ id: '.index',
+ name: 'Index',
+ minimumLicenseRequired: 'basic',
+ enabled: true,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+ {
+ id: '.servicenow',
+ name: 'ServiceNow',
+ minimumLicenseRequired: 'platinum',
+ enabled: false,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+ {
+ id: '.jira',
+ name: 'Jira',
+ minimumLicenseRequired: 'gold',
+ enabled: true,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+ {
+ id: '.resilient',
+ name: 'IBM Resilient',
+ minimumLicenseRequired: 'platinum',
+ enabled: false,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+];
+
export const newConfiguration: CasesConfigureRequest = {
connector: {
id: '456',
diff --git a/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.test.ts b/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.test.ts
index b744a6dc04810..974ae9283dd98 100644
--- a/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.test.ts
+++ b/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.test.ts
@@ -42,10 +42,72 @@ describe('GET connectors', () => {
expect(res.status).toEqual(200);
const expected = getActions();
+ // The first connector returned by getActions is of type .webhook and we expect to be filtered
expected.shift();
expect(res.payload).toEqual(expected);
});
+ it('filters out connectors that are not enabled in license', async () => {
+ const req = httpServerMock.createKibanaRequest({
+ path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
+ method: 'get',
+ });
+
+ const context = await createRouteContext(
+ createMockSavedObjectsRepository({
+ caseConfigureSavedObject: mockCaseConfigure,
+ caseMappingsSavedObject: mockCaseMappings,
+ })
+ );
+
+ const actionsClient = context.actions.getActionsClient();
+ (actionsClient.listTypes as jest.Mock).mockImplementation(() =>
+ Promise.resolve([
+ {
+ id: '.servicenow',
+ name: 'ServiceNow',
+ minimumLicenseRequired: 'platinum',
+ enabled: false,
+ enabledInConfig: true,
+ // User does not have a platinum license
+ enabledInLicense: false,
+ },
+ {
+ id: '.jira',
+ name: 'Jira',
+ minimumLicenseRequired: 'gold',
+ enabled: true,
+ enabledInConfig: true,
+ enabledInLicense: true,
+ },
+ {
+ id: '.resilient',
+ name: 'IBM Resilient',
+ minimumLicenseRequired: 'platinum',
+ enabled: false,
+ enabledInConfig: true,
+ // User does not have a platinum license
+ enabledInLicense: false,
+ },
+ ])
+ );
+
+ const res = await routeHandler(context, req, kibanaResponseFactory);
+ expect(res.status).toEqual(200);
+ expect(res.payload).toEqual([
+ {
+ id: '456',
+ actionTypeId: '.jira',
+ name: 'Connector without isCaseOwned',
+ config: {
+ apiUrl: 'https://elastic.jira.com',
+ },
+ isPreconfigured: false,
+ referencedByCount: 0,
+ },
+ ]);
+ });
+
it('it throws an error when actions client is null', async () => {
const req = httpServerMock.createKibanaRequest({
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
diff --git a/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.ts b/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.ts
index cb88f04a9b835..cf854df9f04f2 100644
--- a/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.ts
+++ b/x-pack/plugins/case/server/routes/api/cases/configure/get_connectors.ts
@@ -7,6 +7,7 @@
import Boom from '@hapi/boom';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
+import { ActionType } from '../../../../../../actions/common';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FindActionResult } from '../../../../../../actions/server/types';
@@ -17,10 +18,13 @@ import {
RESILIENT_ACTION_TYPE_ID,
} from '../../../../../common/constants';
-const isConnectorSupported = (action: FindActionResult): boolean =>
+const isConnectorSupported = (
+ action: FindActionResult,
+ actionTypes: Record
+): boolean =>
[SERVICENOW_ACTION_TYPE_ID, JIRA_ACTION_TYPE_ID, RESILIENT_ACTION_TYPE_ID].includes(
action.actionTypeId
- );
+ ) && actionTypes[action.actionTypeId]?.enabledInLicense;
/*
* Be aware that this api will only return 20 connectors
@@ -40,7 +44,14 @@ export function initCaseConfigureGetActionConnector({ router }: RouteDeps) {
throw Boom.notFound('Action client have not been found');
}
- const results = (await actionsClient.getAll()).filter(isConnectorSupported);
+ const actionTypes = (await actionsClient.listTypes()).reduce(
+ (types, type) => ({ ...types, [type.id]: type }),
+ {}
+ );
+
+ const results = (await actionsClient.getAll()).filter((action) =>
+ isConnectorSupported(action, actionTypes)
+ );
return response.ok({ body: results });
} catch (error) {
return response.customError(wrapError(error));
diff --git a/x-pack/plugins/data_enhanced/common/search/test_data/search_phase_execution_exception.json b/x-pack/plugins/data_enhanced/common/search/test_data/search_phase_execution_exception.json
new file mode 100644
index 0000000000000..b79a396445e3d
--- /dev/null
+++ b/x-pack/plugins/data_enhanced/common/search/test_data/search_phase_execution_exception.json
@@ -0,0 +1,229 @@
+{
+ "error": {
+ "root_cause": [
+ {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ }
+ },
+ {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ }
+ },
+ {
+ "type": "parse_exception",
+ "reason": "failed to parse date field [2021-01-19T12:2755.047Z] with format [strict_date_optional_time]: [failed to parse date field [2021-01-19T12:2755.047Z] with format [strict_date_optional_time]]"
+ },
+ {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ }
+ },
+ {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ }
+ },
+ {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ }
+ }
+ ],
+ "type": "search_phase_execution_exception",
+ "reason": "all shards failed",
+ "phase": "query",
+ "grouped": true,
+ "failed_shards": [
+ {
+ "shard": 0,
+ "index": ".apm-agent-configuration",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ },
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "cannot resolve symbol [invalid]"
+ }
+ }
+ },
+ {
+ "shard": 0,
+ "index": ".apm-custom-link",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ },
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "cannot resolve symbol [invalid]"
+ }
+ }
+ },
+ {
+ "shard": 0,
+ "index": ".kibana-event-log-8.0.0-000001",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "parse_exception",
+ "reason": "failed to parse date field [2021-01-19T12:2755.047Z] with format [strict_date_optional_time]: [failed to parse date field [2021-01-19T12:2755.047Z] with format [strict_date_optional_time]]",
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "failed to parse date field [2021-01-19T12:2755.047Z] with format [strict_date_optional_time]",
+ "caused_by": {
+ "type": "date_time_parse_exception",
+ "reason": "Text '2021-01-19T12:2755.047Z' could not be parsed, unparsed text found at index 16"
+ }
+ }
+ }
+ },
+ {
+ "shard": 0,
+ "index": ".kibana_1",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ },
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "cannot resolve symbol [invalid]"
+ }
+ }
+ },
+ {
+ "shard": 0,
+ "index": ".kibana_task_manager_1",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ },
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "cannot resolve symbol [invalid]"
+ }
+ }
+ },
+ {
+ "shard": 0,
+ "index": ".security-7",
+ "node": "DEfMVCg5R12TRG4CYIxUgQ",
+ "reason": {
+ "type": "script_exception",
+ "reason": "compile error",
+ "script_stack": [
+ "invalid",
+ "^---- HERE"
+ ],
+ "script": "invalid",
+ "lang": "painless",
+ "position": {
+ "offset": 0,
+ "start": 0,
+ "end": 7
+ },
+ "caused_by": {
+ "type": "illegal_argument_exception",
+ "reason": "cannot resolve symbol [invalid]"
+ }
+ }
+ }
+ ]
+ },
+ "status": 400
+}
\ No newline at end of file
diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts
index 1a6fc724e2cf2..22b0f3272ff7d 100644
--- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts
+++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.test.ts
@@ -9,10 +9,16 @@ import { EnhancedSearchInterceptor } from './search_interceptor';
import { CoreSetup, CoreStart } from 'kibana/public';
import { UI_SETTINGS } from '../../../../../src/plugins/data/common';
import { AbortError } from '../../../../../src/plugins/kibana_utils/public';
-import { ISessionService, SearchTimeoutError, SearchSessionState } from 'src/plugins/data/public';
+import {
+ ISessionService,
+ SearchTimeoutError,
+ SearchSessionState,
+ PainlessError,
+} from 'src/plugins/data/public';
import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks';
import { bfetchPluginMock } from '../../../../../src/plugins/bfetch/public/mocks';
import { BehaviorSubject } from 'rxjs';
+import * as xpackResourceNotFoundException from '../../common/search/test_data/search_phase_execution_exception.json';
const timeTravel = (msToRun = 0) => {
jest.advanceTimersByTime(msToRun);
@@ -99,6 +105,33 @@ describe('EnhancedSearchInterceptor', () => {
});
});
+ describe('errors', () => {
+ test('Should throw Painless error on server error with OSS format', async () => {
+ const mockResponse: any = {
+ statusCode: 400,
+ message: 'search_phase_execution_exception',
+ attributes: xpackResourceNotFoundException.error,
+ };
+ fetchMock.mockRejectedValueOnce(mockResponse);
+ const response = searchInterceptor.search({
+ params: {},
+ });
+ await expect(response.toPromise()).rejects.toThrow(PainlessError);
+ });
+
+ test('Renders a PainlessError', async () => {
+ searchInterceptor.showError(
+ new PainlessError({
+ statusCode: 400,
+ message: 'search_phase_execution_exception',
+ attributes: xpackResourceNotFoundException.error,
+ })
+ );
+ expect(mockCoreSetup.notifications.toasts.addDanger).toBeCalledTimes(1);
+ expect(mockCoreSetup.notifications.toasts.addError).not.toBeCalled();
+ });
+ });
+
describe('search', () => {
test('should resolve immediately if first call returns full result', async () => {
const responses = [
@@ -342,7 +375,8 @@ describe('EnhancedSearchInterceptor', () => {
{
time: 10,
value: {
- error: 'oh no',
+ statusCode: 500,
+ message: 'oh no',
id: 1,
},
isError: true,
@@ -364,7 +398,8 @@ describe('EnhancedSearchInterceptor', () => {
await timeTravel(10);
expect(error).toHaveBeenCalled();
- expect(error.mock.calls[0][0]).toBe(responses[1].value);
+ expect(error.mock.calls[0][0]).toBeInstanceOf(Error);
+ expect((error.mock.calls[0][0] as Error).message).toBe('oh no');
expect(fetchMock).toHaveBeenCalledTimes(2);
expect(mockCoreSetup.http.delete).toHaveBeenCalledTimes(1);
});
diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts
index 3230895da7705..b2ddd0310f8f5 100644
--- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts
+++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.test.ts
@@ -7,6 +7,10 @@
import { enhancedEsSearchStrategyProvider } from './es_search_strategy';
import { BehaviorSubject } from 'rxjs';
import { SearchStrategyDependencies } from '../../../../../src/plugins/data/server/search';
+import { KbnServerError } from '../../../../../src/plugins/kibana_utils/server';
+import { ElasticsearchClientError, ResponseError } from '@elastic/elasticsearch/lib/errors';
+import * as indexNotFoundException from '../../../../../src/plugins/data/common/search/test_data/index_not_found_exception.json';
+import * as xContentParseException from '../../../../../src/plugins/data/common/search/test_data/x_content_parse_exception.json';
const mockAsyncResponse = {
body: {
@@ -145,6 +149,54 @@ describe('ES search strategy', () => {
expect(request).toHaveProperty('wait_for_completion_timeout');
expect(request).toHaveProperty('keep_alive');
});
+
+ it('throws normalized error if ResponseError is thrown', async () => {
+ const errResponse = new ResponseError({
+ body: indexNotFoundException,
+ statusCode: 404,
+ headers: {},
+ warnings: [],
+ meta: {} as any,
+ });
+
+ mockSubmitCaller.mockRejectedValue(errResponse);
+
+ const params = { index: 'logstash-*', body: { query: {} } };
+ const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);
+
+ let err: KbnServerError | undefined;
+ try {
+ await esSearch.search({ params }, {}, mockDeps).toPromise();
+ } catch (e) {
+ err = e;
+ }
+ expect(mockSubmitCaller).toBeCalled();
+ expect(err).toBeInstanceOf(KbnServerError);
+ expect(err?.statusCode).toBe(404);
+ expect(err?.message).toBe(errResponse.message);
+ expect(err?.errBody).toBe(indexNotFoundException);
+ });
+
+ it('throws normalized error if Error is thrown', async () => {
+ const errResponse = new Error('not good');
+
+ mockSubmitCaller.mockRejectedValue(errResponse);
+
+ const params = { index: 'logstash-*', body: { query: {} } };
+ const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);
+
+ let err: KbnServerError | undefined;
+ try {
+ await esSearch.search({ params }, {}, mockDeps).toPromise();
+ } catch (e) {
+ err = e;
+ }
+ expect(mockSubmitCaller).toBeCalled();
+ expect(err).toBeInstanceOf(KbnServerError);
+ expect(err?.statusCode).toBe(500);
+ expect(err?.message).toBe(errResponse.message);
+ expect(err?.errBody).toBe(undefined);
+ });
});
describe('cancel', () => {
@@ -160,6 +212,33 @@ describe('ES search strategy', () => {
const request = mockDeleteCaller.mock.calls[0][0];
expect(request).toEqual({ id });
});
+
+ it('throws normalized error on ResponseError', async () => {
+ const errResponse = new ResponseError({
+ body: xContentParseException,
+ statusCode: 400,
+ headers: {},
+ warnings: [],
+ meta: {} as any,
+ });
+ mockDeleteCaller.mockRejectedValue(errResponse);
+
+ const id = 'some_id';
+ const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);
+
+ let err: KbnServerError | undefined;
+ try {
+ await esSearch.cancel!(id, {}, mockDeps);
+ } catch (e) {
+ err = e;
+ }
+
+ expect(mockDeleteCaller).toBeCalled();
+ expect(err).toBeInstanceOf(KbnServerError);
+ expect(err?.statusCode).toBe(400);
+ expect(err?.message).toBe(errResponse.message);
+ expect(err?.errBody).toBe(xContentParseException);
+ });
});
describe('extend', () => {
@@ -176,5 +255,27 @@ describe('ES search strategy', () => {
const request = mockGetCaller.mock.calls[0][0];
expect(request).toEqual({ id, keep_alive: keepAlive });
});
+
+ it('throws normalized error on ElasticsearchClientError', async () => {
+ const errResponse = new ElasticsearchClientError('something is wrong with EsClient');
+ mockGetCaller.mockRejectedValue(errResponse);
+
+ const id = 'some_other_id';
+ const keepAlive = '1d';
+ const esSearch = await enhancedEsSearchStrategyProvider(mockConfig$, mockLogger);
+
+ let err: KbnServerError | undefined;
+ try {
+ await esSearch.extend!(id, keepAlive, {}, mockDeps);
+ } catch (e) {
+ err = e;
+ }
+
+ expect(mockGetCaller).toBeCalled();
+ expect(err).toBeInstanceOf(KbnServerError);
+ expect(err?.statusCode).toBe(500);
+ expect(err?.message).toBe(errResponse.message);
+ expect(err?.errBody).toBe(undefined);
+ });
});
});
diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
index 54ed59b30952a..694d9807b5a4d 100644
--- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
+++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts
@@ -6,7 +6,7 @@
import type { Observable } from 'rxjs';
import type { IScopedClusterClient, Logger, SharedGlobalConfig } from 'kibana/server';
-import { first, tap } from 'rxjs/operators';
+import { catchError, first, tap } from 'rxjs/operators';
import { SearchResponse } from 'elasticsearch';
import { from } from 'rxjs';
import type {
@@ -33,7 +33,7 @@ import {
} from './request_utils';
import { toAsyncKibanaSearchResponse } from './response_utils';
import { AsyncSearchResponse } from './types';
-import { KbnServerError } from '../../../../../src/plugins/kibana_utils/server';
+import { getKbnServerError, KbnServerError } from '../../../../../src/plugins/kibana_utils/server';
export const enhancedEsSearchStrategyProvider = (
config$: Observable,
@@ -41,7 +41,11 @@ export const enhancedEsSearchStrategyProvider = (
usage?: SearchUsage
): ISearchStrategy => {
async function cancelAsyncSearch(id: string, esClient: IScopedClusterClient) {
- await esClient.asCurrentUser.asyncSearch.delete({ id });
+ try {
+ await esClient.asCurrentUser.asyncSearch.delete({ id });
+ } catch (e) {
+ throw getKbnServerError(e);
+ }
}
function asyncSearch(
@@ -70,7 +74,10 @@ export const enhancedEsSearchStrategyProvider = (
return pollSearch(search, cancel, options).pipe(
tap((response) => (id = response.id)),
- tap(searchUsageObserver(logger, usage))
+ tap(searchUsageObserver(logger, usage)),
+ catchError((e) => {
+ throw getKbnServerError(e);
+ })
);
}
@@ -90,40 +97,72 @@ export const enhancedEsSearchStrategyProvider = (
...params,
};
- const promise = esClient.asCurrentUser.transport.request({
- method,
- path,
- body,
- querystring,
- });
+ try {
+ const promise = esClient.asCurrentUser.transport.request({
+ method,
+ path,
+ body,
+ querystring,
+ });
- const esResponse = await shimAbortSignal(promise, options?.abortSignal);
- const response = esResponse.body as SearchResponse;
- return {
- rawResponse: response,
- ...getTotalLoaded(response),
- };
+ const esResponse = await shimAbortSignal(promise, options?.abortSignal);
+ const response = esResponse.body as SearchResponse;
+ return {
+ rawResponse: response,
+ ...getTotalLoaded(response),
+ };
+ } catch (e) {
+ throw getKbnServerError(e);
+ }
}
return {
+ /**
+ * @param request
+ * @param options
+ * @param deps `SearchStrategyDependencies`
+ * @returns `Observable>`
+ * @throws `KbnServerError`
+ */
search: (request, options: IAsyncSearchOptions, deps) => {
logger.debug(`search ${JSON.stringify(request.params) || request.id}`);
+ if (request.indexType && request.indexType !== 'rollup') {
+ throw new KbnServerError('Unknown indexType', 400);
+ }
if (request.indexType === undefined) {
return asyncSearch(request, options, deps);
- } else if (request.indexType === 'rollup') {
- return from(rollupSearch(request, options, deps));
} else {
- throw new KbnServerError('Unknown indexType', 400);
+ return from(rollupSearch(request, options, deps));
}
},
+ /**
+ * @param id async search ID to cancel, as returned from _async_search API
+ * @param options
+ * @param deps `SearchStrategyDependencies`
+ * @returns `Promise`
+ * @throws `KbnServerError`
+ */
cancel: async (id, options, { esClient }) => {
logger.debug(`cancel ${id}`);
await cancelAsyncSearch(id, esClient);
},
+ /**
+ *
+ * @param id async search ID to extend, as returned from _async_search API
+ * @param keepAlive
+ * @param options
+ * @param deps `SearchStrategyDependencies`
+ * @returns `Promise`
+ * @throws `KbnServerError`
+ */
extend: async (id, keepAlive, options, { esClient }) => {
logger.debug(`extend ${id} by ${keepAlive}`);
- await esClient.asCurrentUser.asyncSearch.get({ id, keep_alive: keepAlive });
+ try {
+ await esClient.asCurrentUser.asyncSearch.get({ id, keep_alive: keepAlive });
+ } catch (e) {
+ throw getKbnServerError(e);
+ }
},
};
};
diff --git a/x-pack/plugins/data_enhanced/tsconfig.json b/x-pack/plugins/data_enhanced/tsconfig.json
index c4b09276880d9..29bfd71cb32b4 100644
--- a/x-pack/plugins/data_enhanced/tsconfig.json
+++ b/x-pack/plugins/data_enhanced/tsconfig.json
@@ -14,7 +14,8 @@
"config.ts",
"../../../typings/**/*",
// have to declare *.json explicitly due to https://github.com/microsoft/TypeScript/issues/25636
- "public/autocomplete/providers/kql_query_suggestion/__fixtures__/*.json"
+ "public/autocomplete/providers/kql_query_suggestion/__fixtures__/*.json",
+ "common/search/test_data/*.json"
],
"references": [
{ "path": "../../../src/core/tsconfig.json" },
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_layout.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_layout.tsx
index 68906e2927a0d..22847843826da 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_layout.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_layout.tsx
@@ -7,6 +7,7 @@
import React, { useEffect } from 'react';
import { useParams } from 'react-router-dom';
import { useValues, useActions } from 'kea';
+import { EuiSpacer } from '@elastic/eui';
import { KibanaLogic } from '../../../shared/kibana';
import { FlashMessages } from '../../../shared/flash_messages';
@@ -47,6 +48,7 @@ export const AnalyticsLayout: React.FC = ({
{children}
+
>
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.test.ts
index 0901ff2737803..59e33893a18eb 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.test.ts
@@ -9,13 +9,14 @@ import {
mockKibanaValues,
mockHttpValues,
mockFlashMessageHelpers,
- expectedAsyncError,
} from '../../../__mocks__';
jest.mock('../engine', () => ({
EngineLogic: { values: { engineName: 'test-engine' } },
}));
+import { nextTick } from '@kbn/test/jest';
+
import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';
import { AnalyticsLogic } from './';
@@ -29,6 +30,11 @@ describe('AnalyticsLogic', () => {
dataLoading: true,
analyticsUnavailable: false,
allTags: [],
+ recentQueries: [],
+ topQueries: [],
+ topQueriesNoResults: [],
+ topQueriesNoClicks: [],
+ topQueriesWithClicks: [],
totalQueries: 0,
totalQueriesNoResults: 0,
totalClicks: 0,
@@ -37,6 +43,7 @@ describe('AnalyticsLogic', () => {
queriesNoResultsPerDay: [],
clicksPerDay: [],
queriesPerDayForQuery: [],
+ topClicksForQuery: [],
startDate: '',
};
@@ -129,16 +136,7 @@ describe('AnalyticsLogic', () => {
expect(AnalyticsLogic.values).toEqual({
...DEFAULT_VALUES,
dataLoading: false,
- analyticsUnavailable: false,
- allTags: ['some-tag'],
- startDate: '1970-01-01',
- totalClicks: 1000,
- totalQueries: 5000,
- totalQueriesNoResults: 500,
- queriesPerDay: [10, 50, 100],
- queriesNoResultsPerDay: [1, 2, 3],
- clicksPerDay: [0, 10, 50],
- // TODO: Replace this with ...MOCK_ANALYTICS_RESPONSE once all data is set
+ ...MOCK_ANALYTICS_RESPONSE,
});
});
});
@@ -151,12 +149,7 @@ describe('AnalyticsLogic', () => {
expect(AnalyticsLogic.values).toEqual({
...DEFAULT_VALUES,
dataLoading: false,
- analyticsUnavailable: false,
- allTags: ['some-tag'],
- startDate: '1970-01-01',
- totalQueriesForQuery: 50,
- queriesPerDayForQuery: [25, 0, 25],
- // TODO: Replace this with ...MOCK_QUERY_RESPONSE once all data is set
+ ...MOCK_QUERY_RESPONSE,
});
});
});
@@ -176,13 +169,12 @@ describe('AnalyticsLogic', () => {
});
it('should make an API call and set state based on the response', async () => {
- const promise = Promise.resolve(MOCK_ANALYTICS_RESPONSE);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(MOCK_ANALYTICS_RESPONSE));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onAnalyticsDataLoad');
AnalyticsLogic.actions.loadAnalyticsData();
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/api/app_search/engines/test-engine/analytics/queries',
@@ -220,25 +212,23 @@ describe('AnalyticsLogic', () => {
});
it('calls onAnalyticsUnavailable if analyticsUnavailable is in response', async () => {
- const promise = Promise.resolve({ analyticsUnavailable: true });
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve({ analyticsUnavailable: true }));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onAnalyticsUnavailable');
AnalyticsLogic.actions.loadAnalyticsData();
- await promise;
+ await nextTick();
expect(AnalyticsLogic.actions.onAnalyticsUnavailable).toHaveBeenCalled();
});
it('handles errors', async () => {
- const promise = Promise.reject('error');
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.reject('error'));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onAnalyticsUnavailable');
AnalyticsLogic.actions.loadAnalyticsData();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('error');
expect(AnalyticsLogic.actions.onAnalyticsUnavailable).toHaveBeenCalled();
@@ -258,13 +248,12 @@ describe('AnalyticsLogic', () => {
});
it('should make an API call and set state based on the response', async () => {
- const promise = Promise.resolve(MOCK_QUERY_RESPONSE);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(MOCK_QUERY_RESPONSE));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onQueryDataLoad');
AnalyticsLogic.actions.loadQueryData('some-query');
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/api/app_search/engines/test-engine/analytics/queries/some-query',
@@ -298,25 +287,23 @@ describe('AnalyticsLogic', () => {
});
it('calls onAnalyticsUnavailable if analyticsUnavailable is in response', async () => {
- const promise = Promise.resolve({ analyticsUnavailable: true });
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve({ analyticsUnavailable: true }));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onAnalyticsUnavailable');
AnalyticsLogic.actions.loadQueryData('some-query');
- await promise;
+ await nextTick();
expect(AnalyticsLogic.actions.onAnalyticsUnavailable).toHaveBeenCalled();
});
it('handles errors', async () => {
- const promise = Promise.reject('error');
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.reject('error'));
mount();
jest.spyOn(AnalyticsLogic.actions, 'onAnalyticsUnavailable');
AnalyticsLogic.actions.loadQueryData('some-query');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('error');
expect(AnalyticsLogic.actions.onAnalyticsUnavailable).toHaveBeenCalled();
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
index 537de02a0fee5..0caf804ea2a08 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/analytics_logic.ts
@@ -62,6 +62,36 @@ export const AnalyticsLogic = kea allTags,
},
],
+ recentQueries: [
+ [],
+ {
+ onAnalyticsDataLoad: (_, { recentQueries }) => recentQueries,
+ },
+ ],
+ topQueries: [
+ [],
+ {
+ onAnalyticsDataLoad: (_, { topQueries }) => topQueries,
+ },
+ ],
+ topQueriesNoResults: [
+ [],
+ {
+ onAnalyticsDataLoad: (_, { topQueriesNoResults }) => topQueriesNoResults,
+ },
+ ],
+ topQueriesNoClicks: [
+ [],
+ {
+ onAnalyticsDataLoad: (_, { topQueriesNoClicks }) => topQueriesNoClicks,
+ },
+ ],
+ topQueriesWithClicks: [
+ [],
+ {
+ onAnalyticsDataLoad: (_, { topQueriesWithClicks }) => topQueriesWithClicks,
+ },
+ ],
totalQueries: [
0,
{
@@ -110,6 +140,12 @@ export const AnalyticsLogic = kea queriesPerDayForQuery,
},
],
+ topClicksForQuery: [
+ [],
+ {
+ onQueryDataLoad: (_, { topClicksForQuery }) => topClicksForQuery,
+ },
+ ],
startDate: [
'',
{
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.scss b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.scss
new file mode 100644
index 0000000000000..f3c503d4b27cb
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.scss
@@ -0,0 +1,14 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+.analyticsHeader {
+ flex-wrap: wrap;
+
+ &__filters.euiPageHeaderSection {
+ width: 100%;
+ margin: $euiSizeM 0;
+ }
+}
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.tsx
index 6866a89687a74..e82c3aff70119 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_header.tsx
@@ -30,6 +30,8 @@ import { AnalyticsLogic } from '../';
import { DEFAULT_START_DATE, DEFAULT_END_DATE, SERVER_DATE_FORMAT } from '../constants';
import { convertTagsToSelectOptions } from '../utils';
+import './analytics_header.scss';
+
interface Props {
title: string;
}
@@ -60,7 +62,7 @@ export const AnalyticsHeader: React.FC = ({ title }) => {
const hasInvalidDateRange = startDate > endDate;
return (
-
+
@@ -69,13 +71,13 @@ export const AnalyticsHeader: React.FC = ({ title }) => {
-
+
-
+
-
+
= ({ title }) => {
fullWidth
/>
-
+
{
+ const { navigateToUrl } = mockKibanaValues;
+ const preventDefault = jest.fn();
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ const wrapper = shallow();
+ const setSearchValue = (value: string) =>
+ wrapper.find(EuiFieldSearch).simulate('change', { target: { value } });
+
+ it('renders', () => {
+ expect(wrapper.find(EuiFieldSearch)).toHaveLength(1);
+ });
+
+ it('updates searchValue state on input change', () => {
+ expect(wrapper.find(EuiFieldSearch).prop('value')).toEqual('');
+
+ setSearchValue('some-query');
+ expect(wrapper.find(EuiFieldSearch).prop('value')).toEqual('some-query');
+ });
+
+ it('sends the user to the query detail page on search', () => {
+ wrapper.find('form').simulate('submit', { preventDefault });
+
+ expect(preventDefault).toHaveBeenCalled();
+ expect(navigateToUrl).toHaveBeenCalledWith(
+ '/engines/some-engine/analytics/query_detail/some-query'
+ );
+ });
+
+ it('falls back to showing the "" query if searchValue is empty', () => {
+ setSearchValue('');
+ wrapper.find('form').simulate('submit', { preventDefault });
+
+ expect(navigateToUrl).toHaveBeenCalledWith(
+ '/engines/some-engine/analytics/query_detail/%22%22' // "" gets encoded
+ );
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_search.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_search.tsx
new file mode 100644
index 0000000000000..fc2639d87a2f9
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_search.tsx
@@ -0,0 +1,53 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useState } from 'react';
+import { useValues } from 'kea';
+
+import { i18n } from '@kbn/i18n';
+import { EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiButton, EuiSpacer } from '@elastic/eui';
+
+import { KibanaLogic } from '../../../../shared/kibana';
+import { ENGINE_ANALYTICS_QUERY_DETAIL_PATH } from '../../../routes';
+import { generateEnginePath } from '../../engine';
+
+export const AnalyticsSearch: React.FC = () => {
+ const [searchValue, setSearchValue] = useState('');
+
+ const { navigateToUrl } = useValues(KibanaLogic);
+ const viewQueryDetails = (e: React.SyntheticEvent) => {
+ e.preventDefault();
+ const query = searchValue || '""';
+ navigateToUrl(generateEnginePath(ENGINE_ANALYTICS_QUERY_DETAIL_PATH, { query }));
+ };
+
+ return (
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.test.tsx
new file mode 100644
index 0000000000000..1814aba7497f6
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.test.tsx
@@ -0,0 +1,24 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { AnalyticsSection } from './';
+
+describe('AnalyticsSection', () => {
+ it('renders', () => {
+ const wrapper = shallow(
+
+ Test
+
+ );
+
+ expect(wrapper.find('h2').text()).toEqual('Lorem ipsum');
+ expect(wrapper.find('p').text()).toEqual('Dolor sit amet.');
+ expect(wrapper.find('[data-test-subj="HelloWorld"]')).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.tsx
new file mode 100644
index 0000000000000..e14ef0b1f2631
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_section.tsx
@@ -0,0 +1,28 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import { EuiPageContentBody, EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';
+
+interface Props {
+ title: string;
+ subtitle: string;
+}
+export const AnalyticsSection: React.FC = ({ title, subtitle, children }) => (
+
+
+
+ {title}
+
+
+ {subtitle}
+
+
+
+ {children}
+
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.test.tsx
new file mode 100644
index 0000000000000..88f7e858bef62
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.test.tsx
@@ -0,0 +1,90 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { mountWithIntl, mockKibanaValues } from '../../../../../__mocks__';
+import '../../../../__mocks__/engine_logic.mock';
+
+import React from 'react';
+import { EuiBasicTable, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';
+
+import { AnalyticsTable } from './';
+
+describe('AnalyticsTable', () => {
+ const { navigateToUrl } = mockKibanaValues;
+
+ const items = [
+ {
+ key: 'some search',
+ tags: ['tagA'],
+ searches: { doc_count: 100 },
+ clicks: { doc_count: 10 },
+ },
+ {
+ key: 'another search',
+ tags: ['tagB'],
+ searches: { doc_count: 99 },
+ clicks: { doc_count: 9 },
+ },
+ {
+ key: '',
+ tags: ['tagA', 'tagB'],
+ searches: { doc_count: 1 },
+ clicks: { doc_count: 0 },
+ },
+ ];
+
+ it('renders', () => {
+ const wrapper = mountWithIntl();
+ const tableContent = wrapper.find(EuiBasicTable).text();
+
+ expect(tableContent).toContain('Search term');
+ expect(tableContent).toContain('some search');
+ expect(tableContent).toContain('another search');
+ expect(tableContent).toContain('""');
+
+ expect(tableContent).toContain('Analytics tags');
+ expect(tableContent).toContain('tagA');
+ expect(tableContent).toContain('tagB');
+ expect(wrapper.find(EuiBadge)).toHaveLength(4);
+
+ expect(tableContent).toContain('Queries');
+ expect(tableContent).toContain('100');
+ expect(tableContent).toContain('99');
+ expect(tableContent).toContain('1');
+ expect(tableContent).not.toContain('Clicks');
+ });
+
+ it('renders a clicks column if hasClicks is passed', () => {
+ const wrapper = mountWithIntl();
+ const tableContent = wrapper.find(EuiBasicTable).text();
+
+ expect(tableContent).toContain('Clicks');
+ expect(tableContent).toContain('10');
+ expect(tableContent).toContain('9');
+ expect(tableContent).toContain('0');
+ });
+
+ it('renders an action column', () => {
+ const wrapper = mountWithIntl();
+ const viewQuery = wrapper.find('[data-test-subj="AnalyticsTableViewQueryButton"]').first();
+ const editQuery = wrapper.find('[data-test-subj="AnalyticsTableEditQueryButton"]').first();
+
+ viewQuery.simulate('click');
+ expect(navigateToUrl).toHaveBeenCalledWith(
+ '/engines/some-engine/analytics/query_detail/some%20search'
+ );
+
+ editQuery.simulate('click');
+ // TODO
+ });
+
+ it('renders an empty prompt if no items are passed', () => {
+ const wrapper = mountWithIntl();
+ const promptContent = wrapper.find(EuiEmptyPrompt).text();
+
+ expect(promptContent).toContain('No queries were performed during this time period.');
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.tsx
new file mode 100644
index 0000000000000..41690dfe26e71
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/analytics_table.tsx
@@ -0,0 +1,76 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { i18n } from '@kbn/i18n';
+import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
+
+import { Query } from '../../types';
+import {
+ TERM_COLUMN_PROPS,
+ TAGS_COLUMN,
+ COUNT_COLUMN_PROPS,
+ ACTIONS_COLUMN,
+} from './shared_columns';
+
+interface Props {
+ items: Query[];
+ hasClicks?: boolean;
+}
+type Columns = Array>;
+
+export const AnalyticsTable: React.FC = ({ items, hasClicks }) => {
+ const TERM_COLUMN = {
+ field: 'key',
+ ...TERM_COLUMN_PROPS,
+ };
+
+ const COUNT_COLUMNS = [
+ {
+ field: 'searches.doc_count',
+ name: i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.queriesColumn',
+ { defaultMessage: 'Queries' }
+ ),
+ ...COUNT_COLUMN_PROPS,
+ },
+ ];
+ if (hasClicks) {
+ COUNT_COLUMNS.push({
+ field: 'clicks.doc_count',
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.clicksColumn', {
+ defaultMessage: 'Clicks',
+ }),
+ ...COUNT_COLUMN_PROPS,
+ });
+ }
+
+ return (
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noQueriesTitle',
+ { defaultMessage: 'No queries' }
+ )}
+
+ }
+ body={i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noQueriesDescription',
+ { defaultMessage: 'No queries were performed during this time period.' }
+ )}
+ />
+ }
+ />
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/index.ts
new file mode 100644
index 0000000000000..99363c00caaf7
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/index.ts
@@ -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;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { AnalyticsTable } from './analytics_table';
+export { RecentQueriesTable } from './recent_queries_table';
+export { QueryClicksTable } from './query_clicks_table';
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.test.tsx
new file mode 100644
index 0000000000000..5909ceec4555c
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.test.tsx
@@ -0,0 +1,38 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiBadge, EuiToolTip } from '@elastic/eui';
+
+import { InlineTagsList } from './inline_tags_list';
+
+describe('InlineTagsList', () => {
+ it('renders', () => {
+ const wrapper = shallow();
+
+ expect(wrapper.find(EuiBadge)).toHaveLength(1);
+ expect(wrapper.find(EuiBadge).prop('children')).toEqual('test');
+ });
+
+ it('renders >2 badges in a tooltip list', () => {
+ const wrapper = shallow();
+
+ expect(wrapper.find(EuiBadge)).toHaveLength(3);
+ expect(wrapper.find(EuiToolTip)).toHaveLength(1);
+
+ expect(wrapper.find(EuiBadge).at(0).prop('children')).toEqual('1');
+ expect(wrapper.find(EuiBadge).at(1).prop('children')).toEqual('2');
+ expect(wrapper.find(EuiBadge).at(2).prop('children')).toEqual('and 3 more');
+ expect(wrapper.find(EuiToolTip).prop('content')).toEqual('3, 4, 5');
+ });
+
+ it('does not render with no tags', () => {
+ const wrapper = shallow();
+
+ expect(wrapper.isEmptyRender()).toBe(true);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.tsx
new file mode 100644
index 0000000000000..853f04ee1aa77
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/inline_tags_list.tsx
@@ -0,0 +1,44 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { i18n } from '@kbn/i18n';
+import { EuiBadgeGroup, EuiBadge, EuiToolTip } from '@elastic/eui';
+
+import { Query } from '../../types';
+
+interface Props {
+ tags?: Query['tags'];
+}
+export const InlineTagsList: React.FC = ({ tags }) => {
+ if (!tags?.length) return null;
+
+ const displayedTags = tags.slice(0, 2);
+ const tooltipTags = tags.slice(2);
+
+ return (
+
+ {displayedTags.map((tag: string) => (
+
+ {tag}
+
+ ))}
+ {tooltipTags.length > 0 && (
+
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.moreTagsBadge',
+ {
+ defaultMessage: 'and {moreTagsCount} more',
+ values: { moreTagsCount: tooltipTags.length },
+ }
+ )}
+
+
+ )}
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.test.tsx
new file mode 100644
index 0000000000000..9db9c140d7f50
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.test.tsx
@@ -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;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { mountWithIntl } from '../../../../../__mocks__';
+import '../../../../__mocks__/engine_logic.mock';
+
+import React from 'react';
+import { EuiBasicTable, EuiLink, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';
+
+import { QueryClicksTable } from './';
+
+describe('QueryClicksTable', () => {
+ const items = [
+ {
+ key: 'some-document',
+ document: {
+ engine: 'some-engine',
+ id: 'some-document',
+ },
+ tags: ['tagA'],
+ doc_count: 10,
+ },
+ {
+ key: 'another-document',
+ document: {
+ engine: 'another-engine',
+ id: 'another-document',
+ },
+ tags: ['tagB'],
+ doc_count: 5,
+ },
+ {
+ key: 'deleted-document',
+ tags: [],
+ doc_count: 1,
+ },
+ ];
+
+ it('renders', () => {
+ const wrapper = mountWithIntl();
+ const tableContent = wrapper.find(EuiBasicTable).text();
+
+ expect(tableContent).toContain('Documents');
+ expect(tableContent).toContain('some-document');
+ expect(tableContent).toContain('another-document');
+ expect(tableContent).toContain('deleted-document');
+
+ expect(wrapper.find(EuiLink).first().prop('href')).toEqual(
+ '/app/enterprise_search/engines/some-engine/documents/some-document'
+ );
+ expect(wrapper.find(EuiLink).last().prop('href')).toEqual(
+ '/app/enterprise_search/engines/another-engine/documents/another-document'
+ );
+ // deleted-document should not have a link
+
+ expect(tableContent).toContain('Analytics tags');
+ expect(tableContent).toContain('tagA');
+ expect(tableContent).toContain('tagB');
+ expect(wrapper.find(EuiBadge)).toHaveLength(2);
+
+ expect(tableContent).toContain('Clicks');
+ expect(tableContent).toContain('10');
+ expect(tableContent).toContain('5');
+ expect(tableContent).toContain('1');
+ });
+
+ it('renders an empty prompt if no items are passed', () => {
+ const wrapper = mountWithIntl();
+ const promptContent = wrapper.find(EuiEmptyPrompt).text();
+
+ expect(promptContent).toContain('No clicks');
+ expect(promptContent).toContain('No documents have been clicked from this query.');
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.tsx
new file mode 100644
index 0000000000000..e032e42eca3a6
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/query_clicks_table.tsx
@@ -0,0 +1,78 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import { i18n } from '@kbn/i18n';
+import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
+
+import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
+import { ENGINE_DOCUMENT_DETAIL_PATH } from '../../../../routes';
+import { generateEnginePath } from '../../../engine';
+import { DOCUMENTS_TITLE } from '../../../documents';
+
+import { QueryClick } from '../../types';
+import { FIRST_COLUMN_PROPS, TAGS_COLUMN, COUNT_COLUMN_PROPS } from './shared_columns';
+
+interface Props {
+ items: QueryClick[];
+}
+type Columns = Array>;
+
+export const QueryClicksTable: React.FC = ({ items }) => {
+ const DOCUMENT_COLUMN = {
+ ...FIRST_COLUMN_PROPS,
+ field: 'document',
+ name: DOCUMENTS_TITLE,
+ render: (document: QueryClick['document'], query: QueryClick) => {
+ return document ? (
+
+ {document.id}
+
+ ) : (
+ query.key
+ );
+ },
+ };
+
+ const CLICKS_COLUMN = {
+ ...COUNT_COLUMN_PROPS,
+ field: 'doc_count',
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.clicksColumn', {
+ defaultMessage: 'Clicks',
+ }),
+ };
+
+ return (
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noClicksTitle',
+ { defaultMessage: 'No clicks' }
+ )}
+
+ }
+ body={i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noClicksDescription',
+ { defaultMessage: 'No documents have been clicked from this query.' }
+ )}
+ />
+ }
+ />
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.test.tsx
new file mode 100644
index 0000000000000..261d0f75c1cee
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.test.tsx
@@ -0,0 +1,85 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { mountWithIntl, mockKibanaValues } from '../../../../../__mocks__';
+import '../../../../__mocks__/engine_logic.mock';
+
+import React from 'react';
+import { EuiBasicTable, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';
+
+import { RecentQueriesTable } from './';
+
+describe('RecentQueriesTable', () => {
+ const { navigateToUrl } = mockKibanaValues;
+
+ const items = [
+ {
+ query_string: 'some search',
+ timestamp: '1970-01-03T12:00:00Z',
+ tags: ['tagA'],
+ document_ids: ['documentA', 'documentB'],
+ },
+ {
+ query_string: 'another search',
+ timestamp: '1970-01-02T12:00:00Z',
+ tags: ['tagB'],
+ document_ids: ['documentC'],
+ },
+ {
+ query_string: '',
+ timestamp: '1970-01-01T12:00:00Z',
+ tags: ['tagA', 'tagB'],
+ document_ids: ['documentA', 'documentB', 'documentC'],
+ },
+ ];
+
+ it('renders', () => {
+ const wrapper = mountWithIntl();
+ const tableContent = wrapper.find(EuiBasicTable).text();
+
+ expect(tableContent).toContain('Search term');
+ expect(tableContent).toContain('some search');
+ expect(tableContent).toContain('another search');
+ expect(tableContent).toContain('""');
+
+ expect(tableContent).toContain('Time');
+ expect(tableContent).toContain('1/3/1970');
+ expect(tableContent).toContain('1/2/1970');
+ expect(tableContent).toContain('1/1/1970');
+
+ expect(tableContent).toContain('Analytics tags');
+ expect(tableContent).toContain('tagA');
+ expect(tableContent).toContain('tagB');
+ expect(wrapper.find(EuiBadge)).toHaveLength(4);
+
+ expect(tableContent).toContain('Results');
+ expect(tableContent).toContain('2');
+ expect(tableContent).toContain('1');
+ expect(tableContent).toContain('3');
+ });
+
+ it('renders an action column', () => {
+ const wrapper = mountWithIntl();
+ const viewQuery = wrapper.find('[data-test-subj="AnalyticsTableViewQueryButton"]').first();
+ const editQuery = wrapper.find('[data-test-subj="AnalyticsTableEditQueryButton"]').first();
+
+ viewQuery.simulate('click');
+ expect(navigateToUrl).toHaveBeenCalledWith(
+ '/engines/some-engine/analytics/query_detail/some%20search'
+ );
+
+ editQuery.simulate('click');
+ // TODO
+ });
+
+ it('renders an empty prompt if no items are passed', () => {
+ const wrapper = mountWithIntl();
+ const promptContent = wrapper.find(EuiEmptyPrompt).text();
+
+ expect(promptContent).toContain('No recent queries');
+ expect(promptContent).toContain('Queries will appear here as they are received.');
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.tsx
new file mode 100644
index 0000000000000..b0dc8254c084b
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/recent_queries_table.tsx
@@ -0,0 +1,82 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import { i18n } from '@kbn/i18n';
+import { FormattedDate, FormattedTime } from '@kbn/i18n/react';
+import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
+
+import { RecentQuery } from '../../types';
+import {
+ TERM_COLUMN_PROPS,
+ TAGS_COLUMN,
+ COUNT_COLUMN_PROPS,
+ ACTIONS_COLUMN,
+} from './shared_columns';
+
+interface Props {
+ items: RecentQuery[];
+}
+type Columns = Array>;
+
+export const RecentQueriesTable: React.FC = ({ items }) => {
+ const TERM_COLUMN = {
+ ...TERM_COLUMN_PROPS,
+ field: 'query_string',
+ };
+
+ const TIME_COLUMN = {
+ field: 'timestamp',
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.timeColumn', {
+ defaultMessage: 'Time',
+ }),
+ render: (timestamp: RecentQuery['timestamp']) => {
+ const date = new Date(timestamp);
+ return (
+ <>
+
+ >
+ );
+ },
+ width: '175px',
+ };
+
+ const RESULTS_COLUMN = {
+ ...COUNT_COLUMN_PROPS,
+ field: 'document_ids',
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.resultsColumn', {
+ defaultMessage: 'Results',
+ }),
+ render: (documents: RecentQuery['document_ids']) => documents.length,
+ };
+
+ return (
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noRecentQueriesTitle',
+ { defaultMessage: 'No recent queries' }
+ )}
+
+ }
+ body={i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.empty.noRecentQueriesDescription',
+ { defaultMessage: 'Queries will appear here as they are received.' }
+ )}
+ />
+ }
+ />
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx
new file mode 100644
index 0000000000000..16743405e0b5e
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/analytics_tables/shared_columns.tsx
@@ -0,0 +1,99 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { i18n } from '@kbn/i18n';
+
+import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
+import { KibanaLogic } from '../../../../../shared/kibana';
+import { ENGINE_ANALYTICS_QUERY_DETAIL_PATH } from '../../../../routes';
+import { generateEnginePath } from '../../../engine';
+
+import { Query, RecentQuery } from '../../types';
+import { InlineTagsList } from './inline_tags_list';
+
+/**
+ * Shared columns / column properties between separate analytics tables
+ */
+
+export const FIRST_COLUMN_PROPS = {
+ truncateText: true,
+ width: '25%',
+ mobileOptions: {
+ enlarge: true,
+ width: '100%',
+ },
+};
+
+export const TERM_COLUMN_PROPS = {
+ // Field key changes per-table
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.termColumn', {
+ defaultMessage: 'Search term',
+ }),
+ render: (query: Query['key']) => {
+ if (!query) query = '""';
+ return (
+
+ {query}
+
+ );
+ },
+ ...FIRST_COLUMN_PROPS,
+};
+
+export const ACTIONS_COLUMN = {
+ width: '120px',
+ actions: [
+ {
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.viewAction', {
+ defaultMessage: 'View',
+ }),
+ description: i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.viewTooltip',
+ { defaultMessage: 'View query analytics' }
+ ),
+ type: 'icon',
+ icon: 'popout',
+ color: 'primary',
+ onClick: (item: Query | RecentQuery) => {
+ const { navigateToUrl } = KibanaLogic.values;
+
+ const query = (item as Query).key || (item as RecentQuery).query_string;
+ navigateToUrl(generateEnginePath(ENGINE_ANALYTICS_QUERY_DETAIL_PATH, { query }));
+ },
+ 'data-test-subj': 'AnalyticsTableViewQueryButton',
+ },
+ {
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.editAction', {
+ defaultMessage: 'Edit',
+ }),
+ description: i18n.translate(
+ 'xpack.enterpriseSearch.appSearch.engine.analytics.table.editTooltip',
+ { defaultMessage: 'Edit query analytics' }
+ ),
+ type: 'icon',
+ icon: 'pencil',
+ onClick: () => {
+ // TODO: CurationsLogic
+ },
+ 'data-test-subj': 'AnalyticsTableEditQueryButton',
+ },
+ ],
+};
+
+export const TAGS_COLUMN = {
+ field: 'tags',
+ name: i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.tagsColumn', {
+ defaultMessage: 'Analytics tags',
+ }),
+ truncateText: true,
+ render: (tags: Query['tags']) => ,
+};
+
+export const COUNT_COLUMN_PROPS = {
+ dataType: 'number',
+ width: '100px',
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/index.ts
index ae9c9ca450638..ddad726b04c26 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/index.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/components/index.ts
@@ -7,4 +7,7 @@
export { AnalyticsCards } from './analytics_cards';
export { AnalyticsChart } from './analytics_chart';
export { AnalyticsHeader } from './analytics_header';
+export { AnalyticsSection } from './analytics_section';
+export { AnalyticsSearch } from './analytics_search';
+export { AnalyticsTable, RecentQueriesTable, QueryClicksTable } from './analytics_tables';
export { AnalyticsUnavailable } from './analytics_unavailable';
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/types.ts
index a3977a0c07a80..8bee8fd4407b7 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/types.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/types.ts
@@ -4,27 +4,25 @@
* you may not use this file except in compliance with the Elastic License.
*/
-interface Query {
- doc_count: number;
+export interface Query {
key: string;
- clicks?: { doc_count: number };
- searches?: { doc_count: number };
tags?: string[];
+ searches?: { doc_count: number };
+ clicks?: { doc_count: number };
}
-interface QueryClick extends Query {
+export interface QueryClick extends Query {
document?: {
id: string;
engine: string;
- tags?: string[];
};
}
-interface RecentQuery {
- document_ids: string[];
+export interface RecentQuery {
query_string: string;
- tags: string[];
timestamp: string;
+ tags: string[];
+ document_ids: string[];
}
/**
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.test.tsx
index 06bf77d35372f..e5bff981cb000 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.test.tsx
@@ -5,12 +5,19 @@
*/
import { setMockValues } from '../../../../__mocks__';
+import '../../../__mocks__/engine_logic.mock';
import React from 'react';
import { shallow } from 'enzyme';
-import { AnalyticsCards, AnalyticsChart } from '../components';
-import { Analytics } from './';
+import {
+ AnalyticsCards,
+ AnalyticsChart,
+ AnalyticsSection,
+ AnalyticsTable,
+ RecentQueriesTable,
+} from '../components';
+import { Analytics, ViewAllButton } from './analytics';
describe('Analytics overview', () => {
it('renders', () => {
@@ -22,10 +29,27 @@ describe('Analytics overview', () => {
queriesNoResultsPerDay: [1, 2, 3],
clicksPerDay: [0, 1, 5],
startDate: '1970-01-01',
+ topQueries: [],
+ topQueriesNoResults: [],
+ topQueriesNoClicks: [],
+ topQueriesWithClicks: [],
+ recentQueries: [],
});
const wrapper = shallow();
expect(wrapper.find(AnalyticsCards)).toHaveLength(1);
expect(wrapper.find(AnalyticsChart)).toHaveLength(1);
+ expect(wrapper.find(AnalyticsSection)).toHaveLength(3);
+ expect(wrapper.find(AnalyticsTable)).toHaveLength(4);
+ expect(wrapper.find(RecentQueriesTable)).toHaveLength(1);
+ });
+
+ describe('ViewAllButton', () => {
+ it('renders', () => {
+ const to = '/analytics/top_queries';
+ const wrapper = shallow();
+
+ expect(wrapper.prop('to')).toEqual(to);
+ });
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.tsx
index d3c3bff5a2947..e6a3e1ca5809b 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/analytics.tsx
@@ -7,15 +7,32 @@
import React from 'react';
import { useValues } from 'kea';
-import { EuiSpacer } from '@elastic/eui';
+import { i18n } from '@kbn/i18n';
+import { EuiSpacer, EuiTitle } from '@elastic/eui';
+
+import { EuiButtonTo } from '../../../../shared/react_router_helpers';
+import {
+ ENGINE_ANALYTICS_TOP_QUERIES_PATH,
+ ENGINE_ANALYTICS_TOP_QUERIES_NO_RESULTS_PATH,
+ ENGINE_ANALYTICS_TOP_QUERIES_NO_CLICKS_PATH,
+ ENGINE_ANALYTICS_TOP_QUERIES_WITH_CLICKS_PATH,
+ ENGINE_ANALYTICS_RECENT_QUERIES_PATH,
+} from '../../../routes';
+import { generateEnginePath } from '../../engine';
import {
ANALYTICS_TITLE,
TOTAL_QUERIES,
TOTAL_QUERIES_NO_RESULTS,
TOTAL_CLICKS,
+ TOP_QUERIES,
+ TOP_QUERIES_NO_RESULTS,
+ TOP_QUERIES_WITH_CLICKS,
+ TOP_QUERIES_NO_CLICKS,
+ RECENT_QUERIES,
} from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSection, AnalyticsTable, RecentQueriesTable } from '../components';
import { AnalyticsLogic, AnalyticsCards, AnalyticsChart, convertToChartData } from '../';
export const Analytics: React.FC = () => {
@@ -27,6 +44,11 @@ export const Analytics: React.FC = () => {
queriesNoResultsPerDay,
clicksPerDay,
startDate,
+ topQueries,
+ topQueriesNoResults,
+ topQueriesWithClicks,
+ topQueriesNoClicks,
+ recentQueries,
} = useValues(AnalyticsLogic);
return (
@@ -72,7 +94,77 @@ export const Analytics: React.FC = () => {
/>
- TODO: Analytics overview
+
+
+ {TOP_QUERIES}
+
+
+
+
+
+ {TOP_QUERIES_NO_RESULTS}
+
+
+
+
+
+
+
+
+ {TOP_QUERIES_WITH_CLICKS}
+
+
+
+
+
+ {TOP_QUERIES_NO_CLICKS}
+
+
+
+
+
+
+
+
+
+
);
};
+
+export const ViewAllButton: React.FC<{ to: string }> = ({ to }) => (
+
+ {i18n.translate('xpack.enterpriseSearch.appSearch.engine.analytics.table.viewAllButtonLabel', {
+ defaultMessage: 'View all',
+ })}
+
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.test.tsx
index 99485340f6b88..7705d342ecdce 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.test.tsx
@@ -13,7 +13,7 @@ import { shallow } from 'enzyme';
import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome';
-import { AnalyticsCards, AnalyticsChart } from '../components';
+import { AnalyticsCards, AnalyticsChart, QueryClicksTable } from '../components';
import { QueryDetail } from './';
describe('QueryDetail', () => {
@@ -41,5 +41,6 @@ describe('QueryDetail', () => {
expect(wrapper.find(AnalyticsCards)).toHaveLength(1);
expect(wrapper.find(AnalyticsChart)).toHaveLength(1);
+ expect(wrapper.find(QueryClicksTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.tsx
index 53c1dc8b845b1..d5d864f35f681 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/query_detail.tsx
@@ -15,6 +15,7 @@ import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_c
import { BreadcrumbTrail } from '../../../../shared/kibana_chrome/generate_breadcrumbs';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSection, QueryClicksTable } from '../components';
import { AnalyticsLogic, AnalyticsCards, AnalyticsChart, convertToChartData } from '../';
const QUERY_DETAIL_TITLE = i18n.translate(
@@ -28,7 +29,9 @@ interface Props {
export const QueryDetail: React.FC = ({ breadcrumbs }) => {
const { query } = useParams() as { query: string };
- const { totalQueriesForQuery, queriesPerDayForQuery, startDate } = useValues(AnalyticsLogic);
+ const { totalQueriesForQuery, queriesPerDayForQuery, startDate, topClicksForQuery } = useValues(
+ AnalyticsLogic
+ );
return (
@@ -63,7 +66,18 @@ export const QueryDetail: React.FC = ({ breadcrumbs }) => {
/>
- TODO: Query detail page
+
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.test.tsx
index f25b044e8a56f..efd2de9223c98 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.test.tsx
@@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { setMockValues } from '../../../../__mocks__';
+
import React from 'react';
import { shallow } from 'enzyme';
+import { RecentQueriesTable } from '../components';
import { RecentQueries } from './';
describe('RecentQueries', () => {
it('renders', () => {
+ setMockValues({ recentQueries: [] });
const wrapper = shallow();
- expect(wrapper.isEmptyRender()).toBe(false); // TODO
+ expect(wrapper.find(RecentQueriesTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.tsx
index 3510a2a0e8221..708863ba0e5c8 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/recent_queries.tsx
@@ -5,14 +5,20 @@
*/
import React from 'react';
+import { useValues } from 'kea';
import { RECENT_QUERIES } from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSearch, RecentQueriesTable } from '../components';
+import { AnalyticsLogic } from '../';
export const RecentQueries: React.FC = () => {
+ const { recentQueries } = useValues(AnalyticsLogic);
+
return (
- TODO: Recent queries
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.test.tsx
index 9747609aaf066..754a349c2fe94 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.test.tsx
@@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { setMockValues } from '../../../../__mocks__';
+
import React from 'react';
import { shallow } from 'enzyme';
+import { AnalyticsTable } from '../components';
import { TopQueries } from './';
describe('TopQueries', () => {
it('renders', () => {
+ setMockValues({ topQueries: [] });
const wrapper = shallow();
- expect(wrapper.isEmptyRender()).toBe(false); // TODO
+ expect(wrapper.find(AnalyticsTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.tsx
index 3f2867871765c..0814ba16e39dc 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries.tsx
@@ -5,14 +5,20 @@
*/
import React from 'react';
+import { useValues } from 'kea';
import { TOP_QUERIES } from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSearch, AnalyticsTable } from '../components';
+import { AnalyticsLogic } from '../';
export const TopQueries: React.FC = () => {
+ const { topQueries } = useValues(AnalyticsLogic);
+
return (
- TODO: Top queries
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.test.tsx
index bc55753acf152..f1eb3a2f69a98 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.test.tsx
@@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { setMockValues } from '../../../../__mocks__';
+
import React from 'react';
import { shallow } from 'enzyme';
+import { AnalyticsTable } from '../components';
import { TopQueriesNoClicks } from './';
describe('TopQueriesNoClicks', () => {
it('renders', () => {
+ setMockValues({ topQueriesNoClicks: [] });
const wrapper = shallow();
- expect(wrapper.isEmptyRender()).toBe(false); // TODO
+ expect(wrapper.find(AnalyticsTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.tsx
index dc14c4a83bff3..283a790b61571 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_clicks.tsx
@@ -5,14 +5,20 @@
*/
import React from 'react';
+import { useValues } from 'kea';
import { TOP_QUERIES_NO_CLICKS } from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSearch, AnalyticsTable } from '../components';
+import { AnalyticsLogic } from '../';
export const TopQueriesNoClicks: React.FC = () => {
+ const { topQueriesNoClicks } = useValues(AnalyticsLogic);
+
return (
- TODO: Top queries with no clicks
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.test.tsx
index 72c718f374714..8e404e34b5f3e 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.test.tsx
@@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { setMockValues } from '../../../../__mocks__';
+
import React from 'react';
import { shallow } from 'enzyme';
+import { AnalyticsTable } from '../components';
import { TopQueriesNoResults } from './';
describe('TopQueriesNoResults', () => {
it('renders', () => {
+ setMockValues({ topQueriesNoResults: [] });
const wrapper = shallow();
- expect(wrapper.isEmptyRender()).toBe(false); // TODO
+ expect(wrapper.find(AnalyticsTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.tsx
index da8595b43859f..8a54d529b2dd0 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_no_results.tsx
@@ -5,14 +5,20 @@
*/
import React from 'react';
+import { useValues } from 'kea';
import { TOP_QUERIES_NO_RESULTS } from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSearch, AnalyticsTable } from '../components';
+import { AnalyticsLogic } from '../';
export const TopQueriesNoResults: React.FC = () => {
+ const { topQueriesNoResults } = useValues(AnalyticsLogic);
+
return (
- TODO: Top queries with no results
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.test.tsx
index 74e31e77974ee..714da0d8e45dd 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.test.tsx
@@ -4,15 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { setMockValues } from '../../../../__mocks__';
+
import React from 'react';
import { shallow } from 'enzyme';
+import { AnalyticsTable } from '../components';
import { TopQueriesWithClicks } from './';
describe('TopQueriesWithClicks', () => {
it('renders', () => {
+ setMockValues({ topQueriesWithClicks: [] });
const wrapper = shallow();
- expect(wrapper.isEmptyRender()).toBe(false); // TODO
+ expect(wrapper.find(AnalyticsTable)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.tsx
index dc6e837be61d8..73ad9e2e973d8 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/analytics/views/top_queries_with_clicks.tsx
@@ -5,14 +5,20 @@
*/
import React from 'react';
+import { useValues } from 'kea';
import { TOP_QUERIES_WITH_CLICKS } from '../constants';
import { AnalyticsLayout } from '../analytics_layout';
+import { AnalyticsSearch, AnalyticsTable } from '../components';
+import { AnalyticsLogic } from '../';
export const TopQueriesWithClicks: React.FC = () => {
+ const { topQueriesWithClicks } = useValues(AnalyticsLogic);
+
return (
- TODO: Top queries with clicks
+
+
);
};
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.test.ts
index cdd055fd367ef..2374bcb1b2d03 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_logic.test.ts
@@ -4,12 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../../__mocks__';
+import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__';
jest.mock('../../app_logic', () => ({
AppLogic: {
@@ -17,9 +12,12 @@ jest.mock('../../app_logic', () => ({
values: { myRole: jest.fn(() => ({})) },
},
}));
-import { AppLogic } from '../../app_logic';
+import { nextTick } from '@kbn/test/jest';
+
+import { AppLogic } from '../../app_logic';
import { ApiTokenTypes } from './constants';
+
import { CredentialsLogic } from './credentials_logic';
describe('CredentialsLogic', () => {
@@ -1064,8 +1062,7 @@ describe('CredentialsLogic', () => {
it('will call an API endpoint and set the results with the `setCredentialsData` action', async () => {
mount();
jest.spyOn(CredentialsLogic.actions, 'setCredentialsData').mockImplementationOnce(() => {});
- const promise = Promise.resolve({ meta, results });
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve({ meta, results }));
CredentialsLogic.actions.fetchCredentials(2);
expect(http.get).toHaveBeenCalledWith('/api/app_search/credentials', {
@@ -1073,17 +1070,16 @@ describe('CredentialsLogic', () => {
'page[current]': 2,
},
});
- await promise;
+ await nextTick();
expect(CredentialsLogic.actions.setCredentialsData).toHaveBeenCalledWith(meta, results);
});
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occured');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occured'));
CredentialsLogic.actions.fetchCredentials();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
@@ -1095,12 +1091,11 @@ describe('CredentialsLogic', () => {
jest
.spyOn(CredentialsLogic.actions, 'setCredentialsDetails')
.mockImplementationOnce(() => {});
- const promise = Promise.resolve(credentialsDetails);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(credentialsDetails));
CredentialsLogic.actions.fetchDetails();
expect(http.get).toHaveBeenCalledWith('/api/app_search/credentials/details');
- await promise;
+ await nextTick();
expect(CredentialsLogic.actions.setCredentialsDetails).toHaveBeenCalledWith(
credentialsDetails
);
@@ -1108,11 +1103,10 @@ describe('CredentialsLogic', () => {
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occured');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occured'));
CredentialsLogic.actions.fetchDetails();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
@@ -1124,23 +1118,21 @@ describe('CredentialsLogic', () => {
it('will call an API endpoint and set the results with the `onApiKeyDelete` action', async () => {
mount();
jest.spyOn(CredentialsLogic.actions, 'onApiKeyDelete').mockImplementationOnce(() => {});
- const promise = Promise.resolve();
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.resolve());
CredentialsLogic.actions.deleteApiKey(tokenName);
expect(http.delete).toHaveBeenCalledWith(`/api/app_search/credentials/${tokenName}`);
- await promise;
+ await nextTick();
expect(CredentialsLogic.actions.onApiKeyDelete).toHaveBeenCalledWith(tokenName);
expect(setSuccessMessage).toHaveBeenCalled();
});
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occured');
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.reject('An error occured'));
CredentialsLogic.actions.deleteApiKey(tokenName);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
@@ -1156,14 +1148,13 @@ describe('CredentialsLogic', () => {
activeApiToken: createdToken,
});
jest.spyOn(CredentialsLogic.actions, 'onApiTokenCreateSuccess');
- const promise = Promise.resolve(createdToken);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(createdToken));
CredentialsLogic.actions.onApiTokenChange();
expect(http.post).toHaveBeenCalledWith('/api/app_search/credentials', {
body: JSON.stringify(createdToken),
});
- await promise;
+ await nextTick();
expect(CredentialsLogic.actions.onApiTokenCreateSuccess).toHaveBeenCalledWith(createdToken);
expect(setSuccessMessage).toHaveBeenCalled();
});
@@ -1184,25 +1175,23 @@ describe('CredentialsLogic', () => {
},
});
jest.spyOn(CredentialsLogic.actions, 'onApiTokenUpdateSuccess');
- const promise = Promise.resolve(updatedToken);
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve(updatedToken));
CredentialsLogic.actions.onApiTokenChange();
expect(http.put).toHaveBeenCalledWith('/api/app_search/credentials/test-key', {
body: JSON.stringify(updatedToken),
});
- await promise;
+ await nextTick();
expect(CredentialsLogic.actions.onApiTokenUpdateSuccess).toHaveBeenCalledWith(updatedToken);
expect(setSuccessMessage).toHaveBeenCalled();
});
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occured');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('An error occured'));
CredentialsLogic.actions.onApiTokenChange();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.test.ts
index 2256d5ae7946a..e1b562d9561ee 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/document_creation/document_creation_logic.test.ts
@@ -6,6 +6,7 @@
import { LogicMounter, mockHttpValues } from '../../../__mocks__';
+import { nextTick } from '@kbn/test/jest';
import dedent from 'dedent';
jest.mock('./utils', () => ({
@@ -443,10 +444,10 @@ describe('DocumentCreationLogic', () => {
});
it('should set and show summary from the returned response', async () => {
- const promise = http.post.mockReturnValueOnce(Promise.resolve(mockValidResponse));
+ http.post.mockReturnValueOnce(Promise.resolve(mockValidResponse));
await DocumentCreationLogic.actions.uploadDocuments({ documents: mockValidDocuments });
- await promise;
+ await nextTick();
expect(DocumentCreationLogic.actions.setSummary).toHaveBeenCalledWith(mockValidResponse);
expect(DocumentCreationLogic.actions.setCreationStep).toHaveBeenCalledWith(
@@ -462,7 +463,7 @@ describe('DocumentCreationLogic', () => {
});
it('handles API errors', async () => {
- const promise = http.post.mockReturnValueOnce(
+ http.post.mockReturnValueOnce(
Promise.reject({
body: {
statusCode: 400,
@@ -473,7 +474,7 @@ describe('DocumentCreationLogic', () => {
);
await DocumentCreationLogic.actions.uploadDocuments({ documents: [{}] });
- await promise;
+ await nextTick();
expect(DocumentCreationLogic.actions.setErrors).toHaveBeenCalledWith(
'[400 Bad Request] Invalid request payload JSON format'
@@ -481,10 +482,10 @@ describe('DocumentCreationLogic', () => {
});
it('handles client-side errors', async () => {
- const promise = (http.post as jest.Mock).mockReturnValueOnce(new Error());
+ (http.post as jest.Mock).mockReturnValueOnce(new Error());
await DocumentCreationLogic.actions.uploadDocuments({ documents: [{}] });
- await promise;
+ await nextTick();
expect(DocumentCreationLogic.actions.setErrors).toHaveBeenCalledWith(
"Cannot read property 'total' of undefined"
@@ -493,14 +494,14 @@ describe('DocumentCreationLogic', () => {
// NOTE: I can't seem to reproduce this in a production setting.
it('handles errors returned from the API', async () => {
- const promise = http.post.mockReturnValueOnce(
+ http.post.mockReturnValueOnce(
Promise.resolve({
errors: ['JSON cannot be empty'],
})
);
await DocumentCreationLogic.actions.uploadDocuments({ documents: [{}] });
- await promise;
+ await nextTick();
expect(DocumentCreationLogic.actions.setErrors).toHaveBeenCalledWith([
'JSON cannot be empty',
@@ -536,12 +537,12 @@ describe('DocumentCreationLogic', () => {
});
it('should correctly merge multiple API calls into a single summary obj', async () => {
- const promise = (http.post as jest.Mock)
+ (http.post as jest.Mock)
.mockReturnValueOnce(mockFirstResponse)
.mockReturnValueOnce(mockSecondResponse);
await DocumentCreationLogic.actions.uploadDocuments({ documents: largeDocumentsArray });
- await promise;
+ await nextTick();
expect(http.post).toHaveBeenCalledTimes(2);
expect(DocumentCreationLogic.actions.setSummary).toHaveBeenCalledWith({
@@ -562,12 +563,12 @@ describe('DocumentCreationLogic', () => {
});
it('should correctly merge response errors', async () => {
- const promise = (http.post as jest.Mock)
+ (http.post as jest.Mock)
.mockReturnValueOnce({ ...mockFirstResponse, errors: ['JSON cannot be empty'] })
.mockReturnValueOnce({ ...mockSecondResponse, errors: ['Too large to render'] });
await DocumentCreationLogic.actions.uploadDocuments({ documents: largeDocumentsArray });
- await promise;
+ await nextTick();
expect(http.post).toHaveBeenCalledTimes(2);
expect(DocumentCreationLogic.actions.setErrors).toHaveBeenCalledWith([
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.test.ts
index e33cd9b0e9e71..3a8861ee1e20e 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/documents/document_detail_logic.test.ts
@@ -9,10 +9,11 @@ import {
mockHttpValues,
mockKibanaValues,
mockFlashMessageHelpers,
- expectedAsyncError,
} from '../../../__mocks__';
import { mockEngineValues } from '../../__mocks__';
+import { nextTick } from '@kbn/test/jest';
+
import { DocumentDetailLogic } from './document_detail_logic';
import { InternalSchemaTypes } from '../../../shared/types';
@@ -56,23 +57,21 @@ describe('DocumentDetailLogic', () => {
it('will call an API endpoint and then store the result', async () => {
const fields = [{ name: 'name', value: 'python', type: 'string' }];
jest.spyOn(DocumentDetailLogic.actions, 'setFields');
- const promise = Promise.resolve({ fields });
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve({ fields }));
DocumentDetailLogic.actions.getDocumentDetails('1');
expect(http.get).toHaveBeenCalledWith(`/api/app_search/engines/engine1/documents/1`);
- await promise;
+ await nextTick();
expect(DocumentDetailLogic.actions.setFields).toHaveBeenCalledWith(fields);
});
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occurred');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occurred'));
DocumentDetailLogic.actions.getDocumentDetails('1');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occurred', { isQueued: true });
expect(navigateToUrl).toHaveBeenCalledWith('/engines/engine1/documents');
@@ -81,13 +80,11 @@ describe('DocumentDetailLogic', () => {
describe('deleteDocument', () => {
let confirmSpy: any;
- let promise: Promise;
beforeEach(() => {
confirmSpy = jest.spyOn(window, 'confirm');
confirmSpy.mockImplementation(jest.fn(() => true));
- promise = Promise.resolve({});
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.resolve({}));
});
afterEach(() => {
@@ -99,7 +96,7 @@ describe('DocumentDetailLogic', () => {
DocumentDetailLogic.actions.deleteDocument('1');
expect(http.delete).toHaveBeenCalledWith(`/api/app_search/engines/engine1/documents/1`);
- await promise;
+ await nextTick();
expect(setQueuedSuccessMessage).toHaveBeenCalledWith(
'Successfully marked document for deletion. It will be deleted momentarily.'
);
@@ -113,16 +110,15 @@ describe('DocumentDetailLogic', () => {
DocumentDetailLogic.actions.deleteDocument('1');
expect(http.delete).not.toHaveBeenCalled();
- await promise;
+ await nextTick();
});
it('handles errors', async () => {
mount();
- promise = Promise.reject('An error occured');
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.reject('An error occured'));
DocumentDetailLogic.actions.deleteDocument('1');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.test.ts
index 48cbaeef70c1a..616dae98e29f2 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_logic.test.ts
@@ -4,7 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { LogicMounter, mockHttpValues, expectedAsyncError } from '../../../__mocks__';
+import { LogicMounter, mockHttpValues } from '../../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
import { EngineLogic } from './';
@@ -172,11 +174,10 @@ describe('EngineLogic', () => {
it('fetches and sets engine data', async () => {
mount({ engineName: 'some-engine' });
jest.spyOn(EngineLogic.actions, 'setEngineData');
- const promise = Promise.resolve(mockEngineData);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(mockEngineData));
EngineLogic.actions.initializeEngine();
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines/some-engine');
expect(EngineLogic.actions.setEngineData).toHaveBeenCalledWith(mockEngineData);
@@ -185,11 +186,10 @@ describe('EngineLogic', () => {
it('handles errors', async () => {
mount();
jest.spyOn(EngineLogic.actions, 'setEngineNotFound');
- const promise = Promise.reject('An error occured');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occured'));
EngineLogic.actions.initializeEngine();
- await expectedAsyncError(promise);
+ await nextTick();
expect(EngineLogic.actions.setEngineNotFound).toHaveBeenCalledWith(true);
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.test.ts
index b6620756699d5..9832387a563e3 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview_logic.test.ts
@@ -4,17 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockHttpValues,
- mockFlashMessageHelpers,
- expectedAsyncError,
-} from '../../../__mocks__';
+import { LogicMounter, mockHttpValues, mockFlashMessageHelpers } from '../../../__mocks__';
jest.mock('../engine', () => ({
EngineLogic: { values: { engineName: 'some-engine' } },
}));
+import { nextTick } from '@kbn/test/jest';
+
import { EngineOverviewLogic } from './';
describe('EngineOverviewLogic', () => {
@@ -85,11 +82,10 @@ describe('EngineOverviewLogic', () => {
it('fetches data and calls onPollingSuccess', async () => {
mount();
jest.spyOn(EngineOverviewLogic.actions, 'onPollingSuccess');
- const promise = Promise.resolve(mockEngineMetrics);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(mockEngineMetrics));
EngineOverviewLogic.actions.pollForOverviewMetrics();
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines/some-engine/overview');
expect(EngineOverviewLogic.actions.onPollingSuccess).toHaveBeenCalledWith(
@@ -99,11 +95,10 @@ describe('EngineOverviewLogic', () => {
it('handles errors', async () => {
mount();
- const promise = Promise.reject('An error occurred');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occurred'));
EngineOverviewLogic.actions.pollForOverviewMetrics();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occurred');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.test.ts
index 5a83717aa0030..2e22c9b76cf6f 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engines/engines_logic.test.ts
@@ -6,6 +6,8 @@
import { LogicMounter, mockHttpValues } from '../../../__mocks__';
+import { nextTick } from '@kbn/test/jest';
+
import { EngineDetails } from '../engine/types';
import { EnginesLogic } from './';
@@ -124,13 +126,12 @@ describe('EnginesLogic', () => {
describe('loadEngines', () => {
it('should call the engines API endpoint and set state based on the results', async () => {
- const promise = Promise.resolve(MOCK_ENGINES_API_RESPONSE);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(MOCK_ENGINES_API_RESPONSE));
mount({ enginesPage: 10 });
jest.spyOn(EnginesLogic.actions, 'onEnginesLoad');
EnginesLogic.actions.loadEngines();
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines', {
query: { type: 'indexed', pageIndex: 10 },
@@ -144,13 +145,12 @@ describe('EnginesLogic', () => {
describe('loadMetaEngines', () => {
it('should call the engines API endpoint and set state based on the results', async () => {
- const promise = Promise.resolve(MOCK_ENGINES_API_RESPONSE);
- http.get.mockReturnValueOnce(promise);
+ http.get.mockReturnValueOnce(Promise.resolve(MOCK_ENGINES_API_RESPONSE));
mount({ metaEnginesPage: 99 });
jest.spyOn(EnginesLogic.actions, 'onMetaEnginesLoad');
EnginesLogic.actions.loadMetaEngines();
- await promise;
+ await nextTick();
expect(http.get).toHaveBeenCalledWith('/api/app_search/engines', {
query: { type: 'meta', pageIndex: 99 },
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/log_retention/log_retention_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/log_retention/log_retention_logic.test.ts
index bfdca6791edc1..18ab05a3676c6 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/log_retention/log_retention_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/log_retention/log_retention_logic.test.ts
@@ -4,12 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockHttpValues,
- mockFlashMessageHelpers,
- expectedAsyncError,
-} from '../../../__mocks__';
+import { LogicMounter, mockHttpValues, mockFlashMessageHelpers } from '../../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
import { LogRetentionOptions } from './types';
import { LogRetentionLogic } from './log_retention_logic';
@@ -202,8 +199,7 @@ describe('LogRetentionLogic', () => {
it('will call an API endpoint and update log retention', async () => {
jest.spyOn(LogRetentionLogic.actions, 'updateLogRetention');
- const promise = Promise.resolve(TYPICAL_SERVER_LOG_RETENTION);
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve(TYPICAL_SERVER_LOG_RETENTION));
LogRetentionLogic.actions.saveLogRetention(LogRetentionOptions.Analytics, true);
@@ -215,7 +211,7 @@ describe('LogRetentionLogic', () => {
}),
});
- await promise;
+ await nextTick();
expect(LogRetentionLogic.actions.updateLogRetention).toHaveBeenCalledWith(
TYPICAL_CLIENT_LOG_RETENTION
);
@@ -224,11 +220,10 @@ describe('LogRetentionLogic', () => {
});
it('handles errors', async () => {
- const promise = Promise.reject('An error occured');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('An error occured'));
LogRetentionLogic.actions.saveLogRetention(LogRetentionOptions.Analytics, true);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
expect(LogRetentionLogic.actions.clearLogRetentionUpdating).toHaveBeenCalled();
@@ -276,14 +271,13 @@ describe('LogRetentionLogic', () => {
.spyOn(LogRetentionLogic.actions, 'updateLogRetention')
.mockImplementationOnce(() => {});
- const promise = Promise.resolve(TYPICAL_SERVER_LOG_RETENTION);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(TYPICAL_SERVER_LOG_RETENTION));
LogRetentionLogic.actions.fetchLogRetention();
expect(LogRetentionLogic.values.isLogRetentionUpdating).toBe(true);
expect(http.get).toHaveBeenCalledWith('/api/app_search/log_settings');
- await promise;
+ await nextTick();
expect(LogRetentionLogic.actions.updateLogRetention).toHaveBeenCalledWith(
TYPICAL_CLIENT_LOG_RETENTION
);
@@ -293,11 +287,10 @@ describe('LogRetentionLogic', () => {
it('handles errors', async () => {
mount();
jest.spyOn(LogRetentionLogic.actions, 'clearLogRetentionUpdating');
- const promise = Promise.reject('An error occured');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occured'));
LogRetentionLogic.actions.fetchLogRetention();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
expect(LogRetentionLogic.actions.clearLogRetentionUpdating).toHaveBeenCalled();
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts
index 0a80f8e361025..cfff8cc557836 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts
@@ -4,12 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../__mocks__';
+import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
import { IndexingStatusLogic } from './indexing_status_logic';
@@ -57,37 +54,34 @@ describe('IndexingStatusLogic', () => {
it('calls API and sets values', async () => {
const setIndexingStatusSpy = jest.spyOn(IndexingStatusLogic.actions, 'setIndexingStatus');
- const promise = Promise.resolve(mockStatusResponse);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(mockStatusResponse));
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete });
jest.advanceTimersByTime(TIMEOUT);
expect(http.get).toHaveBeenCalledWith(statusPath);
- await promise;
+ await nextTick();
expect(setIndexingStatusSpy).toHaveBeenCalledWith(mockStatusResponse);
});
it('handles error', async () => {
- const promise = Promise.reject('An error occured');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('An error occured'));
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete });
jest.advanceTimersByTime(TIMEOUT);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('An error occured');
});
it('handles indexing complete state', async () => {
- const promise = Promise.resolve({ ...mockStatusResponse, percentageComplete: 100 });
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve({ ...mockStatusResponse, percentageComplete: 100 }));
IndexingStatusLogic.actions.fetchIndexingStatus({ statusPath, onComplete });
jest.advanceTimersByTime(TIMEOUT);
- await promise;
+ await nextTick();
expect(clearInterval).toHaveBeenCalled();
expect(onComplete).toHaveBeenCalledWith(mockStatusResponse.numDocumentsWithErrors);
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/setup_guide/cloud/instructions.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/setup_guide/cloud/instructions.tsx
index 26bbc8814d108..9af5bfc0c3d40 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/setup_guide/cloud/instructions.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/setup_guide/cloud/instructions.tsx
@@ -34,10 +34,16 @@ export const CloudSetupInstructions: React.FC = ({ productName, cloudDepl
values={{
editDeploymentLink: cloudDeploymentLink ? (
- edit your deployment
+ {i18n.translate(
+ 'xpack.enterpriseSearch.setupGuide.cloud.step1.instruction1LinkText',
+ { defaultMessage: 'edit your deployment' }
+ )}
) : (
- 'Visit the Elastic Cloud console'
+ i18n.translate(
+ 'xpack.enterpriseSearch.setupGuide.cloud.step1.instruction1LinkText',
+ { defaultMessage: 'edit your deployment' }
+ )
),
}}
/>
@@ -76,7 +82,10 @@ export const CloudSetupInstructions: React.FC = ({ productName, cloudDepl
href={`${docLinks.enterpriseSearchBase}/configuration.html`}
target="_blank"
>
- configurable options
+ {i18n.translate(
+ 'xpack.enterpriseSearch.setupGuide.cloud.step3.instruction1LinkText',
+ { defaultMessage: 'configurable options' }
+ )}
),
}}
@@ -118,7 +127,10 @@ export const CloudSetupInstructions: React.FC = ({ productName, cloudDepl
href={`${docLinks.cloudBase}/ec-configure-index-management.html`}
target="_blank"
>
- configure an index lifecycle policy
+ {i18n.translate(
+ 'xpack.enterpriseSearch.setupGuide.cloud.step5.instruction1LinkText',
+ { defaultMessage: 'configure an index lifecycle policy' }
+ )}
),
}}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/app_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/app_logic.ts
index f5f534807fabf..2ce7eed236840 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/app_logic.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/app_logic.ts
@@ -21,6 +21,7 @@ interface AppValues extends WorkplaceSearchInitialData {
interface AppActions {
initializeAppData(props: InitialAppData): InitialAppData;
setContext(isOrganization: boolean): boolean;
+ setSourceRestriction(canCreatePersonalSources: boolean): boolean;
}
const emptyOrg = {} as Organization;
@@ -34,6 +35,7 @@ export const AppLogic = kea>({
isFederatedAuth,
}),
setContext: (isOrganization) => isOrganization,
+ setSourceRestriction: (canCreatePersonalSources: boolean) => canCreatePersonalSources,
},
reducers: {
hasInitialized: [
@@ -64,6 +66,10 @@ export const AppLogic = kea>({
emptyAccount,
{
initializeAppData: (_, { workplaceSearch }) => workplaceSearch?.account || emptyAccount,
+ setSourceRestriction: (state, canCreatePersonalSources) => ({
+ ...state,
+ canCreatePersonalSources,
+ }),
},
],
},
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/nav.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/nav.tsx
index 8a83e9aad5fd9..7357e84f27a41 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/nav.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/layout/nav.tsx
@@ -45,9 +45,7 @@ export const WorkplaceSearchNav: React.FC = ({
{NAV.ROLE_MAPPINGS}
-
- {NAV.SECURITY}
-
+ {NAV.SECURITY}
{NAV.SETTINGS}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts
index e72e28aa47d9b..17fbbf517f347 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts
@@ -289,6 +289,87 @@ export const DOCUMENTATION_LINK_TITLE = i18n.translate(
}
);
+export const PRIVATE_SOURCES_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.privateSources.description',
+ {
+ defaultMessage:
+ 'Private sources are connected by users in your organization to create a personalized search experience.',
+ }
+);
+
+export const PRIVATE_SOURCES_TOGGLE_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.privateSourcesToggle.description',
+ {
+ defaultMessage: 'Enable private sources for your organization',
+ }
+);
+
+export const REMOTE_SOURCES_TOGGLE_TEXT = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.remoteSourcesToggle.text',
+ {
+ defaultMessage: 'Enable remote private sources',
+ }
+);
+
+export const REMOTE_SOURCES_TABLE_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.remoteSourcesTable.description',
+ {
+ defaultMessage:
+ 'Remote sources synchronize and store a limited amount of data on disk, with a low impact on storage resources.',
+ }
+);
+
+export const REMOTE_SOURCES_EMPTY_TABLE_TITLE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.remoteSourcesEmptyTable.title',
+ {
+ defaultMessage: 'No remote private sources configured yet',
+ }
+);
+
+export const STANDARD_SOURCES_TOGGLE_TEXT = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.standardSourcesToggle.text',
+ {
+ defaultMessage: 'Enable standard private sources',
+ }
+);
+
+export const STANDARD_SOURCES_TABLE_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.standardSourcesTable.description',
+ {
+ defaultMessage:
+ 'Standard sources synchronize and store all searchable data on disk, with a directly correlated impact on storage resources.',
+ }
+);
+
+export const STANDARD_SOURCES_EMPTY_TABLE_TITLE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.standardSourcesEmptyTable.title',
+ {
+ defaultMessage: 'No standard private sources configured yet',
+ }
+);
+
+export const SECURITY_UNSAVED_CHANGES_MESSAGE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.unsavedChanges.message',
+ {
+ defaultMessage:
+ 'Your private sources settings have not been saved. Are you sure you want to leave?',
+ }
+);
+
+export const PRIVATE_SOURCES_UPDATE_CONFIRMATION_TEXT = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.privateSourcesUpdateConfirmation.text',
+ {
+ defaultMessage: 'Updates to private source configuration will take effect immediately.',
+ }
+);
+
+export const SOURCE_RESTRICTIONS_SUCCESS_MESSAGE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.sourceRestrictionsSuccess.message',
+ {
+ defaultMessage: 'Successfully updated source restrictions.',
+ }
+);
+
export const PUBLIC_KEY_LABEL = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.publicKey.label',
{
@@ -382,6 +463,20 @@ export const SAVE_CHANGES_BUTTON = i18n.translate(
}
);
+export const SAVE_SETTINGS_BUTTON = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.saveSettings.button',
+ {
+ defaultMessage: 'Save settings',
+ }
+);
+
+export const KEEP_EDITING_BUTTON = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.keepEditing.button',
+ {
+ defaultMessage: 'Keep editing',
+ }
+);
+
export const NAME_LABEL = i18n.translate('xpack.enterpriseSearch.workplaceSearch.name.label', {
defaultMessage: 'Name',
});
@@ -493,6 +588,10 @@ export const UPDATE_BUTTON = i18n.translate(
}
);
+export const RESET_BUTTON = i18n.translate('xpack.enterpriseSearch.workplaceSearch.reset.button', {
+ defaultMessage: 'Reset',
+});
+
export const CONFIGURE_BUTTON = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.configure.button',
{
@@ -522,6 +621,10 @@ export const PRIVATE_PLATINUM_LICENSE_CALLOUT = i18n.translate(
}
);
+export const SOURCE = i18n.translate('xpack.enterpriseSearch.workplaceSearch.source.text', {
+ defaultMessage: 'Source',
+});
+
export const PRIVATE_SOURCE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.privateSource.text',
{
@@ -529,6 +632,20 @@ export const PRIVATE_SOURCE = i18n.translate(
}
);
+export const PRIVATE_SOURCES = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.privateSources.text',
+ {
+ defaultMessage: 'Private Sources',
+ }
+);
+
+export const CONFIRM_CHANGES_TEXT = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.confirmChanges.text',
+ {
+ defaultMessage: 'Confirm changes',
+ }
+);
+
export const CONNECTORS_HEADER_TITLE = i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.connectors.header.title',
{
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx
index d10de7a770171..ec1b8cfcba958 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx
@@ -22,6 +22,7 @@ import {
SOURCES_PATH,
PERSONAL_SOURCES_PATH,
ORG_SETTINGS_PATH,
+ SECURITY_PATH,
} from './routes';
import { SetupGuide } from './views/setup_guide';
@@ -29,6 +30,7 @@ import { ErrorState } from './views/error_state';
import { NotFound } from '../shared/not_found';
import { Overview } from './views/overview';
import { GroupsRouter } from './views/groups';
+import { Security } from './views/security';
import { SourcesRouter } from './views/content_sources';
import { SettingsRouter } from './views/settings';
@@ -102,6 +104,11 @@ export const WorkplaceSearchConfigured: React.FC = (props) => {
+
+ } restrictWidth readOnlyMode={readOnlyMode}>
+
+
+
} />}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts
index d08f807691c2b..058645bd30862 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.test.ts
@@ -4,18 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../../../../__mocks__';
+import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../../../__mocks__';
import { AppLogic } from '../../../../app_logic';
jest.mock('../../../../app_logic', () => ({
AppLogic: { values: { isOrganization: true } },
}));
+import { nextTick } from '@kbn/test/jest';
+
import { CustomSource } from '../../../../types';
import { sourceConfigData } from '../../../../__mocks__/content_sources.mock';
@@ -271,23 +268,21 @@ describe('AddSourceLogic', () => {
describe('getSourceConfigData', () => {
it('calls API and sets values', async () => {
const setSourceConfigDataSpy = jest.spyOn(AddSourceLogic.actions, 'setSourceConfigData');
- const promise = Promise.resolve(sourceConfigData);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(sourceConfigData));
AddSourceLogic.actions.getSourceConfigData('github');
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/settings/connectors/github'
);
- await promise;
+ await nextTick();
expect(setSourceConfigDataSpy).toHaveBeenCalledWith(sourceConfigData);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.getSourceConfigData('github');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -302,15 +297,14 @@ describe('AddSourceLogic', () => {
AddSourceLogic.actions,
'setSourceConnectData'
);
- const promise = Promise.resolve(sourceConnectData);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(sourceConnectData));
AddSourceLogic.actions.getSourceConnectData('github', successCallback);
expect(clearFlashMessages).toHaveBeenCalled();
expect(AddSourceLogic.values.buttonLoading).toEqual(true);
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/org/sources/github/prepare');
- await promise;
+ await nextTick();
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
expect(successCallback).toHaveBeenCalledWith(sourceConnectData.oauthUrl);
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
@@ -327,11 +321,10 @@ describe('AddSourceLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.getSourceConnectData('github', successCallback);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -343,24 +336,22 @@ describe('AddSourceLogic', () => {
AddSourceLogic.actions,
'setSourceConnectData'
);
- const promise = Promise.resolve(sourceConnectData);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(sourceConnectData));
AddSourceLogic.actions.getSourceReConnectData('github');
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/sources/github/reauth_prepare'
);
- await promise;
+ await nextTick();
expect(setSourceConnectDataSpy).toHaveBeenCalledWith(sourceConnectData);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.getSourceReConnectData('github');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -372,22 +363,20 @@ describe('AddSourceLogic', () => {
AddSourceLogic.actions,
'setPreContentSourceConfigData'
);
- const promise = Promise.resolve(config);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(config));
AddSourceLogic.actions.getPreContentSourceConfigData('123');
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/org/pre_sources/123');
- await promise;
+ await nextTick();
expect(setPreContentSourceConfigDataSpy).toHaveBeenCalledWith(config);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.getPreContentSourceConfigData('123');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -414,8 +403,7 @@ describe('AddSourceLogic', () => {
const successCallback = jest.fn();
const setButtonNotLoadingSpy = jest.spyOn(AddSourceLogic.actions, 'setButtonNotLoading');
const setSourceConfigDataSpy = jest.spyOn(AddSourceLogic.actions, 'setSourceConfigData');
- const promise = Promise.resolve({ sourceConfigData });
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve({ sourceConfigData }));
AddSourceLogic.actions.saveSourceConfig(true, successCallback);
@@ -428,7 +416,7 @@ describe('AddSourceLogic', () => {
{ body: JSON.stringify({ params }) }
);
- await promise;
+ await nextTick();
expect(successCallback).toHaveBeenCalled();
expect(setSourceConfigDataSpy).toHaveBeenCalledWith({ sourceConfigData });
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
@@ -453,11 +441,10 @@ describe('AddSourceLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.saveSourceConfig(true);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -495,8 +482,7 @@ describe('AddSourceLogic', () => {
it('calls API and sets values', async () => {
const setButtonNotLoadingSpy = jest.spyOn(AddSourceLogic.actions, 'setButtonNotLoading');
const setCustomSourceDataSpy = jest.spyOn(AddSourceLogic.actions, 'setCustomSourceData');
- const promise = Promise.resolve({ sourceConfigData });
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve({ sourceConfigData }));
AddSourceLogic.actions.createContentSource(serviceType, successCallback, errorCallback);
@@ -505,18 +491,17 @@ describe('AddSourceLogic', () => {
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/org/create_source', {
body: JSON.stringify({ ...params }),
});
- await promise;
+ await nextTick();
expect(setCustomSourceDataSpy).toHaveBeenCalledWith({ sourceConfigData });
expect(successCallback).toHaveBeenCalled();
expect(setButtonNotLoadingSpy).toHaveBeenCalled();
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
AddSourceLogic.actions.createContentSource(serviceType, successCallback, errorCallback);
- await expectedAsyncError(promise);
+ await nextTick();
expect(errorCallback).toHaveBeenCalled();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts
index aed99bdd950c5..d43afd589468f 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.test.ts
@@ -6,11 +6,7 @@
import { LogicMounter } from '../../../../../__mocks__/kea.mock';
-import {
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../../../../__mocks__';
+import { mockFlashMessageHelpers, mockHttpValues } from '../../../../../__mocks__';
const contentSource = { id: 'source123' };
jest.mock('../../source_logic', () => ({
@@ -22,6 +18,8 @@ jest.mock('../../../../app_logic', () => ({
AppLogic: { values: { isOrganization: true } },
}));
+import { nextTick } from '@kbn/test/jest';
+
import { exampleResult } from '../../../../__mocks__/content_sources.mock';
import { LEAVE_UNASSIGNED_FIELD } from './constants';
@@ -286,14 +284,13 @@ describe('DisplaySettingsLogic', () => {
DisplaySettingsLogic.actions,
'onInitializeDisplaySettings'
);
- const promise = Promise.resolve(serverProps);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(serverProps));
DisplaySettingsLogic.actions.initializeDisplaySettings();
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/sources/source123/display_settings/config'
);
- await promise;
+ await nextTick();
expect(onInitializeDisplaySettingsSpy).toHaveBeenCalledWith({
...serverProps,
isOrganization: true,
@@ -307,14 +304,13 @@ describe('DisplaySettingsLogic', () => {
DisplaySettingsLogic.actions,
'onInitializeDisplaySettings'
);
- const promise = Promise.resolve(serverProps);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(serverProps));
DisplaySettingsLogic.actions.initializeDisplaySettings();
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/account/sources/source123/display_settings/config'
);
- await promise;
+ await nextTick();
expect(onInitializeDisplaySettingsSpy).toHaveBeenCalledWith({
...serverProps,
isOrganization: false,
@@ -322,10 +318,9 @@ describe('DisplaySettingsLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
DisplaySettingsLogic.actions.initializeDisplaySettings();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -337,25 +332,23 @@ describe('DisplaySettingsLogic', () => {
DisplaySettingsLogic.actions,
'setServerResponseData'
);
- const promise = Promise.resolve(serverProps);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(serverProps));
DisplaySettingsLogic.actions.onInitializeDisplaySettings(serverProps);
DisplaySettingsLogic.actions.setServerData();
expect(http.post).toHaveBeenCalledWith(serverProps.serverRoute, {
body: JSON.stringify({ ...searchResultConfig }),
});
- await promise;
+ await nextTick();
expect(setServerResponseDataSpy).toHaveBeenCalledWith({
...serverProps,
});
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
DisplaySettingsLogic.actions.setServerData();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts
index 2c3aa6114c7da..c9d68201f33ee 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts
@@ -4,12 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../../../../__mocks__';
+import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
const contentSource = { id: 'source123' };
jest.mock('../../source_logic', () => ({
@@ -198,14 +195,13 @@ describe('SchemaLogic', () => {
describe('initializeSchema', () => {
it('calls API and sets values (org)', async () => {
const onInitializeSchemaSpy = jest.spyOn(SchemaLogic.actions, 'onInitializeSchema');
- const promise = Promise.resolve(serverResponse);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.initializeSchema();
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/org/sources/source123/schemas'
);
- await promise;
+ await nextTick();
expect(onInitializeSchemaSpy).toHaveBeenCalledWith(serverResponse);
});
@@ -213,22 +209,20 @@ describe('SchemaLogic', () => {
AppLogic.values.isOrganization = false;
const onInitializeSchemaSpy = jest.spyOn(SchemaLogic.actions, 'onInitializeSchema');
- const promise = Promise.resolve(serverResponse);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.initializeSchema();
expect(http.get).toHaveBeenCalledWith(
'/api/workplace_search/account/sources/source123/schemas'
);
- await promise;
+ await nextTick();
expect(onInitializeSchemaSpy).toHaveBeenCalledWith(serverResponse);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
SchemaLogic.actions.initializeSchema();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -297,13 +291,12 @@ describe('SchemaLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject({ error: 'this is an error' });
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject({ error: 'this is an error' }));
SchemaLogic.actions.initializeSchemaFieldErrors(
mostRecentIndexJob.activeReindexJobId,
contentSource.id
);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith({
error: 'this is an error',
@@ -352,8 +345,7 @@ describe('SchemaLogic', () => {
it('calls API and sets values (org)', async () => {
AppLogic.values.isOrganization = true;
const onSchemaSetSuccessSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetSuccess');
- const promise = Promise.resolve(serverResponse);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.setServerField(schema, ADD);
expect(http.post).toHaveBeenCalledWith(
@@ -362,7 +354,7 @@ describe('SchemaLogic', () => {
body: JSON.stringify({ ...schema }),
}
);
- await promise;
+ await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(SCHEMA_FIELD_ADDED_MESSAGE);
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
});
@@ -371,8 +363,7 @@ describe('SchemaLogic', () => {
AppLogic.values.isOrganization = false;
const onSchemaSetSuccessSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetSuccess');
- const promise = Promise.resolve(serverResponse);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.setServerField(schema, ADD);
expect(http.post).toHaveBeenCalledWith(
@@ -381,16 +372,15 @@ describe('SchemaLogic', () => {
body: JSON.stringify({ ...schema }),
}
);
- await promise;
+ await nextTick();
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
});
it('handles error', async () => {
const onSchemaSetFormErrorsSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetFormErrors');
- const promise = Promise.reject({ message: 'this is an error' });
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject({ message: 'this is an error' }));
SchemaLogic.actions.setServerField(schema, ADD);
- await expectedAsyncError(promise);
+ await nextTick();
expect(onSchemaSetFormErrorsSpy).toHaveBeenCalledWith('this is an error');
});
@@ -400,8 +390,7 @@ describe('SchemaLogic', () => {
it('calls API and sets values (org)', async () => {
AppLogic.values.isOrganization = true;
const onSchemaSetSuccessSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetSuccess');
- const promise = Promise.resolve(serverResponse);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.setServerField(schema, UPDATE);
expect(http.post).toHaveBeenCalledWith(
@@ -410,7 +399,7 @@ describe('SchemaLogic', () => {
body: JSON.stringify({ ...schema }),
}
);
- await promise;
+ await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(SCHEMA_UPDATED_MESSAGE);
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
});
@@ -419,8 +408,7 @@ describe('SchemaLogic', () => {
AppLogic.values.isOrganization = false;
const onSchemaSetSuccessSpy = jest.spyOn(SchemaLogic.actions, 'onSchemaSetSuccess');
- const promise = Promise.resolve(serverResponse);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(serverResponse));
SchemaLogic.actions.setServerField(schema, UPDATE);
expect(http.post).toHaveBeenCalledWith(
@@ -429,15 +417,14 @@ describe('SchemaLogic', () => {
body: JSON.stringify({ ...schema }),
}
);
- await promise;
+ await nextTick();
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
SchemaLogic.actions.setServerField(schema, UPDATE);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts
index e90acd929a990..2e7a028e43aec 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts
@@ -9,9 +9,10 @@ import {
mockKibanaValues,
mockFlashMessageHelpers,
mockHttpValues,
- expectedAsyncError,
} from '../../../__mocks__';
+import { nextTick } from '@kbn/test/jest';
+
import { groups } from '../../__mocks__/groups.mock';
import { mockGroupValues } from './__mocks__/group_logic.mock';
import { GroupLogic } from './group_logic';
@@ -229,32 +230,29 @@ describe('GroupLogic', () => {
describe('initializeGroup', () => {
it('calls API and sets values', async () => {
const onInitializeGroupSpy = jest.spyOn(GroupLogic.actions, 'onInitializeGroup');
- const promise = Promise.resolve(group);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(group));
GroupLogic.actions.initializeGroup(sourceIds[0]);
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/groups/123');
- await promise;
+ await nextTick();
expect(onInitializeGroupSpy).toHaveBeenCalledWith(group);
});
it('handles 404 error', async () => {
- const promise = Promise.reject({ response: { status: 404 } });
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject({ response: { status: 404 } }));
GroupLogic.actions.initializeGroup(sourceIds[0]);
- await expectedAsyncError(promise);
+ await nextTick();
expect(navigateToUrl).toHaveBeenCalledWith(GROUPS_PATH);
expect(setQueuedErrorMessage).toHaveBeenCalledWith('Unable to find group with ID: "123".');
});
it('handles non-404 error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.initializeGroup(sourceIds[0]);
- await expectedAsyncError(promise);
+ await nextTick();
expect(navigateToUrl).toHaveBeenCalledWith(GROUPS_PATH);
expect(setQueuedErrorMessage).toHaveBeenCalledWith('this is an error');
@@ -266,13 +264,12 @@ describe('GroupLogic', () => {
GroupLogic.actions.onInitializeGroup(group);
});
it('deletes a group', async () => {
- const promise = Promise.resolve(true);
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.resolve(true));
GroupLogic.actions.deleteGroup();
expect(http.delete).toHaveBeenCalledWith('/api/workplace_search/groups/123');
- await promise;
+ await nextTick();
expect(navigateToUrl).toHaveBeenCalledWith(GROUPS_PATH);
expect(setQueuedSuccessMessage).toHaveBeenCalledWith(
'Group "group" was successfully deleted.'
@@ -280,11 +277,10 @@ describe('GroupLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.deleteGroup();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -297,15 +293,14 @@ describe('GroupLogic', () => {
});
it('updates name', async () => {
const onGroupNameChangedSpy = jest.spyOn(GroupLogic.actions, 'onGroupNameChanged');
- const promise = Promise.resolve(group);
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve(group));
GroupLogic.actions.updateGroupName();
expect(http.put).toHaveBeenCalledWith('/api/workplace_search/groups/123', {
body: JSON.stringify({ group: { name: 'new name' } }),
});
- await promise;
+ await nextTick();
expect(onGroupNameChangedSpy).toHaveBeenCalledWith(group);
expect(setSuccessMessage).toHaveBeenCalledWith(
'Successfully renamed this group to "group".'
@@ -313,11 +308,10 @@ describe('GroupLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.updateGroupName();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -330,15 +324,14 @@ describe('GroupLogic', () => {
});
it('updates name', async () => {
const onGroupSourcesSavedSpy = jest.spyOn(GroupLogic.actions, 'onGroupSourcesSaved');
- const promise = Promise.resolve(group);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(group));
GroupLogic.actions.saveGroupSources();
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/groups/123/share', {
body: JSON.stringify({ content_source_ids: sourceIds }),
});
- await promise;
+ await nextTick();
expect(onGroupSourcesSavedSpy).toHaveBeenCalledWith(group);
expect(setSuccessMessage).toHaveBeenCalledWith(
'Successfully updated shared content sources.'
@@ -346,11 +339,10 @@ describe('GroupLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.saveGroupSources();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -362,15 +354,14 @@ describe('GroupLogic', () => {
});
it('updates name', async () => {
const onGroupUsersSavedSpy = jest.spyOn(GroupLogic.actions, 'onGroupUsersSaved');
- const promise = Promise.resolve(group);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(group));
GroupLogic.actions.saveGroupUsers();
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/groups/123/assign', {
body: JSON.stringify({ user_ids: userIds }),
});
- await promise;
+ await nextTick();
expect(onGroupUsersSavedSpy).toHaveBeenCalledWith(group);
expect(setSuccessMessage).toHaveBeenCalledWith(
'Successfully updated the users of this group.'
@@ -378,11 +369,10 @@ describe('GroupLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.saveGroupUsers();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -397,8 +387,7 @@ describe('GroupLogic', () => {
GroupLogic.actions,
'onGroupPrioritiesChanged'
);
- const promise = Promise.resolve(group);
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve(group));
GroupLogic.actions.saveGroupSourcePrioritization();
expect(http.put).toHaveBeenCalledWith('/api/workplace_search/groups/123/boosts', {
@@ -410,7 +399,7 @@ describe('GroupLogic', () => {
}),
});
- await promise;
+ await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(
'Successfully updated shared source prioritization.'
);
@@ -418,11 +407,10 @@ describe('GroupLogic', () => {
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('this is an error'));
GroupLogic.actions.saveGroupSourcePrioritization();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.test.ts
index 76352a6670650..6c9f912a98ce8 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.test.ts
@@ -4,12 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- LogicMounter,
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
-} from '../../../__mocks__';
+import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
import { DEFAULT_META } from '../../../shared/constants';
import { JSON_HEADER as headers } from '../../../../../common/constants';
@@ -22,7 +19,6 @@ import { GroupsLogic } from './groups_logic';
// We need to mock out the debounced functionality
const TIMEOUT = 400;
-const delay = () => new Promise((resolve) => setTimeout(resolve, TIMEOUT));
describe('GroupsLogic', () => {
const { mount } = new LogicMounter(GroupsLogic);
@@ -218,21 +214,19 @@ describe('GroupsLogic', () => {
describe('initializeGroups', () => {
it('calls API and sets values', async () => {
const onInitializeGroupsSpy = jest.spyOn(GroupsLogic.actions, 'onInitializeGroups');
- const promise = Promise.resolve(groupsResponse);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(groupsResponse));
GroupsLogic.actions.initializeGroups();
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/groups');
- await promise;
+ await nextTick();
expect(onInitializeGroupsSpy).toHaveBeenCalledWith(groupsResponse);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
GroupsLogic.actions.initializeGroups();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -256,15 +250,22 @@ describe('GroupsLogic', () => {
headers,
};
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+
+ afterAll(() => {
+ jest.useRealTimers();
+ });
+
it('calls API and sets values', async () => {
const setSearchResultsSpy = jest.spyOn(GroupsLogic.actions, 'setSearchResults');
- const promise = Promise.resolve(groups);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(groups));
GroupsLogic.actions.getSearchResults();
- await delay();
+ jest.advanceTimersByTime(TIMEOUT);
+ await nextTick();
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/groups/search', payload);
- await promise;
expect(setSearchResultsSpy).toHaveBeenCalledWith(groups);
});
@@ -272,24 +273,22 @@ describe('GroupsLogic', () => {
// Set active page to 2 to confirm resetting sends the `payload` value of 1 for the current page.
GroupsLogic.actions.setActivePage(2);
const setSearchResultsSpy = jest.spyOn(GroupsLogic.actions, 'setSearchResults');
- const promise = Promise.resolve(groups);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(groups));
GroupsLogic.actions.getSearchResults(true);
// Account for `breakpoint` that debounces filter value.
- await delay();
+ jest.advanceTimersByTime(TIMEOUT);
+ await nextTick();
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/groups/search', payload);
- await promise;
expect(setSearchResultsSpy).toHaveBeenCalledWith(groups);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
GroupsLogic.actions.getSearchResults();
- await expectedAsyncError(promise);
- await delay();
+ jest.advanceTimersByTime(TIMEOUT);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -298,21 +297,19 @@ describe('GroupsLogic', () => {
describe('fetchGroupUsers', () => {
it('calls API and sets values', async () => {
const setGroupUsersSpy = jest.spyOn(GroupsLogic.actions, 'setGroupUsers');
- const promise = Promise.resolve(users);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(users));
GroupsLogic.actions.fetchGroupUsers('123');
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/groups/123/group_users');
- await promise;
+ await nextTick();
expect(setGroupUsersSpy).toHaveBeenCalledWith(users);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
GroupsLogic.actions.fetchGroupUsers('123');
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -323,24 +320,22 @@ describe('GroupsLogic', () => {
const GROUP_NAME = 'new group';
GroupsLogic.actions.setNewGroupName(GROUP_NAME);
const setNewGroupSpy = jest.spyOn(GroupsLogic.actions, 'setNewGroup');
- const promise = Promise.resolve(groups[0]);
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.resolve(groups[0]));
GroupsLogic.actions.saveNewGroup();
expect(http.post).toHaveBeenCalledWith('/api/workplace_search/groups', {
body: JSON.stringify({ group_name: GROUP_NAME }),
headers,
});
- await promise;
+ await nextTick();
expect(setNewGroupSpy).toHaveBeenCalledWith(groups[0]);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.post.mockReturnValue(promise);
+ http.post.mockReturnValue(Promise.reject('this is an error'));
GroupsLogic.actions.saveNewGroup();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.test.tsx
new file mode 100644
index 0000000000000..4db5c60d5800d
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.test.tsx
@@ -0,0 +1,54 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { setMockValues } from '../../../../__mocks__';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiSwitch } from '@elastic/eui';
+
+import { PrivateSourcesTable } from './private_sources_table';
+
+describe('PrivateSourcesTable', () => {
+ beforeEach(() => {
+ setMockValues({ hasPlatinumLicense: true, isEnabled: true });
+ });
+
+ const props = {
+ sourceSection: { isEnabled: true, contentSources: [] },
+ updateSource: jest.fn(),
+ updateEnabled: jest.fn(),
+ };
+
+ it('renders', () => {
+ const wrapper = shallow();
+
+ expect(wrapper.find(EuiSwitch)).toHaveLength(1);
+ });
+
+ it('handles switches clicks', () => {
+ const wrapper = shallow(
+
+ );
+
+ const sectionSwitch = wrapper.find(EuiSwitch).first();
+ const sourceSwitch = wrapper.find(EuiSwitch).last();
+
+ const event = { target: { value: true } };
+ sectionSwitch.prop('onChange')(event as any);
+ sourceSwitch.prop('onChange')(event as any);
+
+ expect(props.updateEnabled).toHaveBeenCalled();
+ expect(props.updateSource).toHaveBeenCalled();
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.tsx
new file mode 100644
index 0000000000000..c767dfaba86f9
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/components/private_sources_table.tsx
@@ -0,0 +1,182 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import classNames from 'classnames';
+import { useValues } from 'kea';
+
+import {
+ EuiPanel,
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiSwitch,
+ EuiText,
+ EuiTable,
+ EuiTableBody,
+ EuiTableHeader,
+ EuiTableHeaderCell,
+ EuiTableRow,
+ EuiTableRowCell,
+ EuiSpacer,
+} from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
+
+import { LicensingLogic } from '../../../../shared/licensing';
+import { SecurityLogic, PrivateSourceSection } from '../security_logic';
+import {
+ REMOTE_SOURCES_TOGGLE_TEXT,
+ REMOTE_SOURCES_TABLE_DESCRIPTION,
+ REMOTE_SOURCES_EMPTY_TABLE_TITLE,
+ STANDARD_SOURCES_TOGGLE_TEXT,
+ STANDARD_SOURCES_TABLE_DESCRIPTION,
+ STANDARD_SOURCES_EMPTY_TABLE_TITLE,
+ SOURCE,
+} from '../../../constants';
+
+interface PrivateSourcesTableProps {
+ sourceType: 'remote' | 'standard';
+ sourceSection: PrivateSourceSection;
+ updateSource(sourceId: string, isEnabled: boolean): void;
+ updateEnabled(isEnabled: boolean): void;
+}
+
+const REMOTE_SOURCES_EMPTY_TABLE_DESCRIPTION = (
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.remoteSourcesEmptyTable.enabledStrong',
+ { defaultMessage: 'enabled by default' }
+ )}
+
+ ),
+ }}
+ />
+);
+
+const STANDARD_SOURCES_EMPTY_TABLE_DESCRIPTION = (
+
+ {i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.security.standardSourcesEmptyTable.notEnabledStrong',
+ { defaultMessage: 'not enabled by default' }
+ )}
+
+ ),
+ }}
+ />
+);
+
+export const PrivateSourcesTable: React.FC = ({
+ sourceType,
+ sourceSection: { isEnabled: sectionEnabled, contentSources },
+ updateSource,
+ updateEnabled,
+}) => {
+ const { hasPlatinumLicense } = useValues(LicensingLogic);
+ const { isEnabled } = useValues(SecurityLogic);
+
+ const isRemote = sourceType === 'remote';
+ const hasSources = contentSources.length > 0;
+ const panelDisabled = !isEnabled || !hasPlatinumLicense;
+ const sectionDisabled = !sectionEnabled;
+
+ const panelClass = classNames('euiPanel--outline euiPanel--noShadow', {
+ 'euiPanel--disabled': panelDisabled,
+ });
+
+ const tableClass = classNames({ 'euiTable--disabled': sectionDisabled });
+
+ const emptyState = (
+ <>
+
+
+
+
+ {isRemote ? REMOTE_SOURCES_EMPTY_TABLE_TITLE : STANDARD_SOURCES_EMPTY_TABLE_TITLE}
+
+
+
+ {isRemote
+ ? REMOTE_SOURCES_EMPTY_TABLE_DESCRIPTION
+ : STANDARD_SOURCES_EMPTY_TABLE_DESCRIPTION}
+
+
+ >
+ );
+
+ const sectionHeading = (
+
+
+
+ updateEnabled(e.target.checked)}
+ disabled={!isEnabled || !hasPlatinumLicense}
+ showLabel={false}
+ label={`${sourceType} Sources Toggle`}
+ data-test-subj={`${sourceType}EnabledToggle`}
+ compressed
+ />
+
+
+
+ {isRemote ? REMOTE_SOURCES_TOGGLE_TEXT : STANDARD_SOURCES_TOGGLE_TEXT}
+
+
+ {isRemote ? REMOTE_SOURCES_TABLE_DESCRIPTION : STANDARD_SOURCES_TABLE_DESCRIPTION}
+
+ {!hasSources && emptyState}
+
+
+ );
+
+ const sourcesTable = (
+ <>
+
+
+
+ {SOURCE}
+
+
+
+ {contentSources.map((source, i) => (
+
+ {source.name}
+
+ updateSource(source.id, e.target.checked)}
+ showLabel={false}
+ label={`${source.name} Toggle`}
+ data-test-subj={`${sourceType}SourceToggle`}
+ compressed
+ />
+
+
+ ))}
+
+
+ >
+ );
+
+ return (
+
+ {sectionHeading}
+ {hasSources && sourcesTable}
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/index.ts
new file mode 100644
index 0000000000000..a2db1bbc15a15
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { Security } from './security';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.test.tsx
new file mode 100644
index 0000000000000..bca0d5edc32d6
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.test.tsx
@@ -0,0 +1,112 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { setMockValues, setMockActions } from '../../../__mocks__';
+import { unmountHandler } from '../../../__mocks__/shallow_useeffect.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiSwitch, EuiConfirmModal } from '@elastic/eui';
+import { Loading } from '../../../shared/loading';
+
+import { ViewContentHeader } from '../../components/shared/view_content_header';
+import { Security } from './security';
+
+describe('Security', () => {
+ const initializeSourceRestrictions = jest.fn();
+ const updatePrivateSourcesEnabled = jest.fn();
+ const updateRemoteEnabled = jest.fn();
+ const updateRemoteSource = jest.fn();
+ const updateStandardEnabled = jest.fn();
+ const updateStandardSource = jest.fn();
+ const saveSourceRestrictions = jest.fn();
+ const resetState = jest.fn();
+
+ const mockValues = {
+ isEnabled: true,
+ remote: { isEnabled: true, contentSources: [] },
+ standard: { isEnabled: true, contentSources: [] },
+ dataLoading: false,
+ unsavedChanges: false,
+ hasPlatinumLicense: true,
+ };
+
+ beforeEach(() => {
+ setMockValues(mockValues);
+ setMockActions({
+ initializeSourceRestrictions,
+ updatePrivateSourcesEnabled,
+ updateRemoteEnabled,
+ updateRemoteSource,
+ updateStandardEnabled,
+ updateStandardSource,
+ saveSourceRestrictions,
+ resetState,
+ });
+ });
+
+ it('renders on Basic license', () => {
+ setMockValues({ ...mockValues, hasPlatinumLicense: false });
+ const wrapper = shallow();
+
+ expect(wrapper.find(ViewContentHeader)).toHaveLength(1);
+ expect(wrapper.find(EuiSwitch).prop('disabled')).toEqual(true);
+ });
+
+ it('renders on Platinum license', () => {
+ const wrapper = shallow();
+
+ expect(wrapper.find(ViewContentHeader)).toHaveLength(1);
+ expect(wrapper.find(EuiSwitch).prop('disabled')).toEqual(false);
+ });
+
+ it('returns Loading when loading', () => {
+ setMockValues({ ...mockValues, dataLoading: true });
+ const wrapper = shallow();
+
+ expect(wrapper.find(Loading)).toHaveLength(1);
+ });
+
+ it('handles window.onbeforeunload change', () => {
+ setMockValues({ ...mockValues, unsavedChanges: true });
+ shallow();
+
+ expect(window.onbeforeunload!({} as any)).toEqual(
+ 'Your private sources settings have not been saved. Are you sure you want to leave?'
+ );
+ });
+
+ it('handles window.onbeforeunload unmount', () => {
+ setMockValues({ ...mockValues, unsavedChanges: true });
+ shallow();
+
+ unmountHandler();
+
+ expect(window.onbeforeunload).toEqual(null);
+ });
+
+ it('handles switch click', () => {
+ const wrapper = shallow();
+
+ const privateSourcesSwitch = wrapper.find(EuiSwitch);
+ const event = { target: { checked: true } };
+ privateSourcesSwitch.prop('onChange')(event as any);
+
+ expect(updatePrivateSourcesEnabled).toHaveBeenCalled();
+ });
+
+ it('handles confirmModal submission', () => {
+ setMockValues({ ...mockValues, unsavedChanges: true });
+ const wrapper = shallow();
+
+ const header = wrapper.find(ViewContentHeader).dive();
+ header.find('[data-test-subj="SaveSettingsButton"]').prop('onClick')!({} as any);
+ const modal = wrapper.find(EuiConfirmModal);
+ modal.prop('onConfirm')!({} as any);
+
+ expect(saveSourceRestrictions).toHaveBeenCalled();
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx
new file mode 100644
index 0000000000000..41df1a1acc515
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security.tsx
@@ -0,0 +1,196 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useEffect, useState } from 'react';
+
+import classNames from 'classnames';
+import { useActions, useValues } from 'kea';
+
+import {
+ EuiButton,
+ EuiButtonEmpty,
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiSwitch,
+ EuiText,
+ EuiSpacer,
+ EuiPanel,
+ EuiConfirmModal,
+ EuiOverlayMask,
+} from '@elastic/eui';
+
+import { LicensingLogic } from '../../../shared/licensing';
+import { FlashMessages } from '../../../shared/flash_messages';
+import { LicenseCallout } from '../../components/shared/license_callout';
+import { Loading } from '../../../shared/loading';
+import { ViewContentHeader } from '../../components/shared/view_content_header';
+import { SecurityLogic } from './security_logic';
+
+import { PrivateSourcesTable } from './components/private_sources_table';
+
+import {
+ SECURITY_UNSAVED_CHANGES_MESSAGE,
+ RESET_BUTTON,
+ SAVE_SETTINGS_BUTTON,
+ SAVE_CHANGES_BUTTON,
+ KEEP_EDITING_BUTTON,
+ PRIVATE_SOURCES,
+ PRIVATE_SOURCES_DESCRIPTION,
+ PRIVATE_SOURCES_TOGGLE_DESCRIPTION,
+ PRIVATE_PLATINUM_LICENSE_CALLOUT,
+ CONFIRM_CHANGES_TEXT,
+ PRIVATE_SOURCES_UPDATE_CONFIRMATION_TEXT,
+} from '../../constants';
+
+export const Security: React.FC = () => {
+ const [confirmModalVisible, setConfirmModalVisibility] = useState(false);
+
+ const hideConfirmModal = () => setConfirmModalVisibility(false);
+ const showConfirmModal = () => setConfirmModalVisibility(true);
+
+ const { hasPlatinumLicense } = useValues(LicensingLogic);
+
+ const {
+ initializeSourceRestrictions,
+ updatePrivateSourcesEnabled,
+ updateRemoteEnabled,
+ updateRemoteSource,
+ updateStandardEnabled,
+ updateStandardSource,
+ saveSourceRestrictions,
+ resetState,
+ } = useActions(SecurityLogic);
+
+ const { isEnabled, remote, standard, dataLoading, unsavedChanges } = useValues(SecurityLogic);
+
+ useEffect(() => {
+ initializeSourceRestrictions();
+ }, []);
+
+ useEffect(() => {
+ window.onbeforeunload = unsavedChanges ? () => SECURITY_UNSAVED_CHANGES_MESSAGE : null;
+ return () => {
+ window.onbeforeunload = null;
+ };
+ }, [unsavedChanges]);
+
+ if (dataLoading) return ;
+
+ const panelClass = classNames('euiPanel--noShadow', {
+ 'euiPanel--disabled': !hasPlatinumLicense,
+ });
+
+ const savePrivateSources = () => {
+ saveSourceRestrictions();
+ hideConfirmModal();
+ };
+
+ const headerActions = (
+
+
+
+ {RESET_BUTTON}
+
+
+
+
+ {SAVE_SETTINGS_BUTTON}
+
+
+
+ );
+
+ const header = (
+ <>
+
+
+ >
+ );
+
+ const allSourcesToggle = (
+
+
+
+ updatePrivateSourcesEnabled(e.target.checked)}
+ disabled={!hasPlatinumLicense}
+ showLabel={false}
+ label="Private Sources Toggle"
+ data-test-subj="PrivateSourcesToggle"
+ />
+
+
+
+ {PRIVATE_SOURCES_TOGGLE_DESCRIPTION}
+
+
+
+
+ );
+
+ const platinumLicenseCallout = (
+ <>
+
+
+ >
+ );
+
+ const sourceTables = (
+ <>
+
+
+
+
+ >
+ );
+
+ const confirmModal = (
+
+
+ {PRIVATE_SOURCES_UPDATE_CONFIRMATION_TEXT}
+
+
+ );
+
+ return (
+ <>
+
+ {header}
+ {allSourcesToggle}
+ {!hasPlatinumLicense && platinumLicenseCallout}
+ {sourceTables}
+ {confirmModalVisible && confirmModal}
+ >
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.test.ts
new file mode 100644
index 0000000000000..abb1308081f0c
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.test.ts
@@ -0,0 +1,169 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { LogicMounter } from '../../../__mocks__/kea.mock';
+import { mockHttpValues, mockFlashMessageHelpers } from '../../../__mocks__';
+import { SecurityLogic } from './security_logic';
+import { nextTick } from '@kbn/test/jest';
+
+describe('SecurityLogic', () => {
+ const { http } = mockHttpValues;
+ const { flashAPIErrors } = mockFlashMessageHelpers;
+ const { mount } = new LogicMounter(SecurityLogic);
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mount();
+ });
+
+ const defaultValues = {
+ dataLoading: true,
+ cachedServerState: {},
+ isEnabled: false,
+ remote: {},
+ standard: {},
+ unsavedChanges: true,
+ };
+
+ const serverProps = {
+ isEnabled: true,
+ remote: {
+ isEnabled: true,
+ contentSources: [{ id: 'gmail', name: 'Gmail', isEnabled: true }],
+ },
+ standard: {
+ isEnabled: true,
+ contentSources: [{ id: 'one_drive', name: 'OneDrive', isEnabled: true }],
+ },
+ };
+
+ it('has expected default values', () => {
+ expect(SecurityLogic.values).toEqual(defaultValues);
+ });
+
+ describe('actions', () => {
+ it('setServerProps', () => {
+ SecurityLogic.actions.setServerProps(serverProps);
+
+ expect(SecurityLogic.values.isEnabled).toEqual(true);
+ });
+
+ it('setSourceRestrictionsUpdated', () => {
+ SecurityLogic.actions.setSourceRestrictionsUpdated(serverProps);
+
+ expect(SecurityLogic.values.isEnabled).toEqual(true);
+ });
+
+ it('updatePrivateSourcesEnabled', () => {
+ SecurityLogic.actions.updatePrivateSourcesEnabled(false);
+
+ expect(SecurityLogic.values.isEnabled).toEqual(false);
+ });
+
+ it('updateRemoteEnabled', () => {
+ SecurityLogic.actions.updateRemoteEnabled(false);
+
+ expect(SecurityLogic.values.remote.isEnabled).toEqual(false);
+ });
+
+ it('updateStandardEnabled', () => {
+ SecurityLogic.actions.updateStandardEnabled(false);
+
+ expect(SecurityLogic.values.standard.isEnabled).toEqual(false);
+ });
+
+ it('updateRemoteSource', () => {
+ SecurityLogic.actions.setServerProps(serverProps);
+ SecurityLogic.actions.updateRemoteSource('gmail', false);
+
+ expect(SecurityLogic.values.remote.contentSources[0].isEnabled).toEqual(false);
+ });
+
+ it('updateStandardSource', () => {
+ SecurityLogic.actions.setServerProps(serverProps);
+ SecurityLogic.actions.updateStandardSource('one_drive', false);
+
+ expect(SecurityLogic.values.standard.contentSources[0].isEnabled).toEqual(false);
+ });
+ });
+
+ describe('selectors', () => {
+ describe('unsavedChanges', () => {
+ it('returns true while loading', () => {
+ expect(SecurityLogic.values.unsavedChanges).toEqual(true);
+ });
+
+ it('returns false after loading', () => {
+ SecurityLogic.actions.setServerProps(serverProps);
+
+ expect(SecurityLogic.values.unsavedChanges).toEqual(false);
+ });
+ });
+ });
+
+ describe('listeners', () => {
+ describe('initializeSourceRestrictions', () => {
+ it('calls API and sets values', async () => {
+ const setServerPropsSpy = jest.spyOn(SecurityLogic.actions, 'setServerProps');
+ http.get.mockReturnValue(Promise.resolve(serverProps));
+ SecurityLogic.actions.initializeSourceRestrictions();
+
+ expect(http.get).toHaveBeenCalledWith(
+ '/api/workplace_search/org/security/source_restrictions'
+ );
+ await nextTick();
+ expect(setServerPropsSpy).toHaveBeenCalledWith(serverProps);
+ });
+
+ it('handles error', async () => {
+ http.get.mockReturnValue(Promise.reject('this is an error'));
+
+ SecurityLogic.actions.initializeSourceRestrictions();
+ try {
+ await nextTick();
+ } catch {
+ expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
+ }
+ });
+ });
+
+ describe('saveSourceRestrictions', () => {
+ it('calls API and sets values', async () => {
+ http.patch.mockReturnValue(Promise.resolve(serverProps));
+ SecurityLogic.actions.setSourceRestrictionsUpdated(serverProps);
+ SecurityLogic.actions.saveSourceRestrictions();
+
+ expect(http.patch).toHaveBeenCalledWith(
+ '/api/workplace_search/org/security/source_restrictions',
+ {
+ body: JSON.stringify(serverProps),
+ }
+ );
+ });
+
+ it('handles error', async () => {
+ http.patch.mockReturnValue(Promise.reject('this is an error'));
+
+ SecurityLogic.actions.saveSourceRestrictions();
+ try {
+ await nextTick();
+ } catch {
+ expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
+ }
+ });
+ });
+
+ describe('resetState', () => {
+ it('calls API and sets values', async () => {
+ SecurityLogic.actions.setServerProps(serverProps);
+ SecurityLogic.actions.updatePrivateSourcesEnabled(false);
+ SecurityLogic.actions.resetState();
+
+ expect(SecurityLogic.values.isEnabled).toEqual(true);
+ });
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts
new file mode 100644
index 0000000000000..df843b330d411
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/security/security_logic.ts
@@ -0,0 +1,181 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { cloneDeep } from 'lodash';
+import { isEqual } from 'lodash';
+
+import { kea, MakeLogicType } from 'kea';
+
+import {
+ clearFlashMessages,
+ setSuccessMessage,
+ flashAPIErrors,
+} from '../../../shared/flash_messages';
+import { HttpLogic } from '../../../shared/http';
+import { AppLogic } from '../../app_logic';
+
+import { SOURCE_RESTRICTIONS_SUCCESS_MESSAGE } from '../../constants';
+
+export interface PrivateSource {
+ id: string;
+ name: string;
+ isEnabled: boolean;
+}
+
+export interface PrivateSourceSection {
+ isEnabled: boolean;
+ contentSources: PrivateSource[];
+}
+
+export interface SecurityServerProps {
+ isEnabled: boolean;
+ remote: PrivateSourceSection;
+ standard: PrivateSourceSection;
+}
+
+interface SecurityValues extends SecurityServerProps {
+ dataLoading: boolean;
+ unsavedChanges: boolean;
+ cachedServerState: SecurityServerProps;
+}
+
+interface SecurityActions {
+ setServerProps(serverProps: SecurityServerProps): SecurityServerProps;
+ setSourceRestrictionsUpdated(serverProps: SecurityServerProps): SecurityServerProps;
+ initializeSourceRestrictions(): void;
+ saveSourceRestrictions(): void;
+ updatePrivateSourcesEnabled(isEnabled: boolean): { isEnabled: boolean };
+ updateRemoteEnabled(isEnabled: boolean): { isEnabled: boolean };
+ updateRemoteSource(
+ sourceId: string,
+ isEnabled: boolean
+ ): { sourceId: string; isEnabled: boolean };
+ updateStandardEnabled(isEnabled: boolean): { isEnabled: boolean };
+ updateStandardSource(
+ sourceId: string,
+ isEnabled: boolean
+ ): { sourceId: string; isEnabled: boolean };
+ resetState(): void;
+}
+
+const route = '/api/workplace_search/org/security/source_restrictions';
+
+export const SecurityLogic = kea>({
+ path: ['enterprise_search', 'workplace_search', 'security_logic'],
+ actions: {
+ setServerProps: (serverProps: SecurityServerProps) => serverProps,
+ setSourceRestrictionsUpdated: (serverProps: SecurityServerProps) => serverProps,
+ initializeSourceRestrictions: () => true,
+ saveSourceRestrictions: () => null,
+ updatePrivateSourcesEnabled: (isEnabled: boolean) => ({ isEnabled }),
+ updateRemoteEnabled: (isEnabled: boolean) => ({ isEnabled }),
+ updateRemoteSource: (sourceId: string, isEnabled: boolean) => ({ sourceId, isEnabled }),
+ updateStandardEnabled: (isEnabled: boolean) => ({ isEnabled }),
+ updateStandardSource: (sourceId: string, isEnabled: boolean) => ({ sourceId, isEnabled }),
+ resetState: () => null,
+ },
+ reducers: {
+ dataLoading: [
+ true,
+ {
+ setServerProps: () => false,
+ },
+ ],
+ cachedServerState: [
+ {} as SecurityServerProps,
+ {
+ setServerProps: (_, serverProps) => cloneDeep(serverProps),
+ setSourceRestrictionsUpdated: (_, serverProps) => cloneDeep(serverProps),
+ },
+ ],
+ isEnabled: [
+ false,
+ {
+ setServerProps: (_, { isEnabled }) => isEnabled,
+ setSourceRestrictionsUpdated: (_, { isEnabled }) => isEnabled,
+ updatePrivateSourcesEnabled: (_, { isEnabled }) => isEnabled,
+ },
+ ],
+ remote: [
+ {} as PrivateSourceSection,
+ {
+ setServerProps: (_, { remote }) => remote,
+ setSourceRestrictionsUpdated: (_, { remote }) => remote,
+ updateRemoteEnabled: (state, { isEnabled }) => ({ ...state, isEnabled }),
+ updateRemoteSource: (state, { sourceId, isEnabled }) =>
+ updateSourceEnabled(state, sourceId, isEnabled),
+ },
+ ],
+ standard: [
+ {} as PrivateSourceSection,
+ {
+ setServerProps: (_, { standard }) => standard,
+ setSourceRestrictionsUpdated: (_, { standard }) => standard,
+ updateStandardEnabled: (state, { isEnabled }) => ({ ...state, isEnabled }),
+ updateStandardSource: (state, { sourceId, isEnabled }) =>
+ updateSourceEnabled(state, sourceId, isEnabled),
+ },
+ ],
+ },
+ selectors: ({ selectors }) => ({
+ unsavedChanges: [
+ () => [
+ selectors.cachedServerState,
+ selectors.isEnabled,
+ selectors.remote,
+ selectors.standard,
+ ],
+ (cached, isEnabled, remote, standard) =>
+ cached.isEnabled !== isEnabled ||
+ !isEqual(cached.remote, remote) ||
+ !isEqual(cached.standard, standard),
+ ],
+ }),
+ listeners: ({ actions, values }) => ({
+ initializeSourceRestrictions: async () => {
+ const { http } = HttpLogic.values;
+
+ try {
+ const response = await http.get(route);
+ actions.setServerProps(response);
+ } catch (e) {
+ flashAPIErrors(e);
+ }
+ },
+ saveSourceRestrictions: async () => {
+ const { isEnabled, remote, standard } = values;
+ const serverData = { isEnabled, remote, standard };
+ const body = JSON.stringify(serverData);
+ const { http } = HttpLogic.values;
+
+ try {
+ const response = await http.patch(route, { body });
+ actions.setSourceRestrictionsUpdated(response);
+ setSuccessMessage(SOURCE_RESTRICTIONS_SUCCESS_MESSAGE);
+ AppLogic.actions.setSourceRestriction(isEnabled);
+ } catch (e) {
+ flashAPIErrors(e);
+ }
+ },
+ resetState: () => {
+ actions.setServerProps(cloneDeep(values.cachedServerState));
+ clearFlashMessages();
+ },
+ }),
+});
+
+const updateSourceEnabled = (
+ section: PrivateSourceSection,
+ id: string,
+ isEnabled: boolean
+): PrivateSourceSection => {
+ const updatedSection = { ...section };
+ const sources = updatedSection.contentSources;
+ const sourceIndex = sources.findIndex((source) => source.id === id);
+ updatedSection.contentSources[sourceIndex] = { ...sources[sourceIndex], isEnabled };
+
+ return updatedSection;
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts
index aaeae08d552d4..e21b62b500067 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts
@@ -6,12 +6,9 @@
import { LogicMounter } from '../../../__mocks__/kea.mock';
-import {
- mockFlashMessageHelpers,
- mockHttpValues,
- expectedAsyncError,
- mockKibanaValues,
-} from '../../../__mocks__';
+import { mockFlashMessageHelpers, mockHttpValues, mockKibanaValues } from '../../../__mocks__';
+
+import { nextTick } from '@kbn/test/jest';
import { configuredSources, oauthApplication } from '../../__mocks__/content_sources.mock';
@@ -89,20 +86,18 @@ describe('SettingsLogic', () => {
describe('initializeSettings', () => {
it('calls API and sets values', async () => {
const setServerPropsSpy = jest.spyOn(SettingsLogic.actions, 'setServerProps');
- const promise = Promise.resolve(configuredSources);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(configuredSources));
SettingsLogic.actions.initializeSettings();
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/org/settings');
- await promise;
+ await nextTick();
expect(setServerPropsSpy).toHaveBeenCalledWith(configuredSources);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
SettingsLogic.actions.initializeSettings();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -114,20 +109,18 @@ describe('SettingsLogic', () => {
SettingsLogic.actions,
'onInitializeConnectors'
);
- const promise = Promise.resolve(serverProps);
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.resolve(serverProps));
SettingsLogic.actions.initializeConnectors();
expect(http.get).toHaveBeenCalledWith('/api/workplace_search/org/settings/connectors');
- await promise;
+ await nextTick();
expect(onInitializeConnectorsSpy).toHaveBeenCalledWith(serverProps);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.get.mockReturnValue(promise);
+ http.get.mockReturnValue(Promise.reject('this is an error'));
SettingsLogic.actions.initializeConnectors();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -138,25 +131,23 @@ describe('SettingsLogic', () => {
const NAME = 'updated name';
SettingsLogic.actions.onOrgNameInputChange(NAME);
const setUpdatedNameSpy = jest.spyOn(SettingsLogic.actions, 'setUpdatedName');
- const promise = Promise.resolve({ organizationName: NAME });
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve({ organizationName: NAME }));
SettingsLogic.actions.updateOrgName();
expect(http.put).toHaveBeenCalledWith('/api/workplace_search/org/settings/customize', {
body: JSON.stringify({ name: NAME }),
});
- await promise;
+ await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(ORG_UPDATED_MESSAGE);
expect(setUpdatedNameSpy).toHaveBeenCalledWith({ organizationName: NAME });
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('this is an error'));
SettingsLogic.actions.updateOrgName();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
});
@@ -168,8 +159,7 @@ describe('SettingsLogic', () => {
SettingsLogic.actions,
'setUpdatedOauthApplication'
);
- const promise = Promise.resolve({ oauthApplication });
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.resolve({ oauthApplication }));
SettingsLogic.actions.setOauthApplication(oauthApplication);
SettingsLogic.actions.updateOauthApplication();
@@ -183,16 +173,15 @@ describe('SettingsLogic', () => {
}),
}
);
- await promise;
+ await nextTick();
expect(setUpdatedOauthApplicationSpy).toHaveBeenCalledWith({ oauthApplication });
expect(setSuccessMessage).toHaveBeenCalledWith(OAUTH_APP_UPDATED_MESSAGE);
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.put.mockReturnValue(promise);
+ http.put.mockReturnValue(Promise.reject('this is an error'));
SettingsLogic.actions.updateOauthApplication();
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
@@ -203,20 +192,18 @@ describe('SettingsLogic', () => {
const NAME = 'baz';
it('calls API and sets values', async () => {
- const promise = Promise.resolve({});
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.resolve({}));
SettingsLogic.actions.deleteSourceConfig(SERVICE_TYPE, NAME);
- await promise;
+ await nextTick();
expect(navigateToUrl).toHaveBeenCalledWith('/settings/connectors');
expect(setQueuedSuccessMessage).toHaveBeenCalled();
});
it('handles error', async () => {
- const promise = Promise.reject('this is an error');
- http.delete.mockReturnValue(promise);
+ http.delete.mockReturnValue(Promise.reject('this is an error'));
SettingsLogic.actions.deleteSourceConfig(SERVICE_TYPE, NAME);
- await expectedAsyncError(promise);
+ await nextTick();
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts
index 99445108b315a..f2792be8e6535 100644
--- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts
+++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/index.ts
@@ -10,10 +10,12 @@ import { registerOverviewRoute } from './overview';
import { registerGroupsRoutes } from './groups';
import { registerSourcesRoutes } from './sources';
import { registerSettingsRoutes } from './settings';
+import { registerSecurityRoutes } from './security';
export const registerWorkplaceSearchRoutes = (dependencies: RouteDependencies) => {
registerOverviewRoute(dependencies);
registerGroupsRoutes(dependencies);
registerSourcesRoutes(dependencies);
registerSettingsRoutes(dependencies);
+ registerSecurityRoutes(dependencies);
};
diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.test.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.test.ts
new file mode 100644
index 0000000000000..12f84278e9ead
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.test.ts
@@ -0,0 +1,108 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { MockRouter, mockRequestHandler, mockDependencies } from '../../__mocks__';
+
+import { registerSecurityRoute, registerSecuritySourceRestrictionsRoute } from './security';
+
+describe('security routes', () => {
+ describe('GET /api/workplace_search/org/security', () => {
+ let mockRouter: MockRouter;
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+
+ mockRouter = new MockRouter({
+ method: 'get',
+ path: '/api/workplace_search/org/security',
+ });
+
+ registerSecurityRoute({
+ ...mockDependencies,
+ router: mockRouter.router,
+ });
+ });
+
+ it('creates a request handler', () => {
+ mockRouter.callRoute({});
+
+ expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
+ path: '/ws/org/security',
+ });
+ });
+ });
+
+ describe('GET /api/workplace_search/org/security/source_restrictions', () => {
+ let mockRouter: MockRouter;
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+
+ mockRouter = new MockRouter({
+ method: 'get',
+ path: '/api/workplace_search/org/security/source_restrictions',
+ payload: 'body',
+ });
+
+ registerSecuritySourceRestrictionsRoute({
+ ...mockDependencies,
+ router: mockRouter.router,
+ });
+ });
+
+ it('creates a request handler', () => {
+ mockRouter.callRoute({});
+
+ expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
+ path: '/ws/org/security/source_restrictions',
+ });
+ });
+ });
+
+ describe('PATCH /api/workplace_search/org/security/source_restrictions', () => {
+ let mockRouter: MockRouter;
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+
+ mockRouter = new MockRouter({
+ method: 'patch',
+ path: '/api/workplace_search/org/security/source_restrictions',
+ payload: 'body',
+ });
+
+ registerSecuritySourceRestrictionsRoute({
+ ...mockDependencies,
+ router: mockRouter.router,
+ });
+ });
+
+ it('creates a request handler', () => {
+ expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({
+ path: '/ws/org/security/source_restrictions',
+ });
+ });
+
+ describe('validates', () => {
+ it('correctly', () => {
+ const request = {
+ body: {
+ isEnabled: true,
+ remote: {
+ isEnabled: true,
+ contentSources: [{ id: 'gmail', name: 'Gmail', isEnabled: true }],
+ },
+ standard: {
+ isEnabled: false,
+ contentSources: [{ id: 'dropbox', name: 'Dropbox', isEnabled: false }],
+ },
+ },
+ };
+ mockRouter.shouldValidate(request);
+ });
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.ts
new file mode 100644
index 0000000000000..0aa218dfc2883
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/security.ts
@@ -0,0 +1,78 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { schema } from '@kbn/config-schema';
+
+import { RouteDependencies } from '../../plugin';
+
+export function registerSecurityRoute({
+ router,
+ enterpriseSearchRequestHandler,
+}: RouteDependencies) {
+ router.get(
+ {
+ path: '/api/workplace_search/org/security',
+ validate: false,
+ },
+ enterpriseSearchRequestHandler.createRequest({
+ path: '/ws/org/security',
+ })
+ );
+}
+
+export function registerSecuritySourceRestrictionsRoute({
+ router,
+ enterpriseSearchRequestHandler,
+}: RouteDependencies) {
+ router.get(
+ {
+ path: '/api/workplace_search/org/security/source_restrictions',
+ validate: false,
+ },
+ enterpriseSearchRequestHandler.createRequest({
+ path: '/ws/org/security/source_restrictions',
+ })
+ );
+
+ router.patch(
+ {
+ path: '/api/workplace_search/org/security/source_restrictions',
+ validate: {
+ body: schema.object({
+ isEnabled: schema.boolean(),
+ remote: schema.object({
+ isEnabled: schema.boolean(),
+ contentSources: schema.arrayOf(
+ schema.object({
+ isEnabled: schema.boolean(),
+ id: schema.string(),
+ name: schema.string(),
+ })
+ ),
+ }),
+ standard: schema.object({
+ isEnabled: schema.boolean(),
+ contentSources: schema.arrayOf(
+ schema.object({
+ isEnabled: schema.boolean(),
+ id: schema.string(),
+ name: schema.string(),
+ })
+ ),
+ }),
+ }),
+ },
+ },
+ enterpriseSearchRequestHandler.createRequest({
+ path: '/ws/org/security/source_restrictions',
+ })
+ );
+}
+
+export const registerSecurityRoutes = (dependencies: RouteDependencies) => {
+ registerSecurityRoute(dependencies);
+ registerSecuritySourceRestrictionsRoute(dependencies);
+};
diff --git a/x-pack/plugins/enterprise_search/tsconfig.json b/x-pack/plugins/enterprise_search/tsconfig.json
new file mode 100644
index 0000000000000..6b4c50770b49f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/tsconfig.json
@@ -0,0 +1,27 @@
+{
+ "extends": "../../../tsconfig.base.json",
+ "compilerOptions": {
+ "composite": true,
+ "outDir": "./target/types",
+ "emitDeclarationOnly": true,
+ "declaration": true,
+ "declarationMap": true
+ },
+ "include": [
+ "common/**/*",
+ "public/**/*",
+ "server/**/*",
+ "../../../typings/**/*",
+ ],
+ "references": [
+ { "path": "../../../src/core/tsconfig.json" },
+ { "path": "../../../src/plugins/charts/tsconfig.json" },
+ { "path": "../../../src/plugins/home/tsconfig.json" },
+ { "path": "../../../src/plugins/usage_collection/tsconfig.json" },
+ { "path": "../cloud/tsconfig.json" },
+ { "path": "../features/tsconfig.json" },
+ { "path": "../licensing/tsconfig.json" },
+ { "path": "../security/tsconfig.json" },
+ { "path": "../spaces/tsconfig.json" },
+ ]
+}
diff --git a/x-pack/plugins/fleet/server/services/epm/registry/registry_url.ts b/x-pack/plugins/fleet/server/services/epm/registry/registry_url.ts
index efc25cc2efb5d..4f17a2b88670a 100644
--- a/x-pack/plugins/fleet/server/services/epm/registry/registry_url.ts
+++ b/x-pack/plugins/fleet/server/services/epm/registry/registry_url.ts
@@ -11,12 +11,10 @@ import { appContextService, licenseService } from '../../';
const PRODUCTION_REGISTRY_URL_CDN = 'https://epr.elastic.co';
// const STAGING_REGISTRY_URL_CDN = 'https://epr-staging.elastic.co';
-// const EXPERIMENTAL_REGISTRY_URL_CDN = 'https://epr-experimental.elastic.co/';
const SNAPSHOT_REGISTRY_URL_CDN = 'https://epr-snapshot.elastic.co';
// const PRODUCTION_REGISTRY_URL_NO_CDN = 'https://epr.ea-web.elastic.dev';
// const STAGING_REGISTRY_URL_NO_CDN = 'https://epr-staging.ea-web.elastic.dev';
-// const EXPERIMENTAL_REGISTRY_URL_NO_CDN = 'https://epr-experimental.ea-web.elastic.dev/';
// const SNAPSHOT_REGISTRY_URL_NO_CDN = 'https://epr-snapshot.ea-web.elastic.dev';
const getDefaultRegistryUrl = (): string => {
diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx
index 64b654b030236..d9256ec916ec8 100644
--- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx
+++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.helpers.tsx
@@ -251,6 +251,7 @@ export const setup = async (arg?: { appServicesContext: Partial exists('timelineHotPhaseRolloverToolTip'),
hasHotPhase: () => exists('ilmTimelineHotPhase'),
hasWarmPhase: () => exists('ilmTimelineWarmPhase'),
hasColdPhase: () => exists('ilmTimelineColdPhase'),
diff --git a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
index bb96e8b4df239..05793a4bed581 100644
--- a/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
+++ b/x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
@@ -843,5 +843,13 @@ describe('', () => {
expect(actions.timeline.hasColdPhase()).toBe(true);
expect(actions.timeline.hasDeletePhase()).toBe(true);
});
+
+ test('show and hide rollover indicator on timeline', async () => {
+ const { actions } = testBed;
+ expect(actions.timeline.hasRolloverIndicator()).toBe(true);
+ await actions.hot.toggleDefaultRollover(false);
+ await actions.hot.toggleRollover(false);
+ expect(actions.timeline.hasRolloverIndicator()).toBe(false);
+ });
});
});
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx
index fb7c9a80acba0..02de47f8c56ef 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/hot_phase/hot_phase.tsx
@@ -16,6 +16,7 @@ import {
EuiTextColor,
EuiSwitch,
EuiIconTip,
+ EuiIcon,
} from '@elastic/eui';
import { useFormData, UseField, SelectField, NumericField } from '../../../../../../shared_imports';
@@ -80,6 +81,10 @@ export const HotPhase: FunctionComponent = () => {
+
+
+ {i18nTexts.editPolicy.rolloverOffsetsHotPhaseTiming}
+
path={isUsingDefaultRolloverPath}>
{(field) => (
<>
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/index.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/index.ts
new file mode 100644
index 0000000000000..1c9d5e1abc316
--- /dev/null
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { TimelinePhaseText } from './timeline_phase_text';
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/timeline_phase_text.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/timeline_phase_text.tsx
new file mode 100644
index 0000000000000..a44e0f2407c52
--- /dev/null
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/components/timeline_phase_text.tsx
@@ -0,0 +1,28 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { FunctionComponent, ReactNode } from 'react';
+import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
+
+export const TimelinePhaseText: FunctionComponent<{
+ phaseName: ReactNode | string;
+ durationInPhase?: ReactNode | string;
+}> = ({ phaseName, durationInPhase }) => (
+
+
+
+ {phaseName}
+
+
+
+ {typeof durationInPhase === 'string' ? (
+ {durationInPhase}
+ ) : (
+ durationInPhase
+ )}
+
+
+);
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/index.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/index.ts
index 4664429db37d7..7bcaa6584edf0 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/index.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/index.ts
@@ -3,4 +3,4 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-export { Timeline } from './timeline';
+export { Timeline } from './timeline.container';
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.container.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.container.tsx
new file mode 100644
index 0000000000000..75f53fcb25091
--- /dev/null
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.container.tsx
@@ -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;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { FunctionComponent } from 'react';
+
+import { useFormData } from '../../../../../shared_imports';
+
+import { formDataToAbsoluteTimings } from '../../lib';
+
+import { useConfigurationIssues } from '../../form';
+
+import { FormInternal } from '../../types';
+
+import { Timeline as ViewComponent } from './timeline';
+
+export const Timeline: FunctionComponent = () => {
+ const [formData] = useFormData();
+ const timings = formDataToAbsoluteTimings(formData);
+ const { isUsingRollover } = useConfigurationIssues();
+ return (
+
+ );
+};
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.scss b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.scss
index 452221a29a991..7d65d2cd6b212 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.scss
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.scss
@@ -84,4 +84,8 @@ $ilmDeletePhaseColor: shadeOrTint($euiColorVis5, 40%, 40%);
background-color: $euiColorVis1;
}
}
+
+ &__rolloverIcon {
+ display: inline-block;
+ }
}
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx
index 40bab9c676de2..2e2db88e1384d 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/timeline/timeline.tsx
@@ -4,9 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
-import React, { FunctionComponent, useMemo } from 'react';
+import React, { FunctionComponent, memo } from 'react';
import {
- EuiText,
EuiIcon,
EuiIconProps,
EuiFlexGroup,
@@ -16,18 +15,19 @@ import {
} from '@elastic/eui';
import { PhasesExceptDelete } from '../../../../../../common/types';
-import { useFormData } from '../../../../../shared_imports';
-
-import { FormInternal } from '../../types';
import {
- calculateRelativeTimingMs,
+ calculateRelativeFromAbsoluteMilliseconds,
normalizeTimingsToHumanReadable,
PhaseAgeInMilliseconds,
+ AbsoluteTimings,
} from '../../lib';
import './timeline.scss';
import { InfinityIconSvg } from './infinity_icon.svg';
+import { TimelinePhaseText } from './components';
+
+const exists = (v: unknown) => v != null;
const InfinityIcon: FunctionComponent> = (props) => (
@@ -56,6 +56,13 @@ const i18nTexts = {
hotPhase: i18n.translate('xpack.indexLifecycleMgmt.timeline.hotPhaseSectionTitle', {
defaultMessage: 'Hot phase',
}),
+ rolloverTooltip: i18n.translate(
+ 'xpack.indexLifecycleMgmt.timeline.hotPhaseRolloverToolTipContent',
+ {
+ defaultMessage:
+ 'How long it takes to reach the rollover criteria in the hot phase can vary. Data moves to the next phase when the time since rollover reaches the minimum age.',
+ }
+ ),
warmPhase: i18n.translate('xpack.indexLifecycleMgmt.timeline.warmPhaseSectionTitle', {
defaultMessage: 'Warm phase',
}),
@@ -88,121 +95,136 @@ const calculateWidths = (inputs: PhaseAgeInMilliseconds) => {
};
};
-const TimelinePhaseText: FunctionComponent<{
- phaseName: string;
- durationInPhase?: React.ReactNode | string;
-}> = ({ phaseName, durationInPhase }) => (
-
-
-
- {phaseName}
-
-
-
- {typeof durationInPhase === 'string' ? (
- {durationInPhase}
- ) : (
- durationInPhase
- )}
-
-
-);
-
-export const Timeline: FunctionComponent = () => {
- const [formData] = useFormData();
-
- const phaseTimingInMs = useMemo(() => {
- return calculateRelativeTimingMs(formData);
- }, [formData]);
+interface Props {
+ hasDeletePhase: boolean;
+ /**
+ * For now we assume the hot phase does not have a min age
+ */
+ hotPhaseMinAge: undefined;
+ isUsingRollover: boolean;
+ warmPhaseMinAge?: string;
+ coldPhaseMinAge?: string;
+ deletePhaseMinAge?: string;
+}
- const humanReadableTimings = useMemo(() => normalizeTimingsToHumanReadable(phaseTimingInMs), [
- phaseTimingInMs,
- ]);
-
- const widths = calculateWidths(phaseTimingInMs);
-
- const getDurationInPhaseContent = (phase: PhasesExceptDelete): string | React.ReactNode =>
- phaseTimingInMs.phases[phase] === Infinity ? (
-
- ) : (
- humanReadableTimings[phase]
- );
-
- return (
-
-
-
-
- {i18n.translate('xpack.indexLifecycleMgmt.timeline.title', {
- defaultMessage: 'Policy Timeline',
- })}
-
-
-
-
- {
- if (el) {
- el.style.setProperty('--ilm-timeline-hot-phase-width', widths.hot);
- el.style.setProperty('--ilm-timeline-warm-phase-width', widths.warm ?? null);
- el.style.setProperty('--ilm-timeline-cold-phase-width', widths.cold ?? null);
- }
- }}
- >
-
-
-
- {/* These are the actual color bars for the timeline */}
-
- {formData._meta?.warm.enabled && (
+/**
+ * Display a timeline given ILM policy phase information. This component is re-usable and memo-ized
+ * and should not rely directly on any application-specific context.
+ */
+export const Timeline: FunctionComponent
= memo(
+ ({ hasDeletePhase, isUsingRollover, ...phasesMinAge }) => {
+ const absoluteTimings: AbsoluteTimings = {
+ hot: { min_age: phasesMinAge.hotPhaseMinAge },
+ warm: phasesMinAge.warmPhaseMinAge ? { min_age: phasesMinAge.warmPhaseMinAge } : undefined,
+ cold: phasesMinAge.coldPhaseMinAge ? { min_age: phasesMinAge.coldPhaseMinAge } : undefined,
+ delete: phasesMinAge.deletePhaseMinAge
+ ? { min_age: phasesMinAge.deletePhaseMinAge }
+ : undefined,
+ };
+
+ const phaseAgeInMilliseconds = calculateRelativeFromAbsoluteMilliseconds(absoluteTimings);
+ const humanReadableTimings = normalizeTimingsToHumanReadable(phaseAgeInMilliseconds);
+
+ const widths = calculateWidths(phaseAgeInMilliseconds);
+
+ const getDurationInPhaseContent = (phase: PhasesExceptDelete): string | React.ReactNode =>
+ phaseAgeInMilliseconds.phases[phase] === Infinity ? (
+
+ ) : (
+ humanReadableTimings[phase]
+ );
+
+ return (
+
+
+
+
+ {i18n.translate('xpack.indexLifecycleMgmt.timeline.title', {
+ defaultMessage: 'Policy Timeline',
+ })}
+
+
+
+
+ {
+ if (el) {
+ el.style.setProperty('--ilm-timeline-hot-phase-width', widths.hot);
+ el.style.setProperty('--ilm-timeline-warm-phase-width', widths.warm ?? null);
+ el.style.setProperty('--ilm-timeline-cold-phase-width', widths.cold ?? null);
+ }
+ }}
+ >
+
+
+
+ {/* These are the actual color bars for the timeline */}
-
+
+ {i18nTexts.hotPhase}
+
+
+
+
+ >
+ ) : (
+ i18nTexts.hotPhase
+ )
+ }
+ durationInPhase={getDurationInPhaseContent('hot')}
/>
- )}
- {formData._meta?.cold.enabled && (
+ {exists(phaseAgeInMilliseconds.phases.warm) && (
+
+ )}
+ {exists(phaseAgeInMilliseconds.phases.cold) && (
+
+ )}
+
+
+ {hasDeletePhase && (
+
- )}
-
-
- {formData._meta?.delete.enabled && (
-
-
-
-
-
- )}
-
-
-
-
- );
-};
+
+ )}
+
+
+
+
+ );
+ }
+);
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/i18n_texts.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/i18n_texts.ts
index 71085a6d7a2b8..cf8c92b8333d0 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/i18n_texts.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/i18n_texts.ts
@@ -11,6 +11,13 @@ export const i18nTexts = {
shrinkLabel: i18n.translate('xpack.indexLifecycleMgmt.shrink.indexFieldLabel', {
defaultMessage: 'Shrink index',
}),
+ rolloverOffsetsHotPhaseTiming: i18n.translate(
+ 'xpack.indexLifecycleMgmt.rollover.rolloverOffsetsPhaseTimingDescription',
+ {
+ defaultMessage:
+ 'How long it takes to reach the rollover criteria in the hot phase can vary. Data moves to the next phase when the time since rollover reaches the minimum age.',
+ }
+ ),
searchableSnapshotInHotPhase: {
searchableSnapshotDisallowed: {
calloutTitle: i18n.translate(
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.test.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.test.ts
index 28910871fa33b..405de2b55a2f7 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.test.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.test.ts
@@ -4,13 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { flow } from 'fp-ts/function';
import { deserializer } from '../form';
import {
+ formDataToAbsoluteTimings,
+ calculateRelativeFromAbsoluteMilliseconds,
absoluteTimingToRelativeTiming,
- calculateRelativeTimingMs,
} from './absolute_timing_to_relative_timing';
+export const calculateRelativeTimingMs = flow(
+ formDataToAbsoluteTimings,
+ calculateRelativeFromAbsoluteMilliseconds
+);
+
describe('Conversion of absolute policy timing to relative timing', () => {
describe('calculateRelativeTimingMs', () => {
describe('policy that never deletes data (keep forever)', () => {
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.ts
index 2f37608b2d7ae..a44863b2f1ce2 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/absolute_timing_to_relative_timing.ts
@@ -14,16 +14,21 @@
*
* This code converts the absolute timings to _relative_ timings of the form: 30 days in hot phase,
* 40 days in warm phase then forever in cold phase.
+ *
+ * All functions exported from this file can be viewed as utilities for working with form data and
+ * other defined interfaces to calculate the relative amount of time data will spend in a phase.
*/
import moment from 'moment';
-import { flow } from 'fp-ts/lib/function';
import { i18n } from '@kbn/i18n';
+import { flow } from 'fp-ts/function';
import { splitSizeAndUnits } from '../../../lib/policies';
import { FormInternal } from '../types';
+/* -===- Private functions and types -===- */
+
type MinAgePhase = 'warm' | 'cold' | 'delete';
type Phase = 'hot' | MinAgePhase;
@@ -43,7 +48,34 @@ const i18nTexts = {
}),
};
-interface AbsoluteTimings {
+const phaseOrder: Phase[] = ['hot', 'warm', 'cold', 'delete'];
+
+const getMinAge = (phase: MinAgePhase, formData: FormInternal) => ({
+ min_age: formData.phases?.[phase]?.min_age
+ ? formData.phases[phase]!.min_age! + formData._meta[phase].minAgeUnit
+ : '0ms',
+});
+
+/**
+ * See https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math
+ * for all date math values. ILM policies also support "micros" and "nanos".
+ */
+const getPhaseMinAgeInMilliseconds = (phase: { min_age: string }): number => {
+ let milliseconds: number;
+ const { units, size } = splitSizeAndUnits(phase.min_age);
+ if (units === 'micros') {
+ milliseconds = parseInt(size, 10) / 1e3;
+ } else if (units === 'nanos') {
+ milliseconds = parseInt(size, 10) / 1e6;
+ } else {
+ milliseconds = moment.duration(size, units as any).asMilliseconds();
+ }
+ return milliseconds;
+};
+
+/* -===- Public functions and types -===- */
+
+export interface AbsoluteTimings {
hot: {
min_age: undefined;
};
@@ -67,16 +99,7 @@ export interface PhaseAgeInMilliseconds {
};
}
-const phaseOrder: Phase[] = ['hot', 'warm', 'cold', 'delete'];
-
-const getMinAge = (phase: MinAgePhase, formData: FormInternal) => ({
- min_age:
- formData.phases && formData.phases[phase]?.min_age
- ? formData.phases[phase]!.min_age! + formData._meta[phase].minAgeUnit
- : '0ms',
-});
-
-const formDataToAbsoluteTimings = (formData: FormInternal): AbsoluteTimings => {
+export const formDataToAbsoluteTimings = (formData: FormInternal): AbsoluteTimings => {
const { _meta } = formData;
if (!_meta) {
return { hot: { min_age: undefined } };
@@ -89,28 +112,13 @@ const formDataToAbsoluteTimings = (formData: FormInternal): AbsoluteTimings => {
};
};
-/**
- * See https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math
- * for all date math values. ILM policies also support "micros" and "nanos".
- */
-const getPhaseMinAgeInMilliseconds = (phase: { min_age: string }): number => {
- let milliseconds: number;
- const { units, size } = splitSizeAndUnits(phase.min_age);
- if (units === 'micros') {
- milliseconds = parseInt(size, 10) / 1e3;
- } else if (units === 'nanos') {
- milliseconds = parseInt(size, 10) / 1e6;
- } else {
- milliseconds = moment.duration(size, units as any).asMilliseconds();
- }
- return milliseconds;
-};
-
/**
* Given a set of phase minimum age absolute timings, like hot phase 0ms and warm phase 3d, work out
* the number of milliseconds data will reside in phase.
*/
-const calculateMilliseconds = (inputs: AbsoluteTimings): PhaseAgeInMilliseconds => {
+export const calculateRelativeFromAbsoluteMilliseconds = (
+ inputs: AbsoluteTimings
+): PhaseAgeInMilliseconds => {
return phaseOrder.reduce(
(acc, phaseName, idx) => {
// Delete does not have an age associated with it
@@ -152,6 +160,8 @@ const calculateMilliseconds = (inputs: AbsoluteTimings): PhaseAgeInMilliseconds
);
};
+export type RelativePhaseTimingInMs = ReturnType;
+
const millisecondsToDays = (milliseconds?: number): string | undefined => {
if (milliseconds == null) {
return;
@@ -177,10 +187,12 @@ export const normalizeTimingsToHumanReadable = ({
};
};
-export const calculateRelativeTimingMs = flow(formDataToAbsoluteTimings, calculateMilliseconds);
-
+/**
+ * Given {@link FormInternal}, extract the min_age values for each phase and calculate
+ * human readable strings for communicating how long data will remain in a phase.
+ */
export const absoluteTimingToRelativeTiming = flow(
formDataToAbsoluteTimings,
- calculateMilliseconds,
+ calculateRelativeFromAbsoluteMilliseconds,
normalizeTimingsToHumanReadable
);
diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/index.ts b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/index.ts
index 9593fcc810a6f..a9372c99a72fc 100644
--- a/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/index.ts
+++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/lib/index.ts
@@ -6,7 +6,10 @@
export {
absoluteTimingToRelativeTiming,
- calculateRelativeTimingMs,
+ calculateRelativeFromAbsoluteMilliseconds,
normalizeTimingsToHumanReadable,
+ formDataToAbsoluteTimings,
+ AbsoluteTimings,
PhaseAgeInMilliseconds,
+ RelativePhaseTimingInMs,
} from './absolute_timing_to_relative_timing';
diff --git a/x-pack/plugins/infra/kibana.json b/x-pack/plugins/infra/kibana.json
index e84767f4931ca..d1fa83793d1dd 100644
--- a/x-pack/plugins/infra/kibana.json
+++ b/x-pack/plugins/infra/kibana.json
@@ -6,7 +6,7 @@
"features",
"usageCollection",
"spaces",
-
+ "embeddable",
"data",
"dataEnhanced",
"visTypeTimeseries",
diff --git a/x-pack/plugins/infra/public/components/log_stream/index.ts b/x-pack/plugins/infra/public/components/log_stream/index.ts
new file mode 100644
index 0000000000000..6abb292f919d9
--- /dev/null
+++ b/x-pack/plugins/infra/public/components/log_stream/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export * from './log_stream';
diff --git a/x-pack/plugins/infra/public/components/log_stream/lazy_log_stream_wrapper.tsx b/x-pack/plugins/infra/public/components/log_stream/lazy_log_stream_wrapper.tsx
index 65433aab15716..13eb6431f97a3 100644
--- a/x-pack/plugins/infra/public/components/log_stream/lazy_log_stream_wrapper.tsx
+++ b/x-pack/plugins/infra/public/components/log_stream/lazy_log_stream_wrapper.tsx
@@ -5,9 +5,9 @@
*/
import React from 'react';
-import type { LogStreamProps } from './';
+import type { LogStreamProps } from './log_stream';
-const LazyLogStream = React.lazy(() => import('./'));
+const LazyLogStream = React.lazy(() => import('./log_stream'));
export const LazyLogStreamWrapper: React.FC = (props) => (
}>
diff --git a/x-pack/plugins/infra/public/components/log_stream/index.tsx b/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx
similarity index 98%
rename from x-pack/plugins/infra/public/components/log_stream/index.tsx
rename to x-pack/plugins/infra/public/components/log_stream/log_stream.tsx
index b485a21221af2..b7410fda6f6fd 100644
--- a/x-pack/plugins/infra/public/components/log_stream/index.tsx
+++ b/x-pack/plugins/infra/public/components/log_stream/log_stream.tsx
@@ -17,6 +17,7 @@ import { useLogStream } from '../../containers/logs/log_stream';
import { ScrollableLogTextStreamView } from '../logging/log_text_stream';
import { LogColumnRenderConfiguration } from '../../utils/log_column_render_configuration';
import { JsonValue } from '../../../../../../src/plugins/kibana_utils/common';
+import { Query } from '../../../../../../src/plugins/data/common';
const PAGE_THRESHOLD = 2;
@@ -55,7 +56,7 @@ export interface LogStreamProps {
sourceId?: string;
startTimestamp: number;
endTimestamp: number;
- query?: string;
+ query?: string | Query;
center?: LogEntryCursor;
highlight?: string;
height?: string | number;
diff --git a/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable.tsx b/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable.tsx
new file mode 100644
index 0000000000000..0d6dfc50960f9
--- /dev/null
+++ b/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable.tsx
@@ -0,0 +1,91 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { CoreStart } from 'kibana/public';
+
+import { I18nProvider } from '@kbn/i18n/react';
+import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
+import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
+import { Query, TimeRange } from '../../../../../../src/plugins/data/public';
+import {
+ Embeddable,
+ EmbeddableInput,
+ IContainer,
+} from '../../../../../../src/plugins/embeddable/public';
+import { datemathToEpochMillis } from '../../utils/datemath';
+import { LazyLogStreamWrapper } from './lazy_log_stream_wrapper';
+
+export const LOG_STREAM_EMBEDDABLE = 'LOG_STREAM_EMBEDDABLE';
+
+export interface LogStreamEmbeddableInput extends EmbeddableInput {
+ timeRange: TimeRange;
+ query: Query;
+}
+
+export class LogStreamEmbeddable extends Embeddable {
+ public readonly type = LOG_STREAM_EMBEDDABLE;
+ private node?: HTMLElement;
+
+ constructor(
+ private services: CoreStart,
+ initialInput: LogStreamEmbeddableInput,
+ parent?: IContainer
+ ) {
+ super(initialInput, {}, parent);
+ }
+
+ public render(node: HTMLElement) {
+ if (this.node) {
+ ReactDOM.unmountComponentAtNode(this.node);
+ }
+ this.node = node;
+
+ this.renderComponent();
+ }
+
+ public reload() {
+ this.renderComponent();
+ }
+
+ public destroy() {
+ super.destroy();
+ if (this.node) {
+ ReactDOM.unmountComponentAtNode(this.node);
+ }
+ }
+
+ private renderComponent() {
+ if (!this.node) {
+ return;
+ }
+
+ const startTimestamp = datemathToEpochMillis(this.input.timeRange.from);
+ const endTimestamp = datemathToEpochMillis(this.input.timeRange.to);
+
+ if (!startTimestamp || !endTimestamp) {
+ return;
+ }
+
+ ReactDOM.render(
+
+
+
+
+
+
+
+
+ ,
+ this.node
+ );
+ }
+}
diff --git a/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable_factory.ts b/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable_factory.ts
new file mode 100644
index 0000000000000..f4d1b83a07593
--- /dev/null
+++ b/x-pack/plugins/infra/public/components/log_stream/log_stream_embeddable_factory.ts
@@ -0,0 +1,37 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { CoreStart } from 'kibana/public';
+import {
+ EmbeddableFactoryDefinition,
+ IContainer,
+} from '../../../../../../src/plugins/embeddable/public';
+import {
+ LogStreamEmbeddable,
+ LOG_STREAM_EMBEDDABLE,
+ LogStreamEmbeddableInput,
+} from './log_stream_embeddable';
+
+export class LogStreamEmbeddableFactoryDefinition
+ implements EmbeddableFactoryDefinition {
+ public readonly type = LOG_STREAM_EMBEDDABLE;
+
+ constructor(private getCoreServices: () => Promise) {}
+
+ public async isEditable() {
+ const { application } = await this.getCoreServices();
+ return application.capabilities.logs.save as boolean;
+ }
+
+ public async create(initialInput: LogStreamEmbeddableInput, parent?: IContainer) {
+ const services = await this.getCoreServices();
+ return new LogStreamEmbeddable(services, initialInput, parent);
+ }
+
+ public getDisplayName() {
+ return 'Log stream';
+ }
+}
diff --git a/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_actions_menu.tsx b/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_actions_menu.tsx
index aa3b4532e878e..9fef939733432 100644
--- a/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_actions_menu.tsx
+++ b/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_actions_menu.tsx
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { EuiButtonEmpty, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui';
+import { EuiButton, EuiContextMenuItem, EuiContextMenuPanel, EuiPopover } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { useMemo } from 'react';
import { useVisibilityState } from '../../../utils/use_visibility_state';
@@ -67,7 +67,7 @@ export const LogEntryActionsMenu: React.FunctionComponent<{
-
+
}
closePopover={hide}
id="logEntryActionsMenu"
diff --git a/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_flyout.tsx b/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_flyout.tsx
index 5684d4068f3be..7d8ca95f9b93b 100644
--- a/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_flyout.tsx
+++ b/x-pack/plugins/infra/public/components/logging/log_entry_flyout/log_entry_flyout.tsx
@@ -88,7 +88,7 @@ export const LogEntryFlyout = ({
>
) : null}
-
+
{logEntry ? : null}
diff --git a/x-pack/plugins/infra/public/containers/logs/log_stream/index.ts b/x-pack/plugins/infra/public/containers/logs/log_stream/index.ts
index da7176125dae4..1d9a7a1b1d777 100644
--- a/x-pack/plugins/infra/public/containers/logs/log_stream/index.ts
+++ b/x-pack/plugins/infra/public/containers/logs/log_stream/index.ts
@@ -7,7 +7,7 @@
import { useMemo, useEffect } from 'react';
import useSetState from 'react-use/lib/useSetState';
import usePrevious from 'react-use/lib/usePrevious';
-import { esKuery } from '../../../../../../../src/plugins/data/public';
+import { esKuery, esQuery, Query } from '../../../../../../../src/plugins/data/public';
import { fetchLogEntries } from '../log_entries/api/fetch_log_entries';
import { useTrackedPromise } from '../../../utils/use_tracked_promise';
import { LogEntryCursor, LogEntry } from '../../../../common/log_entry';
@@ -18,7 +18,7 @@ interface LogStreamProps {
sourceId: string;
startTimestamp: number;
endTimestamp: number;
- query?: string;
+ query?: string | Query;
center?: LogEntryCursor;
columns?: LogSourceConfigurationProperties['logColumns'];
}
@@ -84,9 +84,21 @@ export function useLogStream({
}, [prevEndTimestamp, endTimestamp, setState]);
const parsedQuery = useMemo(() => {
- return query
- ? JSON.stringify(esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(query)))
- : null;
+ if (!query) {
+ return null;
+ }
+
+ let q;
+
+ if (typeof query === 'string') {
+ q = esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(query));
+ } else if (query.language === 'kuery') {
+ q = esKuery.toElasticsearchQuery(esKuery.fromKueryExpression(query.query as string));
+ } else if (query.language === 'lucene') {
+ q = esQuery.luceneStringToDsl(query.query as string);
+ }
+
+ return JSON.stringify(q);
}, [query]);
// Callbacks
diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts
index 2bbd0067642c0..809046ee1e17b 100644
--- a/x-pack/plugins/infra/public/plugin.ts
+++ b/x-pack/plugins/infra/public/plugin.ts
@@ -19,6 +19,8 @@ import {
} from './types';
import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_overview_fetchers';
import { createMetricsHasData, createMetricsFetchData } from './metrics_overview_fetchers';
+import { LOG_STREAM_EMBEDDABLE } from './components/log_stream/log_stream_embeddable';
+import { LogStreamEmbeddableFactoryDefinition } from './components/log_stream/log_stream_embeddable_factory';
export class Plugin implements InfraClientPluginClass {
constructor(_context: PluginInitializerContext) {}
@@ -46,6 +48,13 @@ export class Plugin implements InfraClientPluginClass {
});
}
+ const getCoreServices = async () => (await core.getStartServices())[0];
+
+ pluginsSetup.embeddable.registerEmbeddableFactory(
+ LOG_STREAM_EMBEDDABLE,
+ new LogStreamEmbeddableFactoryDefinition(getCoreServices)
+ );
+
core.application.register({
id: 'logs',
title: i18n.translate('xpack.infra.logs.pluginTitle', {
diff --git a/x-pack/plugins/infra/public/types.ts b/x-pack/plugins/infra/public/types.ts
index f1052672978d5..037cfa4b7eb2d 100644
--- a/x-pack/plugins/infra/public/types.ts
+++ b/x-pack/plugins/infra/public/types.ts
@@ -7,6 +7,7 @@
import type { CoreSetup, CoreStart, Plugin as PluginClass } from 'kibana/public';
import type { DataPublicPluginStart } from '../../../../src/plugins/data/public';
import type { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
+import type { EmbeddableSetup } from '../../../../src/plugins/embeddable/public';
import type {
UsageCollectionSetup,
UsageCollectionStart,
@@ -33,6 +34,7 @@ export interface InfraClientSetupDeps {
observability: ObservabilityPluginSetup;
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
usageCollection: UsageCollectionSetup;
+ embeddable: EmbeddableSetup;
}
export interface InfraClientStartDeps {
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/README.md b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/README.md
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/README.md
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/README.md
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/constants.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/constants.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/constants.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/constants.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/http_requests.helpers.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/http_requests.helpers.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/http_requests.helpers.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/http_requests.helpers.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.helpers.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.helpers.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.helpers.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/pipeline_processors_editor.test.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/pipeline_processors_editor.test.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors/processor.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors/processor.helpers.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/processor.helpers.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors/uri_parts.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors/uri_parts.test.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors/uri_parts.test.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors_editor.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors_editor.tsx
similarity index 89%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors_editor.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors_editor.tsx
index 8fb51ade921a9..3fa245ff96d37 100644
--- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/processors_editor.tsx
+++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/processors_editor.tsx
@@ -9,7 +9,7 @@ import { notificationServiceMock, scopedHistoryMock } from 'src/core/public/mock
import { LocationDescriptorObject } from 'history';
import { KibanaContextProvider } from 'src/plugins/kibana_react/public';
-import { ProcessorsEditorContextProvider, Props, PipelineProcessorsEditor } from '../';
+import { ProcessorsEditorContextProvider, Props, PipelineEditor } from '../';
import {
breadcrumbService,
@@ -36,7 +36,7 @@ export const ProcessorsEditorWithDeps: React.FunctionComponent = (props)
return (
-
+
);
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/test_pipeline.helpers.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/test_pipeline.helpers.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.helpers.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/test_pipeline.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.test.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/__jest__/test_pipeline.test.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/__jest__/test_pipeline.test.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/_shared.scss b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/_shared.scss
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/_shared.scss
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/_shared.scss
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/add_processor_button.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/add_processor_button.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/add_processor_button.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/add_processor_button.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/index.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/index.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/index.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/index.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/button.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/button.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/button.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/button.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/index.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/index.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/index.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/index.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/modal_provider.test.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/modal_provider.test.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.test.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/modal_provider.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.tsx
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/load_from_json/modal_provider.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/load_from_json/modal_provider.tsx
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/on_failure_processors_title.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/on_failure_processors_title.tsx
similarity index 96%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/on_failure_processors_title.tsx
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/on_failure_processors_title.tsx
index 7adc37d1897d1..fe3e6d79f84d7 100644
--- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/components/on_failure_processors_title.tsx
+++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/components/on_failure_processors_title.tsx
@@ -14,7 +14,7 @@ export const OnFailureProcessorsTitle: FunctionComponent = () => {
const { services } = useKibana();
return (
-
+
= ({ onLoadJson }) => {
+export const PipelineEditor: React.FunctionComponent = ({ onLoadJson }) => {
const {
state: { processors: allProcessors },
} = usePipelineProcessorsContext();
@@ -52,12 +52,12 @@ export const PipelineProcessorsEditor: React.FunctionComponent = ({ onLoa
}
return (
-
+
0} />
-
+
{content}
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/constants.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/constants.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/constants.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/constants.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/index.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/index.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/index.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/index.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/processors_reducer.test.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/processors_reducer.test.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/processors_reducer.test.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/processors_reducer.test.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/processors_reducer.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/processors_reducer.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/processors_reducer.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/processors_reducer.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/utils.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/utils.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/processors_reducer/utils.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/processors_reducer/utils.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/serialize.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/serialize.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/serialize.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/serialize.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/types.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/types.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/types.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/types.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/use_is_mounted.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/use_is_mounted.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/use_is_mounted.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/use_is_mounted.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/utils.test.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/utils.test.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.test.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/utils.ts b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts
similarity index 100%
rename from x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/utils.ts
rename to x-pack/plugins/ingest_pipelines/public/application/components/pipeline_editor/utils.ts
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx
index ffd82b0bbaf35..ac8612a36dd7e 100644
--- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx
+++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form.tsx
@@ -11,7 +11,7 @@ import { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiFlexItem, EuiSpacer } from
import { useForm, Form, FormConfig } from '../../../shared_imports';
import { Pipeline, Processor } from '../../../../common/types';
-import { OnUpdateHandlerArg, OnUpdateHandler } from '../pipeline_processors_editor';
+import { OnUpdateHandlerArg, OnUpdateHandler } from '../pipeline_editor';
import { PipelineRequestFlyout } from './pipeline_request_flyout';
import { PipelineFormFields } from './pipeline_form_fields';
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
index a7ffe7ba02caa..b1b2e04e7d0dc 100644
--- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
+++ b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_form/pipeline_form_fields.tsx
@@ -16,8 +16,8 @@ import {
ProcessorsEditorContextProvider,
OnUpdateHandler,
OnDoneLoadJsonHandler,
- PipelineProcessorsEditor,
-} from '../pipeline_processors_editor';
+ PipelineEditor,
+} from '../pipeline_editor';
interface Props {
processors: Processor[];
@@ -119,7 +119,7 @@ export const PipelineFormFields: React.FunctionComponent
= ({
onUpdate={onProcessorsUpdate}
value={{ processors, onFailure }}
>
-
+
>
);
diff --git a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/pipeline_processors_editor.scss b/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/pipeline_processors_editor.scss
deleted file mode 100644
index d5592b87dda51..0000000000000
--- a/x-pack/plugins/ingest_pipelines/public/application/components/pipeline_processors_editor/pipeline_processors_editor.scss
+++ /dev/null
@@ -1,11 +0,0 @@
-.pipelineProcessorsEditor {
- margin-bottom: $euiSizeXL;
-
- &__container {
- background-color: $euiColorLightestShade;
- }
-
- &__onFailureTitle {
- padding-left: $euiSizeS;
- }
-}
diff --git a/x-pack/plugins/lens/public/drag_drop/__snapshots__/drag_drop.test.tsx.snap b/x-pack/plugins/lens/public/drag_drop/__snapshots__/drag_drop.test.tsx.snap
index dc53f3a2bc2a7..6423a9f6190a7 100644
--- a/x-pack/plugins/lens/public/drag_drop/__snapshots__/drag_drop.test.tsx.snap
+++ b/x-pack/plugins/lens/public/drag_drop/__snapshots__/drag_drop.test.tsx.snap
@@ -13,10 +13,8 @@ exports[`DragDrop items that have droppable=false get special styling when anoth