From 33f4505159683d51c1128cf5a7cd4ccf685cca8d Mon Sep 17 00:00:00 2001 From: klacabane Date: Fri, 21 Jun 2024 13:31:18 +0200 Subject: [PATCH 1/9] rename asset_manager to entity_manager --- .buildkite/ftr_configs.yml | 1 - package.json | 2 +- tsconfig.base.json | 4 +- .../asset_manager/README.md | 13 - .../asset_manager/common/config.ts | 48 --- .../asset_manager/common/constants_routes.ts | 21 -- .../asset_manager/common/types_api.ts | 315 ---------------- .../asset_manager/common/types_client.ts | 24 -- .../public/lib/public_assets_client.test.ts | 130 ------- .../public/lib/public_assets_client.ts | 94 ----- .../asset_manager/server/constants.ts | 8 - .../asset_manager/server/index.ts | 24 -- .../containers/get_containers.test.ts | 357 ------------------ .../accessors/containers/get_containers.ts | 91 ----- .../lib/accessors/hosts/get_hosts.test.ts | 357 ------------------ .../server/lib/accessors/hosts/get_hosts.ts | 91 ----- .../lib/accessors/pods/get_pods.test.ts | 341 ----------------- .../server/lib/accessors/pods/get_pods.ts | 96 ----- .../lib/accessors/services/get_services.ts | 108 ------ .../server/lib/asset_client.test.ts | 167 -------- .../asset_manager/server/lib/asset_client.ts | 56 --- .../server/lib/asset_client_types.ts | 28 -- .../server/lib/collectors/containers.ts | 101 ----- .../server/lib/collectors/hosts.ts | 119 ------ .../server/lib/collectors/index.ts | 38 -- .../server/lib/collectors/pods.ts | 101 ----- .../server/lib/collectors/services.ts | 147 -------- .../server/lib/manage_index_templates.ts | 119 ------ .../server/lib/parse_ean.test.ts | 33 -- .../asset_manager/server/lib/parse_ean.ts | 18 - .../asset_manager/server/lib/sample_assets.ts | 218 ----------- .../asset_manager/server/lib/write_assets.ts | 37 -- .../server/routes/assets/containers.ts | 73 ---- .../server/routes/assets/hosts.ts | 70 ---- .../server/routes/assets/index.ts | 70 ---- .../server/routes/assets/pods.ts | 70 ---- .../server/routes/assets/services.ts | 74 ---- .../server/routes/sample_assets.ts | 143 ------- .../asset_manager/server/routes/utils.ts | 46 --- .../server/templates/assets_template.ts | 44 --- .../asset_manager/server/test_utils.ts | 46 --- .../entity_manager/README.md | 3 + .../entity_manager/common/config.ts | 30 ++ .../common/constants_entities.ts | 0 .../common/debug_log.ts | 0 .../common/errors.ts | 0 .../entity_manager/common/types_api.ts | 25 ++ .../docs/entity_definitions.md | 0 .../jest.config.js | 6 +- .../kibana.jsonc | 10 +- .../public/index.ts | 10 +- .../public/lib/entity_client.ts | 0 .../public/plugin.ts | 26 +- .../public/types.ts | 18 +- .../entity_manager/server/index.ts | 18 + .../server/lib/auth/api_key/api_key.ts | 8 +- .../server/lib/auth/api_key/saved_object.ts | 6 +- .../server/lib/auth/index.ts | 0 .../server/lib/auth/privileges.ts | 0 .../server/lib/entities/built_in/constants.ts | 0 .../server/lib/entities/built_in/index.ts | 0 .../server/lib/entities/built_in/services.ts | 2 +- .../create_and_install_ingest_pipeline.ts | 0 .../entities/create_and_install_transform.ts | 0 .../lib/entities/delete_entity_definition.ts | 0 .../server/lib/entities/delete_index.ts | 0 .../lib/entities/delete_ingest_pipeline.ts | 0 .../errors/entity_id_conflict_error.ts | 0 .../lib/entities/errors/entity_not_found.ts | 0 .../errors/entity_security_exception.ts | 0 .../errors/invalid_transform_error.ts | 0 .../lib/entities/find_entity_definition.ts | 0 .../helpers/fixtures/entity_definition.ts | 0 .../entities/helpers/generate_index_name.ts | 0 .../get_elasticsearch_query_or_throw.ts | 0 .../server/lib/entities/helpers/retry.ts | 0 .../generate_history_processors.test.ts.snap | 0 .../generate_latest_processors.test.ts.snap | 0 .../generate_history_ingest_pipeline_id.ts | 0 .../generate_history_processors.test.ts | 0 .../generate_history_processors.ts | 0 .../generate_latest_ingest_pipeline_id.ts | 0 .../generate_latest_processors.test.ts | 0 .../generate_latest_processors.ts | 0 .../install_entity_definition.test.ts | 0 .../lib/entities/install_entity_definition.ts | 0 .../lib/entities/read_entity_definition.ts | 0 .../lib/entities/save_entity_definition.ts | 0 .../server/lib/entities/start_transform.ts | 0 .../lib/entities/stop_and_delete_transform.ts | 0 .../generate_history_transform.test.ts.snap | 0 .../generate_latest_transform.test.ts.snap | 0 .../generate_history_transform.test.ts | 0 .../transform/generate_history_transform.ts | 0 .../generate_history_transform_id.ts | 0 .../generate_latest_transform.test.ts | 0 .../transform/generate_latest_transform.ts | 0 .../transform/generate_latest_transform_id.ts | 0 .../generate_metadata_aggregations.ts | 0 .../transform/generate_metric_aggregations.ts | 0 .../entities/uninstall_entity_definition.ts | 0 .../server/lib/errors.ts | 0 .../server/lib/manage_index_templates.ts | 52 +++ .../server/lib/utils.ts | 0 .../lib/validators/validate_date_range.ts | 0 .../server/lib/validators/validation_error.ts | 0 .../server/plugin.ts | 67 +--- .../server/routes/enablement/check.ts | 0 .../server/routes/enablement/disable.ts | 0 .../server/routes/enablement/enable.ts | 0 .../server/routes/entities/create.ts | 0 .../server/routes/entities/delete.ts | 0 .../server/routes/entities/get.ts | 0 .../server/routes/entities/reset.ts | 0 .../server/routes/index.ts | 12 - .../server/routes/ping.ts | 6 +- .../server/routes/types.ts | 6 +- .../server/saved_objects/entity_definition.ts | 0 .../saved_objects/entity_discovery_api_key.ts | 0 .../server/saved_objects/index.ts | 0 .../server/templates/components/base.ts | 0 .../server/templates/components/entity.ts | 0 .../server/templates/components/event.ts | 0 .../server/templates/entities_template.ts | 0 .../server/types.ts | 21 +- .../tsconfig.json | 5 - .../asset_manager/config_when_disabled.ts | 17 - .../apis/asset_manager/tests/basics.ts | 29 -- .../apis/asset_manager/tests/constants.ts | 8 - .../apis/asset_manager/tests/helpers.ts | 104 ----- .../apis/asset_manager/tests/index.ts | 14 - .../apis/asset_manager/tests/sample_assets.ts | 162 -------- .../apis/asset_manager/tests/when_disabled.ts | 27 -- x-pack/test/tsconfig.json | 1 - yarn.lock | 8 +- 135 files changed, 194 insertions(+), 4450 deletions(-) delete mode 100644 x-pack/plugins/observability_solution/asset_manager/README.md delete mode 100644 x-pack/plugins/observability_solution/asset_manager/common/config.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/common/constants_routes.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/common/types_api.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/common/types_client.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/constants.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/index.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/services/get_services.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client_types.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/containers.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/hosts.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/index.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/pods.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/services.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/manage_index_templates.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.test.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/sample_assets.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/lib/write_assets.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/assets/containers.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/assets/hosts.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/assets/index.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/assets/pods.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/assets/services.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/routes/utils.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/templates/assets_template.ts delete mode 100644 x-pack/plugins/observability_solution/asset_manager/server/test_utils.ts create mode 100644 x-pack/plugins/observability_solution/entity_manager/README.md create mode 100644 x-pack/plugins/observability_solution/entity_manager/common/config.ts rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/common/constants_entities.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/common/debug_log.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/common/errors.ts (100%) create mode 100644 x-pack/plugins/observability_solution/entity_manager/common/types_api.ts rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/docs/entity_definitions.md (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/jest.config.js (68%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/kibana.jsonc (59%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/public/index.ts (61%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/public/lib/entity_client.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/public/plugin.ts (51%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/public/types.ts (59%) create mode 100644 x-pack/plugins/observability_solution/entity_manager/server/index.ts rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/auth/api_key/api_key.ts (92%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/auth/api_key/saved_object.ts (87%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/auth/index.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/auth/privileges.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/built_in/constants.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/built_in/index.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/built_in/services.ts (96%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/create_and_install_ingest_pipeline.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/create_and_install_transform.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/delete_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/delete_index.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/delete_ingest_pipeline.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/errors/entity_id_conflict_error.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/errors/entity_not_found.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/errors/entity_security_exception.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/errors/invalid_transform_error.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/find_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/helpers/fixtures/entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/helpers/generate_index_name.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/helpers/get_elasticsearch_query_or_throw.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/helpers/retry.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_history_ingest_pipeline_id.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_history_processors.test.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_history_processors.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_latest_ingest_pipeline_id.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_latest_processors.test.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/ingest_pipeline/generate_latest_processors.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/install_entity_definition.test.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/install_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/read_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/save_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/start_transform.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/stop_and_delete_transform.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/__snapshots__/generate_history_transform.test.ts.snap (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/__snapshots__/generate_latest_transform.test.ts.snap (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_history_transform.test.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_history_transform.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_history_transform_id.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_latest_transform.test.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_latest_transform.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_latest_transform_id.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_metadata_aggregations.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/transform/generate_metric_aggregations.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/entities/uninstall_entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/errors.ts (100%) create mode 100644 x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/utils.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/validators/validate_date_range.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/lib/validators/validation_error.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/plugin.ts (59%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/enablement/check.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/enablement/disable.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/enablement/enable.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/entities/create.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/entities/delete.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/entities/get.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/entities/reset.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/index.ts (72%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/ping.ts (79%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/routes/types.ts (77%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/saved_objects/entity_definition.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/saved_objects/entity_discovery_api_key.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/saved_objects/index.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/templates/components/base.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/templates/components/entity.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/templates/components/event.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/templates/entities_template.ts (100%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/server/types.ts (61%) rename x-pack/plugins/observability_solution/{asset_manager => entity_manager}/tsconfig.json (81%) delete mode 100644 x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/basics.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/constants.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/helpers.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/index.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/sample_assets.ts delete mode 100644 x-pack/test/api_integration/apis/asset_manager/tests/when_disabled.ts diff --git a/.buildkite/ftr_configs.yml b/.buildkite/ftr_configs.yml index 9abdda759760c..a7c682d284ac7 100644 --- a/.buildkite/ftr_configs.yml +++ b/.buildkite/ftr_configs.yml @@ -193,7 +193,6 @@ enabled: - x-pack/test/api_integration/config_security_basic.ts - x-pack/test/api_integration/config_security_trial.ts - x-pack/test/api_integration/apis/aiops/config.ts - - x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts - x-pack/test/api_integration/apis/cases/config.ts - x-pack/test/api_integration/apis/content_management/config.ts - x-pack/test/api_integration/apis/cloud_security_posture/config.ts diff --git a/package.json b/package.json index 0969445f4255f..31221a8fa24ea 100644 --- a/package.json +++ b/package.json @@ -176,7 +176,6 @@ "@kbn/apm-utils": "link:packages/kbn-apm-utils", "@kbn/app-link-test-plugin": "link:test/plugin_functional/plugins/app_link_test", "@kbn/application-usage-test-plugin": "link:x-pack/test/usage_collection/plugins/application_usage_test", - "@kbn/assetManager-plugin": "link:x-pack/plugins/observability_solution/asset_manager", "@kbn/assets-data-access-plugin": "link:x-pack/plugins/observability_solution/assets_data_access", "@kbn/audit-log-plugin": "link:x-pack/test/security_api_integration/plugins/audit_log", "@kbn/banners-plugin": "link:x-pack/plugins/banners", @@ -446,6 +445,7 @@ "@kbn/encrypted-saved-objects-plugin": "link:x-pack/plugins/encrypted_saved_objects", "@kbn/enterprise-search-plugin": "link:x-pack/plugins/enterprise_search", "@kbn/entities-schema": "link:x-pack/packages/kbn-entities-schema", + "@kbn/entityManager-plugin": "link:x-pack/plugins/observability_solution/entity_manager", "@kbn/error-boundary-example-plugin": "link:examples/error_boundary", "@kbn/es-errors": "link:packages/kbn-es-errors", "@kbn/es-query": "link:packages/kbn-es-query", diff --git a/tsconfig.base.json b/tsconfig.base.json index 0f8d9a11563e0..bfed534fa532b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -88,8 +88,6 @@ "@kbn/app-link-test-plugin/*": ["test/plugin_functional/plugins/app_link_test/*"], "@kbn/application-usage-test-plugin": ["x-pack/test/usage_collection/plugins/application_usage_test"], "@kbn/application-usage-test-plugin/*": ["x-pack/test/usage_collection/plugins/application_usage_test/*"], - "@kbn/assetManager-plugin": ["x-pack/plugins/observability_solution/asset_manager"], - "@kbn/assetManager-plugin/*": ["x-pack/plugins/observability_solution/asset_manager/*"], "@kbn/assets-data-access-plugin": ["x-pack/plugins/observability_solution/assets_data_access"], "@kbn/assets-data-access-plugin/*": ["x-pack/plugins/observability_solution/assets_data_access/*"], "@kbn/audit-log-plugin": ["x-pack/test/security_api_integration/plugins/audit_log"], @@ -776,6 +774,8 @@ "@kbn/enterprise-search-plugin/*": ["x-pack/plugins/enterprise_search/*"], "@kbn/entities-schema": ["x-pack/packages/kbn-entities-schema"], "@kbn/entities-schema/*": ["x-pack/packages/kbn-entities-schema/*"], + "@kbn/entityManager-plugin": ["x-pack/plugins/observability_solution/entity_manager"], + "@kbn/entityManager-plugin/*": ["x-pack/plugins/observability_solution/entity_manager/*"], "@kbn/error-boundary-example-plugin": ["examples/error_boundary"], "@kbn/error-boundary-example-plugin/*": ["examples/error_boundary/*"], "@kbn/es": ["packages/kbn-es"], diff --git a/x-pack/plugins/observability_solution/asset_manager/README.md b/x-pack/plugins/observability_solution/asset_manager/README.md deleted file mode 100644 index d73bfbb53b087..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Asset Manager Plugin - -This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more. - -## Documentation - -### User Docs - -For those interested in making use of the APIs provided by this plugin, see [our API docs](./docs/api.md). - -### Developer Docs - -For those working on this plugin directly and developing it, please see [our development docs](./docs/development.md). diff --git a/x-pack/plugins/observability_solution/asset_manager/common/config.ts b/x-pack/plugins/observability_solution/asset_manager/common/config.ts deleted file mode 100644 index 22d1c2ace4578..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/common/config.ts +++ /dev/null @@ -1,48 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema, TypeOf } from '@kbn/config-schema'; - -export const INDEX_DEFAULTS = { - logs: 'filebeat-*,logs-*', -}; - -export const configSchema = schema.object({ - alphaEnabled: schema.maybe(schema.boolean()), - // Designate where various types of data live. - // NOTE: this should be handled in a centralized way for observability, so - // that when a user configures these differently from the known defaults, - // that value is propagated everywhere. For now, we duplicate the value here. - sourceIndices: schema.object( - { - logs: schema.string({ defaultValue: INDEX_DEFAULTS.logs }), - }, - { defaultValue: INDEX_DEFAULTS } - ), -}); - -export type AssetManagerConfig = TypeOf; - -/** - * The following map is passed to the server plugin setup under the - * exposeToBrowser: option, and controls which of the above config - * keys are allow-listed to be available in the browser config. - * - * NOTE: anything exposed here will be visible in the UI dev tools, - * and therefore MUST NOT be anything that is sensitive information! - */ -export const exposeToBrowserConfig = { - alphaEnabled: true, -} as const; - -type ValidKeys = keyof { - [K in keyof typeof exposeToBrowserConfig as typeof exposeToBrowserConfig[K] extends true - ? K - : never]: true; -}; - -export type AssetManagerPublicConfig = Pick; diff --git a/x-pack/plugins/observability_solution/asset_manager/common/constants_routes.ts b/x-pack/plugins/observability_solution/asset_manager/common/constants_routes.ts deleted file mode 100644 index 6bbde84cc668b..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/common/constants_routes.ts +++ /dev/null @@ -1,21 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const ASSET_MANAGER_API_BASE = '/api/asset-manager'; - -function base(path: string) { - return `${ASSET_MANAGER_API_BASE}${path}`; -} - -export const GET_ASSETS = base('/assets'); -export const GET_RELATED_ASSETS = base('/assets/related'); -export const GET_ASSETS_DIFF = base('/assets/diff'); - -export const GET_HOSTS = base('/assets/hosts'); -export const GET_SERVICES = base('/assets/services'); -export const GET_CONTAINERS = base('/assets/containers'); -export const GET_PODS = base('/assets/pods'); diff --git a/x-pack/plugins/observability_solution/asset_manager/common/types_api.ts b/x-pack/plugins/observability_solution/asset_manager/common/types_api.ts deleted file mode 100644 index 108e4b254343f..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/common/types_api.ts +++ /dev/null @@ -1,315 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as rt from 'io-ts'; -import { - dateRt, - inRangeFromStringRt, - datemathStringRt, - createLiteralValueFromUndefinedRT, -} from '@kbn/io-ts-utils'; - -export const assetTypeRT = rt.keyof({ - 'k8s.pod': null, - 'k8s.cluster': null, - 'k8s.node': null, -}); - -export type AssetType = rt.TypeOf; - -export const assetKindRT = rt.keyof({ - cluster: null, - host: null, - pod: null, - container: null, - service: null, -}); - -export type AssetKind = rt.TypeOf; - -export const assetStatusRT = rt.keyof({ - CREATING: null, - ACTIVE: null, - DELETING: null, - FAILED: null, - UPDATING: null, - PENDING: null, - UNKNOWN: null, -}); - -export type AssetStatus = rt.TypeOf; - -// https://github.com/gcanti/io-ts/blob/master/index.md#union-of-string-literals -export const cloudProviderNameRT = rt.keyof({ - aws: null, - gcp: null, - azure: null, - other: null, - unknown: null, - none: null, -}); - -export type CloudProviderName = rt.TypeOf; - -const withTimestampRT = rt.type({ - '@timestamp': rt.string, -}); - -export type WithTimestamp = rt.TypeOf; - -export const ECSDocumentRT = rt.intersection([ - withTimestampRT, - rt.partial({ - 'kubernetes.namespace': rt.string, - 'kubernetes.pod.name': rt.string, - 'kubernetes.pod.uid': rt.string, - 'kubernetes.pod.start_time': rt.string, - 'kubernetes.node.name': rt.string, - 'kubernetes.node.start_time': rt.string, - 'orchestrator.api_version': rt.string, - 'orchestrator.namespace': rt.string, - 'orchestrator.organization': rt.string, - 'orchestrator.type': rt.string, - 'orchestrator.cluster.id': rt.string, - 'orchestrator.cluster.name': rt.string, - 'orchestrator.cluster.url': rt.string, - 'orchestrator.cluster.version': rt.string, - 'cloud.provider': cloudProviderNameRT, - 'cloud.instance.id': rt.string, - 'cloud.region': rt.string, - 'cloud.service.name': rt.string, - 'service.environment': rt.string, - }), -]); - -export type ECSDocument = rt.TypeOf; - -export const assetRT = rt.intersection([ - ECSDocumentRT, - rt.type({ - 'asset.ean': rt.string, - 'asset.id': rt.string, - 'asset.kind': assetKindRT, - }), - // mixed required and optional require separate hashes combined via intersection - // https://github.com/gcanti/io-ts/blob/master/index.md#mixing-required-and-optional-props - rt.partial({ - 'asset.collection_version': rt.string, - 'asset.name': rt.string, - 'asset.type': assetTypeRT, - 'asset.status': assetStatusRT, - 'asset.parents': rt.union([rt.string, rt.array(rt.string)]), - 'asset.children': rt.union([rt.string, rt.array(rt.string)]), - 'asset.references': rt.union([rt.string, rt.array(rt.string)]), - 'asset.namespace': rt.string, - }), -]); - -export type Asset = rt.TypeOf; - -export type AssetWithoutTimestamp = Omit; - -export interface K8sPod extends WithTimestamp { - id: string; - name?: string; - ean: string; - node?: string; - cloud?: { - provider?: CloudProviderName; - region?: string; - }; -} - -export interface K8sNodeMetricBucket { - timestamp: number; - date?: string; - averageMemoryAvailable: number | null; - averageMemoryUsage: number | null; - maxMemoryUsage: number | null; - averageCpuCoreNs: number | null; - maxCpuCoreNs: number | null; -} - -export interface K8sNodeLog { - timestamp: number; - message: string; -} - -export interface K8sNode extends WithTimestamp { - id: string; - name?: string; - ean: string; - pods?: K8sPod[]; - cluster?: K8sCluster; - cloud?: { - provider?: CloudProviderName; - region?: string; - }; - metrics?: K8sNodeMetricBucket[]; - logs?: K8sNodeLog[]; -} - -export interface K8sCluster extends WithTimestamp { - name?: string; - nodes?: K8sNode[]; - ean: string; - status?: AssetStatus; - version?: string; - cloud?: { - provider?: CloudProviderName; - region?: string; - }; -} - -export const assetFiltersSingleKindRT = rt.exact( - rt.partial({ - type: rt.union([assetTypeRT, rt.array(assetTypeRT)]), - ean: rt.union([rt.string, rt.array(rt.string)]), - id: rt.string, - parentEan: rt.string, - ['cloud.provider']: rt.string, - ['cloud.region']: rt.string, - ['orchestrator.cluster.name']: rt.string, - }) -); - -export type SingleKindAssetFilters = rt.TypeOf; - -const supportedKindRT = rt.union([rt.literal('host'), rt.literal('service')]); -export const assetFiltersRT = rt.intersection([ - assetFiltersSingleKindRT, - rt.partial({ kind: rt.union([supportedKindRT, rt.array(supportedKindRT)]) }), -]); - -export type AssetFilters = rt.TypeOf; - -export const relationRT = rt.union([ - rt.literal('ancestors'), - rt.literal('descendants'), - rt.literal('references'), -]); - -export type Relation = rt.TypeOf; -export type RelationField = keyof Pick< - Asset, - 'asset.children' | 'asset.parents' | 'asset.references' ->; - -export const sizeRT = rt.union([ - inRangeFromStringRt(1, 100), - createLiteralValueFromUndefinedRT(10), -]); -export const assetDateRT = rt.union([dateRt, datemathStringRt]); - -/** - * Hosts - */ -export const getHostAssetsQueryOptionsRT = rt.intersection([ - rt.strict({ from: assetDateRT }), - rt.partial({ - to: assetDateRT, - size: sizeRT, - stringFilters: rt.string, - filters: assetFiltersSingleKindRT, - }), -]); -export type GetHostAssetsQueryOptions = rt.TypeOf; -export const getHostAssetsResponseRT = rt.type({ - hosts: rt.array(assetRT), -}); -export type GetHostAssetsResponse = rt.TypeOf; - -/** - * Containers - */ -export const getContainerAssetsQueryOptionsRT = rt.intersection([ - rt.strict({ from: assetDateRT }), - rt.partial({ - to: assetDateRT, - size: sizeRT, - stringFilters: rt.string, - filters: assetFiltersSingleKindRT, - }), -]); -export type GetContainerAssetsQueryOptions = rt.TypeOf; -export const getContainerAssetsResponseRT = rt.type({ - containers: rt.array(assetRT), -}); -export type GetContainerAssetsResponse = rt.TypeOf; - -/** - * Services - */ -export const getServiceAssetsQueryOptionsRT = rt.intersection([ - rt.strict({ from: assetDateRT }), - rt.partial({ - from: assetDateRT, - to: assetDateRT, - size: sizeRT, - stringFilters: rt.string, - filters: assetFiltersSingleKindRT, - }), -]); - -export type GetServiceAssetsQueryOptions = rt.TypeOf; -export const getServiceAssetsResponseRT = rt.type({ - services: rt.array(assetRT), -}); -export type GetServiceAssetsResponse = rt.TypeOf; - -/** - * Pods - */ -export const getPodAssetsQueryOptionsRT = rt.intersection([ - rt.strict({ from: assetDateRT }), - rt.partial({ - to: assetDateRT, - size: sizeRT, - stringFilters: rt.string, - filters: assetFiltersSingleKindRT, - }), -]); -export type GetPodAssetsQueryOptions = rt.TypeOf; -export const getPodAssetsResponseRT = rt.type({ - pods: rt.array(assetRT), -}); -export type GetPodAssetsResponse = rt.TypeOf; - -/** - * Assets - */ -export const getAssetsQueryOptionsRT = rt.intersection([ - rt.strict({ from: assetDateRT }), - rt.partial({ - to: assetDateRT, - size: sizeRT, - stringFilters: rt.string, - filters: assetFiltersRT, - }), -]); -export type GetAssetsQueryOptions = rt.TypeOf; -export const getAssetsResponseRT = rt.type({ - assets: rt.array(assetRT), -}); -export type GetAssetsResponse = rt.TypeOf; - -/** - * Managed entities enablement - */ -export const managedEntityEnabledResponseRT = rt.type({ - enabled: rt.boolean, - reason: rt.string, -}); -export type ManagedEntityEnabledResponse = rt.TypeOf; - -export const managedEntityResponseBase = rt.type({ - success: rt.boolean, - reason: rt.string, - message: rt.string, -}); -export type EnableManagedEntityResponse = rt.TypeOf; -export type DisableManagedEntityResponse = rt.TypeOf; diff --git a/x-pack/plugins/observability_solution/asset_manager/common/types_client.ts b/x-pack/plugins/observability_solution/asset_manager/common/types_client.ts deleted file mode 100644 index e779a8a15ae31..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/common/types_client.ts +++ /dev/null @@ -1,24 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { AssetFilters, SingleKindAssetFilters } from './types_api'; - -export interface SharedAssetsOptionsPublic { - from: string; - to?: string; - filters?: F; - stringFilters?: string; -} - -// Methods that return only a single "kind" of asset should not accept -// a filter of "kind" to filter by asset kinds - -export type GetHostsOptionsPublic = SharedAssetsOptionsPublic; -export type GetContainersOptionsPublic = SharedAssetsOptionsPublic; -export type GetPodsOptionsPublic = SharedAssetsOptionsPublic; -export type GetServicesOptionsPublic = SharedAssetsOptionsPublic; -export type GetAssetsOptionsPublic = SharedAssetsOptionsPublic; diff --git a/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.test.ts b/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.test.ts deleted file mode 100644 index 649bcfcb83dc3..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.test.ts +++ /dev/null @@ -1,130 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { HttpSetupMock } from '@kbn/core-http-browser-mocks'; -import { coreMock } from '@kbn/core/public/mocks'; -import { PublicAssetsClient } from './public_assets_client'; -import * as routePaths from '../../common/constants_routes'; - -describe('Public assets client', () => { - let http: HttpSetupMock = coreMock.createSetup().http; - - beforeEach(() => { - http = coreMock.createSetup().http; - }); - - describe('class instantiation', () => { - it('should successfully instantiate', () => { - new PublicAssetsClient(http); - }); - }); - - describe('getHosts', () => { - it('should call the REST API', async () => { - const client = new PublicAssetsClient(http); - await client.getHosts({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledTimes(1); - }); - - it('should include specified "from" and "to" parameters in http.get query', async () => { - const client = new PublicAssetsClient(http); - await client.getHosts({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledWith(routePaths.GET_HOSTS, { - query: { from: 'x', to: 'y' }, - }); - }); - - it('should include provided filters, but in string form', async () => { - const client = new PublicAssetsClient(http); - const filters = { id: '*id-1*' }; - await client.getHosts({ from: 'x', filters }); - expect(http.get).toBeCalledWith(routePaths.GET_HOSTS, { - query: { - from: 'x', - stringFilters: JSON.stringify(filters), - }, - }); - }); - - it('should return the direct results of http.get', async () => { - const client = new PublicAssetsClient(http); - http.get.mockResolvedValueOnce('my hosts'); - const result = await client.getHosts({ from: 'x', to: 'y' }); - expect(result).toBe('my hosts'); - }); - }); - - describe('getContainers', () => { - it('should call the REST API', async () => { - const client = new PublicAssetsClient(http); - await client.getContainers({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledTimes(1); - }); - - it('should include specified "from" and "to" parameters in http.get query', async () => { - const client = new PublicAssetsClient(http); - await client.getContainers({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledWith(routePaths.GET_CONTAINERS, { - query: { from: 'x', to: 'y' }, - }); - }); - - it('should include provided filters, but in string form', async () => { - const client = new PublicAssetsClient(http); - const filters = { id: '*id-1*' }; - await client.getContainers({ from: 'x', filters }); - expect(http.get).toBeCalledWith(routePaths.GET_CONTAINERS, { - query: { - from: 'x', - stringFilters: JSON.stringify(filters), - }, - }); - }); - - it('should return the direct results of http.get', async () => { - const client = new PublicAssetsClient(http); - http.get.mockResolvedValueOnce('my hosts'); - const result = await client.getContainers({ from: 'x', to: 'y' }); - expect(result).toBe('my hosts'); - }); - }); - - describe('getServices', () => { - it('should call the REST API', async () => { - const client = new PublicAssetsClient(http); - await client.getServices({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledTimes(1); - }); - - it('should include specified "from" and "to" parameters in http.get query', async () => { - const client = new PublicAssetsClient(http); - await client.getServices({ from: 'x', to: 'y' }); - expect(http.get).toBeCalledWith(routePaths.GET_SERVICES, { - query: { from: 'x', to: 'y' }, - }); - }); - - it('should include provided filters, but in string form', async () => { - const client = new PublicAssetsClient(http); - const filters = { id: '*id-1*', parentEan: 'container:123' }; - await client.getServices({ from: 'x', filters }); - expect(http.get).toBeCalledWith(routePaths.GET_SERVICES, { - query: { - from: 'x', - stringFilters: JSON.stringify(filters), - }, - }); - }); - - it('should return the direct results of http.get', async () => { - const client = new PublicAssetsClient(http); - http.get.mockResolvedValueOnce('my services'); - const result = await client.getServices({ from: 'x', to: 'y' }); - expect(result).toBe('my services'); - }); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.ts b/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.ts deleted file mode 100644 index 130e723da34a6..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/public/lib/public_assets_client.ts +++ /dev/null @@ -1,94 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { HttpStart } from '@kbn/core/public'; -import { - GetContainersOptionsPublic, - GetHostsOptionsPublic, - GetServicesOptionsPublic, - GetPodsOptionsPublic, - GetAssetsOptionsPublic, -} from '../../common/types_client'; -import { - GetContainerAssetsResponse, - GetHostAssetsResponse, - GetServiceAssetsResponse, - GetPodAssetsResponse, - GetAssetsResponse, -} from '../../common/types_api'; -import { - GET_CONTAINERS, - GET_HOSTS, - GET_SERVICES, - GET_PODS, - GET_ASSETS, -} from '../../common/constants_routes'; -import { IPublicAssetsClient } from '../types'; - -export class PublicAssetsClient implements IPublicAssetsClient { - constructor(private readonly http: HttpStart) {} - - async getHosts(options: GetHostsOptionsPublic) { - const { filters, ...otherOptions } = options; - const results = await this.http.get(GET_HOSTS, { - query: { - stringFilters: JSON.stringify(filters), - ...otherOptions, - }, - }); - - return results; - } - - async getContainers(options: GetContainersOptionsPublic) { - const { filters, ...otherOptions } = options; - const results = await this.http.get(GET_CONTAINERS, { - query: { - stringFilters: JSON.stringify(filters), - ...otherOptions, - }, - }); - - return results; - } - - async getServices(options: GetServicesOptionsPublic) { - const { filters, ...otherOptions } = options; - const results = await this.http.get(GET_SERVICES, { - query: { - stringFilters: JSON.stringify(filters), - ...otherOptions, - }, - }); - - return results; - } - - async getPods(options: GetPodsOptionsPublic) { - const { filters, ...otherOptions } = options; - const results = await this.http.get(GET_PODS, { - query: { - stringFilters: JSON.stringify(filters), - ...otherOptions, - }, - }); - - return results; - } - - async getAssets(options: GetAssetsOptionsPublic) { - const { filters, ...otherOptions } = options; - const results = await this.http.get(GET_ASSETS, { - query: { - stringFilters: JSON.stringify(filters), - ...otherOptions, - }, - }); - - return results; - } -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/constants.ts b/x-pack/plugins/observability_solution/asset_manager/server/constants.ts deleted file mode 100644 index 4630365e47875..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/constants.ts +++ /dev/null @@ -1,8 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const ASSETS_INDEX_PREFIX = 'assets'; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/index.ts b/x-pack/plugins/observability_solution/asset_manager/server/index.ts deleted file mode 100644 index 86e5e855a74c9..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/index.ts +++ /dev/null @@ -1,24 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { PluginInitializerContext } from '@kbn/core-plugins-server'; -import { AssetManagerConfig } from '../common/config'; -import { AssetManagerServerPluginSetup, AssetManagerServerPluginStart, config } from './plugin'; -import type { WriteSamplesPostBody } from './routes/sample_assets'; - -export type { - AssetManagerConfig, - WriteSamplesPostBody, - AssetManagerServerPluginSetup, - AssetManagerServerPluginStart, -}; -export { config }; - -export const plugin = async (context: PluginInitializerContext) => { - const { AssetManagerServerPlugin } = await import('./plugin'); - return new AssetManagerServerPlugin(context); -}; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.test.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.test.ts deleted file mode 100644 index 8a7aad907a368..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.test.ts +++ /dev/null @@ -1,357 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import { GetApmIndicesMethod } from '../../asset_client_types'; -import { getContainers } from './get_containers'; -import { - createGetApmIndicesMock, - expectToThrowValidationErrorWithStatusCode, -} from '../../../test_utils'; -import { MetricsDataClient, MetricsDataClientMock } from '@kbn/metrics-data-access-plugin/server'; -import { SearchRequest } from '@elastic/elasticsearch/lib/api/types'; - -function createBaseOptions({ - getApmIndicesMock, - metricsDataClientMock, -}: { - getApmIndicesMock: GetApmIndicesMethod; - metricsDataClientMock: MetricsDataClient; -}) { - return { - sourceIndices: { - logs: 'my-logs*', - }, - getApmIndices: getApmIndicesMock, - metricsClient: metricsDataClientMock, - }; -} - -describe('getContainers', () => { - let getApmIndicesMock = createGetApmIndicesMock(); - let metricsDataClientMock = MetricsDataClientMock.create(); - let baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - let esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - let soClientMock = savedObjectsClientMock.create(); - - function resetMocks() { - getApmIndicesMock = createGetApmIndicesMock(); - metricsDataClientMock = MetricsDataClientMock.create(); - baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - soClientMock = savedObjectsClientMock.create(); - } - - beforeEach(() => { - resetMocks(); - - // ES returns no results, just enough structure to not blow up - esClientMock.search.mockResolvedValueOnce({ - took: 1, - timed_out: false, - _shards: { - failed: 0, - successful: 1, - total: 1, - }, - hits: { - hits: [], - }, - }); - }); - - it('should query Elasticsearch correctly', async () => { - await getContainers({ - ...baseOptions, - from: 'now-5d', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }); - - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledTimes(1); - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledWith({ - savedObjectsClient: soClientMock, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.filter).toEqual([ - { - range: { - '@timestamp': { - gte: 'now-5d', - lte: 'now-3d', - }, - }, - }, - ]); - - expect(bool?.must).toEqual([ - { - exists: { - field: 'container.id', - }, - }, - ]); - - expect(bool?.should).toEqual([ - { exists: { field: 'kubernetes.container.id' } }, - { exists: { field: 'kubernetes.pod.uid' } }, - { exists: { field: 'kubernetes.node.name' } }, - { exists: { field: 'host.hostname' } }, - ]); - }); - - it('should correctly include an EAN filter as a container ID term query', async () => { - const mockContainerId = '123abc'; - - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `container:${mockContainerId}`, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'container.id', - }, - }, - { - term: { - 'container.id': mockContainerId, - }, - }, - ]) - ); - }); - - it('should not query ES and return empty if filtering on non-container EAN', async () => { - const mockId = 'some-id-123'; - - const result = await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `pod:${mockId}`, - }, - }); - - expect(esClientMock.search).toHaveBeenCalledTimes(0); - expect(result).toEqual({ containers: [] }); - }); - - it('should throw an error when an invalid EAN is provided', async () => { - try { - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `invalid`, - }, - }); - } catch (error) { - const hasMessage = 'message' in error; - expect(hasMessage).toEqual(true); - expect(error.message).toEqual('invalid is not a valid EAN'); - } - - try { - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `invalid:toomany:colons`, - }, - }); - } catch (error) { - const hasMessage = 'message' in error; - expect(hasMessage).toEqual(true); - expect(error.message).toEqual('invalid:toomany:colons is not a valid EAN'); - } - }); - - it('should include a wildcard ID filter when an ID filter is provided with asterisks included', async () => { - const mockIdPattern = '*partial-id*'; - - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockIdPattern, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'container.id', - }, - }, - { - wildcard: { - 'container.id': mockIdPattern, - }, - }, - ]) - ); - }); - - it('should include a term ID filter when an ID filter is provided without asterisks included', async () => { - const mockId = 'full-id'; - - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockId, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'container.id', - }, - }, - { - term: { - 'container.id': mockId, - }, - }, - ]) - ); - }); - - it('should include a term filter for cloud filters', async () => { - const mockCloudProvider = 'gcp'; - const mockCloudRegion = 'us-central-1'; - - await getContainers({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - 'cloud.provider': mockCloudProvider, - 'cloud.region': mockCloudRegion, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'container.id', - }, - }, - { - term: { - 'cloud.provider': mockCloudProvider, - }, - }, - { - term: { - 'cloud.region': mockCloudRegion, - }, - }, - ]) - ); - }); - - it('should reject with 400 for invalid "from" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getContainers({ - ...baseOptions, - from: 'now-1zz', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 for invalid "to" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getContainers({ - ...baseOptions, - from: 'now-5d', - to: 'now-3fe', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is a date that is after "to"', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getContainers({ - ...baseOptions, - from: 'now', - to: 'now-5d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is in the future', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getContainers({ - ...baseOptions, - from: 'now+1d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.ts deleted file mode 100644 index c3c11bc375a84..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/containers/get_containers.ts +++ /dev/null @@ -1,91 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; -import { Asset } from '../../../../common/types_api'; -import { GetContainersOptionsPublic } from '../../../../common/types_client'; -import { - AssetClientDependencies, - AssetClientOptionsWithInjectedValues, -} from '../../asset_client_types'; -import { parseEan } from '../../parse_ean'; -import { collectContainers } from '../../collectors'; -import { validateStringDateRange } from '../../validators/validate_date_range'; - -export type GetContainersOptions = GetContainersOptionsPublic & AssetClientDependencies; -export type GetContainersOptionsInjected = - AssetClientOptionsWithInjectedValues; - -export async function getContainers( - options: GetContainersOptionsInjected -): Promise<{ containers: Asset[] }> { - validateStringDateRange(options.from, options.to); - - const metricsIndices = await options.metricsClient.getMetricIndices({ - savedObjectsClient: options.savedObjectsClient, - }); - - const filters: QueryDslQueryContainer[] = []; - - if (options.filters?.ean) { - const ean = Array.isArray(options.filters.ean) ? options.filters.ean[0] : options.filters.ean; - const { kind, id } = parseEan(ean); - - // if EAN filter isn't targeting a container asset, we don't need to do this query - if (kind !== 'container') { - return { - containers: [], - }; - } - - filters.push({ - term: { - 'container.id': id, - }, - }); - } - - if (options.filters?.id) { - const fn = options.filters.id.includes('*') ? 'wildcard' : 'term'; - filters.push({ - [fn]: { - 'container.id': options.filters.id, - }, - }); - } - - if (options.filters?.['cloud.provider']) { - filters.push({ - term: { - 'cloud.provider': options.filters['cloud.provider'], - }, - }); - } - - if (options.filters?.['cloud.region']) { - filters.push({ - term: { - 'cloud.region': options.filters['cloud.region'], - }, - }); - } - - const { assets } = await collectContainers({ - client: options.elasticsearchClient, - from: options.from, - to: options.to || 'now', - filters, - sourceIndices: { - metrics: metricsIndices, - logs: options.sourceIndices.logs, - }, - }); - - return { - containers: assets, - }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.test.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.test.ts deleted file mode 100644 index 1f7d1e7007bb5..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.test.ts +++ /dev/null @@ -1,357 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import { GetApmIndicesMethod } from '../../asset_client_types'; -import { getHosts } from './get_hosts'; -import { - createGetApmIndicesMock, - expectToThrowValidationErrorWithStatusCode, -} from '../../../test_utils'; -import { MetricsDataClient, MetricsDataClientMock } from '@kbn/metrics-data-access-plugin/server'; -import { SearchRequest } from '@elastic/elasticsearch/lib/api/types'; - -function createBaseOptions({ - getApmIndicesMock, - metricsDataClientMock, -}: { - getApmIndicesMock: GetApmIndicesMethod; - metricsDataClientMock: MetricsDataClient; -}) { - return { - sourceIndices: { - logs: 'my-logs*', - }, - getApmIndices: getApmIndicesMock, - metricsClient: metricsDataClientMock, - }; -} - -describe('getHosts', () => { - let getApmIndicesMock = createGetApmIndicesMock(); - let metricsDataClientMock = MetricsDataClientMock.create(); - let baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - let esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - let soClientMock = savedObjectsClientMock.create(); - - function resetMocks() { - getApmIndicesMock = createGetApmIndicesMock(); - metricsDataClientMock = MetricsDataClientMock.create(); - baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - soClientMock = savedObjectsClientMock.create(); - } - - beforeEach(() => { - resetMocks(); - - // ES returns no results, just enough structure to not blow up - esClientMock.search.mockResolvedValueOnce({ - took: 1, - timed_out: false, - _shards: { - failed: 0, - successful: 1, - total: 1, - }, - hits: { - hits: [], - }, - }); - }); - - it('should query Elasticsearch correctly', async () => { - await getHosts({ - ...baseOptions, - from: 'now-5d', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }); - - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledTimes(1); - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledWith({ - savedObjectsClient: soClientMock, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.filter).toEqual([ - { - range: { - '@timestamp': { - gte: 'now-5d', - lte: 'now-3d', - }, - }, - }, - ]); - - expect(bool?.must).toEqual([ - { - exists: { - field: 'host.hostname', - }, - }, - ]); - - expect(bool?.should).toEqual([ - { exists: { field: 'kubernetes.node.name' } }, - { exists: { field: 'kubernetes.pod.uid' } }, - { exists: { field: 'container.id' } }, - { exists: { field: 'cloud.provider' } }, - ]); - }); - - it('should correctly include an EAN filter as a hostname term query', async () => { - const mockHostName = 'some-hostname-123'; - - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `host:${mockHostName}`, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'host.hostname', - }, - }, - { - terms: { - 'host.hostname': [mockHostName], - }, - }, - ]) - ); - }); - - it('should not query ES and return empty if filtering on non-host EAN', async () => { - const mockId = 'some-id-123'; - - const result = await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `container:${mockId}`, - }, - }); - - expect(esClientMock.search).toHaveBeenCalledTimes(0); - expect(result).toEqual({ hosts: [] }); - }); - - it('should throw an error when an invalid EAN is provided', async () => { - try { - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `invalid`, - }, - }); - } catch (error) { - const hasMessage = 'message' in error; - expect(hasMessage).toEqual(true); - expect(error.message).toEqual('invalid is not a valid EAN'); - } - - try { - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `invalid:toomany:colons`, - }, - }); - } catch (error) { - const hasMessage = 'message' in error; - expect(hasMessage).toEqual(true); - expect(error.message).toEqual('invalid:toomany:colons is not a valid EAN'); - } - }); - - it('should include a wildcard ID filter when an ID filter is provided with asterisks included', async () => { - const mockIdPattern = '*partial-id*'; - - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockIdPattern, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'host.hostname', - }, - }, - { - wildcard: { - 'host.hostname': mockIdPattern, - }, - }, - ]) - ); - }); - - it('should include a term ID filter when an ID filter is provided without asterisks included', async () => { - const mockId = 'full-id'; - - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockId, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'host.hostname', - }, - }, - { - term: { - 'host.hostname': mockId, - }, - }, - ]) - ); - }); - - it('should include a term filter for cloud filters', async () => { - const mockCloudProvider = 'gcp'; - const mockCloudRegion = 'us-central-1'; - - await getHosts({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - 'cloud.provider': mockCloudProvider, - 'cloud.region': mockCloudRegion, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'host.hostname', - }, - }, - { - term: { - 'cloud.provider': mockCloudProvider, - }, - }, - { - term: { - 'cloud.region': mockCloudRegion, - }, - }, - ]) - ); - }); - - it('should reject with 400 for invalid "from" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getHosts({ - ...baseOptions, - from: 'now-1zz', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 for invalid "to" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getHosts({ - ...baseOptions, - from: 'now-5d', - to: 'now-3fe', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is a date that is after "to"', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getHosts({ - ...baseOptions, - from: 'now', - to: 'now-5d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is in the future', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getHosts({ - ...baseOptions, - from: 'now+1d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.ts deleted file mode 100644 index 8252c57da3b0f..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/hosts/get_hosts.ts +++ /dev/null @@ -1,91 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; -import { Asset } from '../../../../common/types_api'; -import { collectHosts } from '../../collectors/hosts'; -import { GetHostsOptionsPublic } from '../../../../common/types_client'; -import { - AssetClientDependencies, - AssetClientOptionsWithInjectedValues, -} from '../../asset_client_types'; -import { parseEan } from '../../parse_ean'; -import { validateStringDateRange } from '../../validators/validate_date_range'; - -export type GetHostsOptions = GetHostsOptionsPublic & AssetClientDependencies; -export type GetHostsOptionsInjected = AssetClientOptionsWithInjectedValues; - -export async function getHosts(options: GetHostsOptionsInjected): Promise<{ hosts: Asset[] }> { - validateStringDateRange(options.from, options.to); - - const metricsIndices = await options.metricsClient.getMetricIndices({ - savedObjectsClient: options.savedObjectsClient, - }); - - const filters: QueryDslQueryContainer[] = []; - - if (options.filters?.ean) { - const eans = Array.isArray(options.filters.ean) ? options.filters.ean : [options.filters.ean]; - const hostnames = eans - .map(parseEan) - .filter(({ kind }) => kind === 'host') - .map(({ id }) => id); - - // if EAN filter isn't targeting a host asset, we don't need to do this query - if (hostnames.length === 0) { - return { - hosts: [], - }; - } - - filters.push({ - terms: { - 'host.hostname': hostnames, - }, - }); - } - - if (options.filters?.id) { - const fn = options.filters.id.includes('*') ? 'wildcard' : 'term'; - filters.push({ - [fn]: { - 'host.hostname': options.filters.id, - }, - }); - } - - if (options.filters?.['cloud.provider']) { - filters.push({ - term: { - 'cloud.provider': options.filters['cloud.provider'], - }, - }); - } - - if (options.filters?.['cloud.region']) { - filters.push({ - term: { - 'cloud.region': options.filters['cloud.region'], - }, - }); - } - - const { assets } = await collectHosts({ - client: options.elasticsearchClient, - from: options.from, - to: options.to || 'now', - filters, - sourceIndices: { - metrics: metricsIndices, - logs: options.sourceIndices.logs, - }, - }); - - return { - hosts: assets, - }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.test.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.test.ts deleted file mode 100644 index 94d367963588c..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.test.ts +++ /dev/null @@ -1,341 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; -import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import { GetApmIndicesMethod } from '../../asset_client_types'; -import { getPods } from './get_pods'; -import { - createGetApmIndicesMock, - expectToThrowValidationErrorWithStatusCode, -} from '../../../test_utils'; -import { MetricsDataClient, MetricsDataClientMock } from '@kbn/metrics-data-access-plugin/server'; -import { SearchRequest } from '@elastic/elasticsearch/lib/api/types'; - -function createBaseOptions({ - getApmIndicesMock, - metricsDataClientMock, -}: { - getApmIndicesMock: GetApmIndicesMethod; - metricsDataClientMock: MetricsDataClient; -}) { - return { - sourceIndices: { - logs: 'my-logs*', - }, - getApmIndices: getApmIndicesMock, - metricsClient: metricsDataClientMock, - }; -} - -describe('getPods', () => { - let getApmIndicesMock = createGetApmIndicesMock(); - let metricsDataClientMock = MetricsDataClientMock.create(); - let baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - let esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - let soClientMock = savedObjectsClientMock.create(); - - function resetMocks() { - getApmIndicesMock = createGetApmIndicesMock(); - metricsDataClientMock = MetricsDataClientMock.create(); - baseOptions = createBaseOptions({ getApmIndicesMock, metricsDataClientMock }); - esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - soClientMock = savedObjectsClientMock.create(); - } - - beforeEach(() => { - resetMocks(); - - // ES returns no results, just enough structure to not blow up - esClientMock.search.mockResolvedValueOnce({ - took: 1, - timed_out: false, - _shards: { - failed: 0, - successful: 1, - total: 1, - }, - hits: { - hits: [], - }, - }); - }); - - it('should query Elasticsearch correctly', async () => { - await getPods({ - ...baseOptions, - from: 'now-5d', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }); - - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledTimes(1); - expect(metricsDataClientMock.getMetricIndices).toHaveBeenCalledWith({ - savedObjectsClient: soClientMock, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.filter).toEqual([ - { - range: { - '@timestamp': { - gte: 'now-5d', - lte: 'now-3d', - }, - }, - }, - ]); - - expect(bool?.must).toEqual([ - { - exists: { - field: 'kubernetes.pod.uid', - }, - }, - { - exists: { - field: 'kubernetes.node.name', - }, - }, - ]); - }); - - it('should correctly include an EAN filter as a pod ID term query', async () => { - const mockPodId = '123abc'; - - await getPods({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `pod:${mockPodId}`, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'kubernetes.pod.uid', - }, - }, - { - exists: { - field: 'kubernetes.node.name', - }, - }, - { - term: { - 'kubernetes.pod.uid': mockPodId, - }, - }, - ]) - ); - }); - - it('should not query ES and return empty if filtering on non-pod EAN', async () => { - const mockId = 'some-id-123'; - - const result = await getPods({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - ean: `container:${mockId}`, - }, - }); - - expect(esClientMock.search).toHaveBeenCalledTimes(0); - expect(result).toEqual({ pods: [] }); - }); - - it('should include a wildcard ID filter when an ID filter is provided with asterisks included', async () => { - const mockIdPattern = '*partial-id*'; - - await getPods({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockIdPattern, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'kubernetes.pod.uid', - }, - }, - { - exists: { - field: 'kubernetes.node.name', - }, - }, - { - wildcard: { - 'kubernetes.pod.uid': mockIdPattern, - }, - }, - ]) - ); - }); - - it('should include a term ID filter when an ID filter is provided without asterisks included', async () => { - const mockId = 'full-id'; - - await getPods({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - id: mockId, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'kubernetes.pod.uid', - }, - }, - { - exists: { - field: 'kubernetes.node.name', - }, - }, - { - term: { - 'kubernetes.pod.uid': mockId, - }, - }, - ]) - ); - }); - - it('should include a term filter for cloud filters', async () => { - const mockCloudProvider = 'gcp'; - const mockCloudRegion = 'us-central-1'; - - await getPods({ - ...baseOptions, - from: 'now-1h', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - filters: { - 'cloud.provider': mockCloudProvider, - 'cloud.region': mockCloudRegion, - }, - }); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.must).toEqual( - expect.arrayContaining([ - { - exists: { - field: 'kubernetes.pod.uid', - }, - }, - { - exists: { - field: 'kubernetes.node.name', - }, - }, - { - term: { - 'cloud.provider': mockCloudProvider, - }, - }, - { - term: { - 'cloud.region': mockCloudRegion, - }, - }, - ]) - ); - }); - - it('should reject with 400 for invalid "from" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getPods({ - ...baseOptions, - from: 'now-1zz', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 for invalid "to" date', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getPods({ - ...baseOptions, - from: 'now-5d', - to: 'now-3fe', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is a date that is after "to"', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getPods({ - ...baseOptions, - from: 'now', - to: 'now-5d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is in the future', () => { - return expectToThrowValidationErrorWithStatusCode( - () => - getPods({ - ...baseOptions, - from: 'now+1d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.ts deleted file mode 100644 index db2bc11ae2315..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/pods/get_pods.ts +++ /dev/null @@ -1,96 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; -import { Asset } from '../../../../common/types_api'; -import { GetPodsOptionsPublic } from '../../../../common/types_client'; -import { - AssetClientDependencies, - AssetClientOptionsWithInjectedValues, -} from '../../asset_client_types'; -import { parseEan } from '../../parse_ean'; -import { collectPods } from '../../collectors/pods'; -import { validateStringDateRange } from '../../validators/validate_date_range'; - -export type GetPodsOptions = GetPodsOptionsPublic & AssetClientDependencies; -export type GetPodsOptionsInjected = AssetClientOptionsWithInjectedValues; - -export async function getPods(options: GetPodsOptionsInjected): Promise<{ pods: Asset[] }> { - validateStringDateRange(options.from, options.to); - - const metricsIndices = await options.metricsClient.getMetricIndices({ - savedObjectsClient: options.savedObjectsClient, - }); - - const filters: QueryDslQueryContainer[] = []; - - if (options.filters?.ean) { - const ean = Array.isArray(options.filters.ean) ? options.filters.ean[0] : options.filters.ean; - const { kind, id } = parseEan(ean); - - // if EAN filter isn't targeting a pod asset, we don't need to do this query - if (kind !== 'pod') { - return { - pods: [], - }; - } - - filters.push({ - term: { - 'kubernetes.pod.uid': id, - }, - }); - } - - if (options.filters?.id) { - const fn = options.filters.id.includes('*') ? 'wildcard' : 'term'; - filters.push({ - [fn]: { - 'kubernetes.pod.uid': options.filters.id, - }, - }); - } - - if (options.filters?.['orchestrator.cluster.name']) { - filters.push({ - term: { - 'orchestrator.cluster.name': options.filters['orchestrator.cluster.name'], - }, - }); - } - - if (options.filters?.['cloud.provider']) { - filters.push({ - term: { - 'cloud.provider': options.filters['cloud.provider'], - }, - }); - } - - if (options.filters?.['cloud.region']) { - filters.push({ - term: { - 'cloud.region': options.filters['cloud.region'], - }, - }); - } - - const { assets } = await collectPods({ - client: options.elasticsearchClient, - from: options.from, - to: options.to || 'now', - filters, - sourceIndices: { - metrics: metricsIndices, - logs: options.sourceIndices.logs, - }, - }); - - return { - pods: assets, - }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/services/get_services.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/services/get_services.ts deleted file mode 100644 index b5a68028efcdb..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/accessors/services/get_services.ts +++ /dev/null @@ -1,108 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types'; -import { Asset } from '../../../../common/types_api'; -import { collectServices } from '../../collectors/services'; -import { parseEan } from '../../parse_ean'; -import { GetServicesOptionsPublic } from '../../../../common/types_client'; -import { - AssetClientDependencies, - AssetClientOptionsWithInjectedValues, -} from '../../asset_client_types'; -import { validateStringDateRange } from '../../validators/validate_date_range'; - -export type GetServicesOptions = GetServicesOptionsPublic & AssetClientDependencies; -export type GetServicesOptionsInjected = AssetClientOptionsWithInjectedValues; - -export async function getServices( - options: GetServicesOptionsInjected -): Promise<{ services: Asset[] }> { - validateStringDateRange(options.from, options.to); - - const filters: QueryDslQueryContainer[] = []; - - if (options.filters?.ean) { - const eans = Array.isArray(options.filters.ean) ? options.filters.ean : [options.filters.ean]; - const services = eans - .map(parseEan) - .filter(({ kind }) => kind === 'service') - .map(({ id }) => id); - - if (services.length === 0) { - return { - services: [], - }; - } - - filters.push({ - terms: { - 'service.name': services, - }, - }); - } - - if (options.filters?.parentEan) { - const { kind, id } = parseEan(options.filters?.parentEan); - - if (kind === 'host') { - filters.push({ - bool: { - should: [{ term: { 'host.name': id } }, { term: { 'host.hostname': id } }], - minimum_should_match: 1, - }, - }); - } - - if (kind === 'container') { - filters.push({ - bool: { - should: [{ term: { 'container.id': id } }], - minimum_should_match: 1, - }, - }); - } - } - - if (options.filters?.id) { - const fn = options.filters.id.includes('*') ? 'wildcard' : 'term'; - filters.push({ - [fn]: { - 'service.name': options.filters.id, - }, - }); - } - - if (options.filters?.['cloud.provider']) { - filters.push({ - term: { - 'cloud.provider': options.filters['cloud.provider'], - }, - }); - } - - if (options.filters?.['cloud.region']) { - filters.push({ - term: { - 'cloud.region': options.filters['cloud.region'], - }, - }); - } - - const apmIndices = await options.getApmIndices(options.savedObjectsClient); - const { assets } = await collectServices({ - client: options.elasticsearchClient, - from: options.from, - to: options.to || 'now', - sourceIndices: { - apm: apmIndices, - }, - filters, - }); - - return { services: assets }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.test.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.test.ts deleted file mode 100644 index 9ed5fb536251c..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.test.ts +++ /dev/null @@ -1,167 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - ElasticsearchClientMock, - elasticsearchClientMock, -} from '@kbn/core-elasticsearch-client-server-mocks'; -import { AssetClient } from './asset_client'; -import { MetricsDataClient, MetricsDataClientMock } from '@kbn/metrics-data-access-plugin/server'; -import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; -import { SearchRequest } from '@elastic/elasticsearch/lib/api/types'; -import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { AssetsValidationError } from './validators/validation_error'; -import { GetApmIndicesMethod } from './asset_client_types'; -import { createGetApmIndicesMock, expectToThrowValidationErrorWithStatusCode } from '../test_utils'; - -function createAssetClient( - metricsDataClient: MetricsDataClient, - getApmIndicesMock: jest.Mocked -) { - return new AssetClient({ - sourceIndices: { - logs: 'my-logs*', - }, - getApmIndices: getApmIndicesMock, - metricsClient: metricsDataClient, - }); -} - -describe('Server assets client', () => { - let metricsDataClientMock: MetricsDataClient = MetricsDataClientMock.create(); - let getApmIndicesMock: jest.Mocked = createGetApmIndicesMock(); - let esClientMock: ElasticsearchClientMock = - elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - let soClientMock: jest.Mocked; - - beforeEach(() => { - // Reset mocks - esClientMock = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - soClientMock = savedObjectsClientMock.create(); - metricsDataClientMock = MetricsDataClientMock.create(); - getApmIndicesMock = createGetApmIndicesMock(); - - // ES returns no results, just enough structure to not blow up - esClientMock.search.mockResolvedValueOnce({ - took: 1, - timed_out: false, - _shards: { - failed: 0, - successful: 1, - total: 1, - }, - hits: { - hits: [], - }, - }); - }); - - describe('class instantiation', () => { - it('should successfully instantiate', () => { - createAssetClient(metricsDataClientMock, getApmIndicesMock); - }); - }); - - // TODO: Move this block to the get_services accessor folder - describe('getServices', () => { - it('should query Elasticsearch correctly', async () => { - const client = createAssetClient(metricsDataClientMock, getApmIndicesMock); - - await client.getServices({ - from: 'now-5d', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }); - - expect(getApmIndicesMock).toHaveBeenCalledTimes(1); - expect(getApmIndicesMock).toHaveBeenCalledWith(soClientMock); - - const dsl = esClientMock.search.mock.lastCall?.[0] as SearchRequest | undefined; - const { bool } = dsl?.query || {}; - expect(bool).toBeDefined(); - - expect(bool?.filter).toEqual([ - { - range: { - '@timestamp': { - gte: 'now-5d', - lte: 'now-3d', - }, - }, - }, - ]); - - expect(bool?.must).toEqual([ - { - exists: { - field: 'service.name', - }, - }, - ]); - - expect(bool?.should).toBeUndefined(); - }); - - it('should reject with 400 for invalid "from" date', () => { - const client = createAssetClient(metricsDataClientMock, getApmIndicesMock); - - return expect(() => - client.getServices({ - from: 'now-1zz', - to: 'now-3d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }) - ).rejects.toThrow(AssetsValidationError); - }); - - it('should reject with 400 for invalid "to" date', () => { - const client = createAssetClient(metricsDataClientMock, getApmIndicesMock); - - return expectToThrowValidationErrorWithStatusCode( - () => - client.getServices({ - from: 'now-5d', - to: 'now-3fe', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is a date that is after "to"', () => { - const client = createAssetClient(metricsDataClientMock, getApmIndicesMock); - - return expectToThrowValidationErrorWithStatusCode( - () => - client.getServices({ - from: 'now', - to: 'now-5d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - - it('should reject with 400 when "from" is in the future', () => { - const client = createAssetClient(metricsDataClientMock, getApmIndicesMock); - - return expectToThrowValidationErrorWithStatusCode( - () => - client.getServices({ - from: 'now+1d', - elasticsearchClient: esClientMock, - savedObjectsClient: soClientMock, - }), - { statusCode: 400 } - ); - }); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.ts deleted file mode 100644 index 9de64a9e6c000..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client.ts +++ /dev/null @@ -1,56 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { orderBy } from 'lodash'; -import { Asset } from '../../common/types_api'; -import { GetAssetsOptionsPublic } from '../../common/types_client'; -import { getContainers, GetContainersOptions } from './accessors/containers/get_containers'; -import { getHosts, GetHostsOptions } from './accessors/hosts/get_hosts'; -import { getServices, GetServicesOptions } from './accessors/services/get_services'; -import { getPods, GetPodsOptions } from './accessors/pods/get_pods'; -import { AssetClientBaseOptions, AssetClientOptionsWithInjectedValues } from './asset_client_types'; -import { AssetClientDependencies } from './asset_client_types'; - -type GetAssetsOptions = GetAssetsOptionsPublic & AssetClientDependencies; - -export class AssetClient { - constructor(private baseOptions: AssetClientBaseOptions) {} - - injectOptions(options: T): AssetClientOptionsWithInjectedValues { - return { - ...options, - ...this.baseOptions, - }; - } - - async getHosts(options: GetHostsOptions): Promise<{ hosts: Asset[] }> { - const withInjected = this.injectOptions(options); - return await getHosts(withInjected); - } - - async getServices(options: GetServicesOptions): Promise<{ services: Asset[] }> { - const withInjected = this.injectOptions(options); - return await getServices(withInjected); - } - - async getContainers(options: GetContainersOptions): Promise<{ containers: Asset[] }> { - const withInjected = this.injectOptions(options); - return await getContainers(withInjected); - } - - async getPods(options: GetPodsOptions): Promise<{ pods: Asset[] }> { - const withInjected = this.injectOptions(options); - return await getPods(withInjected); - } - - async getAssets(options: GetAssetsOptions): Promise<{ assets: Asset[] }> { - const withInjected = this.injectOptions(options); - const { hosts } = await getHosts(withInjected); - const { services } = await getServices(withInjected); - return { assets: orderBy(hosts.concat(services), ['@timestamp'], ['desc']) }; - } -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client_types.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client_types.ts deleted file mode 100644 index a15886ce3a00a..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/asset_client_types.ts +++ /dev/null @@ -1,28 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { APMDataAccessConfig } from '@kbn/apm-data-access-plugin/server'; -import { ElasticsearchClient } from '@kbn/core-elasticsearch-server'; -import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { MetricsDataClient } from '@kbn/metrics-data-access-plugin/server'; -import { AssetManagerConfig } from '../../common/config'; - -export type GetApmIndicesMethod = ( - soClient: SavedObjectsClientContract -) => Promise; -export interface AssetClientDependencies { - elasticsearchClient: ElasticsearchClient; - savedObjectsClient: SavedObjectsClientContract; -} - -export interface AssetClientBaseOptions { - sourceIndices: AssetManagerConfig['sourceIndices']; - getApmIndices: GetApmIndicesMethod; - metricsClient: MetricsDataClient; -} - -export type AssetClientOptionsWithInjectedValues = T & AssetClientBaseOptions; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/containers.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/containers.ts deleted file mode 100644 index 2012e05912487..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/containers.ts +++ /dev/null @@ -1,101 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { estypes } from '@elastic/elasticsearch'; -import { Asset } from '../../../common/types_api'; -import { CollectorOptions, QUERY_MAX_SIZE } from '.'; -import { extractFieldValue } from '../utils'; - -export async function collectContainers({ - client, - from, - to, - sourceIndices, - filters = [], - afterKey, -}: CollectorOptions) { - if (!sourceIndices?.metrics || !sourceIndices?.logs) { - throw new Error('missing required metrics/logs indices'); - } - - const musts = [...filters, { exists: { field: 'container.id' } }]; - - const { metrics, logs } = sourceIndices; - const dsl: estypes.SearchRequest = { - index: [metrics, logs], - size: QUERY_MAX_SIZE, - collapse: { - field: 'container.id', - }, - sort: [{ 'container.id': 'asc' }], - _source: false, - fields: [ - '@timestamp', - 'kubernetes.*', - 'cloud.provider', - 'orchestrator.cluster.name', - 'host.name', - 'host.hostname', - ], - query: { - bool: { - filter: [ - { - range: { - '@timestamp': { - gte: from, - lte: to, - }, - }, - }, - ], - must: musts, - should: [ - { exists: { field: 'kubernetes.container.id' } }, - { exists: { field: 'kubernetes.pod.uid' } }, - { exists: { field: 'kubernetes.node.name' } }, - { exists: { field: 'host.hostname' } }, - ], - }, - }, - }; - - if (afterKey) { - dsl.search_after = afterKey; - } - - const esResponse = await client.search(dsl); - - const assets = esResponse.hits.hits.reduce((acc: Asset[], hit: any) => { - const { fields = {} } = hit; - const containerId = extractFieldValue(fields['container.id']); - const podUid = extractFieldValue(fields['kubernetes.pod.uid']); - const nodeName = extractFieldValue(fields['kubernetes.node.name']); - - const parentEan = podUid ? `pod:${podUid}` : `host:${fields['host.hostname']}`; - - const container: Asset = { - '@timestamp': extractFieldValue(fields['@timestamp']), - 'asset.kind': 'container', - 'asset.id': containerId, - 'asset.ean': `container:${containerId}`, - 'asset.parents': [parentEan], - }; - - if (nodeName) { - container['asset.references'] = [`host:${nodeName}`]; - } - - acc.push(container); - - return acc; - }, []); - - const hitsLen = esResponse.hits.hits.length; - const next = hitsLen === QUERY_MAX_SIZE ? esResponse.hits.hits[hitsLen - 1].sort : undefined; - return { assets, afterKey: next }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/hosts.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/hosts.ts deleted file mode 100644 index b624373010f10..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/hosts.ts +++ /dev/null @@ -1,119 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { estypes } from '@elastic/elasticsearch'; -import { Asset } from '../../../common/types_api'; -import { CollectorOptions, QUERY_MAX_SIZE } from '.'; -import { extractFieldValue } from '../utils'; - -export async function collectHosts({ - client, - from, - to, - sourceIndices, - afterKey, - filters = [], -}: CollectorOptions) { - if (!sourceIndices?.metrics || !sourceIndices?.logs) { - throw new Error('missing required metrics/logs indices'); - } - - const { metrics, logs } = sourceIndices; - - const musts = [...filters, { exists: { field: 'host.hostname' } }]; - const dsl: estypes.SearchRequest = { - index: [metrics, logs], - size: QUERY_MAX_SIZE, - collapse: { field: 'host.hostname' }, - sort: [{ 'host.hostname': 'asc' }], - _source: false, - fields: [ - '@timestamp', - 'cloud.*', - 'container.*', - 'host.hostname', - 'kubernetes.*', - 'orchestrator.cluster.name', - ], - query: { - bool: { - filter: [ - { - range: { - '@timestamp': { - gte: from, - lte: to, - }, - }, - }, - ], - must: musts, - should: [ - { exists: { field: 'kubernetes.node.name' } }, - { exists: { field: 'kubernetes.pod.uid' } }, - { exists: { field: 'container.id' } }, - { exists: { field: 'cloud.provider' } }, - ], - }, - }, - }; - - if (afterKey) { - dsl.search_after = afterKey; - } - - const esResponse = await client.search(dsl); - - const assets = esResponse.hits.hits.reduce((acc: Asset[], hit: any) => { - const { fields = {} } = hit; - const hostName = extractFieldValue(fields['host.hostname']); - const k8sNode = extractFieldValue(fields['kubernetes.node.name']); - const k8sPod = extractFieldValue(fields['kubernetes.pod.uid']); - - const hostEan = `host:${k8sNode || hostName}`; - - const host: Asset = { - '@timestamp': extractFieldValue(fields['@timestamp']), - 'asset.kind': 'host', - 'asset.id': k8sNode || hostName, - 'asset.name': k8sNode || hostName, - 'asset.ean': hostEan, - }; - - if (fields['cloud.provider']) { - host['cloud.provider'] = extractFieldValue(fields['cloud.provider']); - } - - if (fields['cloud.instance.id']) { - host['cloud.instance.id'] = extractFieldValue(fields['cloud.instance.id']); - } - - if (fields['cloud.service.name']) { - host['cloud.service.name'] = extractFieldValue(fields['cloud.service.name']); - } - - if (fields['cloud.region']) { - host['cloud.region'] = extractFieldValue(fields['cloud.region']); - } - - if (fields['orchestrator.cluster.name']) { - host['orchestrator.cluster.name'] = extractFieldValue(fields['orchestrator.cluster.name']); - } - - if (k8sPod) { - host['asset.children'] = [`pod:${k8sPod}`]; - } - - acc.push(host); - - return acc; - }, []); - - const hitsLen = esResponse.hits.hits.length; - const next = hitsLen === QUERY_MAX_SIZE ? esResponse.hits.hits[hitsLen - 1].sort : undefined; - return { assets, afterKey: next }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/index.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/index.ts deleted file mode 100644 index f1d79e749cd97..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/index.ts +++ /dev/null @@ -1,38 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { estypes } from '@elastic/elasticsearch'; -import type { APMIndices } from '@kbn/apm-data-access-plugin/server'; -import { ElasticsearchClient } from '@kbn/core/server'; -import { Asset } from '../../../common/types_api'; - -export const QUERY_MAX_SIZE = 10000; - -export type Collector = (opts: CollectorOptions) => Promise; - -export interface CollectorOptions { - client: ElasticsearchClient; - from: string; - to: string; - sourceIndices?: { - apm?: APMIndices; - metrics?: string; - logs?: string; - }; - afterKey?: estypes.SortResults; - filters?: estypes.QueryDslQueryContainer[]; -} - -export interface CollectorResult { - assets: Asset[]; - afterKey?: estypes.SortResults; -} - -export { collectContainers } from './containers'; -export { collectHosts } from './hosts'; -export { collectPods } from './pods'; -export { collectServices } from './services'; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/pods.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/pods.ts deleted file mode 100644 index e78fa106452ca..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/pods.ts +++ /dev/null @@ -1,101 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { estypes } from '@elastic/elasticsearch'; -import { Asset } from '../../../common/types_api'; -import { CollectorOptions, QUERY_MAX_SIZE } from '.'; -import { extractFieldValue } from '../utils'; - -export async function collectPods({ - client, - from, - to, - sourceIndices, - filters = [], - afterKey, -}: CollectorOptions) { - if (!sourceIndices?.metrics || !sourceIndices?.logs) { - throw new Error('missing required metrics/logs indices'); - } - - const musts = [ - ...filters, - { exists: { field: 'kubernetes.pod.uid' } }, - { exists: { field: 'kubernetes.node.name' } }, - ]; - - const { metrics, logs } = sourceIndices; - const dsl: estypes.SearchRequest = { - index: [metrics, logs], - size: QUERY_MAX_SIZE, - collapse: { - field: 'kubernetes.pod.uid', - }, - sort: [{ 'kubernetes.pod.uid': 'asc' }], - _source: false, - fields: [ - '@timestamp', - 'kubernetes.*', - 'cloud.provider', - 'orchestrator.cluster.name', - 'host.name', - 'host.hostname', - ], - query: { - bool: { - filter: [ - { - range: { - '@timestamp': { - gte: from, - lte: to, - }, - }, - }, - ], - must: musts, - }, - }, - }; - - if (afterKey) { - dsl.search_after = afterKey; - } - - const esResponse = await client.search(dsl); - - const assets = esResponse.hits.hits.reduce((acc: Asset[], hit: any) => { - const { fields = {} } = hit; - const podUid = extractFieldValue(fields['kubernetes.pod.uid']); - const nodeName = extractFieldValue(fields['kubernetes.node.name']); - const clusterName = extractFieldValue(fields['orchestrator.cluster.name']); - - const pod: Asset = { - '@timestamp': extractFieldValue(fields['@timestamp']), - 'asset.kind': 'pod', - 'asset.id': podUid, - 'asset.ean': `pod:${podUid}`, - 'asset.parents': [`host:${nodeName}`], - }; - - if (fields['cloud.provider']) { - pod['cloud.provider'] = extractFieldValue(fields['cloud.provider']); - } - - if (clusterName) { - pod['orchestrator.cluster.name'] = clusterName; - } - - acc.push(pod); - - return acc; - }, []); - - const hitsLen = esResponse.hits.hits.length; - const next = hitsLen === QUERY_MAX_SIZE ? esResponse.hits.hits[hitsLen - 1].sort : undefined; - return { assets, afterKey: next }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/services.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/services.ts deleted file mode 100644 index 4c49f75d13594..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/collectors/services.ts +++ /dev/null @@ -1,147 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { estypes } from '@elastic/elasticsearch'; -import { debug } from '../../../common/debug_log'; -import { Asset } from '../../../common/types_api'; -import { CollectorOptions, QUERY_MAX_SIZE } from '.'; - -export async function collectServices({ - client, - from, - to, - sourceIndices, - afterKey, - filters = [], -}: CollectorOptions) { - if (!sourceIndices?.apm) { - throw new Error('missing required apm indices'); - } - - const { transaction, error, metric } = sourceIndices.apm; - const musts: estypes.QueryDslQueryContainer[] = [ - ...filters, - { - exists: { - field: 'service.name', - }, - }, - ]; - - const dsl: estypes.SearchRequest = { - index: [transaction, error, metric], - size: 0, - _source: false, - query: { - bool: { - filter: [ - { - range: { - '@timestamp': { - gte: from, - lte: to, - }, - }, - }, - ], - must: musts, - }, - }, - aggs: { - services: { - composite: { - size: QUERY_MAX_SIZE, - sources: [ - { - serviceName: { - terms: { - field: 'service.name', - }, - }, - }, - { - serviceEnvironment: { - terms: { - field: 'service.environment', - missing_bucket: true, - }, - }, - }, - ], - }, - aggs: { - last_seen: { - max: { field: '@timestamp' }, - }, - container_and_hosts: { - multi_terms: { - terms: [ - { - field: 'host.hostname', - }, - { - field: 'container.id', - }, - ], - }, - }, - }, - }, - }, - }; - - if (afterKey) { - dsl.aggs!.services!.composite!.after = afterKey; - } - - debug(dsl); - - const esResponse = await client.search(dsl); - - const { after_key: nextKey, buckets = [] } = (esResponse.aggregations?.services || {}) as any; - const assets = buckets.reduce((acc: Asset[], bucket: any) => { - const { - key: { serviceName, serviceEnvironment }, - container_and_hosts: containerHosts, - last_seen: lastSeen, - } = bucket; - - if (!serviceName) { - return acc; - } - - const service: Asset = { - '@timestamp': lastSeen.value_as_string, - 'asset.kind': 'service', - 'asset.id': serviceName, - 'asset.ean': `service:${serviceName}`, - 'asset.references': [], - 'asset.parents': [], - }; - - if (serviceEnvironment) { - service['service.environment'] = serviceEnvironment; - } - - containerHosts.buckets?.forEach((containerBucket: any) => { - const [hostname, containerId] = containerBucket.key; - if (hostname) { - (service['asset.references'] as string[]).push(`host:${hostname}`); - } - - if (containerId) { - (service['asset.parents'] as string[]).push(`container:${containerId}`); - } - }); - - acc.push(service); - - return acc; - }, []); - - return { assets, afterKey: buckets.length === QUERY_MAX_SIZE ? nextKey : undefined }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/manage_index_templates.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/manage_index_templates.ts deleted file mode 100644 index b364e63ff9a1f..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/manage_index_templates.ts +++ /dev/null @@ -1,119 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - ClusterPutComponentTemplateRequest, - IndicesGetIndexTemplateResponse, - IndicesPutIndexTemplateRequest, -} from '@elastic/elasticsearch/lib/api/types'; -import { ElasticsearchClient, Logger } from '@kbn/core/server'; -import { ASSETS_INDEX_PREFIX } from '../constants'; - -function templateExists( - template: IndicesPutIndexTemplateRequest, - existing: IndicesGetIndexTemplateResponse | null -) { - if (existing === null) { - return false; - } - - if (existing.index_templates.length === 0) { - return false; - } - - const checkPatterns = Array.isArray(template.index_patterns) - ? template.index_patterns - : [template.index_patterns]; - - return existing.index_templates.some((t) => { - const { priority: existingPriority = 0 } = t.index_template; - const { priority: incomingPriority = 0 } = template; - if (existingPriority !== incomingPriority) { - return false; - } - - const existingPatterns = Array.isArray(t.index_template.index_patterns) - ? t.index_template.index_patterns - : [t.index_template.index_patterns]; - - if (checkPatterns.every((p) => p && existingPatterns.includes(p))) { - return true; - } - - return false; - }); -} - -interface TemplateManagementOptions { - esClient: ElasticsearchClient; - template: IndicesPutIndexTemplateRequest; - logger: Logger; -} - -interface ComponentManagementOptions { - esClient: ElasticsearchClient; - component: ClusterPutComponentTemplateRequest; - logger: Logger; -} - -export async function maybeCreateTemplate({ - esClient, - template, - logger, -}: TemplateManagementOptions) { - const pattern = ASSETS_INDEX_PREFIX + '*'; - template.index_patterns = [pattern]; - let existing: IndicesGetIndexTemplateResponse | null = null; - try { - existing = await esClient.indices.getIndexTemplate({ name: template.name }); - } catch (error: any) { - if (error?.name !== 'ResponseError' || error?.statusCode !== 404) { - logger.warn(`Asset manager index template lookup failed: ${error.message}`); - } - } - try { - if (!templateExists(template, existing)) { - await esClient.indices.putIndexTemplate(template); - } - } catch (error: any) { - logger.error(`Asset manager index template creation failed: ${error.message}`); - return; - } - - logger.info( - `Asset manager index template is up to date (use debug logging to see what was installed)` - ); - logger.debug(`Asset manager index template: ${JSON.stringify(template)}`); -} - -export async function upsertTemplate({ esClient, template, logger }: TemplateManagementOptions) { - try { - await esClient.indices.putIndexTemplate(template); - } catch (error: any) { - logger.error(`Error updating asset manager index template: ${error.message}`); - return; - } - - logger.info( - `Asset manager index template is up to date (use debug logging to see what was installed)` - ); - logger.debug(`Asset manager index template: ${JSON.stringify(template)}`); -} - -export async function upsertComponent({ esClient, component, logger }: ComponentManagementOptions) { - try { - await esClient.cluster.putComponentTemplate(component); - } catch (error: any) { - logger.error(`Error updating asset manager component template: ${error.message}`); - return; - } - - logger.info( - `Asset manager component template is up to date (use debug logging to see what was installed)` - ); - logger.debug(`Asset manager component template: ${JSON.stringify(component)}`); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.test.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.test.ts deleted file mode 100644 index b7dc5e592dabd..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.test.ts +++ /dev/null @@ -1,33 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { parseEan } from './parse_ean'; - -describe('parseEan function', () => { - it('should parse a valid EAN and return the kind and id as separate values', () => { - const ean = 'host:some-id-123'; - const { kind, id } = parseEan(ean); - expect(kind).toBe('host'); - expect(id).toBe('some-id-123'); - }); - - it('should throw an error when the provided EAN does not have enough segments', () => { - expect(() => parseEan('invalid-ean')).toThrowError('not a valid EAN'); - expect(() => parseEan('invalid-ean:')).toThrowError('not a valid EAN'); - expect(() => parseEan(':invalid-ean')).toThrowError('not a valid EAN'); - }); - - it('should throw an error when the provided EAN has too many segments', () => { - const ean = 'host:invalid:segments'; - expect(() => parseEan(ean)).toThrowError('not a valid EAN'); - }); - - it('should throw an error when the provided EAN includes an unsupported "kind" value', () => { - const ean = 'unsupported_kind:some-id-123'; - expect(() => parseEan(ean)).toThrowError('not a valid EAN'); - }); -}); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.ts deleted file mode 100644 index 6be17f40de005..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/parse_ean.ts +++ /dev/null @@ -1,18 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { assetKindRT } from '../../common/types_api'; - -export function parseEan(ean: string) { - const [kind, id, ...rest] = ean.split(':'); - - if (!assetKindRT.is(kind) || !kind || !id || rest.length > 0) { - throw new Error(`${ean} is not a valid EAN`); - } - - return { kind, id }; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/sample_assets.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/sample_assets.ts deleted file mode 100644 index 2e9fbc2bcd5be..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/sample_assets.ts +++ /dev/null @@ -1,218 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { Asset, AssetWithoutTimestamp } from '../../common/types_api'; - -// Provide a list of asset EAN values to remove, to simulate disappearing or -// appearing assets over time. -export function getSampleAssetDocs({ - baseDateTime = new Date(), - excludeEans = [], -}: { - baseDateTime?: Date; - excludeEans?: string[]; -}): Asset[] { - const timestamp = baseDateTime.toISOString(); - return sampleAssets - .filter((asset) => !excludeEans.includes(asset['asset.ean'])) - .map((asset) => { - return { - '@timestamp': timestamp, - ...asset, - }; - }); -} - -const sampleK8sClusters: AssetWithoutTimestamp[] = [ - { - 'asset.type': 'k8s.cluster', - 'asset.kind': 'cluster', - 'asset.id': 'cluster-001', - 'asset.name': 'Cluster 001 (AWS EKS)', - 'asset.ean': 'cluster:cluster-001', - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 001 (AWS EKS)', - 'orchestrator.cluster.id': 'cluster-001', - 'cloud.provider': 'aws', - 'cloud.region': 'us-east-1', - 'cloud.service.name': 'eks', - }, - { - 'asset.type': 'k8s.cluster', - 'asset.kind': 'cluster', - 'asset.id': 'cluster-002', - 'asset.name': 'Cluster 002 (Azure AKS)', - 'asset.ean': 'cluster:cluster-002', - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 002 (Azure AKS)', - 'orchestrator.cluster.id': 'cluster-002', - 'cloud.provider': 'azure', - 'cloud.region': 'eu-west', - 'cloud.service.name': 'aks', - }, -]; - -const sampleK8sNodes: AssetWithoutTimestamp[] = [ - { - 'asset.type': 'k8s.node', - 'asset.kind': 'host', - 'asset.id': 'node-101', - 'asset.name': 'k8s-node-101-aws', - 'asset.ean': 'host:node-101', - 'asset.parents': ['cluster:cluster-001'], - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 001 (AWS EKS)', - 'orchestrator.cluster.id': 'cluster-001', - 'cloud.provider': 'aws', - 'cloud.region': 'us-east-1', - 'cloud.service.name': 'eks', - }, - { - 'asset.type': 'k8s.node', - 'asset.kind': 'host', - 'asset.id': 'node-102', - 'asset.name': 'k8s-node-102-aws', - 'asset.ean': 'host:node-102', - 'asset.parents': ['cluster:cluster-001'], - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 001 (AWS EKS)', - 'orchestrator.cluster.id': 'cluster-001', - 'cloud.provider': 'aws', - 'cloud.region': 'us-east-1', - 'cloud.service.name': 'eks', - }, - { - 'asset.type': 'k8s.node', - 'asset.kind': 'host', - 'asset.id': 'node-103', - 'asset.name': 'k8s-node-103-aws', - 'asset.ean': 'host:node-103', - 'asset.parents': ['cluster:cluster-001'], - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 001 (AWS EKS)', - 'orchestrator.cluster.id': 'cluster-001', - 'cloud.provider': 'aws', - 'cloud.region': 'us-east-1', - 'cloud.service.name': 'eks', - }, -]; - -const sampleK8sPods: AssetWithoutTimestamp[] = [ - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200xrg1', - 'asset.name': 'k8s-pod-200xrg1-aws', - 'asset.ean': 'pod:pod-200xrg1', - 'asset.parents': ['host:node-101'], - 'asset.references': ['cluster:cluster-001'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200dfp2', - 'asset.name': 'k8s-pod-200dfp2-aws', - 'asset.ean': 'pod:pod-200dfp2', - 'asset.parents': ['host:node-101'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200wwc3', - 'asset.name': 'k8s-pod-200wwc3-aws', - 'asset.ean': 'pod:pod-200wwc3', - 'asset.parents': ['host:node-101'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200naq4', - 'asset.name': 'k8s-pod-200naq4-aws', - 'asset.ean': 'pod:pod-200naq4', - 'asset.parents': ['host:node-102'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200ohr5', - 'asset.name': 'k8s-pod-200ohr5-aws', - 'asset.ean': 'pod:pod-200ohr5', - 'asset.parents': ['host:node-102'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200yyx6', - 'asset.name': 'k8s-pod-200yyx6-aws', - 'asset.ean': 'pod:pod-200yyx6', - 'asset.parents': ['host:node-103'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200psd7', - 'asset.name': 'k8s-pod-200psd7-aws', - 'asset.ean': 'pod:pod-200psd7', - 'asset.parents': ['host:node-103'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200wmc8', - 'asset.name': 'k8s-pod-200wmc8-aws', - 'asset.ean': 'pod:pod-200wmc8', - 'asset.parents': ['host:node-103'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-200ugg9', - 'asset.name': 'k8s-pod-200ugg9-aws', - 'asset.ean': 'pod:pod-200ugg9', - 'asset.parents': ['host:node-103'], - }, -]; - -const sampleCircularReferences: AssetWithoutTimestamp[] = [ - { - 'asset.type': 'k8s.node', - 'asset.kind': 'host', - 'asset.id': 'node-203', - 'asset.name': 'k8s-node-203-aws', - 'asset.ean': 'host:node-203', - 'orchestrator.type': 'kubernetes', - 'orchestrator.cluster.name': 'Cluster 001 (AWS EKS)', - 'orchestrator.cluster.id': 'cluster-001', - 'cloud.provider': 'aws', - 'cloud.region': 'us-east-1', - 'cloud.service.name': 'eks', - 'asset.references': ['pod:pod-203ugg9', 'pod:pod-203ugg5'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-203ugg5', - 'asset.name': 'k8s-pod-203ugg5-aws', - 'asset.ean': 'pod:pod-203ugg5', - 'asset.references': ['host:node-203'], - }, - { - 'asset.type': 'k8s.pod', - 'asset.kind': 'pod', - 'asset.id': 'pod-203ugg9', - 'asset.name': 'k8s-pod-203ugg9-aws', - 'asset.ean': 'pod:pod-203ugg9', - 'asset.references': ['host:node-203'], - }, -]; - -export const sampleAssets: AssetWithoutTimestamp[] = [ - ...sampleK8sClusters, - ...sampleK8sNodes, - ...sampleK8sPods, - ...sampleCircularReferences, -]; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/write_assets.ts b/x-pack/plugins/observability_solution/asset_manager/server/lib/write_assets.ts deleted file mode 100644 index 72b79bc366b6d..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/write_assets.ts +++ /dev/null @@ -1,37 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { BulkRequest } from '@elastic/elasticsearch/lib/api/types'; -import { debug } from '../../common/debug_log'; -import { Asset } from '../../common/types_api'; -import { ASSETS_INDEX_PREFIX } from '../constants'; -import { ElasticsearchAccessorOptions } from '../types'; - -interface WriteAssetsOptions extends ElasticsearchAccessorOptions { - assetDocs: Asset[]; - namespace?: string; - refresh?: boolean | 'wait_for'; -} - -export async function writeAssets({ - elasticsearchClient, - assetDocs, - namespace = 'default', - refresh = false, -}: WriteAssetsOptions) { - const dsl: BulkRequest = { - refresh, - operations: assetDocs.flatMap((asset) => [ - { create: { _index: `${ASSETS_INDEX_PREFIX}-${asset['asset.type']}-${namespace}` } }, - asset, - ]), - }; - - debug('Performing Write Asset Query', '\n\n', JSON.stringify(dsl, null, 2)); - - return await elasticsearchClient.bulk<{}>(dsl); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/containers.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/containers.ts deleted file mode 100644 index f96fd79c05812..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/containers.ts +++ /dev/null @@ -1,73 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createRouteValidationFunction } from '@kbn/io-ts-utils'; -import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { - GetContainerAssetsQueryOptions, - getContainerAssetsQueryOptionsRT, -} from '../../../common/types_api'; -import { debug } from '../../../common/debug_log'; -import { SetupRouteOptions } from '../types'; -import * as routePaths from '../../../common/constants_routes'; -import { getClientsFromContext, validateStringAssetFilters } from '../utils'; -import { AssetsValidationError } from '../../lib/validators/validation_error'; - -export function containersRoutes({ - router, - server, -}: SetupRouteOptions) { - const validate = createRouteValidationFunction(getContainerAssetsQueryOptionsRT); - router.get( - { - path: routePaths.GET_CONTAINERS, - validate: { - query: (q, res) => { - const [invalidResponse, validatedFilters] = validateStringAssetFilters(q, res); - if (invalidResponse) { - return invalidResponse; - } - if (validatedFilters) { - q.filters = validatedFilters; - } - return validate(q, res); - }, - }, - }, - async (context, req, res) => { - const { from = 'now-24h', to = 'now', filters } = req.query || {}; - const { elasticsearchClient, savedObjectsClient } = await getClientsFromContext(context); - - try { - const response = await server.assetClient.getContainers({ - from, - to, - filters, // safe due to route validation, are there better ways to do this? - elasticsearchClient, - savedObjectsClient, - }); - - return res.ok({ body: response }); - } catch (error: unknown) { - debug('Error while looking up CONTAINER asset records', error); - - if (error instanceof AssetsValidationError) { - return res.customError({ - statusCode: error.statusCode, - body: { - message: `Error while looking up container asset records - ${error.message}`, - }, - }); - } - return res.customError({ - statusCode: 500, - body: { message: 'Error while looking up container asset records - ' + `${error}` }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/hosts.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/hosts.ts deleted file mode 100644 index 74f0724f43587..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/hosts.ts +++ /dev/null @@ -1,70 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createRouteValidationFunction } from '@kbn/io-ts-utils'; -import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { GetHostAssetsQueryOptions, getHostAssetsQueryOptionsRT } from '../../../common/types_api'; -import { debug } from '../../../common/debug_log'; -import { SetupRouteOptions } from '../types'; -import * as routePaths from '../../../common/constants_routes'; -import { getClientsFromContext, validateStringAssetFilters } from '../utils'; -import { AssetsValidationError } from '../../lib/validators/validation_error'; - -export function hostsRoutes({ - router, - server, -}: SetupRouteOptions) { - const validate = createRouteValidationFunction(getHostAssetsQueryOptionsRT); - router.get( - { - path: routePaths.GET_HOSTS, - validate: { - query: (q, res) => { - const [invalidResponse, validatedFilters] = validateStringAssetFilters(q, res); - if (invalidResponse) { - return invalidResponse; - } - if (validatedFilters) { - q.filters = validatedFilters; - } - return validate(q, res); - }, - }, - }, - async (context, req, res) => { - const { from = 'now-24h', to = 'now', filters } = req.query || {}; - const { elasticsearchClient, savedObjectsClient } = await getClientsFromContext(context); - - try { - const response = await server.assetClient.getHosts({ - from, - to, - filters, // safe due to route validation, are there better ways to do this? - elasticsearchClient, - savedObjectsClient, - }); - - return res.ok({ body: response }); - } catch (error: unknown) { - debug('Error while looking up HOST asset records', error); - - if (error instanceof AssetsValidationError) { - return res.customError({ - statusCode: error.statusCode, - body: { - message: `Error while looking up host asset records - ${error.message}`, - }, - }); - } - return res.customError({ - statusCode: 500, - body: { message: 'Error while looking up host asset records - ' + `${error}` }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/index.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/index.ts deleted file mode 100644 index b82aa4c15e10f..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/index.ts +++ /dev/null @@ -1,70 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createRouteValidationFunction } from '@kbn/io-ts-utils'; -import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { GetAssetsQueryOptions, getAssetsQueryOptionsRT } from '../../../common/types_api'; -import { debug } from '../../../common/debug_log'; -import { SetupRouteOptions } from '../types'; -import * as routePaths from '../../../common/constants_routes'; -import { getClientsFromContext, validateStringAssetFilters } from '../utils'; -import { AssetsValidationError } from '../../lib/validators/validation_error'; - -export function assetsRoutes({ - router, - server, -}: SetupRouteOptions) { - const validate = createRouteValidationFunction(getAssetsQueryOptionsRT); - router.get( - { - path: routePaths.GET_ASSETS, - validate: { - query: (q, res) => { - const [invalidResponse, validatedFilters] = validateStringAssetFilters(q, res); - if (invalidResponse) { - return invalidResponse; - } - if (validatedFilters) { - q.filters = validatedFilters; - } - return validate(q, res); - }, - }, - }, - async (context, req, res) => { - const { from = 'now-24h', to = 'now', filters } = req.query || {}; - const { elasticsearchClient, savedObjectsClient } = await getClientsFromContext(context); - - try { - const response = await server.assetClient.getAssets({ - from, - to, - filters, - elasticsearchClient, - savedObjectsClient, - }); - - return res.ok({ body: response }); - } catch (error: unknown) { - debug('Error while looking up asset records', error); - - if (error instanceof AssetsValidationError) { - return res.customError({ - statusCode: error.statusCode, - body: { - message: `Error while looking up asset records - ${error.message}`, - }, - }); - } - return res.customError({ - statusCode: 500, - body: { message: 'Error while looking up asset records - ' + `${error}` }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/pods.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/pods.ts deleted file mode 100644 index b5ff387641763..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/pods.ts +++ /dev/null @@ -1,70 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createRouteValidationFunction } from '@kbn/io-ts-utils'; -import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { GetPodAssetsQueryOptions, getPodAssetsQueryOptionsRT } from '../../../common/types_api'; -import { debug } from '../../../common/debug_log'; -import { SetupRouteOptions } from '../types'; -import * as routePaths from '../../../common/constants_routes'; -import { getClientsFromContext, validateStringAssetFilters } from '../utils'; -import { AssetsValidationError } from '../../lib/validators/validation_error'; - -export function podsRoutes({ - router, - server, -}: SetupRouteOptions) { - const validate = createRouteValidationFunction(getPodAssetsQueryOptionsRT); - router.get( - { - path: routePaths.GET_PODS, - validate: { - query: (q, res) => { - const [invalidResponse, validatedFilters] = validateStringAssetFilters(q, res); - if (invalidResponse) { - return invalidResponse; - } - if (validatedFilters) { - q.filters = validatedFilters; - } - return validate(q, res); - }, - }, - }, - async (context, req, res) => { - const { from = 'now-24h', to = 'now', filters } = req.query || {}; - const { elasticsearchClient, savedObjectsClient } = await getClientsFromContext(context); - - try { - const response = await server.assetClient.getPods({ - from, - to, - filters, - elasticsearchClient, - savedObjectsClient, - }); - - return res.ok({ body: response }); - } catch (error: unknown) { - debug('Error while looking up POD asset records', error); - - if (error instanceof AssetsValidationError) { - return res.customError({ - statusCode: error.statusCode, - body: { - message: `Error while looking up pod asset records - ${error.message}`, - }, - }); - } - return res.customError({ - statusCode: 500, - body: { message: 'Error while looking up pod asset records - ' + `${error}` }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/services.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/services.ts deleted file mode 100644 index 667a9568cda1d..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/assets/services.ts +++ /dev/null @@ -1,74 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createRouteValidationFunction } from '@kbn/io-ts-utils'; -import { RequestHandlerContext } from '@kbn/core-http-request-handler-context-server'; -import { - GetServiceAssetsQueryOptions, - getServiceAssetsQueryOptionsRT, -} from '../../../common/types_api'; -import { debug } from '../../../common/debug_log'; -import { SetupRouteOptions } from '../types'; -import * as routePaths from '../../../common/constants_routes'; -import { getClientsFromContext, validateStringAssetFilters } from '../utils'; -import { AssetsValidationError } from '../../lib/validators/validation_error'; - -export function servicesRoutes({ - router, - server, -}: SetupRouteOptions) { - const validate = createRouteValidationFunction(getServiceAssetsQueryOptionsRT); - // GET /assets/services - router.get( - { - path: routePaths.GET_SERVICES, - validate: { - query: (q, res) => { - const [invalidResponse, validatedFilters] = validateStringAssetFilters(q, res); - if (invalidResponse) { - return invalidResponse; - } - if (validatedFilters) { - q.filters = validatedFilters; - } - return validate(q, res); - }, - }, - }, - async (context, req, res) => { - const { from = 'now-24h', to = 'now', filters } = req.query || {}; - const { elasticsearchClient, savedObjectsClient } = await getClientsFromContext(context); - try { - const response = await server.assetClient.getServices({ - from, - to, - filters, - elasticsearchClient, - savedObjectsClient, - }); - - return res.ok({ body: response }); - } catch (error: unknown) { - debug('Error while looking up SERVICE asset records', error); - - if (error instanceof AssetsValidationError) { - return res.customError({ - statusCode: error.statusCode, - body: { - message: `Error while looking up service asset records - ${error.message}`, - }, - }); - } - - return res.customError({ - statusCode: 500, - body: { message: 'Error while looking up service asset records - ' + `${error}` }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts deleted file mode 100644 index 447051bbb2730..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts +++ /dev/null @@ -1,143 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { schema } from '@kbn/config-schema'; -import { RequestHandlerContext } from '@kbn/core/server'; -import { ASSET_MANAGER_API_BASE } from '../../common/constants_routes'; -import { getSampleAssetDocs, sampleAssets } from '../lib/sample_assets'; -import { writeAssets } from '../lib/write_assets'; -import { SetupRouteOptions } from './types'; -import { getClientsFromContext } from './utils'; - -export type WriteSamplesPostBody = { - baseDateTime?: string | number; - excludeEans?: string[]; - refresh?: boolean | 'wait_for'; -} | null; - -export function sampleAssetsRoutes({ - router, -}: SetupRouteOptions) { - const SAMPLE_ASSETS_API_PATH = `${ASSET_MANAGER_API_BASE}/assets/sample`; - - // GET sample assets - router.get( - { - path: SAMPLE_ASSETS_API_PATH, - validate: {}, - }, - async (context, req, res) => { - return res.ok({ body: { results: sampleAssets } }); - } - ); - - // POST sample assets - router.post( - { - path: SAMPLE_ASSETS_API_PATH, - validate: { - body: schema.nullable( - schema.object({ - baseDateTime: schema.maybe( - schema.oneOf([schema.string(), schema.number()]) - ), - excludeEans: schema.maybe(schema.arrayOf(schema.string())), - refresh: schema.maybe(schema.oneOf([schema.boolean(), schema.literal('wait_for')])), - }) - ), - }, - }, - async (context, req, res) => { - const { baseDateTime, excludeEans, refresh } = req.body || {}; - const parsed = baseDateTime === undefined ? undefined : new Date(baseDateTime); - if (parsed?.toString() === 'Invalid Date') { - return res.customError({ - statusCode: 400, - body: { - message: `${baseDateTime} is not a valid date time value`, - }, - }); - } - const { elasticsearchClient } = await getClientsFromContext(context); - const assetDocs = getSampleAssetDocs({ baseDateTime: parsed, excludeEans }); - - try { - const response = await writeAssets({ - elasticsearchClient, - assetDocs, - namespace: 'sample_data', - refresh, - }); - - if (response.errors) { - return res.customError({ - statusCode: 500, - body: { - message: JSON.stringify(response.errors), - }, - }); - } - - return res.ok({ body: response }); - } catch (error: any) { - return res.customError({ - statusCode: 500, - body: { - message: error.message || 'unknown error occurred while creating sample assets', - }, - }); - } - } - ); - - // DELETE all sample assets - router.delete( - { - path: SAMPLE_ASSETS_API_PATH, - validate: {}, - }, - async (context, req, res) => { - const { elasticsearchClient } = await getClientsFromContext(context); - - const sampleDataStreams = await elasticsearchClient.indices.getDataStream({ - name: 'assets-*-sample_data', - expand_wildcards: 'all', - }); - - const deletedDataStreams: string[] = []; - let errorWhileDeleting: string | null = null; - const dataStreamsToDelete = sampleDataStreams.data_streams.map((ds) => ds.name); - - for (let i = 0; i < dataStreamsToDelete.length; i++) { - const dsName = dataStreamsToDelete[i]; - try { - await elasticsearchClient.indices.deleteDataStream({ name: dsName }); - deletedDataStreams.push(dsName); - } catch (error: any) { - errorWhileDeleting = - typeof error.message === 'string' - ? error.message - : `Unknown error occurred while deleting sample data streams, at data stream name: ${dsName}`; - break; - } - } - - if (!errorWhileDeleting && deletedDataStreams.length === dataStreamsToDelete.length) { - return res.ok({ body: { deleted: deletedDataStreams } }); - } else { - return res.custom({ - statusCode: 500, - body: { - message: ['Not all found data streams were deleted', errorWhileDeleting].join(' - '), - deleted: deletedDataStreams, - matching: dataStreamsToDelete, - }, - }); - } - } - ); -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/utils.ts b/x-pack/plugins/observability_solution/asset_manager/server/routes/utils.ts deleted file mode 100644 index 3eb2a855e4854..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/utils.ts +++ /dev/null @@ -1,46 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - RequestHandlerContext, - RouteValidationError, - RouteValidationResultFactory, -} from '@kbn/core/server'; -import { AssetFilters, assetFiltersSingleKindRT } from '../../common/types_api'; - -export async function getClientsFromContext(context: T) { - const coreContext = await context.core; - - return { - coreContext, - elasticsearchClient: coreContext.elasticsearch.client.asCurrentUser, - savedObjectsClient: coreContext.savedObjects.client, - }; -} - -type ValidateStringAssetFiltersReturn = - | [{ error: RouteValidationError }] - | [null, AssetFilters | undefined]; - -export function validateStringAssetFilters( - q: any, - res: RouteValidationResultFactory -): ValidateStringAssetFiltersReturn { - if (typeof q.stringFilters === 'string') { - try { - const parsedFilters = JSON.parse(q.stringFilters); - if (assetFiltersSingleKindRT.is(parsedFilters)) { - return [null, parsedFilters]; - } else { - return [res.badRequest(new Error(`Invalid asset filters - ${q.filters}`))]; - } - } catch (err: any) { - return [res.badRequest(err)]; - } - } - return [null, undefined]; -} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/templates/assets_template.ts b/x-pack/plugins/observability_solution/asset_manager/server/templates/assets_template.ts deleted file mode 100644 index b99ecc4559187..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/templates/assets_template.ts +++ /dev/null @@ -1,44 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/types'; -import { ASSETS_INDEX_PREFIX } from '../constants'; - -export const assetsIndexTemplateConfig: IndicesPutIndexTemplateRequest = { - name: 'assets', - priority: 100, - data_stream: {}, - index_patterns: [`${ASSETS_INDEX_PREFIX}*`], - template: { - settings: {}, - mappings: { - dynamic_templates: [ - { - strings_as_keywords: { - mapping: { - ignore_above: 1024, - type: 'keyword', - }, - match_mapping_type: 'string', - }, - }, - ], - properties: { - '@timestamp': { - type: 'date', - }, - asset: { - type: 'object', - // subobjects appears to not exist in the types, but is a valid ES mapping option - // see: https://www.elastic.co/guide/en/elasticsearch/reference/master/subobjects.html - // @ts-ignore - subobjects: false, - }, - }, - }, - }, -}; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/test_utils.ts b/x-pack/plugins/observability_solution/asset_manager/server/test_utils.ts deleted file mode 100644 index 8e07f201b1599..0000000000000 --- a/x-pack/plugins/observability_solution/asset_manager/server/test_utils.ts +++ /dev/null @@ -1,46 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -// Helper function allows test to verify error was thrown, -// verify error is of the right class type, and error has - -import { SavedObjectsClientContract } from '@kbn/core-saved-objects-api-server'; -import { GetApmIndicesMethod } from './lib/asset_client_types'; -import { AssetsValidationError } from './lib/validators/validation_error'; - -// the expected metadata such as statusCode on it -export function expectToThrowValidationErrorWithStatusCode( - testFn: () => Promise, - expectedError: Partial = {} -) { - return expect(async () => { - try { - return await testFn(); - } catch (error: any) { - if (error instanceof AssetsValidationError) { - if (expectedError.statusCode) { - expect(error.statusCode).toEqual(expectedError.statusCode); - } - if (expectedError.message) { - expect(error.message).toEqual(expect.stringContaining(expectedError.message)); - } - } - throw error; - } - }).rejects.toThrow(AssetsValidationError); -} - -export function createGetApmIndicesMock(): jest.Mocked { - return jest.fn(async (client: SavedObjectsClientContract) => ({ - transaction: 'apm-mock-transaction-indices', - span: 'apm-mock-span-indices', - error: 'apm-mock-error-indices', - metric: 'apm-mock-metric-indices', - onboarding: 'apm-mock-onboarding-indices', - sourcemap: 'apm-mock-sourcemap-indices', - })); -} diff --git a/x-pack/plugins/observability_solution/entity_manager/README.md b/x-pack/plugins/observability_solution/entity_manager/README.md new file mode 100644 index 0000000000000..325bea1b583e8 --- /dev/null +++ b/x-pack/plugins/observability_solution/entity_manager/README.md @@ -0,0 +1,3 @@ +# Entity Manager Plugin + +This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more. \ No newline at end of file diff --git a/x-pack/plugins/observability_solution/entity_manager/common/config.ts b/x-pack/plugins/observability_solution/entity_manager/common/config.ts new file mode 100644 index 0000000000000..5c1edfa618626 --- /dev/null +++ b/x-pack/plugins/observability_solution/entity_manager/common/config.ts @@ -0,0 +1,30 @@ +/* + * 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 { schema, TypeOf } from '@kbn/config-schema'; + +export const configSchema = schema.object({}); + +export type EntityManagerConfig = TypeOf; + +/** + * The following map is passed to the server plugin setup under the + * exposeToBrowser: option, and controls which of the above config + * keys are allow-listed to be available in the browser config. + * + * NOTE: anything exposed here will be visible in the UI dev tools, + * and therefore MUST NOT be anything that is sensitive information! + */ +export const exposeToBrowserConfig = {} as const; + +type ValidKeys = keyof { + [K in keyof typeof exposeToBrowserConfig as typeof exposeToBrowserConfig[K] extends true + ? K + : never]: true; +}; + +export type EntityManagerPublicConfig = Pick; diff --git a/x-pack/plugins/observability_solution/asset_manager/common/constants_entities.ts b/x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/common/constants_entities.ts rename to x-pack/plugins/observability_solution/entity_manager/common/constants_entities.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/common/debug_log.ts b/x-pack/plugins/observability_solution/entity_manager/common/debug_log.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/common/debug_log.ts rename to x-pack/plugins/observability_solution/entity_manager/common/debug_log.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/common/errors.ts b/x-pack/plugins/observability_solution/entity_manager/common/errors.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/common/errors.ts rename to x-pack/plugins/observability_solution/entity_manager/common/errors.ts diff --git a/x-pack/plugins/observability_solution/entity_manager/common/types_api.ts b/x-pack/plugins/observability_solution/entity_manager/common/types_api.ts new file mode 100644 index 0000000000000..90540ab06a243 --- /dev/null +++ b/x-pack/plugins/observability_solution/entity_manager/common/types_api.ts @@ -0,0 +1,25 @@ +/* + * 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 * as rt from 'io-ts'; + +/** + * Managed entities enablement + */ +export const managedEntityEnabledResponseRT = rt.type({ + enabled: rt.boolean, + reason: rt.string, +}); +export type ManagedEntityEnabledResponse = rt.TypeOf; + +export const managedEntityResponseBase = rt.type({ + success: rt.boolean, + reason: rt.string, + message: rt.string, +}); +export type EnableManagedEntityResponse = rt.TypeOf; +export type DisableManagedEntityResponse = rt.TypeOf; diff --git a/x-pack/plugins/observability_solution/asset_manager/docs/entity_definitions.md b/x-pack/plugins/observability_solution/entity_manager/docs/entity_definitions.md similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/docs/entity_definitions.md rename to x-pack/plugins/observability_solution/entity_manager/docs/entity_definitions.md diff --git a/x-pack/plugins/observability_solution/asset_manager/jest.config.js b/x-pack/plugins/observability_solution/entity_manager/jest.config.js similarity index 68% rename from x-pack/plugins/observability_solution/asset_manager/jest.config.js rename to x-pack/plugins/observability_solution/entity_manager/jest.config.js index 3f091dd5109b3..29fb7c37260fb 100644 --- a/x-pack/plugins/observability_solution/asset_manager/jest.config.js +++ b/x-pack/plugins/observability_solution/entity_manager/jest.config.js @@ -8,11 +8,11 @@ module.exports = { preset: '@kbn/test', rootDir: '../../../..', - roots: ['/x-pack/plugins/observability_solution/asset_manager'], + roots: ['/x-pack/plugins/observability_solution/entity_manager'], coverageDirectory: - '/target/kibana-coverage/jest/x-pack/plugins/observability_solution/asset_manager', + '/target/kibana-coverage/jest/x-pack/plugins/observability_solution/entity_manager', coverageReporters: ['text', 'html'], collectCoverageFrom: [ - '/x-pack/plugins/observability_solution/asset_manager/{common,public,server}/**/*.{js,ts,tsx}', + '/x-pack/plugins/observability_solution/entity_manager/{common,public,server}/**/*.{js,ts,tsx}', ], }; diff --git a/x-pack/plugins/observability_solution/asset_manager/kibana.jsonc b/x-pack/plugins/observability_solution/entity_manager/kibana.jsonc similarity index 59% rename from x-pack/plugins/observability_solution/asset_manager/kibana.jsonc rename to x-pack/plugins/observability_solution/entity_manager/kibana.jsonc index d4c7703deb6eb..b13c51630469e 100644 --- a/x-pack/plugins/observability_solution/asset_manager/kibana.jsonc +++ b/x-pack/plugins/observability_solution/entity_manager/kibana.jsonc @@ -1,20 +1,18 @@ { "type": "plugin", - "id": "@kbn/assetManager-plugin", + "id": "@kbn/entityManager-plugin", "owner": "@elastic/obs-knowledge-team", - "description": "Asset manager plugin for entity assets (inventory, topology, etc)", + "description": "Entity manager plugin for entity assets (inventory, topology, etc)", "plugin": { - "id": "assetManager", + "id": "entityManager", "configPath": [ "xpack", - "assetManager" + "entityManager" ], "optionalPlugins": [ "spaces" ], "requiredPlugins": [ - "apmDataAccess", - "metricsDataAccess", "security", "encryptedSavedObjects", ], diff --git a/x-pack/plugins/observability_solution/asset_manager/public/index.ts b/x-pack/plugins/observability_solution/entity_manager/public/index.ts similarity index 61% rename from x-pack/plugins/observability_solution/asset_manager/public/index.ts rename to x-pack/plugins/observability_solution/entity_manager/public/index.ts index 7837c00909430..e17edb959595d 100644 --- a/x-pack/plugins/observability_solution/asset_manager/public/index.ts +++ b/x-pack/plugins/observability_solution/entity_manager/public/index.ts @@ -7,14 +7,14 @@ import { PluginInitializer, PluginInitializerContext } from '@kbn/core/public'; import { Plugin } from './plugin'; -import { AssetManagerPublicPluginSetup, AssetManagerPublicPluginStart } from './types'; +import { EntityManagerPublicPluginSetup, EntityManagerPublicPluginStart } from './types'; export const plugin: PluginInitializer< - AssetManagerPublicPluginSetup | undefined, - AssetManagerPublicPluginStart | undefined + EntityManagerPublicPluginSetup | undefined, + EntityManagerPublicPluginStart | undefined > = (context: PluginInitializerContext) => { return new Plugin(context); }; -export type { AssetManagerPublicPluginSetup, AssetManagerPublicPluginStart }; -export type AssetManagerAppId = 'assetManager'; +export type { EntityManagerPublicPluginSetup, EntityManagerPublicPluginStart }; +export type EntityManagerAppId = 'entityManager'; diff --git a/x-pack/plugins/observability_solution/asset_manager/public/lib/entity_client.ts b/x-pack/plugins/observability_solution/entity_manager/public/lib/entity_client.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/public/lib/entity_client.ts rename to x-pack/plugins/observability_solution/entity_manager/public/lib/entity_client.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/public/plugin.ts b/x-pack/plugins/observability_solution/entity_manager/public/plugin.ts similarity index 51% rename from x-pack/plugins/observability_solution/asset_manager/public/plugin.ts rename to x-pack/plugins/observability_solution/entity_manager/public/plugin.ts index 8c3dd9115c1ef..0de83b4252b62 100644 --- a/x-pack/plugins/observability_solution/asset_manager/public/plugin.ts +++ b/x-pack/plugins/observability_solution/entity_manager/public/plugin.ts @@ -8,13 +8,12 @@ import { CoreSetup, CoreStart, PluginInitializerContext } from '@kbn/core/public'; import { Logger } from '@kbn/logging'; -import { AssetManagerPluginClass } from './types'; -import { PublicAssetsClient } from './lib/public_assets_client'; -import type { AssetManagerPublicConfig } from '../common/config'; +import { EntityManagerPluginClass } from './types'; +import type { EntityManagerPublicConfig } from '../common/config'; import { EntityClient } from './lib/entity_client'; -export class Plugin implements AssetManagerPluginClass { - public config: AssetManagerPublicConfig; +export class Plugin implements EntityManagerPluginClass { + public config: EntityManagerPublicConfig; public logger: Logger; constructor(context: PluginInitializerContext<{}>) { @@ -23,32 +22,15 @@ export class Plugin implements AssetManagerPluginClass { } setup(core: CoreSetup) { - // Check for config value and bail out if not "alpha-enabled" - if (!this.config.alphaEnabled) { - this.logger.debug('Public is NOT enabled'); - return; - } - - this.logger.debug('Public is enabled'); - - const publicAssetsClient = new PublicAssetsClient(core.http); const entityClient = new EntityClient(core.http); return { - publicAssetsClient, entityClient, }; } start(core: CoreStart) { - // Check for config value and bail out if not "alpha-enabled" - if (!this.config.alphaEnabled) { - return; - } - - const publicAssetsClient = new PublicAssetsClient(core.http); const entityClient = new EntityClient(core.http); return { - publicAssetsClient, entityClient, }; } diff --git a/x-pack/plugins/observability_solution/asset_manager/public/types.ts b/x-pack/plugins/observability_solution/entity_manager/public/types.ts similarity index 59% rename from x-pack/plugins/observability_solution/asset_manager/public/types.ts rename to x-pack/plugins/observability_solution/entity_manager/public/types.ts index 8a89793e361d9..5c7ab11058d4d 100644 --- a/x-pack/plugins/observability_solution/asset_manager/public/types.ts +++ b/x-pack/plugins/observability_solution/entity_manager/public/types.ts @@ -5,33 +5,25 @@ * 2.0. */ import type { Plugin as PluginClass } from '@kbn/core/public'; -import { GetHostsOptionsPublic } from '../common/types_client'; import { DisableManagedEntityResponse, EnableManagedEntityResponse, - GetHostAssetsResponse, ManagedEntityEnabledResponse, } from '../common/types_api'; -export interface AssetManagerPublicPluginSetup { - publicAssetsClient: IPublicAssetsClient; +export interface EntityManagerPublicPluginSetup { entityClient: IEntityClient; } -export interface AssetManagerPublicPluginStart { - publicAssetsClient: IPublicAssetsClient; +export interface EntityManagerPublicPluginStart { entityClient: IEntityClient; } -export type AssetManagerPluginClass = PluginClass< - AssetManagerPublicPluginSetup | undefined, - AssetManagerPublicPluginStart | undefined +export type EntityManagerPluginClass = PluginClass< + EntityManagerPublicPluginSetup | undefined, + EntityManagerPublicPluginStart | undefined >; -export interface IPublicAssetsClient { - getHosts: (options: GetHostsOptionsPublic) => Promise; -} - export interface IEntityClient { isManagedEntityDiscoveryEnabled: () => Promise; enableManagedEntityDiscovery: () => Promise; diff --git a/x-pack/plugins/observability_solution/entity_manager/server/index.ts b/x-pack/plugins/observability_solution/entity_manager/server/index.ts new file mode 100644 index 0000000000000..172b22b588f58 --- /dev/null +++ b/x-pack/plugins/observability_solution/entity_manager/server/index.ts @@ -0,0 +1,18 @@ +/* + * 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 { PluginInitializerContext } from '@kbn/core-plugins-server'; +import { EntityManagerConfig } from '../common/config'; +import { EntityManagerServerPluginSetup, EntityManagerServerPluginStart, config } from './plugin'; + +export type { EntityManagerConfig, EntityManagerServerPluginSetup, EntityManagerServerPluginStart }; +export { config }; + +export const plugin = async (context: PluginInitializerContext) => { + const { EntityManagerServerPlugin } = await import('./plugin'); + return new EntityManagerServerPlugin(context); +}; diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts similarity index 92% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts index ecd73b643176e..5d48ff6e36f0d 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts @@ -7,7 +7,7 @@ import { KibanaRequest } from '@kbn/core-http-server'; import { getFakeKibanaRequest } from '@kbn/security-plugin/server/authentication/api_keys/fake_kibana_request'; -import { AssetManagerServerSetup } from '../../../types'; +import { EntityManagerServerSetup } from '../../../types'; import { canRunEntityDiscovery, requiredRunTimePrivileges } from '../privileges'; export interface EntityDiscoveryAPIKey { @@ -17,13 +17,13 @@ export interface EntityDiscoveryAPIKey { } export const checkIfAPIKeysAreEnabled = async ( - server: AssetManagerServerSetup + server: EntityManagerServerSetup ): Promise => { return await server.security.authc.apiKeys.areAPIKeysEnabled(); }; export const checkIfEntityDiscoveryAPIKeyIsValid = async ( - server: AssetManagerServerSetup, + server: EntityManagerServerSetup, apiKey: EntityDiscoveryAPIKey ): Promise => { server.logger.debug('validating API key against authentication service'); @@ -49,7 +49,7 @@ export const checkIfEntityDiscoveryAPIKeyIsValid = async ( }; export const generateEntityDiscoveryAPIKey = async ( - server: AssetManagerServerSetup, + server: EntityManagerServerSetup, req: KibanaRequest ): Promise => { const apiKey = await server.security.authc.apiKeys.grantAsInternalUser(req, { diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/saved_object.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/saved_object.ts similarity index 87% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/saved_object.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/saved_object.ts index 481efc60721a6..5bd5004f1b9bc 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/saved_object.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/saved_object.ts @@ -7,18 +7,18 @@ import { SavedObjectsErrorHelpers, SavedObjectsClientContract } from '@kbn/core/server'; import { EntityDiscoveryApiKeyType } from '../../../saved_objects'; -import { AssetManagerServerSetup } from '../../../types'; +import { EntityManagerServerSetup } from '../../../types'; import { EntityDiscoveryAPIKey } from './api_key'; const ENTITY_DISCOVERY_API_KEY_SO_ID = '19540C97-E35C-485B-8566-FB86EC8455E4'; -const getEncryptedSOClient = (server: AssetManagerServerSetup) => { +const getEncryptedSOClient = (server: EntityManagerServerSetup) => { return server.encryptedSavedObjects.getClient({ includedHiddenTypes: [EntityDiscoveryApiKeyType.name], }); }; -export const readEntityDiscoveryAPIKey = async (server: AssetManagerServerSetup) => { +export const readEntityDiscoveryAPIKey = async (server: EntityManagerServerSetup) => { try { const soClient = getEncryptedSOClient(server); const obj = await soClient.getDecryptedAsInternalUser( diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/index.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/index.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/auth/index.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/auth/index.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/privileges.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/auth/privileges.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/auth/privileges.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/constants.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/constants.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/constants.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/constants.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/index.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/index.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/index.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/index.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/services.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts similarity index 96% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/services.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts index 916fef586e4d5..5fa34635f9a46 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/built_in/services.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts @@ -13,7 +13,7 @@ export const builtInServicesEntityDefinition: EntityDefinition = entityDefinitio name: 'Services from logs', type: 'service', managed: true, - indexPatterns: ['logs-*', 'filebeat*'], + indexPatterns: ['logs-*', 'filebeat*', 'remote_cluster:logs-*'], history: { timestampField: '@timestamp', interval: '1m', diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/create_and_install_ingest_pipeline.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/create_and_install_ingest_pipeline.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/create_and_install_ingest_pipeline.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/create_and_install_ingest_pipeline.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/create_and_install_transform.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/create_and_install_transform.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/create_and_install_transform.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/create_and_install_transform.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_index.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_index.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_index.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_index.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_ingest_pipeline.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_ingest_pipeline.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/delete_ingest_pipeline.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/delete_ingest_pipeline.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_id_conflict_error.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_id_conflict_error.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_id_conflict_error.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_id_conflict_error.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_not_found.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_not_found.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_not_found.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_not_found.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_security_exception.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_security_exception.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/entity_security_exception.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/entity_security_exception.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/invalid_transform_error.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/invalid_transform_error.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/errors/invalid_transform_error.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/errors/invalid_transform_error.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/find_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/find_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/find_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/find_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/fixtures/entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/fixtures/entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/fixtures/entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/fixtures/entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/generate_index_name.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/generate_index_name.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/generate_index_name.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/generate_index_name.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/get_elasticsearch_query_or_throw.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/get_elasticsearch_query_or_throw.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/get_elasticsearch_query_or_throw.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/get_elasticsearch_query_or_throw.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/retry.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/retry.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/helpers/retry.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/helpers/retry.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_history_processors.test.ts.snap diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/__snapshots__/generate_latest_processors.test.ts.snap diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_ingest_pipeline_id.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_ingest_pipeline_id.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_ingest_pipeline_id.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_ingest_pipeline_id.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_processors.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.test.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_processors.test.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.test.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_history_processors.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_ingest_pipeline_id.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_ingest_pipeline_id.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_ingest_pipeline_id.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_ingest_pipeline_id.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.test.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.test.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.test.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/ingest_pipeline/generate_latest_processors.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/install_entity_definition.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/install_entity_definition.test.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.test.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/install_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/install_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/install_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/read_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/read_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/read_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/read_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/save_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/save_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/save_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/save_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/start_transform.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/start_transform.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/start_transform.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/start_transform.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/stop_and_delete_transform.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/stop_and_delete_transform.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/stop_and_delete_transform.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/stop_and_delete_transform.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/__snapshots__/generate_history_transform.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/__snapshots__/generate_history_transform.test.ts.snap similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/__snapshots__/generate_history_transform.test.ts.snap rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/__snapshots__/generate_history_transform.test.ts.snap diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/__snapshots__/generate_latest_transform.test.ts.snap b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/__snapshots__/generate_latest_transform.test.ts.snap similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/__snapshots__/generate_latest_transform.test.ts.snap rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/__snapshots__/generate_latest_transform.test.ts.snap diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform.test.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform.test.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform.test.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform_id.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform_id.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_history_transform_id.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_history_transform_id.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform.test.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform.test.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform.test.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform.test.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform_id.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform_id.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_latest_transform_id.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_latest_transform_id.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_metadata_aggregations.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_metadata_aggregations.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_metadata_aggregations.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_metadata_aggregations.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_metric_aggregations.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_metric_aggregations.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/transform/generate_metric_aggregations.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/transform/generate_metric_aggregations.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/entities/uninstall_entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/entities/uninstall_entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/entities/uninstall_entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/errors.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/errors.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/errors.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/errors.ts diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts new file mode 100644 index 0000000000000..f3591d82e0d25 --- /dev/null +++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/manage_index_templates.ts @@ -0,0 +1,52 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + ClusterPutComponentTemplateRequest, + IndicesPutIndexTemplateRequest, +} from '@elastic/elasticsearch/lib/api/types'; +import { ElasticsearchClient, Logger } from '@kbn/core/server'; + +interface TemplateManagementOptions { + esClient: ElasticsearchClient; + template: IndicesPutIndexTemplateRequest; + logger: Logger; +} + +interface ComponentManagementOptions { + esClient: ElasticsearchClient; + component: ClusterPutComponentTemplateRequest; + logger: Logger; +} + +export async function upsertTemplate({ esClient, template, logger }: TemplateManagementOptions) { + try { + await esClient.indices.putIndexTemplate(template); + } catch (error: any) { + logger.error(`Error updating entity manager index template: ${error.message}`); + return; + } + + logger.info( + `Entity manager index template is up to date (use debug logging to see what was installed)` + ); + logger.debug(`Entity manager index template: ${JSON.stringify(template)}`); +} + +export async function upsertComponent({ esClient, component, logger }: ComponentManagementOptions) { + try { + await esClient.cluster.putComponentTemplate(component); + } catch (error: any) { + logger.error(`Error updating entity manager component template: ${error.message}`); + return; + } + + logger.info( + `Entity manager component template is up to date (use debug logging to see what was installed)` + ); + logger.debug(`Entity manager component template: ${JSON.stringify(component)}`); +} diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/utils.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/utils.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/utils.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/utils.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/validators/validate_date_range.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/validators/validate_date_range.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/validators/validate_date_range.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/validators/validate_date_range.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/lib/validators/validation_error.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/validators/validation_error.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/lib/validators/validation_error.ts rename to x-pack/plugins/observability_solution/entity_manager/server/lib/validators/validation_error.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/plugin.ts b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts similarity index 59% rename from x-pack/plugins/observability_solution/asset_manager/server/plugin.ts rename to x-pack/plugins/observability_solution/entity_manager/server/plugin.ts index 46cfa228fde1a..7bc6a21a0f4f9 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/plugin.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts @@ -16,55 +16,45 @@ import { } from '@kbn/core/server'; import { upsertComponent, upsertTemplate } from './lib/manage_index_templates'; import { setupRoutes } from './routes'; -import { assetsIndexTemplateConfig } from './templates/assets_template'; -import { AssetClient } from './lib/asset_client'; import { - AssetManagerPluginSetupDependencies, - AssetManagerPluginStartDependencies, - AssetManagerServerSetup, + EntityManagerPluginSetupDependencies, + EntityManagerPluginStartDependencies, + EntityManagerServerSetup, } from './types'; -import { AssetManagerConfig, configSchema, exposeToBrowserConfig } from '../common/config'; +import { EntityManagerConfig, configSchema, exposeToBrowserConfig } from '../common/config'; import { entitiesBaseComponentTemplateConfig } from './templates/components/base'; import { entitiesEventComponentTemplateConfig } from './templates/components/event'; import { entitiesIndexTemplateConfig } from './templates/entities_template'; import { entityDefinition, EntityDiscoveryApiKeyType } from './saved_objects'; import { entitiesEntityComponentTemplateConfig } from './templates/components/entity'; -export type AssetManagerServerPluginSetup = ReturnType; -export type AssetManagerServerPluginStart = ReturnType; +export type EntityManagerServerPluginSetup = ReturnType; +export type EntityManagerServerPluginStart = ReturnType; -export const config: PluginConfigDescriptor = { +export const config: PluginConfigDescriptor = { schema: configSchema, exposeToBrowser: exposeToBrowserConfig, }; -export class AssetManagerServerPlugin +export class EntityManagerServerPlugin implements Plugin< - AssetManagerServerPluginSetup, - AssetManagerServerPluginStart, - AssetManagerPluginSetupDependencies, - AssetManagerPluginStartDependencies + EntityManagerServerPluginSetup, + EntityManagerServerPluginStart, + EntityManagerPluginSetupDependencies, + EntityManagerPluginStartDependencies > { - public config: AssetManagerConfig; + public config: EntityManagerConfig; public logger: Logger; - public server?: AssetManagerServerSetup; + public server?: EntityManagerServerSetup; - constructor(context: PluginInitializerContext) { + constructor(context: PluginInitializerContext) { this.config = context.config.get(); this.logger = context.logger.get(); } - public setup(core: CoreSetup, plugins: AssetManagerPluginSetupDependencies) { - // Check for config value and bail out if not "alpha-enabled" - if (!this.config.alphaEnabled) { - this.logger.info('Server is NOT enabled'); - return; - } - - this.logger.info('Server is enabled'); - + public setup(core: CoreSetup, plugins: EntityManagerPluginSetupDependencies) { core.savedObjects.registerType(entityDefinition); core.savedObjects.registerType(EntityDiscoveryApiKeyType); plugins.encryptedSavedObjects.registerType({ @@ -73,38 +63,24 @@ export class AssetManagerServerPlugin attributesToIncludeInAAD: new Set(['id', 'name']), }); - const assetClient = new AssetClient({ - sourceIndices: this.config.sourceIndices, - getApmIndices: plugins.apmDataAccess.getApmIndices, - metricsClient: plugins.metricsDataAccess.client, - }); - const router = core.http.createRouter(); this.server = { config: this.config, logger: this.logger, - } as AssetManagerServerSetup; + } as EntityManagerServerSetup; setupRoutes({ router, - assetClient, logger: this.logger, spaces: plugins.spaces, server: this.server, }); - return { - assetClient, - }; + return {}; } - public start(core: CoreStart, plugins: AssetManagerPluginStartDependencies) { - // Check for config value and bail out if not "alpha-enabled" - if (!this.config.alphaEnabled) { - return; - } - + public start(core: CoreStart, plugins: EntityManagerPluginStartDependencies) { if (this.server) { this.server.core = core; this.server.isServerless = core.elasticsearch.getCapabilities().serverless; @@ -113,11 +89,6 @@ export class AssetManagerServerPlugin } const esClient = core.elasticsearch.client.asInternalUser; - upsertTemplate({ - esClient, - template: assetsIndexTemplateConfig, - logger: this.logger, - }).catch(() => {}); // it shouldn't reject, but just in case // Install entities compoent templates and index template Promise.all([ diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/check.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/check.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/check.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/check.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/entities/create.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/entities/create.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/entities/create.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/entities/delete.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/entities/delete.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/entities/delete.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/entities/get.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/entities/get.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/entities/get.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/entities/reset.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/entities/reset.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/entities/reset.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/index.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/index.ts similarity index 72% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/index.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/index.ts index 67e6df7dff41b..1ee71ebd197df 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/index.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/index.ts @@ -8,12 +8,6 @@ import { RequestHandlerContext } from '@kbn/core/server'; import { SetupRouteOptions } from './types'; import { pingRoute } from './ping'; -import { sampleAssetsRoutes } from './sample_assets'; -import { assetsRoutes } from './assets'; -import { hostsRoutes } from './assets/hosts'; -import { servicesRoutes } from './assets/services'; -import { containersRoutes } from './assets/containers'; -import { podsRoutes } from './assets/pods'; import { createEntityDefinitionRoute } from './entities/create'; import { deleteEntityDefinitionRoute } from './entities/delete'; import { resetEntityDefinitionRoute } from './entities/reset'; @@ -24,12 +18,6 @@ import { disableEntityDiscoveryRoute } from './enablement/disable'; export function setupRoutes(dependencies: SetupRouteOptions) { pingRoute(dependencies); - sampleAssetsRoutes(dependencies); - assetsRoutes(dependencies); - hostsRoutes(dependencies); - servicesRoutes(dependencies); - containersRoutes(dependencies); - podsRoutes(dependencies); createEntityDefinitionRoute(dependencies); deleteEntityDefinitionRoute(dependencies); resetEntityDefinitionRoute(dependencies); diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/ping.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/ping.ts similarity index 79% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/ping.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/ping.ts index 3d7a20b5fd476..c5f6f65a49a52 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/ping.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/ping.ts @@ -6,18 +6,18 @@ */ import { RequestHandlerContextBase } from '@kbn/core-http-server'; -import { ASSET_MANAGER_API_BASE } from '../../common/constants_routes'; +import { ENTITY_API_PREFIX } from '../../common/constants_entities'; import { SetupRouteOptions } from './types'; export function pingRoute({ router }: SetupRouteOptions) { router.get( { - path: `${ASSET_MANAGER_API_BASE}/ping`, + path: `${ENTITY_API_PREFIX}/ping`, validate: false, }, async (_context, _req, res) => { return res.ok({ - body: { message: 'Asset Manager OK' }, + body: { message: 'Entity Manager OK' }, headers: { 'content-type': 'application/json' }, }); } diff --git a/x-pack/plugins/observability_solution/asset_manager/server/routes/types.ts b/x-pack/plugins/observability_solution/entity_manager/server/routes/types.ts similarity index 77% rename from x-pack/plugins/observability_solution/asset_manager/server/routes/types.ts rename to x-pack/plugins/observability_solution/entity_manager/server/routes/types.ts index 72cb202de2af3..e5c11777a57de 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/routes/types.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/routes/types.ts @@ -8,13 +8,11 @@ import { IRouter, RequestHandlerContextBase } from '@kbn/core-http-server'; import { Logger } from '@kbn/core/server'; import { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; -import { AssetClient } from '../lib/asset_client'; -import { AssetManagerServerSetup } from '../types'; +import { EntityManagerServerSetup } from '../types'; export interface SetupRouteOptions { router: IRouter; - server: AssetManagerServerSetup; - assetClient: AssetClient; + server: EntityManagerServerSetup; logger: Logger; spaces?: SpacesPluginSetup; } diff --git a/x-pack/plugins/observability_solution/asset_manager/server/saved_objects/entity_definition.ts b/x-pack/plugins/observability_solution/entity_manager/server/saved_objects/entity_definition.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/saved_objects/entity_definition.ts rename to x-pack/plugins/observability_solution/entity_manager/server/saved_objects/entity_definition.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/saved_objects/entity_discovery_api_key.ts b/x-pack/plugins/observability_solution/entity_manager/server/saved_objects/entity_discovery_api_key.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/saved_objects/entity_discovery_api_key.ts rename to x-pack/plugins/observability_solution/entity_manager/server/saved_objects/entity_discovery_api_key.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/saved_objects/index.ts b/x-pack/plugins/observability_solution/entity_manager/server/saved_objects/index.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/saved_objects/index.ts rename to x-pack/plugins/observability_solution/entity_manager/server/saved_objects/index.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/templates/components/base.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/base.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/templates/components/base.ts rename to x-pack/plugins/observability_solution/entity_manager/server/templates/components/base.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/templates/components/entity.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/entity.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/templates/components/entity.ts rename to x-pack/plugins/observability_solution/entity_manager/server/templates/components/entity.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/templates/components/event.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/components/event.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/templates/components/event.ts rename to x-pack/plugins/observability_solution/entity_manager/server/templates/components/event.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/templates/entities_template.ts b/x-pack/plugins/observability_solution/entity_manager/server/templates/entities_template.ts similarity index 100% rename from x-pack/plugins/observability_solution/asset_manager/server/templates/entities_template.ts rename to x-pack/plugins/observability_solution/entity_manager/server/templates/entities_template.ts diff --git a/x-pack/plugins/observability_solution/asset_manager/server/types.ts b/x-pack/plugins/observability_solution/entity_manager/server/types.ts similarity index 61% rename from x-pack/plugins/observability_solution/asset_manager/server/types.ts rename to x-pack/plugins/observability_solution/entity_manager/server/types.ts index 9df0485f31291..505f44eccf3ff 100644 --- a/x-pack/plugins/observability_solution/asset_manager/server/types.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/types.ts @@ -6,25 +6,18 @@ */ import { CoreStart, ElasticsearchClient, Logger } from '@kbn/core/server'; -import { - ApmDataAccessPluginSetup, - ApmDataAccessPluginStart, -} from '@kbn/apm-data-access-plugin/server'; -import { MetricsDataPluginSetup } from '@kbn/metrics-data-access-plugin/server'; import { SecurityPluginStart } from '@kbn/security-plugin/server'; import { EncryptedSavedObjectsPluginSetup, EncryptedSavedObjectsPluginStart, } from '@kbn/encrypted-saved-objects-plugin/server'; import { SpacesPluginSetup } from '@kbn/spaces-plugin/server'; -import { AssetClient } from './lib/asset_client'; -import { AssetManagerConfig } from '../common/config'; +import { EntityManagerConfig } from '../common/config'; -export interface AssetManagerServerSetup { +export interface EntityManagerServerSetup { core: CoreStart; - config: AssetManagerConfig; + config: EntityManagerConfig; logger: Logger; - assetClient: AssetClient; security: SecurityPluginStart; encryptedSavedObjects: EncryptedSavedObjectsPluginStart; isServerless: boolean; @@ -34,14 +27,12 @@ export interface ElasticsearchAccessorOptions { elasticsearchClient: ElasticsearchClient; } -export interface AssetManagerPluginSetupDependencies { - apmDataAccess: ApmDataAccessPluginSetup; - metricsDataAccess: MetricsDataPluginSetup; +export interface EntityManagerPluginSetupDependencies { encryptedSavedObjects: EncryptedSavedObjectsPluginSetup; spaces?: SpacesPluginSetup; } -export interface AssetManagerPluginStartDependencies { - apmDataAccess: ApmDataAccessPluginStart; + +export interface EntityManagerPluginStartDependencies { security: SecurityPluginStart; encryptedSavedObjects: EncryptedSavedObjectsPluginStart; } diff --git a/x-pack/plugins/observability_solution/asset_manager/tsconfig.json b/x-pack/plugins/observability_solution/entity_manager/tsconfig.json similarity index 81% rename from x-pack/plugins/observability_solution/asset_manager/tsconfig.json rename to x-pack/plugins/observability_solution/entity_manager/tsconfig.json index c153938f4b33e..176494e26e600 100644 --- a/x-pack/plugins/observability_solution/asset_manager/tsconfig.json +++ b/x-pack/plugins/observability_solution/entity_manager/tsconfig.json @@ -17,13 +17,8 @@ "@kbn/config-schema", "@kbn/core-http-server", "@kbn/core-elasticsearch-client-server-mocks", - "@kbn/io-ts-utils", - "@kbn/core-http-request-handler-context-server", "@kbn/datemath", - "@kbn/apm-data-access-plugin", - "@kbn/core-http-browser-mocks", "@kbn/logging", - "@kbn/metrics-data-access-plugin", "@kbn/core-elasticsearch-server", "@kbn/core-saved-objects-api-server", "@kbn/core-saved-objects-api-server-mocks", diff --git a/x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts b/x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts deleted file mode 100644 index af9d3d0d206a4..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts +++ /dev/null @@ -1,17 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { FtrConfigProviderContext } from '@kbn/test'; - -export default async function ({ readConfigFile }: FtrConfigProviderContext) { - const baseIntegrationTestsConfig = await readConfigFile(require.resolve('../../config.ts')); - - return { - ...baseIntegrationTestsConfig.getAll(), - testFiles: [require.resolve('./tests/when_disabled.ts')], - }; -} diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/basics.ts b/x-pack/test/api_integration/apis/asset_manager/tests/basics.ts deleted file mode 100644 index d0d44b88f68c1..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/basics.ts +++ /dev/null @@ -1,29 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const esSupertest = getService('esSupertest'); - - describe('during basic startup', () => { - describe('ping endpoint', () => { - it('returns a successful response', async () => { - const response = await supertest.get('/api/asset-manager/ping').expect(200); - expect(response.body).to.eql({ message: 'Asset Manager OK' }); - }); - }); - - describe('assets index templates', () => { - it('should always be installed', async () => { - await esSupertest.get('/_index_template/assets').expect(200); - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/constants.ts b/x-pack/test/api_integration/apis/asset_manager/tests/constants.ts deleted file mode 100644 index e71ee4fa7f49a..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/constants.ts +++ /dev/null @@ -1,8 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const ASSETS_ENDPOINT = '/api/asset-manager/assets'; diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/helpers.ts b/x-pack/test/api_integration/apis/asset_manager/tests/helpers.ts deleted file mode 100644 index 94ab2f5b99ffe..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/helpers.ts +++ /dev/null @@ -1,104 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { AssetWithoutTimestamp } from '@kbn/assetManager-plugin/common/types_api'; -import type { WriteSamplesPostBody } from '@kbn/assetManager-plugin/server'; -import { apm, infra, timerange } from '@kbn/apm-synthtrace-client'; -import expect from '@kbn/expect'; -import { Agent as SuperTestAgent } from 'supertest'; - -const SAMPLE_ASSETS_ENDPOINT = '/api/asset-manager/assets/sample'; - -export type KibanaSupertest = SuperTestAgent; - -// NOTE: In almost every case in tests, you want { refresh: true } -// in the options of this function, so it is defaulted to that value. -// Otherwise, it's likely whatever action you are testing after you -// create the sample asset docs will fail to find them. -// This refresh key passes through to the underlying ES -// query via the refresh option, see: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html -export async function createSampleAssets( - supertest: KibanaSupertest, - options: WriteSamplesPostBody = {} -) { - if (options === null) { - options = {}; - } - if (!('refresh' in options)) { - options.refresh = true; - } - return supertest.post(SAMPLE_ASSETS_ENDPOINT).set('kbn-xsrf', 'xxx').send(options).expect(200); -} - -export async function deleteSampleAssets(supertest: KibanaSupertest) { - return await supertest.delete(SAMPLE_ASSETS_ENDPOINT).set('kbn-xsrf', 'xxx').expect(200); -} - -export async function viewSampleAssetDocs(supertest: KibanaSupertest) { - const response = await supertest.get(SAMPLE_ASSETS_ENDPOINT).expect(200); - expect(response).to.have.property('body'); - expect(response.body).to.have.property('results'); - return response.body.results as AssetWithoutTimestamp[]; -} - -export function generateServicesData({ - from, - to, - count = 1, -}: { - from: string; - to: string; - count: number; -}) { - const range = timerange(from, to); - - const services = Array(count) - .fill(0) - .map((_, idx) => - apm - .service({ - name: `service-${idx}`, - environment: 'production', - agentName: 'nodejs', - }) - .instance(`my-host-${idx}`) - ); - - return range - .interval('1m') - .rate(1) - .generator((timestamp, index) => - services.map((service) => - service - .transaction({ transactionName: 'GET /foo' }) - .timestamp(timestamp) - .duration(500) - .success() - ) - ); -} - -export function generateHostsData({ - from, - to, - count = 1, -}: { - from: string; - to: string; - count: number; -}) { - const range = timerange(from, to); - - const hosts = Array(count) - .fill(0) - .map((_, idx) => infra.host(`my-host-${idx}`)); - - return range - .interval('1m') - .rate(1) - .generator((timestamp, index) => hosts.map((host) => host.cpu().timestamp(timestamp))); -} diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/index.ts b/x-pack/test/api_integration/apis/asset_manager/tests/index.ts deleted file mode 100644 index e32e37c8ac020..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/index.ts +++ /dev/null @@ -1,14 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ loadTestFile }: FtrProviderContext) { - describe('Asset Manager API Endpoints', () => { - loadTestFile(require.resolve('./basics')); - loadTestFile(require.resolve('./sample_assets')); - }); -} diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/sample_assets.ts b/x-pack/test/api_integration/apis/asset_manager/tests/sample_assets.ts deleted file mode 100644 index a9e7ebab188e8..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/sample_assets.ts +++ /dev/null @@ -1,162 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { Asset } from '@kbn/assetManager-plugin/common/types_api'; -import expect from '@kbn/expect'; -import { FtrProviderContext } from '../../../ftr_provider_context'; -import { createSampleAssets, deleteSampleAssets, viewSampleAssetDocs } from './helpers'; - -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const esSupertest = getService('esSupertest'); - - async function countSampleDocs() { - const sampleAssetDocs = await viewSampleAssetDocs(supertest); - return sampleAssetDocs.length; - } - - // This function performs the direct ES search using esSupertest, - // so we don't use the assets API to test the assets API - interface SearchESForAssetsOptions { - size?: number; - from?: string; - to?: string; - } - async function searchESForSampleAssets({ - size = 0, - from = 'now-24h', - to = 'now', - }: SearchESForAssetsOptions = {}) { - const queryPostBody = { - size, - query: { - range: { - '@timestamp': { - gte: from, - lte: to, - }, - }, - }, - }; - - return await esSupertest.post('/assets-*-sample_data/_search').send(queryPostBody).expect(200); - } - - describe('Sample Assets API', () => { - // Clear out the asset indices before each test - beforeEach(async () => { - await deleteSampleAssets(supertest); - }); - - // Clear out the asset indices one last time after the last test - after(async () => { - await deleteSampleAssets(supertest); - }); - - it('should return the sample asset documents', async () => { - const sampleAssetDocs = await viewSampleAssetDocs(supertest); - expect(sampleAssetDocs.length).to.be.greaterThan(0); - }); - - it('should find no sample assets in ES at first', async () => { - const initialResponse = await searchESForSampleAssets(); - expect(initialResponse.body.hits?.total?.value).to.equal(0); - }); - - it('should successfully create sample assets', async () => { - const nSampleDocs = await countSampleDocs(); - - const postResponse = await createSampleAssets(supertest, { refresh: true }); - expect(postResponse.status).to.equal(200); - expect(postResponse.body?.items?.length).to.equal(nSampleDocs); - - // using 'within the past 5 minutes' to approximate whatever the 'now' time was plus query and test lag - const searchResponse = await searchESForSampleAssets({ from: 'now-5m' }); - - expect(searchResponse.body.hits?.total?.value).to.equal(nSampleDocs); - }); - - it('should delete all sample data', async () => { - const nSampleDocs = await countSampleDocs(); - await createSampleAssets(supertest, { refresh: true }); - - const responseBeforeDelete = await searchESForSampleAssets(); - expect(responseBeforeDelete.body.hits?.total?.value).to.equal(nSampleDocs); - - await deleteSampleAssets(supertest); - - const responseAfterDelete = await searchESForSampleAssets(); - expect(responseAfterDelete.body.hits?.total?.value).to.equal(0); - }); - - it('should create sample data with a timestamp in the past', async () => { - const nSampleDocs = await countSampleDocs(); - - // Create sample documents dated three days prior to now - const now = new Date(); - const threeDaysAgo = new Date(now.getTime() - 1000 * 60 * 60 * 24 * 3); - const response = await createSampleAssets(supertest, { - refresh: true, - baseDateTime: threeDaysAgo.toISOString(), - }); - - // Expect that all of the sample docs have been indexed - expect(response.body?.items?.length).to.equal(nSampleDocs); - - // Searching only within the past day, we don't expect to find any of the asset documents - const oneDayAgoResponse = await searchESForSampleAssets({ size: 1, from: 'now-1d' }); - expect(oneDayAgoResponse.body.hits?.total?.value).to.equal(0); - - // Searching within the past 5 days, we should find all of the asset documents - const fiveDaysAgoResponse = await searchESForSampleAssets({ from: 'now-5d' }); - expect(fiveDaysAgoResponse.body.hits?.total?.value).to.equal(nSampleDocs); - }); - - it('should create sample data but exclude some documents via provided Elastic Asset Name values', async () => { - const sampleAssetDocs = await viewSampleAssetDocs(supertest); - const nSampleDocs = sampleAssetDocs.length; - - // We will remove the first and the last sample document, just for a test. - // Note: This test will continue to work without any hard-coded EAN values, and - // regardless of how those EAN values may change or expand. - const first = sampleAssetDocs.shift(); - const last = sampleAssetDocs.pop(); - const included = sampleAssetDocs.map((doc) => doc['asset.ean']); - - if (!first || !last) { - throw new Error('Sample asset documents were incorrectly returned'); - } - - const excluded = [first['asset.ean'], last['asset.ean']]; - const createResponse = await createSampleAssets(supertest, { - refresh: true, - excludeEans: excluded, - }); - - // We expect the created response should reference all sample docs, minus the 2 we excluded - expect(createResponse.body.items.length).to.equal(nSampleDocs - 2); - - // In Elasticsearch, we should also find 2 less asset documents than the total sample docs - const searchResponse = await searchESForSampleAssets({ size: nSampleDocs }); - expect(searchResponse.body.hits?.total?.value).to.equal(nSampleDocs - 2); - - // Lastly, we should confirm that the EAN values found in the sample docs are all - // included in the asset documents returned from ES, minus the two we excluded - const returnedAssetEans = searchResponse.body.hits.hits.map( - (doc: { _source: Asset }) => doc._source['asset.ean'] - ); - - included.forEach((ean) => { - expect(returnedAssetEans).to.contain(ean); - }); - - excluded.forEach((ean) => { - expect(returnedAssetEans).to.not.contain(ean); - }); - }); - }); -} diff --git a/x-pack/test/api_integration/apis/asset_manager/tests/when_disabled.ts b/x-pack/test/api_integration/apis/asset_manager/tests/when_disabled.ts deleted file mode 100644 index d8b556a959f8d..0000000000000 --- a/x-pack/test/api_integration/apis/asset_manager/tests/when_disabled.ts +++ /dev/null @@ -1,27 +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; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { FtrProviderContext } from '../../../ftr_provider_context'; - -export default function ({ getService }: FtrProviderContext) { - const supertest = getService('supertest'); - const esSupertest = getService('esSupertest'); - - describe('Asset Manager API Endpoints - when NOT enabled', () => { - describe('basic ping endpoint', () => { - it('returns a 404 response', async () => { - await supertest.get('/api/asset-manager/ping').expect(404); - }); - }); - - describe('assets index templates', () => { - it('should not be installed', async () => { - await esSupertest.get('/_index_template/assets').expect(404); - }); - }); - }); -} diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index d7727ec005328..13e3d0634cd40 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -120,7 +120,6 @@ "@kbn/discover-plugin", "@kbn/files-plugin", "@kbn/shared-ux-file-types", - "@kbn/assetManager-plugin", "@kbn/guided-onboarding-plugin", "@kbn/field-formats-plugin", "@kbn/ml-anomaly-utils", diff --git a/yarn.lock b/yarn.lock index 7ae0cbe249d52..670d6dbca49b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3389,10 +3389,6 @@ version "0.0.0" uid "" -"@kbn/assetManager-plugin@link:x-pack/plugins/observability_solution/asset_manager": - version "0.0.0" - uid "" - "@kbn/assets-data-access-plugin@link:x-pack/plugins/observability_solution/assets_data_access": version "0.0.0" uid "" @@ -4765,6 +4761,10 @@ version "0.0.0" uid "" +"@kbn/entityManager-plugin@link:x-pack/plugins/observability_solution/entity_manager": + version "0.0.0" + uid "" + "@kbn/error-boundary-example-plugin@link:examples/error_boundary": version "0.0.0" uid "" From 032744d262d2379488cdc52a0fe65b1b08d1750f Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:03:14 +0000 Subject: [PATCH 2/9] [CI] Auto-commit changed files from 'node scripts/generate codeowners' --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a6a45a24266a8..ea7068cdee363 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -47,7 +47,6 @@ packages/kbn-apm-synthtrace-client @elastic/obs-ux-infra_services-team @elastic/ packages/kbn-apm-utils @elastic/obs-ux-infra_services-team test/plugin_functional/plugins/app_link_test @elastic/kibana-core x-pack/test/usage_collection/plugins/application_usage_test @elastic/kibana-core -x-pack/plugins/observability_solution/asset_manager @elastic/obs-knowledge-team x-pack/plugins/observability_solution/assets_data_access @elastic/obs-knowledge-team x-pack/test/security_api_integration/plugins/audit_log @elastic/kibana-security packages/kbn-axe-config @elastic/kibana-qa @@ -391,6 +390,7 @@ x-pack/examples/embedded_lens_example @elastic/kibana-visualizations x-pack/plugins/encrypted_saved_objects @elastic/kibana-security x-pack/plugins/enterprise_search @elastic/search-kibana x-pack/packages/kbn-entities-schema @elastic/obs-knowledge-team +x-pack/plugins/observability_solution/entity_manager @elastic/obs-knowledge-team examples/error_boundary @elastic/appex-sharedux packages/kbn-es @elastic/kibana-operations packages/kbn-es-archiver @elastic/kibana-operations @elastic/appex-qa From c7ffc352f1ba0439eabbc998e18ddb9392e0544c Mon Sep 17 00:00:00 2001 From: klacabane Date: Fri, 21 Jun 2024 14:31:50 +0200 Subject: [PATCH 3/9] update plugin list --- docs/developer/plugin-list.asciidoc | 8 ++++---- .../entity_manager/server/plugin.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc index fc15206bd284d..e4f161ac8f4e5 100644 --- a/docs/developer/plugin-list.asciidoc +++ b/docs/developer/plugin-list.asciidoc @@ -470,10 +470,6 @@ The plugin exposes the static DefaultEditorController class to consume. |WARNING: Missing README. -|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/asset_manager/README.md[assetManager] -|This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more. - - |{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/assets_data_access[assetsDataAccess] |WARNING: Missing README. @@ -573,6 +569,10 @@ security and spaces filtering. |This plugin provides Kibana user interfaces for managing the Enterprise Search solution and its products, App Search and Workplace Search. +|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/entity_manager/README.md[entityManager] +|This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more. + + |{kib-repo}blob/{branch}/x-pack/plugins/event_log/README.md[eventLog] |The event log plugin provides a persistent history of alerting and action activities. diff --git a/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts index 7bc6a21a0f4f9..e71f5b36bb468 100644 --- a/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/plugin.ts @@ -90,7 +90,7 @@ export class EntityManagerServerPlugin const esClient = core.elasticsearch.client.asInternalUser; - // Install entities compoent templates and index template + // Install entities component templates and index template Promise.all([ upsertComponent({ esClient, From 2c9ab6cf6ac9d93bdf78a0bca969c4531b6c59cc Mon Sep 17 00:00:00 2001 From: klacabane Date: Fri, 21 Jun 2024 14:40:05 +0200 Subject: [PATCH 4/9] remove asset_manager references --- api_docs/asset_manager.devdocs.json | 193 ------------------ api_docs/asset_manager.mdx | 44 ---- api_docs/deprecations_by_api.mdx | 4 +- api_docs/deprecations_by_plugin.mdx | 18 +- api_docs/kbn_core_http_server.devdocs.json | 66 +----- ..._security_plugin_types_server.devdocs.json | 22 +- api_docs/plugin_directory.mdx | 1 - api_docs/security.devdocs.json | 22 +- packages/kbn-optimizer/limits.yml | 1 - .../test_suites/core_plugins/rendering.ts | 1 - 10 files changed, 34 insertions(+), 338 deletions(-) delete mode 100644 api_docs/asset_manager.devdocs.json delete mode 100644 api_docs/asset_manager.mdx diff --git a/api_docs/asset_manager.devdocs.json b/api_docs/asset_manager.devdocs.json deleted file mode 100644 index cb0687b7f9922..0000000000000 --- a/api_docs/asset_manager.devdocs.json +++ /dev/null @@ -1,193 +0,0 @@ -{ - "id": "assetManager", - "client": { - "classes": [], - "functions": [], - "interfaces": [ - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginSetup", - "type": "Interface", - "tags": [], - "label": "AssetManagerPublicPluginSetup", - "description": [], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false, - "children": [ - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginSetup.publicAssetsClient", - "type": "Object", - "tags": [], - "label": "publicAssetsClient", - "description": [], - "signature": [ - "IPublicAssetsClient" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false - }, - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginSetup.entityClient", - "type": "Object", - "tags": [], - "label": "entityClient", - "description": [], - "signature": [ - "IEntityClient" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false - } - ], - "initialIsOpen": false - }, - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginStart", - "type": "Interface", - "tags": [], - "label": "AssetManagerPublicPluginStart", - "description": [], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false, - "children": [ - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginStart.publicAssetsClient", - "type": "Object", - "tags": [], - "label": "publicAssetsClient", - "description": [], - "signature": [ - "IPublicAssetsClient" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false - }, - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerPublicPluginStart.entityClient", - "type": "Object", - "tags": [], - "label": "entityClient", - "description": [], - "signature": [ - "IEntityClient" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/public/types.ts", - "deprecated": false, - "trackAdoption": false - } - ], - "initialIsOpen": false - } - ], - "enums": [], - "misc": [ - { - "parentPluginId": "assetManager", - "id": "def-public.AssetManagerAppId", - "type": "Type", - "tags": [], - "label": "AssetManagerAppId", - "description": [], - "signature": [ - "\"assetManager\"" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/public/index.ts", - "deprecated": false, - "trackAdoption": false, - "initialIsOpen": false - } - ], - "objects": [] - }, - "server": { - "classes": [], - "functions": [], - "interfaces": [], - "enums": [], - "misc": [ - { - "parentPluginId": "assetManager", - "id": "def-server.AssetManagerConfig", - "type": "Type", - "tags": [], - "label": "AssetManagerConfig", - "description": [], - "signature": [ - "{ readonly alphaEnabled?: boolean | undefined; readonly sourceIndices: Readonly<{} & { logs: string; }>; }" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/common/config.ts", - "deprecated": false, - "trackAdoption": false, - "initialIsOpen": false - }, - { - "parentPluginId": "assetManager", - "id": "def-server.WriteSamplesPostBody", - "type": "Type", - "tags": [], - "label": "WriteSamplesPostBody", - "description": [], - "signature": [ - "{ baseDateTime?: string | number | undefined; excludeEans?: string[] | undefined; refresh?: boolean | \"wait_for\" | undefined; } | null" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts", - "deprecated": false, - "trackAdoption": false, - "initialIsOpen": false - } - ], - "objects": [], - "setup": { - "parentPluginId": "assetManager", - "id": "def-server.AssetManagerServerPluginSetup", - "type": "Type", - "tags": [], - "label": "AssetManagerServerPluginSetup", - "description": [], - "signature": [ - "{ assetClient: ", - "AssetClient", - "; } | undefined" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/server/plugin.ts", - "deprecated": false, - "trackAdoption": false, - "lifecycle": "setup", - "initialIsOpen": true - }, - "start": { - "parentPluginId": "assetManager", - "id": "def-server.AssetManagerServerPluginStart", - "type": "Type", - "tags": [], - "label": "AssetManagerServerPluginStart", - "description": [], - "signature": [ - "{} | undefined" - ], - "path": "x-pack/plugins/observability_solution/asset_manager/server/plugin.ts", - "deprecated": false, - "trackAdoption": false, - "lifecycle": "start", - "initialIsOpen": true - } - }, - "common": { - "classes": [], - "functions": [], - "interfaces": [], - "enums": [], - "misc": [], - "objects": [] - } -} \ No newline at end of file diff --git a/api_docs/asset_manager.mdx b/api_docs/asset_manager.mdx deleted file mode 100644 index e06a6ada52132..0000000000000 --- a/api_docs/asset_manager.mdx +++ /dev/null @@ -1,44 +0,0 @@ ---- -#### -#### This document is auto-generated and is meant to be viewed inside our experimental, new docs system. -#### Reach out in #docs-engineering for more info. -#### -id: kibAssetManagerPluginApi -slug: /kibana-dev-docs/api/assetManager -title: "assetManager" -image: https://source.unsplash.com/400x175/?github -description: API docs for the assetManager plugin -date: 2024-06-21 -tags: ['contributor', 'dev', 'apidocs', 'kibana', 'assetManager'] ---- -import assetManagerObj from './asset_manager.devdocs.json'; - -Asset manager plugin for entity assets (inventory, topology, etc) - -Contact [@elastic/obs-knowledge-team](https://github.com/orgs/elastic/teams/obs-knowledge-team) for questions regarding this plugin. - -**Code health stats** - -| Public API count | Any count | Items lacking comments | Missing exports | -|-------------------|-----------|------------------------|-----------------| -| 11 | 0 | 11 | 3 | - -## Client - -### Interfaces - - -### Consts, variables and types - - -## Server - -### Setup - - -### Start - - -### Consts, variables and types - - diff --git a/api_docs/deprecations_by_api.mdx b/api_docs/deprecations_by_api.mdx index ed047dd05af71..00ba61db20872 100644 --- a/api_docs/deprecations_by_api.mdx +++ b/api_docs/deprecations_by_api.mdx @@ -39,7 +39,7 @@ tags: ['contributor', 'dev', 'apidocs', 'kibana'] | | securitySolution | - | | | cloudDefend, osquery, securitySolution, synthetics | - | | | cloudDefend, osquery, securitySolution, synthetics | - | -| | actions, alerting, files, cases, observabilityAIAssistant, fleet, cloudDefend, cloudSecurityPosture, elasticAssistant, enterpriseSearch, lists, osquery, securitySolution, reporting, serverlessSearch, transform, upgradeAssistant, apm, assetManager, synthetics, security | - | +| | actions, alerting, files, cases, observabilityAIAssistant, fleet, cloudDefend, cloudSecurityPosture, elasticAssistant, enterpriseSearch, lists, osquery, securitySolution, reporting, serverlessSearch, transform, upgradeAssistant, apm, entityManager, synthetics, security | - | | | cases, securitySolution, security | - | | | @kbn/securitysolution-data-table, securitySolution | - | | | @kbn/securitysolution-data-table, securitySolution | - | @@ -239,4 +239,4 @@ Safe to remove. | | @kbn/core-saved-objects-api-browser | | | @kbn/storybook | | | @kbn/ui-theme | -| | @kbn/ui-theme | \ No newline at end of file +| | @kbn/ui-theme | diff --git a/api_docs/deprecations_by_plugin.mdx b/api_docs/deprecations_by_plugin.mdx index b35b4095cc978..48335e8532631 100644 --- a/api_docs/deprecations_by_plugin.mdx +++ b/api_docs/deprecations_by_plugin.mdx @@ -511,14 +511,6 @@ tags: ['contributor', 'dev', 'apidocs', 'kibana'] -## assetManager - -| Deprecated API | Reference location(s) | Remove By | -| ---------------|-----------|-----------| -| | [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [enable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts#:~:text=authc), [disable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [enable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts#:~:text=authc), [disable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts#:~:text=authc) | - | - - - ## canvas | Deprecated API | Reference location(s) | Remove By | @@ -786,6 +778,14 @@ tags: ['contributor', 'dev', 'apidocs', 'kibana'] +## entityManager + +| Deprecated API | Reference location(s) | Remove By | +| ---------------|-----------|-----------| +| | [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [enable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts#:~:text=authc), [disable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [api_key.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts#:~:text=authc), [enable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts#:~:text=authc), [disable.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts#:~:text=authc) | - | + + + ## eventAnnotation | Deprecated API | Reference location(s) | Remove By | @@ -1644,4 +1644,4 @@ migrates to using the Kibana Privilege model: https://github.com/elastic/kibana/ | Deprecated API | Reference location(s) | Remove By | | ---------------|-----------|-----------| -| | [plugin.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/watcher/public/plugin.ts#:~:text=license%24), [plugin.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/watcher/public/plugin.ts#:~:text=license%24) | 8.8.0 | \ No newline at end of file +| | [plugin.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/watcher/public/plugin.ts#:~:text=license%24), [plugin.ts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/watcher/public/plugin.ts#:~:text=license%24) | 8.8.0 | diff --git a/api_docs/kbn_core_http_server.devdocs.json b/api_docs/kbn_core_http_server.devdocs.json index 08e97dfda981b..b7059be1d02a1 100644 --- a/api_docs/kbn_core_http_server.devdocs.json +++ b/api_docs/kbn_core_http_server.devdocs.json @@ -4730,42 +4730,6 @@ "plugin": "grokdebugger", "path": "x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts" }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/ping.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/assets/index.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/assets/hosts.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/assets/services.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/assets/containers.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/assets/pods.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/entities/get.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/check.ts" - }, { "plugin": "profiling", "path": "x-pack/plugins/observability_solution/profiling/server/routes/apm.ts" @@ -7248,18 +7212,6 @@ "plugin": "grokdebugger", "path": "x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts" }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/entities/create.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/entities/reset.ts" - }, { "plugin": "profiling", "path": "x-pack/plugins/observability_solution/profiling/server/routes/setup/route.ts" @@ -8758,10 +8710,6 @@ "plugin": "grokdebugger", "path": "x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts" }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts" - }, { "plugin": "synthetics", "path": "x-pack/plugins/observability_solution/synthetics/server/server.ts" @@ -9682,18 +9630,6 @@ "plugin": "grokdebugger", "path": "x-pack/plugins/grokdebugger/server/lib/kibana_framework.ts" }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/sample_assets.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/entities/delete.ts" - }, - { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts" - }, { "plugin": "synthetics", "path": "x-pack/plugins/observability_solution/synthetics/server/server.ts" @@ -19731,4 +19667,4 @@ } ] } -} \ No newline at end of file +} diff --git a/api_docs/kbn_security_plugin_types_server.devdocs.json b/api_docs/kbn_security_plugin_types_server.devdocs.json index 9e4605fe0085b..717a4edfcd7bc 100644 --- a/api_docs/kbn_security_plugin_types_server.devdocs.json +++ b/api_docs/kbn_security_plugin_types_server.devdocs.json @@ -3380,24 +3380,24 @@ "path": "x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts" }, { "plugin": "synthetics", @@ -4617,4 +4617,4 @@ "misc": [], "objects": [] } -} \ No newline at end of file +} diff --git a/api_docs/plugin_directory.mdx b/api_docs/plugin_directory.mdx index bcbe136208691..1b48ef5d3d876 100644 --- a/api_docs/plugin_directory.mdx +++ b/api_docs/plugin_directory.mdx @@ -34,7 +34,6 @@ tags: ['contributor', 'dev', 'apidocs', 'kibana'] | | [@elastic/response-ops](https://github.com/orgs/elastic/teams/response-ops) | - | 868 | 1 | 836 | 54 | | | [@elastic/obs-ux-infra_services-team](https://github.com/orgs/elastic/teams/obs-ux-infra_services-team) | The user interface for Elastic APM | 29 | 0 | 29 | 123 | | | [@elastic/obs-knowledge-team](https://github.com/orgs/elastic/teams/obs-knowledge-team) | - | 9 | 0 | 9 | 0 | -| | [@elastic/obs-knowledge-team](https://github.com/orgs/elastic/teams/obs-knowledge-team) | Asset manager plugin for entity assets (inventory, topology, etc) | 11 | 0 | 11 | 3 | | | [@elastic/obs-knowledge-team](https://github.com/orgs/elastic/teams/obs-knowledge-team) | - | 2 | 0 | 2 | 0 | | | [@elastic/appex-sharedux](https://github.com/orgs/elastic/teams/appex-sharedux) | - | 9 | 0 | 9 | 0 | | | [@elastic/appex-sharedux](https://github.com/orgs/elastic/teams/appex-sharedux) | Considering using bfetch capabilities when fetching large amounts of data. This services supports batching HTTP requests and streaming responses back. | 83 | 1 | 73 | 2 | diff --git a/api_docs/security.devdocs.json b/api_docs/security.devdocs.json index edcb390da545f..607fdbe830c19 100644 --- a/api_docs/security.devdocs.json +++ b/api_docs/security.devdocs.json @@ -5684,24 +5684,24 @@ "path": "x-pack/plugins/observability_solution/apm/server/routes/fleet/is_superuser.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/lib/auth/api_key/api_key.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/lib/auth/api_key/api_key.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/enable.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/enable.ts" }, { - "plugin": "assetManager", - "path": "x-pack/plugins/observability_solution/asset_manager/server/routes/enablement/disable.ts" + "plugin": "entityManager", + "path": "x-pack/plugins/observability_solution/entity_manager/server/routes/enablement/disable.ts" }, { "plugin": "synthetics", @@ -8092,4 +8092,4 @@ ], "objects": [] } -} \ No newline at end of file +} diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index c3ffc507387b8..ddd774a471136 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -5,7 +5,6 @@ pageLoadAssetSize: aiops: 10000 alerting: 106936 apm: 64385 - assetManager: 25000 banners: 17946 bfetch: 22837 canvas: 29355 diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index 5a16b46a366e2..c8234869bf805 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -220,7 +220,6 @@ export default function ({ getService }: PluginFunctionalProviderContext) { 'xpack.apm.featureFlags.storageExplorerAvailable (any)', 'xpack.apm.featureFlags.profilingIntegrationAvailable (boolean)', 'xpack.apm.serverless.enabled (any)', // It's a boolean (any because schema.conditional) - 'xpack.assetManager.alphaEnabled (boolean)', 'xpack.observability_onboarding.serverless.enabled (any)', // It's a boolean (any because schema.conditional) 'xpack.cases.files.allowedMimeTypes (array)', 'xpack.cases.files.maxSize (number)', From c80eee44c6f26dcb6d85b51a8807e56e3a8ca5f3 Mon Sep 17 00:00:00 2001 From: klacabane Date: Fri, 21 Jun 2024 15:08:40 +0200 Subject: [PATCH 5/9] update-limits --- packages/kbn-optimizer/limits.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index ddd774a471136..3e6e250753037 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -41,6 +41,7 @@ pageLoadAssetSize: embeddable: 87309 embeddableEnhanced: 22107 enterpriseSearch: 66810 + entityManager: 17175 esqlDataGrid: 24582 esUiShared: 326654 eventAnnotation: 30000 From c7a6e9bc2b58dfb65783781c77e73c0d20235f8c Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Jun 2024 13:43:03 +0000 Subject: [PATCH 6/9] [CI] Auto-commit changed files from 'node scripts/check_mappings_update --fix' --- .../current_fields.json | 16 +++++++ .../current_mappings.json | 46 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/packages/kbn-check-mappings-update-cli/current_fields.json b/packages/kbn-check-mappings-update-cli/current_fields.json index 8bce3d4d5e536..b0277b79eca6b 100644 --- a/packages/kbn-check-mappings-update-cli/current_fields.json +++ b/packages/kbn-check-mappings-update-cli/current_fields.json @@ -290,6 +290,22 @@ "schemaVersion" ], "enterprise_search_telemetry": [], + "entity-definition": [ + "description", + "filter", + "id", + "identityFields", + "indexPatterns", + "managed", + "metadata", + "metrics", + "name", + "staticFields", + "type" + ], + "entity-discovery-api-key": [ + "apiKey" + ], "epm-packages": [ "es_index_patterns", "experimental_data_stream_features", diff --git a/packages/kbn-check-mappings-update-cli/current_mappings.json b/packages/kbn-check-mappings-update-cli/current_mappings.json index a498714b970f2..e0b84e572e0f9 100644 --- a/packages/kbn-check-mappings-update-cli/current_mappings.json +++ b/packages/kbn-check-mappings-update-cli/current_mappings.json @@ -993,6 +993,52 @@ "dynamic": false, "properties": {} }, + "entity-definition": { + "dynamic": false, + "properties": { + "description": { + "type": "text" + }, + "filter": { + "type": "keyword" + }, + "id": { + "type": "keyword" + }, + "identityFields": { + "type": "object" + }, + "indexPatterns": { + "type": "keyword" + }, + "managed": { + "type": "boolean" + }, + "metadata": { + "type": "object" + }, + "metrics": { + "type": "object" + }, + "name": { + "type": "text" + }, + "staticFields": { + "type": "object" + }, + "type": { + "type": "keyword" + } + } + }, + "entity-discovery-api-key": { + "dynamic": false, + "properties": { + "apiKey": { + "type": "binary" + } + } + }, "epm-packages": { "properties": { "es_index_patterns": { From 09acbb55af16e2fa4b5267d104b3982cbc04e6f8 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Jun 2024 14:48:01 +0000 Subject: [PATCH 7/9] [CI] Auto-commit changed files from 'node scripts/jest_integration -u src/core/server/integration_tests/ci_checks' --- .../ci_checks/saved_objects/check_registered_types.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts index 2337bbfaaa89e..d318b96435469 100644 --- a/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts +++ b/src/core/server/integration_tests/ci_checks/saved_objects/check_registered_types.test.ts @@ -88,6 +88,8 @@ describe('checking migration metadata changes on all registered SO types', () => "endpoint:unified-user-artifact-manifest": "71c7fcb52c658b21ea2800a6b6a76972ae1c776e", "endpoint:user-artifact-manifest": "1c3533161811a58772e30cdc77bac4631da3ef2b", "enterprise_search_telemetry": "9ac912e1417fc8681e0cd383775382117c9e3d3d", + "entity-definition": "33fe0194bd896f0bfe479d55f6de20f8ba1d7713", + "entity-discovery-api-key": "c267a65c69171d1804362155c1378365f5acef88", "epm-packages": "f8ee125b57df31fd035dc04ad81aef475fd2f5bd", "epm-packages-assets": "7a3e58efd9a14191d0d1a00b8aaed30a145fd0b1", "event-annotation-group": "715ba867d8c68f3c9438052210ea1c30a9362582", From a9ce7d5f08de6f197c0381f0a1806471b8a018fc Mon Sep 17 00:00:00 2001 From: klacabane Date: Fri, 21 Jun 2024 20:16:57 +0200 Subject: [PATCH 8/9] fix so tests --- .../saved_objects/migrations/group3/type_registrations.test.ts | 2 ++ .../saved_objects/migrations/group5/dot_kibana_split.test.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts index f6a9bfd089008..a137b905f07a7 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group3/type_registrations.test.ts @@ -51,6 +51,8 @@ const previouslyRegisteredTypes = [ 'endpoint:user-artifact-manifest', 'endpoint:unified-user-artifact-manifest', 'enterprise_search_telemetry', + 'entity-definition', + 'entity-discovery-api-key', 'epm-packages', 'epm-packages-assets', 'event_loop_delays_daily', diff --git a/src/core/server/integration_tests/saved_objects/migrations/group5/dot_kibana_split.test.ts b/src/core/server/integration_tests/saved_objects/migrations/group5/dot_kibana_split.test.ts index 8f765010e37a8..c4c56442c23f8 100644 --- a/src/core/server/integration_tests/saved_objects/migrations/group5/dot_kibana_split.test.ts +++ b/src/core/server/integration_tests/saved_objects/migrations/group5/dot_kibana_split.test.ts @@ -208,6 +208,8 @@ describe('split .kibana index into multiple system indices', () => { "endpoint:unified-user-artifact-manifest", "endpoint:user-artifact-manifest", "enterprise_search_telemetry", + "entity-definition", + "entity-discovery-api-key", "epm-packages", "epm-packages-assets", "event-annotation-group", From 1ada9b42ff6adfd88b5d6b0603fa85a081c167b0 Mon Sep 17 00:00:00 2001 From: klacabane Date: Wed, 26 Jun 2024 10:18:45 +0200 Subject: [PATCH 9/9] clear builtin def --- .../entity_manager/server/lib/entities/built_in/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts index 5fa34635f9a46..916fef586e4d5 100644 --- a/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts +++ b/x-pack/plugins/observability_solution/entity_manager/server/lib/entities/built_in/services.ts @@ -13,7 +13,7 @@ export const builtInServicesEntityDefinition: EntityDefinition = entityDefinitio name: 'Services from logs', type: 'service', managed: true, - indexPatterns: ['logs-*', 'filebeat*', 'remote_cluster:logs-*'], + indexPatterns: ['logs-*', 'filebeat*'], history: { timestampField: '@timestamp', interval: '1m',