From 631675ba39a1b6f685885d803ac86b103f438f29 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Wed, 25 Jan 2023 13:38:05 +0100 Subject: [PATCH 01/11] [Saved Objects] Import SO types from `server` rather than `common` to avoid deprecation (#149289) ## Summary After merging https://github.com/elastic/kibana/pull/148979 there are a number of imports that can be fixed immediately to address our new deprecation notice. ## To Core reviewers The package `core-saved-objects-server` is using types from `core-saved-objects-api-server` which creates a circular dependency when using `SavedObject` type from it's new home in `core-saved-object-server`: `core-saved-objects-server` -> `core-saved-objects-api-server` -> `core-saved-objects-server` One solution is that we can create a new package `packages/core/saved-objects/core-saved-objects-server-shared` that will only hold the `SavedObject` type and a select few others. I'm not sure what the best approach here is. I have left `core-saved-objects-api-server` unchanged for now (i.e., it is still importing `SavedObject` from `common` which is deprecated). Any input would be greatly appreciated! Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../src/lib/collect_multi_namespace_references.ts | 2 +- .../src/lib/internal_bulk_resolve.test.ts | 2 +- .../src/lib/internal_bulk_resolve.ts | 2 +- .../src/lib/internal_utils.ts | 2 +- .../src/lib/repository.security_extension.test.ts | 2 +- .../src/lib/repository.spaces_extension.test.ts | 2 +- .../src/lib/repository.test.ts | 2 +- .../src/lib/repository.ts | 2 +- .../src/lib/update_objects_spaces.ts | 2 +- .../src/saved_objects_client.ts | 2 +- .../src/test_helpers/repository.test.common.ts | 2 +- .../core-saved-objects-api-server/src/apis/create.ts | 6 ++---- .../core-saved-objects-api-server/tsconfig.json | 2 +- .../core-saved-objects-common/src/saved_objects.ts | 10 +++++----- .../src/export/apply_export_transforms.test.ts | 2 +- .../src/export/collect_exported_objects.test.ts | 3 ++- .../src/export/collect_exported_objects.ts | 2 +- .../src/export/errors.ts | 2 +- .../src/export/saved_objects_exporter.test.ts | 2 +- .../src/export/saved_objects_exporter.ts | 2 +- .../src/export/sort_objects.test.ts | 2 +- .../src/export/sort_objects.ts | 2 +- .../src/export/utils.test.ts | 2 +- .../src/export/utils.ts | 2 +- .../src/import/import_saved_objects.test.ts | 2 +- .../src/import/lib/check_conflicts.test.ts | 7 ++----- .../src/import/lib/check_conflicts.ts | 2 +- .../src/import/lib/check_origin_conflicts.test.ts | 8 +++++--- .../src/import/lib/check_origin_conflicts.ts | 3 +-- .../src/import/lib/collect_saved_objects.ts | 3 ++- .../src/import/lib/create_objects_filter.ts | 3 ++- .../src/import/lib/create_saved_objects.test.ts | 3 ++- .../src/import/lib/create_saved_objects.ts | 3 ++- .../src/import/lib/execute_import_hooks.test.ts | 3 ++- .../src/import/lib/execute_import_hooks.ts | 3 ++- .../src/import/lib/extract_errors.test.ts | 3 +-- .../src/import/lib/extract_errors.ts | 3 ++- .../lib/get_import_state_map_for_retries.test.ts | 3 ++- .../src/import/lib/get_import_state_map_for_retries.ts | 3 ++- .../src/import/lib/regenerate_ids.test.ts | 2 +- .../src/import/lib/split_overwrites.ts | 3 ++- .../src/import/lib/validate_references.ts | 2 +- .../src/import/resolve_import_errors.test.ts | 3 +-- .../src/import/resolve_import_errors.ts | 2 +- .../src/routes/legacy_import_export/import.ts | 2 +- .../lib/collect_references_deep.test.ts | 2 +- .../lib/collect_references_deep.ts | 2 +- .../legacy_import_export/lib/import_dashboards.test.ts | 2 +- .../legacy_import_export/lib/import_dashboards.ts | 2 +- .../src/routes/utils.ts | 2 +- .../core-saved-objects-server-internal/tsconfig.json | 1 - .../core-saved-objects-server/src/export.ts | 3 ++- .../src/extensions/encryption.ts | 2 +- .../src/extensions/security.ts | 2 +- .../core-saved-objects-server/src/import.ts | 2 +- .../src/saved_objects_management.ts | 2 +- .../core-saved-objects-server/src/serialization.ts | 6 ++---- .../service/lib/repository_with_proxy.test.ts | 2 +- .../server/rules_client/tests/bulk_disable.test.ts | 2 +- .../alerting/server/rules_client/tests/test_helpers.ts | 2 +- .../server/saved_objects/migrations/7.11/index.ts | 2 +- .../server/saved_objects/migrations/7.13/index.ts | 2 +- .../server/saved_objects/migrations/7.15/index.ts | 2 +- .../server/saved_objects/migrations/7.16/index.ts | 2 +- x-pack/plugins/alerting/tsconfig.json | 1 - .../cases/server/authorization/authorization.ts | 2 +- x-pack/plugins/cases/server/authorization/utils.ts | 2 +- x-pack/plugins/cases/server/common/types.ts | 2 +- .../saved_objects_encryption_extension.ts | 2 +- x-pack/plugins/encrypted_saved_objects/tsconfig.json | 1 - .../fleet/server/services/agents/action.mock.ts | 2 +- .../server/embeddable/make_lens_embeddable_factory.ts | 2 +- x-pack/plugins/lens/tsconfig.json | 1 + .../observability/server/services/slo/fixtures/slo.ts | 2 +- x-pack/plugins/observability/tsconfig.json | 1 - .../saved_objects/saved_objects_security_extension.ts | 2 +- x-pack/plugins/security/tsconfig.json | 1 - .../monitor_cruds/bulk_cruds/delete_monitor_bulk.ts | 2 +- x-pack/plugins/synthetics/tsconfig.json | 1 + .../apis/synthetics/sync_global_params.ts | 2 +- x-pack/test/tsconfig.json | 1 - 81 files changed, 98 insertions(+), 98 deletions(-) diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/collect_multi_namespace_references.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/collect_multi_namespace_references.ts index 9a97f2f91e4eb..183d2509ad48d 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/collect_multi_namespace_references.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/collect_multi_namespace_references.ts @@ -7,7 +7,7 @@ */ import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsCollectMultiNamespaceReferencesObject, SavedObjectsCollectMultiNamespaceReferencesOptions, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.test.ts index 3ef9aa48f30e4..cd888ddb4c2e4 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.test.ts @@ -13,7 +13,7 @@ import { } from './internal_bulk_resolve.test.mock'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsBulkResolveObject, SavedObjectsBaseOptions, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.ts index 747a0d5f5e6d6..2d4e75654b1fe 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_bulk_resolve.ts @@ -9,7 +9,7 @@ import type { MgetResponseItem } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { isNotFoundFromUnsupportedServer } from '@kbn/core-elasticsearch-server-internal'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsBaseOptions, SavedObjectsBulkResolveObject, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_utils.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_utils.ts index 2dfe78a3d5ccd..37b29a6a94e66 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_utils.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/internal_utils.ts @@ -7,7 +7,7 @@ */ import type { Payload } from '@hapi/boom'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { ISavedObjectTypeRegistry, SavedObjectsRawDoc, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.security_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.security_extension.test.ts index dad313988e1c6..bd30f9a10eeb1 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.security_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.security_extension.test.ts @@ -20,7 +20,7 @@ import { estypes } from '@elastic/elasticsearch'; import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; import { SavedObjectsBulkUpdateObject } from '@kbn/core-saved-objects-api-server'; import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; -import { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import { ISavedObjectsSecurityExtension, AuditAction, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts index 59162f991928a..adfa75a48e986 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.spaces_extension.test.ts @@ -27,7 +27,7 @@ import { SavedObjectsBulkUpdateObject, } from '@kbn/core-saved-objects-api-server'; import { SavedObjectsSerializer } from '@kbn/core-saved-objects-base-server-internal'; -import { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import { ISavedObjectsSpacesExtension, ISavedObjectsSecurityExtension, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.test.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.test.ts index e8365293991fe..550bf9560a9fd 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.test.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.test.ts @@ -23,7 +23,7 @@ import { import type { Payload } from '@hapi/boom'; import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import type { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-common'; +import type { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-server'; import type { SavedObjectsBaseOptions, SavedObjectsFindOptions, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts index cb23c5f89fbcf..1c36ad1edc8b8 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/repository.ts @@ -17,7 +17,7 @@ import { isSupportedEsServer, isNotFoundFromUnsupportedServer, } from '@kbn/core-elasticsearch-server-internal'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsBaseOptions, SavedObjectsIncrementCounterOptions, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/update_objects_spaces.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/update_objects_spaces.ts index 3144460270178..5eab945874309 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/update_objects_spaces.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/update_objects_spaces.ts @@ -34,7 +34,7 @@ import type { IndexMapping, SavedObjectsSerializer, } from '@kbn/core-saved-objects-base-server-internal'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { getBulkOperationError, getExpectedVersionProperties, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/saved_objects_client.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/saved_objects_client.ts index 50f78f09dd684..1771012ebba33 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/saved_objects_client.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/saved_objects_client.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract, ISavedObjectsRepository, diff --git a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts index a6b9ba684b568..bbe40c8dba8c5 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server-internal/src/test_helpers/repository.test.common.ts @@ -20,7 +20,7 @@ import { SavedObjectsType, SavedObjectsTypeMappingDefinition, } from '@kbn/core-saved-objects-server'; -import { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-common'; +import { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-server'; import { SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, diff --git a/packages/core/saved-objects/core-saved-objects-api-server/src/apis/create.ts b/packages/core/saved-objects/core-saved-objects-api-server/src/apis/create.ts index 78a017ed03aba..f26e75bd37865 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server/src/apis/create.ts +++ b/packages/core/saved-objects/core-saved-objects-api-server/src/apis/create.ts @@ -6,10 +6,8 @@ * Side Public License, v 1. */ -import type { - SavedObjectsMigrationVersion, - SavedObjectReference, -} from '@kbn/core-saved-objects-common'; +import type { SavedObjectsMigrationVersion } from '@kbn/core-saved-objects-common'; +import type { SavedObjectReference } from '@kbn/core-saved-objects-common'; import type { MutatingOperationRefreshSetting, SavedObjectsBaseOptions } from './base'; /** diff --git a/packages/core/saved-objects/core-saved-objects-api-server/tsconfig.json b/packages/core/saved-objects/core-saved-objects-api-server/tsconfig.json index 0e593db446f6f..c091f255cbd21 100644 --- a/packages/core/saved-objects/core-saved-objects-api-server/tsconfig.json +++ b/packages/core/saved-objects/core-saved-objects-api-server/tsconfig.json @@ -11,7 +11,7 @@ "**/*.ts" ], "kbn_references": [ - "@kbn/core-saved-objects-common" + "@kbn/core-saved-objects-common", ], "exclude": [ "target/**/*", diff --git a/packages/core/saved-objects/core-saved-objects-common/src/saved_objects.ts b/packages/core/saved-objects/core-saved-objects-common/src/saved_objects.ts index 12e554cf185c8..00c12280bccda 100644 --- a/packages/core/saved-objects/core-saved-objects-common/src/saved_objects.ts +++ b/packages/core/saved-objects/core-saved-objects-common/src/saved_objects.ts @@ -51,30 +51,30 @@ export interface SavedObjectError { /** * @public - * @deprecated See https://github.com/elastic/kibana/issues/149098 + * @deprecated See https://github.com/elastic/kibana/issues/149098. Import this type from @kbn/core/server instead. */ export type SavedObjectAttributeSingle = serverTypes.SavedObjectAttributeSingle; /** * @public - * @deprecated See https://github.com/elastic/kibana/issues/149098 + * @deprecated See https://github.com/elastic/kibana/issues/149098. Import this type from @kbn/core/server instead. */ export type SavedObjectAttribute = serverTypes.SavedObjectAttribute; /** * @public - * @deprecated See https://github.com/elastic/kibana/issues/149098 + * @deprecated See https://github.com/elastic/kibana/issues/149098. Import this type from @kbn/core/server instead. */ export type SavedObjectAttributes = serverTypes.SavedObjectAttributes; /** * @public - * @deprecated See https://github.com/elastic/kibana/issues/149098 + * @deprecated See https://github.com/elastic/kibana/issues/149098. Import this type from @kbn/core/server instead. */ export type SavedObjectReference = serverTypes.SavedObjectReference; /** * @public - * @deprecated See https://github.com/elastic/kibana/issues/149098 + * @deprecated See https://github.com/elastic/kibana/issues/149098. Import this type from @kbn/core/server instead. */ export type SavedObject = serverTypes.SavedObject; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/apply_export_transforms.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/apply_export_transforms.test.ts index daa13393d962e..f963342b7e2d7 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/apply_export_transforms.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/apply_export_transforms.test.ts @@ -8,7 +8,7 @@ import { CoreKibanaRequest } from '@kbn/core-http-router-server-internal'; import { httpServerMock } from '@kbn/core-http-server-mocks'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsExportTransform } from '@kbn/core-saved-objects-server'; import { applyExportTransforms } from './apply_export_transforms'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.test.ts index 6125c9fb7d739..e440b1baffafc 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.test.ts @@ -7,7 +7,8 @@ */ import { httpServerMock } from '@kbn/core-http-server-mocks'; -import type { SavedObject, SavedObjectError } from '@kbn/core-saved-objects-common'; +import type { SavedObjectError } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsExportTransform, SavedObjectsExportablePredicate, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.ts index 6d9adeb8a0d94..dddefe8ad73f7 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/collect_exported_objects.ts @@ -8,7 +8,7 @@ import type { Logger } from '@kbn/logging'; import type { KibanaRequest } from '@kbn/core-http-server'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { SavedObjectsExportablePredicate, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/errors.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/errors.ts index 6ca23c358f931..a90c0fd78e743 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/errors.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/errors.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; /** * @public diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.test.ts index 498ddde9fbbae..2bb65c891d837 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.test.ts @@ -7,7 +7,7 @@ */ import { httpServerMock } from '@kbn/core-http-server-mocks'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { SavedObjectTypeRegistry } from '@kbn/core-saved-objects-base-server-internal'; import { SavedObjectsExporter } from './saved_objects_exporter'; import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.ts index bd122dbf8b392..0f7705396f256 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/saved_objects_exporter.ts @@ -9,7 +9,7 @@ import type { Readable } from 'stream'; import { createListStream } from '@kbn/utils'; import type { Logger } from '@kbn/logging'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract, SavedObjectsFindResult, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.test.ts index 27fbb09a37018..07310a86fe7dc 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.test.ts @@ -8,7 +8,7 @@ import { range } from 'lodash'; import { sortObjects } from './sort_objects'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; describe('sortObjects()', () => { test('should return on empty array', () => { diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.ts index 551ba3989e527..d742a60d6be99 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/sort_objects.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; const getId = (object: { type: string; id: string }) => `${object.type}:${object.id}`; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.test.ts index 6088217bd9201..030edcbca7f3f 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { byIdAscComparator, getPreservedOrderComparator } from './utils'; const createObj = (id: string): SavedObject => ({ diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.ts index dbace21e98ca6..a02fefa8068df 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/export/utils.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; export type SavedObjectComparator = (a: SavedObject, b: SavedObject) => number; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/import_saved_objects.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/import_saved_objects.test.ts index 02af9ca6dca77..a88e0864f532c 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/import_saved_objects.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/import_saved_objects.test.ts @@ -20,10 +20,10 @@ import { import { Readable } from 'stream'; import { v4 as uuidv4 } from 'uuid'; import type { - SavedObject, SavedObjectsImportFailure, SavedObjectsImportWarning, } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { SavedObjectsType, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.test.ts index 8c58af772b882..13faae72ea25a 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.test.ts @@ -7,11 +7,8 @@ */ import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import type { - SavedObject, - SavedObjectReference, - SavedObjectsImportRetry, -} from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { checkConflicts } from './check_conflicts'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.ts index f4f6082ef18ab..c145d8ee97b26 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_conflicts.ts @@ -8,11 +8,11 @@ import { v4 as uuidv4 } from 'uuid'; import type { - SavedObject, SavedObjectsImportFailure, SavedObjectError, SavedObjectsImportRetry, } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { ImportStateMap } from './types'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.test.ts index 225db282b31ee..42ba91279d75d 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.test.ts @@ -9,13 +9,15 @@ import { mockCreateOriginQuery } from './check_reference_origins.test.mock'; import type { - SavedObjectReference, - SavedObject, SavedObjectsImportFailure, SavedObjectsImportRetry, } from '@kbn/core-saved-objects-common'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; +import type { + ISavedObjectTypeRegistry, + SavedObject, + SavedObjectReference, +} from '@kbn/core-saved-objects-server'; import { typeRegistryMock } from '@kbn/core-saved-objects-base-server-mocks'; import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; import { checkOriginConflicts } from './check_origin_conflicts'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.ts index 079c5c22191ed..0d4765743cddb 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/check_origin_conflicts.ts @@ -9,12 +9,11 @@ import pMap from 'p-map'; import { v4 as uuidv4 } from 'uuid'; import type { - SavedObject, SavedObjectsImportFailure, SavedObjectsImportRetry, } from '@kbn/core-saved-objects-common'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import type { ISavedObjectTypeRegistry } from '@kbn/core-saved-objects-server'; +import type { ISavedObjectTypeRegistry, SavedObject } from '@kbn/core-saved-objects-server'; import { getObjectKey } from '@kbn/core-saved-objects-base-server-internal'; import type { ImportStateMap } from './types'; import { createOriginQuery } from './utils'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/collect_saved_objects.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/collect_saved_objects.ts index e86ff1f70794d..4120aff3ef215 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/collect_saved_objects.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/collect_saved_objects.ts @@ -14,7 +14,8 @@ import { createPromiseFromStreams, } from '@kbn/utils'; -import type { SavedObject, SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { SavedObjectsImportError } from '../errors'; import { getNonUniqueEntries } from './get_non_unique_entries'; import { createLimitStream } from './create_limit_stream'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_objects_filter.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_objects_filter.ts index 4b830e80fa6cb..872df75d2960b 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_objects_filter.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_objects_filter.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; export function createObjectsFilter(retries: SavedObjectsImportRetry[]) { const retryKeys = new Set(retries.map((retry) => `${retry.type}:${retry.id}`)); diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.test.ts index 146e6650fa4c4..9e332f1da896e 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.test.ts @@ -7,7 +7,8 @@ */ import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import type { SavedObject, SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { createSavedObjects } from './create_saved_objects'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.ts index 31caf8a130cae..6276902e7b3a2 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/create_saved_objects.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { CreatedObject } from '@kbn/core-saved-objects-server'; import { extractErrors } from './extract_errors'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.test.ts index bebe27492d41a..d677205526113 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.test.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportWarning } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportWarning } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsImportHookResult } from '@kbn/core-saved-objects-server'; import { executeImportHooks } from './execute_import_hooks'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.ts index d2e3063b1c49f..c2ae2ead97ee5 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/execute_import_hooks.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportWarning } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportWarning } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsImportHook } from '@kbn/core-saved-objects-server'; export interface ExecuteImportHooksOptions { diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.test.ts index c4d3d0e4c2722..4ce5ac5d82d85 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.test.ts @@ -6,8 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; -import type { CreatedObject } from '@kbn/core-saved-objects-server'; +import type { SavedObject, CreatedObject } from '@kbn/core-saved-objects-server'; import { SavedObjectsErrorHelpers } from '@kbn/core-saved-objects-utils-server'; import { extractErrors } from './extract_errors'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.ts index 97eca4a5d57be..a5124f269daa6 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/extract_errors.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportFailure } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { CreatedObject } from '@kbn/core-saved-objects-server'; export function extractErrors( diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.test.ts index d598326afa136..c0f0e510e1bb0 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.test.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { getImportStateMapForRetries } from './get_import_state_map_for_retries'; describe('#getImportStateMapForRetries', () => { diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.ts index dd4ed3036fb8c..65d30b040b2b3 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/get_import_state_map_for_retries.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { ImportStateMap } from './types'; interface GetImportStateMapForRetriesParams { diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/regenerate_ids.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/regenerate_ids.test.ts index f8a8c502af38a..485c3ccb03380 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/regenerate_ids.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/regenerate_ids.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { regenerateIds } from './regenerate_ids'; jest.mock('uuid', () => ({ diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/split_overwrites.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/split_overwrites.ts index 818b6e512dcc2..77599011836a5 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/split_overwrites.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/split_overwrites.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObjectsImportRetry } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; export function splitOverwrites( savedObjects: Array>, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/validate_references.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/validate_references.ts index 8f271908bf48d..05f6b9aa061b5 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/validate_references.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/lib/validate_references.ts @@ -7,10 +7,10 @@ */ import type { - SavedObject, SavedObjectsImportFailure, SavedObjectsImportRetry, } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import { SavedObjectsImportError } from '../errors'; import type { ImportStateMap } from './types'; diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.test.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.test.ts index 0bc8a9190202e..e1cafa319eaf9 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.test.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.test.ts @@ -24,12 +24,11 @@ import { import { Readable } from 'stream'; import { v4 as uuidv4 } from 'uuid'; import type { - SavedObject, SavedObjectsImportFailure, SavedObjectsImportRetry, - SavedObjectReference, SavedObjectsImportWarning, } from '@kbn/core-saved-objects-common'; +import type { SavedObject, SavedObjectReference } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { SavedObjectsType, diff --git a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.ts b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.ts index 72533ba7c877b..d6876492d11f3 100644 --- a/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.ts +++ b/packages/core/saved-objects/core-saved-objects-import-export-server-internal/src/import/resolve_import_errors.ts @@ -8,12 +8,12 @@ import { Readable } from 'stream'; import type { - SavedObject, SavedObjectsImportRetry, SavedObjectsImportFailure, SavedObjectsImportResponse, SavedObjectsImportSuccess, } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; import type { ISavedObjectTypeRegistry, diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts index 44ee99aa2c970..5de9d4dc82b1a 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/import.ts @@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema'; import type { Logger } from '@kbn/logging'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { InternalCoreUsageDataSetup } from '@kbn/core-usage-data-base-server-internal'; import type { InternalSavedObjectRouter } from '../../internal_types'; import { importDashboards } from './lib'; diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.test.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.test.ts index 4470983fafc62..d9c5f48b3bab1 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.test.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject, SavedObjectAttributes } from '@kbn/core-saved-objects-common'; +import type { SavedObject, SavedObjectAttributes } from '@kbn/core-saved-objects-server'; import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; import { collectReferencesDeep } from './collect_references_deep'; diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.ts index 0c193f618624d..e6b31d044479e 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/collect_references_deep.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; const MAX_BULK_GET_SIZE = 10000; diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.test.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.test.ts index 87452664ac517..e931ec2d3eb2a 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.test.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.test.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; import { importDashboards } from './import_dashboards'; diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.ts index 51a63f23322bf..052576916c12d 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/legacy_import_export/lib/import_dashboards.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; export async function importDashboards( diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/utils.ts b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/utils.ts index 47579b949aced..1faaba0f5b710 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/utils.ts +++ b/packages/core/saved-objects/core-saved-objects-server-internal/src/routes/utils.ts @@ -17,8 +17,8 @@ import { } from '@kbn/utils'; import Boom from '@hapi/boom'; import type { RequestHandlerWrapper } from '@kbn/core-http-server'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { + SavedObject, ISavedObjectTypeRegistry, SavedObjectsExportResultDetails, } from '@kbn/core-saved-objects-server'; diff --git a/packages/core/saved-objects/core-saved-objects-server-internal/tsconfig.json b/packages/core/saved-objects/core-saved-objects-server-internal/tsconfig.json index f2db7db82446d..6d9f8874ebdb4 100644 --- a/packages/core/saved-objects/core-saved-objects-server-internal/tsconfig.json +++ b/packages/core/saved-objects/core-saved-objects-server-internal/tsconfig.json @@ -18,7 +18,6 @@ "@kbn/core-http-server", "@kbn/core-http-server-internal", "@kbn/core-elasticsearch-server", - "@kbn/core-saved-objects-common", "@kbn/core-saved-objects-server", "@kbn/core-saved-objects-api-server", "@kbn/core-saved-objects-api-server-internal", diff --git a/packages/core/saved-objects/core-saved-objects-server/src/export.ts b/packages/core/saved-objects/core-saved-objects-server/src/export.ts index 67afd0b011a1d..72133ce4319a2 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/export.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/export.ts @@ -8,8 +8,9 @@ import type { Readable } from 'stream'; import type { KibanaRequest } from '@kbn/core-http-server'; -import type { SavedObject, SavedObjectTypeIdTuple } from '@kbn/core-saved-objects-common'; +import type { SavedObjectTypeIdTuple } from '@kbn/core-saved-objects-common'; import type { SavedObjectsFindOptionsReference } from '@kbn/core-saved-objects-api-server'; +import type { SavedObject } from '..'; /** * Utility class used to export savedObjects. diff --git a/packages/core/saved-objects/core-saved-objects-server/src/extensions/encryption.ts b/packages/core/saved-objects/core-saved-objects-server/src/extensions/encryption.ts index 6dcdac347faca..64bfa8d6c736a 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/extensions/encryption.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/extensions/encryption.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '../..'; /** * The EncryptedObjectDescriptor interface contains settings for describing diff --git a/packages/core/saved-objects/core-saved-objects-server/src/extensions/security.ts b/packages/core/saved-objects/core-saved-objects-server/src/extensions/security.ts index 4364bbbf2ad8f..7ad9c37062a3d 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/extensions/security.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/extensions/security.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { EcsEventOutcome } from '@kbn/ecs'; +import type { SavedObject } from '../..'; /** * The PerformAuthorizationParams interface contains settings for checking diff --git a/packages/core/saved-objects/core-saved-objects-server/src/import.ts b/packages/core/saved-objects/core-saved-objects-server/src/import.ts index e0f6a4c05e14a..b42ebeb68b03a 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/import.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/import.ts @@ -8,11 +8,11 @@ import { Readable } from 'stream'; import { - SavedObject, SavedObjectsImportRetry, SavedObjectsImportWarning, SavedObjectsImportResponse, } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '..'; /** * Utility class used to import savedObjects. diff --git a/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_management.ts b/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_management.ts index 7a67d70cbf4d4..b68fa59d95302 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_management.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/saved_objects_management.ts @@ -6,9 +6,9 @@ * Side Public License, v 1. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { SavedObjectsExportTransform } from './export'; import type { SavedObjectsImportHook } from './import'; +import type { SavedObject } from '..'; /** * Configuration options for the {@link SavedObjectsType | type}'s management section. diff --git a/packages/core/saved-objects/core-saved-objects-server/src/serialization.ts b/packages/core/saved-objects/core-saved-objects-server/src/serialization.ts index 7752d0dd99e90..6b8159f9fce18 100644 --- a/packages/core/saved-objects/core-saved-objects-server/src/serialization.ts +++ b/packages/core/saved-objects/core-saved-objects-server/src/serialization.ts @@ -6,10 +6,8 @@ * Side Public License, v 1. */ -import type { - SavedObjectsMigrationVersion, - SavedObjectReference, -} from '@kbn/core-saved-objects-common'; +import type { SavedObjectsMigrationVersion } from '@kbn/core-saved-objects-common'; +import type { SavedObjectReference } from '..'; /** * A serializer that can be used to manually convert {@link SavedObjectsRawDoc | raw} or diff --git a/src/core/server/integration_tests/saved_objects/service/lib/repository_with_proxy.test.ts b/src/core/server/integration_tests/saved_objects/service/lib/repository_with_proxy.test.ts index 8cb2a5452726b..e38231a6e0ea4 100644 --- a/src/core/server/integration_tests/saved_objects/service/lib/repository_with_proxy.test.ts +++ b/src/core/server/integration_tests/saved_objects/service/lib/repository_with_proxy.test.ts @@ -9,7 +9,7 @@ import Hapi from '@hapi/hapi'; import h2o2 from '@hapi/h2o2'; import { URL } from 'url'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { ISavedObjectsRepository } from '@kbn/core-saved-objects-api-server'; import type { InternalCoreSetup, InternalCoreStart } from '@kbn/core-lifecycle-server-internal'; import { Root } from '@kbn/core-root-server-internal'; diff --git a/x-pack/plugins/alerting/server/rules_client/tests/bulk_disable.test.ts b/x-pack/plugins/alerting/server/rules_client/tests/bulk_disable.test.ts index ddb1a5da58e5b..7d35c1e12c57e 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/bulk_disable.test.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/bulk_disable.test.ts @@ -8,7 +8,7 @@ import { RulesClient, ConstructorOptions } from '../rules_client'; import { savedObjectsClientMock } from '@kbn/core/server/mocks'; import { taskManagerMock } from '@kbn/task-manager-plugin/server/mocks'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { ruleTypeRegistryMock } from '../../rule_type_registry.mock'; import { alertingAuthorizationMock } from '../../authorization/alerting_authorization.mock'; import { encryptedSavedObjectsMock } from '@kbn/encrypted-saved-objects-plugin/server/mocks'; diff --git a/x-pack/plugins/alerting/server/rules_client/tests/test_helpers.ts b/x-pack/plugins/alerting/server/rules_client/tests/test_helpers.ts index 0100242672be9..08c037e9410e7 100644 --- a/x-pack/plugins/alerting/server/rules_client/tests/test_helpers.ts +++ b/x-pack/plugins/alerting/server/rules_client/tests/test_helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; export const savedObjectWith500Error = { id: 'id2', diff --git a/x-pack/plugins/alerting/server/saved_objects/migrations/7.11/index.ts b/x-pack/plugins/alerting/server/saved_objects/migrations/7.11/index.ts index 186b20679c00d..0a4dc41390f2b 100644 --- a/x-pack/plugins/alerting/server/saved_objects/migrations/7.11/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/migrations/7.11/index.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { SavedObjectAttributes } from '@kbn/core-saved-objects-common'; +import { SavedObjectAttributes } from '@kbn/core-saved-objects-server'; import { SavedObjectUnsanitizedDoc } from '@kbn/core-saved-objects-server'; import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { RawRule, RawRuleAction } from '../../../types'; diff --git a/x-pack/plugins/alerting/server/saved_objects/migrations/7.13/index.ts b/x-pack/plugins/alerting/server/saved_objects/migrations/7.13/index.ts index 67b595531dfdb..75848e1a304c4 100644 --- a/x-pack/plugins/alerting/server/saved_objects/migrations/7.13/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/migrations/7.13/index.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { SavedObjectAttribute } from '@kbn/core-saved-objects-common'; +import { SavedObjectAttribute } from '@kbn/core-saved-objects-server'; import { SavedObjectUnsanitizedDoc } from '@kbn/core-saved-objects-server'; import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { RawRule } from '../../../types'; diff --git a/x-pack/plugins/alerting/server/saved_objects/migrations/7.15/index.ts b/x-pack/plugins/alerting/server/saved_objects/migrations/7.15/index.ts index a7b90ab347a71..e972f7e754f0f 100644 --- a/x-pack/plugins/alerting/server/saved_objects/migrations/7.15/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/migrations/7.15/index.ts @@ -9,7 +9,7 @@ import { SavedObjectAttribute, SavedObjectAttributes, SavedObjectReference, -} from '@kbn/core-saved-objects-common'; +} from '@kbn/core-saved-objects-server'; import { SavedObjectUnsanitizedDoc } from '@kbn/core-saved-objects-server'; import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { isString } from 'lodash/fp'; diff --git a/x-pack/plugins/alerting/server/saved_objects/migrations/7.16/index.ts b/x-pack/plugins/alerting/server/saved_objects/migrations/7.16/index.ts index 35aded8311803..bf2870eb613bb 100644 --- a/x-pack/plugins/alerting/server/saved_objects/migrations/7.16/index.ts +++ b/x-pack/plugins/alerting/server/saved_objects/migrations/7.16/index.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { SavedObjectAttribute, SavedObjectReference } from '@kbn/core-saved-objects-common'; +import { SavedObjectAttribute, SavedObjectReference } from '@kbn/core-saved-objects-server'; import { SavedObjectUnsanitizedDoc } from '@kbn/core-saved-objects-server'; import { EncryptedSavedObjectsPluginSetup } from '@kbn/encrypted-saved-objects-plugin/server'; import { isString } from 'lodash/fp'; diff --git a/x-pack/plugins/alerting/tsconfig.json b/x-pack/plugins/alerting/tsconfig.json index 73c407bd325a8..1f7017de59a2e 100644 --- a/x-pack/plugins/alerting/tsconfig.json +++ b/x-pack/plugins/alerting/tsconfig.json @@ -34,7 +34,6 @@ "@kbn/rule-data-utils", "@kbn/logging-mocks", "@kbn/core-logging-server-mocks", - "@kbn/core-saved-objects-common", "@kbn/securitysolution-rules", "@kbn/apm-utils", "@kbn/data-views-plugin", diff --git a/x-pack/plugins/cases/server/authorization/authorization.ts b/x-pack/plugins/cases/server/authorization/authorization.ts index 07c4b70e45bb6..884ae817a7a95 100644 --- a/x-pack/plugins/cases/server/authorization/authorization.ts +++ b/x-pack/plugins/cases/server/authorization/authorization.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { KibanaRequest, Logger } from '@kbn/core/server'; import Boom from '@hapi/boom'; import type { SecurityPluginStart } from '@kbn/security-plugin/server'; diff --git a/x-pack/plugins/cases/server/authorization/utils.ts b/x-pack/plugins/cases/server/authorization/utils.ts index 1b1a7b218c0e8..3ca28e3f2d7e3 100644 --- a/x-pack/plugins/cases/server/authorization/utils.ts +++ b/x-pack/plugins/cases/server/authorization/utils.ts @@ -8,7 +8,7 @@ import { partition, remove, uniq } from 'lodash'; import type { KueryNode } from '@kbn/es-query'; import { nodeBuilder } from '@kbn/es-query'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { OWNER_FIELD } from '../../common/api'; export const getOwnersFilter = ( diff --git a/x-pack/plugins/cases/server/common/types.ts b/x-pack/plugins/cases/server/common/types.ts index 8ae038992b28f..6a9eaed578a8f 100644 --- a/x-pack/plugins/cases/server/common/types.ts +++ b/x-pack/plugins/cases/server/common/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { KueryNode } from '@kbn/es-query'; import type { CaseAttributes, SavedObjectFindOptions } from '../../common/api'; diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/saved_objects_encryption_extension.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/saved_objects_encryption_extension.ts index 32015c8c23036..10c870275e590 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/saved_objects_encryption_extension.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/saved_objects_encryption_extension.ts @@ -5,11 +5,11 @@ * 2.0. */ -import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { EncryptedObjectDescriptor, ISavedObjectsEncryptionExtension, ISavedObjectTypeRegistry, + SavedObject, } from '@kbn/core-saved-objects-server'; import type { AuthenticatedUser } from '@kbn/security-plugin/common'; diff --git a/x-pack/plugins/encrypted_saved_objects/tsconfig.json b/x-pack/plugins/encrypted_saved_objects/tsconfig.json index 4359bebb24833..7d60b8171f1d9 100644 --- a/x-pack/plugins/encrypted_saved_objects/tsconfig.json +++ b/x-pack/plugins/encrypted_saved_objects/tsconfig.json @@ -10,7 +10,6 @@ "@kbn/core", "@kbn/utility-types", "@kbn/core-saved-objects-server", - "@kbn/core-saved-objects-common", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/fleet/server/services/agents/action.mock.ts b/x-pack/plugins/fleet/server/services/agents/action.mock.ts index 7f381ba009066..3534327e196db 100644 --- a/x-pack/plugins/fleet/server/services/agents/action.mock.ts +++ b/x-pack/plugins/fleet/server/services/agents/action.mock.ts @@ -7,7 +7,7 @@ import { elasticsearchServiceMock, savedObjectsClientMock } from '@kbn/core/server/mocks'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { AgentPolicy } from '../../types'; diff --git a/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts b/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts index aa4f634b700af..b1abbca792cea 100644 --- a/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts +++ b/x-pack/plugins/lens/server/embeddable/make_lens_embeddable_factory.ts @@ -7,7 +7,7 @@ import { EmbeddableRegistryDefinition } from '@kbn/embeddable-plugin/server'; import type { SerializableRecord } from '@kbn/utility-types'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; +import type { SavedObject } from '@kbn/core-saved-objects-server'; import { mergeMigrationFunctionMaps, MigrateFunctionsObject, diff --git a/x-pack/plugins/lens/tsconfig.json b/x-pack/plugins/lens/tsconfig.json index d09cd3fd47eb4..86430fa103252 100644 --- a/x-pack/plugins/lens/tsconfig.json +++ b/x-pack/plugins/lens/tsconfig.json @@ -62,6 +62,7 @@ "@kbn/language-documentation-popover", "@kbn/core-saved-objects-common", "@kbn/core-ui-settings-browser", + "@kbn/core-saved-objects-server", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/observability/server/services/slo/fixtures/slo.ts b/x-pack/plugins/observability/server/services/slo/fixtures/slo.ts index 9d68ad174f127..3a097cc0a8381 100644 --- a/x-pack/plugins/observability/server/services/slo/fixtures/slo.ts +++ b/x-pack/plugins/observability/server/services/slo/fixtures/slo.ts @@ -7,7 +7,7 @@ import { cloneDeep } from 'lodash'; import { v1 as uuidv1 } from 'uuid'; -import { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import { sloSchema, CreateSLOParams } from '@kbn/slo-schema'; import { SO_SLO_TYPE } from '../../../saved_objects'; diff --git a/x-pack/plugins/observability/tsconfig.json b/x-pack/plugins/observability/tsconfig.json index 0460c75bf1011..04217f4087e17 100644 --- a/x-pack/plugins/observability/tsconfig.json +++ b/x-pack/plugins/observability/tsconfig.json @@ -63,7 +63,6 @@ "@kbn/logging", "@kbn/core-saved-objects-api-server", "@kbn/core-saved-objects-utils-server", - "@kbn/core-saved-objects-common", "@kbn/share-plugin", "@kbn/core-notifications-browser", "@kbn/slo-schema", diff --git a/x-pack/plugins/security/server/saved_objects/saved_objects_security_extension.ts b/x-pack/plugins/security/server/saved_objects/saved_objects_security_extension.ts index 6a85951231a59..e464fbe8e4478 100644 --- a/x-pack/plugins/security/server/saved_objects/saved_objects_security_extension.ts +++ b/x-pack/plugins/security/server/saved_objects/saved_objects_security_extension.ts @@ -6,7 +6,6 @@ */ import type { SavedObjectsClient } from '@kbn/core-saved-objects-api-server-internal'; -import type { SavedObject } from '@kbn/core-saved-objects-common'; import type { AddAuditEventParams, AuthorizationTypeEntry, @@ -17,6 +16,7 @@ import type { ISavedObjectsSecurityExtension, PerformAuthorizationParams, RedactNamespacesParams, + SavedObject, } from '@kbn/core-saved-objects-server'; import { ALL_SPACES_ID, UNKNOWN_SPACE } from '../../common/constants'; diff --git a/x-pack/plugins/security/tsconfig.json b/x-pack/plugins/security/tsconfig.json index 46043f33e56ec..ac00fedba9ebe 100644 --- a/x-pack/plugins/security/tsconfig.json +++ b/x-pack/plugins/security/tsconfig.json @@ -45,7 +45,6 @@ "@kbn/es-errors", "@kbn/logging", "@kbn/core-saved-objects-api-server-internal", - "@kbn/core-saved-objects-common", "@kbn/core-saved-objects-api-server-mocks", "@kbn/logging-mocks", "@kbn/web-worker-stub", diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts index 305963e1ce430..d720306f357c6 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/bulk_cruds/delete_monitor_bulk.ts @@ -5,7 +5,7 @@ * 2.0. */ import { SavedObjectsClientContract, KibanaRequest } from '@kbn/core/server'; -import { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import { formatTelemetryDeleteEvent, sendTelemetryEvents, diff --git a/x-pack/plugins/synthetics/tsconfig.json b/x-pack/plugins/synthetics/tsconfig.json index 685a74cc6e871..e752376f4e908 100644 --- a/x-pack/plugins/synthetics/tsconfig.json +++ b/x-pack/plugins/synthetics/tsconfig.json @@ -70,6 +70,7 @@ "@kbn/actions-plugin", "@kbn/core-elasticsearch-server", "@kbn/core-saved-objects-api-server-mocks", + "@kbn/core-saved-objects-server", ], "exclude": [ "target/**/*", diff --git a/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts b/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts index 1ea7933ce57de..73fcffe5a67e0 100644 --- a/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts +++ b/x-pack/test/api_integration/apis/synthetics/sync_global_params.ts @@ -15,7 +15,7 @@ import { secretKeys } from '@kbn/synthetics-plugin/common/constants/monitor_mana import { PackagePolicy } from '@kbn/fleet-plugin/common'; import expect from '@kbn/expect'; import { syntheticsParamType } from '@kbn/synthetics-plugin/common/types/saved_objects'; -import { SavedObject } from '@kbn/core-saved-objects-common'; +import { SavedObject } from '@kbn/core-saved-objects-server'; import { FtrProviderContext } from '../../ftr_provider_context'; import { getFixtureJson } from '../uptime/rest/helper/get_fixture_json'; import { PrivateLocationTestService } from './services/private_location_test_service'; diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index b3be2d080e7fe..0deb6cd41c437 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -105,7 +105,6 @@ "@kbn/controls-plugin", "@kbn/core-saved-objects-server", "@kbn/core-provider-plugin", - "@kbn/core-saved-objects-common", "@kbn/user-profile-components", "@kbn/apm-synthtrace-client", "@kbn/utils", From 43247bdc0f21906f20aec63694de45f037eeceb1 Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Wed, 25 Jan 2023 13:53:50 +0100 Subject: [PATCH 02/11] [Fleet] fix updates available when beta integrations are off (#149486) ## Summary Fixes https://github.com/elastic/kibana/issues/149470 Loading installed packages with prerelease flag, so that the `Updates available` is not showing prerelease versions when prerelease flag is off. How to test: - Install endpoint latest GA (8.6.1) - Check that there are no updates available on `Installed integrations` tab - Enable `Show Beta integrations` switch - Check that there is 1 badge in `Updates available`, showing the latest `Endpoint` `8.7.0-next` version. image image Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../sections/epm/screens/home/available_packages.tsx | 5 ++++- .../integrations/sections/epm/screens/home/index.tsx | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/available_packages.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/available_packages.tsx index 95d89491c620a..640c482376cc1 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/available_packages.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/available_packages.tsx @@ -97,7 +97,9 @@ function OnPremLink() { ); } -export const AvailablePackages: React.FC<{}> = ({}) => { +export const AvailablePackages: React.FC<{ + setPrereleaseEnabled: (isEnabled: boolean) => void; +}> = ({ setPrereleaseEnabled }) => { useBreadcrumbs('integrations_all'); const { @@ -137,6 +139,7 @@ export const AvailablePackages: React.FC<{}> = ({}) => { onChange={setPreference} onPrereleaseEnabledChange={(isEnabled) => { setPrereleaseIntegrationsEnabled(isEnabled); + setPrereleaseEnabled(isEnabled); }} /> , diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/index.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/index.tsx index 7b0431a1cd618..d69fe175f0961 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/index.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/home/index.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useMemo } from 'react'; +import React, { useMemo, useState } from 'react'; import { Switch, Route } from 'react-router-dom'; import type { CustomIntegration } from '@kbn/custom-integrations-plugin/common'; @@ -112,9 +112,11 @@ export const mapToCard = ({ }; export const EPMHomePage: React.FC = () => { + const [prereleaseEnabled, setPrereleaseEnabled] = useState(false); + // loading packages to find installed ones const { data: allPackages, isLoading } = useGetPackages({ - prerelease: true, + prerelease: prereleaseEnabled, }); const installedPackages = useMemo( @@ -141,7 +143,7 @@ export const EPMHomePage: React.FC = () => { - + From 026d3473054fdcb7d9c12da7089fb00dcba54e2b Mon Sep 17 00:00:00 2001 From: Katerina Patticha Date: Wed, 25 Jan 2023 13:56:53 +0100 Subject: [PATCH 03/11] [APM] Display comparison for mobile stats (#149097) ## Summary related to https://github.com/elastic/kibana/issues/146854 1. Show the comparison for the mobile stats 2. Display a badge "comparison not supported" (when the comparison is enabled )for the components that don't support comparison 3. display "coming soon" text for the metrics that are not available yet Addressing feedback - Replace the badge with a tooltip with an icon - Always display the previous state for metrics when loading and add the spinner - Update Crash rate to Crash rate (Crash per minute) - Remove fallback to transaction events badge ## Before image ## After ![Jan-25-2023 09-52-53](https://user-images.githubusercontent.com/3369346/214520021-6ff04d13-250a-47bd-b983-66c6f35cfb46.gif) Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../src/scenarios/mobile.ts | 4 +- .../app/mobile/service_overview/index.tsx | 56 +++++++----- .../service_overview/latency_map/index.tsx | 40 +++++++-- .../mobile/service_overview/stats/index.tsx | 85 ++++++++++++++----- .../service_overview/stats/metric_item.tsx | 11 ++- .../app/mobile/transaction_overview/index.tsx | 14 +-- .../plugins/apm/server/routes/mobile/route.ts | 4 +- .../tests/mobile/generate_mobile_data.ts | 4 +- .../mobile_http_requests_timeseries.spec.ts | 8 +- 9 files changed, 152 insertions(+), 74 deletions(-) diff --git a/packages/kbn-apm-synthtrace/src/scenarios/mobile.ts b/packages/kbn-apm-synthtrace/src/scenarios/mobile.ts index 85fdee43b713c..0d57b99d9230e 100644 --- a/packages/kbn-apm-synthtrace/src/scenarios/mobile.ts +++ b/packages/kbn-apm-synthtrace/src/scenarios/mobile.ts @@ -356,7 +356,9 @@ const scenario: Scenario = async ({ scenarioOpts, logger }) => { .span({ spanName: 'onCreate', spanType: 'app', - spanSubtype: 'internal', + spanSubtype: 'external', + 'service.target.type': 'http', + 'span.destination.service.resource': 'external', }) .duration(50) .success() diff --git a/x-pack/plugins/apm/public/components/app/mobile/service_overview/index.tsx b/x-pack/plugins/apm/public/components/app/mobile/service_overview/index.tsx index 847df33534455..92cb472307888 100644 --- a/x-pack/plugins/apm/public/components/app/mobile/service_overview/index.tsx +++ b/x-pack/plugins/apm/public/components/app/mobile/service_overview/index.tsx @@ -16,6 +16,7 @@ import { EuiSpacer, EuiTitle, EuiCallOut, + EuiIconTip, } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; @@ -38,7 +39,6 @@ import { MostUsedChart } from './most_used_chart'; import { LatencyMap } from './latency_map'; import { FailedTransactionRateChart } from '../../../shared/charts/failed_transaction_rate_chart'; import { ServiceOverviewDependenciesTable } from '../../service_overview/service_overview_dependencies_table'; -import { AggregatedTransactionsBadge } from '../../../shared/aggregated_transactions_badge'; import { LatencyChart } from '../../../shared/charts/latency_chart'; import { useFiltersForEmbeddableCharts } from '../../../../hooks/use_filters_for_embeddable_charts'; import { getKueryWithMobileFilters } from '../../../../../common/utils/get_kuery_with_mobile_filters'; @@ -50,7 +50,7 @@ import { MobileStats } from './stats'; export const chartHeight = 288; export function MobileServiceOverview() { - const { serviceName, fallbackToTransactions } = useApmServiceContext(); + const { serviceName } = useApmServiceContext(); const router = useApmRouter(); const embeddableFilters = useFiltersForEmbeddableCharts(); @@ -65,6 +65,7 @@ export function MobileServiceOverview() { osVersion, appVersion, netConnectionType, + comparisonEnabled, }, } = useApmParams('/mobile-services/{serviceName}/overview'); @@ -142,11 +143,6 @@ export function MobileServiceOverview() { - {fallbackToTransactions && ( - - - - )} - - -

- {i18n.translate( - 'xpack.apm.serviceOverview.mostUsedTitle', - { - defaultMessage: 'Most used', - } - )} -

-
-
+ + + +

+ {i18n.translate( + 'xpack.apm.serviceOverview.mostUsedTitle', + { + defaultMessage: 'Top 5 most used', + } + )} +

+
+
+ + {comparisonEnabled && ( + + )} + +
+ {/* Device */} diff --git a/x-pack/plugins/apm/public/components/app/mobile/service_overview/latency_map/index.tsx b/x-pack/plugins/apm/public/components/app/mobile/service_overview/latency_map/index.tsx index 2bc0e18bf04cc..6ac672dea1f06 100644 --- a/x-pack/plugins/apm/public/components/app/mobile/service_overview/latency_map/index.tsx +++ b/x-pack/plugins/apm/public/components/app/mobile/service_overview/latency_map/index.tsx @@ -6,7 +6,13 @@ */ import React from 'react'; -import { EuiTitle, EuiSpacer } from '@elastic/eui'; +import { + EuiFlexGroup, + EuiFlexItem, + EuiSpacer, + EuiTitle, + EuiIconTip, +} from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import type { Filter } from '@kbn/es-query'; import { EmbeddedMap } from './embedded_map'; @@ -16,21 +22,39 @@ export function LatencyMap({ end, kuery, filters, + comparisonEnabled, }: { start: string; end: string; kuery?: string; filters: Filter[]; + comparisonEnabled: boolean; }) { return ( <> - -

- {i18n.translate('xpack.apm.serviceOverview.embeddedMap.title', { - defaultMessage: 'Average latency per country', - })} -

-
+ + + +

+ {i18n.translate('xpack.apm.serviceOverview.embeddedMap.title', { + defaultMessage: 'Average latency per country', + })} +

+
+
+ + {comparisonEnabled && ( + + )} + +
diff --git a/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/index.tsx b/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/index.tsx index d94e988ba6d71..2bc6f221540bc 100644 --- a/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/index.tsx +++ b/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/index.tsx @@ -6,30 +6,24 @@ */ import { MetricDatum, MetricTrendShape } from '@elastic/charts'; import { i18n } from '@kbn/i18n'; -import { EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import React from 'react'; +import { + EuiIcon, + EuiFlexGroup, + EuiFlexItem, + EuiLoadingSpinner, +} from '@elastic/eui'; +import React, { useCallback } from 'react'; import { useTheme } from '@kbn/observability-plugin/public'; +import { isEmpty } from 'lodash'; import { useAnyOfApmParams } from '../../../../../hooks/use_apm_params'; import { useFetcher, FETCH_STATUS } from '../../../../../hooks/use_fetcher'; import { MetricItem } from './metric_item'; +import { usePreviousPeriodLabel } from '../../../../../hooks/use_previous_period_text'; const valueFormatter = (value: number, suffix = '') => { return `${value} ${suffix}`; }; -const getIcon = - (type: string) => - ({ - width = 20, - height = 20, - color, - }: { - width: number; - height: number; - color: string; - }) => - ; - export function MobileStats({ start, end, @@ -43,9 +37,11 @@ export function MobileStats({ const { path: { serviceName }, - query: { environment, transactionType }, + query: { environment, transactionType, offset, comparisonEnabled }, } = useAnyOfApmParams('/mobile-services/{serviceName}/overview'); + const previousPeriodLabel = usePreviousPeriodLabel(); + const { data, status } = useFetcher( (callApmApi) => { return callApmApi( @@ -59,31 +55,71 @@ export function MobileStats({ environment, kuery, transactionType, + offset, }, }, } ); }, - [start, end, environment, kuery, serviceName, transactionType] + [start, end, environment, kuery, serviceName, transactionType, offset] + ); + + const getComparisonValueFormatter = useCallback( + (value) => { + return ( + + {value && comparisonEnabled + ? `${previousPeriodLabel}: ${value}` + : null} + + ); + }, + [comparisonEnabled, previousPeriodLabel] + ); + + const getIcon = useCallback( + (type: string) => + ({ + width = 20, + height = 20, + color, + }: { + width: number; + height: number; + color: string; + }) => { + return status === FETCH_STATUS.LOADING ? ( + + ) : ( + + ); + }, + [status] ); const metrics: MetricDatum[] = [ { - color: euiTheme.eui.euiColorLightestShade, + color: euiTheme.eui.euiColorDisabled, title: i18n.translate('xpack.apm.mobile.metrics.crash.rate', { - defaultMessage: 'Crash Rate', + defaultMessage: 'Crash Rate (Crash per minute)', + }), + subtitle: i18n.translate('xpack.apm.mobile.coming.soon', { + defaultMessage: 'Coming Soon', }), icon: getIcon('bug'), value: 'N/A', - valueFormatter: (value: number) => valueFormatter(value, 'cpm'), + valueFormatter: (value: number) => valueFormatter(value), trend: [], trendShape: MetricTrendShape.Area, }, { - color: euiTheme.eui.euiColorLightestShade, + color: euiTheme.eui.euiColorDisabled, title: i18n.translate('xpack.apm.mobile.metrics.load.time', { defaultMessage: 'Slowest App load time', }), + subtitle: i18n.translate('xpack.apm.mobile.coming.soon', { + defaultMessage: 'Coming Soon', + }), icon: getIcon('visGauge'), value: 'N/A', valueFormatter: (value: number) => valueFormatter(value, 's'), @@ -99,6 +135,7 @@ export function MobileStats({ value: data?.currentPeriod?.sessions?.value ?? NaN, valueFormatter: (value: number) => valueFormatter(value), trend: data?.currentPeriod?.sessions?.timeseries, + extra: getComparisonValueFormatter(data?.previousPeriod.sessions?.value), trendShape: MetricTrendShape.Area, }, { @@ -108,8 +145,9 @@ export function MobileStats({ }), icon: getIcon('kubernetesPod'), value: data?.currentPeriod?.requests?.value ?? NaN, + extra: getComparisonValueFormatter(data?.previousPeriod.requests?.value), valueFormatter: (value: number) => valueFormatter(value), - trend: data?.currentPeriod?.requests?.timeseries ?? [], + trend: data?.currentPeriod?.requests?.timeseries, trendShape: MetricTrendShape.Area, }, ]; @@ -121,7 +159,8 @@ export function MobileStats({
))} diff --git a/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/metric_item.tsx b/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/metric_item.tsx index fb90e775780a9..7ddcdea271397 100644 --- a/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/metric_item.tsx +++ b/x-pack/plugins/apm/public/components/app/mobile/service_overview/stats/metric_item.tsx @@ -7,15 +7,18 @@ import React from 'react'; import { Chart, Metric, MetricDatum } from '@elastic/charts'; import { EuiLoadingContent, EuiPanel } from '@elastic/eui'; +import { FETCH_STATUS, isPending } from '../../../../../hooks/use_fetcher'; export function MetricItem({ data, id, - isLoading, + status, + hasData, }: { data: MetricDatum[]; id: number; - isLoading: boolean; + status: FETCH_STATUS; + hasData: boolean; }) { return (
- {isLoading ? ( + {!hasData && isPending(status) ? ( diff --git a/x-pack/plugins/apm/public/components/app/mobile/transaction_overview/index.tsx b/x-pack/plugins/apm/public/components/app/mobile/transaction_overview/index.tsx index 3194a21c5d14a..ecebbeab50986 100644 --- a/x-pack/plugins/apm/public/components/app/mobile/transaction_overview/index.tsx +++ b/x-pack/plugins/apm/public/components/app/mobile/transaction_overview/index.tsx @@ -6,7 +6,6 @@ */ import { - EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiPanel, @@ -17,7 +16,6 @@ import { useHistory } from 'react-router-dom'; import { useApmServiceContext } from '../../../../context/apm_service/use_apm_service_context'; import { useApmParams } from '../../../../hooks/use_apm_params'; import { useTimeRange } from '../../../../hooks/use_time_range'; -import { AggregatedTransactionsBadge } from '../../../shared/aggregated_transactions_badge'; import { TransactionsTable } from '../../../shared/transactions_table'; import { replace } from '../../../shared/links/url_helpers'; import { getKueryWithMobileFilters } from '../../../../../common/utils/get_kuery_with_mobile_filters'; @@ -51,7 +49,7 @@ export function MobileTransactionOverview() { const { start, end } = useTimeRange({ rangeFrom, rangeTo }); - const { transactionType, fallbackToTransactions } = useApmServiceContext(); + const { transactionType } = useApmServiceContext(); const history = useHistory(); @@ -65,16 +63,6 @@ export function MobileTransactionOverview() { - {fallbackToTransactions && ( - <> - - - - - - - - )} item.y === 0 && item.x) - ).to.eql(true); + expect(response.body.currentPeriod.timeseries.some((item) => item.x && item.y)).to.eql( + true + ); expect(response.body.previousPeriod.timeseries[0].y).to.eql(0); }); @@ -88,7 +88,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { response.body.currentPeriod.timeseries.some((item) => item.y === 0 && item.x) ).to.eql(true); - expect(response.body.currentPeriod.timeseries[0].y).to.eql(0); + expect(response.body.currentPeriod.timeseries[0].y).to.eql(1); expect(response.body.previousPeriod.timeseries).to.eql([]); }); }); From e6f24a227200a2d40e3e5727f30c49cb524510a7 Mon Sep 17 00:00:00 2001 From: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com> Date: Wed, 25 Jan 2023 08:15:48 -0500 Subject: [PATCH 04/11] [Cases] Adding oldestPushDate field to get connectors API (#149451) This PR adds the `oldestPushDate` field to the `_connectors` API. This is needed to determine whether to show the text `pushed as new incident ` or `updated incident `. Update response ``` { "8548e270-9c26-11ed-8376-87998de9968e": { "name": "Jira", "type": ".jira", "fields": { "issueType": "10001", "parent": null, "priority": null }, "id": "8548e270-9c26-11ed-8376-87998de9968e", "needsToBePushed": false, "latestPushDate": "2023-01-24T20:35:54.325Z", "oldestPushDate": "2023-01-24T20:35:43.730Z", <--- New field "hasBeenPushed": true } } ``` --- .../cases/common/api/connectors/index.ts | 2 +- .../server/client/user_actions/connectors.ts | 64 +++++++++---- .../server/services/user_actions/index.ts | 89 +++++++++++++------ .../server/services/user_actions/types.ts | 7 +- .../tests/trial/internal/get_connectors.ts | 7 +- 5 files changed, 119 insertions(+), 50 deletions(-) diff --git a/x-pack/plugins/cases/common/api/connectors/index.ts b/x-pack/plugins/cases/common/api/connectors/index.ts index 8aac471c634b8..7ed31947e9c12 100644 --- a/x-pack/plugins/cases/common/api/connectors/index.ts +++ b/x-pack/plugins/cases/common/api/connectors/index.ts @@ -120,7 +120,7 @@ export const GetCaseConnectorsResponseRt = rt.record( rt.string, rt.intersection([ rt.type({ needsToBePushed: rt.boolean, hasBeenPushed: rt.boolean }), - rt.partial(rt.type({ latestPushDate: rt.string }).props), + rt.partial(rt.type({ latestPushDate: rt.string, oldestPushDate: rt.string }).props), CaseConnectorRt, ]) ); diff --git a/x-pack/plugins/cases/server/client/user_actions/connectors.ts b/x-pack/plugins/cases/server/client/user_actions/connectors.ts index 3eb02b11c3d75..0239d740e4069 100644 --- a/x-pack/plugins/cases/server/client/user_actions/connectors.ts +++ b/x-pack/plugins/cases/server/client/user_actions/connectors.ts @@ -22,7 +22,7 @@ import type { CasesClientArgs } from '..'; import type { Authorization, OwnerEntity } from '../../authorization'; import { Operations } from '../../authorization'; import type { GetConnectorsRequest } from './types'; -import type { CaseConnectorActivity, PushInfo } from '../../services/user_actions/types'; +import type { CaseConnectorActivity } from '../../services/user_actions/types'; import type { CaseUserActionService } from '../../services'; export const getConnectors = async ( @@ -82,10 +82,18 @@ const checkConnectorsAuthorization = async ({ }); if (connector.push) { - entities.push({ - owner: connector.push.attributes.owner, - id: connector.connectorId, - }); + entities.push( + ...[ + { + owner: connector.push.mostRecent.attributes.owner, + id: connector.connectorId, + }, + { + owner: connector.push.oldest.attributes.owner, + id: connector.connectorId, + }, + ] + ); } } @@ -96,7 +104,8 @@ const checkConnectorsAuthorization = async ({ }; interface EnrichedPushInfo { - pushDate: Date; + latestPushDate: Date; + oldestPushDate: Date; connectorFieldsUsedInPush: CaseConnector; } @@ -123,6 +132,12 @@ const getConnectorsInfo = async ({ return createConnectorInfoResult({ actionConnectors, connectors, pushInfo, latestUserAction }); }; +interface PushTimeFrameDetails { + connectorId: string; + mostRecentPush: Date; + oldestPush: Date; +} + const getPushInfo = async ({ caseId, activity, @@ -132,29 +147,39 @@ const getPushInfo = async ({ activity: CaseConnectorActivity[]; userActionService: CaseUserActionService; }): Promise> => { - const pushRequest: PushInfo[] = []; + const pushDetails: PushTimeFrameDetails[] = []; for (const connectorInfo of activity) { - const pushCreatedAt = getDate(connectorInfo.push?.attributes.created_at); - - if (connectorInfo.push != null && pushCreatedAt != null) { - pushRequest.push({ connectorId: connectorInfo.connectorId, date: pushCreatedAt }); + const mostRecentPushCreatedAt = getDate(connectorInfo.push?.mostRecent.attributes.created_at); + const oldestPushCreatedAt = getDate(connectorInfo.push?.oldest.attributes.created_at); + + if ( + connectorInfo.push != null && + mostRecentPushCreatedAt != null && + oldestPushCreatedAt != null + ) { + pushDetails.push({ + connectorId: connectorInfo.connectorId, + mostRecentPush: mostRecentPushCreatedAt, + oldestPush: oldestPushCreatedAt, + }); } } const connectorFieldsForPushes = await userActionService.getConnectorFieldsBeforeLatestPush( caseId, - pushRequest + pushDetails.map((push) => ({ connectorId: push.connectorId, date: push.mostRecentPush })) ); const enrichedPushInfo = new Map(); - for (const request of pushRequest) { - const connectorFieldsSO = connectorFieldsForPushes.get(request.connectorId); + for (const pushInfo of pushDetails) { + const connectorFieldsSO = connectorFieldsForPushes.get(pushInfo.connectorId); const connectorFields = getConnectorInfoFromSavedObject(connectorFieldsSO); if (connectorFields != null) { - enrichedPushInfo.set(request.connectorId, { - pushDate: request.date, + enrichedPushInfo.set(pushInfo.connectorId, { + latestPushDate: pushInfo.mostRecentPush, + oldestPushDate: pushInfo.oldestPush, connectorFieldsUsedInPush: connectorFields, }); } @@ -223,7 +248,8 @@ const createConnectorInfoResult = ({ ...connector, name: connectorDetails.name, needsToBePushed, - latestPushDate: enrichedPushInfo?.pushDate.toISOString(), + latestPushDate: enrichedPushInfo?.latestPushDate.toISOString(), + oldestPushDate: enrichedPushInfo?.oldestPushDate.toISOString(), hasBeenPushed: hasBeenPushed(enrichedPushInfo), }; } @@ -256,7 +282,9 @@ const hasDataToPush = ({ * push fields will be undefined which will not equal the latest connector fields anyway. */ !isEqual(connector, pushInfo?.connectorFieldsUsedInPush) || - (pushInfo != null && latestUserActionDate != null && latestUserActionDate > pushInfo.pushDate) + (pushInfo != null && + latestUserActionDate != null && + latestUserActionDate > pushInfo.latestPushDate) ); }; diff --git a/x-pack/plugins/cases/server/services/user_actions/index.ts b/x-pack/plugins/cases/server/services/user_actions/index.ts index 0612c1374a4ec..9db6c25c5e496 100644 --- a/x-pack/plugins/cases/server/services/user_actions/index.ts +++ b/x-pack/plugins/cases/server/services/user_actions/index.ts @@ -26,7 +26,13 @@ import { MAX_DOCS_PER_PAGE, } from '../../../common/constants'; import { buildFilter, combineFilters } from '../../client/utils'; -import type { CaseConnectorActivity, CaseConnectorFields, PushInfo, ServiceContext } from './types'; +import type { + CaseConnectorActivity, + CaseConnectorFields, + PushInfo, + PushTimeFrameInfo, + ServiceContext, +} from './types'; import { defaultSortField } from '../../common/utils'; import { UserActionPersister } from './operations/create'; import { UserActionFinder } from './operations/find'; @@ -37,15 +43,18 @@ export interface UserActionItem { references: SavedObjectReference[]; } -interface MostRecentResults { - mostRecent: { - hits: { - total: number; - hits: SavedObjectsRawDoc[]; - }; +interface TopHits { + hits: { + total: number; + hits: SavedObjectsRawDoc[]; }; } +interface TimeFrameInfo { + mostRecent: TopHits; + oldest: TopHits; +} + interface ConnectorActivityAggsResult { references: { connectors: { @@ -55,9 +64,9 @@ interface ConnectorActivityAggsResult { reverse: { connectorActivity: { buckets: { - changeConnector: MostRecentResults; - createCase: MostRecentResults; - pushInfo: MostRecentResults; + changeConnector: TimeFrameInfo; + createCase: TimeFrameInfo; + pushInfo: TimeFrameInfo; }; }; }; @@ -72,7 +81,7 @@ interface ConnectorFieldsBeforePushAggsResult { connectors: { reverse: { ids: { - buckets: Record; + buckets: Record; }; }; }; @@ -381,28 +390,13 @@ export class CaseUserActionService { ); } - const pushInfo = connectorInfo.reverse.connectorActivity.buckets.pushInfo; - let pushDoc: SavedObject | undefined; - - if (pushInfo.mostRecent.hits.hits.length > 0) { - const rawPushDoc = pushInfo.mostRecent.hits.hits[0]; - - const doc = - this.context.savedObjectsSerializer.rawToSavedObject( - rawPushDoc - ); - - pushDoc = transformToExternalModel( - doc, - this.context.persistableStateAttachmentTypeRegistry - ); - } + const pushDocs = this.getPushDocs(connectorInfo.reverse.connectorActivity.buckets.pushInfo); if (fieldsDoc != null) { caseConnectorInfo.push({ connectorId: connectorInfo.key, fields: fieldsDoc, - push: pushDoc, + push: pushDocs, }); } else { this.context.log.warn(`Unable to find fields for connector id: ${connectorInfo.key}`); @@ -412,6 +406,33 @@ export class CaseUserActionService { return caseConnectorInfo; } + private getPushDocs(pushTimeFrameInfo: TimeFrameInfo): PushTimeFrameInfo | undefined { + const mostRecentPushDoc = this.getTopHitsDoc(pushTimeFrameInfo.mostRecent); + const oldestPushDoc = this.getTopHitsDoc(pushTimeFrameInfo.oldest); + + if (mostRecentPushDoc && oldestPushDoc) { + return { + mostRecent: mostRecentPushDoc, + oldest: oldestPushDoc, + }; + } + } + + private getTopHitsDoc( + topHits: TopHits + ): SavedObject | undefined { + if (topHits.hits.hits.length > 0) { + const rawPushDoc = topHits.hits.hits[0]; + + const doc = + this.context.savedObjectsSerializer.rawToSavedObject( + rawPushDoc + ); + + return transformToExternalModel(doc, this.context.persistableStateAttachmentTypeRegistry); + } + } + private static buildConnectorInfoAggs(): Record< string, estypes.AggregationsAggregationContainer @@ -480,6 +501,18 @@ export class CaseUserActionService { size: 1, }, }, + oldest: { + top_hits: { + sort: [ + { + [`${CASE_USER_ACTION_SAVED_OBJECT}.created_at`]: { + order: 'asc', + }, + }, + ], + size: 1, + }, + }, }, }, }, diff --git a/x-pack/plugins/cases/server/services/user_actions/types.ts b/x-pack/plugins/cases/server/services/user_actions/types.ts index dc37ec06d9f56..1e9e1f644b6d2 100644 --- a/x-pack/plugins/cases/server/services/user_actions/types.ts +++ b/x-pack/plugins/cases/server/services/user_actions/types.ts @@ -143,10 +143,15 @@ export interface ServiceContext { auditLogger: AuditLogger; } +export interface PushTimeFrameInfo { + mostRecent: SavedObject; + oldest: SavedObject; +} + export interface CaseConnectorActivity { connectorId: string; fields: SavedObject; - push?: SavedObject; + push?: PushTimeFrameInfo; } export type CaseConnectorFields = Map< diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts index c200cc366d5af..e4bea7009bf3e 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts @@ -233,7 +233,7 @@ export default ({ getService }: FtrProviderContext): void => { describe('push', () => { describe('latestPushDate', () => { - it('does not set latestPushDate when the connector has not been used to push', async () => { + it('does not set latestPushDate or oldestPushDate when the connector has not been used to push', async () => { const { postedCase, connector } = await createCaseWithConnector({ supertest, serviceNowSimulatorURL, @@ -245,9 +245,10 @@ export default ({ getService }: FtrProviderContext): void => { expect(Object.keys(connectors).length).to.be(1); expect(connectors).to.have.property(connector.id); expect(connectors[connector.id].latestPushDate).to.be(undefined); + expect(connectors[connector.id].oldestPushDate).to.be(undefined); }); - it('sets latestPushDate to the most recent push date', async () => { + it('sets latestPushDate to the most recent push date and oldestPushDate to the first push date', async () => { const { postedCase, connector } = await createCaseWithConnector({ supertest, serviceNowSimulatorURL, @@ -278,10 +279,12 @@ export default ({ getService }: FtrProviderContext): void => { ]); const pushes = userActions.filter((ua) => ua.type === ActionTypes.pushed); + const oldestPush = pushes[0]; const latestPush = pushes[pushes.length - 1]; expect(Object.keys(connectors).length).to.be(1); expect(connectors[connector.id].latestPushDate).to.eql(latestPush.created_at); + expect(connectors[connector.id].oldestPushDate).to.eql(oldestPush.created_at); }); }); From 83d56cd776801bfd408b3eff4d4f79517613b726 Mon Sep 17 00:00:00 2001 From: Achyut Jhunjhunwala Date: Wed, 25 Jan 2023 14:32:31 +0100 Subject: [PATCH 05/11] add language specific headers (#149400) Closes https://github.com/elastic/kibana/issues/76296 ## Summary Stacktrace for various Languages and Frameworks were not displaying proper Title. With this PR, it fixes the display of individual language-framework specific error title in Exception Stack Traces | Agent | Template | |---------|-----------| | .NET | `"${exception.type}: ${exception.message}"` | | Javascript | `"${exception.type}: ${exception.message}"` | | PHP | `"${exception.type}: ${exception.message}"` | | Python | `"${exception.type}: ${exception.message}"` | | Go | `"${exception.message}"` | | Java | `exception.message ? "${exception.type}: ${exception.message}" : "${exception.type}"` | | Ruby | `"${exception.type} (${exception.message ? exception.message : exception.type})"`| ## C# ### Before Screenshot 2023-01-24 at 14 56 29 ### After Screenshot 2023-01-24 at 14 55 13 ## Javascript ### Before Screenshot 2023-01-24 at 15 02 25 ### After Screenshot 2023-01-24 at 15 00 47 ## PHP ### Before Screenshot 2023-01-24 at 15 20 19 ### After Screenshot 2023-01-24 at 15 19 31 ## Python ### Before Screenshot 2023-01-24 at 15 21 49 ### After Screenshot 2023-01-24 at 15 23 03 ## Go ### Before and After Same Screenshot 2023-01-24 at 15 10 16 ## Java ### Before Screenshot 2023-01-24 at 15 14 19 ### After Screenshot 2023-01-24 at 15 18 07 ## Ruby ### Before Screenshot 2023-01-24 at 15 22 26 ### After Screenshot 2023-01-24 at 15 23 46 Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../exception_stacktrace.test.tsx | 10 ++++ .../error_sampler/exception_stacktrace.tsx | 13 +++-- .../exception_stacktrace_title.tsx | 47 +++++++++++++++++++ 3 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace_title.tsx diff --git a/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.test.tsx b/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.test.tsx index 9417c0c584f1b..b357c41bceb6e 100644 --- a/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.test.tsx +++ b/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.test.tsx @@ -9,6 +9,7 @@ import { composeStories } from '@storybook/testing-react'; import React from 'react'; import { mount } from 'enzyme'; import * as stories from './exception_stacktrace.stories'; +import { ExceptionStackTraceTitleProps } from './exception_stacktrace_title'; const { JavaWithLongLines } = composeStories(stories); @@ -18,6 +19,15 @@ describe('ExceptionStacktrace', () => { it('renders the stacktraces', () => { expect(mount().find('Stacktrace')).toHaveLength(3); }); + it('should have the title in a specific format', function () { + const wrapper = mount().find( + 'ExceptionStacktraceTitle' + ); + expect(wrapper).toHaveLength(1); + const { type, message } = + wrapper.props() as ExceptionStackTraceTitleProps; + expect(wrapper.text()).toContain(`${type}: ${message}`); + }); }); describe('with more than one stack trace', () => { diff --git a/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.tsx b/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.tsx index 85ad5c5336c8c..fd32b8960abb3 100644 --- a/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.tsx +++ b/x-pack/plugins/apm/public/components/app/error_group_details/error_sampler/exception_stacktrace.tsx @@ -5,11 +5,11 @@ * 2.0. */ -import { EuiTitle } from '@elastic/eui'; import React from 'react'; import { Exception } from '../../../../../typings/es_schemas/raw/error_raw'; import { Stacktrace } from '../../../shared/stacktrace'; import { CauseStacktrace } from '../../../shared/stacktrace/cause_stacktrace'; +import { ExceptionStacktraceTitle } from './exception_stacktrace_title'; interface ExceptionStacktraceProps { codeLanguage?: string; @@ -20,13 +20,16 @@ export function ExceptionStacktrace({ codeLanguage, exceptions, }: ExceptionStacktraceProps) { - const title = exceptions[0]?.message; + const message = exceptions[0]?.message; + const type = exceptions[0]?.type; return ( <> - -

{title}

-
+ {exceptions.map((ex, index) => { return index === 0 ? ( +

{title}

+ + ); +} From 52f324b9ad98ace5c975289cddb750d437ea7696 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Wed, 25 Jan 2023 10:09:50 -0400 Subject: [PATCH 06/11] [Fleet] Fix agent status when .fleet-agents do not exists (#149509) --- x-pack/plugins/fleet/server/services/agents/status.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/plugins/fleet/server/services/agents/status.ts b/x-pack/plugins/fleet/server/services/agents/status.ts index d05d972925eb5..fecc369f6ad33 100644 --- a/x-pack/plugins/fleet/server/services/agents/status.ts +++ b/x-pack/plugins/fleet/server/services/agents/status.ts @@ -106,6 +106,7 @@ export async function getAgentStatusForAgentPolicy( }, }, }, + ignore_unavailable: true, }); } catch (error) { logger.debug(`Error getting agent statuses: ${error}`); From 2589e34f3e336a311a50190183e14f5ecb6abdd6 Mon Sep 17 00:00:00 2001 From: Jordan <51442161+JordanSh@users.noreply.github.com> Date: Wed, 25 Jan 2023 16:19:03 +0200 Subject: [PATCH 07/11] [Cloud Posture] Benchmark page AWS changes (#149505) --- .../public/pages/benchmarks/benchmarks.tsx | 24 ++++++++++++------- .../pages/benchmarks/benchmarks_table.tsx | 9 ++++--- .../public/pages/benchmarks/test_subjects.ts | 2 +- .../translations/translations/fr-FR.json | 2 -- .../translations/translations/ja-JP.json | 2 -- .../translations/translations/zh-CN.json | 2 -- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx index b013f6b33dac5..cfcc48b08b15d 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks.tsx @@ -20,8 +20,8 @@ import { import { FormattedMessage } from '@kbn/i18n-react'; import useDebounce from 'react-use/lib/useDebounce'; import { i18n } from '@kbn/i18n'; -import { KSPM_POLICY_TEMPLATE } from '../../../common/constants'; -import { useCspIntegrationLink } from '../../common/navigation/use_csp_integration_link'; +import { pagePathGetters } from '@kbn/fleet-plugin/public'; +import { CLOUD_SECURITY_POSTURE_PACKAGE_NAME } from '../../../common/constants'; import { CloudPosturePageTitle } from '../../components/cloud_posture_page_title'; import { CloudPosturePage } from '../../components/cloud_posture_page'; import { BenchmarksTable } from './benchmarks_table'; @@ -33,24 +33,29 @@ import { extractErrorMessage } from '../../../common/utils/helpers'; import * as TEST_SUBJ from './test_subjects'; import { LOCAL_STORAGE_PAGE_SIZE_BENCHMARK_KEY } from '../../common/constants'; import { usePageSize } from '../../common/hooks/use_page_size'; +import { useKibana } from '../../common/hooks/use_kibana'; const SEARCH_DEBOUNCE_MS = 300; -// TODO: CIS AWS - add cspm integration button as well const AddCisIntegrationButton = () => { - const cisIntegrationLink = useCspIntegrationLink(KSPM_POLICY_TEMPLATE); + const { http } = useKibana().services; + + const integrationsPath = pagePathGetters + .integrations_all({ + searchTerm: CLOUD_SECURITY_POSTURE_PACKAGE_NAME, + }) + .join(''); return ( ); @@ -116,11 +121,12 @@ const BenchmarkSearchField = ({ diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks_table.tsx b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks_table.tsx index ee4fed93d5789..ed276dc374744 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks_table.tsx +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/benchmarks_table.tsx @@ -50,6 +50,7 @@ const IntegrationButtonLink = ({ policyId: string; }) => { const { application } = useKibana().services; + return ( > = [ }), dataType: 'string', truncateText: true, - sortable: true, 'data-test-subj': TEST_SUBJ.BENCHMARKS_TABLE_COLUMNS.INTEGRATION, render: (field: PackagePolicy) => { const enabledIntegration = getEnabledCspIntegrationDetails(field); @@ -105,13 +105,12 @@ const BENCHMARKS_TABLE_COLUMNS: Array> = [ }, { field: 'package_policy', - name: i18n.translate('xpack.csp.benchmarks.benchmarksTable.deploymentTypeColumnTitle', { - defaultMessage: 'Deployment Type', + name: i18n.translate('xpack.csp.benchmarks.benchmarksTable.monitoringColumnTitle', { + defaultMessage: 'Monitoring', }), dataType: 'string', truncateText: true, - sortable: true, - 'data-test-subj': TEST_SUBJ.BENCHMARKS_TABLE_COLUMNS.DEPLOYMENT_TYPE, + 'data-test-subj': TEST_SUBJ.BENCHMARKS_TABLE_COLUMNS.MONITORING, render: (field: PackagePolicy) => { const enabledIntegration = getEnabledCspIntegrationDetails(field); return enabledIntegration?.enabledIntegrationOption?.name || ' '; diff --git a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/test_subjects.ts b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/test_subjects.ts index d1d27325f9f88..3e75715abf32f 100644 --- a/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/test_subjects.ts +++ b/x-pack/plugins/cloud_security_posture/public/pages/benchmarks/test_subjects.ts @@ -10,7 +10,7 @@ export const BENCHMARKS_TABLE_DATA_TEST_SUBJ = 'csp_benchmarks_table'; export const ADD_INTEGRATION_TEST_SUBJ = 'csp_add_integration'; export const BENCHMARKS_TABLE_COLUMNS = { INTEGRATION_NAME: 'benchmarks-table-column-integration-name', - DEPLOYMENT_TYPE: 'benchmarks-table-column-deployment-type', + MONITORING: 'benchmarks-table-column-monitoring', RULES: 'benchmarks-table-column-rules', INTEGRATION: 'benchmarks-table-column-integration', AGENT_POLICY: 'benchmarks-table-column-agent-policy', diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 8a3128a906583..7bc02c0c7cdf1 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -10149,12 +10149,10 @@ "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundTitle": "Aucune intégration Benchmark trouvée", "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundWithFiltersTitle": "Nous n'avons trouvé aucune intégration Benchmark avec les filtres ci-dessus.", "xpack.csp.benchmarks.benchmarkSearchField.searchPlaceholder": "par exemple, le nom d'un benchmark", - "xpack.csp.benchmarks.benchmarksPageHeader.addKSPMIntegrationButtonLabel": "Ajouter une intégration KSPM", "xpack.csp.benchmarks.benchmarksPageHeader.benchmarkIntegrationsTitle": "Intégrations Benchmark", "xpack.csp.benchmarks.benchmarksTable.agentPolicyColumnTitle": "Politique d'agent", "xpack.csp.benchmarks.benchmarksTable.createdAtColumnTitle": "Créé à", "xpack.csp.benchmarks.benchmarksTable.createdByColumnTitle": "Créé par", - "xpack.csp.benchmarks.benchmarksTable.deploymentTypeColumnTitle": "Type de déploiement", "xpack.csp.benchmarks.benchmarksTable.integrationColumnTitle": "Intégration", "xpack.csp.benchmarks.benchmarksTable.integrationNameColumnTitle": "Nom de l'intégration", "xpack.csp.benchmarks.benchmarksTable.numberOfAgentsColumnTitle": "Nombre d'agents", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index e37f51fa4caa7..f7737d7fcf9aa 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -10138,12 +10138,10 @@ "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundTitle": "ベンチマーク統合が見つかりません", "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundWithFiltersTitle": "上記のフィルターでベンチマーク統合が見つかりませんでした。", "xpack.csp.benchmarks.benchmarkSearchField.searchPlaceholder": "例:ベンチマーク名", - "xpack.csp.benchmarks.benchmarksPageHeader.addKSPMIntegrationButtonLabel": "KSPM統合の追加", "xpack.csp.benchmarks.benchmarksPageHeader.benchmarkIntegrationsTitle": "ベンチマーク統合", "xpack.csp.benchmarks.benchmarksTable.agentPolicyColumnTitle": "エージェントポリシー", "xpack.csp.benchmarks.benchmarksTable.createdAtColumnTitle": "作成日時:", "xpack.csp.benchmarks.benchmarksTable.createdByColumnTitle": "作成者", - "xpack.csp.benchmarks.benchmarksTable.deploymentTypeColumnTitle": "デプロイタイプ", "xpack.csp.benchmarks.benchmarksTable.integrationColumnTitle": "統合", "xpack.csp.benchmarks.benchmarksTable.integrationNameColumnTitle": "統合名", "xpack.csp.benchmarks.benchmarksTable.numberOfAgentsColumnTitle": "エージェント数", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 122f825258021..2cf614e7aedea 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -10153,12 +10153,10 @@ "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundTitle": "找不到基准集成", "xpack.csp.benchmarks.benchmarkEmptyState.integrationsNotFoundWithFiltersTitle": "使用上述筛选,我们无法找到任何基准集成。", "xpack.csp.benchmarks.benchmarkSearchField.searchPlaceholder": "例如,基准名称", - "xpack.csp.benchmarks.benchmarksPageHeader.addKSPMIntegrationButtonLabel": "添加 KSPM 集成", "xpack.csp.benchmarks.benchmarksPageHeader.benchmarkIntegrationsTitle": "基准集成", "xpack.csp.benchmarks.benchmarksTable.agentPolicyColumnTitle": "代理策略", "xpack.csp.benchmarks.benchmarksTable.createdAtColumnTitle": "创建于", "xpack.csp.benchmarks.benchmarksTable.createdByColumnTitle": "创建者", - "xpack.csp.benchmarks.benchmarksTable.deploymentTypeColumnTitle": "部署类型", "xpack.csp.benchmarks.benchmarksTable.integrationColumnTitle": "集成", "xpack.csp.benchmarks.benchmarksTable.integrationNameColumnTitle": "集成名称", "xpack.csp.benchmarks.benchmarksTable.numberOfAgentsColumnTitle": "代理数目", From 32b1e9b1ab378c350dff19d95e07e2cf34cd90a0 Mon Sep 17 00:00:00 2001 From: Rodney Norris Date: Wed, 25 Jan 2023 08:21:38 -0600 Subject: [PATCH 08/11] [Enterprise Search][Engines] feat: create engine flow (#149263) ## Summary Added the create engine flyout and associated logics ### Screenshots https://user-images.githubusercontent.com/1972968/213552877-52f81594-bf0d-41bf-bf4b-ca16f922562d.mov ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --- .../engines/create_engine_api_logic.test.ts | 32 +++ .../api/engines/create_engine_api_logic.ts | 34 ++++ .../api/engines/fetch_indices_api_logic.ts | 59 ++++++ .../components/engine/engine_indices.tsx | 4 +- .../components/indices_select_combobox.tsx | 89 ++++++++ .../engines/create_engine_flyout.tsx | 191 ++++++++++++++++++ .../engines/create_engine_logic.test.ts | 127 ++++++++++++ .../components/engines/create_engine_logic.ts | 121 +++++++++++ .../engines/engine_list_logic.test.ts | 8 +- .../components/engines/engines_list.test.tsx | 4 +- .../components/engines/engines_list.tsx | 30 +-- .../components/engines/engines_list_logic.ts | 41 +++- .../shared/api_logic/create_api_logic.ts | 6 +- .../shared/constants/health_colors.ts | 12 +- .../routes/enterprise_search/engines.test.ts | 60 ++++++ .../routes/enterprise_search/engines.ts | 13 ++ 16 files changed, 796 insertions(+), 35 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.test.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/fetch_indices_api_logic.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/components/indices_select_combobox.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_flyout.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.test.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.test.ts new file mode 100644 index 0000000000000..069f225fa5de2 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.test.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { mockHttpValues } from '../../../__mocks__/kea_logic'; + +import { nextTick } from '@kbn/test-jest-helpers'; + +import { createEngine } from './create_engine_api_logic'; + +describe('CreateEngineApiLogic', () => { + const { http } = mockHttpValues; + beforeEach(() => { + jest.clearAllMocks(); + }); + describe('createEngine', () => { + it('calls correct api', async () => { + const engine = { engineName: 'my-engine', indices: ['an-index'] }; + const promise = Promise.resolve(engine); + http.post.mockReturnValue(promise); + const result = createEngine(engine); + await nextTick(); + expect(http.post).toHaveBeenCalledWith('/internal/enterprise_search/engines', { + body: '{"indices":["an-index"],"name":"my-engine"}', + }); + await expect(result).resolves.toEqual(engine); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.ts new file mode 100644 index 0000000000000..ff1ffa86d37ec --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/create_engine_api_logic.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 + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { EnterpriseSearchEngine } from '../../../../../common/types/engines'; +import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic'; +import { HttpLogic } from '../../../shared/http'; + +export interface CreateEngineApiParams { + engineName: string; + indices: string[]; +} + +export type CreateEngineApiResponse = EnterpriseSearchEngine; + +export type CreateEngineApiLogicActions = Actions; + +export const createEngine = async ({ + engineName, + indices, +}: CreateEngineApiParams): Promise => { + const route = `/internal/enterprise_search/engines`; + + return await HttpLogic.values.http.post(route, { + body: JSON.stringify({ indices, name: engineName }), + }); +}; + +export const CreateEngineApiLogic = createApiLogic(['create_engine_api_logic'], createEngine, { + showErrorFlash: false, +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/fetch_indices_api_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/fetch_indices_api_logic.ts new file mode 100644 index 0000000000000..c9764d7751f73 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/api/engines/fetch_indices_api_logic.ts @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Meta } from '../../../../../common/types'; +import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices'; + +import { Actions, createApiLogic } from '../../../shared/api_logic/create_api_logic'; +import { INPUT_THROTTLE_DELAY_MS } from '../../../shared/constants/timers'; +import { HttpLogic } from '../../../shared/http'; + +export interface EnginesFetchIndicesApiParams { + searchQuery?: string; +} + +export interface EnginesFetchIndicesApiResponse { + indices: ElasticsearchIndexWithIngestion[]; + meta: Meta; + searchQuery?: string; +} + +const INDEX_SEARCH_PAGE_SIZE = 40; + +export const fetchIndices = async ({ + searchQuery, +}: EnginesFetchIndicesApiParams): Promise => { + const { http } = HttpLogic.values; + const route = '/internal/enterprise_search/indices'; + const query = { + page: 1, + return_hidden_indices: false, + search_query: searchQuery || null, + size: INDEX_SEARCH_PAGE_SIZE, + }; + const response = await http.get<{ indices: ElasticsearchIndexWithIngestion[]; meta: Meta }>( + route, + { + query, + } + ); + + return { ...response, searchQuery }; +}; + +export const FetchIndicesForEnginesAPILogic = createApiLogic( + ['content', 'engines_fetch_indices_api_logic'], + fetchIndices, + { + requestBreakpointMS: INPUT_THROTTLE_DELAY_MS, + } +); + +export type FetchIndicesForEnginesAPILogicActions = Actions< + EnginesFetchIndicesApiParams, + EnginesFetchIndicesApiResponse +>; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_indices.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_indices.tsx index bcda0026ddd3c..00e14382afbb3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_indices.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engine/engine_indices.tsx @@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n'; import { EnterpriseSearchEngineIndex } from '../../../../../common/types/engines'; import { CANCEL_BUTTON_LABEL } from '../../../shared/constants'; -import { healthColorsMap } from '../../../shared/constants/health_colors'; +import { indexHealthToHealthColor } from '../../../shared/constants/health_colors'; import { generateEncodedPath } from '../../../shared/encode_path_params'; import { KibanaLogic } from '../../../shared/kibana'; import { EuiLinkTo } from '../../../shared/react_router_helpers'; @@ -68,7 +68,7 @@ export const EngineIndices: React.FC = () => { }), render: (health: 'red' | 'green' | 'yellow' | 'unavailable') => ( - +  {health ?? '-'} ), diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/components/indices_select_combobox.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/components/indices_select_combobox.tsx new file mode 100644 index 0000000000000..65a9879bb1e5e --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/components/indices_select_combobox.tsx @@ -0,0 +1,89 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React, { useState, useEffect } from 'react'; + +import { useValues, useActions } from 'kea'; + +import { + EuiComboBox, + EuiComboBoxProps, + EuiComboBoxOptionOption, + EuiFlexGroup, + EuiFlexItem, + EuiHealth, + EuiHighlight, +} from '@elastic/eui'; + +import { i18n } from '@kbn/i18n'; +import { FormattedNumber } from '@kbn/i18n-react'; + +import { Status } from '../../../../../../common/types/api'; +import { ElasticsearchIndexWithIngestion } from '../../../../../../common/types/indices'; + +import { indexHealthToHealthColor } from '../../../../shared/constants/health_colors'; +import { FetchIndicesForEnginesAPILogic } from '../../../api/engines/fetch_indices_api_logic'; + +export type IndicesSelectComboBoxProps = Omit< + EuiComboBoxProps, + 'onCreateOption' | 'onSearchChange' | 'noSuggestions' | 'async' +> & { + 'data-telemetry-id'?: string; +}; + +export const IndicesSelectComboBox = (props: IndicesSelectComboBoxProps) => { + const [searchQuery, setSearchQuery] = useState(undefined); + const { makeRequest } = useActions(FetchIndicesForEnginesAPILogic); + const { status, data } = useValues(FetchIndicesForEnginesAPILogic); + + useEffect(() => { + makeRequest({ searchQuery }); + }, [searchQuery]); + + const options: Array> = + data?.indices?.map(indexToOption) ?? []; + + const renderOption = (option: EuiComboBoxOptionOption) => ( + + + + {option.value?.name ?? ''} + + + + + + {i18n.translate('xpack.enterpriseSearch.content.engine.indicesSelect.docsLabel', { + defaultMessage: 'Docs:', + })} + + + + + + + + ); + + const defaultedProps: EuiComboBoxProps = { + isLoading: status === Status.LOADING, + onSearchChange: (searchValue?: string) => { + setSearchQuery(searchValue); + }, + options, + renderOption, + ...props, + }; + return ; +}; + +export const indexToOption = ( + index: ElasticsearchIndexWithIngestion +): EuiComboBoxOptionOption => ({ + label: index.name, + value: index, +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_flyout.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_flyout.tsx new file mode 100644 index 0000000000000..06a2509edad53 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_flyout.tsx @@ -0,0 +1,191 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import React from 'react'; + +import { useActions, useValues } from 'kea'; + +import { + EuiButton, + EuiButtonEmpty, + EuiFlexGroup, + EuiFlexItem, + EuiFieldText, + EuiFlyout, + EuiFlyoutHeader, + EuiFlyoutBody, + EuiFlyoutFooter, + EuiLink, + EuiSpacer, + EuiSteps, + EuiText, + EuiTitle, + EuiComboBoxOptionOption, + EuiCallOut, +} from '@elastic/eui'; + +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; + +import { Status } from '../../../../../common/types/api'; +import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices'; +import { isNotNullish } from '../../../../../common/utils/is_not_nullish'; + +import { CANCEL_BUTTON_LABEL } from '../../../shared/constants'; + +import { getErrorsFromHttpResponse } from '../../../shared/flash_messages/handle_api_errors'; + +import { indexToOption, IndicesSelectComboBox } from './components/indices_select_combobox'; + +import { CreateEngineLogic } from './create_engine_logic'; + +export interface CreateEngineFlyoutProps { + onClose: () => void; +} + +export const CreateEngineFlyout = ({ onClose }: CreateEngineFlyoutProps) => { + const { createEngine, setEngineName, setSelectedIndices } = useActions(CreateEngineLogic); + const { + createDisabled, + createEngineError, + createEngineStatus, + engineName, + engineNameStatus, + formDisabled, + indicesStatus, + selectedIndices, + } = useValues(CreateEngineLogic); + + const onIndicesChange = ( + selectedOptions: Array> + ) => { + setSelectedIndices(selectedOptions.map((option) => option.value).filter(isNotNullish)); + }; + + return ( + + + +

+ {i18n.translate('xpack.enterpriseSearch.content.engines.createEngine.headerTitle', { + defaultMessage: 'Create an engine', + })} +

+
+ + +

+ + {i18n.translate( + 'xpack.enterpriseSearch.content.engines.createEngine.header.docsLink', + { defaultMessage: 'Engines documentation' } + )} + + ), + }} + /> +

+
+ {createEngineStatus === Status.ERROR && createEngineError && ( + <> + + + {getErrorsFromHttpResponse(createEngineError).map((errMessage, i) => ( +

{errMessage}

+ ))} +
+ + )} +
+ + + ), + status: indicesStatus, + title: i18n.translate( + 'xpack.enterpriseSearch.content.engines.createEngine.selectIndices.title', + { defaultMessage: 'Select indices' } + ), + }, + { + children: ( + setEngineName(e.target.value)} + /> + ), + status: engineNameStatus, + title: i18n.translate( + 'xpack.enterpriseSearch.content.engines.createEngine.nameEngine.title', + { defaultMessage: 'Name your engine' } + ), + }, + ]} + /> + + + + + + {CANCEL_BUTTON_LABEL} + + + + + { + createEngine(); + }} + > + {i18n.translate('xpack.enterpriseSearch.content.engines.createEngine.submit', { + defaultMessage: 'Create this engine', + })} + + + + +
+ ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.test.ts new file mode 100644 index 0000000000000..2ed3239d69e38 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.test.ts @@ -0,0 +1,127 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { LogicMounter } from '../../../__mocks__/kea_logic'; + +import { Status } from '../../../../../common/types/api'; +import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices'; + +import { CreateEngineApiLogic } from '../../api/engines/create_engine_api_logic'; + +import { CreateEngineLogic, CreateEngineLogicValues } from './create_engine_logic'; + +const DEFAULT_VALUES: CreateEngineLogicValues = { + createDisabled: true, + createEngineError: undefined, + createEngineStatus: Status.IDLE, + engineName: '', + engineNameStatus: 'incomplete', + formDisabled: false, + indicesStatus: 'incomplete', + selectedIndices: [], +}; + +const VALID_ENGINE_NAME = 'unit-test-001'; +const INVALID_ENGINE_NAME = 'TEST'; +const VALID_INDICES_DATA = [{ name: 'search-index-01' }] as ElasticsearchIndexWithIngestion[]; + +describe('CreateEngineLogic', () => { + const { mount: apiLogicMount } = new LogicMounter(CreateEngineApiLogic); + const { mount } = new LogicMounter(CreateEngineLogic); + + beforeEach(() => { + jest.clearAllMocks(); + jest.useRealTimers(); + apiLogicMount(); + mount(); + }); + + it('has expected defaults', () => { + expect(CreateEngineLogic.values).toEqual(DEFAULT_VALUES); + }); + + describe('listeners', () => { + it('createEngine makes expected request action', () => { + jest.spyOn(CreateEngineLogic.actions, 'createEngineRequest'); + + CreateEngineLogic.actions.setEngineName(VALID_ENGINE_NAME); + CreateEngineLogic.actions.setSelectedIndices(VALID_INDICES_DATA); + + CreateEngineLogic.actions.createEngine(); + + expect(CreateEngineLogic.actions.createEngineRequest).toHaveBeenCalledTimes(1); + expect(CreateEngineLogic.actions.createEngineRequest).toHaveBeenCalledWith({ + engineName: VALID_ENGINE_NAME, + indices: ['search-index-01'], + }); + }); + it('engineCreated is handled', () => { + jest.spyOn(CreateEngineLogic.actions, 'fetchEngines'); + jest.spyOn(CreateEngineLogic.actions, 'closeEngineCreate'); + + CreateEngineApiLogic.actions.apiSuccess({ + created: '', + indices: ['search-index-001'], + name: 'unit-test', + updated: '', + }); + + expect(CreateEngineLogic.actions.fetchEngines).toHaveBeenCalledTimes(1); + expect(CreateEngineLogic.actions.closeEngineCreate).toHaveBeenCalledTimes(1); + }); + }); + describe('selectors', () => { + describe('engineNameStatus', () => { + it('returns incomplete with empty engine name', () => { + expect(CreateEngineLogic.values.engineNameStatus).toEqual('incomplete'); + }); + it('returns complete with valid engine name', () => { + CreateEngineLogic.actions.setEngineName(VALID_ENGINE_NAME); + + expect(CreateEngineLogic.values.engineNameStatus).toEqual('complete'); + }); + it('returns warning for invalid engine name', () => { + CreateEngineLogic.actions.setEngineName(INVALID_ENGINE_NAME); + + expect(CreateEngineLogic.values.engineNameStatus).toEqual('warning'); + }); + }); + describe('indicesStatus', () => { + it('returns incomplete with 0 indices', () => { + expect(CreateEngineLogic.values.indicesStatus).toEqual('incomplete'); + }); + it('returns complete with at least one index', () => { + CreateEngineLogic.actions.setSelectedIndices(VALID_INDICES_DATA); + expect(CreateEngineLogic.values.indicesStatus).toEqual('complete'); + }); + }); + describe('createDisabled', () => { + it('false with valid data', () => { + CreateEngineLogic.actions.setSelectedIndices(VALID_INDICES_DATA); + CreateEngineLogic.actions.setEngineName(VALID_ENGINE_NAME); + + expect(CreateEngineLogic.values.createDisabled).toEqual(false); + }); + it('true with invalid data', () => { + CreateEngineLogic.actions.setSelectedIndices(VALID_INDICES_DATA); + CreateEngineLogic.actions.setEngineName(INVALID_ENGINE_NAME); + + expect(CreateEngineLogic.values.createDisabled).toEqual(true); + }); + }); + describe('formDisabled', () => { + it('returns true while create request in progress', () => { + CreateEngineApiLogic.actions.makeRequest({ + engineName: VALID_ENGINE_NAME, + indices: [VALID_INDICES_DATA[0].name], + }); + + expect(CreateEngineLogic.values.formDisabled).toEqual(true); + }); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.ts new file mode 100644 index 0000000000000..266dab05c5441 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/create_engine_logic.ts @@ -0,0 +1,121 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { kea, MakeLogicType } from 'kea'; + +import { Status } from '../../../../../common/types/api'; +import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices'; + +import { + CreateEngineApiLogic, + CreateEngineApiLogicActions, +} from '../../api/engines/create_engine_api_logic'; + +import { EnginesListLogic } from './engines_list_logic'; + +const NAME_VALIDATION = new RegExp(/^[a-z0-9\-]+$/); + +export interface CreateEngineLogicActions { + closeEngineCreate: () => void; + createEngine: () => void; + createEngineRequest: CreateEngineApiLogicActions['makeRequest']; + engineCreateError: CreateEngineApiLogicActions['apiError']; + engineCreated: CreateEngineApiLogicActions['apiSuccess']; + fetchEngines: () => void; + setEngineName: (engineName: string) => { engineName: string }; + setSelectedIndices: (indices: ElasticsearchIndexWithIngestion[]) => { + indices: ElasticsearchIndexWithIngestion[]; + }; +} + +export interface CreateEngineLogicValues { + createDisabled: boolean; + createEngineError?: typeof CreateEngineApiLogic.values.error; + createEngineStatus: typeof CreateEngineApiLogic.values.status; + engineName: string; + engineNameStatus: 'complete' | 'incomplete' | 'warning'; + formDisabled: boolean; + indicesStatus: 'complete' | 'incomplete'; + selectedIndices: ElasticsearchIndexWithIngestion[]; +} + +export const CreateEngineLogic = kea< + MakeLogicType +>({ + actions: { + createEngine: true, + setEngineName: (engineName: string) => ({ engineName }), + setSelectedIndices: (indices: ElasticsearchIndexWithIngestion[]) => ({ indices }), + }, + connect: { + actions: [ + EnginesListLogic, + ['closeEngineCreate', 'fetchEngines'], + CreateEngineApiLogic, + [ + 'makeRequest as createEngineRequest', + 'apiSuccess as engineCreated', + 'apiError as engineCreateError', + ], + ], + values: [CreateEngineApiLogic, ['status as createEngineStatus', 'error as createEngineError']], + }, + listeners: ({ actions, values }) => ({ + createEngine: () => { + actions.createEngineRequest({ + engineName: values.engineName, + indices: values.selectedIndices.map((index) => index.name), + }); + }, + engineCreated: () => { + actions.fetchEngines(); + actions.closeEngineCreate(); + }, + }), + path: ['enterprise_search', 'content', 'create_engine_logic'], + reducers: { + engineName: [ + '', + { + setEngineName: (_, { engineName }) => engineName, + }, + ], + selectedIndices: [ + [], + { + setSelectedIndices: (_, { indices }) => indices, + }, + ], + }, + selectors: ({ selectors }) => ({ + createDisabled: [ + () => [selectors.indicesStatus, selectors.engineNameStatus], + ( + indicesStatus: CreateEngineLogicValues['indicesStatus'], + engineNameStatus: CreateEngineLogicValues['engineNameStatus'] + ) => indicesStatus !== 'complete' || engineNameStatus !== 'complete', + ], + engineNameStatus: [ + () => [selectors.engineName], + (engineName: string) => { + if (engineName.length === 0) return 'incomplete'; + if (NAME_VALIDATION.test(engineName)) return 'complete'; + return 'warning'; + }, + ], + formDisabled: [ + () => [selectors.createEngineStatus], + (createEngineStatus: CreateEngineLogicValues['createEngineStatus']) => + createEngineStatus === Status.LOADING, + ], + indicesStatus: [ + () => [selectors.selectedIndices], + (selectedIndices: CreateEngineLogicValues['selectedIndices']) => + selectedIndices.length > 0 ? 'complete' : 'incomplete', + ], + }), +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engine_list_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engine_list_logic.test.ts index bfbbb71d220c6..9a512c07b9cb4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engine_list_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engine_list_logic.test.ts @@ -18,6 +18,7 @@ import { EnginesListLogic } from './engines_list_logic'; import { DEFAULT_META } from './types'; const DEFAULT_VALUES = { + createEngineFlyoutOpen: false, data: undefined, deleteModalEngine: null, deleteModalEngineName: '', @@ -28,6 +29,7 @@ const DEFAULT_VALUES = { meta: DEFAULT_META, parameters: { meta: DEFAULT_META }, results: [], + searchQuery: '', status: Status.IDLE, }; @@ -196,15 +198,13 @@ describe('EnginesListLogic', () => { EnginesListLogic.actions.deleteSuccess({ engineName: results[0].name }); expect(mockFlashMessageHelpers.flashSuccessToast).toHaveBeenCalledTimes(1); - expect(EnginesListLogic.actions.fetchEngines).toHaveBeenCalledWith( - EnginesListLogic.values.parameters - ); + expect(EnginesListLogic.actions.fetchEngines).toHaveBeenCalledWith(); expect(EnginesListLogic.actions.closeDeleteEngineModal).toHaveBeenCalled(); }); it('call makeRequest on fetchEngines', async () => { jest.useFakeTimers({ legacyFakeTimers: true }); EnginesListLogic.actions.makeRequest = jest.fn(); - EnginesListLogic.actions.fetchEngines({ meta: DEFAULT_META }); + EnginesListLogic.actions.fetchEngines(); await nextTick(); expect(EnginesListLogic.actions.makeRequest).toHaveBeenCalledWith({ meta: DEFAULT_META, diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.test.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.test.tsx index 3de8546bcf5f7..4d5840a062cfd 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.test.tsx @@ -13,7 +13,7 @@ import { shallow } from 'enzyme'; import { Status } from '../../../../../common/types/api'; -import { EnterpriseSearchContentPageTemplate } from '../layout/page_template'; +import { EnterpriseSearchEnginesPageTemplate } from '../layout/engines_page_template'; import { EmptyEnginesPrompt } from './components/empty_engines_prompt'; import { EnginesListTable } from './components/tables/engines_table'; @@ -57,7 +57,7 @@ describe('EnginesList', () => { setMockActions(mockActions); const wrapper = shallow(); - const pageTemplate = wrapper.find(EnterpriseSearchContentPageTemplate); + const pageTemplate = wrapper.find(EnterpriseSearchEnginesPageTemplate); expect(pageTemplate.prop('isLoading')).toEqual(true); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.tsx index db125c425c501..e9bded754116c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import React, { useEffect, useState } from 'react'; +import React, { useEffect } from 'react'; import { useActions, useValues } from 'kea'; import useThrottle from 'react-use/lib/useThrottle'; @@ -18,21 +18,23 @@ import { FormattedMessage, FormattedNumber } from '@kbn/i18n-react'; import { INPUT_THROTTLE_DELAY_MS } from '../../../shared/constants/timers'; import { DataPanel } from '../../../shared/data_panel/data_panel'; -import { EnterpriseSearchContentPageTemplate } from '../layout/page_template'; +import { EnterpriseSearchEnginesPageTemplate } from '../layout/engines_page_template'; import { EmptyEnginesPrompt } from './components/empty_engines_prompt'; import { EnginesListTable } from './components/tables/engines_table'; +import { CreateEngineFlyout } from './create_engine_flyout'; import { DeleteEngineModal } from './delete_engine_modal'; import { EnginesListLogic } from './engines_list_logic'; const CreateButton: React.FC = () => { + const { openEngineCreate } = useActions(EnginesListLogic); return ( {i18n.translate('xpack.enterpriseSearch.content.engines.createEngineButtonLabel', { defaultMessage: 'Create engine', @@ -42,22 +44,22 @@ const CreateButton: React.FC = () => { }; export const EnginesList: React.FC = () => { - const { fetchEngines, onPaginate, openDeleteEngineModal } = useActions(EnginesListLogic); - const { meta, results, isLoading } = useValues(EnginesListLogic); - const [searchQuery, setSearchValue] = useState(''); + const { closeEngineCreate, fetchEngines, onPaginate, openDeleteEngineModal, setSearchQuery } = + useActions(EnginesListLogic); + const { isLoading, meta, results, createEngineFlyoutOpen, searchQuery } = + useValues(EnginesListLogic); + const throttledSearchQuery = useThrottle(searchQuery, INPUT_THROTTLE_DELAY_MS); useEffect(() => { - fetchEngines({ - meta, - searchQuery: throttledSearchQuery, - }); + fetchEngines(); }, [meta.from, meta.size, throttledSearchQuery]); return ( <> - } + { pageTitle: i18n.translate('xpack.enterpriseSearch.content.engines.title', { defaultMessage: 'Engines', }), - rightSideItems: [], + rightSideItems: results.length ? [] : [], }} pageViewTelemetry="Engines" isLoading={isLoading} @@ -114,7 +116,7 @@ export const EnginesList: React.FC = () => { )} fullWidth onChange={(event) => { - setSearchValue(event.currentTarget.value); + setSearchQuery(event.currentTarget.value); }} />
@@ -174,7 +176,7 @@ export const EnginesList: React.FC = () => {
- + ); }; diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list_logic.ts index 6428217e12b5b..81cf12da12c34 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/engines/engines_list_logic.ts @@ -37,19 +37,20 @@ type EnginesListActions = Pick< 'apiError' | 'apiSuccess' | 'makeRequest' > & { closeDeleteEngineModal(): void; + closeEngineCreate(): void; deleteEngine: DeleteEnginesApiLogicActions['makeRequest']; deleteError: DeleteEnginesApiLogicActions['apiError']; deleteSuccess: DeleteEnginesApiLogicActions['apiSuccess']; - fetchEngines({ meta, searchQuery }: { meta: Meta; searchQuery?: string }): { - meta: Meta; - searchQuery?: string; - }; + fetchEngines(): void; onPaginate(args: EuiBasicTableOnChange): { pageNumber: number }; openDeleteEngineModal: (engine: EnterpriseSearchEngine) => { engine: EnterpriseSearchEngine }; + openEngineCreate(): void; + setSearchQuery(searchQuery: string): { searchQuery: string }; }; interface EngineListValues { + createEngineFlyoutOpen: boolean; data: typeof FetchEnginesAPILogic.values.data; deleteModalEngine: EnterpriseSearchEngine | null; deleteModalEngineName: string; @@ -60,6 +61,7 @@ interface EngineListValues { meta: Meta; parameters: { meta: Meta; searchQuery?: string }; // Added this variable to store to the search Query value as well results: EnterpriseSearchEngine[]; // stores engine list value from data + searchQuery: string; status: typeof FetchEnginesAPILogic.values.status; } @@ -80,15 +82,22 @@ export const EnginesListLogic = kea ({ - meta, - searchQuery, - }), + closeEngineCreate: true, + fetchEngines: true, onPaginate: (args: EuiBasicTableOnChange) => ({ pageNumber: args.page.index }), openDeleteEngineModal: (engine) => ({ engine }), + openEngineCreate: true, + setSearchQuery: (searchQuery: string) => ({ searchQuery }), }, path: ['enterprise_search', 'content', 'engine_list_logic'], reducers: ({}) => ({ + createEngineFlyoutOpen: [ + false, + { + closeEngineCreate: () => false, + openEngineCreate: () => true, + }, + ], deleteModalEngine: [ null, { @@ -113,6 +122,16 @@ export const EnginesListLogic = kea ({ + ...state, + searchQuery: searchQuery ? searchQuery : undefined, + }), + }, + ], + searchQuery: [ + '', + { + setSearchQuery: (_, { searchQuery }) => searchQuery, }, ], }), @@ -132,10 +151,10 @@ export const EnginesListLogic = kea ({ deleteSuccess: () => { actions.closeDeleteEngineModal(); - actions.fetchEngines(values.parameters); + actions.fetchEngines(); }, - fetchEngines: async (input) => { - actions.makeRequest(input); + fetchEngines: async () => { + actions.makeRequest(values.parameters); }, }), }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/api_logic/create_api_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/api_logic/create_api_logic.ts index f8a3eb7a823d8..38ffd8ff8a438 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/api_logic/create_api_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/api_logic/create_api_logic.ts @@ -26,6 +26,7 @@ export interface Actions { export interface CreateApiOptions { clearFlashMessagesOnMakeRequest: boolean; + requestBreakpointMS?: number; showErrorFlash: boolean; showSuccessFlashFn?: (result: Result) => string; } @@ -60,10 +61,13 @@ export const createApiLogic = ( flashSuccessToast(options.showSuccessFlashFn(result)); } }, - makeRequest: async (args) => { + makeRequest: async (args, breakpoint) => { if (options.clearFlashMessagesOnMakeRequest) { clearFlashMessages(); } + if (options.requestBreakpointMS) { + await breakpoint(options.requestBreakpointMS); + } try { const result = await apiFunction(args); actions.apiSuccess(result); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/constants/health_colors.ts b/x-pack/plugins/enterprise_search/public/applications/shared/constants/health_colors.ts index 9c87507ae6994..66c114f6899e1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/constants/health_colors.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/constants/health_colors.ts @@ -5,7 +5,12 @@ * 2.0. */ -export const healthColorsMap = { +import { HealthStatus } from '@elastic/elasticsearch/lib/api/types'; + +import { IconColor } from '@elastic/eui'; + +type HealthStatusStrings = 'red' | 'green' | 'yellow' | 'unavailable'; +export const healthColorsMap: Record = { red: 'danger', green: 'success', yellow: 'warning', @@ -20,3 +25,8 @@ export const healthColorsMapSelectable = { yellow: 'warning', YELLOW: 'warning', }; + +export const indexHealthToHealthColor = (health?: HealthStatus | 'unavailable'): IconColor => { + if (!health) return ''; + return healthColorsMap[health.toLowerCase() as HealthStatusStrings] ?? ''; +}; diff --git a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.test.ts b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.test.ts index c037d2a07e8c7..e966e3eb2cb1f 100644 --- a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.test.ts @@ -51,6 +51,66 @@ describe('engines routes', () => { }); }); + describe('POST /internal/enterprise_search/engines', () => { + let mockRouter: MockRouter; + + beforeEach(() => { + jest.clearAllMocks(); + mockRouter = new MockRouter({ + method: 'post', + path: '/internal/enterprise_search/engines', + }); + + registerEnginesRoutes({ + ...mockDependencies, + router: mockRouter.router, + }); + }); + + it('creates a request to enterprise search', () => { + expect(mockRequestHandler.createRequest).toHaveBeenCalledWith({ + path: '/api/engines', + }); + }); + + it('validates correctly with engine_name', () => { + const request = { + body: { + indices: ['search-unit-test'], + name: 'some-engine', + }, + }; + + mockRouter.shouldValidate(request); + }); + + it('fails validation without body', () => { + const request = { params: {} }; + + mockRouter.shouldThrow(request); + }); + + it('fails validation without name', () => { + const request = { + body: { + indices: ['search-unit-test'], + }, + }; + + mockRouter.shouldThrow(request); + }); + + it('fails validation without indices', () => { + const request = { + body: { + name: 'some-engine', + }, + }; + + mockRouter.shouldThrow(request); + }); + }); + describe('GET /internal/enterprise_search/engines/{engine_name}', () => { let mockRouter: MockRouter; diff --git a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.ts b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.ts index 11cdd16b2f79b..ade72d09c2148 100644 --- a/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.ts +++ b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/engines.ts @@ -26,6 +26,19 @@ export function registerEnginesRoutes({ enterpriseSearchRequestHandler.createRequest({ path: '/api/engines' }) ); + router.post( + { + path: '/internal/enterprise_search/engines', + validate: { + body: schema.object({ + indices: schema.arrayOf(schema.string()), + name: schema.string(), + }), + }, + }, + enterpriseSearchRequestHandler.createRequest({ path: '/api/engines' }) + ); + router.get( { path: '/internal/enterprise_search/engines/{engine_name}', From e2824c3041e3f455a3c6cdf2cf0b1224162af48c Mon Sep 17 00:00:00 2001 From: Jiawei Wu <74562234+JiaweiWu@users.noreply.github.com> Date: Wed, 25 Jan 2023 06:23:02 -0800 Subject: [PATCH 09/11] [RAM] Reduce triggers actions UI bundle size (#149473) ## Summary Reduces the bundle size of `triggersActionsUI`. Fix a change in a recent PR that added util functions to an index file that was in turn being imported when it wasn't needed. Gets it down to `118085`. ![image](https://user-images.githubusercontent.com/74562234/214467217-7e778b38-51e9-482a-8ce2-5774f9d96425.png) --- .../application/lib/action_connector_api/index.ts | 4 ---- .../actions_connectors_event_log_list_table.tsx | 2 +- .../components/with_actions_api_operations.tsx | 12 +++++++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/action_connector_api/index.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/action_connector_api/index.ts index 01b4ca62845fa..7cc4f1df6a735 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/action_connector_api/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/action_connector_api/index.ts @@ -11,7 +11,3 @@ export { createActionConnector } from './create'; export { deleteActions } from './delete'; export { executeAction } from './execute'; export { updateActionConnector } from './update'; -export type { LoadGlobalConnectorExecutionLogAggregationsProps } from './load_execution_log_aggregations'; -export { loadGlobalConnectorExecutionLogAggregations } from './load_execution_log_aggregations'; -export type { LoadGlobalConnectorExecutionKPIAggregationsProps } from './load_execution_kpi_aggregations'; -export { loadGlobalConnectorExecutionKPIAggregations } from './load_execution_kpi_aggregations'; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_event_log_list_table.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_event_log_list_table.tsx index 53b7d99483049..a2a674ecd73ee 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_event_log_list_table.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/actions_connectors_list/components/actions_connectors_event_log_list_table.tsx @@ -29,7 +29,7 @@ import { CONNECTOR_LOCKED_COLUMNS, } from '../../../constants'; import { CenterJustifiedSpinner } from '../../../components/center_justified_spinner'; -import { LoadGlobalConnectorExecutionLogAggregationsProps } from '../../../lib/action_connector_api'; +import { LoadGlobalConnectorExecutionLogAggregationsProps } from '../../../lib/action_connector_api/load_execution_log_aggregations'; import { ComponentOpts as ConnectorApis, withActionOperations, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_actions_api_operations.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_actions_api_operations.tsx index ebb36c1d4f385..7b2233ded244c 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_actions_api_operations.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_actions_api_operations.tsx @@ -9,13 +9,15 @@ import React from 'react'; import { IExecutionLogResult, IExecutionKPIResult } from '@kbn/actions-plugin/common'; import { ActionType } from '../../../../types'; +import { loadActionTypes } from '../../../lib/action_connector_api'; import { - loadActionTypes, - LoadGlobalConnectorExecutionLogAggregationsProps, - loadGlobalConnectorExecutionLogAggregations, - LoadGlobalConnectorExecutionKPIAggregationsProps, loadGlobalConnectorExecutionKPIAggregations, -} from '../../../lib/action_connector_api'; + LoadGlobalConnectorExecutionKPIAggregationsProps, +} from '../../../lib/action_connector_api/load_execution_kpi_aggregations'; +import { + loadGlobalConnectorExecutionLogAggregations, + LoadGlobalConnectorExecutionLogAggregationsProps, +} from '../../../lib/action_connector_api/load_execution_log_aggregations'; import { useKibana } from '../../../../common/lib/kibana'; export interface ComponentOpts { From 179b36f93feea37470998a04d50f2260b11d8c6d Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:32:12 +0100 Subject: [PATCH 10/11] [Fleet] experimental toggles for doc-value-only (#149131) ## Summary Closes https://github.com/elastic/kibana/issues/144357 WIP. Review can be started, but still requires a lot of testing and fixing the issue below. How to test locally: - Turn on `experimentalDataStreamSettings` feature flag - Go to Add integration, System integration - On the first data stream, turn on the Doc value only switches, Save - The mapping changes are visible under Stack Management / Index Management / Component Templates e.g. `logs-system.auth@package` - The numeric switch sets `index:false` on all numeric field mappings (long, double, etc.) - The other switch sets `index:false` on all other field type mappings that support it (keyword, ip, date, etc.) - The new mappings will take effect after rollover image image What works: - When turning the new doc-value-only numeric and other checkboxes on or off, the corresponding mapping changes are done in the component template - The logic also reads the package spec's template and preserves the `index:false` values regardless of the switch (tested manually by setting `@timestamp` field to `index:false` in the template, there is also the `original` field in `logs-system.auth@package` stream that is set to `index:false` in the package by default. ``` "original": { "index": false, "doc_values": false, "type": "keyword" }, ``` Pending: - Add/update unit and integration tests to verify the mapping change logic - DONE - Manual testing (turning the switches on/off, create/update package policy, upgrade package) - DONE - Clarify TODOs in the code about the supported types - DONE - Hitting an issue when turning on `doc-value-only` for "other" types (keyword, date, etc.). Could be that one of the fields doesn't support `index:false` setting. Didn't experience this when turning on only the numeric types. - FIXED ``` illegal_argument_exception: [illegal_argument_exception] Reason: updating component template [logs-system.auth@package] results in invalid composable template [logs-system.auth] after templates are merged ``` EDIT: found the root cause of this: `Caused by: java.lang.IllegalArgumentException: data stream timestamp field [@timestamp] is not indexed` ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../migrations/check_registered_types.test.ts | 2 +- .../simplified_package_policy_helper.test.ts | 4 + .../plugins/fleet/common/types/models/epm.ts | 6 +- .../experimental_datastream_settings.test.tsx | 8 + .../experimental_datastream_settings.tsx | 54 ++++ .../fleet/server/saved_objects/index.ts | 1 + .../elasticsearch/template/install.test.ts | 4 + .../epm/elasticsearch/template/install.ts | 27 +- ...experimental_datastream_features_helper.ts | 70 +++++ .../experimental_datastream_features.test.ts | 282 ++++++++++++++++-- .../experimental_datastream_features.ts | 96 +++++- .../server/types/models/package_policy.ts | 11 +- 12 files changed, 510 insertions(+), 55 deletions(-) create mode 100644 x-pack/plugins/fleet/server/services/experimental_datastream_features_helper.ts diff --git a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts index 5f148325d6f5a..54a61456ac769 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/check_registered_types.test.ts @@ -84,7 +84,7 @@ describe('checking migration metadata changes on all registered SO types', () => "endpoint:user-artifact": "f94c250a52b30d0a2d32635f8b4c5bdabd1e25c0", "endpoint:user-artifact-manifest": "8c14d49a385d5d1307d956aa743ec78de0b2be88", "enterprise_search_telemetry": "fafcc8318528d34f721c42d1270787c52565bad5", - "epm-packages": "7d80ba3f1fcd80316aa0b112657272034b66d5a8", + "epm-packages": "21e096cf4554abe1652953a6cd2119d68ddc9403", "epm-packages-assets": "9fd3d6726ac77369249e9a973902c2cd615fc771", "event_loop_delays_daily": "d2ed39cf669577d90921c176499908b4943fb7bd", "exception-list": "fe8cc004fd2742177cdb9300f4a67689463faf9c", diff --git a/x-pack/plugins/fleet/common/services/simplified_package_policy_helper.test.ts b/x-pack/plugins/fleet/common/services/simplified_package_policy_helper.test.ts index e60da12d924cc..6a8104f38a991 100644 --- a/x-pack/plugins/fleet/common/services/simplified_package_policy_helper.test.ts +++ b/x-pack/plugins/fleet/common/services/simplified_package_policy_helper.test.ts @@ -132,6 +132,8 @@ describe('toPackagePolicy', () => { features: { synthetic_source: true, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ], @@ -144,6 +146,8 @@ describe('toPackagePolicy', () => { features: { synthetic_source: true, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ]); diff --git a/x-pack/plugins/fleet/common/types/models/epm.ts b/x-pack/plugins/fleet/common/types/models/epm.ts index 6c9a61cf17ce1..db3497d20c349 100644 --- a/x-pack/plugins/fleet/common/types/models/epm.ts +++ b/x-pack/plugins/fleet/common/types/models/epm.ts @@ -460,7 +460,11 @@ export type PackageInfo = | Installable>; // TODO - Expand this with other experimental indexing types -export type ExperimentalIndexingFeature = 'synthetic_source' | 'tsdb'; +export type ExperimentalIndexingFeature = + | 'synthetic_source' + | 'tsdb' + | 'doc_value_only_numeric' + | 'doc_value_only_other'; export interface ExperimentalDataStreamFeature { data_stream: string; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.test.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.test.tsx index 1bd0e7bb39919..8b857676301eb 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.test.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.test.tsx @@ -92,6 +92,8 @@ describe('ExperimentDatastreamSettings', () => { features: { synthetic_source: false, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ]} @@ -141,6 +143,8 @@ describe('ExperimentDatastreamSettings', () => { features: { synthetic_source: true, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ]; @@ -169,6 +173,8 @@ describe('ExperimentDatastreamSettings', () => { features: { synthetic_source: false, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ]); @@ -178,6 +184,8 @@ describe('ExperimentDatastreamSettings', () => { features: { synthetic_source: true, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, ]); diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.tsx index 28ce97d17fe97..190541be0e1f5 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/components/steps/components/experimental_datastream_settings.tsx @@ -64,6 +64,18 @@ export const ExperimentDatastreamSettings: React.FunctionComponent = ({ const isSyntheticSourceEnabledByDefault = registryDataStream.elasticsearch?.source_mode === 'synthetic' || isTimeSeriesEnabledByDefault; + const docValueOnlyNumericExperimentalValue = getExperimentalFeatureValue( + 'doc_value_only_numeric', + experimentalDataFeatures ?? [], + registryDataStream + ); + + const docValueOnlyOtherExperimentalValue = getExperimentalFeatureValue( + 'doc_value_only_other', + experimentalDataFeatures ?? [], + registryDataStream + ); + const newExperimentalIndexingFeature = { synthetic_source: typeof syntheticSourceExperimentalValue !== 'undefined' @@ -73,6 +85,14 @@ export const ExperimentDatastreamSettings: React.FunctionComponent = ({ ? isTimeSeriesEnabledByDefault : getExperimentalFeatureValue('tsdb', experimentalDataFeatures ?? [], registryDataStream) ?? false, + doc_value_only_numeric: + typeof docValueOnlyNumericExperimentalValue !== 'undefined' + ? docValueOnlyNumericExperimentalValue + : false, + doc_value_only_other: + typeof docValueOnlyOtherExperimentalValue !== 'undefined' + ? docValueOnlyOtherExperimentalValue + : false, }; const onIndexingSettingChange = ( @@ -178,6 +198,40 @@ export const ExperimentDatastreamSettings: React.FunctionComponent = ({ /> + + + } + onChange={(e) => { + onIndexingSettingChange({ + doc_value_only_numeric: e.target.checked, + }); + }} + /> + + + + } + onChange={(e) => { + onIndexingSettingChange({ + doc_value_only_other: e.target.checked, + }); + }} + /> + ); diff --git a/x-pack/plugins/fleet/server/saved_objects/index.ts b/x-pack/plugins/fleet/server/saved_objects/index.ts index e45b0825306fa..f13a37ed402b2 100644 --- a/x-pack/plugins/fleet/server/saved_objects/index.ts +++ b/x-pack/plugins/fleet/server/saved_objects/index.ts @@ -289,6 +289,7 @@ const getSavedObjectTypes = ( data_stream: { type: 'keyword' }, features: { type: 'nested', + dynamic: false, properties: { synthetic_source: { type: 'boolean' }, tsdb: { type: 'boolean' }, diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.test.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.test.ts index 8ba41a5556f46..27b7b49ec1d44 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.test.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.test.ts @@ -201,6 +201,8 @@ describe('EPM index template install', () => { features: { synthetic_source: false, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, }); @@ -241,6 +243,8 @@ describe('EPM index template install', () => { features: { synthetic_source: false, tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, }, }); diff --git a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts index 993f26c3a38e0..f122b04381920 100644 --- a/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts +++ b/x-pack/plugins/fleet/server/services/epm/elasticsearch/template/install.ts @@ -49,6 +49,11 @@ import { import { getESAssetMetadata } from '../meta'; import { retryTransientEsErrors } from '../retry'; +import { + applyDocOnlyValueToMapping, + forEachMappings, +} from '../../../experimental_datastream_features_helper'; + import { generateMappings, generateTemplateName, @@ -262,6 +267,7 @@ export function buildComponentTemplates(params: { defaultSettings, mappings, pipelineName, + experimentalDataStreamFeature, } = params; const packageTemplateName = `${templateName}${PACKAGE_TEMPLATE_SUFFIX}`; const userSettingsTemplateName = `${templateName}${USER_SETTINGS_TEMPLATE_SUFFIX}`; @@ -275,6 +281,23 @@ export function buildComponentTemplates(params: { const indexTemplateMappings = registryElasticsearch?.['index_template.mappings'] ?? {}; + const isDocValueOnlyNumericEnabled = + experimentalDataStreamFeature?.features.doc_value_only_numeric === true; + const isDocValueOnlyOtherEnabled = + experimentalDataStreamFeature?.features.doc_value_only_other === true; + + if (isDocValueOnlyNumericEnabled || isDocValueOnlyOtherEnabled) { + forEachMappings(mappings.properties, (mappingProp, name) => + applyDocOnlyValueToMapping( + mappingProp, + name, + experimentalDataStreamFeature, + isDocValueOnlyNumericEnabled, + isDocValueOnlyOtherEnabled + ) + ); + } + const mappingsProperties = merge(mappings.properties, indexTemplateMappings.properties ?? {}); const mappingsDynamicTemplates = uniqBy( @@ -286,8 +309,8 @@ export function buildComponentTemplates(params: { const isSyntheticSourceEnabledByDefault = registryElasticsearch?.source_mode === 'synthetic'; const sourceModeSynthetic = - params.experimentalDataStreamFeature?.features.synthetic_source !== false && - (params.experimentalDataStreamFeature?.features.synthetic_source === true || + experimentalDataStreamFeature?.features.synthetic_source !== false && + (experimentalDataStreamFeature?.features.synthetic_source === true || isSyntheticSourceEnabledByDefault || isTimeSeriesEnabledByDefault); diff --git a/x-pack/plugins/fleet/server/services/experimental_datastream_features_helper.ts b/x-pack/plugins/fleet/server/services/experimental_datastream_features_helper.ts new file mode 100644 index 0000000000000..029215e282383 --- /dev/null +++ b/x-pack/plugins/fleet/server/services/experimental_datastream_features_helper.ts @@ -0,0 +1,70 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import type { + MappingProperty, + PropertyName, +} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; + +import type { ExperimentalDataStreamFeature } from '../../common/types'; + +export const forEachMappings = ( + mappingProperties: Record, + process: (prop: MappingProperty, name: string) => void +) => { + Object.keys(mappingProperties).forEach((mapping) => { + const property = mappingProperties[mapping] as any; + if (property.properties) { + forEachMappings(property.properties, process); + } else { + process(property, mapping); + } + }); +}; + +export const applyDocOnlyValueToMapping = ( + mappingProp: MappingProperty, + name: string, + featureMap: ExperimentalDataStreamFeature, + isDocValueOnlyNumericChanged: boolean, + isDocValueOnlyOtherChanged: boolean +) => { + const mapping = mappingProp as any; + + const numericTypes = [ + 'long', + 'integer', + 'short', + 'byte', + 'double', + 'float', + 'half_float', + 'scaled_float', + 'unsigned_long', + ]; + if (isDocValueOnlyNumericChanged && numericTypes.includes(mapping.type ?? '')) { + updateMapping(mapping, featureMap.features.doc_value_only_numeric); + } + + const otherSupportedTypes = ['date', 'date_nanos', 'boolean', 'ip', 'geo_point', 'keyword']; + if ( + isDocValueOnlyOtherChanged && + name !== '@timestamp' && + otherSupportedTypes.includes(mapping.type ?? '') + ) { + updateMapping(mapping, featureMap.features.doc_value_only_other); + } +}; + +const updateMapping = (mapping: { index?: boolean }, featureValue: boolean) => { + if (featureValue === false && mapping.index === false) { + delete mapping.index; + } + if (featureValue && !mapping.index) { + mapping.index = false; + } +}; diff --git a/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.test.ts b/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.test.ts index 4e6db957633ef..db37f85f56701 100644 --- a/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.test.ts +++ b/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.test.ts @@ -9,15 +9,60 @@ import { elasticsearchServiceMock } from '@kbn/core-elasticsearch-server-mocks'; import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; import type { NewPackagePolicy, PackagePolicy } from '../../types'; +import { getInstallation } from '../epm/packages'; import { handleExperimentalDatastreamFeatureOptIn } from './experimental_datastream_features'; +jest.mock('../epm/packages', () => { + return { + getInstallation: jest.fn(), + getPackageInfo: jest.fn().mockResolvedValue({ + data_streams: [ + { + dataset: 'test', + type: 'metrics', + }, + ], + }), + }; +}); + +const mockGetInstallation = getInstallation as jest.Mock; + +jest.mock('../epm/elasticsearch/template/install', () => { + return { + prepareTemplate: jest.fn().mockReturnValue({ + componentTemplates: { + 'metrics-test.test@package': { + template: { + mappings: { + properties: { + sequence: { + type: 'long', + }, + name: { + type: 'keyword', + index: false, + }, + }, + }, + }, + }, + }, + }), + }; +}); + function getNewTestPackagePolicy({ isSyntheticSourceEnabled, isTSDBEnabled, + isDocValueOnlyNumeric, + isDocValueOnlyOther, }: { isSyntheticSourceEnabled: boolean; isTSDBEnabled: boolean; + isDocValueOnlyNumeric: boolean; + isDocValueOnlyOther: boolean; }): NewPackagePolicy { const packagePolicy: NewPackagePolicy = { name: 'Test policy', @@ -36,6 +81,8 @@ function getNewTestPackagePolicy({ features: { synthetic_source: isSyntheticSourceEnabled, tsdb: isTSDBEnabled, + doc_value_only_numeric: isDocValueOnlyNumeric, + doc_value_only_other: isDocValueOnlyOther, }, }, ], @@ -48,9 +95,13 @@ function getNewTestPackagePolicy({ function getExistingTestPackagePolicy({ isSyntheticSourceEnabled, isTSDBEnabled, + isDocValueOnlyNumeric, + isDocValueOnlyOther, }: { isSyntheticSourceEnabled: boolean; isTSDBEnabled: boolean; + isDocValueOnlyNumeric: boolean; + isDocValueOnlyOther: boolean; }): PackagePolicy { const packagePolicy: PackagePolicy = { id: 'test-policy', @@ -70,6 +121,8 @@ function getExistingTestPackagePolicy({ features: { synthetic_source: isSyntheticSourceEnabled, tsdb: isTSDBEnabled, + doc_value_only_numeric: isDocValueOnlyNumeric, + doc_value_only_other: isDocValueOnlyOther, }, }, ], @@ -104,6 +157,15 @@ describe('experimental_datastream_features', () => { type: 'keyword', time_series_dimension: true, }, + sequence: { + type: 'long', + }, + name: { + type: 'keyword', + }, + '@timestamp': { + type: 'date', + }, }, }, }, @@ -118,24 +180,26 @@ describe('experimental_datastream_features', () => { describe('when package policy does not exist (create)', () => { beforeEach(() => { - soClient.get.mockResolvedValueOnce({ - attributes: { - experimental_data_stream_features: [ - { - data_stream: 'metrics-test.test', - features: { synthetic_source: false, tsdb: false }, + mockGetInstallation.mockResolvedValueOnce({ + experimental_data_stream_features: [ + { + data_stream: 'metrics-test.test', + features: { + synthetic_source: false, + tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, - ], - }, - id: 'mocked', - type: 'mocked', - references: [], + }, + ], }); }); it('updates component template', async () => { const packagePolicy = getNewTestPackagePolicy({ isSyntheticSourceEnabled: true, isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: false, }); await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); @@ -152,10 +216,98 @@ describe('experimental_datastream_features', () => { ); }); + it('updates component template number fields', async () => { + const packagePolicy = getNewTestPackagePolicy({ + isSyntheticSourceEnabled: false, + isTSDBEnabled: false, + isDocValueOnlyNumeric: true, + isDocValueOnlyOther: false, + }); + + await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); + + expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); + expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + body: expect.objectContaining({ + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + sequence: { + type: 'long', + index: false, + }, + }), + }), + }), + }), + }) + ); + }); + + it('updates component template other fields', async () => { + const packagePolicy = getNewTestPackagePolicy({ + isSyntheticSourceEnabled: false, + isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: true, + }); + + await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); + + expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); + expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + body: expect.objectContaining({ + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + name: { + type: 'keyword', + index: false, + }, + }), + }), + }), + }), + }) + ); + }); + + it('should not set index:false on @timestamp field', async () => { + const packagePolicy = getNewTestPackagePolicy({ + isSyntheticSourceEnabled: false, + isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: true, + }); + + await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); + + expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); + expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + body: expect.objectContaining({ + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + '@timestamp': { + type: 'date', + }, + }), + }), + }), + }), + }) + ); + }); + it('should update index template', async () => { const packagePolicy = getNewTestPackagePolicy({ isSyntheticSourceEnabled: false, isTSDBEnabled: true, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: false, }); esClient.indices.getIndexTemplate.mockResolvedValueOnce({ @@ -197,20 +349,22 @@ describe('experimental_datastream_features', () => { const packagePolicy = getExistingTestPackagePolicy({ isSyntheticSourceEnabled: true, isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: false, }); - soClient.get.mockResolvedValueOnce({ - attributes: { - experimental_data_stream_features: [ - { - data_stream: 'metrics-test.test', - features: { synthetic_source: true, tsdb: false }, + mockGetInstallation.mockResolvedValueOnce({ + experimental_data_stream_features: [ + { + data_stream: 'metrics-test.test', + features: { + synthetic_source: true, + tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: false, }, - ], - }, - id: 'mocked', - type: 'mocked', - references: [], + }, + ], }); await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); @@ -222,24 +376,26 @@ describe('experimental_datastream_features', () => { describe('when opt in status is changed', () => { beforeEach(() => { - soClient.get.mockResolvedValueOnce({ - attributes: { - experimental_data_stream_features: [ - { - data_stream: 'metrics-test.test', - features: { synthetic_source: false, tsdb: false }, + mockGetInstallation.mockResolvedValueOnce({ + experimental_data_stream_features: [ + { + data_stream: 'metrics-test.test', + features: { + synthetic_source: false, + tsdb: false, + doc_value_only_numeric: false, + doc_value_only_other: true, }, - ], - }, - id: 'mocked', - type: 'mocked', - references: [], + }, + ], }); }); it('updates component template', async () => { const packagePolicy = getExistingTestPackagePolicy({ isSyntheticSourceEnabled: true, isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: true, }); await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); @@ -256,10 +412,70 @@ describe('experimental_datastream_features', () => { ); }); + it('updates component template number fields', async () => { + const packagePolicy = getExistingTestPackagePolicy({ + isSyntheticSourceEnabled: false, + isTSDBEnabled: false, + isDocValueOnlyNumeric: true, + isDocValueOnlyOther: true, + }); + + await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); + + expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); + expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + body: expect.objectContaining({ + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + sequence: { + type: 'long', + index: false, + }, + }), + }), + }), + }), + }) + ); + }); + + it('should not remove index:false from a field that has it in package spec', async () => { + const packagePolicy = getExistingTestPackagePolicy({ + isSyntheticSourceEnabled: false, + isTSDBEnabled: false, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: false, + }); + + await handleExperimentalDatastreamFeatureOptIn({ soClient, esClient, packagePolicy }); + + expect(esClient.cluster.getComponentTemplate).toHaveBeenCalled(); + expect(esClient.cluster.putComponentTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + body: expect.objectContaining({ + template: expect.objectContaining({ + mappings: expect.objectContaining({ + properties: expect.objectContaining({ + name: { + type: 'keyword', + index: false, + }, + }), + }), + }), + }), + }) + ); + }); + it('should update index template', async () => { const packagePolicy = getExistingTestPackagePolicy({ isSyntheticSourceEnabled: false, isTSDBEnabled: true, + isDocValueOnlyNumeric: false, + isDocValueOnlyOther: false, }); esClient.indices.getIndexTemplate.mockResolvedValueOnce({ diff --git a/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.ts b/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.ts index 0355b9a8553e8..20bd7fe4b546d 100644 --- a/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.ts +++ b/x-pack/plugins/fleet/server/services/package_policies/experimental_datastream_features.ts @@ -8,9 +8,19 @@ import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; import type { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; +import { merge } from 'lodash'; + +import { getRegistryDataStreamAssetBaseName } from '../../../common/services'; + +import type { ExperimentalIndexingFeature } from '../../../common/types'; import type { NewPackagePolicy, PackagePolicy } from '../../types'; -import { getInstallation } from '../epm/packages'; +import { prepareTemplate } from '../epm/elasticsearch/template/install'; +import { getInstallation, getPackageInfo } from '../epm/packages'; import { updateDatastreamExperimentalFeatures } from '../epm/packages/update'; +import { + applyDocOnlyValueToMapping, + forEachMappings, +} from '../experimental_datastream_features_helper'; export async function handleExperimentalDatastreamFeatureOptIn({ soClient, @@ -29,12 +39,36 @@ export async function handleExperimentalDatastreamFeatureOptIn({ // an update to the component templates for the package. So we fetch the saved object // for the package policy here to compare later. let installation; + const templateMappings: { [key: string]: any } = {}; if (packagePolicy.package) { installation = await getInstallation({ savedObjectsClient: soClient, pkgName: packagePolicy.package.name, }); + + const packageInfo = await getPackageInfo({ + savedObjectsClient: soClient, + pkgName: packagePolicy.package.name, + pkgVersion: packagePolicy.package.version, + }); + + // prepare template from package spec to find original index:false values + const templates = packageInfo.data_streams?.map((dataStream: any) => { + const experimentalDataStreamFeature = + packagePolicy.package?.experimental_data_stream_features?.find( + (datastreamFeature) => + datastreamFeature.data_stream === getRegistryDataStreamAssetBaseName(dataStream) + ); + return prepareTemplate({ pkg: packageInfo, dataStream, experimentalDataStreamFeature }); + }); + + templates?.forEach((template) => { + Object.keys(template.componentTemplates).forEach((templateName) => { + templateMappings[templateName] = + (template.componentTemplates[templateName].template as any).mappings ?? {}; + }); + }); } for (const featureMapEntry of packagePolicy.package.experimental_data_stream_features) { @@ -42,12 +76,25 @@ export async function handleExperimentalDatastreamFeatureOptIn({ (optIn) => optIn.data_stream === featureMapEntry.data_stream ); - const isSyntheticSourceOptInChanged = - existingOptIn?.features.synthetic_source !== featureMapEntry.features.synthetic_source; + const hasFeatureChanged = (name: ExperimentalIndexingFeature) => + existingOptIn?.features[name] !== featureMapEntry.features[name]; - const isTSDBOptInChanged = existingOptIn?.features.tsdb !== featureMapEntry.features.tsdb; + const isSyntheticSourceOptInChanged = hasFeatureChanged('synthetic_source'); - if (!isSyntheticSourceOptInChanged && !isTSDBOptInChanged) continue; + const isTSDBOptInChanged = hasFeatureChanged('tsdb'); + + const isDocValueOnlyNumericChanged = hasFeatureChanged('doc_value_only_numeric'); + const isDocValueOnlyOtherChanged = hasFeatureChanged('doc_value_only_other'); + + if ( + [ + isSyntheticSourceOptInChanged, + isTSDBOptInChanged, + isDocValueOnlyNumericChanged, + isDocValueOnlyOtherChanged, + ].every((hasFlagChange) => !hasFlagChange) + ) + continue; const componentTemplateName = `${featureMapEntry.data_stream}@package`; const componentTemplateRes = await esClient.cluster.getComponentTemplate({ @@ -56,22 +103,51 @@ export async function handleExperimentalDatastreamFeatureOptIn({ const componentTemplate = componentTemplateRes.component_templates[0].component_template; + const mappings = componentTemplate.template.mappings; + const componentTemplateChanged = + isDocValueOnlyNumericChanged || isDocValueOnlyOtherChanged || isSyntheticSourceOptInChanged; + + let mappingsProperties = componentTemplate.template.mappings?.properties; + if (isDocValueOnlyNumericChanged || isDocValueOnlyOtherChanged) { + forEachMappings(mappings?.properties ?? {}, (mappingProp, name) => + applyDocOnlyValueToMapping( + mappingProp, + name, + featureMapEntry, + isDocValueOnlyNumericChanged, + isDocValueOnlyOtherChanged + ) + ); + + const templateProperties = (templateMappings[componentTemplateName] ?? {}).properties ?? {}; + // merge package spec mappings with generated mappings, so that index:false from package spec is not overwritten + mappingsProperties = merge(templateProperties, mappings?.properties ?? {}); + } + + let sourceModeSettings = {}; + if (isSyntheticSourceOptInChanged) { + sourceModeSettings = { + _source: { + ...(featureMapEntry.features.synthetic_source ? { mode: 'synthetic' } : {}), + }, + }; + } + + if (componentTemplateChanged) { const body = { template: { ...componentTemplate.template, mappings: { - ...componentTemplate.template.mappings, - _source: { - ...(featureMapEntry.features.synthetic_source ? { mode: 'synthetic' } : {}), - }, + ...mappings, + properties: mappingsProperties ?? {}, + ...sourceModeSettings, }, }, }; await esClient.cluster.putComponentTemplate({ name: componentTemplateName, - // @ts-expect-error - TODO: Remove when ES client typings include support for synthetic source body, }); } diff --git a/x-pack/plugins/fleet/server/types/models/package_policy.ts b/x-pack/plugins/fleet/server/types/models/package_policy.ts index 64837501b941b..e1851693d3367 100644 --- a/x-pack/plugins/fleet/server/types/models/package_policy.ts +++ b/x-pack/plugins/fleet/server/types/models/package_policy.ts @@ -85,6 +85,8 @@ const ExperimentalDataStreamFeatures = schema.arrayOf( features: schema.object({ synthetic_source: schema.boolean(), tsdb: schema.boolean(), + doc_value_only_numeric: schema.boolean(), + doc_value_only_other: schema.boolean(), }), }) ); @@ -125,14 +127,7 @@ const CreatePackagePolicyProps = { name: schema.string(), title: schema.maybe(schema.string()), version: schema.string(), - experimental_data_stream_features: schema.maybe( - schema.arrayOf( - schema.object({ - data_stream: schema.string(), - features: schema.object({ synthetic_source: schema.boolean(), tsdb: schema.boolean() }), - }) - ) - ), + experimental_data_stream_features: schema.maybe(ExperimentalDataStreamFeatures), }) ), // Deprecated TODO create remove issue From 4e7560f19df610adb03c8a938d3c770d8659f5a4 Mon Sep 17 00:00:00 2001 From: Spencer Date: Wed, 25 Jan 2023 08:20:40 -0700 Subject: [PATCH 11/11] [ci-stats] move shipper to a package, validate limits in on-merge job (#149474) We just had an issue where two PRs were merged and it caused the limit of the `triggerActionsUi` bundle to be exceeded, breaking PR builds. The issue is that we didn't see any indication of this in the on-merge jobs because we don't produce the PR report for on-merge jobs or ask ci-stats if we should fail the job. Instead, we just ship the metrics for baseline purposes. This fixes that problem by adding a `--validate` flag to `node scripts/ship_ci_stats`, which takes care of sending at least some ci-stats and will verify that the bundle limits are not exceeded. Since we didn't catch this issue in the on-merge job the limits were incorrect for over an hour and merged into many PRs, wasting engineering and CI time. Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .buildkite/scripts/post_build_kibana.sh | 14 +++- .github/CODEOWNERS | 1 + package.json | 1 + packages/kbn-ci-stats-shipper-cli/README.md | 5 ++ .../kbn-ci-stats-shipper-cli/jest.config.js | 13 ++++ .../kbn-ci-stats-shipper-cli/kibana.jsonc | 6 ++ .../kbn-ci-stats-shipper-cli/package.json | 7 ++ .../ship_ci_stats_cli.ts | 77 +++++++++++++++++++ .../kbn-ci-stats-shipper-cli/tsconfig.json | 21 +++++ packages/kbn-dev-utils/index.ts | 1 - .../kbn-dev-utils/src/ship_ci_stats_cli.ts | 66 ---------------- packages/kbn-dev-utils/tsconfig.json | 1 - scripts/ship_ci_stats.js | 2 +- tsconfig.base.json | 2 + yarn.lock | 4 + 15 files changed, 149 insertions(+), 72 deletions(-) create mode 100644 packages/kbn-ci-stats-shipper-cli/README.md create mode 100644 packages/kbn-ci-stats-shipper-cli/jest.config.js create mode 100644 packages/kbn-ci-stats-shipper-cli/kibana.jsonc create mode 100644 packages/kbn-ci-stats-shipper-cli/package.json create mode 100644 packages/kbn-ci-stats-shipper-cli/ship_ci_stats_cli.ts create mode 100644 packages/kbn-ci-stats-shipper-cli/tsconfig.json delete mode 100644 packages/kbn-dev-utils/src/ship_ci_stats_cli.ts diff --git a/.buildkite/scripts/post_build_kibana.sh b/.buildkite/scripts/post_build_kibana.sh index d8b297935471a..e03c55684bf3d 100755 --- a/.buildkite/scripts/post_build_kibana.sh +++ b/.buildkite/scripts/post_build_kibana.sh @@ -3,10 +3,18 @@ set -euo pipefail if [[ ! "${DISABLE_CI_STATS_SHIPPING:-}" ]]; then + cmd=( + "node" "scripts/ship_ci_stats" + "--metrics" "target/optimizer_bundle_metrics.json" + "--metrics" "build/kibana/node_modules/@kbn/ui-shared-deps-src/shared_built_assets/metrics.json" + ) + + if [ "$BUILDKITE_PIPELINE_SLUG" == "kibana-on-merge" ]; then + cmd+=("--validate") + fi + echo "--- Ship Kibana Distribution Metrics to CI Stats" - node scripts/ship_ci_stats \ - --metrics target/optimizer_bundle_metrics.json \ - --metrics build/kibana/node_modules/@kbn/ui-shared-deps-src/shared_built_assets/metrics.json + "${cmd[@]}" fi echo "--- Upload Build Artifacts" diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 174cd07a4f00a..1a4e356ede959 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -901,6 +901,7 @@ packages/kbn-chart-icons @elastic/kibana-visualizations packages/kbn-ci-stats-core @elastic/kibana-operations packages/kbn-ci-stats-performance-metrics @elastic/kibana-operations packages/kbn-ci-stats-reporter @elastic/kibana-operations +packages/kbn-ci-stats-shipper-cli @elastic/kibana-operations packages/kbn-cli-dev-mode @elastic/kibana-operations packages/kbn-coloring @elastic/kibana-visualizations packages/kbn-config @elastic/kibana-core diff --git a/package.json b/package.json index bda02247f639e..6046f5f6b734b 100644 --- a/package.json +++ b/package.json @@ -764,6 +764,7 @@ "@kbn/ci-stats-core": "link:packages/kbn-ci-stats-core", "@kbn/ci-stats-performance-metrics": "link:packages/kbn-ci-stats-performance-metrics", "@kbn/ci-stats-reporter": "link:packages/kbn-ci-stats-reporter", + "@kbn/ci-stats-shipper-cli": "link:packages/kbn-ci-stats-shipper-cli", "@kbn/cli-dev-mode": "link:packages/kbn-cli-dev-mode", "@kbn/core-test-helpers-kbn-server": "link:packages/core/test-helpers/core-test-helpers-kbn-server", "@kbn/cypress-config": "link:packages/kbn-cypress-config", diff --git a/packages/kbn-ci-stats-shipper-cli/README.md b/packages/kbn-ci-stats-shipper-cli/README.md new file mode 100644 index 0000000000000..ee25c556845cf --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/README.md @@ -0,0 +1,5 @@ +# @kbn/ci-stats-shipper-cli + +Simple CLI that runs in CI to ship the metrics produced by the build process. We used to ship these metrics as part of the build, but in order to enable distributed caching of optimizer bundles (which we still don't do) we broke the metrics out of the build and write them to disk instead, to be shipped at a later time. + +Run `node scripts/ship_ci_stats --help` for usage information. \ No newline at end of file diff --git a/packages/kbn-ci-stats-shipper-cli/jest.config.js b/packages/kbn-ci-stats-shipper-cli/jest.config.js new file mode 100644 index 0000000000000..ef7da75f533e0 --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/jest.config.js @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../..', + roots: ['/packages/kbn-ci-stats-shipper-cli'], +}; diff --git a/packages/kbn-ci-stats-shipper-cli/kibana.jsonc b/packages/kbn-ci-stats-shipper-cli/kibana.jsonc new file mode 100644 index 0000000000000..725b15f63e988 --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/kibana.jsonc @@ -0,0 +1,6 @@ +{ + "type": "shared-common", + "id": "@kbn/ci-stats-shipper-cli", + "owner": "@elastic/kibana-operations", + "devOnly": true +} diff --git a/packages/kbn-ci-stats-shipper-cli/package.json b/packages/kbn-ci-stats-shipper-cli/package.json new file mode 100644 index 0000000000000..249e9cb36373c --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/package.json @@ -0,0 +1,7 @@ +{ + "name": "@kbn/ci-stats-shipper-cli", + "private": true, + "version": "1.0.0", + "license": "SSPL-1.0 OR Elastic License 2.0", + "main": "./ship_ci_stats_cli" +} \ No newline at end of file diff --git a/packages/kbn-ci-stats-shipper-cli/ship_ci_stats_cli.ts b/packages/kbn-ci-stats-shipper-cli/ship_ci_stats_cli.ts new file mode 100644 index 0000000000000..216a3c5bd04a3 --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/ship_ci_stats_cli.ts @@ -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 + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import Path from 'path'; +import Fs from 'fs'; + +import { CiStatsReporter, CiStatsMetric } from '@kbn/ci-stats-reporter'; + +import { createFailError } from '@kbn/dev-cli-errors'; +import { run } from '@kbn/dev-cli-runner'; + +run( + async ({ log, flagsReader }) => { + const validate = flagsReader.boolean('validate'); + const metricPaths = flagsReader.arrayOfStrings('metrics') ?? []; + + const maybeFail = (message: string) => { + const error = createFailError(message); + if (process.env.IGNORE_SHIP_CI_STATS_ERROR === 'true') { + error.exitCode = 0; + } + return error; + }; + + const reporter = CiStatsReporter.fromEnv(log); + + if (!reporter.isEnabled()) { + throw maybeFail('unable to initilize the CI Stats reporter'); + } + + const overLimit: string[] = []; + + for (const path of metricPaths) { + // resolve path from CLI relative to CWD + const abs = Path.resolve(path); + const json = Fs.readFileSync(abs, 'utf8'); + const metrics: CiStatsMetric[] = JSON.parse(json); + if (await reporter.metrics(metrics)) { + log.success('shipped metrics from', path); + } else { + throw maybeFail('failed to ship metrics'); + } + + for (const metric of metrics) { + if (metric.limit !== undefined && metric.limit < metric.value) { + overLimit.push( + `${metric.group} > ${metric.id} with value of ${metric.value} is greater than the limit of ${metric.limit}` + ); + } + } + } + + if (validate && overLimit.length) { + throw maybeFail(`Metric overages:\n${overLimit.map((l) => ` ${l}`).join('\n')}`); + } + }, + { + description: 'ship ci-stats which have been written to files', + usage: `node scripts/ship_ci_stats`, + log: { + defaultLevel: 'debug', + }, + flags: { + string: ['metrics'], + boolean: ['validate'], + help: ` + --metrics [path] A path to a JSON file that includes metrics which should be sent. Multiple instances supported + --validate When passed, the process will exit with an error message and a non-zero exit status if any of the bundle limits are exceeded. + `, + }, + } +); diff --git a/packages/kbn-ci-stats-shipper-cli/tsconfig.json b/packages/kbn-ci-stats-shipper-cli/tsconfig.json new file mode 100644 index 0000000000000..ded872f5961b3 --- /dev/null +++ b/packages/kbn-ci-stats-shipper-cli/tsconfig.json @@ -0,0 +1,21 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/ci-stats-reporter", + "@kbn/dev-cli-errors", + "@kbn/dev-cli-runner", + ] +} diff --git a/packages/kbn-dev-utils/index.ts b/packages/kbn-dev-utils/index.ts index c1ee96a2a35ab..86bdafebccf97 100644 --- a/packages/kbn-dev-utils/index.ts +++ b/packages/kbn-dev-utils/index.ts @@ -20,7 +20,6 @@ export { KBN_P12_PASSWORD, } from './src/certs'; export * from './src/axios'; -export * from './src/ship_ci_stats_cli'; export * from './src/plugin_list'; export * from './src/streams'; export * from './src/extract'; diff --git a/packages/kbn-dev-utils/src/ship_ci_stats_cli.ts b/packages/kbn-dev-utils/src/ship_ci_stats_cli.ts deleted file mode 100644 index 6f80a22a32ed9..0000000000000 --- a/packages/kbn-dev-utils/src/ship_ci_stats_cli.ts +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import Path from 'path'; -import Fs from 'fs'; - -import { CiStatsReporter } from '@kbn/ci-stats-reporter'; - -import { createFlagError, createFailError } from '@kbn/dev-cli-errors'; -import { run } from '@kbn/dev-cli-runner'; - -export function shipCiStatsCli() { - run( - async ({ log, flags }) => { - let metricPaths = flags.metrics; - if (typeof metricPaths === 'string') { - metricPaths = [metricPaths]; - } else if (!Array.isArray(metricPaths) || !metricPaths.every((p) => typeof p === 'string')) { - throw createFlagError('expected --metrics to be a string'); - } - - const maybeFail = (message: string) => { - const error = createFailError(message); - if (process.env.IGNORE_SHIP_CI_STATS_ERROR === 'true') { - error.exitCode = 0; - } - return error; - }; - - const reporter = CiStatsReporter.fromEnv(log); - - if (!reporter.isEnabled()) { - throw maybeFail('unable to initilize the CI Stats reporter'); - } - - for (const path of metricPaths) { - // resolve path from CLI relative to CWD - const abs = Path.resolve(path); - const json = Fs.readFileSync(abs, 'utf8'); - if (await reporter.metrics(JSON.parse(json))) { - log.success('shipped metrics from', path); - } else { - throw maybeFail('failed to ship metrics'); - } - } - }, - { - description: 'ship ci-stats which have been written to files', - usage: `node scripts/ship_ci_stats`, - log: { - defaultLevel: 'debug', - }, - flags: { - string: ['metrics'], - help: ` - --metrics [path] A path to a JSON file that includes metrics which should be sent. Multiple instances supported - `, - }, - } - ); -} diff --git a/packages/kbn-dev-utils/tsconfig.json b/packages/kbn-dev-utils/tsconfig.json index a4ad2f1db3a71..d66b40e46e31a 100644 --- a/packages/kbn-dev-utils/tsconfig.json +++ b/packages/kbn-dev-utils/tsconfig.json @@ -14,7 +14,6 @@ "@kbn/dev-cli-runner", "@kbn/dev-cli-errors", "@kbn/plugin-discovery", - "@kbn/ci-stats-reporter", "@kbn/repo-info", ], "exclude": [ diff --git a/scripts/ship_ci_stats.js b/scripts/ship_ci_stats.js index a45ab8472956c..4ceb5a6bc668a 100644 --- a/scripts/ship_ci_stats.js +++ b/scripts/ship_ci_stats.js @@ -7,4 +7,4 @@ */ require('../src/setup_node_env'); -require('@kbn/dev-utils').shipCiStatsCli(); +require('@kbn/ci-stats-shipper-cli'); diff --git a/tsconfig.base.json b/tsconfig.base.json index ca0c15d5a7cac..1d3dd3cd33b82 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -106,6 +106,8 @@ "@kbn/ci-stats-performance-metrics/*": ["packages/kbn-ci-stats-performance-metrics/*"], "@kbn/ci-stats-reporter": ["packages/kbn-ci-stats-reporter"], "@kbn/ci-stats-reporter/*": ["packages/kbn-ci-stats-reporter/*"], + "@kbn/ci-stats-shipper-cli": ["packages/kbn-ci-stats-shipper-cli"], + "@kbn/ci-stats-shipper-cli/*": ["packages/kbn-ci-stats-shipper-cli/*"], "@kbn/cli-dev-mode": ["packages/kbn-cli-dev-mode"], "@kbn/cli-dev-mode/*": ["packages/kbn-cli-dev-mode/*"], "@kbn/cloud-chat-plugin": ["x-pack/plugins/cloud_integrations/cloud_chat"], diff --git a/yarn.lock b/yarn.lock index c77393870b07f..a904689da8da9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2849,6 +2849,10 @@ version "0.0.0" uid "" +"@kbn/ci-stats-shipper-cli@link:packages/kbn-ci-stats-shipper-cli": + version "0.0.0" + uid "" + "@kbn/cli-dev-mode@link:packages/kbn-cli-dev-mode": version "0.0.0" uid ""