diff --git a/.ci/pipeline-library/src/test/prChanges.groovy b/.ci/pipeline-library/src/test/prChanges.groovy index 0f354e768724..e3f82e6102ac 100644 --- a/.ci/pipeline-library/src/test/prChanges.groovy +++ b/.ci/pipeline-library/src/test/prChanges.groovy @@ -90,7 +90,7 @@ class PrChangesTest extends KibanaBasePipelineTest { props([ githubPrs: [ getChanges: { [ - [filename: 'docs/developer/architecture/code-exploration.asciidoc'], + [filename: 'docs/developer/plugin-list.asciidoc'], ] }, ], ]) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 52df586b8bda..66fb31cc91d5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,7 +8,6 @@ /x-pack/plugins/lens/ @elastic/kibana-app /x-pack/plugins/graph/ @elastic/kibana-app /src/plugins/dashboard/ @elastic/kibana-app -/src/plugins/dashboard/**/*.scss @elastic/kibana-core-ui-designers /src/plugins/discover/ @elastic/kibana-app /src/plugins/input_control_vis/ @elastic/kibana-app /src/plugins/kibana_legacy/ @elastic/kibana-app @@ -59,7 +58,6 @@ # APM /x-pack/plugins/apm/ @elastic/apm-ui -/x-pack/plugins/apm/**/*.scss @elastic/observability-design /x-pack/test/functional/apps/apm/ @elastic/apm-ui /src/legacy/core_plugins/apm_oss/ @elastic/apm-ui /src/plugins/apm_oss/ @elastic/apm-ui @@ -70,7 +68,6 @@ # Canvas /x-pack/plugins/canvas/ @elastic/kibana-canvas -/x-pack/plugins/canvas/**/*.scss @elastic/kibana-core-ui-designers /x-pack/test/functional/apps/canvas/ @elastic/kibana-canvas # Core UI @@ -80,18 +77,14 @@ /src/plugins/home/server/services/ @elastic/kibana-core-ui # Exclude tutorial resources folder for now because they are not owned by Kibana app and most will move out soon /src/legacy/core_plugins/kibana/public/home/*.ts @elastic/kibana-core-ui -/src/legacy/core_plugins/kibana/public/home/**/*.scss @elastic/kibana-core-ui-designers /src/legacy/core_plugins/kibana/public/home/np_ready/ @elastic/kibana-core-ui # Observability UIs /x-pack/legacy/plugins/infra/ @elastic/logs-metrics-ui /x-pack/plugins/infra/ @elastic/logs-metrics-ui -/x-pack/plugins/infra/**/*.scss @elastic/observability-design /x-pack/plugins/ingest_manager/ @elastic/ingest-management -/x-pack/plugins/ingest_manager/**/*.scss @elastic/observability-design /x-pack/legacy/plugins/ingest_manager/ @elastic/ingest-management /x-pack/plugins/observability/ @elastic/observability-ui -/x-pack/plugins/observability/**/*.scss @elastic/observability-design /x-pack/legacy/plugins/monitoring/ @elastic/stack-monitoring-ui /x-pack/plugins/monitoring/ @elastic/stack-monitoring-ui /x-pack/plugins/uptime @elastic/uptime @@ -165,14 +158,10 @@ # Security /src/core/server/csp/ @elastic/kibana-security @elastic/kibana-platform /x-pack/legacy/plugins/security/ @elastic/kibana-security -/x-pack/legacy/plugins/security/**/*.scss @elastic/kibana-core-ui-designers /x-pack/legacy/plugins/spaces/ @elastic/kibana-security -/x-pack/legacy/plugins/spaces/**/*.scss @elastic/kibana-core-ui-designers /x-pack/plugins/spaces/ @elastic/kibana-security -/x-pack/plugins/spaces/**/*.scss @elastic/kibana-core-ui-designers /x-pack/plugins/encrypted_saved_objects/ @elastic/kibana-security /x-pack/plugins/security/ @elastic/kibana-security -/x-pack/plugins/security/**/*.scss @elastic/kibana-core-ui-designers /x-pack/test/api_integration/apis/security/ @elastic/kibana-security /x-pack/test/encrypted_saved_objects_api_integration/ @elastic/kibana-security /x-pack/test/functional/apps/security/ @elastic/kibana-security @@ -220,13 +209,9 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib /x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/ @elastic/kibana-alerting-services /x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/ @elastic/kibana-alerting-services -# Design -**/*.scss @elastic/kibana-design - # Enterprise Search /x-pack/plugins/enterprise_search/ @elastic/app-search-frontend @elastic/workplace-search-frontend /x-pack/test/functional_enterprise_search/ @elastic/app-search-frontend @elastic/workplace-search-frontend -/x-pack/plugins/enterprise_search/**/*.scss @elastic/ent-search-design # Elasticsearch UI /src/plugins/dev_tools/ @elastic/es-ui @@ -255,7 +240,6 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib # Endpoint /x-pack/plugins/endpoint/ @elastic/endpoint-app-team @elastic/siem -/x-pack/plugins/endpoint/**/*.scss @elastic/security-design /x-pack/test/api_integration/apis/endpoint/ @elastic/endpoint-app-team @elastic/siem /x-pack/test/endpoint_api_integration_no_ingest/ @elastic/endpoint-app-team @elastic/siem /x-pack/test/security_solution_endpoint/ @elastic/endpoint-app-team @elastic/siem @@ -265,7 +249,6 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib # Security Solution /x-pack/plugins/security_solution/ @elastic/siem @elastic/endpoint-app-team -/x-pack/plugins/security_solution/**/*.scss @elastic/security-design /x-pack/test/detection_engine_api_integration @elastic/siem @elastic/endpoint-app-team /x-pack/test/lists_api_integration @elastic/siem @elastic/endpoint-app-team /x-pack/test/api_integration/apis/security_solution @elastic/siem @elastic/endpoint-app-team @@ -274,3 +257,29 @@ x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @elastic/kib # Security Intelligence And Analytics /x-pack/plugins/security_solution/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics + +# Design (at the bottom for specificity of SASS files) +**/*.scss @elastic/kibana-design + +# Core design +/src/plugins/dashboard/**/*.scss @elastic/kibana-core-ui-designers +/x-pack/plugins/canvas/**/*.scss @elastic/kibana-core-ui-designers +/src/legacy/core_plugins/kibana/public/home/**/*.scss @elastic/kibana-core-ui-designers +/x-pack/legacy/plugins/security/**/*.scss @elastic/kibana-core-ui-designers +/x-pack/legacy/plugins/spaces/**/*.scss @elastic/kibana-core-ui-designers +/x-pack/plugins/spaces/**/*.scss @elastic/kibana-core-ui-designers +/x-pack/plugins/security/**/*.scss @elastic/kibana-core-ui-designers + +# Observability design +/x-pack/plugins/apm/**/*.scss @elastic/observability-design +/x-pack/plugins/infra/**/*.scss @elastic/observability-design +/x-pack/plugins/ingest_manager/**/*.scss @elastic/observability-design +/x-pack/plugins/observability/**/*.scss @elastic/observability-design + +# Ent. Search design +/x-pack/plugins/enterprise_search/**/*.scss @elastic/ent-search-design + +# Security design +/x-pack/plugins/endpoint/**/*.scss @elastic/security-design +/x-pack/plugins/security_solution/**/*.scss @elastic/security-design + diff --git a/docs/canvas/canvas-function-reference.asciidoc b/docs/canvas/canvas-function-reference.asciidoc index 657e3ec8b8bb..6a6c840074f0 100644 --- a/docs/canvas/canvas-function-reference.asciidoc +++ b/docs/canvas/canvas-function-reference.asciidoc @@ -13,7 +13,7 @@ A *** denotes a required argument. A † denotes an argument can be passed multiple times. -<> | B | <> | <> | <> | <> | <> | <> | <> | <> | K | <> | <> | <> | O | <> | Q | <> | <> | <> | <> | V | W | X | Y | Z +<> | B | <> | <> | <> | <> | <> | <> | <> | <> | K | <> | <> | <> | O | <> | Q | <> | <> | <> | <> | <> | W | X | Y | Z [float] [[a_fns]] @@ -897,7 +897,7 @@ Default: `"-_index:.kibana"` |`string` |An index or index pattern. For example, `"logstash-*"`. -Default: `_all` +Default: `"_all"` |=== *Returns:* `number` @@ -965,7 +965,7 @@ Default: `1000` |`string` |An index or index pattern. For example, `"logstash-*"`. -Default: `_all` +Default: `"_all"` |`metaFields` |`string` @@ -1026,7 +1026,7 @@ Alias: `tz` |`string` |The timezone to use for date operations. Valid ISO8601 formats and UTC offsets both work. -Default: `UTC` +Default: `"UTC"` |=== *Returns:* `datatable` @@ -1238,7 +1238,7 @@ filters |`string` |The horizontal text alignment. -Default: `left` +Default: `"left"` |`color` |`string` @@ -1280,7 +1280,7 @@ Default: `false` |`string` |The font weight. For example, `"normal"`, `"bold"`, `"bolder"`, `"lighter"`, `"100"`, `"200"`, `"300"`, `"400"`, `"500"`, `"600"`, `"700"`, `"800"`, or `"900"`. -Default: `normal` +Default: `"normal"` |=== *Returns:* `style` @@ -2469,7 +2469,7 @@ Alias: `shape` |`string` |Pick a shape. -Default: `square` +Default: `"square"` |`border` @@ -2732,7 +2732,7 @@ Aliases: `c`, `field` |`string` |The column or field that you want to filter. -Default: `@timestamp` +Default: `"@timestamp"` |`compact` |`boolean` @@ -2871,3 +2871,56 @@ Default: `""` |=== *Returns:* `string` + +[float] +[[v_fns]] +== V + +[float] +[[var_fn]] +=== `var` + +Updates the Kibana global context. + +*Accepts:* `any` + +[cols="3*^<"] +|=== +|Argument |Type |Description + +|_Unnamed_ *** + +Alias: `name` +|`string` +|Specify the name of the variable. +|=== + +*Returns:* Depends on your input and arguments + + +[float] +[[var_set_fn]] +=== `var_set` + +Updates the Kibana global context. + +*Accepts:* `any` + +[cols="3*^<"] +|=== +|Argument |Type |Description + +|_Unnamed_ *** + +Alias: `name` +|`string` +|Specify the name of the variable. + +|`value` + +Alias: `val` +|`any` +|Specify the value for the variable. When unspecified, the input context is used. +|=== + +*Returns:* Depends on your input and arguments diff --git a/docs/developer/architecture/code-exploration.asciidoc b/docs/developer/architecture/code-exploration.asciidoc deleted file mode 100644 index d65456f2ad92..000000000000 --- a/docs/developer/architecture/code-exploration.asciidoc +++ /dev/null @@ -1,593 +0,0 @@ -//// - -NOTE: - This is an automatically generated file. Please do not edit directly. Instead, run the - following from within the kibana repository: - - node scripts/build_plugin_list_docs - - You can update the template within packages/kbn-dev-utils/target/plugin_list/generate_plugin_list.js - -//// - -[[code-exploration]] -== Exploring Kibana code - -The goals of our folder heirarchy are: - -- Easy for developers to know where to add new services, plugins and applications. -- Easy for developers to know where to find the code from services, plugins and applications. -- Easy to browse and understand our folder structure. - -To that aim, we strive to: - -- Avoid too many files in any given folder. -- Choose clear, unambigious folder names. -- Organize by domain. -- Every folder should contain a README that describes the contents of that folder. - -[discrete] -[[kibana-services-applications]] -=== Services and Applications - -[discrete] -==== src/plugins - -- {kib-repo}blob/{branch}/src/plugins/advanced_settings[advancedSettings] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/apm_oss[apmOss] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/bfetch/README.md[bfetch] - -bfetch allows to batch HTTP requests and streams responses back. - - -- {kib-repo}blob/{branch}/src/plugins/charts/README.md[charts] - -The Charts plugin is a way to create easier integration of shared colors, themes, types and other utilities across all Kibana charts and visualizations. - - -- {kib-repo}blob/{branch}/src/plugins/console[console] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/dashboard/README.md[dashboard] - -Contains the dashboard application. - - -- {kib-repo}blob/{branch}/src/plugins/data/README.md[data] - -data plugin provides common data access services. - - -- {kib-repo}blob/{branch}/src/plugins/dev_tools/README.md[devTools] - -The ui/registry/dev_tools is removed in favor of the devTools plugin which exposes a register method in the setup contract. -Registering app works mostly the same as registering apps in core.application.register. -Routing will be handled by the id of the dev tool - your dev tool will be mounted when the URL matches /app/dev_tools#/. -This API doesn't support angular, for registering angular dev tools, bootstrap a local module on mount into the given HTML element. - - -- {kib-repo}blob/{branch}/src/plugins/discover/README.md[discover] - -Contains the Discover application and the saved search embeddable. - - -- {kib-repo}blob/{branch}/src/plugins/embeddable/README.md[embeddable] - -Embeddables are re-usable widgets that can be rendered in any environment or plugin. Developers can embed them directly in their plugin. End users can dynamically add them to any embeddable containers. - - -- {kib-repo}blob/{branch}/src/plugins/es_ui_shared/README.md[esUiShared] - -This plugin contains reusable code in the form of self-contained modules (or libraries). Each of these modules exports a set of functionality relevant to the domain of the module. - - -- {kib-repo}blob/{branch}/src/plugins/expressions/README.md[expressions] - -This plugin provides methods which will parse & execute an expression pipeline -string for you, as well as a series of registries for advanced users who might -want to incorporate their own functions, types, and renderers into the service -for use in their own application. - - -- {kib-repo}blob/{branch}/src/plugins/home/README.md[home] - -Moves the legacy ui/registry/feature_catalogue module for registering "features" that should be shown in the home page's feature catalogue to a service within a "home" plugin. The feature catalogue refered to here should not be confused with the "feature" plugin for registering features used to derive UI capabilities for feature controls. - - -- {kib-repo}blob/{branch}/src/plugins/index_pattern_management[indexPatternManagement] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/input_control_vis/README.md[inputControlVis] - -Contains the input control visualization allowing to place custom filter controls on a dashboard. - - -- {kib-repo}blob/{branch}/src/plugins/inspector/README.md[inspector] - -The inspector is a contextual tool to gain insights into different elements -in Kibana, e.g. visualizations. It has the form of a flyout panel. - - -- {kib-repo}blob/{branch}/src/plugins/kibana_legacy/README.md[kibanaLegacy] - -This plugin will contain several helpers and services to integrate pieces of the legacy Kibana app with the new Kibana platform. - - -- {kib-repo}blob/{branch}/src/plugins/kibana_react/README.md[kibanaReact] - -Tools for building React applications in Kibana. - - -- {kib-repo}blob/{branch}/src/plugins/kibana_usage_collection/README.md[kibanaUsageCollection] - -This plugin registers the basic usage collectors from Kibana: - - -- {kib-repo}blob/{branch}/src/plugins/kibana_utils/README.md[kibanaUtils] - -Utilities for building Kibana plugins. - - -- {kib-repo}blob/{branch}/src/plugins/legacy_export[legacyExport] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/management[management] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/maps_legacy[mapsLegacy] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/navigation/README.md[navigation] - -The navigation plugins exports the TopNavMenu component. -It also provides a stateful version of it on the start contract. - - -- {kib-repo}blob/{branch}/src/plugins/newsfeed[newsfeed] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/region_map[regionMap] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/saved_objects[savedObjects] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/saved_objects_management[savedObjectsManagement] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/share/README.md[share] - -Replaces the legacy ui/share module for registering share context menus. - - -- {kib-repo}blob/{branch}/src/plugins/telemetry/README.md[telemetry] - -Telemetry allows Kibana features to have usage tracked in the wild. The general term "telemetry" refers to multiple things: - - -- {kib-repo}blob/{branch}/src/plugins/telemetry_collection_manager/README.md[telemetryCollectionManager] - -Telemetry's collection manager to go through all the telemetry sources when fetching it before reporting. - - -- {kib-repo}blob/{branch}/src/plugins/telemetry_management_section/README.md[telemetryManagementSection] - -This plugin adds the Advanced Settings section for the Usage Data collection (aka Telemetry). - - -- {kib-repo}blob/{branch}/src/plugins/tile_map[tileMap] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/src/plugins/timelion/README.md[timelion] - -Contains the deprecated timelion application. For the timelion visualization, -which also contains the timelion APIs and backend, look at the vis_type_timelion plugin. - - -- {kib-repo}blob/{branch}/src/plugins/ui_actions/README.md[uiActions] - -An API for: - - -- {kib-repo}blob/{branch}/src/plugins/usage_collection/README.md[usageCollection] - -Usage Collection allows collecting usage data for other services to consume (telemetry and monitoring). -To integrate with the telemetry services for usage collection of your feature, there are 2 steps: - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_markdown/README.md[visTypeMarkdown] - -The markdown visualization that can be used to place text panels on dashboards. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_metric/README.md[visTypeMetric] - -Contains the metric visualization. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_table/README.md[visTypeTable] - -Contains the data table visualization, that allows presenting data in a simple table format. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_tagcloud/README.md[visTypeTagcloud] - -Contains the tagcloud visualization. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_timelion/README.md[visTypeTimelion] - -Contains the timelion visualization and the timelion backend. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_timeseries/README.md[visTypeTimeseries] - -Contains everything around TSVB (the editor, visualizatin implementations and backends). - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_vega/README.md[visTypeVega] - -Contains the Vega visualization. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_vislib/README.md[visTypeVislib] - -Contains the vislib visualizations. These are the classical area/line/bar, pie, gauge/goal and -heatmap charts. - - -- {kib-repo}blob/{branch}/src/plugins/vis_type_xy/README.md[visTypeXy] - -Contains the new xy-axis chart using the elastic-charts library, which will eventually -replace the vislib xy-axis (bar, area, line) charts. - - -- {kib-repo}blob/{branch}/src/plugins/visualizations/README.md[visualizations] - -Contains most of the visualization infrastructure, e.g. the visualization type registry or the -visualization embeddable. - - -- {kib-repo}blob/{branch}/src/plugins/visualize/README.md[visualize] - -Contains the visualize application which includes the listing page and the app frame, -which will load the visualization's editor. - - -[discrete] -==== x-pack/plugins - -- {kib-repo}blob/{branch}/x-pack/plugins/actions/README.md[actions] - -The Kibana actions plugin provides a framework to create executable actions. You can: - - -- {kib-repo}blob/{branch}/x-pack/plugins/alerting_builtins/README.md[alertingBuiltins] - -This plugin provides alertTypes shipped with Kibana for use with the -the alerts plugin. When enabled, it will register -the built-in alertTypes with the alerting plugin, register associated HTTP -routes, etc. - - -- {kib-repo}blob/{branch}/x-pack/plugins/alerts/README.md[alerts] - -The Kibana alerting plugin provides a common place to set up alerts. You can: - - -- {kib-repo}blob/{branch}/x-pack/plugins/apm/readme.md[apm] - -To access an elasticsearch instance that has live data you have two options: - - -- {kib-repo}blob/{branch}/x-pack/plugins/audit_trail[auditTrail] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/beats_management/readme.md[beatsManagement] - -Notes: -Failure to have auth enabled in Kibana will make for a broken UI. UI-based errors not yet in place - - -- {kib-repo}blob/{branch}/x-pack/plugins/canvas/README.md[canvas] - -"Never look back. The past is done. The future is a blank canvas." ― Suzy Kassem, Rise Up and Salute the Sun - - -- {kib-repo}blob/{branch}/x-pack/plugins/case/README.md[case] - -Experimental Feature - - -- {kib-repo}blob/{branch}/x-pack/plugins/cloud[cloud] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/code[code] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/console_extensions[consoleExtensions] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/cross_cluster_replication/README.md[crossClusterReplication] - -You can run a local cluster and simulate a remote cluster within a single Kibana directory. - - -- {kib-repo}blob/{branch}/x-pack/plugins/dashboard_enhanced/README.md[dashboardEnhanced] - -Contains the enhancements to the OSS dashboard app. - - -- {kib-repo}blob/{branch}/x-pack/plugins/dashboard_mode/README.md[dashboardMode] - -The deprecated dashboard only mode. - - -- {kib-repo}blob/{branch}/x-pack/plugins/data_enhanced[dataEnhanced] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/discover_enhanced/README.md[discoverEnhanced] - -Contains the enhancements to the OSS discover app. - - -- {kib-repo}blob/{branch}/x-pack/plugins/embeddable_enhanced[embeddableEnhanced] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/encrypted_saved_objects/README.md[encryptedSavedObjects] - -The purpose of this plugin is to provide a way to encrypt/decrypt attributes on the custom Saved Objects that works with -security and spaces filtering as well as performing audit logging. - - -- {kib-repo}blob/{branch}/x-pack/plugins/enterprise_search/README.md[enterpriseSearch] - -This plugin's goal is to provide a Kibana user interface to the Enterprise Search solution's products (App Search and Workplace Search). In it's current MVP state, the plugin provides the following with the goal of gathering user feedback and raising product awareness: - - -- {kib-repo}blob/{branch}/x-pack/plugins/event_log/README.md[eventLog] - -The purpose of this plugin is to provide a way to persist a history of events -occuring in Kibana, initially just for the Make It Action project - alerts -and actions. - - -- {kib-repo}blob/{branch}/x-pack/plugins/features[features] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/file_upload[fileUpload] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/global_search/README.md[globalSearch] - -The GlobalSearch plugin provides an easy way to search for various objects, such as applications -or dashboards from the Kibana instance, from both server and client-side plugins - - -- {kib-repo}blob/{branch}/x-pack/plugins/global_search_providers[globalSearchProviders] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/graph/README.md[graph] - -This is the main source folder of the Graph plugin. It contains all of the Kibana server and client source code. x-pack/test/functional/apps/graph contains additional functional tests. - - -- {kib-repo}blob/{branch}/x-pack/plugins/grokdebugger/README.md[grokdebugger] - -- {kib-repo}blob/{branch}/x-pack/plugins/index_lifecycle_management/README.md[indexLifecycleManagement] - -You can test that the Frozen badge, phase filtering, and lifecycle information is surfaced in -Index Management by running this series of requests in Console: - - -- {kib-repo}blob/{branch}/x-pack/plugins/index_management/README.md[indexManagement] - -Create a data stream using Console and you'll be able to view it in the UI: - - -- {kib-repo}blob/{branch}/x-pack/plugins/infra/README.md[infra] - -This is the home of the infra plugin, which aims to provide a solution for -the infrastructure monitoring use-case within Kibana. - - -- {kib-repo}blob/{branch}/x-pack/plugins/ingest_manager/README.md[ingestManager] - -Fleet needs to have Elasticsearch API keys enabled, and also to have TLS enabled on kibana, (if you want to run Kibana without TLS you can provide the following config flag --xpack.ingestManager.fleet.tlsCheckDisabled=false) - - -- {kib-repo}blob/{branch}/x-pack/plugins/ingest_pipelines/README.md[ingestPipelines] - -The ingest_pipelines plugin provides Kibana support for Elasticsearch's ingest nodes. Please refer to the Elasticsearch documentation for more details. - - -- {kib-repo}blob/{branch}/x-pack/plugins/lens/readme.md[lens] - -Run all tests from the x-pack root directory - - -- {kib-repo}blob/{branch}/x-pack/plugins/license_management[licenseManagement] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/licensing/README.md[licensing] - -The licensing plugin retrieves license data from Elasticsearch at regular configurable intervals. - - -- {kib-repo}blob/{branch}/x-pack/plugins/lists/README.md[lists] - -README.md for developers working on the backend lists on how to get started -using the CURL scripts in the scripts folder. - - -- {kib-repo}blob/{branch}/x-pack/plugins/logstash[logstash] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/maps/README.md[maps] - -Visualize geo data from Elasticsearch or 3rd party geo-services. - - -- {kib-repo}blob/{branch}/x-pack/plugins/maps_legacy_licensing/README.md[mapsLegacyLicensing] - -This plugin provides access to the detailed tile map services from Elastic. - - -- {kib-repo}blob/{branch}/x-pack/plugins/ml[ml] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/monitoring[monitoring] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/observability/README.md[observability] - -This plugin provides shared components and services for use across observability solutions, as well as the observability landing page UI. - - -- {kib-repo}blob/{branch}/x-pack/plugins/oss_telemetry[ossTelemetry] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/painless_lab[painlessLab] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/remote_clusters[remoteClusters] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/reporting/README.md[reporting] - -An awesome Kibana reporting plugin - - -- {kib-repo}blob/{branch}/x-pack/plugins/rollup/README.md[rollup] - -Welcome to the Kibana rollup plugin! This plugin provides Kibana support for Elasticsearch's rollup feature. Please refer to the Elasticsearch documentation to understand rollup indices and how to create rollup jobs. - - -- {kib-repo}blob/{branch}/x-pack/plugins/searchprofiler[searchprofiler] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/security/README.md[security] - -See Configuring security in Kibana. - - -- {kib-repo}blob/{branch}/x-pack/plugins/security_solution/README.md[securitySolution] - -Welcome to the Kibana Security Solution plugin! This README will go over getting started with development and testing. - - -- {kib-repo}blob/{branch}/x-pack/plugins/snapshot_restore/README.md[snapshotRestore] - -or - - -- {kib-repo}blob/{branch}/x-pack/plugins/spaces[spaces] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/task_manager[taskManager] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/telemetry_collection_xpack/README.md[telemetryCollectionXpack] - -Gathers all usage collection, retrieving them from both: OSS and X-Pack plugins. - - -- {kib-repo}blob/{branch}/x-pack/plugins/transform[transform] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/translations[translations] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/triggers_actions_ui/README.md[triggers_actions_ui] - -The Kibana alerts and actions UI plugin provides a user interface for managing alerts and actions. -As a developer you can reuse and extend built-in alerts and actions UI functionality: - - -- {kib-repo}blob/{branch}/x-pack/plugins/ui_actions_enhanced/README.md[uiActionsEnhanced] - -- {kib-repo}blob/{branch}/x-pack/plugins/upgrade_assistant[upgradeAssistant] - -WARNING: Missing README. - - -- {kib-repo}blob/{branch}/x-pack/plugins/uptime/README.md[uptime] - -The purpose of this plugin is to provide users of Heartbeat more visibility of what's happening -in their infrastructure. - - -- {kib-repo}blob/{branch}/x-pack/plugins/watcher/README.md[watcher] - -This plugins adopts some conventions in addition to or in place of conventions in Kibana (at the time of the plugin's creation): - diff --git a/docs/developer/architecture/index.asciidoc b/docs/developer/architecture/index.asciidoc index 2e6ab1a4ad6a..ac25fe003df0 100644 --- a/docs/developer/architecture/index.asciidoc +++ b/docs/developer/architecture/index.asciidoc @@ -17,7 +17,6 @@ A few notable services are called out below. * <> * <> * <> -* <> include::add-data-tutorials.asciidoc[leveloffset=+1] @@ -25,4 +24,3 @@ include::development-visualize-index.asciidoc[leveloffset=+1] include::security/index.asciidoc[leveloffset=+1] -include::code-exploration.asciidoc[leveloffset=+1] diff --git a/docs/developer/architecture/security/rbac.asciidoc b/docs/developer/architecture/security/rbac.asciidoc index 7b35a91ca73d..451e833651a7 100644 --- a/docs/developer/architecture/security/rbac.asciidoc +++ b/docs/developer/architecture/security/rbac.asciidoc @@ -1,4 +1,4 @@ -[[development-security-rbac]] +[[development-rbac]] == Role-based access control Role-based access control (RBAC) in {kib} relies upon the @@ -7,7 +7,7 @@ that {es} exposes. This allows {kib} to define the privileges that {kib} wishes to grant to users, assign them to the relevant users using roles, and then authorize the user to perform a specific action. This is handled within a secured instance of the `SavedObjectsClient` and available transparently to -consumers when using `request.getSavedObjectsClient()` or +consumers when using `request.getSavedObjectsClient()` or `savedObjects.getScopedSavedObjectsClient()`. [[development-rbac-privileges]] @@ -77,7 +77,7 @@ The application is created by concatenating the prefix of `kibana-` with the val } ---------------------------------- -Roles that grant <> should be managed using the <> or the *Management -> Security -> Roles* page, not directly using the {es} {ref}/security-api.html#security-role-apis[role management API]. This role can then be assigned to users using the {es} +Roles that grant <> should be managed using the <> or the *Management -> Security -> Roles* page, not directly using the {es} {ref}/security-api.html#security-role-apis[role management API]. This role can then be assigned to users using the {es} {ref}/security-api.html#security-user-apis[user management APIs]. [[development-rbac-authorization]] diff --git a/docs/developer/best-practices/index.asciidoc b/docs/developer/best-practices/index.asciidoc index 90b0092d835a..63a44b54d454 100644 --- a/docs/developer/best-practices/index.asciidoc +++ b/docs/developer/best-practices/index.asciidoc @@ -99,7 +99,7 @@ Re-using these services will help create a consistent experience across [discrete] === Backward compatibility -Eventually we want to garauntee to our plugin developers that their plugins will not break from minor to minor. +Eventually we want to guarantee to our plugin developers that their plugins will not break from minor to minor. Any time you create or change a public API, keep this in mind, and consider potential backward compatibility issues. While we have a formal diff --git a/docs/developer/getting-started/index.asciidoc b/docs/developer/getting-started/index.asciidoc index 2ac51b6cf86f..eaa35eece5a2 100644 --- a/docs/developer/getting-started/index.asciidoc +++ b/docs/developer/getting-started/index.asciidoc @@ -99,7 +99,7 @@ preserving data inbetween runs, running remote cluster, etc. [discrete] === Run {kib} -In another terminal window, start up {kib}. Include developer examples by adding an optional `--run-examples` flag. +In another terminal window, start up {kib}. Include {kib-repo}tree/{branch}/examples[developer examples] by adding an optional `--run-examples` flag. [source,bash] ---- diff --git a/docs/developer/index.asciidoc b/docs/developer/index.asciidoc index db57815a1285..5f032a395217 100644 --- a/docs/developer/index.asciidoc +++ b/docs/developer/index.asciidoc @@ -12,6 +12,7 @@ running in no time. If you have any problems, file an issue in the https://githu * <> * <> * <> +* <> -- @@ -27,3 +28,5 @@ include::plugin/index.asciidoc[] include::advanced/index.asciidoc[] +include::plugin-list.asciidoc[] + diff --git a/docs/developer/plugin-list.asciidoc b/docs/developer/plugin-list.asciidoc new file mode 100644 index 000000000000..b3180a7a0387 --- /dev/null +++ b/docs/developer/plugin-list.asciidoc @@ -0,0 +1,497 @@ +//// + +NOTE: + This is an automatically generated file. Please do not edit directly. Instead, run the + following from within the kibana repository: + + node scripts/build_plugin_list_docs + + You can update the template within packages/kbn-dev-utils/target/plugin_list/generate_plugin_list.js + +//// + +[[plugin-list]] +== List of {kib} plugins + +[discrete] +=== src/plugins + +[%header,cols=2*] +|=== +|Name +|Description + + +|{kib-repo}blob/{branch}/src/plugins/advanced_settings[advancedSettings] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/apm_oss[apmOss] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/bfetch/README.md[bfetch] +|bfetch allows to batch HTTP requests and streams responses back. + + +|{kib-repo}blob/{branch}/src/plugins/charts/README.md[charts] +|The Charts plugin is a way to create easier integration of shared colors, themes, types and other utilities across all Kibana charts and visualizations. + + +|{kib-repo}blob/{branch}/src/plugins/console[console] +|WARNING: Missing README. + + +|<> +|- Registers the dashboard application. +- Adds a dashboard embeddable that can be used in other applications. + + +|{kib-repo}blob/{branch}/src/plugins/data/README.md[data] +|data plugin provides common data access services. + + +|{kib-repo}blob/{branch}/src/plugins/dev_tools/README.md[devTools] +|The ui/registry/dev_tools is removed in favor of the devTools plugin which exposes a register method in the setup contract. +Registering app works mostly the same as registering apps in core.application.register. +Routing will be handled by the id of the dev tool - your dev tool will be mounted when the URL matches /app/dev_tools#/. +This API doesn't support angular, for registering angular dev tools, bootstrap a local module on mount into the given HTML element. + + +|{kib-repo}blob/{branch}/src/plugins/discover/README.md[discover] +|Contains the Discover application and the saved search embeddable. + + +|{kib-repo}blob/{branch}/src/plugins/embeddable/README.md[embeddable] +|Embeddables are re-usable widgets that can be rendered in any environment or plugin. Developers can embed them directly in their plugin. End users can dynamically add them to any embeddable containers. + + +|{kib-repo}blob/{branch}/src/plugins/es_ui_shared/README.md[esUiShared] +|This plugin contains reusable code in the form of self-contained modules (or libraries). Each of these modules exports a set of functionality relevant to the domain of the module. + + +|{kib-repo}blob/{branch}/src/plugins/expressions/README.md[expressions] +|This plugin provides methods which will parse & execute an expression pipeline +string for you, as well as a series of registries for advanced users who might +want to incorporate their own functions, types, and renderers into the service +for use in their own application. + + +|{kib-repo}blob/{branch}/src/plugins/home/README.md[home] +|Moves the legacy ui/registry/feature_catalogue module for registering "features" that should be shown in the home page's feature catalogue to a service within a "home" plugin. The feature catalogue refered to here should not be confused with the "feature" plugin for registering features used to derive UI capabilities for feature controls. + + +|{kib-repo}blob/{branch}/src/plugins/index_pattern_management[indexPatternManagement] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/input_control_vis/README.md[inputControlVis] +|Contains the input control visualization allowing to place custom filter controls on a dashboard. + + +|{kib-repo}blob/{branch}/src/plugins/inspector/README.md[inspector] +|The inspector is a contextual tool to gain insights into different elements +in Kibana, e.g. visualizations. It has the form of a flyout panel. + + +|{kib-repo}blob/{branch}/src/plugins/kibana_legacy/README.md[kibanaLegacy] +|This plugin will contain several helpers and services to integrate pieces of the legacy Kibana app with the new Kibana platform. + + +|{kib-repo}blob/{branch}/src/plugins/kibana_react/README.md[kibanaReact] +|Tools for building React applications in Kibana. + + +|{kib-repo}blob/{branch}/src/plugins/kibana_usage_collection/README.md[kibanaUsageCollection] +|This plugin registers the basic usage collectors from Kibana: + + +|{kib-repo}blob/{branch}/src/plugins/kibana_utils/README.md[kibanaUtils] +|Utilities for building Kibana plugins. + + +|{kib-repo}blob/{branch}/src/plugins/legacy_export[legacyExport] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/management[management] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/maps_legacy[mapsLegacy] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/navigation/README.md[navigation] +|The navigation plugins exports the TopNavMenu component. +It also provides a stateful version of it on the start contract. + + +|{kib-repo}blob/{branch}/src/plugins/newsfeed[newsfeed] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/region_map[regionMap] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/saved_objects[savedObjects] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/saved_objects_management[savedObjectsManagement] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/share/README.md[share] +|Replaces the legacy ui/share module for registering share context menus. + + +|{kib-repo}blob/{branch}/src/plugins/telemetry/README.md[telemetry] +|Telemetry allows Kibana features to have usage tracked in the wild. The general term "telemetry" refers to multiple things: + + +|{kib-repo}blob/{branch}/src/plugins/telemetry_collection_manager/README.md[telemetryCollectionManager] +|Telemetry's collection manager to go through all the telemetry sources when fetching it before reporting. + + +|{kib-repo}blob/{branch}/src/plugins/telemetry_management_section/README.md[telemetryManagementSection] +|This plugin adds the Advanced Settings section for the Usage Data collection (aka Telemetry). + + +|{kib-repo}blob/{branch}/src/plugins/tile_map[tileMap] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/src/plugins/timelion/README.md[timelion] +|Contains the deprecated timelion application. For the timelion visualization, +which also contains the timelion APIs and backend, look at the vis_type_timelion plugin. + + +|{kib-repo}blob/{branch}/src/plugins/ui_actions/README.md[uiActions] +|An API for: + + +|{kib-repo}blob/{branch}/src/plugins/usage_collection/README.md[usageCollection] +|Usage Collection allows collecting usage data for other services to consume (telemetry and monitoring). +To integrate with the telemetry services for usage collection of your feature, there are 2 steps: + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_markdown/README.md[visTypeMarkdown] +|The markdown visualization that can be used to place text panels on dashboards. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_metric/README.md[visTypeMetric] +|Contains the metric visualization. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_table/README.md[visTypeTable] +|Contains the data table visualization, that allows presenting data in a simple table format. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_tagcloud/README.md[visTypeTagcloud] +|Contains the tagcloud visualization. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_timelion/README.md[visTypeTimelion] +|Contains the timelion visualization and the timelion backend. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_timeseries/README.md[visTypeTimeseries] +|Contains everything around TSVB (the editor, visualizatin implementations and backends). + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_vega/README.md[visTypeVega] +|Contains the Vega visualization. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_vislib/README.md[visTypeVislib] +|Contains the vislib visualizations. These are the classical area/line/bar, pie, gauge/goal and +heatmap charts. + + +|{kib-repo}blob/{branch}/src/plugins/vis_type_xy/README.md[visTypeXy] +|Contains the new xy-axis chart using the elastic-charts library, which will eventually +replace the vislib xy-axis (bar, area, line) charts. + + +|{kib-repo}blob/{branch}/src/plugins/visualizations/README.md[visualizations] +|Contains most of the visualization infrastructure, e.g. the visualization type registry or the +visualization embeddable. + + +|{kib-repo}blob/{branch}/src/plugins/visualize/README.md[visualize] +|Contains the visualize application which includes the listing page and the app frame, +which will load the visualization's editor. + + +|=== + +[discrete] +=== x-pack/plugins + +[%header,cols=2*] +|=== +|Name +|Description + + +|{kib-repo}blob/{branch}/x-pack/plugins/actions/README.md[actions] +|The Kibana actions plugin provides a framework to create executable actions. You can: + + +|{kib-repo}blob/{branch}/x-pack/plugins/alerting_builtins/README.md[alertingBuiltins] +|This plugin provides alertTypes shipped with Kibana for use with the +the alerts plugin. When enabled, it will register +the built-in alertTypes with the alerting plugin, register associated HTTP +routes, etc. + + +|{kib-repo}blob/{branch}/x-pack/plugins/alerts/README.md[alerts] +|The Kibana alerting plugin provides a common place to set up alerts. You can: + + +|{kib-repo}blob/{branch}/x-pack/plugins/apm/readme.md[apm] +|To access an elasticsearch instance that has live data you have two options: + + +|{kib-repo}blob/{branch}/x-pack/plugins/audit_trail[auditTrail] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/beats_management/readme.md[beatsManagement] +|Notes: +Failure to have auth enabled in Kibana will make for a broken UI. UI-based errors not yet in place + + +|{kib-repo}blob/{branch}/x-pack/plugins/canvas/README.md[canvas] +|"Never look back. The past is done. The future is a blank canvas." ― Suzy Kassem, Rise Up and Salute the Sun + + +|{kib-repo}blob/{branch}/x-pack/plugins/case/README.md[case] +|Experimental Feature + + +|{kib-repo}blob/{branch}/x-pack/plugins/cloud[cloud] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/code[code] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/console_extensions[consoleExtensions] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/cross_cluster_replication/README.md[crossClusterReplication] +|You can run a local cluster and simulate a remote cluster within a single Kibana directory. + + +|<> +|Adds drilldown capabilities to dashboard. Owned by the Kibana App team. + + +|{kib-repo}blob/{branch}/x-pack/plugins/dashboard_mode/README.md[dashboardMode] +|The deprecated dashboard only mode. + + +|{kib-repo}blob/{branch}/x-pack/plugins/data_enhanced[dataEnhanced] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/discover_enhanced/README.md[discoverEnhanced] +|Contains the enhancements to the OSS discover app. + + +|<> +|Enhances Embeddables by registering a custom factory provider. The enhanced factory provider +adds dynamic actions to every embeddables state, in order to support drilldowns. + + +|{kib-repo}blob/{branch}/x-pack/plugins/encrypted_saved_objects/README.md[encryptedSavedObjects] +|The purpose of this plugin is to provide a way to encrypt/decrypt attributes on the custom Saved Objects that works with +security and spaces filtering as well as performing audit logging. + + +|{kib-repo}blob/{branch}/x-pack/plugins/enterprise_search/README.md[enterpriseSearch] +|This plugin's goal is to provide a Kibana user interface to the Enterprise Search solution's products (App Search and Workplace Search). In it's current MVP state, the plugin provides the following with the goal of gathering user feedback and raising product awareness: + + +|{kib-repo}blob/{branch}/x-pack/plugins/event_log/README.md[eventLog] +|The purpose of this plugin is to provide a way to persist a history of events +occuring in Kibana, initially just for the Make It Action project - alerts +and actions. + + +|{kib-repo}blob/{branch}/x-pack/plugins/features[features] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/file_upload[fileUpload] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/global_search/README.md[globalSearch] +|The GlobalSearch plugin provides an easy way to search for various objects, such as applications +or dashboards from the Kibana instance, from both server and client-side plugins + + +|{kib-repo}blob/{branch}/x-pack/plugins/global_search_providers[globalSearchProviders] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/graph/README.md[graph] +|This is the main source folder of the Graph plugin. It contains all of the Kibana server and client source code. x-pack/test/functional/apps/graph contains additional functional tests. + + +|{kib-repo}blob/{branch}/x-pack/plugins/grokdebugger[grokdebugger] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/index_lifecycle_management/README.md[indexLifecycleManagement] +|You can test that the Frozen badge, phase filtering, and lifecycle information is surfaced in +Index Management by running this series of requests in Console: + + +|{kib-repo}blob/{branch}/x-pack/plugins/index_management/README.md[indexManagement] +|Create a data stream using Console and you'll be able to view it in the UI: + + +|{kib-repo}blob/{branch}/x-pack/plugins/infra/README.md[infra] +|This is the home of the infra plugin, which aims to provide a solution for +the infrastructure monitoring use-case within Kibana. + + +|{kib-repo}blob/{branch}/x-pack/plugins/ingest_manager/README.md[ingestManager] +|Fleet needs to have Elasticsearch API keys enabled, and also to have TLS enabled on kibana, (if you want to run Kibana without TLS you can provide the following config flag --xpack.ingestManager.fleet.tlsCheckDisabled=false) + + +|{kib-repo}blob/{branch}/x-pack/plugins/ingest_pipelines/README.md[ingestPipelines] +|The ingest_pipelines plugin provides Kibana support for Elasticsearch's ingest nodes. Please refer to the Elasticsearch documentation for more details. + + +|{kib-repo}blob/{branch}/x-pack/plugins/lens/readme.md[lens] +|Run all tests from the x-pack root directory + + +|{kib-repo}blob/{branch}/x-pack/plugins/license_management[licenseManagement] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/licensing/README.md[licensing] +|The licensing plugin retrieves license data from Elasticsearch at regular configurable intervals. + + +|{kib-repo}blob/{branch}/x-pack/plugins/lists/README.md[lists] +|README.md for developers working on the backend lists on how to get started +using the CURL scripts in the scripts folder. + + +|{kib-repo}blob/{branch}/x-pack/plugins/logstash[logstash] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/maps/README.md[maps] +|Visualize geo data from Elasticsearch or 3rd party geo-services. + + +|{kib-repo}blob/{branch}/x-pack/plugins/maps_legacy_licensing/README.md[mapsLegacyLicensing] +|This plugin provides access to the detailed tile map services from Elastic. + + +|{kib-repo}blob/{branch}/x-pack/plugins/ml[ml] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/monitoring[monitoring] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/observability/README.md[observability] +|This plugin provides shared components and services for use across observability solutions, as well as the observability landing page UI. + + +|{kib-repo}blob/{branch}/x-pack/plugins/oss_telemetry[ossTelemetry] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/painless_lab[painlessLab] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/remote_clusters[remoteClusters] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/reporting/README.md[reporting] +|An awesome Kibana reporting plugin + + +|{kib-repo}blob/{branch}/x-pack/plugins/rollup/README.md[rollup] +|Welcome to the Kibana rollup plugin! This plugin provides Kibana support for Elasticsearch's rollup feature. Please refer to the Elasticsearch documentation to understand rollup indices and how to create rollup jobs. + + +|{kib-repo}blob/{branch}/x-pack/plugins/searchprofiler[searchprofiler] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/security/README.md[security] +|See Configuring security in Kibana. + + +|{kib-repo}blob/{branch}/x-pack/plugins/security_solution/README.md[securitySolution] +|Welcome to the Kibana Security Solution plugin! This README will go over getting started with development and testing. + + +|{kib-repo}blob/{branch}/x-pack/plugins/snapshot_restore/README.md[snapshotRestore] +|or + + +|{kib-repo}blob/{branch}/x-pack/plugins/spaces[spaces] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/task_manager[taskManager] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/telemetry_collection_xpack/README.md[telemetryCollectionXpack] +|Gathers all usage collection, retrieving them from both: OSS and X-Pack plugins. + + +|{kib-repo}blob/{branch}/x-pack/plugins/transform[transform] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/translations[translations] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/triggers_actions_ui/README.md[triggers_actions_ui] +|The Kibana alerts and actions UI plugin provides a user interface for managing alerts and actions. +As a developer you can reuse and extend built-in alerts and actions UI functionality: + + +|{kib-repo}blob/{branch}/x-pack/plugins/ui_actions_enhanced/README.md[uiActionsEnhanced] +|Registers commercially licensed generic actions like per panel time range and contains some code that supports drilldown work. + + +|{kib-repo}blob/{branch}/x-pack/plugins/upgrade_assistant[upgradeAssistant] +|WARNING: Missing README. + + +|{kib-repo}blob/{branch}/x-pack/plugins/uptime/README.md[uptime] +|The purpose of this plugin is to provide users of Heartbeat more visibility of what's happening +in their infrastructure. + + +|{kib-repo}blob/{branch}/x-pack/plugins/watcher/README.md[watcher] +|This plugins adopts some conventions in addition to or in place of conventions in Kibana (at the time of the plugin's creation): + + +|=== + +include::{kibana-root}/src/plugins/dashboard/README.asciidoc[leveloffset=+1] +include::{kibana-root}/x-pack/plugins/dashboard_enhanced/README.asciidoc[leveloffset=+1] +include::{kibana-root}/x-pack/plugins/embeddable_enhanced/README.asciidoc[leveloffset=+1] diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md new file mode 100644 index 000000000000..6d93dc97a107 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [createTooManyRequestsError](./kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md) + +## SavedObjectsErrorHelpers.createTooManyRequestsError() method + +Signature: + +```typescript +static createTooManyRequestsError(type: string, id: string): DecoratedError; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| type | string | | +| id | string | | + +Returns: + +`DecoratedError` + diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md new file mode 100644 index 000000000000..46c94e1756ed --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md @@ -0,0 +1,23 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [decorateTooManyRequestsError](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md) + +## SavedObjectsErrorHelpers.decorateTooManyRequestsError() method + +Signature: + +```typescript +static decorateTooManyRequestsError(error: Error, reason?: string): DecoratedError; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| error | Error | | +| reason | string | | + +Returns: + +`DecoratedError` + diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.istoomanyrequestserror.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.istoomanyrequestserror.md new file mode 100644 index 000000000000..4422966ee3e5 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.istoomanyrequestserror.md @@ -0,0 +1,22 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [SavedObjectsErrorHelpers](./kibana-plugin-core-server.savedobjectserrorhelpers.md) > [isTooManyRequestsError](./kibana-plugin-core-server.savedobjectserrorhelpers.istoomanyrequestserror.md) + +## SavedObjectsErrorHelpers.isTooManyRequestsError() method + +Signature: + +```typescript +static isTooManyRequestsError(error: Error | DecoratedError): boolean; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| error | Error | DecoratedError | | + +Returns: + +`boolean` + diff --git a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md index 7874be311d52..a2eff4dd99ea 100644 --- a/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md +++ b/docs/development/core/server/kibana-plugin-core-server.savedobjectserrorhelpers.md @@ -19,6 +19,7 @@ export declare class SavedObjectsErrorHelpers | [createConflictError(type, id)](./kibana-plugin-core-server.savedobjectserrorhelpers.createconflicterror.md) | static | | | [createGenericNotFoundError(type, id)](./kibana-plugin-core-server.savedobjectserrorhelpers.creategenericnotfounderror.md) | static | | | [createInvalidVersionError(versionInput)](./kibana-plugin-core-server.savedobjectserrorhelpers.createinvalidversionerror.md) | static | | +| [createTooManyRequestsError(type, id)](./kibana-plugin-core-server.savedobjectserrorhelpers.createtoomanyrequestserror.md) | static | | | [createUnsupportedTypeError(type)](./kibana-plugin-core-server.savedobjectserrorhelpers.createunsupportedtypeerror.md) | static | | | [decorateBadRequestError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratebadrequesterror.md) | static | | | [decorateConflictError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorateconflicterror.md) | static | | @@ -28,6 +29,7 @@ export declare class SavedObjectsErrorHelpers | [decorateGeneralError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decorategeneralerror.md) | static | | | [decorateNotAuthorizedError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratenotauthorizederror.md) | static | | | [decorateRequestEntityTooLargeError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoraterequestentitytoolargeerror.md) | static | | +| [decorateTooManyRequestsError(error, reason)](./kibana-plugin-core-server.savedobjectserrorhelpers.decoratetoomanyrequestserror.md) | static | | | [isBadRequestError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isbadrequesterror.md) | static | | | [isConflictError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isconflicterror.md) | static | | | [isEsCannotExecuteScriptError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isescannotexecutescripterror.md) | static | | @@ -38,4 +40,5 @@ export declare class SavedObjectsErrorHelpers | [isNotFoundError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isnotfounderror.md) | static | | | [isRequestEntityTooLargeError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.isrequestentitytoolargeerror.md) | static | | | [isSavedObjectsClientError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.issavedobjectsclienterror.md) | static | | +| [isTooManyRequestsError(error)](./kibana-plugin-core-server.savedobjectserrorhelpers.istoomanyrequestserror.md) | static | | diff --git a/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.md b/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.md index 0551a217520a..3d3b73ccda25 100644 --- a/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.md +++ b/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.md @@ -17,4 +17,5 @@ export interface StatusServiceSetup | Property | Type | Description | | --- | --- | --- | | [core$](./kibana-plugin-core-server.statusservicesetup.core_.md) | Observable<CoreStatus> | Current status for all Core services. | +| [overall$](./kibana-plugin-core-server.statusservicesetup.overall_.md) | Observable<ServiceStatus> | Overall system status for all of Kibana. | diff --git a/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.overall_.md b/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.overall_.md new file mode 100644 index 000000000000..bb7c31311d52 --- /dev/null +++ b/docs/development/core/server/kibana-plugin-core-server.statusservicesetup.overall_.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [kibana-plugin-core-server](./kibana-plugin-core-server.md) > [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) > [overall$](./kibana-plugin-core-server.statusservicesetup.overall_.md) + +## StatusServiceSetup.overall$ property + +Overall system status for all of Kibana. + +Signature: + +```typescript +overall$: Observable; +``` + +## Remarks + +The level of the overall status will reflect the most severe status of any core service or plugin. + +Exposed only for reporting purposes to outside systems and should not be used by plugins. Instead, plugins should only depend on the statuses of [Core](./kibana-plugin-core-server.statusservicesetup.core_.md) or their dependencies. + diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md index 18fca3d2c8a6..139c5794f014 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.plugin.setup.md @@ -8,6 +8,7 @@ ```typescript setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; @@ -25,6 +26,7 @@ setup(core: CoreSetup, { expressio Returns: `{ + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; diff --git a/docs/redirects.asciidoc b/docs/redirects.asciidoc index 58687d99627b..1a20c1df582e 100644 --- a/docs/redirects.asciidoc +++ b/docs/redirects.asciidoc @@ -90,3 +90,8 @@ Watcher error reports have been removed and replaced with Kibana's <>. + +[role="exclude",id="development-security-rbac"] +== Role-based access control + +This content has moved to the <> page. diff --git a/examples/embeddable_examples/public/book/edit_book_action.tsx b/examples/embeddable_examples/public/book/edit_book_action.tsx index b31d69696598..5b14dc85b1fc 100644 --- a/examples/embeddable_examples/public/book/edit_book_action.tsx +++ b/examples/embeddable_examples/public/book/edit_book_action.tsx @@ -65,8 +65,8 @@ export const createEditBookAction = (getStartServices: () => Promise { const newInput = await attributeService.wrapAttributes(attributes, useRefType, embeddable); if (!useRefType && (embeddable.getInput() as SavedObjectEmbeddableInput).savedObjectId) { - // Remove the savedObejctId when un-linking - newInput.savedObjectId = null; + // Set the saved object ID to null so that update input will remove the existing savedObjectId... + (newInput as BookByValueInput & { savedObjectId: unknown }).savedObjectId = null; } embeddable.updateInput(newInput); if (useRefType) { diff --git a/examples/embeddable_explorer/public/list_container_example.tsx b/examples/embeddable_explorer/public/list_container_example.tsx index b9bd825ed024..d9d9c49249ab 100644 --- a/examples/embeddable_explorer/public/list_container_example.tsx +++ b/examples/embeddable_explorer/public/list_container_example.tsx @@ -29,11 +29,7 @@ import { EuiText, EuiTitle, } from '@elastic/eui'; -import { - EmbeddableInput, - EmbeddableRenderer, - ViewMode, -} from '../../../src/plugins/embeddable/public'; +import { EmbeddableRenderer, ViewMode } from '../../../src/plugins/embeddable/public'; import { HELLO_WORLD_EMBEDDABLE, MULTI_TASK_TODO_EMBEDDABLE, @@ -41,6 +37,9 @@ import { ListContainerFactory, SearchableListContainerFactory, } from '../../embeddable_examples/public'; +import { SearchableContainerInput } from '../../embeddable_examples/public/searchable_list_container/searchable_list_container'; +import { TodoInput } from '../../embeddable_examples/public/todo'; +import { MultiTaskTodoInput } from '../../embeddable_examples/public/multi_task_todo'; interface Props { listContainerEmbeddableFactory: ListContainerFactory; @@ -51,7 +50,7 @@ export function ListContainerExample({ listContainerEmbeddableFactory, searchableListContainerEmbeddableFactory, }: Props) { - const listInput: EmbeddableInput = { + const listInput: SearchableContainerInput = { id: 'hello', title: 'My todo list', viewMode: ViewMode.VIEW, @@ -69,7 +68,7 @@ export function ListContainerExample({ task: 'Goes out on Wednesdays!', icon: 'broom', title: 'Take out the trash', - }, + } as TodoInput, }, '3': { type: TODO_EMBEDDABLE, @@ -77,12 +76,12 @@ export function ListContainerExample({ id: '3', icon: 'broom', title: 'Vaccum the floor', - }, + } as TodoInput, }, }, }; - const searchableInput: EmbeddableInput = { + const searchableInput: SearchableContainerInput = { id: '1', title: 'My searchable todo list', viewMode: ViewMode.VIEW, @@ -101,7 +100,7 @@ export function ListContainerExample({ task: 'Goes out on Wednesdays!', icon: 'broom', title: 'Take out the trash', - }, + } as TodoInput, }, '3': { type: MULTI_TASK_TODO_EMBEDDABLE, @@ -110,7 +109,7 @@ export function ListContainerExample({ icon: 'searchProfilerApp', title: 'Learn more', tasks: ['Go to school', 'Watch planet earth', 'Read the encyclopedia'], - }, + } as MultiTaskTodoInput, }, }, }; diff --git a/packages/kbn-dev-utils/src/plugin_list/discover_plugins.ts b/packages/kbn-dev-utils/src/plugin_list/discover_plugins.ts index 733b9f23a539..783d584656b1 100644 --- a/packages/kbn-dev-utils/src/plugin_list/discover_plugins.ts +++ b/packages/kbn-dev-utils/src/plugin_list/discover_plugins.ts @@ -25,12 +25,14 @@ import cheerio from 'cheerio'; import { REPO_ROOT } from '../repo_root'; import { simpleKibanaPlatformPluginDiscovery } from '../simple_kibana_platform_plugin_discovery'; +import { extractAsciidocInfo } from './extract_asciidoc_info'; export interface Plugin { id: string; relativeDir?: string; relativeReadmePath?: string; readmeSnippet?: string; + readmeAsciidocAnchor?: string; } export type Plugins = Plugin[]; @@ -38,14 +40,29 @@ export type Plugins = Plugin[]; const getReadmeName = (directory: string) => Fs.readdirSync(directory).find((name) => name.toLowerCase() === 'readme.md'); +const getReadmeAsciidocName = (directory: string) => + Fs.readdirSync(directory).find((name) => name.toLowerCase() === 'readme.asciidoc'); + export const discoverPlugins = (pluginsRootDir: string): Plugins => simpleKibanaPlatformPluginDiscovery([pluginsRootDir], []).map( ({ directory, manifest: { id } }): Plugin => { const readmeName = getReadmeName(directory); + const readmeAsciidocName = getReadmeAsciidocName(directory); let relativeReadmePath: string | undefined; let readmeSnippet: string | undefined; - if (readmeName) { + let readmeAsciidocAnchor: string | undefined; + + if (readmeAsciidocName) { + const readmePath = Path.resolve(directory, readmeAsciidocName); + relativeReadmePath = Path.relative(REPO_ROOT, readmePath); + + const readmeText = Fs.readFileSync(relativeReadmePath).toString(); + + const { firstParagraph, anchor } = extractAsciidocInfo(readmeText); + readmeSnippet = firstParagraph; + readmeAsciidocAnchor = anchor; + } else if (readmeName) { const readmePath = Path.resolve(directory, readmeName); relativeReadmePath = Path.relative(REPO_ROOT, readmePath); @@ -64,6 +81,7 @@ export const discoverPlugins = (pluginsRootDir: string): Plugins => relativeReadmePath, relativeDir: relativeReadmePath || Path.relative(REPO_ROOT, directory), readmeSnippet, + readmeAsciidocAnchor, }; } ); diff --git a/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.test.ts b/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.test.ts new file mode 100644 index 000000000000..baa88bbe1d2f --- /dev/null +++ b/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.test.ts @@ -0,0 +1,86 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { extractAsciidocInfo } from './extract_asciidoc_info'; + +it('Returns the info and anchor when there is only one paragraph', () => { + const { firstParagraph, anchor } = extractAsciidocInfo( + `[[this-is-the-anchor]] +== I'm the heading! + +Hello + +I'm an intro paragraph!` + ); + + expect(firstParagraph).toEqual(`Hello\n\nI'm an intro paragraph!`); + expect(anchor).toEqual('this-is-the-anchor'); +}); + +it('Returns the info and anchor when there are multiple paragraphs without an anchor', () => { + const { firstParagraph, anchor } = extractAsciidocInfo( + `[[this-is-the-anchor]] +== Heading here + +Intro. + +=== Another heading + +More details` + ); + + expect(firstParagraph).toEqual(`Intro.`); + expect(anchor).toEqual('this-is-the-anchor'); +}); + +it('Returns the info and anchor when there are multiple paragraphs with anchors', () => { + const { firstParagraph, anchor } = extractAsciidocInfo( + `[[this-is-the-anchor]] +== Heading here + +Intro. + +[[an-anchor]] +=== Another heading + +More details + ` + ); + + expect(firstParagraph).toEqual(`Intro.`); + expect(anchor).toEqual('this-is-the-anchor'); +}); + +it('Returns the info and anchor when there are multiple paragraphs with discrete prefixes', () => { + const { firstParagraph, anchor } = extractAsciidocInfo( + `[[this-is-the-anchor]] +== Heading here + +Intro. + +[discrete] +=== Another heading + +More details + ` + ); + + expect(firstParagraph).toEqual(`Intro.`); + expect(anchor).toEqual('this-is-the-anchor'); +}); diff --git a/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.ts b/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.ts new file mode 100644 index 000000000000..85b63141a217 --- /dev/null +++ b/packages/kbn-dev-utils/src/plugin_list/extract_asciidoc_info.ts @@ -0,0 +1,32 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export function extractAsciidocInfo(text: string): { firstParagraph?: string; anchor?: string } { + // First group is to grab the anchor - \[\[(.*)\]\] + // Tecond group, (== ), removes the equals from the header + // Third group could perhaps be done better, but is essentially: + // If there is a sub heading after the intro, match the intro and stop - (([\s\S]*?)(?=\=\=\=|\[\[))) + // If there is not a sub heading after the intro, match the intro - ([\s\S]*) + const matchAnchorAndIntro = /\[\[(.*)\]\]\n(== .*)\n(((([\s\S]*?)(?=\=\=\=|\[)))|([\s\S]*))/gm; + + const matches = matchAnchorAndIntro.exec(text); + const firstParagraph = matches && matches.length >= 4 ? matches[3].toString().trim() : undefined; + const anchor = matches && matches.length >= 2 ? matches[1].toString().trim() : undefined; + return { firstParagraph, anchor }; +} diff --git a/packages/kbn-dev-utils/src/plugin_list/generate_plugin_list.ts b/packages/kbn-dev-utils/src/plugin_list/generate_plugin_list.ts index f0f799862e24..43dac1cb7d41 100644 --- a/packages/kbn-dev-utils/src/plugin_list/generate_plugin_list.ts +++ b/packages/kbn-dev-utils/src/plugin_list/generate_plugin_list.ts @@ -24,21 +24,29 @@ import normalizePath from 'normalize-path'; import { REPO_ROOT } from '../repo_root'; import { Plugins } from './discover_plugins'; -function* printPlugins(plugins: Plugins) { +function* printPlugins(plugins: Plugins, includes: string[]) { for (const plugin of plugins) { const path = plugin.relativeReadmePath || plugin.relativeDir; yield ''; - yield `- {kib-repo}blob/{branch}/${path}[${plugin.id}]`; + + if (plugin.readmeAsciidocAnchor) { + yield `|<<${plugin.readmeAsciidocAnchor}>>`; + + includes.push(`include::{kibana-root}/${path}[leveloffset=+1]`); + } else { + yield `|{kib-repo}blob/{branch}/${path}[${plugin.id}]`; + } if (!plugin.relativeReadmePath || plugin.readmeSnippet) { - yield ''; - yield plugin.readmeSnippet || 'WARNING: Missing README.'; + yield plugin.readmeSnippet ? `|${plugin.readmeSnippet}` : '|WARNING: Missing README.'; yield ''; } } } export function generatePluginList(ossPlugins: Plugins, xpackPlugins: Plugins) { + const includes: string[] = []; + return `//// NOTE: @@ -53,32 +61,33 @@ NOTE: //// -[[code-exploration]] -== Exploring Kibana code +[[plugin-list]] +== List of {kib} plugins -The goals of our folder heirarchy are: +[discrete] +=== src/plugins -- Easy for developers to know where to add new services, plugins and applications. -- Easy for developers to know where to find the code from services, plugins and applications. -- Easy to browse and understand our folder structure. +[%header,cols=2*] +|=== +|Name +|Description -To that aim, we strive to: +${Array.from(printPlugins(ossPlugins, includes)).join('\n')} -- Avoid too many files in any given folder. -- Choose clear, unambigious folder names. -- Organize by domain. -- Every folder should contain a README that describes the contents of that folder. +|=== [discrete] -[[kibana-services-applications]] -=== Services and Applications +=== x-pack/plugins -[discrete] -==== src/plugins -${Array.from(printPlugins(ossPlugins)).join('\n')} +[%header,cols=2*] +|=== +|Name +|Description -[discrete] -==== x-pack/plugins -${Array.from(printPlugins(xpackPlugins)).join('\n')} +${Array.from(printPlugins(xpackPlugins, includes)).join('\n')} + +|=== + +${Array.from(includes).join('\n')} `; } diff --git a/packages/kbn-dev-utils/src/plugin_list/run_plugin_list_cli.ts b/packages/kbn-dev-utils/src/plugin_list/run_plugin_list_cli.ts index 817534ba5b15..553eb1dd8afa 100644 --- a/packages/kbn-dev-utils/src/plugin_list/run_plugin_list_cli.ts +++ b/packages/kbn-dev-utils/src/plugin_list/run_plugin_list_cli.ts @@ -28,10 +28,7 @@ import { generatePluginList } from './generate_plugin_list'; const OSS_PLUGIN_DIR = Path.resolve(REPO_ROOT, 'src/plugins'); const XPACK_PLUGIN_DIR = Path.resolve(REPO_ROOT, 'x-pack/plugins'); -const OUTPUT_PATH = Path.resolve( - REPO_ROOT, - 'docs/developer/architecture/code-exploration.asciidoc' -); +const OUTPUT_PATH = Path.resolve(REPO_ROOT, 'docs/developer/plugin-list.asciidoc'); export function runPluginListCli() { run(async ({ log }) => { diff --git a/packages/kbn-telemetry-tools/src/cli/run_telemetry_check.ts b/packages/kbn-telemetry-tools/src/cli/run_telemetry_check.ts index 116c484a5c36..2f85fd2cdd2a 100644 --- a/packages/kbn-telemetry-tools/src/cli/run_telemetry_check.ts +++ b/packages/kbn-telemetry-tools/src/cli/run_telemetry_check.ts @@ -65,7 +65,8 @@ export function runTelemetryCheck() { }, { title: 'Checking Matching collector.schema against stored json files', - task: (context) => new Listr(checkMatchingSchemasTask(context), { exitOnError: true }), + task: (context) => + new Listr(checkMatchingSchemasTask(context, !fix), { exitOnError: true }), }, { enabled: (_) => fix, diff --git a/packages/kbn-telemetry-tools/src/tools/tasks/check_matching_schemas_task.ts b/packages/kbn-telemetry-tools/src/tools/tasks/check_matching_schemas_task.ts index a1f23bcd44c7..2f73a0ee6ad4 100644 --- a/packages/kbn-telemetry-tools/src/tools/tasks/check_matching_schemas_task.ts +++ b/packages/kbn-telemetry-tools/src/tools/tasks/check_matching_schemas_task.ts @@ -22,7 +22,7 @@ import { TaskContext } from './task_context'; import { checkMatchingMapping } from '../check_collector_integrity'; import { readFileAsync } from '../utils'; -export function checkMatchingSchemasTask({ roots }: TaskContext) { +export function checkMatchingSchemasTask({ roots }: TaskContext, throwOnDiff: boolean) { return roots.map((root) => ({ task: async () => { const fullPath = path.resolve(process.cwd(), root.config.output); @@ -31,8 +31,16 @@ export function checkMatchingSchemasTask({ roots }: TaskContext) { if (root.parsedCollections) { const differences = checkMatchingMapping(root.parsedCollections, esMapping); - root.esMappingDiffs = Object.keys(differences); + if (root.esMappingDiffs.length && throwOnDiff) { + throw Error( + `The following changes must be persisted in ${fullPath} file. Use '--fix' to update.\n${JSON.stringify( + differences, + null, + 2 + )}` + ); + } } }, title: `Checking in ${root.config.root}`, diff --git a/src/core/server/core_app/integration_tests/static_assets.test.ts b/src/core/server/core_app/integration_tests/static_assets.test.ts index 23125cb3a670..160ef064a14d 100644 --- a/src/core/server/core_app/integration_tests/static_assets.test.ts +++ b/src/core/server/core_app/integration_tests/static_assets.test.ts @@ -23,7 +23,7 @@ describe('Platform assets', function () { let root: Root; beforeAll(async function () { - root = kbnTestServer.createRoot(); + root = kbnTestServer.createRoot({ plugins: { initialize: false } }); await root.setup(); await root.start(); diff --git a/src/core/server/elasticsearch/client/configure_client.test.ts b/src/core/server/elasticsearch/client/configure_client.test.ts index 11e3199a79fd..716e2fd98a5e 100644 --- a/src/core/server/elasticsearch/client/configure_client.test.ts +++ b/src/core/server/elasticsearch/client/configure_client.test.ts @@ -157,6 +157,44 @@ describe('configureClient', () => { `); }); + it('logs default error info when the error response body is empty', () => { + const client = configureClient(config, { logger, scoped: false }); + + let response = createApiResponse({ + statusCode: 400, + headers: {}, + body: { + error: {}, + }, + }); + client.emit('response', new errors.ResponseError(response), response); + + expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` + Array [ + Array [ + "[ResponseError]: Response Error", + ], + ] + `); + + logger.error.mockClear(); + + response = createApiResponse({ + statusCode: 400, + headers: {}, + body: {} as any, + }); + client.emit('response', new errors.ResponseError(response), response); + + expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(` + Array [ + Array [ + "[ResponseError]: Response Error", + ], + ] + `); + }); + it('logs each queries if `logQueries` is true', () => { const client = configureClient( createFakeConfig({ diff --git a/src/core/server/elasticsearch/client/configure_client.ts b/src/core/server/elasticsearch/client/configure_client.ts index 9746ecb538b7..a77734481306 100644 --- a/src/core/server/elasticsearch/client/configure_client.ts +++ b/src/core/server/elasticsearch/client/configure_client.ts @@ -21,7 +21,6 @@ import { stringify } from 'querystring'; import { Client } from '@elastic/elasticsearch'; import { Logger } from '../../logging'; import { parseClientOptions, ElasticsearchClientConfig } from './client_config'; -import { isResponseError } from './errors'; export const configureClient = ( config: ElasticsearchClientConfig, @@ -39,10 +38,8 @@ const addLogging = (client: Client, logger: Logger, logQueries: boolean) => { client.on('response', (error, event) => { if (error) { const errorMessage = - // error details for response errors provided by elasticsearch - isResponseError(error) - ? `[${event.body.error.type}]: ${event.body.error.reason}` - : `[${error.name}]: ${error.message}`; + // error details for response errors provided by elasticsearch, defaults to error name/message + `[${event.body?.error?.type ?? error.name}]: ${event.body?.error?.reason ?? error.message}`; logger.error(errorMessage); } diff --git a/src/core/server/http_resources/integration_tests/http_resources_service.test.ts b/src/core/server/http_resources/integration_tests/http_resources_service.test.ts index 0a5daa02e17e..eee7dc278607 100644 --- a/src/core/server/http_resources/integration_tests/http_resources_service.test.ts +++ b/src/core/server/http_resources/integration_tests/http_resources_service.test.ts @@ -28,6 +28,7 @@ describe('http resources service', () => { csp: { rules: [defaultCspRules], }, + plugins: { initialize: false }, }); }, 30000); diff --git a/src/core/server/legacy/integration_tests/legacy_service.test.ts b/src/core/server/legacy/integration_tests/legacy_service.test.ts index e8bcf7a42d19..1dc8d53e7c3d 100644 --- a/src/core/server/legacy/integration_tests/legacy_service.test.ts +++ b/src/core/server/legacy/integration_tests/legacy_service.test.ts @@ -22,7 +22,10 @@ describe('legacy service', () => { describe('http server', () => { let root: ReturnType; beforeEach(() => { - root = kbnTestServer.createRoot({ migrations: { skip: true } }); + root = kbnTestServer.createRoot({ + migrations: { skip: true }, + plugins: { initialize: false }, + }); }, 30000); afterEach(async () => await root.shutdown()); diff --git a/src/core/server/legacy/integration_tests/logging.test.ts b/src/core/server/legacy/integration_tests/logging.test.ts index 66234f677903..2581c85debf2 100644 --- a/src/core/server/legacy/integration_tests/logging.test.ts +++ b/src/core/server/legacy/integration_tests/logging.test.ts @@ -28,6 +28,7 @@ import { LegacyLoggingConfig } from '../config/legacy_object_to_config_adapter'; function createRoot(legacyLoggingConfig: LegacyLoggingConfig = {}) { return kbnTestServer.createRoot({ migrations: { skip: true }, // otherwise stuck in polling ES + plugins: { initialize: false }, logging: { // legacy platform config silent: false, diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index 0c1e8562a1de..f39282a6f9cb 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -322,6 +322,7 @@ export class LegacyService implements CoreService { }, status: { core$: setupDeps.core.status.core$, + overall$: setupDeps.core.status.overall$, }, uiSettings: { register: setupDeps.core.uiSettings.register, diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts index 5235f3ee6d58..62058f6d478e 100644 --- a/src/core/server/plugins/plugin_context.ts +++ b/src/core/server/plugins/plugin_context.ts @@ -178,6 +178,7 @@ export function createPluginSetupContext( }, status: { core$: deps.status.core$, + overall$: deps.status.overall$, }, uiSettings: { register: deps.uiSettings.register, diff --git a/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts b/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts index 5bc7d126ace0..7a0e39b71afb 100644 --- a/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts +++ b/src/core/server/saved_objects/routes/integration_tests/migrate.test.ts @@ -24,7 +24,7 @@ describe('SavedObjects /_migrate endpoint', () => { let root: ReturnType; beforeEach(async () => { - root = kbnTestServer.createRoot({ migrations: { skip: true } }); + root = kbnTestServer.createRoot({ migrations: { skip: true }, plugins: { initialize: false } }); await root.setup(); await root.start(); migratorInstanceMock.runMigrations.mockClear(); diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts index 623610eebd8d..3358de1c1031 100644 --- a/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts +++ b/src/core/server/saved_objects/service/lib/decorate_es_error.test.ts @@ -73,6 +73,15 @@ describe('savedObjectsClient/decorateEsError', () => { expect(SavedObjectsErrorHelpers.isConflictError(error)).toBe(true); }); + it('makes TooManyRequests a SavedObjectsClient/tooManyRequests error', () => { + const error = new esErrors.ResponseError( + elasticsearchClientMock.createApiResponse({ statusCode: 429 }) + ); + expect(SavedObjectsErrorHelpers.isTooManyRequestsError(error)).toBe(false); + expect(decorateEsError(error)).toBe(error); + expect(SavedObjectsErrorHelpers.isTooManyRequestsError(error)).toBe(true); + }); + it('makes NotAuthorized a SavedObjectsClient/NotAuthorized error', () => { const error = new esErrors.ResponseError( elasticsearchClientMock.createApiResponse({ statusCode: 401 }) diff --git a/src/core/server/saved_objects/service/lib/decorate_es_error.ts b/src/core/server/saved_objects/service/lib/decorate_es_error.ts index cf8a16cdaae6..592b268d8219 100644 --- a/src/core/server/saved_objects/service/lib/decorate_es_error.ts +++ b/src/core/server/saved_objects/service/lib/decorate_es_error.ts @@ -28,6 +28,7 @@ const responseErrors = { isRequestEntityTooLarge: (statusCode: number) => statusCode === 413, isNotFound: (statusCode: number) => statusCode === 404, isBadRequest: (statusCode: number) => statusCode === 400, + isTooManyRequests: (statusCode: number) => statusCode === 429, }; const { ConnectionError, NoLivingConnectionsError, TimeoutError } = esErrors; const SCRIPT_CONTEXT_DISABLED_REGEX = /(?:cannot execute scripts using \[)([a-z]*)(?:\] context)/; @@ -76,6 +77,10 @@ export function decorateEsError(error: EsErrors) { return SavedObjectsErrorHelpers.createGenericNotFoundError(); } + if (responseErrors.isTooManyRequests(error.statusCode)) { + return SavedObjectsErrorHelpers.decorateTooManyRequestsError(error, reason); + } + if (responseErrors.isBadRequest(error.statusCode)) { if ( SCRIPT_CONTEXT_DISABLED_REGEX.test(reason || '') || diff --git a/src/core/server/saved_objects/service/lib/errors.test.ts b/src/core/server/saved_objects/service/lib/errors.test.ts index 324d19e27921..931d9f725e41 100644 --- a/src/core/server/saved_objects/service/lib/errors.test.ts +++ b/src/core/server/saved_objects/service/lib/errors.test.ts @@ -274,6 +274,53 @@ describe('savedObjectsClient/errorTypes', () => { }); }); + describe('TooManyRequests error', () => { + describe('decorateTooManyRequestsError', () => { + it('returns original object', () => { + const error = new Error(); + expect(SavedObjectsErrorHelpers.decorateTooManyRequestsError(error)).toBe(error); + }); + + it('makes the error identifiable as a TooManyRequests error', () => { + const error = new Error(); + expect(SavedObjectsErrorHelpers.isTooManyRequestsError(error)).toBe(false); + SavedObjectsErrorHelpers.decorateTooManyRequestsError(error); + expect(SavedObjectsErrorHelpers.isTooManyRequestsError(error)).toBe(true); + }); + + it('adds boom properties', () => { + const error = SavedObjectsErrorHelpers.decorateTooManyRequestsError(new Error()); + expect(error).toHaveProperty('isBoom', true); + }); + + describe('error.output', () => { + it('defaults to message of error', () => { + const error = SavedObjectsErrorHelpers.decorateTooManyRequestsError(new Error('foobar')); + expect(error.output.payload).toHaveProperty('message', 'foobar'); + }); + + it('prefixes message with passed reason', () => { + const error = SavedObjectsErrorHelpers.decorateTooManyRequestsError( + new Error('foobar'), + 'biz' + ); + expect(error.output.payload).toHaveProperty('message', 'biz: foobar'); + }); + + it('sets statusCode to 429', () => { + const error = SavedObjectsErrorHelpers.decorateTooManyRequestsError(new Error('foo')); + expect(error.output).toHaveProperty('statusCode', 429); + }); + + it('preserves boom properties of input', () => { + const error = Boom.tooManyRequests(); + SavedObjectsErrorHelpers.decorateTooManyRequestsError(error); + expect(error.output).toHaveProperty('statusCode', 429); + }); + }); + }); + }); + describe('EsCannotExecuteScript error', () => { describe('decorateEsCannotExecuteScriptError', () => { it('returns original object', () => { diff --git a/src/core/server/saved_objects/service/lib/errors.ts b/src/core/server/saved_objects/service/lib/errors.ts index 9614d692741e..6fd5bc9de0ec 100644 --- a/src/core/server/saved_objects/service/lib/errors.ts +++ b/src/core/server/saved_objects/service/lib/errors.ts @@ -33,6 +33,8 @@ const CODE_REQUEST_ENTITY_TOO_LARGE = 'SavedObjectsClient/requestEntityTooLarge' const CODE_NOT_FOUND = 'SavedObjectsClient/notFound'; // 409 - Conflict const CODE_CONFLICT = 'SavedObjectsClient/conflict'; +// 429 - Too Many Requests +const CODE_TOO_MANY_REQUESTS = 'SavedObjectsClient/tooManyRequests'; // 400 - Es Cannot Execute Script const CODE_ES_CANNOT_EXECUTE_SCRIPT = 'SavedObjectsClient/esCannotExecuteScript'; // 503 - Es Unavailable @@ -162,6 +164,18 @@ export class SavedObjectsErrorHelpers { return isSavedObjectsClientError(error) && error[code] === CODE_CONFLICT; } + public static decorateTooManyRequestsError(error: Error, reason?: string) { + return decorate(error, CODE_TOO_MANY_REQUESTS, 429, reason); + } + + public static createTooManyRequestsError(type: string, id: string) { + return SavedObjectsErrorHelpers.decorateTooManyRequestsError(Boom.tooManyRequests()); + } + + public static isTooManyRequestsError(error: Error | DecoratedError) { + return isSavedObjectsClientError(error) && error[code] === CODE_TOO_MANY_REQUESTS; + } + public static decorateEsCannotExecuteScriptError(error: Error, reason?: string) { return decorate(error, CODE_ES_CANNOT_EXECUTE_SCRIPT, 400, reason); } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 772be68f507d..cd7f4973f886 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -2220,6 +2220,8 @@ export class SavedObjectsErrorHelpers { // (undocumented) static createInvalidVersionError(versionInput?: string): DecoratedError; // (undocumented) + static createTooManyRequestsError(type: string, id: string): DecoratedError; + // (undocumented) static createUnsupportedTypeError(type: string): DecoratedError; // (undocumented) static decorateBadRequestError(error: Error, reason?: string): DecoratedError; @@ -2238,6 +2240,8 @@ export class SavedObjectsErrorHelpers { // (undocumented) static decorateRequestEntityTooLargeError(error: Error, reason?: string): DecoratedError; // (undocumented) + static decorateTooManyRequestsError(error: Error, reason?: string): DecoratedError; + // (undocumented) static isBadRequestError(error: Error | DecoratedError): boolean; // (undocumented) static isConflictError(error: Error | DecoratedError): boolean; @@ -2259,6 +2263,8 @@ export class SavedObjectsErrorHelpers { // // (undocumented) static isSavedObjectsClientError(error: any): error is DecoratedError; + // (undocumented) + static isTooManyRequestsError(error: Error | DecoratedError): boolean; } // @public @@ -2796,6 +2802,7 @@ export type StartServicesAccessor; + overall$: Observable; } // @public diff --git a/src/core/server/status/status_service.mock.ts b/src/core/server/status/status_service.mock.ts index c6eb11be6967..47ef8659b407 100644 --- a/src/core/server/status/status_service.mock.ts +++ b/src/core/server/status/status_service.mock.ts @@ -39,6 +39,7 @@ const availableCoreStatus: CoreStatus = { const createSetupContractMock = () => { const setupContract: jest.Mocked = { core$: new BehaviorSubject(availableCoreStatus), + overall$: new BehaviorSubject(available), }; return setupContract; diff --git a/src/core/server/status/types.ts b/src/core/server/status/types.ts index b04c25a1eee9..2ecf11deb296 100644 --- a/src/core/server/status/types.ts +++ b/src/core/server/status/types.ts @@ -123,13 +123,20 @@ export interface StatusServiceSetup { * Current status for all Core services. */ core$: Observable; -} -/** @internal */ -export interface InternalStatusServiceSetup extends StatusServiceSetup { /** - * Overall system status used for HTTP API + * Overall system status for all of Kibana. + * + * @remarks + * The level of the overall status will reflect the most severe status of any core service or plugin. + * + * Exposed only for reporting purposes to outside systems and should not be used by plugins. Instead, plugins should + * only depend on the statuses of {@link StatusServiceSetup.core$ | Core} or their dependencies. */ overall$: Observable; +} + +/** @internal */ +export interface InternalStatusServiceSetup extends StatusServiceSetup { isStatusPageAnonymous: () => boolean; } diff --git a/src/core/server/ui_settings/integration_tests/routes.test.ts b/src/core/server/ui_settings/integration_tests/routes.test.ts index c1261bc7c135..b18cc370fac3 100644 --- a/src/core/server/ui_settings/integration_tests/routes.test.ts +++ b/src/core/server/ui_settings/integration_tests/routes.test.ts @@ -24,7 +24,7 @@ describe('ui settings service', () => { describe('routes', () => { let root: ReturnType; beforeAll(async () => { - root = kbnTestServer.createRoot(); + root = kbnTestServer.createRoot({ plugins: { initialize: false } }); const { uiSettings } = await root.setup(); uiSettings.register({ diff --git a/src/core/server/ui_settings/settings/accessibility.test.ts b/src/core/server/ui_settings/settings/accessibility.test.ts new file mode 100644 index 000000000000..8d8f9d00fada --- /dev/null +++ b/src/core/server/ui_settings/settings/accessibility.test.ts @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getAccessibilitySettings } from './accessibility'; + +describe('accessibility settings', () => { + const accessibilitySettings = getAccessibilitySettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('accessibility:disableAnimations', () => { + const validate = getValidationFn(accessibilitySettings['accessibility:disableAnimations']); + + it('should only accept boolean', () => { + expect(() => validate(true)).not.toThrow(); + expect(() => validate(false)).not.toThrow(); + + expect(() => validate(42)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/accessibility.ts b/src/core/server/ui_settings/settings/accessibility.ts new file mode 100644 index 000000000000..ddf3e53d9118 --- /dev/null +++ b/src/core/server/ui_settings/settings/accessibility.ts @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getAccessibilitySettings = (): Record => { + return { + 'accessibility:disableAnimations': { + name: i18n.translate('core.ui_settings.params.disableAnimationsTitle', { + defaultMessage: 'Disable Animations', + }), + value: false, + description: i18n.translate('core.ui_settings.params.disableAnimationsText', { + defaultMessage: + 'Turn off all unnecessary animations in the Kibana UI. Refresh the page to apply the changes.', + }), + category: ['accessibility'], + requiresPageReload: true, + schema: schema.boolean(), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/date_formats.test.ts b/src/core/server/ui_settings/settings/date_formats.test.ts new file mode 100644 index 000000000000..3c179af0b1d0 --- /dev/null +++ b/src/core/server/ui_settings/settings/date_formats.test.ts @@ -0,0 +1,104 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import moment from 'moment-timezone'; +import { UiSettingsParams } from '../../../types'; +import { getDateFormatSettings } from './date_formats'; + +describe('accessibility settings', () => { + const dateFormatSettings = getDateFormatSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('dateFormat', () => { + const validate = getValidationFn(dateFormatSettings.dateFormat); + + it('should only accept string values', () => { + expect(() => validate('some format')).not.toThrow(); + + expect(() => validate(42)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); + expect(() => validate(true)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [boolean]"` + ); + }); + }); + + describe('dateFormat:tz', () => { + const validate = getValidationFn(dateFormatSettings['dateFormat:tz']); + + it('should only accept valid timezones or `Browser`', () => { + expect(() => validate('Browser')).not.toThrow(); + expect(() => validate('UTC')).not.toThrow(); + + expect(() => validate('EST')).toThrowErrorMatchingInlineSnapshot(`"Invalid timezone: EST"`); + expect(() => validate('random string')).toThrowErrorMatchingInlineSnapshot( + `"Invalid timezone: random string"` + ); + }); + }); + + describe('dateFormat:scaled', () => { + const validate = getValidationFn(dateFormatSettings['dateFormat:scaled']); + + it('should only accept string values', () => { + expect(() => validate('some format')).not.toThrow(); + + expect(() => validate(42)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); + expect(() => validate(true)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [boolean]"` + ); + }); + }); + + describe('dateFormat:dow', () => { + const [validDay] = moment.weekdays(); + const validate = getValidationFn(dateFormatSettings['dateFormat:dow']); + + it('should only accept DOW values', () => { + expect(() => validate(validDay)).not.toThrow(); + + expect(() => validate('invalid value')).toThrowErrorMatchingInlineSnapshot( + `"Invalid day of week: invalid value"` + ); + expect(() => validate(true)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [boolean]"` + ); + }); + }); + + describe('dateNanosFormat', () => { + const validate = getValidationFn(dateFormatSettings.dateNanosFormat); + + it('should only accept string values', () => { + expect(() => validate('some format')).not.toThrow(); + + expect(() => validate(42)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); + expect(() => validate(true)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [boolean]"` + ); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/date_formats.ts b/src/core/server/ui_settings/settings/date_formats.ts new file mode 100644 index 000000000000..22351d36ac4b --- /dev/null +++ b/src/core/server/ui_settings/settings/date_formats.ts @@ -0,0 +1,168 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import moment from 'moment-timezone'; +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getDateFormatSettings = (): Record => { + const weekdays = moment.weekdays().slice(); + const [defaultWeekday] = weekdays; + + const timezones = [ + 'Browser', + ...moment.tz + .names() + // We need to filter out some time zones, that moment.js knows about, but Elasticsearch + // does not understand and would fail thus with a 400 bad request when using them. + .filter((tz) => !['America/Nuuk', 'EST', 'HST', 'ROC', 'MST'].includes(tz)), + ]; + + return { + dateFormat: { + name: i18n.translate('core.ui_settings.params.dateFormatTitle', { + defaultMessage: 'Date format', + }), + value: 'MMM D, YYYY @ HH:mm:ss.SSS', + description: i18n.translate('core.ui_settings.params.dateFormatText', { + defaultMessage: 'When displaying a pretty formatted date, use this {formatLink}', + description: + 'Part of composite text: core.ui_settings.params.dateFormatText + ' + + 'core.ui_settings.params.dateFormat.optionsLinkText', + values: { + formatLink: + '' + + i18n.translate('core.ui_settings.params.dateFormat.optionsLinkText', { + defaultMessage: 'format', + }) + + '', + }, + }), + schema: schema.string(), + }, + 'dateFormat:tz': { + name: i18n.translate('core.ui_settings.params.dateFormat.timezoneTitle', { + defaultMessage: 'Timezone for date formatting', + }), + value: 'Browser', + description: i18n.translate('core.ui_settings.params.dateFormat.timezoneText', { + defaultMessage: + 'Which timezone should be used. {defaultOption} will use the timezone detected by your browser.', + values: { + defaultOption: '"Browser"', + }, + }), + type: 'select', + options: timezones, + requiresPageReload: true, + schema: schema.string({ + validate: (value) => { + if (!timezones.includes(value)) { + return i18n.translate( + 'core.ui_settings.params.dateFormat.timezone.invalidValidationMessage', + { + defaultMessage: 'Invalid timezone: {timezone}', + values: { + timezone: value, + }, + } + ); + } + }, + }), + }, + 'dateFormat:scaled': { + name: i18n.translate('core.ui_settings.params.dateFormat.scaledTitle', { + defaultMessage: 'Scaled date format', + }), + type: 'json', + value: `[ + ["", "HH:mm:ss.SSS"], + ["PT1S", "HH:mm:ss"], + ["PT1M", "HH:mm"], + ["PT1H", "YYYY-MM-DD HH:mm"], + ["P1DT", "YYYY-MM-DD"], + ["P1YT", "YYYY"] +]`, + description: i18n.translate('core.ui_settings.params.dateFormat.scaledText', { + defaultMessage: + 'Values that define the format used in situations where time-based ' + + 'data is rendered in order, and formatted timestamps should adapt to the ' + + 'interval between measurements. Keys are {intervalsLink}.', + description: + 'Part of composite text: core.ui_settings.params.dateFormat.scaledText + ' + + 'core.ui_settings.params.dateFormat.scaled.intervalsLinkText', + values: { + intervalsLink: + '' + + i18n.translate('core.ui_settings.params.dateFormat.scaled.intervalsLinkText', { + defaultMessage: 'ISO8601 intervals', + }) + + '', + }, + }), + schema: schema.string(), + }, + 'dateFormat:dow': { + name: i18n.translate('core.ui_settings.params.dateFormat.dayOfWeekTitle', { + defaultMessage: 'Day of week', + }), + value: defaultWeekday, + description: i18n.translate('core.ui_settings.params.dateFormat.dayOfWeekText', { + defaultMessage: 'What day should weeks start on?', + }), + type: 'select', + options: weekdays, + schema: schema.string({ + validate: (value) => { + if (!weekdays.includes(value)) { + return i18n.translate( + 'core.ui_settings.params.dayOfWeekText.invalidValidationMessage', + { + defaultMessage: 'Invalid day of week: {dayOfWeek}', + values: { + dayOfWeek: value, + }, + } + ); + } + }, + }), + }, + dateNanosFormat: { + name: i18n.translate('core.ui_settings.params.dateNanosFormatTitle', { + defaultMessage: 'Date with nanoseconds format', + }), + value: 'MMM D, YYYY @ HH:mm:ss.SSSSSSSSS', + description: i18n.translate('core.ui_settings.params.dateNanosFormatText', { + defaultMessage: 'Used for the {dateNanosLink} datatype of Elasticsearch', + values: { + dateNanosLink: + '' + + i18n.translate('core.ui_settings.params.dateNanosLinkTitle', { + defaultMessage: 'date_nanos', + }) + + '', + }, + }), + schema: schema.string(), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/index.test.ts b/src/core/server/ui_settings/settings/index.test.ts new file mode 100644 index 000000000000..e234160fbb4a --- /dev/null +++ b/src/core/server/ui_settings/settings/index.test.ts @@ -0,0 +1,44 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { getAccessibilitySettings } from './accessibility'; +import { getDateFormatSettings } from './date_formats'; +import { getMiscUiSettings } from './misc'; +import { getNavigationSettings } from './navigation'; +import { getNotificationsSettings } from './notifications'; +import { getThemeSettings } from './theme'; +import { getCoreSettings } from './index'; +import { getStateSettings } from './state'; + +describe('getCoreSettings', () => { + it('should not have setting overlaps', () => { + const coreSettingsLength = Object.keys(getCoreSettings()).length; + const summedLength = [ + getAccessibilitySettings(), + getDateFormatSettings(), + getMiscUiSettings(), + getNavigationSettings(), + getNotificationsSettings(), + getThemeSettings(), + getStateSettings(), + ].reduce((sum, settings) => sum + Object.keys(settings).length, 0); + + expect(coreSettingsLength).toBe(summedLength); + }); +}); diff --git a/src/core/server/ui_settings/settings/index.ts b/src/core/server/ui_settings/settings/index.ts new file mode 100644 index 000000000000..88baf7cd22ee --- /dev/null +++ b/src/core/server/ui_settings/settings/index.ts @@ -0,0 +1,39 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getAccessibilitySettings } from './accessibility'; +import { getDateFormatSettings } from './date_formats'; +import { getMiscUiSettings } from './misc'; +import { getNavigationSettings } from './navigation'; +import { getNotificationsSettings } from './notifications'; +import { getThemeSettings } from './theme'; +import { getStateSettings } from './state'; + +export const getCoreSettings = (): Record => { + return { + ...getAccessibilitySettings(), + ...getDateFormatSettings(), + ...getMiscUiSettings(), + ...getNavigationSettings(), + ...getNotificationsSettings(), + ...getThemeSettings(), + ...getStateSettings(), + }; +}; diff --git a/src/core/server/ui_settings/settings/misc.test.ts b/src/core/server/ui_settings/settings/misc.test.ts new file mode 100644 index 000000000000..db2c039d9b42 --- /dev/null +++ b/src/core/server/ui_settings/settings/misc.test.ts @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getMiscUiSettings } from './misc'; + +describe('misc settings', () => { + const miscSettings = getMiscUiSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('truncate:maxHeight', () => { + const validate = getValidationFn(miscSettings['truncate:maxHeight']); + + it('should only accept positive numeric values', () => { + expect(() => validate(127)).not.toThrow(); + expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot( + `"Value must be equal to or greater than [0]."` + ); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [number] but got [string]"` + ); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/misc.ts b/src/core/server/ui_settings/settings/misc.ts new file mode 100644 index 000000000000..d158b07839c6 --- /dev/null +++ b/src/core/server/ui_settings/settings/misc.ts @@ -0,0 +1,42 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { i18n } from '@kbn/i18n'; +import { schema } from '@kbn/config-schema'; +import { UiSettingsParams } from '../types'; + +export const getMiscUiSettings = (): Record => { + return { + 'truncate:maxHeight': { + name: i18n.translate('core.ui_settings.params.maxCellHeightTitle', { + defaultMessage: 'Maximum table cell height', + }), + value: 115, + description: i18n.translate('core.ui_settings.params.maxCellHeightText', { + defaultMessage: + 'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation', + }), + schema: schema.number({ min: 0 }), + }, + buildNum: { + readonly: true, + schema: schema.maybe(schema.number()), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/navigation.test.ts b/src/core/server/ui_settings/settings/navigation.test.ts new file mode 100644 index 000000000000..40cd0e172468 --- /dev/null +++ b/src/core/server/ui_settings/settings/navigation.test.ts @@ -0,0 +1,56 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getNavigationSettings } from './navigation'; + +describe('navigation settings', () => { + const navigationSettings = getNavigationSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('defaultRoute', () => { + const validate = getValidationFn(navigationSettings.defaultRoute); + + it('should only accept relative urls', () => { + expect(() => validate('/some-url')).not.toThrow(); + expect(() => validate('http://some-url')).toThrowErrorMatchingInlineSnapshot( + `"Must be a relative URL."` + ); + expect(() => validate(125)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); + }); + }); + + describe('pageNavigation', () => { + const validate = getValidationFn(navigationSettings.pageNavigation); + + it('should only accept valid values', () => { + expect(() => validate('modern')).not.toThrow(); + expect(() => validate('legacy')).not.toThrow(); + expect(() => validate('invalid')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value to equal [modern] +- [1]: expected value to equal [legacy]" +`); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/navigation.ts b/src/core/server/ui_settings/settings/navigation.ts new file mode 100644 index 000000000000..6483e86a1395 --- /dev/null +++ b/src/core/server/ui_settings/settings/navigation.ts @@ -0,0 +1,72 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; +import { isRelativeUrl } from '../../../utils'; + +export const getNavigationSettings = (): Record => { + return { + defaultRoute: { + name: i18n.translate('core.ui_settings.params.defaultRoute.defaultRouteTitle', { + defaultMessage: 'Default route', + }), + value: '/app/home', + schema: schema.string({ + validate(value) { + if (!value.startsWith('/') || !isRelativeUrl(value)) { + return i18n.translate( + 'core.ui_settings.params.defaultRoute.defaultRouteIsRelativeValidationMessage', + { + defaultMessage: 'Must be a relative URL.', + } + ); + } + }, + }), + description: i18n.translate('core.ui_settings.params.defaultRoute.defaultRouteText', { + defaultMessage: + 'This setting specifies the default route when opening Kibana. ' + + 'You can use this setting to modify the landing page when opening Kibana. ' + + 'The route must be a relative URL.', + }), + }, + pageNavigation: { + name: i18n.translate('core.ui_settings.params.pageNavigationName', { + defaultMessage: 'Side nav style', + }), + value: 'modern', + description: i18n.translate('core.ui_settings.params.pageNavigationDesc', { + defaultMessage: 'Change the style of navigation', + }), + type: 'select', + options: ['modern', 'legacy'], + optionLabels: { + modern: i18n.translate('core.ui_settings.params.pageNavigationModern', { + defaultMessage: 'Modern', + }), + legacy: i18n.translate('core.ui_settings.params.pageNavigationLegacy', { + defaultMessage: 'Legacy', + }), + }, + schema: schema.oneOf([schema.literal('modern'), schema.literal('legacy')]), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/notifications.test.ts b/src/core/server/ui_settings/settings/notifications.test.ts new file mode 100644 index 000000000000..e1bdf63c7e0d --- /dev/null +++ b/src/core/server/ui_settings/settings/notifications.test.ts @@ -0,0 +1,118 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getNotificationsSettings } from './notifications'; + +describe('notifications settings', () => { + const notificationsSettings = getNotificationsSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('notifications:banner', () => { + const validate = getValidationFn(notificationsSettings['notifications:banner']); + + it('should only accept string values', () => { + expect(() => validate('some text')).not.toThrow(); + expect(() => validate(true)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [boolean]"` + ); + expect(() => validate(12)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [string] but got [number]"` + ); + }); + }); + + describe('notifications:lifetime:banner', () => { + const validate = getValidationFn(notificationsSettings['notifications:lifetime:banner']); + + it('should only accept positive numeric values or `Infinity`', () => { + expect(() => validate(42)).not.toThrow(); + expect(() => validate('Infinity')).not.toThrow(); + expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: Value must be equal to or greater than [0]. +- [1]: expected value to equal [Infinity]" +`); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [number] but got [string] +- [1]: expected value to equal [Infinity]" +`); + }); + }); + + describe('notifications:lifetime:error', () => { + const validate = getValidationFn(notificationsSettings['notifications:lifetime:error']); + + it('should only accept positive numeric values or `Infinity`', () => { + expect(() => validate(42)).not.toThrow(); + expect(() => validate('Infinity')).not.toThrow(); + expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: Value must be equal to or greater than [0]. +- [1]: expected value to equal [Infinity]" +`); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [number] but got [string] +- [1]: expected value to equal [Infinity]" +`); + }); + }); + + describe('notifications:lifetime:warning', () => { + const validate = getValidationFn(notificationsSettings['notifications:lifetime:warning']); + + it('should only accept positive numeric values or `Infinity`', () => { + expect(() => validate(42)).not.toThrow(); + expect(() => validate('Infinity')).not.toThrow(); + expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: Value must be equal to or greater than [0]. +- [1]: expected value to equal [Infinity]" +`); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [number] but got [string] +- [1]: expected value to equal [Infinity]" +`); + }); + }); + + describe('notifications:lifetime:info', () => { + const validate = getValidationFn(notificationsSettings['notifications:lifetime:info']); + + it('should only accept positive numeric values or `Infinity`', () => { + expect(() => validate(42)).not.toThrow(); + expect(() => validate('Infinity')).not.toThrow(); + expect(() => validate(-12)).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: Value must be equal to or greater than [0]. +- [1]: expected value to equal [Infinity]" +`); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value of type [number] but got [string] +- [1]: expected value to equal [Infinity]" +`); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/notifications.ts b/src/core/server/ui_settings/settings/notifications.ts new file mode 100644 index 000000000000..7d9e70dc9036 --- /dev/null +++ b/src/core/server/ui_settings/settings/notifications.ts @@ -0,0 +1,120 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getNotificationsSettings = (): Record => { + return { + 'notifications:banner': { + name: i18n.translate('core.ui_settings.params.notifications.bannerTitle', { + defaultMessage: 'Custom banner notification', + }), + value: '', + type: 'markdown', + description: i18n.translate('core.ui_settings.params.notifications.bannerText', { + defaultMessage: + 'A custom banner intended for temporary notices to all users. {markdownLink}.', + description: + 'Part of composite text: core.ui_settings.params.notifications.bannerText + ' + + 'core.ui_settings.params.notifications.banner.markdownLinkText', + values: { + markdownLink: + `` + + i18n.translate('core.ui_settings.params.notifications.banner.markdownLinkText', { + defaultMessage: 'Markdown supported', + }) + + '', + }, + }), + category: ['notifications'], + schema: schema.string(), + }, + 'notifications:lifetime:banner': { + name: i18n.translate('core.ui_settings.params.notifications.bannerLifetimeTitle', { + defaultMessage: 'Banner notification lifetime', + }), + value: 3000000, + description: i18n.translate('core.ui_settings.params.notifications.bannerLifetimeText', { + defaultMessage: + 'The time in milliseconds which a banner notification will be displayed on-screen for. ' + + 'Setting to {infinityValue} will disable the countdown.', + values: { + infinityValue: 'Infinity', + }, + }), + type: 'number', + category: ['notifications'], + schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), + }, + 'notifications:lifetime:error': { + name: i18n.translate('core.ui_settings.params.notifications.errorLifetimeTitle', { + defaultMessage: 'Error notification lifetime', + }), + value: 300000, + description: i18n.translate('core.ui_settings.params.notifications.errorLifetimeText', { + defaultMessage: + 'The time in milliseconds which an error notification will be displayed on-screen for. ' + + 'Setting to {infinityValue} will disable.', + values: { + infinityValue: 'Infinity', + }, + }), + type: 'number', + category: ['notifications'], + schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), + }, + 'notifications:lifetime:warning': { + name: i18n.translate('core.ui_settings.params.notifications.warningLifetimeTitle', { + defaultMessage: 'Warning notification lifetime', + }), + value: 10000, + description: i18n.translate('core.ui_settings.params.notifications.warningLifetimeText', { + defaultMessage: + 'The time in milliseconds which a warning notification will be displayed on-screen for. ' + + 'Setting to {infinityValue} will disable.', + values: { + infinityValue: 'Infinity', + }, + }), + type: 'number', + category: ['notifications'], + schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), + }, + 'notifications:lifetime:info': { + name: i18n.translate('core.ui_settings.params.notifications.infoLifetimeTitle', { + defaultMessage: 'Info notification lifetime', + }), + value: 5000, + description: i18n.translate('core.ui_settings.params.notifications.infoLifetimeText', { + defaultMessage: + 'The time in milliseconds which an information notification will be displayed on-screen for. ' + + 'Setting to {infinityValue} will disable.', + values: { + infinityValue: 'Infinity', + }, + }), + type: 'number', + category: ['notifications'], + schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/state.test.ts b/src/core/server/ui_settings/settings/state.test.ts new file mode 100644 index 000000000000..7be30abe71bb --- /dev/null +++ b/src/core/server/ui_settings/settings/state.test.ts @@ -0,0 +1,43 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getStateSettings } from './state'; + +describe('state settings', () => { + const state = getStateSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('state:storeInSessionStorage', () => { + const validate = getValidationFn(state['state:storeInSessionStorage']); + + it('should only accept boolean values', () => { + expect(() => validate(true)).not.toThrow(); + expect(() => validate(false)).not.toThrow(); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); + expect(() => validate(12)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/state.ts b/src/core/server/ui_settings/settings/state.ts new file mode 100644 index 000000000000..ee85cc844259 --- /dev/null +++ b/src/core/server/ui_settings/settings/state.ts @@ -0,0 +1,40 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getStateSettings = (): Record => { + return { + 'state:storeInSessionStorage': { + name: i18n.translate('core.ui_settings.params.storeUrlTitle', { + defaultMessage: 'Store URLs in session storage', + }), + value: false, + description: i18n.translate('core.ui_settings.params.storeUrlText', { + defaultMessage: + 'The URL can sometimes grow to be too large for some browsers to handle. ' + + 'To counter-act this we are testing if storing parts of the URL in session storage could help. ' + + 'Please let us know how it goes!', + }), + schema: schema.boolean(), + }, + }; +}; diff --git a/src/core/server/ui_settings/settings/theme.test.ts b/src/core/server/ui_settings/settings/theme.test.ts new file mode 100644 index 000000000000..eb18bcc2dd0c --- /dev/null +++ b/src/core/server/ui_settings/settings/theme.test.ts @@ -0,0 +1,57 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { UiSettingsParams } from '../../../types'; +import { getThemeSettings } from './theme'; + +describe('theme settings', () => { + const themeSettings = getThemeSettings(); + + const getValidationFn = (setting: UiSettingsParams) => (value: any) => + setting.schema.validate(value); + + describe('theme:darkMode', () => { + const validate = getValidationFn(themeSettings['theme:darkMode']); + + it('should only accept boolean values', () => { + expect(() => validate(true)).not.toThrow(); + expect(() => validate(false)).not.toThrow(); + expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [string]"` + ); + expect(() => validate(12)).toThrowErrorMatchingInlineSnapshot( + `"expected value of type [boolean] but got [number]"` + ); + }); + }); + + describe('theme:version', () => { + const validate = getValidationFn(themeSettings['theme:version']); + + it('should only accept valid values', () => { + expect(() => validate('v7')).not.toThrow(); + expect(() => validate('v8 (beta)')).not.toThrow(); + expect(() => validate('v12')).toThrowErrorMatchingInlineSnapshot(` +"types that failed validation: +- [0]: expected value to equal [v7] +- [1]: expected value to equal [v8 (beta)]" +`); + }); + }); +}); diff --git a/src/core/server/ui_settings/settings/theme.ts b/src/core/server/ui_settings/settings/theme.ts new file mode 100644 index 000000000000..9f1857932f01 --- /dev/null +++ b/src/core/server/ui_settings/settings/theme.ts @@ -0,0 +1,51 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { schema } from '@kbn/config-schema'; +import { i18n } from '@kbn/i18n'; +import { UiSettingsParams } from '../../../types'; + +export const getThemeSettings = (): Record => { + return { + 'theme:darkMode': { + name: i18n.translate('core.ui_settings.params.darkModeTitle', { + defaultMessage: 'Dark mode', + }), + value: false, + description: i18n.translate('core.ui_settings.params.darkModeText', { + defaultMessage: `Enable a dark mode for the Kibana UI. A page refresh is required for the setting to be applied.`, + }), + requiresPageReload: true, + schema: schema.boolean(), + }, + 'theme:version': { + name: i18n.translate('core.ui_settings.params.themeVersionTitle', { + defaultMessage: 'Theme version', + }), + value: 'v7', + type: 'select', + options: ['v7', 'v8 (beta)'], + description: i18n.translate('core.ui_settings.params.themeVersionText', { + defaultMessage: `Switch between the theme used for the current and next version of Kibana. A page refresh is required for the setting to be applied.`, + }), + requiresPageReload: true, + schema: schema.oneOf([schema.literal('v7'), schema.literal('v8 (beta)')]), + }, + }; +}; diff --git a/src/core/server/ui_settings/ui_settings_config.ts b/src/core/server/ui_settings/ui_settings_config.ts index a0ac48e2dd08..3a3573a06d49 100644 --- a/src/core/server/ui_settings/ui_settings_config.ts +++ b/src/core/server/ui_settings/ui_settings_config.ts @@ -27,20 +27,7 @@ const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) => ]; const configSchema = schema.object({ - overrides: schema.object( - { - defaultRoute: schema.maybe( - schema.string({ - validate(value) { - if (!value.startsWith('/')) { - return 'must start with a slash'; - } - }, - }) - ), - }, - { unknowns: 'allow' } - ), + overrides: schema.object({}, { unknowns: 'allow' }), }); export type UiSettingsConfigType = TypeOf; diff --git a/src/core/server/ui_settings/ui_settings_service.test.mock.ts b/src/core/server/ui_settings/ui_settings_service.test.mock.ts index 586ad3049ed6..b4e98f55e159 100644 --- a/src/core/server/ui_settings/ui_settings_service.test.mock.ts +++ b/src/core/server/ui_settings/ui_settings_service.test.mock.ts @@ -18,7 +18,11 @@ */ export const MockUiSettingsClientConstructor = jest.fn(); - jest.doMock('./ui_settings_client', () => ({ UiSettingsClient: MockUiSettingsClientConstructor, })); + +export const getCoreSettingsMock = jest.fn(); +jest.doMock('./settings', () => ({ + getCoreSettings: getCoreSettingsMock, +})); diff --git a/src/core/server/ui_settings/ui_settings_service.test.ts b/src/core/server/ui_settings/ui_settings_service.test.ts index 096ca347e6f4..0c17a3a614d6 100644 --- a/src/core/server/ui_settings/ui_settings_service.test.ts +++ b/src/core/server/ui_settings/ui_settings_service.test.ts @@ -19,7 +19,10 @@ import { BehaviorSubject } from 'rxjs'; import { schema } from '@kbn/config-schema'; -import { MockUiSettingsClientConstructor } from './ui_settings_service.test.mock'; +import { + MockUiSettingsClientConstructor, + getCoreSettingsMock, +} from './ui_settings_service.test.mock'; import { UiSettingsService, SetupDeps } from './ui_settings_service'; import { httpServiceMock } from '../http/http_service.mock'; import { savedObjectsClientMock } from '../mocks'; @@ -58,6 +61,7 @@ describe('uiSettings', () => { afterEach(() => { MockUiSettingsClientConstructor.mockClear(); + getCoreSettingsMock.mockClear(); }); describe('#setup', () => { @@ -67,6 +71,11 @@ describe('uiSettings', () => { expect(setupDeps.savedObjects.registerType).toHaveBeenCalledWith(uiSettingsType); }); + it('calls `getCoreSettings`', async () => { + await service.setup(setupDeps); + expect(getCoreSettingsMock).toHaveBeenCalledTimes(1); + }); + describe('#register', () => { it('throws if registers the same key twice', async () => { const setup = await service.setup(setupDeps); diff --git a/src/core/server/ui_settings/ui_settings_service.ts b/src/core/server/ui_settings/ui_settings_service.ts index 93593b29221d..8598cf7a6228 100644 --- a/src/core/server/ui_settings/ui_settings_service.ts +++ b/src/core/server/ui_settings/ui_settings_service.ts @@ -36,6 +36,7 @@ import { import { mapToObject } from '../../utils/'; import { uiSettingsType } from './saved_objects'; import { registerRoutes } from './routes'; +import { getCoreSettings } from './settings'; export interface SetupDeps { http: InternalHttpServiceSetup; @@ -60,6 +61,8 @@ export class UiSettingsService savedObjects.registerType(uiSettingsType); registerRoutes(http.createRouter('')); + this.register(getCoreSettings()); + const config = await this.config$.pipe(first()).toPromise(); this.overrides = config.overrides; diff --git a/src/dev/build/tasks/os_packages/docker_generator/run.ts b/src/dev/build/tasks/os_packages/docker_generator/run.ts index 6cf4a7af7084..362c34d41674 100644 --- a/src/dev/build/tasks/os_packages/docker_generator/run.ts +++ b/src/dev/build/tasks/os_packages/docker_generator/run.ts @@ -58,8 +58,8 @@ export async function runDockerGenerator( 'kibana-docker', build.isOss() ? `oss` : `default${ubiImageFlavor}` ); - const dockerOutputDir = config.resolveFromTarget( - `kibana${imageFlavor}${ubiImageFlavor}-${version}-docker.tar.gz` + const dockerTargetFilename = config.resolveFromTarget( + `kibana${imageFlavor}${ubiImageFlavor}-${version}-docker-image.tar.gz` ); const scope: TemplateContext = { artifactTarball, @@ -69,7 +69,7 @@ export async function runDockerGenerator( artifactsDir, imageTag, dockerBuildDir, - dockerOutputDir, + dockerTargetFilename, baseOSImage, ubiImageFlavor, dockerBuildDate, diff --git a/src/dev/build/tasks/os_packages/docker_generator/template_context.ts b/src/dev/build/tasks/os_packages/docker_generator/template_context.ts index a7c40db44b87..49fb173c5a89 100644 --- a/src/dev/build/tasks/os_packages/docker_generator/template_context.ts +++ b/src/dev/build/tasks/os_packages/docker_generator/template_context.ts @@ -25,7 +25,7 @@ export interface TemplateContext { artifactsDir: string; imageTag: string; dockerBuildDir: string; - dockerOutputDir: string; + dockerTargetFilename: string; baseOSImage: string; ubiImageFlavor: string; dockerBuildDate: string; diff --git a/src/dev/build/tasks/os_packages/docker_generator/templates/build_docker_sh.template.ts b/src/dev/build/tasks/os_packages/docker_generator/templates/build_docker_sh.template.ts index 699bba758e1c..86a02d74dea1 100644 --- a/src/dev/build/tasks/os_packages/docker_generator/templates/build_docker_sh.template.ts +++ b/src/dev/build/tasks/os_packages/docker_generator/templates/build_docker_sh.template.ts @@ -25,7 +25,7 @@ function generator({ imageTag, imageFlavor, version, - dockerOutputDir, + dockerTargetFilename, baseOSImage, ubiImageFlavor, }: TemplateContext) { @@ -41,7 +41,7 @@ function generator({ echo "Building: kibana${imageFlavor}${ubiImageFlavor}-docker"; \\ docker build -t ${imageTag}${imageFlavor}${ubiImageFlavor}:${version} -f Dockerfile . || exit 1; - docker save ${imageTag}${imageFlavor}${ubiImageFlavor}:${version} | gzip -c > ${dockerOutputDir} + docker save ${imageTag}${imageFlavor}${ubiImageFlavor}:${version} | gzip -c > ${dockerTargetFilename} exit 0 `); diff --git a/src/legacy/core_plugins/kibana/server/ui_setting_defaults.js b/src/legacy/core_plugins/kibana/server/ui_setting_defaults.js index 625c2c02510d..2562657a7162 100644 --- a/src/legacy/core_plugins/kibana/server/ui_setting_defaults.js +++ b/src/legacy/core_plugins/kibana/server/ui_setting_defaults.js @@ -17,159 +17,11 @@ * under the License. */ -import moment from 'moment-timezone'; import { i18n } from '@kbn/i18n'; -import { schema } from '@kbn/config-schema'; - -import { isRelativeUrl } from '../../../../core/server'; export function getUiSettingDefaults() { - const weekdays = moment.weekdays().slice(); - const [defaultWeekday] = weekdays; - // wrapped in provider so that a new instance is given to each app/test return { - buildNum: { - readonly: true, - }, - 'state:storeInSessionStorage': { - name: i18n.translate('kbn.advancedSettings.storeUrlTitle', { - defaultMessage: 'Store URLs in session storage', - }), - value: false, - description: i18n.translate('kbn.advancedSettings.storeUrlText', { - defaultMessage: - 'The URL can sometimes grow to be too large for some browsers to handle. ' + - 'To counter-act this we are testing if storing parts of the URL in session storage could help. ' + - 'Please let us know how it goes!', - }), - }, - defaultRoute: { - name: i18n.translate('kbn.advancedSettings.defaultRoute.defaultRouteTitle', { - defaultMessage: 'Default route', - }), - value: '/app/home', - schema: schema.string({ - validate(value) { - if (!value.startsWith('/') || !isRelativeUrl(value)) { - return i18n.translate( - 'kbn.advancedSettings.defaultRoute.defaultRouteIsRelativeValidationMessage', - { - defaultMessage: 'Must be a relative URL.', - } - ); - } - }, - }), - description: i18n.translate('kbn.advancedSettings.defaultRoute.defaultRouteText', { - defaultMessage: - 'This setting specifies the default route when opening Kibana. ' + - 'You can use this setting to modify the landing page when opening Kibana. ' + - 'The route must be a relative URL.', - }), - }, - dateFormat: { - name: i18n.translate('kbn.advancedSettings.dateFormatTitle', { - defaultMessage: 'Date format', - }), - value: 'MMM D, YYYY @ HH:mm:ss.SSS', - description: i18n.translate('kbn.advancedSettings.dateFormatText', { - defaultMessage: 'When displaying a pretty formatted date, use this {formatLink}', - description: - 'Part of composite text: kbn.advancedSettings.dateFormatText + ' + - 'kbn.advancedSettings.dateFormat.optionsLinkText', - values: { - formatLink: - '' + - i18n.translate('kbn.advancedSettings.dateFormat.optionsLinkText', { - defaultMessage: 'format', - }) + - '', - }, - }), - }, - 'dateFormat:tz': { - name: i18n.translate('kbn.advancedSettings.dateFormat.timezoneTitle', { - defaultMessage: 'Timezone for date formatting', - }), - value: 'Browser', - description: i18n.translate('kbn.advancedSettings.dateFormat.timezoneText', { - defaultMessage: - 'Which timezone should be used. {defaultOption} will use the timezone detected by your browser.', - values: { - defaultOption: '"Browser"', - }, - }), - type: 'select', - options: [ - 'Browser', - ...moment.tz - .names() - // We need to filter out some time zones, that moment.js knows about, but Elasticsearch - // does not understand and would fail thus with a 400 bad request when using them. - .filter((tz) => !['America/Nuuk', 'EST', 'HST', 'ROC', 'MST'].includes(tz)), - ], - requiresPageReload: true, - }, - 'dateFormat:scaled': { - name: i18n.translate('kbn.advancedSettings.dateFormat.scaledTitle', { - defaultMessage: 'Scaled date format', - }), - type: 'json', - value: `[ - ["", "HH:mm:ss.SSS"], - ["PT1S", "HH:mm:ss"], - ["PT1M", "HH:mm"], - ["PT1H", "YYYY-MM-DD HH:mm"], - ["P1DT", "YYYY-MM-DD"], - ["P1YT", "YYYY"] -]`, - description: i18n.translate('kbn.advancedSettings.dateFormat.scaledText', { - defaultMessage: - 'Values that define the format used in situations where time-based ' + - 'data is rendered in order, and formatted timestamps should adapt to the ' + - 'interval between measurements. Keys are {intervalsLink}.', - description: - 'Part of composite text: kbn.advancedSettings.dateFormat.scaledText + ' + - 'kbn.advancedSettings.dateFormat.scaled.intervalsLinkText', - values: { - intervalsLink: - '' + - i18n.translate('kbn.advancedSettings.dateFormat.scaled.intervalsLinkText', { - defaultMessage: 'ISO8601 intervals', - }) + - '', - }, - }), - }, - 'dateFormat:dow': { - name: i18n.translate('kbn.advancedSettings.dateFormat.dayOfWeekTitle', { - defaultMessage: 'Day of week', - }), - value: defaultWeekday, - description: i18n.translate('kbn.advancedSettings.dateFormat.dayOfWeekText', { - defaultMessage: 'What day should weeks start on?', - }), - type: 'select', - options: weekdays, - }, - dateNanosFormat: { - name: i18n.translate('kbn.advancedSettings.dateNanosFormatTitle', { - defaultMessage: 'Date with nanoseconds format', - }), - value: 'MMM D, YYYY @ HH:mm:ss.SSSSSSSSS', - description: i18n.translate('kbn.advancedSettings.dateNanosFormatText', { - defaultMessage: 'Used for the {dateNanosLink} datatype of Elasticsearch', - values: { - dateNanosLink: - '' + - i18n.translate('kbn.advancedSettings.dateNanosLinkTitle', { - defaultMessage: 'date_nanos', - }) + - '', - }, - }), - }, 'visualization:tileMap:maxPrecision': { name: i18n.translate('kbn.advancedSettings.visualization.tileMap.maxPrecisionTitle', { defaultMessage: 'Maximum tile map precision', @@ -248,157 +100,5 @@ export function getUiSettingDefaults() { }), category: ['visualization'], }, - 'truncate:maxHeight': { - name: i18n.translate('kbn.advancedSettings.maxCellHeightTitle', { - defaultMessage: 'Maximum table cell height', - }), - value: 115, - description: i18n.translate('kbn.advancedSettings.maxCellHeightText', { - defaultMessage: - 'The maximum height that a cell in a table should occupy. Set to 0 to disable truncation', - }), - }, - 'theme:darkMode': { - name: i18n.translate('kbn.advancedSettings.darkModeTitle', { - defaultMessage: 'Dark mode', - }), - value: false, - description: i18n.translate('kbn.advancedSettings.darkModeText', { - defaultMessage: `Enable a dark mode for the Kibana UI. A page refresh is required for the setting to be applied.`, - }), - requiresPageReload: true, - }, - 'theme:version': { - name: i18n.translate('kbn.advancedSettings.themeVersionTitle', { - defaultMessage: 'Theme version', - }), - value: 'v7', - type: 'select', - options: ['v7', 'v8 (beta)'], - description: i18n.translate('kbn.advancedSettings.themeVersionText', { - defaultMessage: `Switch between the theme used for the current and next version of Kibana. A page refresh is required for the setting to be applied.`, - }), - requiresPageReload: true, - }, - 'notifications:banner': { - name: i18n.translate('kbn.advancedSettings.notifications.bannerTitle', { - defaultMessage: 'Custom banner notification', - }), - value: '', - type: 'markdown', - description: i18n.translate('kbn.advancedSettings.notifications.bannerText', { - defaultMessage: - 'A custom banner intended for temporary notices to all users. {markdownLink}.', - description: - 'Part of composite text: kbn.advancedSettings.notifications.bannerText + ' + - 'kbn.advancedSettings.notifications.banner.markdownLinkText', - values: { - markdownLink: - `` + - i18n.translate('kbn.advancedSettings.notifications.banner.markdownLinkText', { - defaultMessage: 'Markdown supported', - }) + - '', - }, - }), - category: ['notifications'], - }, - 'notifications:lifetime:banner': { - name: i18n.translate('kbn.advancedSettings.notifications.bannerLifetimeTitle', { - defaultMessage: 'Banner notification lifetime', - }), - value: 3000000, - description: i18n.translate('kbn.advancedSettings.notifications.bannerLifetimeText', { - defaultMessage: - 'The time in milliseconds which a banner notification will be displayed on-screen for. ' + - 'Setting to {infinityValue} will disable the countdown.', - values: { - infinityValue: 'Infinity', - }, - }), - type: 'number', - category: ['notifications'], - }, - 'notifications:lifetime:error': { - name: i18n.translate('kbn.advancedSettings.notifications.errorLifetimeTitle', { - defaultMessage: 'Error notification lifetime', - }), - value: 300000, - description: i18n.translate('kbn.advancedSettings.notifications.errorLifetimeText', { - defaultMessage: - 'The time in milliseconds which an error notification will be displayed on-screen for. ' + - 'Setting to {infinityValue} will disable.', - values: { - infinityValue: 'Infinity', - }, - }), - type: 'number', - category: ['notifications'], - }, - 'notifications:lifetime:warning': { - name: i18n.translate('kbn.advancedSettings.notifications.warningLifetimeTitle', { - defaultMessage: 'Warning notification lifetime', - }), - value: 10000, - description: i18n.translate('kbn.advancedSettings.notifications.warningLifetimeText', { - defaultMessage: - 'The time in milliseconds which a warning notification will be displayed on-screen for. ' + - 'Setting to {infinityValue} will disable.', - values: { - infinityValue: 'Infinity', - }, - }), - type: 'number', - category: ['notifications'], - }, - 'notifications:lifetime:info': { - name: i18n.translate('kbn.advancedSettings.notifications.infoLifetimeTitle', { - defaultMessage: 'Info notification lifetime', - }), - value: 5000, - description: i18n.translate('kbn.advancedSettings.notifications.infoLifetimeText', { - defaultMessage: - 'The time in milliseconds which an information notification will be displayed on-screen for. ' + - 'Setting to {infinityValue} will disable.', - values: { - infinityValue: 'Infinity', - }, - }), - type: 'number', - category: ['notifications'], - }, - 'accessibility:disableAnimations': { - name: i18n.translate('kbn.advancedSettings.disableAnimationsTitle', { - defaultMessage: 'Disable Animations', - }), - value: false, - description: i18n.translate('kbn.advancedSettings.disableAnimationsText', { - defaultMessage: - 'Turn off all unnecessary animations in the Kibana UI. Refresh the page to apply the changes.', - }), - category: ['accessibility'], - requiresPageReload: true, - }, - pageNavigation: { - name: i18n.translate('kbn.advancedSettings.pageNavigationName', { - defaultMessage: 'Side nav style', - }), - value: 'modern', - description: i18n.translate('kbn.advancedSettings.pageNavigationDesc', { - defaultMessage: 'Change the style of navigation', - }), - type: 'select', - options: ['modern', 'legacy'], - optionLabels: { - modern: i18n.translate('kbn.advancedSettings.pageNavigationModern', { - defaultMessage: 'Modern', - }), - legacy: i18n.translate('kbn.advancedSettings.pageNavigationLegacy', { - defaultMessage: 'Legacy', - }), - }, - schema: schema.oneOf([schema.literal('modern'), schema.literal('legacy')]), - }, }; } diff --git a/src/legacy/server/http/integration_tests/max_payload_size.test.js b/src/legacy/server/http/integration_tests/max_payload_size.test.js index a019220ca7a2..789a54f681ba 100644 --- a/src/legacy/server/http/integration_tests/max_payload_size.test.js +++ b/src/legacy/server/http/integration_tests/max_payload_size.test.js @@ -21,7 +21,11 @@ import * as kbnTestServer from '../../../../test_utils/kbn_server'; let root; beforeAll(async () => { - root = kbnTestServer.createRoot({ server: { maxPayloadBytes: 100 }, migrations: { skip: true } }); + root = kbnTestServer.createRoot({ + server: { maxPayloadBytes: 100 }, + migrations: { skip: true }, + plugins: { initialize: false }, + }); await root.setup(); await root.start(); diff --git a/src/plugins/dashboard/public/application/actions/add_to_library_action.test.tsx b/src/plugins/dashboard/public/application/actions/add_to_library_action.test.tsx index 9fa7fff9ad08..755269d1a31b 100644 --- a/src/plugins/dashboard/public/application/actions/add_to_library_action.test.tsx +++ b/src/plugins/dashboard/public/application/actions/add_to_library_action.test.tsx @@ -16,7 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -import { isErrorEmbeddable, IContainer, ReferenceOrValueEmbeddable } from '../../embeddable_plugin'; +import { + isErrorEmbeddable, + IContainer, + ReferenceOrValueEmbeddable, + EmbeddableInput, +} from '../../embeddable_plugin'; import { DashboardContainer } from '../embeddable'; import { getSampleDashboardInput } from '../test_helpers'; import { @@ -145,7 +150,7 @@ test('Add to library returns reference type input', async () => { embeddable = embeddablePluginMock.mockRefOrValEmbeddable(embeddable, { mockedByReferenceInput: { savedObjectId: 'testSavedObjectId', id: embeddable.id }, - mockedByValueInput: { attributes: complicatedAttributes, id: embeddable.id }, + mockedByValueInput: { attributes: complicatedAttributes, id: embeddable.id } as EmbeddableInput, }); const dashboard = embeddable.getRoot() as IContainer; const originalPanelKeySet = new Set(Object.keys(dashboard.getInput().panels)); diff --git a/src/plugins/dashboard/public/application/actions/clone_panel_action.tsx b/src/plugins/dashboard/public/application/actions/clone_panel_action.tsx index 26af13b4410f..dc5887ee0e64 100644 --- a/src/plugins/dashboard/public/application/actions/clone_panel_action.tsx +++ b/src/plugins/dashboard/public/application/actions/clone_panel_action.tsx @@ -24,7 +24,11 @@ import _ from 'lodash'; import { ActionByType, IncompatibleActionError } from '../../ui_actions_plugin'; import { ViewMode, PanelState, IEmbeddable } from '../../embeddable_plugin'; import { SavedObject } from '../../../../saved_objects/public'; -import { PanelNotFoundError, EmbeddableInput } from '../../../../embeddable/public'; +import { + PanelNotFoundError, + EmbeddableInput, + SavedObjectEmbeddableInput, +} from '../../../../embeddable/public'; import { placePanelBeside, IPanelPlacementBesideArgs, @@ -143,7 +147,7 @@ export class ClonePanelAction implements ActionByType }, { references: _.cloneDeep(savedObjectToClone.references) } ); - panelState.explicitInput.savedObjectId = clonedSavedObject.id; + (panelState.explicitInput as SavedObjectEmbeddableInput).savedObjectId = clonedSavedObject.id; } this.core.notifications.toasts.addSuccess({ title: i18n.translate('dashboard.panel.clonedToast', { diff --git a/src/plugins/dashboard/public/application/actions/unlink_from_library_action.test.tsx b/src/plugins/dashboard/public/application/actions/unlink_from_library_action.test.tsx index 681a6a734a53..b4178fd40c76 100644 --- a/src/plugins/dashboard/public/application/actions/unlink_from_library_action.test.tsx +++ b/src/plugins/dashboard/public/application/actions/unlink_from_library_action.test.tsx @@ -30,7 +30,7 @@ import { coreMock } from '../../../../../core/public/mocks'; import { CoreStart } from 'kibana/public'; import { UnlinkFromLibraryAction } from '.'; import { embeddablePluginMock } from 'src/plugins/embeddable/public/mocks'; -import { ViewMode } from '../../../../embeddable/public'; +import { ViewMode, SavedObjectEmbeddableInput } from '../../../../embeddable/public'; const { setup, doStart } = embeddablePluginMock.createInstance(); setup.registerEmbeddableFactory( @@ -142,7 +142,11 @@ test('Unlink unwraps all attributes from savedObject', async () => { attribute4: { nestedattribute: 'hello from the nest' }, }; - embeddable = embeddablePluginMock.mockRefOrValEmbeddable(embeddable, { + embeddable = embeddablePluginMock.mockRefOrValEmbeddable< + ContactCardEmbeddable, + { attributes: unknown; id: string }, + SavedObjectEmbeddableInput + >(embeddable, { mockedByReferenceInput: { savedObjectId: 'testSavedObjectId', id: embeddable.id }, mockedByValueInput: { attributes: complicatedAttributes, id: embeddable.id }, }); diff --git a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx index 7a19514eebe1..e10265376f2d 100644 --- a/src/plugins/dashboard/public/application/dashboard_app_controller.tsx +++ b/src/plugins/dashboard/public/application/dashboard_app_controller.tsx @@ -474,7 +474,8 @@ export class DashboardAppController { : undefined; container.addOrUpdateEmbeddable( incomingEmbeddable.type, - explicitInput, + // This ugly solution is temporary - https://github.com/elastic/kibana/pull/70272 fixes this whole section + (explicitInput as unknown) as EmbeddableInput, embeddableId ); } diff --git a/src/plugins/dashboard/public/application/lib/embeddable_saved_object_converters.test.ts b/src/plugins/dashboard/public/application/lib/embeddable_saved_object_converters.test.ts index 25ce20333242..926d5f405b38 100644 --- a/src/plugins/dashboard/public/application/lib/embeddable_saved_object_converters.test.ts +++ b/src/plugins/dashboard/public/application/lib/embeddable_saved_object_converters.test.ts @@ -23,6 +23,7 @@ import { } from './embeddable_saved_object_converters'; import { SavedDashboardPanel } from '../../types'; import { DashboardPanelState } from '../embeddable'; +import { EmbeddableInput } from '../../../../embeddable/public'; test('convertSavedDashboardPanelToPanelState', () => { const savedDashboardPanel: SavedDashboardPanel = { @@ -93,7 +94,7 @@ test('convertPanelStateToSavedDashboardPanel', () => { something: 'hi!', id: '123', savedObjectId: 'savedObjectId', - }, + } as EmbeddableInput, type: 'search', }; @@ -127,7 +128,7 @@ test('convertPanelStateToSavedDashboardPanel will not add an undefined id when n explicitInput: { id: '123', something: 'hi!', - }, + } as EmbeddableInput, type: 'search', }; diff --git a/src/plugins/data/common/search/index.ts b/src/plugins/data/common/search/index.ts index 557ab64079d1..d8184551b7f3 100644 --- a/src/plugins/data/common/search/index.ts +++ b/src/plugins/data/common/search/index.ts @@ -23,9 +23,6 @@ export * from './expressions'; export * from './tabify'; export * from './types'; -import { ES_SEARCH_STRATEGY } from './es_search'; -export const DEFAULT_SEARCH_STRATEGY = ES_SEARCH_STRATEGY; - export { IEsSearchRequest, IEsSearchResponse, diff --git a/src/plugins/data/public/mocks.ts b/src/plugins/data/public/mocks.ts index 78e40cfedd90..0eb0e3b65804 100644 --- a/src/plugins/data/public/mocks.ts +++ b/src/plugins/data/public/mocks.ts @@ -61,7 +61,7 @@ const createStartContract = (): Start => { query: queryStartMock, ui: { IndexPatternSelect: jest.fn(), - SearchBar: jest.fn(), + SearchBar: jest.fn().mockReturnValue(null), }, indexPatterns: ({ createField: jest.fn(() => {}), diff --git a/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_capabilities.ts b/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_capabilities.ts index b4b86b73a5f4..6b26c82dc95e 100644 --- a/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_capabilities.ts +++ b/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_capabilities.ts @@ -25,10 +25,6 @@ import { FieldCapsResponse, readFieldCapsResponse } from './field_caps_response' import { mergeOverrides } from './overrides'; import { FieldDescriptor } from '../../index_patterns_fetcher'; -export function concatIfUniq(arr: T[], value: T) { - return arr.includes(value) ? arr : arr.concat(value); -} - /** * Get the field capabilities for field in `indices`, excluding * all internal/underscore-prefixed fields that are not in `metaFields` @@ -49,8 +45,20 @@ export async function getFieldCapabilities( const allFieldsUnsorted = Object.keys(fieldsFromFieldCapsByName) .filter((name) => !name.startsWith('_')) .concat(metaFields) - .reduce(concatIfUniq, [] as string[]) - .map((name) => + .reduce<{ names: string[]; hash: Record }>( + (agg, value) => { + // This is intentionally using a "hash" and a "push" to be highly optimized with very large indexes + if (agg.hash[value] != null) { + return agg; + } else { + agg.hash[value] = value; + agg.names.push(value); + return agg; + } + }, + { names: [], hash: {} } + ) + .names.map((name) => defaults({}, fieldsFromFieldCapsByName[name], { name, type: 'string', diff --git a/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_caps_response.ts b/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_caps_response.ts index cb1ec6a2ebcf..861b92569faf 100644 --- a/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_caps_response.ts +++ b/src/plugins/data/server/index_patterns/fetcher/lib/field_capabilities/field_caps_response.ts @@ -93,8 +93,12 @@ export interface FieldCapsResponse { */ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): FieldDescriptor[] { const capsByNameThenType = fieldCapsResponse.fields; - const kibanaFormattedCaps: FieldDescriptor[] = Object.keys(capsByNameThenType).map( - (fieldName) => { + + const kibanaFormattedCaps = Object.keys(capsByNameThenType).reduce<{ + array: FieldDescriptor[]; + hash: Record; + }>( + (agg, fieldName) => { const capsByType = capsByNameThenType[fieldName]; const types = Object.keys(capsByType); @@ -119,7 +123,7 @@ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): Fie // ignore the conflict and carry on (my wayward son) const uniqueKibanaTypes = uniq(types.map(castEsToKbnFieldTypeName)); if (uniqueKibanaTypes.length > 1) { - return { + const field = { name: fieldName, type: 'conflict', esTypes: types, @@ -134,10 +138,14 @@ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): Fie {} ), }; + // This is intentionally using a "hash" and a "push" to be highly optimized with very large indexes + agg.array.push(field); + agg.hash[fieldName] = field; + return agg; } const esType = types[0]; - return { + const field = { name: fieldName, type: castEsToKbnFieldTypeName(esType), esTypes: types, @@ -145,11 +153,19 @@ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): Fie aggregatable: isAggregatable, readFromDocValues: shouldReadFieldFromDocValues(isAggregatable, esType), }; + // This is intentionally using a "hash" and a "push" to be highly optimized with very large indexes + agg.array.push(field); + agg.hash[fieldName] = field; + return agg; + }, + { + array: [], + hash: {}, } ); // Get all types of sub fields. These could be multi fields or children of nested/object types - const subFields = kibanaFormattedCaps.filter((field) => { + const subFields = kibanaFormattedCaps.array.filter((field) => { return field.name.includes('.'); }); @@ -161,9 +177,9 @@ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): Fie .map((_, index, parentFieldNameParts) => { return parentFieldNameParts.slice(0, index + 1).join('.'); }); - const parentFieldCaps = parentFieldNames.map((parentFieldName) => { - return kibanaFormattedCaps.find((caps) => caps.name === parentFieldName); - }); + const parentFieldCaps = parentFieldNames.map( + (parentFieldName) => kibanaFormattedCaps.hash[parentFieldName] + ); const parentFieldCapsAscending = parentFieldCaps.reverse(); if (parentFieldCaps && parentFieldCaps.length > 0) { @@ -188,7 +204,7 @@ export function readFieldCapsResponse(fieldCapsResponse: FieldCapsResponse): Fie } }); - return kibanaFormattedCaps.filter((field) => { + return kibanaFormattedCaps.array.filter((field) => { return !['object', 'nested'].includes(field.type); }); } diff --git a/src/plugins/data/server/plugin.ts b/src/plugins/data/server/plugin.ts index 5163bfcb17d4..588885391262 100644 --- a/src/plugins/data/server/plugin.ts +++ b/src/plugins/data/server/plugin.ts @@ -21,7 +21,7 @@ import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from ' import { ExpressionsServerSetup } from 'src/plugins/expressions/server'; import { ConfigSchema } from '../config'; import { IndexPatternsService, IndexPatternsServiceStart } from './index_patterns'; -import { ISearchSetup, ISearchStart } from './search'; +import { ISearchSetup, ISearchStart, SearchEnhancements } from './search'; import { SearchService } from './search/search_service'; import { QueryService } from './query/query_service'; import { ScriptsService } from './scripts'; @@ -31,9 +31,17 @@ import { AutocompleteService } from './autocomplete'; import { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats'; import { getUiSettings } from './ui_settings'; +export interface DataEnhancements { + search: SearchEnhancements; +} + export interface DataPluginSetup { search: ISearchSetup; fieldFormats: FieldFormatsSetup; + /** + * @internal + */ + __enhance: (enhancements: DataEnhancements) => void; } export interface DataPluginStart { @@ -87,11 +95,16 @@ export class DataServerPlugin core.uiSettings.register(getUiSettings()); + const searchSetup = this.searchService.setup(core, { + registerFunction: expressions.registerFunction, + usageCollection, + }); + return { - search: this.searchService.setup(core, { - registerFunction: expressions.registerFunction, - usageCollection, - }), + __enhance: (enhancements: DataEnhancements) => { + searchSetup.__enhance(enhancements.search); + }, + search: searchSetup, fieldFormats: this.fieldFormats.setup(), }; } diff --git a/src/plugins/data/server/search/index.ts b/src/plugins/data/server/search/index.ts index 4a3990621ca3..02c21c325464 100644 --- a/src/plugins/data/server/search/index.ts +++ b/src/plugins/data/server/search/index.ts @@ -17,7 +17,13 @@ * under the License. */ -export { ISearchStrategy, ISearchOptions, ISearchSetup, ISearchStart } from './types'; +export { + ISearchStrategy, + ISearchOptions, + ISearchSetup, + ISearchStart, + SearchEnhancements, +} from './types'; export { getDefaultSearchParams, getTotalLoaded } from './es_search'; diff --git a/src/plugins/data/server/search/mocks.ts b/src/plugins/data/server/search/mocks.ts index 578a170f468b..0c74ecb4b2c9 100644 --- a/src/plugins/data/server/search/mocks.ts +++ b/src/plugins/data/server/search/mocks.ts @@ -24,6 +24,7 @@ export function createSearchSetupMock(): jest.Mocked { return { aggs: searchAggsSetupMock(), registerSearchStrategy: jest.fn(), + __enhance: jest.fn(), }; } diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index cc23c455bed2..edc94961c79d 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -25,7 +25,7 @@ import { PluginInitializerContext, RequestHandlerContext, } from '../../../../core/server'; -import { ISearchSetup, ISearchStart, ISearchStrategy } from './types'; +import { ISearchSetup, ISearchStart, ISearchStrategy, SearchEnhancements } from './types'; import { AggsService, AggsSetupDependencies } from './aggs'; @@ -57,6 +57,7 @@ export interface SearchServiceStartDependencies { export class SearchService implements Plugin { private readonly aggsService = new AggsService(); + private defaultSearchStrategyName: string = ES_SEARCH_STRATEGY; private searchStrategies: StrategyMap = {}; constructor( @@ -87,6 +88,11 @@ export class SearchService implements Plugin { registerSearchRoute(core); return { + __enhance: (enhancements: SearchEnhancements) => { + if (this.searchStrategies.hasOwnProperty(enhancements.defaultStrategy)) { + this.defaultSearchStrategyName = enhancements.defaultStrategy; + } + }, aggs: this.aggsService.setup({ registerFunction }), registerSearchStrategy: this.registerSearchStrategy, usage, @@ -98,11 +104,9 @@ export class SearchService implements Plugin { searchRequest: IEsSearchRequest, options: Record ) { - return this.getSearchStrategy(options.strategy || ES_SEARCH_STRATEGY).search( - context, - searchRequest, - { signal: options.signal } - ); + return this.getSearchStrategy( + options.strategy || this.defaultSearchStrategyName + ).search(context, searchRequest, { signal: options.signal }); } public start( diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 56f803512aa1..5ce1bb3e6b9f 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -23,6 +23,10 @@ import { AggsSetup, AggsStart } from './aggs'; import { SearchUsage } from './collectors/usage'; import { IEsSearchRequest, IEsSearchResponse } from './es_search'; +export interface SearchEnhancements { + defaultStrategy: string; +} + export interface ISearchOptions { /** * An `AbortSignal` that allows the caller of `search` to abort a search request. @@ -49,6 +53,11 @@ export interface ISearchSetup { * Used internally for telemetry */ usage?: SearchUsage; + + /** + * @internal + */ + __enhance: (enhancements: SearchEnhancements) => void; } export interface ISearchStart< diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index f870030ae956..9f114f213200 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -685,6 +685,10 @@ export interface ISearchOptions { // // @public (undocumented) export interface ISearchSetup { + // Warning: (ae-forgotten-export) The symbol "SearchEnhancements" needs to be exported by the entry point index.d.ts + // + // @internal (undocumented) + __enhance: (enhancements: SearchEnhancements) => void; // Warning: (ae-forgotten-export) The symbol "AggsSetup" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -855,6 +859,7 @@ export class Plugin implements Plugin_2); // (undocumented) setup(core: CoreSetup, { expressions, usageCollection }: DataPluginSetupDependencies): { + __enhance: (enhancements: DataEnhancements) => void; search: ISearchSetup; fieldFormats: { register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number; @@ -883,6 +888,8 @@ export function plugin(initializerContext: PluginInitializerContext void; // Warning: (ae-forgotten-export) The symbol "FieldFormatsSetup" needs to be exported by the entry point index.d.ts // // (undocumented) @@ -1090,6 +1097,7 @@ export function usageProvider(core: CoreSetup_2): SearchUsage; // src/plugins/data/server/index.ts:240:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:244:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts // src/plugins/data/server/index.ts:247:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts +// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/src/plugins/embeddable/public/lib/containers/i_container.ts b/src/plugins/embeddable/public/lib/containers/i_container.ts index 31a7cd4f2e55..db219fa8b731 100644 --- a/src/plugins/embeddable/public/lib/containers/i_container.ts +++ b/src/plugins/embeddable/public/lib/containers/i_container.ts @@ -25,7 +25,7 @@ import { IEmbeddable, } from '../embeddables'; -export interface PanelState { +export interface PanelState { // The type of embeddable in this panel. Will be used to find the factory in which to // load the embeddable. type: string; @@ -43,7 +43,7 @@ export interface ContainerOutput extends EmbeddableOutput { export interface ContainerInput extends EmbeddableInput { hidePanelTitles?: boolean; panels: { - [key: string]: PanelState; + [key: string]: PanelState; }; } diff --git a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts index 9c4a1b5602c4..e8aecdba0abc 100644 --- a/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts +++ b/src/plugins/embeddable/public/lib/embeddables/i_embeddable.ts @@ -70,8 +70,6 @@ export interface EmbeddableInput { * Visualization filters used to narrow down results. */ filters?: Filter[]; - - [key: string]: unknown; } export interface EmbeddableOutput { diff --git a/src/plugins/embeddable/public/tests/container.test.ts b/src/plugins/embeddable/public/tests/container.test.ts index 621ffe4c9dad..69c21fdf3f07 100644 --- a/src/plugins/embeddable/public/tests/container.test.ts +++ b/src/plugins/embeddable/public/tests/container.test.ts @@ -19,7 +19,13 @@ import * as Rx from 'rxjs'; import { skip } from 'rxjs/operators'; -import { isErrorEmbeddable, EmbeddableOutput, ContainerInput, ViewMode } from '../lib'; +import { + isErrorEmbeddable, + EmbeddableOutput, + ContainerInput, + ViewMode, + SavedObjectEmbeddableInput, +} from '../lib'; import { FilterableEmbeddableInput, FilterableEmbeddable, @@ -648,7 +654,7 @@ test('container stores ErrorEmbeddables when a saved object cannot be found', as panels: { '123': { type: 'vis', - explicitInput: { id: '123', savedObjectId: '456' }, + explicitInput: { id: '123', savedObjectId: '456' } as SavedObjectEmbeddableInput, }, }, viewMode: ViewMode.EDIT, @@ -669,7 +675,7 @@ test('ErrorEmbeddables get updated when parent does', async (done) => { panels: { '123': { type: 'vis', - explicitInput: { id: '123', savedObjectId: '456' }, + explicitInput: { id: '123', savedObjectId: '456' } as SavedObjectEmbeddableInput, }, }, viewMode: ViewMode.EDIT, diff --git a/src/plugins/expressions/common/expression_functions/specs/var.ts b/src/plugins/expressions/common/expression_functions/specs/var.ts index 4bc185a4cadf..7d95c9816b99 100644 --- a/src/plugins/expressions/common/expression_functions/specs/var.ts +++ b/src/plugins/expressions/common/expression_functions/specs/var.ts @@ -34,7 +34,7 @@ export type ExpressionFunctionVar = ExpressionFunctionDefinition< export const variable: ExpressionFunctionVar = { name: 'var', help: i18n.translate('expressions.functions.var.help', { - defaultMessage: 'Updates kibana global context', + defaultMessage: 'Updates the Kibana global context.', }), args: { name: { @@ -42,7 +42,7 @@ export const variable: ExpressionFunctionVar = { aliases: ['_'], required: true, help: i18n.translate('expressions.functions.var.name.help', { - defaultMessage: 'Specify name of the variable', + defaultMessage: 'Specify the name of the variable.', }), }, }, diff --git a/src/plugins/expressions/common/expression_functions/specs/var_set.ts b/src/plugins/expressions/common/expression_functions/specs/var_set.ts index 8f15bc8b9004..c45ca593f020 100644 --- a/src/plugins/expressions/common/expression_functions/specs/var_set.ts +++ b/src/plugins/expressions/common/expression_functions/specs/var_set.ts @@ -35,7 +35,7 @@ export type ExpressionFunctionVarSet = ExpressionFunctionDefinition< export const variableSet: ExpressionFunctionVarSet = { name: 'var_set', help: i18n.translate('expressions.functions.varset.help', { - defaultMessage: 'Updates kibana global context', + defaultMessage: 'Updates the Kibana global context.', }), args: { name: { @@ -43,14 +43,14 @@ export const variableSet: ExpressionFunctionVarSet = { aliases: ['_'], required: true, help: i18n.translate('expressions.functions.varset.name.help', { - defaultMessage: 'Specify name of the variable', + defaultMessage: 'Specify the name of the variable.', }), }, value: { aliases: ['val'], help: i18n.translate('expressions.functions.varset.val.help', { defaultMessage: - 'Specify value for the variable. If not provided input context will be used', + 'Specify the value for the variable. When unspecified, the input context is used.', }), }, }, diff --git a/src/plugins/telemetry/schema/oss_plugins.json b/src/plugins/telemetry/schema/oss_plugins.json index a5172c01b1da..c306446b9780 100644 --- a/src/plugins/telemetry/schema/oss_plugins.json +++ b/src/plugins/telemetry/schema/oss_plugins.json @@ -13,6 +13,19 @@ } } }, + "search": { + "properties": { + "successCount": { + "type": "number" + }, + "errorCount": { + "type": "number" + }, + "averageDuration": { + "type": "long" + } + } + }, "sample-data": { "properties": { "installed": { @@ -35,6 +48,19 @@ } } }, + "csp": { + "properties": { + "strict": { + "type": "boolean" + }, + "warnLegacyBrowsers": { + "type": "boolean" + }, + "rulesChangedFromDefault": { + "type": "boolean" + } + } + }, "telemetry": { "properties": { "opt_in_status": { diff --git a/src/plugins/telemetry/server/plugin.ts b/src/plugins/telemetry/server/plugin.ts index 6c8888feafc1..bd7a2a8c1a8c 100644 --- a/src/plugins/telemetry/server/plugin.ts +++ b/src/plugins/telemetry/server/plugin.ts @@ -89,6 +89,7 @@ export class TelemetryPlugin implements Plugin { config$, currentKibanaVersion, isDev, + logger: this.logger, router, telemetryCollectionManager, }); diff --git a/src/plugins/telemetry/server/routes/index.ts b/src/plugins/telemetry/server/routes/index.ts index ad84cb9d2665..f46c616a734e 100644 --- a/src/plugins/telemetry/server/routes/index.ts +++ b/src/plugins/telemetry/server/routes/index.ts @@ -18,7 +18,7 @@ */ import { Observable } from 'rxjs'; -import { IRouter } from 'kibana/server'; +import { IRouter, Logger } from 'kibana/server'; import { TelemetryCollectionManagerPluginSetup } from 'src/plugins/telemetry_collection_manager/server'; import { registerTelemetryOptInRoutes } from './telemetry_opt_in'; import { registerTelemetryUsageStatsRoutes } from './telemetry_usage_stats'; @@ -28,6 +28,7 @@ import { TelemetryConfigType } from '../config'; interface RegisterRoutesParams { isDev: boolean; + logger: Logger; config$: Observable; currentKibanaVersion: string; router: IRouter; diff --git a/src/plugins/telemetry/server/routes/telemetry_opt_in.ts b/src/plugins/telemetry/server/routes/telemetry_opt_in.ts index 7dd15f73029e..aa1de4b2443a 100644 --- a/src/plugins/telemetry/server/routes/telemetry_opt_in.ts +++ b/src/plugins/telemetry/server/routes/telemetry_opt_in.ts @@ -21,7 +21,7 @@ import moment from 'moment'; import { Observable } from 'rxjs'; import { take } from 'rxjs/operators'; import { schema } from '@kbn/config-schema'; -import { IRouter } from 'kibana/server'; +import { IRouter, Logger } from 'kibana/server'; import { StatsGetterConfig, TelemetryCollectionManagerPluginSetup, @@ -39,12 +39,14 @@ import { TelemetryConfigType } from '../config'; interface RegisterOptInRoutesParams { currentKibanaVersion: string; router: IRouter; + logger: Logger; config$: Observable; telemetryCollectionManager: TelemetryCollectionManagerPluginSetup; } export function registerTelemetryOptInRoutes({ config$, + logger, router, currentKibanaVersion, telemetryCollectionManager, @@ -95,11 +97,16 @@ export function registerTelemetryOptInRoutes({ if (config.sendUsageFrom === 'server') { const optInStatusUrl = config.optInStatusUrl; - await sendTelemetryOptInStatus( + sendTelemetryOptInStatus( telemetryCollectionManager, { optInStatusUrl, newOptInStatus }, statsGetterConfig - ); + ).catch((err) => { + // The server is likely behind a firewall and can't reach the remote service + logger.warn( + `Failed to notify "${optInStatusUrl}" from the server about the opt-in selection. Possibly blocked by a firewall? - Error: ${err.message}` + ); + }); } await updateTelemetrySavedObject(context.core.savedObjects.client, attributes); diff --git a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts index ad19def16020..dee718decdc1 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts @@ -59,16 +59,16 @@ describe('get_data_telemetry', () => { test('matches some indices and puts them in their own category', () => { expect( buildDataTelemetryPayload([ - // APM Indices have known shipper (so we can infer the datasetType from mapping constant) + // APM Indices have known shipper (so we can infer the dataStreamType from mapping constant) { name: 'apm-7.7.0-error-000001', shipper: 'apm', isECS: true }, { name: 'apm-7.7.0-metric-000001', shipper: 'apm', isECS: true }, { name: 'apm-7.7.0-onboarding-2020.05.17', shipper: 'apm', isECS: true }, { name: 'apm-7.7.0-profile-000001', shipper: 'apm', isECS: true }, { name: 'apm-7.7.0-span-000001', shipper: 'apm', isECS: true }, { name: 'apm-7.7.0-transaction-000001', shipper: 'apm', isECS: true }, - // Packetbeat indices with known shipper (we can infer datasetType from mapping constant) + // Packetbeat indices with known shipper (we can infer dataStreamType from mapping constant) { name: 'packetbeat-7.7.0-2020.06.11-000001', shipper: 'packetbeat', isECS: true }, - // Matching patterns from the list => known datasetName but the rest is unknown + // Matching patterns from the list => known dataStreamDataset but the rest is unknown { name: 'filebeat-12314', docCount: 100, sizeInBytes: 10 }, { name: 'metricbeat-1234', docCount: 100, sizeInBytes: 10, isECS: false }, { name: '.app-search-1234', docCount: 0 }, @@ -76,8 +76,8 @@ describe('get_data_telemetry', () => { // New Indexing strategy: everything can be inferred from the constant_keyword values { name: '.ds-logs-nginx.access-default-000001', - datasetName: 'nginx.access', - datasetType: 'logs', + dataStreamDataset: 'nginx.access', + dataStreamType: 'logs', shipper: 'filebeat', isECS: true, docCount: 1000, @@ -85,8 +85,8 @@ describe('get_data_telemetry', () => { }, { name: '.ds-logs-nginx.access-default-000002', - datasetName: 'nginx.access', - datasetType: 'logs', + dataStreamDataset: 'nginx.access', + dataStreamType: 'logs', shipper: 'filebeat', isECS: true, docCount: 1000, @@ -94,8 +94,8 @@ describe('get_data_telemetry', () => { }, { name: '.ds-traces-something-default-000002', - datasetName: 'something', - datasetType: 'traces', + dataStreamDataset: 'something', + dataStreamType: 'traces', packageName: 'some-package', isECS: true, docCount: 1000, @@ -103,26 +103,26 @@ describe('get_data_telemetry', () => { }, { name: '.ds-metrics-something.else-default-000002', - datasetName: 'something.else', - datasetType: 'metrics', + dataStreamDataset: 'something.else', + dataStreamType: 'metrics', managedBy: 'ingest-manager', isECS: true, docCount: 1000, sizeInBytes: 60, }, - // Filter out if it has datasetName and datasetType but none of the shipper, packageName or managedBy === 'ingest-manager' + // Filter out if it has dataStreamDataset and dataStreamType but none of the shipper, packageName or managedBy === 'ingest-manager' { name: 'some-index-that-should-not-show', - datasetName: 'should-not-show', - datasetType: 'logs', + dataStreamDataset: 'should-not-show', + dataStreamType: 'logs', isECS: true, docCount: 1000, sizeInBytes: 60, }, { name: 'other-index-that-should-not-show', - datasetName: 'should-not-show-either', - datasetType: 'metrics', + dataStreamDataset: 'should-not-show-either', + dataStreamType: 'metrics', managedBy: 'me', isECS: true, docCount: 1000, @@ -167,7 +167,7 @@ describe('get_data_telemetry', () => { doc_count: 0, }, { - dataset: { name: 'nginx.access', type: 'logs' }, + data_stream: { dataset: 'nginx.access', type: 'logs' }, shipper: 'filebeat', index_count: 2, ecs_index_count: 2, @@ -175,7 +175,7 @@ describe('get_data_telemetry', () => { size_in_bytes: 1060, }, { - dataset: { name: 'something', type: 'traces' }, + data_stream: { dataset: 'something', type: 'traces' }, package: { name: 'some-package' }, index_count: 1, ecs_index_count: 1, @@ -183,7 +183,7 @@ describe('get_data_telemetry', () => { size_in_bytes: 60, }, { - dataset: { name: 'something.else', type: 'metrics' }, + data_stream: { dataset: 'something.else', type: 'metrics' }, index_count: 1, ecs_index_count: 1, doc_count: 1000, @@ -236,7 +236,7 @@ describe('get_data_telemetry', () => { test('find an index that does not match any index pattern but has mappings metadata', async () => { const callCluster = mockCallCluster( ['cannot_match_anything'], - { isECS: true, datasetType: 'traces', shipper: 'my-beat' }, + { isECS: true, dataStreamType: 'traces', shipper: 'my-beat' }, { indices: { cannot_match_anything: { @@ -247,7 +247,7 @@ describe('get_data_telemetry', () => { ); await expect(getDataTelemetry(callCluster)).resolves.toStrictEqual([ { - dataset: { name: undefined, type: 'traces' }, + data_stream: { dataset: undefined, type: 'traces' }, shipper: 'my-beat', index_count: 1, ecs_index_count: 1, @@ -266,7 +266,7 @@ describe('get_data_telemetry', () => { function mockCallCluster( indicesMappings: string[] = [], - { isECS = false, datasetName = '', datasetType = '', shipper = '' } = {}, + { isECS = false, dataStreamDataset = '', dataStreamType = '', shipper = '' } = {}, indexStats: any = {} ) { return jest.fn().mockImplementation(async (method: string, opts: any) => { @@ -279,14 +279,14 @@ function mockCallCluster( ...(shipper && { _meta: { beat: shipper } }), properties: { ...(isECS && { ecs: { properties: { version: { type: 'keyword' } } } }), - ...((datasetType || datasetName) && { - dataset: { + ...((dataStreamType || dataStreamDataset) && { + data_stream: { properties: { - ...(datasetName && { - name: { type: 'constant_keyword', value: datasetName }, + ...(dataStreamDataset && { + dataset: { type: 'constant_keyword', value: dataStreamDataset }, }), - ...(datasetType && { - type: { type: 'constant_keyword', value: datasetType }, + ...(dataStreamType && { + type: { type: 'constant_keyword', value: dataStreamType }, }), }, }, diff --git a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.ts b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.ts index 079f510bb256..f4734dde251c 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.ts @@ -32,9 +32,9 @@ export interface DataTelemetryBasePayload { } export interface DataTelemetryDocument extends DataTelemetryBasePayload { - dataset?: { - name?: string; - type?: DataTelemetryType | 'unknown' | string; // The union of types is to help autocompletion with some known `dataset.type`s + data_stream?: { + dataset?: string; + type?: DataTelemetryType | string; // The union of types is to help autocompletion with some known `data_stream.type`s }; package?: { name: string; @@ -49,8 +49,8 @@ export interface DataTelemetryIndex { name: string; packageName?: string; // Populated by Ingest Manager at `_meta.package.name` managedBy?: string; // Populated by Ingest Manager at `_meta.managed_by` - datasetName?: string; // To be obtained from `mappings.dataset.name` if it's a constant keyword - datasetType?: string; // To be obtained from `mappings.dataset.type` if it's a constant keyword + dataStreamDataset?: string; // To be obtained from `mappings.data_stream.dataset` if it's a constant keyword + dataStreamType?: string; // To be obtained from `mappings.data_stream.type` if it's a constant keyword shipper?: string; // To be obtained from `_meta.beat` if it's set isECS?: boolean; // Optional because it can't be obtained via Monitoring. @@ -64,8 +64,8 @@ type AtLeastOne }> = Partial & U[keyof U] type DataDescriptor = AtLeastOne<{ packageName: string; - datasetName: string; - datasetType: string; + dataStreamDataset: string; + dataStreamType: string; shipper: string; patternName: DataPatternName; // When found from the list of the index patterns }>; @@ -75,24 +75,24 @@ function findMatchingDescriptors({ shipper, packageName, managedBy, - datasetName, - datasetType, + dataStreamDataset, + dataStreamType, }: DataTelemetryIndex): DataDescriptor[] { // If we already have the data from the indices' mappings... if ( [shipper, packageName].some(Boolean) || - (managedBy === 'ingest-manager' && [datasetType, datasetName].some(Boolean)) + (managedBy === 'ingest-manager' && [dataStreamType, dataStreamDataset].some(Boolean)) ) { return [ { ...(shipper && { shipper }), ...(packageName && { packageName }), - ...(datasetName && { datasetName }), - ...(datasetType && { datasetType }), + ...(dataStreamDataset && { dataStreamDataset }), + ...(dataStreamType && { dataStreamType }), } as AtLeastOne<{ packageName: string; - datasetName: string; - datasetType: string; + dataStreamDataset: string; + dataStreamType: string; shipper: string; }>, // Using casting here because TS doesn't infer at least one exists from the if clause ]; @@ -149,15 +149,17 @@ export function buildDataTelemetryPayload(indices: DataTelemetryIndex[]): DataTe for (const indexCandidate of indexCandidates) { const matchingDescriptors = findMatchingDescriptors(indexCandidate); for (const { - datasetName, - datasetType, + dataStreamDataset, + dataStreamType, packageName, shipper, patternName, } of matchingDescriptors) { - const key = `${datasetName}-${datasetType}-${packageName}-${shipper}-${patternName}`; + const key = `${dataStreamDataset}-${dataStreamType}-${packageName}-${shipper}-${patternName}`; acc.set(key, { - ...((datasetName || datasetType) && { dataset: { name: datasetName, type: datasetType } }), + ...((dataStreamDataset || dataStreamType) && { + data_stream: { dataset: dataStreamDataset, type: dataStreamType }, + }), ...(packageName && { package: { name: packageName } }), ...(shipper && { shipper }), ...(patternName && { pattern_name: patternName }), @@ -198,9 +200,9 @@ interface IndexMappings { managed_by?: string; // Typically "ingest-manager" }; properties: { - dataset?: { + data_stream?: { properties: { - name?: { + dataset?: { type: string; value?: string; }; @@ -242,10 +244,10 @@ export async function getDataTelemetry(callCluster: LegacyAPICaller) { // Does it have `ecs.version` in the mappings? => It follows the ECS conventions '*.mappings.properties.ecs.properties.version.type', - // If `dataset.type` is a `constant_keyword`, it can be reported as a type - '*.mappings.properties.dataset.properties.type.value', - // If `dataset.name` is a `constant_keyword`, it can be reported as the dataset - '*.mappings.properties.dataset.properties.name.value', + // If `data_stream.type` is a `constant_keyword`, it can be reported as a type + '*.mappings.properties.data_stream.properties.type.value', + // If `data_stream.dataset` is a `constant_keyword`, it can be reported as the dataset + '*.mappings.properties.data_stream.properties.dataset.value', ], }), // GET /_stats/docs,store?level=indices&filter_path=indices.*.total @@ -265,8 +267,10 @@ export async function getDataTelemetry(callCluster: LegacyAPICaller) { shipper: indexMappings[name]?.mappings?._meta?.beat, packageName: indexMappings[name]?.mappings?._meta?.package?.name, managedBy: indexMappings[name]?.mappings?._meta?.managed_by, - datasetName: indexMappings[name]?.mappings?.properties.dataset?.properties.name?.value, - datasetType: indexMappings[name]?.mappings?.properties.dataset?.properties.type?.value, + dataStreamDataset: + indexMappings[name]?.mappings?.properties.data_stream?.properties.dataset?.value, + dataStreamType: + indexMappings[name]?.mappings?.properties.data_stream?.properties.type?.value, }; const stats = (indexStats?.indices || {})[name]; diff --git a/src/plugins/timelion/server/plugin.ts b/src/plugins/timelion/server/plugin.ts index 3e4cd5467dd4..fe77ebeb0866 100644 --- a/src/plugins/timelion/server/plugin.ts +++ b/src/plugins/timelion/server/plugin.ts @@ -17,13 +17,42 @@ * under the License. */ -import { CoreSetup, Plugin, PluginInitializerContext } from 'src/core/server'; +import { CoreSetup, CoreStart, Plugin, PluginInitializerContext, Logger } from 'src/core/server'; import { i18n } from '@kbn/i18n'; import { schema } from '@kbn/config-schema'; import { TimelionConfigType } from './config'; +import { timelionSheetSavedObjectType } from './saved_objects'; + +/** + * Deprecated since 7.0, the Timelion app will be removed in 8.0. + * To continue using your Timelion worksheets, migrate them to a dashboard. + * + * @link https://www.elastic.co/guide/en/kibana/master/timelion.html#timelion-deprecation + **/ +const showWarningMessageIfTimelionSheetWasFound = (core: CoreStart, logger: Logger) => { + const { savedObjects } = core; + const savedObjectsClient = savedObjects.createInternalRepository(); + + savedObjectsClient + .find({ + type: 'timelion-sheet', + perPage: 1, + }) + .then( + ({ total }) => + total && + logger.warn( + 'Deprecated since 7.0, the Timelion app will be removed in 8.0. To continue using your Timelion worksheets, migrate them to a dashboard. See https://www.elastic.co/guide/en/kibana/master/timelion.html#timelion-deprecation.' + ) + ); +}; export class TimelionPlugin implements Plugin { - constructor(context: PluginInitializerContext) {} + private logger: Logger; + + constructor(context: PluginInitializerContext) { + this.logger = context.logger.get(); + } public setup(core: CoreSetup) { core.capabilities.registerProvider(() => ({ @@ -31,30 +60,7 @@ export class TimelionPlugin implements Plugin { save: true, }, })); - core.savedObjects.registerType({ - name: 'timelion-sheet', - hidden: false, - namespaceType: 'single', - mappings: { - properties: { - description: { type: 'text' }, - hits: { type: 'integer' }, - kibanaSavedObjectMeta: { - properties: { - searchSourceJSON: { type: 'text' }, - }, - }, - timelion_chart_height: { type: 'integer' }, - timelion_columns: { type: 'integer' }, - timelion_interval: { type: 'keyword' }, - timelion_other_interval: { type: 'keyword' }, - timelion_rows: { type: 'integer' }, - timelion_sheet: { type: 'text' }, - title: { type: 'text' }, - version: { type: 'integer' }, - }, - }, - }); + core.savedObjects.registerType(timelionSheetSavedObjectType); core.uiSettings.register({ 'timelion:showTutorial': { @@ -92,6 +98,8 @@ export class TimelionPlugin implements Plugin { }, }); } - start() {} + start(core: CoreStart) { + showWarningMessageIfTimelionSheetWasFound(core, this.logger); + } stop() {} } diff --git a/src/plugins/timelion/server/saved_objects/index.ts b/src/plugins/timelion/server/saved_objects/index.ts new file mode 100644 index 000000000000..102dc2581101 --- /dev/null +++ b/src/plugins/timelion/server/saved_objects/index.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { timelionSheetSavedObjectType } from './timelion_sheet'; diff --git a/src/plugins/timelion/server/saved_objects/timelion_sheet.ts b/src/plugins/timelion/server/saved_objects/timelion_sheet.ts new file mode 100644 index 000000000000..6a46217c3e61 --- /dev/null +++ b/src/plugins/timelion/server/saved_objects/timelion_sheet.ts @@ -0,0 +1,45 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { SavedObjectsType } from 'kibana/server'; + +export const timelionSheetSavedObjectType: SavedObjectsType = { + name: 'timelion-sheet', + hidden: false, + namespaceType: 'single', + mappings: { + properties: { + description: { type: 'text' }, + hits: { type: 'integer' }, + kibanaSavedObjectMeta: { + properties: { + searchSourceJSON: { type: 'text' }, + }, + }, + timelion_chart_height: { type: 'integer' }, + timelion_columns: { type: 'integer' }, + timelion_interval: { type: 'keyword' }, + timelion_other_interval: { type: 'keyword' }, + timelion_rows: { type: 'integer' }, + timelion_sheet: { type: 'text' }, + title: { type: 'text' }, + version: { type: 'integer' }, + }, + }, +}; diff --git a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts index 4efdfd2911cb..cc278a6ee9b3 100644 --- a/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts +++ b/src/plugins/visualizations/public/embeddable/visualize_embeddable.ts @@ -42,7 +42,7 @@ import { ExpressionRenderError, } from '../../../../plugins/expressions/public'; import { buildPipeline } from '../legacy/build_pipeline'; -import { Vis } from '../vis'; +import { Vis, SerializedVis } from '../vis'; import { getExpressions, getUiActions } from '../services'; import { VIS_EVENT_TO_TRIGGER } from './events'; import { VisualizeEmbeddableFactoryDeps } from './visualize_embeddable_factory'; @@ -63,6 +63,7 @@ export interface VisualizeInput extends EmbeddableInput { vis?: { colors?: { [key: string]: string }; }; + savedVis?: SerializedVis; table?: unknown; } diff --git a/test/functional/apps/management/_scripted_fields.js b/test/functional/apps/management/_scripted_fields.js index 116d1eac90ce..6da9ebed0538 100644 --- a/test/functional/apps/management/_scripted_fields.js +++ b/test/functional/apps/management/_scripted_fields.js @@ -165,6 +165,27 @@ export default function ({ getService, getPageObjects }) { }); }); + //add a test to sort numeric scripted field + it('should sort scripted field value in Discover', async function () { + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName}`); + // after the first click on the scripted field, it becomes secondary sort after time. + // click on the timestamp twice to make it be the secondary sort key. + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('Sep 17, 2015 @ 10:53:14.181\n-1'); + }); + + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName}`); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('Sep 17, 2015 @ 06:32:29.479\n20'); + }); + }); + it('should filter by scripted field value in Discover', async function () { await PageObjects.discover.clickFieldListItem(scriptedPainlessFieldName); await log.debug('filter by the first value (14) in the expanded scripted field list'); @@ -252,6 +273,27 @@ export default function ({ getService, getPageObjects }) { }); }); + //add a test to sort string scripted field + it('should sort scripted field value in Discover', async function () { + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + // after the first click on the scripted field, it becomes secondary sort after time. + // click on the timestamp twice to make it be the secondary sort key. + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('Sep 17, 2015 @ 09:48:40.594\nbad'); + }); + + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('Sep 17, 2015 @ 06:32:29.479\ngood'); + }); + }); + it('should filter by scripted field value in Discover', async function () { await PageObjects.discover.clickFieldListItem(scriptedPainlessFieldName2); await log.debug('filter by "bad" in the expanded scripted field list'); @@ -330,6 +372,28 @@ export default function ({ getService, getPageObjects }) { await filterBar.removeAllFilters(); }); + //add a test to sort boolean + //existing bug: https://github.com/elastic/kibana/issues/75519 hence the issue is skipped. + it.skip('should sort scripted field value in Discover', async function () { + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + // after the first click on the scripted field, it becomes secondary sort after time. + // click on the timestamp twice to make it be the secondary sort key. + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('updateExpectedResultHere\ntrue'); + }); + + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('updateExpectedResultHere\nfalse'); + }); + }); + it('should visualize scripted field in vertical bar chart', async function () { await PageObjects.discover.clickFieldListItemVisualize(scriptedPainlessFieldName2); await PageObjects.header.waitUntilLoadingHasFinished(); @@ -384,6 +448,28 @@ export default function ({ getService, getPageObjects }) { }); }); + //add a test to sort date scripted field + //https://github.com/elastic/kibana/issues/75711 + it.skip('should sort scripted field value in Discover', async function () { + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + // after the first click on the scripted field, it becomes secondary sort after time. + // click on the timestamp twice to make it be the secondary sort key. + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await testSubjects.click('docTableHeaderFieldSort_@timestamp'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('updateExpectedResultHere\n2015-09-18 07:00'); + }); + + await testSubjects.click(`docTableHeaderFieldSort_${scriptedPainlessFieldName2}`); + await PageObjects.header.waitUntilLoadingHasFinished(); + await retry.try(async function () { + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData).to.be('updateExpectedResultHere\n2015-09-18 07:00'); + }); + }); + it('should filter by scripted field value in Discover', async function () { await PageObjects.discover.clickFieldListItem(scriptedPainlessFieldName2); await log.debug('filter by "Sep 17, 2015 @ 23:00" in the expanded scripted field list'); diff --git a/test/functional/apps/visualize/_vega_chart.ts b/test/functional/apps/visualize/_vega_chart.ts index b59d9590bb62..f599afa3afc3 100644 --- a/test/functional/apps/visualize/_vega_chart.ts +++ b/test/functional/apps/visualize/_vega_chart.ts @@ -50,7 +50,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) { const retry = getService('retry'); const browser = getService('browser'); - describe('vega chart in visualize app', () => { + // FLAKY: https://github.com/elastic/kibana/issues/75699 + describe.skip('vega chart in visualize app', () => { before(async () => { log.debug('navigateToApp visualize'); await PageObjects.visualize.navigateToNewVisualization(); diff --git a/test/functional/page_objects/login_page.ts b/test/functional/page_objects/login_page.ts index 350ab8be1a27..6cab2d39f3a9 100644 --- a/test/functional/page_objects/login_page.ts +++ b/test/functional/page_objects/login_page.ts @@ -48,10 +48,8 @@ export function LoginPageProvider({ getService }: FtrProviderContext) { class LoginPage { async login(user: string, pwd: string) { - if ( - process.env.VM === 'ubuntu18_deb_oidc' || - process.env.VM === 'ubuntu16_deb_desktop_saml' - ) { + const loginType = process.env.VM || ''; + if (loginType.includes('oidc') || loginType.includes('saml')) { await samlLogin(user, pwd); return; } diff --git a/vars/kibanaPipeline.groovy b/vars/kibanaPipeline.groovy index 00668f2ccdaa..e5b39584a519 100644 --- a/vars/kibanaPipeline.groovy +++ b/vars/kibanaPipeline.groovy @@ -86,6 +86,7 @@ def withFunctionalTestEnv(List additionalEnvs = [], Closure closure) { def esPort = "61${parallelId}2" def esTransportPort = "61${parallelId}3" def ingestManagementPackageRegistryPort = "61${parallelId}4" + def alertingProxyPort = "61${parallelId}5" withEnv([ "CI_GROUP=${parallelId}", @@ -98,6 +99,7 @@ def withFunctionalTestEnv(List additionalEnvs = [], Closure closure) { "TEST_ES_TRANSPORT_PORT=${esTransportPort}", "KBN_NP_PLUGINS_BUILT=true", "INGEST_MANAGEMENT_PACKAGE_REGISTRY_PORT=${ingestManagementPackageRegistryPort}", + "ALERTING_PROXY_PORT=${alertingProxyPort}" ] + additionalEnvs) { closure() } diff --git a/vars/prChanges.groovy b/vars/prChanges.groovy index 5bdd62946caf..d082672c065a 100644 --- a/vars/prChanges.groovy +++ b/vars/prChanges.groovy @@ -22,7 +22,7 @@ def getSkippablePaths() { def getNotSkippablePaths() { return [ // this file is auto-generated and changes to it need to be validated with CI - /^docs\/developer\/architecture\/code-exploration.asciidoc$/, + /^docs\/developer\/plugin-list.asciidoc$/, // don't skip CI on prs with changes to plugin readme files (?i) is for case-insensitive matching /(?i)\/plugins\/[^\/]+\/readme\.(md|asciidoc)$/, ] diff --git a/x-pack/package.json b/x-pack/package.json index a9ffb8592456..992a186d41d7 100644 --- a/x-pack/package.json +++ b/x-pack/package.json @@ -269,7 +269,7 @@ "font-awesome": "4.7.0", "formsy-react": "^1.1.5", "fp-ts": "^2.3.1", - "get-port": "^4.2.0", + "get-port": "^5.0.0", "getos": "^3.1.0", "git-url-parse": "11.1.2", "github-markdown-css": "^2.10.0", diff --git a/x-pack/plugins/actions/README.md b/x-pack/plugins/actions/README.md index 3470ede0f15c..868f6f180cc9 100644 --- a/x-pack/plugins/actions/README.md +++ b/x-pack/plugins/actions/README.md @@ -19,7 +19,7 @@ Table of Contents - [Usage](#usage) - [Kibana Actions Configuration](#kibana-actions-configuration) - [Configuration Options](#configuration-options) - - [Whitelisting Built-in Action Types](#whitelisting-built-in-action-types) + - [Adding Built-in Action Types to allowedHosts](#adding-built-in-action-types-to-hosts-allow-list) - [Configuration Utilities](#configuration-utilities) - [Action types](#action-types) - [Methods](#methods) @@ -106,15 +106,15 @@ Built-In-Actions are configured using the _xpack.actions_ namespoace under _kiba | Namespaced Key | Description | Type | | -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | | _xpack.actions._**enabled** | Feature toggle which enabled Actions in Kibana. | boolean | -| _xpack.actions._**whitelistedHosts** | Which _hostnames_ are whitelisted for the Built-In-Action? This list should contain hostnames of every external service you wish to interact with using Webhooks, Email or any other built in Action. Note that you may use the string "\*" in place of a specific hostname to enable Kibana to target any URL, but keep in mind the potential use of such a feature to execute [SSRF](https://www.owasp.org/index.php/Server_Side_Request_Forgery) attacks from your server. | Array | +| _xpack.actions._**allowedHosts** | Which _hostnames_ are allowed for the Built-In-Action? This list should contain hostnames of every external service you wish to interact with using Webhooks, Email or any other built in Action. Note that you may use the string "\*" in place of a specific hostname to enable Kibana to target any URL, but keep in mind the potential use of such a feature to execute [SSRF](https://www.owasp.org/index.php/Server_Side_Request_Forgery) attacks from your server. | Array | | _xpack.actions._**enabledActionTypes** | A list of _actionTypes_ id's that are enabled. A "\*" may be used as an element to indicate all registered actionTypes should be enabled. The actionTypes registered for Kibana are `.server-log`, `.slack`, `.email`, `.index`, `.pagerduty`, `.webhook`. Default: `["*"]` | Array | | _xpack.actions._**preconfigured** | A object of action id / preconfigured actions. Default: `{}` | Array | -#### Whitelisting Built-in Action Types +#### Adding Built-in Action Types to allowedHosts -It is worth noting that the **whitelistedHosts** configuation applies to built-in action types (such as Slack, or PagerDuty) as well. +It is worth noting that the **allowedHosts** configuation applies to built-in action types (such as Slack, or PagerDuty) as well. -Uniquely, the _PagerDuty Action Type_ has been configured to support the service's Events API (at _https://events.pagerduty.com/v2/enqueue_, which you can read about [here](https://v2.developer.pagerduty.com/docs/events-api-v2)) as a default, but this too, must be included in the whitelist before the PagerDuty action can be used. +Uniquely, the _PagerDuty Action Type_ has been configured to support the service's Events API (at _https://events.pagerduty.com/v2/enqueue_, which you can read about [here](https://v2.developer.pagerduty.com/docs/events-api-v2)) as a default, but this too, must be included in the allowedHosts before the PagerDuty action can be used. ### Configuration Utilities @@ -122,11 +122,11 @@ This module provides a Utilities for interacting with the configuration. | Method | Arguments | Description | Return Type | | ------------------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | -| isWhitelistedUri | _uri_: The URI you wish to validate is whitelisted | Validates whether the URI is whitelisted. This checks the configuration and validates that the hostname of the URI is in the list of whitelisted Hosts and returns `true` if it is whitelisted. If the configuration says that all URI's are whitelisted (using an "\*") then it will always return `true`. | Boolean | -| isWhitelistedHostname | _hostname_: The Hostname you wish to validate is whitelisted | Validates whether the Hostname is whitelisted. This checks the configuration and validates that the hostname is in the list of whitelisted Hosts and returns `true` if it is whitelisted. If the configuration says that all Hostnames are whitelisted (using an "\*") then it will always return `true`. | Boolean | +| isUriAllowed | _uri_: The URI you wish to validate is allowed | Validates whether the URI is allowed. This checks the configuration and validates that the hostname of the URI is in the list of allowed Hosts and returns `true` if it is allowed. If the configuration says that all URI's are allowed (using an "\*") then it will always return `true`. | Boolean | +| isHostnameAllowed | _hostname_: The Hostname you wish to validate is allowed | Validates whether the Hostname is allowed. This checks the configuration and validates that the hostname is in the list of allowed Hosts and returns `true` if it is allowed. If the configuration says that all Hostnames are allowed (using an "\*") then it will always return `true`. | Boolean | | isActionTypeEnabled | _actionType_: The actionType to check to see if it's enabled | Returns true if the actionType is enabled, otherwise false. | Boolean | -| ensureWhitelistedUri | _uri_: The URI you wish to validate is whitelisted | Validates whether the URI is whitelisted. This checks the configuration and validates that the hostname of the URI is in the list of whitelisted Hosts and throws an error if it is not whitelisted. If the configuration says that all URI's are whitelisted (using an "\*") then it will never throw. | No return value, throws if URI isn't whitelisted | -| ensureWhitelistedHostname | _hostname_: The Hostname you wish to validate is whitelisted | Validates whether the Hostname is whitelisted. This checks the configuration and validates that the hostname is in the list of whitelisted Hosts and throws an error if it is not whitelisted. If the configuration says that all Hostnames are whitelisted (using an "\*") then it will never throw | No return value, throws if Hostname isn't whitelisted | +| ensureUriAllowed | _uri_: The URI you wish to validate is allowed | Validates whether the URI is allowed. This checks the configuration and validates that the hostname of the URI is in the list of allowed Hosts and throws an error if it is not allowed. If the configuration says that all URI's are allowed (using an "\*") then it will never throw. | No return value, throws if URI isn't allowed | +| ensureHostnameAllowed | _hostname_: The Hostname you wish to validate is allowed | Validates whether the Hostname is allowed. This checks the configuration and validates that the hostname is in the list of allowed Hosts and throws an error if it is not allowed. If the configuration says that all Hostnames are allowed (using an "\*") then it will never throw | No return value, throws if Hostname isn't allowed . | | ensureActionTypeEnabled | _actionType_: The actionType to check to see if it's enabled | Throws an error if the actionType is not enabled | No return value, throws if actionType isn't enabled | ## Action types @@ -666,7 +666,7 @@ Currently actions are licensed as "basic" if the action only interacts with the Currently actions that are licensed as "basic" **MUST** be implemented in the actions plugin, other actions can be implemented in any other plugin that pre-reqs the actions plugin. If the new action is generic across the stack, it probably belongs in the actions plugin, but if your action is very specific to a plugin/solution, it might be easiest to implement it in the plugin/solution. Keep in mind that if Kibana is run without the plugin being enabled, any actions defined in that plugin will not run, nor will those actions be available via APIs or UI. -Actions that take URLs or hostnames should check that those values are whitelisted. The whitelisting utilities are currently internal to the actions plugin, and so such actions will need to be implemented in the actions plugin. Longer-term, we will expose these utilities so they can be used by alerts implemented in other plugins; see [issue #64659](https://github.com/elastic/kibana/issues/64659). +Actions that take URLs or hostnames should check that those values are allowed. The allowed host list utilities are currently internal to the actions plugin, and so such actions will need to be implemented in the actions plugin. Longer-term, we will expose these utilities so they can be used by alerts implemented in other plugins; see [issue #64659](https://github.com/elastic/kibana/issues/64659). ## documentation diff --git a/x-pack/plugins/actions/server/actions_client.test.ts b/x-pack/plugins/actions/server/actions_client.test.ts index 16a5a59882dd..573fb0e1be58 100644 --- a/x-pack/plugins/actions/server/actions_client.test.ts +++ b/x-pack/plugins/actions/server/actions_client.test.ts @@ -295,7 +295,7 @@ describe('create()', () => { const localConfigUtils = getActionsConfigurationUtilities({ enabled: true, enabledActionTypes: ['some-not-ignored-action-type'], - whitelistedHosts: ['*'], + allowedHosts: ['*'], }); const localActionTypeRegistryParams = { diff --git a/x-pack/plugins/actions/server/actions_config.mock.ts b/x-pack/plugins/actions/server/actions_config.mock.ts index addd35ae4f5f..67ab495fc967 100644 --- a/x-pack/plugins/actions/server/actions_config.mock.ts +++ b/x-pack/plugins/actions/server/actions_config.mock.ts @@ -8,11 +8,11 @@ import { ActionsConfigurationUtilities } from './actions_config'; const createActionsConfigMock = () => { const mocked: jest.Mocked = { - isWhitelistedHostname: jest.fn().mockReturnValue(true), - isWhitelistedUri: jest.fn().mockReturnValue(true), + isHostnameAllowed: jest.fn().mockReturnValue(true), + isUriAllowed: jest.fn().mockReturnValue(true), isActionTypeEnabled: jest.fn().mockReturnValue(true), - ensureWhitelistedHostname: jest.fn().mockReturnValue({}), - ensureWhitelistedUri: jest.fn().mockReturnValue({}), + ensureHostnameAllowed: jest.fn().mockReturnValue({}), + ensureUriAllowed: jest.fn().mockReturnValue({}), ensureActionTypeEnabled: jest.fn().mockReturnValue({}), }; return mocked; diff --git a/x-pack/plugins/actions/server/actions_config.test.ts b/x-pack/plugins/actions/server/actions_config.test.ts index 7d9d431d1c1b..56c58054ca79 100644 --- a/x-pack/plugins/actions/server/actions_config.test.ts +++ b/x-pack/plugins/actions/server/actions_config.test.ts @@ -7,163 +7,151 @@ import { ActionsConfigType } from './types'; import { getActionsConfigurationUtilities, - WhitelistedHosts, + AllowedHosts, EnabledActionTypes, } from './actions_config'; const DefaultActionsConfig: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: [], }; -describe('ensureWhitelistedUri', () => { +describe('ensureUriAllowed', () => { test('returns true when "any" hostnames are allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [WhitelistedHosts.Any], + allowedHosts: [AllowedHosts.Any], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).ensureWhitelistedUri( - 'https://github.com/elastic/kibana' - ) + getActionsConfigurationUtilities(config).ensureUriAllowed('https://github.com/elastic/kibana') ).toBeUndefined(); }); - test('throws when the hostname in the requested uri is not in the whitelist', () => { + test('throws when the hostname in the requested uri is not in the allowedHosts', () => { const config: ActionsConfigType = DefaultActionsConfig; expect(() => - getActionsConfigurationUtilities(config).ensureWhitelistedUri( - 'https://github.com/elastic/kibana' - ) + getActionsConfigurationUtilities(config).ensureUriAllowed('https://github.com/elastic/kibana') ).toThrowErrorMatchingInlineSnapshot( - `"target url \\"https://github.com/elastic/kibana\\" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts"` + `"target url \\"https://github.com/elastic/kibana\\" is not added to the Kibana config xpack.actions.allowedHosts"` ); }); test('throws when the uri cannot be parsed as a valid URI', () => { const config: ActionsConfigType = DefaultActionsConfig; expect(() => - getActionsConfigurationUtilities(config).ensureWhitelistedUri('github.com/elastic') + getActionsConfigurationUtilities(config).ensureUriAllowed('github.com/elastic') ).toThrowErrorMatchingInlineSnapshot( - `"target url \\"github.com/elastic\\" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts"` + `"target url \\"github.com/elastic\\" is not added to the Kibana config xpack.actions.allowedHosts"` ); }); - test('returns true when the hostname in the requested uri is in the whitelist', () => { + test('returns true when the hostname in the requested uri is in the allowedHosts', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: ['github.com'], + allowedHosts: ['github.com'], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).ensureWhitelistedUri( - 'https://github.com/elastic/kibana' - ) + getActionsConfigurationUtilities(config).ensureUriAllowed('https://github.com/elastic/kibana') ).toBeUndefined(); }); }); -describe('ensureWhitelistedHostname', () => { +describe('ensureHostnameAllowed', () => { test('returns true when "any" hostnames are allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [WhitelistedHosts.Any], + allowedHosts: [AllowedHosts.Any], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).ensureWhitelistedHostname('github.com') + getActionsConfigurationUtilities(config).ensureHostnameAllowed('github.com') ).toBeUndefined(); }); - test('throws when the hostname in the requested uri is not in the whitelist', () => { + test('throws when the hostname in the requested uri is not in the allowedHosts', () => { const config: ActionsConfigType = DefaultActionsConfig; expect(() => - getActionsConfigurationUtilities(config).ensureWhitelistedHostname('github.com') + getActionsConfigurationUtilities(config).ensureHostnameAllowed('github.com') ).toThrowErrorMatchingInlineSnapshot( - `"target hostname \\"github.com\\" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts"` + `"target hostname \\"github.com\\" is not added to the Kibana config xpack.actions.allowedHosts"` ); }); - test('returns true when the hostname in the requested uri is in the whitelist', () => { + test('returns true when the hostname in the requested uri is in the allowedHosts', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: ['github.com'], + allowedHosts: ['github.com'], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).ensureWhitelistedHostname('github.com') + getActionsConfigurationUtilities(config).ensureHostnameAllowed('github.com') ).toBeUndefined(); }); }); -describe('isWhitelistedUri', () => { +describe('isUriAllowed', () => { test('returns true when "any" hostnames are allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [WhitelistedHosts.Any], + allowedHosts: [AllowedHosts.Any], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).isWhitelistedUri('https://github.com/elastic/kibana') + getActionsConfigurationUtilities(config).isUriAllowed('https://github.com/elastic/kibana') ).toEqual(true); }); - test('throws when the hostname in the requested uri is not in the whitelist', () => { + test('throws when the hostname in the requested uri is not in the allowedHosts', () => { const config: ActionsConfigType = DefaultActionsConfig; expect( - getActionsConfigurationUtilities(config).isWhitelistedUri('https://github.com/elastic/kibana') + getActionsConfigurationUtilities(config).isUriAllowed('https://github.com/elastic/kibana') ).toEqual(false); }); test('throws when the uri cannot be parsed as a valid URI', () => { const config: ActionsConfigType = DefaultActionsConfig; - expect(getActionsConfigurationUtilities(config).isWhitelistedUri('github.com/elastic')).toEqual( + expect(getActionsConfigurationUtilities(config).isUriAllowed('github.com/elastic')).toEqual( false ); }); - test('returns true when the hostname in the requested uri is in the whitelist', () => { + test('returns true when the hostname in the requested uri is in the allowedHosts', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: ['github.com'], + allowedHosts: ['github.com'], enabledActionTypes: [], }; expect( - getActionsConfigurationUtilities(config).isWhitelistedUri('https://github.com/elastic/kibana') + getActionsConfigurationUtilities(config).isUriAllowed('https://github.com/elastic/kibana') ).toEqual(true); }); }); -describe('isWhitelistedHostname', () => { +describe('isHostnameAllowed', () => { test('returns true when "any" hostnames are allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [WhitelistedHosts.Any], + allowedHosts: [AllowedHosts.Any], enabledActionTypes: [], }; - expect(getActionsConfigurationUtilities(config).isWhitelistedHostname('github.com')).toEqual( - true - ); + expect(getActionsConfigurationUtilities(config).isHostnameAllowed('github.com')).toEqual(true); }); - test('throws when the hostname in the requested uri is not in the whitelist', () => { + test('throws when the hostname in the requested uri is not in the allowedHosts', () => { const config: ActionsConfigType = DefaultActionsConfig; - expect(getActionsConfigurationUtilities(config).isWhitelistedHostname('github.com')).toEqual( - false - ); + expect(getActionsConfigurationUtilities(config).isHostnameAllowed('github.com')).toEqual(false); }); - test('returns true when the hostname in the requested uri is in the whitelist', () => { + test('returns true when the hostname in the requested uri is in the allowedHosts', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: ['github.com'], + allowedHosts: ['github.com'], enabledActionTypes: [], }; - expect(getActionsConfigurationUtilities(config).isWhitelistedHostname('github.com')).toEqual( - true - ); + expect(getActionsConfigurationUtilities(config).isHostnameAllowed('github.com')).toEqual(true); }); }); @@ -171,7 +159,7 @@ describe('isActionTypeEnabled', () => { test('returns true when "any" actionTypes are allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['ignore', EnabledActionTypes.Any], }; expect(getActionsConfigurationUtilities(config).isActionTypeEnabled('foo')).toEqual(true); @@ -180,7 +168,7 @@ describe('isActionTypeEnabled', () => { test('returns false when no actionType is allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: [], }; expect(getActionsConfigurationUtilities(config).isActionTypeEnabled('foo')).toEqual(false); @@ -189,7 +177,7 @@ describe('isActionTypeEnabled', () => { test('returns false when the actionType is not in the enabled list', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['foo'], }; expect(getActionsConfigurationUtilities(config).isActionTypeEnabled('bar')).toEqual(false); @@ -198,7 +186,7 @@ describe('isActionTypeEnabled', () => { test('returns true when the actionType is in the enabled list', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['ignore', 'foo'], }; expect(getActionsConfigurationUtilities(config).isActionTypeEnabled('foo')).toEqual(true); @@ -209,7 +197,7 @@ describe('ensureActionTypeEnabled', () => { test('does not throw when any actionType is allowed', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['ignore', EnabledActionTypes.Any], }; expect(getActionsConfigurationUtilities(config).ensureActionTypeEnabled('foo')).toBeUndefined(); @@ -227,7 +215,7 @@ describe('ensureActionTypeEnabled', () => { test('throws when actionType is not enabled', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['ignore'], }; expect(() => @@ -240,7 +228,7 @@ describe('ensureActionTypeEnabled', () => { test('does not throw when actionType is enabled', () => { const config: ActionsConfigType = { enabled: false, - whitelistedHosts: [], + allowedHosts: [], enabledActionTypes: ['ignore', 'foo'], }; expect(getActionsConfigurationUtilities(config).ensureActionTypeEnabled('foo')).toBeUndefined(); diff --git a/x-pack/plugins/actions/server/actions_config.ts b/x-pack/plugins/actions/server/actions_config.ts index b15fe5b4007c..609e4969222f 100644 --- a/x-pack/plugins/actions/server/actions_config.ts +++ b/x-pack/plugins/actions/server/actions_config.ts @@ -13,7 +13,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { ActionsConfigType } from './types'; import { ActionTypeDisabledError } from './lib'; -export enum WhitelistedHosts { +export enum AllowedHosts { Any = '*', } @@ -21,24 +21,24 @@ export enum EnabledActionTypes { Any = '*', } -enum WhitelistingField { +enum AllowListingField { url = 'url', hostname = 'hostname', } export interface ActionsConfigurationUtilities { - isWhitelistedHostname: (hostname: string) => boolean; - isWhitelistedUri: (uri: string) => boolean; + isHostnameAllowed: (hostname: string) => boolean; + isUriAllowed: (uri: string) => boolean; isActionTypeEnabled: (actionType: string) => boolean; - ensureWhitelistedHostname: (hostname: string) => void; - ensureWhitelistedUri: (uri: string) => void; + ensureHostnameAllowed: (hostname: string) => void; + ensureUriAllowed: (uri: string) => void; ensureActionTypeEnabled: (actionType: string) => void; } -function whitelistingErrorMessage(field: WhitelistingField, value: string) { - return i18n.translate('xpack.actions.urlWhitelistConfigurationError', { +function allowListErrorMessage(field: AllowListingField, value: string) { + return i18n.translate('xpack.actions.urlAllowedHostsConfigurationError', { defaultMessage: - 'target {field} "{value}" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'target {field} "{value}" is not added to the Kibana config xpack.actions.allowedHosts', values: { value, field, @@ -56,18 +56,18 @@ function disabledActionTypeErrorMessage(actionType: string) { }); } -function isWhitelisted({ whitelistedHosts }: ActionsConfigType, hostname: string): boolean { - const whitelisted = new Set(whitelistedHosts); - if (whitelisted.has(WhitelistedHosts.Any)) return true; - if (whitelisted.has(hostname)) return true; +function isAllowed({ allowedHosts }: ActionsConfigType, hostname: string): boolean { + const allowed = new Set(allowedHosts); + if (allowed.has(AllowedHosts.Any)) return true; + if (allowed.has(hostname)) return true; return false; } -function isWhitelistedHostnameInUri(config: ActionsConfigType, uri: string): boolean { +function isHostnameAllowedInUri(config: ActionsConfigType, uri: string): boolean { return pipe( tryCatch(() => new URL(uri)), map((url) => url.hostname), - mapNullable((hostname) => isWhitelisted(config, hostname)), + mapNullable((hostname) => isAllowed(config, hostname)), getOrElse(() => false) ); } @@ -85,21 +85,21 @@ function isActionTypeEnabledInConfig( export function getActionsConfigurationUtilities( config: ActionsConfigType ): ActionsConfigurationUtilities { - const isWhitelistedHostname = curry(isWhitelisted)(config); - const isWhitelistedUri = curry(isWhitelistedHostnameInUri)(config); + const isHostnameAllowed = curry(isAllowed)(config); + const isUriAllowed = curry(isHostnameAllowedInUri)(config); const isActionTypeEnabled = curry(isActionTypeEnabledInConfig)(config); return { - isWhitelistedHostname, - isWhitelistedUri, + isHostnameAllowed, + isUriAllowed, isActionTypeEnabled, - ensureWhitelistedUri(uri: string) { - if (!isWhitelistedUri(uri)) { - throw new Error(whitelistingErrorMessage(WhitelistingField.url, uri)); + ensureUriAllowed(uri: string) { + if (!isUriAllowed(uri)) { + throw new Error(allowListErrorMessage(AllowListingField.url, uri)); } }, - ensureWhitelistedHostname(hostname: string) { - if (!isWhitelistedHostname(hostname)) { - throw new Error(whitelistingErrorMessage(WhitelistingField.hostname, hostname)); + ensureHostnameAllowed(hostname: string) { + if (!isHostnameAllowed(hostname)) { + throw new Error(allowListErrorMessage(AllowListingField.hostname, hostname)); } }, ensureActionTypeEnabled(actionType: string) { diff --git a/x-pack/plugins/actions/server/builtin_action_types/case/validators.ts b/x-pack/plugins/actions/server/builtin_action_types/case/validators.ts index 80e301e5be08..08e8a8be6a3e 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/case/validators.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/case/validators.ts @@ -23,9 +23,9 @@ export const validateCommonConfig = ( return i18n.MAPPING_EMPTY; } - configurationUtilities.ensureWhitelistedUri(configObject.apiUrl); - } catch (whitelistError) { - return i18n.WHITE_LISTED_ERROR(whitelistError.message); + configurationUtilities.ensureUriAllowed(configObject.apiUrl); + } catch (allowListError) { + return i18n.WHITE_LISTED_ERROR(allowListError.message); } }; diff --git a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts index 62f369816d71..7147483998d9 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/email.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/email.test.ts @@ -121,56 +121,56 @@ describe('config validation', () => { const NODEMAILER_AOL_SERVICE = 'AOL'; const NODEMAILER_AOL_SERVICE_HOST = 'smtp.aol.com'; - test('config validation handles email host whitelisting', () => { + test('config validation handles email host in allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - isWhitelistedHostname: (hostname) => hostname === NODEMAILER_AOL_SERVICE_HOST, + isHostnameAllowed: (hostname) => hostname === NODEMAILER_AOL_SERVICE_HOST, }, }); const baseConfig = { from: 'bob@example.com', }; - const whitelistedConfig1 = { + const allowedHosts1 = { ...baseConfig, service: NODEMAILER_AOL_SERVICE, }; - const whitelistedConfig2 = { + const allowedHosts2 = { ...baseConfig, host: NODEMAILER_AOL_SERVICE_HOST, port: 42, }; - const notWhitelistedConfig1 = { + const notAllowedHosts1 = { ...baseConfig, service: 'gmail', }; - const notWhitelistedConfig2 = { + const notAllowedHosts2 = { ...baseConfig, host: 'smtp.gmail.com', port: 42, }; - const validatedConfig1 = validateConfig(actionType, whitelistedConfig1); - expect(validatedConfig1.service).toEqual(whitelistedConfig1.service); - expect(validatedConfig1.from).toEqual(whitelistedConfig1.from); + const validatedConfig1 = validateConfig(actionType, allowedHosts1); + expect(validatedConfig1.service).toEqual(allowedHosts1.service); + expect(validatedConfig1.from).toEqual(allowedHosts1.from); - const validatedConfig2 = validateConfig(actionType, whitelistedConfig2); - expect(validatedConfig2.host).toEqual(whitelistedConfig2.host); - expect(validatedConfig2.port).toEqual(whitelistedConfig2.port); - expect(validatedConfig2.from).toEqual(whitelistedConfig2.from); + const validatedConfig2 = validateConfig(actionType, allowedHosts2); + expect(validatedConfig2.host).toEqual(allowedHosts2.host); + expect(validatedConfig2.port).toEqual(allowedHosts2.port); + expect(validatedConfig2.from).toEqual(allowedHosts2.from); expect(() => { - validateConfig(actionType, notWhitelistedConfig1); + validateConfig(actionType, notAllowedHosts1); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action type config: [service] value 'gmail' resolves to host 'smtp.gmail.com' which is not in the whitelistedHosts configuration"` + `"error validating action type config: [service] value 'gmail' resolves to host 'smtp.gmail.com' which is not in the allowedHosts configuration"` ); expect(() => { - validateConfig(actionType, notWhitelistedConfig2); + validateConfig(actionType, notAllowedHosts2); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action type config: [host] value 'smtp.gmail.com' is not in the whitelistedHosts configuration"` + `"error validating action type config: [host] value 'smtp.gmail.com' is not in the allowedHosts configuration"` ); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/email.ts b/x-pack/plugins/actions/server/builtin_action_types/email.ts index e9dc4eea5dcf..6fd2d694b06f 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/email.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/email.ts @@ -66,16 +66,16 @@ function validateConfig( return '[port] is required if [service] is not provided'; } - if (!configurationUtilities.isWhitelistedHostname(config.host)) { - return `[host] value '${config.host}' is not in the whitelistedHosts configuration`; + if (!configurationUtilities.isHostnameAllowed(config.host)) { + return `[host] value '${config.host}' is not in the allowedHosts configuration`; } } else { const host = getServiceNameHost(config.service); if (host == null) { return `[service] value '${config.service}' is not valid`; } - if (!configurationUtilities.isWhitelistedHostname(host)) { - return `[service] value '${config.service}' resolves to host '${host}' which is not in the whitelistedHosts configuration`; + if (!configurationUtilities.isHostnameAllowed(host)) { + return `[service] value '${config.service}' resolves to host '${host}' which is not in the allowedHosts configuration`; } } } diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts index c379c05ee88e..772e7df41697 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts @@ -64,12 +64,12 @@ describe('validateConfig()', () => { ); }); - test('should validate and pass when the pagerduty url is whitelisted', () => { + test('should validate and pass when the pagerduty url is added to allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - ensureWhitelistedUri: (url) => { + ensureUriAllowed: (url) => { expect(url).toEqual('https://events.pagerduty.com/v2/enqueue'); }, }, @@ -80,13 +80,13 @@ describe('validateConfig()', () => { ).toEqual({ apiUrl: 'https://events.pagerduty.com/v2/enqueue' }); }); - test('config validation returns an error if the specified URL isnt whitelisted', () => { + test('config validation returns an error if the specified URL isnt added to allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - ensureWhitelistedUri: (_) => { - throw new Error(`target url is not whitelisted`); + ensureUriAllowed: (_) => { + throw new Error(`target url is not added to allowedHosts`); }, }, }); @@ -94,7 +94,7 @@ describe('validateConfig()', () => { expect(() => { validateConfig(actionType, { apiUrl: 'https://events.pagerduty.com/v2/enqueue' }); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action type config: error configuring pagerduty action: target url is not whitelisted"` + `"error validating action type config: error configuring pagerduty action: target url is not added to allowedHosts"` ); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts index c0edfc530e73..640a38d77b6c 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts @@ -135,12 +135,12 @@ function valdiateActionTypeConfig( configObject: ActionTypeConfigType ) { try { - configurationUtilities.ensureWhitelistedUri(getPagerDutyApiUrl(configObject)); - } catch (whitelistError) { + configurationUtilities.ensureUriAllowed(getPagerDutyApiUrl(configObject)); + } catch (allowListError) { return i18n.translate('xpack.actions.builtin.pagerduty.pagerdutyConfigurationError', { defaultMessage: 'error configuring pagerduty action: {message}', values: { - message: whitelistError.message, + message: allowListError.message, }, }); } diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts index cf1c26e6462a..9b1da4b4007c 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/service.ts @@ -78,8 +78,6 @@ export const createExternalService = ( const createIncident = async ({ incident }: ExternalServiceParams) => { try { - logger.warn(`incident error : ${JSON.stringify(proxySettings)}`); - logger.warn(`incident error : ${url}`); const res = await request({ axios: axiosInstance, url: `${incidentUrl}`, diff --git a/x-pack/plugins/actions/server/builtin_action_types/servicenow/validators.ts b/x-pack/plugins/actions/server/builtin_action_types/servicenow/validators.ts index 65bbe9aea811..6eec3b8d63b8 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/servicenow/validators.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/servicenow/validators.ts @@ -26,9 +26,9 @@ export const validateCommonConfig = ( } try { - configurationUtilities.ensureWhitelistedUri(configObject.apiUrl); - } catch (whitelistError) { - return i18n.WHITE_LISTED_ERROR(whitelistError.message); + configurationUtilities.ensureUriAllowed(configObject.apiUrl); + } catch (allowListError) { + return i18n.WHITE_LISTED_ERROR(allowListError.message); } }; diff --git a/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts b/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts index 812657138152..b15d92cecba6 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/slack.test.ts @@ -96,12 +96,12 @@ describe('validateActionTypeSecrets()', () => { ); }); - test('should validate and pass when the slack webhookUrl is whitelisted', () => { + test('should validate and pass when the slack webhookUrl is added to allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - ensureWhitelistedUri: (url) => { + ensureUriAllowed: (url) => { expect(url).toEqual('https://api.slack.com/'); }, }, @@ -112,13 +112,13 @@ describe('validateActionTypeSecrets()', () => { }); }); - test('config validation returns an error if the specified URL isnt whitelisted', () => { + test('config validation returns an error if the specified URL isnt added to allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - ensureWhitelistedHostname: () => { - throw new Error(`target hostname is not whitelisted`); + ensureHostnameAllowed: () => { + throw new Error(`target hostname is not added to allowedHosts`); }, }, }); @@ -126,7 +126,7 @@ describe('validateActionTypeSecrets()', () => { expect(() => { validateSecrets(actionType, { webhookUrl: 'https://api.slack.com/' }); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action type secrets: error configuring slack action: target hostname is not whitelisted"` + `"error validating action type secrets: error configuring slack action: target hostname is not added to allowedHosts"` ); }); }); @@ -209,7 +209,7 @@ describe('execute()', () => { rejectUnauthorizedCertificates: false, }, }); - expect(mockedLogger.info).toHaveBeenCalledWith( + expect(mockedLogger.debug).toHaveBeenCalledWith( 'IncomingWebhook was called with proxyUrl https://someproxyhost' ); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/slack.ts b/x-pack/plugins/actions/server/builtin_action_types/slack.ts index 293328c80943..1605cd4b69f5 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/slack.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/slack.ts @@ -91,12 +91,12 @@ function valdiateActionTypeConfig( } try { - configurationUtilities.ensureWhitelistedHostname(url.hostname); - } catch (whitelistError) { + configurationUtilities.ensureHostnameAllowed(url.hostname); + } catch (allowListError) { return i18n.translate('xpack.actions.builtin.slack.slackConfigurationError', { defaultMessage: 'error configuring slack action: {message}', values: { - message: whitelistError.message, + message: allowListError.message, }, }); } @@ -119,7 +119,7 @@ async function slackExecutor( let proxyAgent: HttpsProxyAgent | HttpProxyAgent | undefined; if (execOptions.proxySettings) { proxyAgent = getProxyAgent(execOptions.proxySettings, logger); - logger.info(`IncomingWebhook was called with proxyUrl ${execOptions.proxySettings.proxyUrl}`); + logger.debug(`IncomingWebhook was called with proxyUrl ${execOptions.proxySettings.proxyUrl}`); } try { @@ -130,8 +130,6 @@ async function slackExecutor( }); result = await webhook.send(message); } catch (err) { - logger.error(`error on ${actionId} slack event: ${err.message}`); - if (err.original == null || err.original.response == null) { return serviceErrorResult(actionId, err.message); } diff --git a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts index ea9f30452918..23ce527d4ae0 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/webhook.test.ts @@ -176,7 +176,7 @@ describe('config validation', () => { `); }); - test('config validation passes when kibana config whitelists the url', () => { + test('config validation passes when kibana config url does not present in allowedHosts', () => { // any for testing // eslint-disable-next-line @typescript-eslint/no-explicit-any const config: Record = { @@ -192,13 +192,13 @@ describe('config validation', () => { }); }); - test('config validation returns an error if the specified URL isnt whitelisted', () => { + test('config validation returns an error if the specified URL isnt added to allowedHosts', () => { actionType = getActionType({ logger: mockedLogger, configurationUtilities: { ...actionsConfigMock.create(), - ensureWhitelistedUri: (_) => { - throw new Error(`target url is not whitelisted`); + ensureUriAllowed: (_) => { + throw new Error(`target url is not present in allowedHosts`); }, }, }); @@ -215,7 +215,7 @@ describe('config validation', () => { expect(() => { validateConfig(actionType, config); }).toThrowErrorMatchingInlineSnapshot( - `"error validating action type config: error configuring webhook action: target url is not whitelisted"` + `"error validating action type config: error configuring webhook action: target url is not present in allowedHosts"` ); }); }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/webhook.ts b/x-pack/plugins/actions/server/builtin_action_types/webhook.ts index d9a005565498..d0ec31721685 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/webhook.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/webhook.ts @@ -111,12 +111,12 @@ function validateActionTypeConfig( } try { - configurationUtilities.ensureWhitelistedUri(url.toString()); - } catch (whitelistError) { + configurationUtilities.ensureUriAllowed(url.toString()); + } catch (allowListError) { return i18n.translate('xpack.actions.builtin.webhook.webhookConfigurationError', { defaultMessage: 'error configuring webhook action: {message}', values: { - message: whitelistError.message, + message: allowListError.message, }, }); } diff --git a/x-pack/plugins/actions/server/config.test.ts b/x-pack/plugins/actions/server/config.test.ts index 795fbbf84145..ac815a425a2b 100644 --- a/x-pack/plugins/actions/server/config.test.ts +++ b/x-pack/plugins/actions/server/config.test.ts @@ -10,15 +10,15 @@ describe('config validation', () => { const config: Record = {}; expect(configSchema.validate(config)).toMatchInlineSnapshot(` Object { + "allowedHosts": Array [ + "*", + ], "enabled": true, "enabledActionTypes": Array [ "*", ], "preconfigured": Object {}, "rejectUnauthorizedCertificates": true, - "whitelistedHosts": Array [ - "*", - ], } `); }); @@ -38,6 +38,9 @@ describe('config validation', () => { }; expect(configSchema.validate(config)).toMatchInlineSnapshot(` Object { + "allowedHosts": Array [ + "*", + ], "enabled": true, "enabledActionTypes": Array [ "*", @@ -53,9 +56,6 @@ describe('config validation', () => { }, }, "rejectUnauthorizedCertificates": false, - "whitelistedHosts": Array [ - "*", - ], } `); }); diff --git a/x-pack/plugins/actions/server/config.ts b/x-pack/plugins/actions/server/config.ts index ba80915ebe24..087a08f572c6 100644 --- a/x-pack/plugins/actions/server/config.ts +++ b/x-pack/plugins/actions/server/config.ts @@ -5,7 +5,7 @@ */ import { schema, TypeOf } from '@kbn/config-schema'; -import { WhitelistedHosts, EnabledActionTypes } from './actions_config'; +import { AllowedHosts, EnabledActionTypes } from './actions_config'; const preconfiguredActionSchema = schema.object({ name: schema.string({ minLength: 1 }), @@ -16,16 +16,16 @@ const preconfiguredActionSchema = schema.object({ export const configSchema = schema.object({ enabled: schema.boolean({ defaultValue: true }), - whitelistedHosts: schema.arrayOf( - schema.oneOf([schema.string({ hostname: true }), schema.literal(WhitelistedHosts.Any)]), + allowedHosts: schema.arrayOf( + schema.oneOf([schema.string({ hostname: true }), schema.literal(AllowedHosts.Any)]), { - defaultValue: [WhitelistedHosts.Any], + defaultValue: [AllowedHosts.Any], } ), enabledActionTypes: schema.arrayOf( schema.oneOf([schema.string(), schema.literal(EnabledActionTypes.Any)]), { - defaultValue: [WhitelistedHosts.Any], + defaultValue: [AllowedHosts.Any], } ), preconfigured: schema.recordOf(schema.string(), preconfiguredActionSchema, { diff --git a/x-pack/plugins/actions/server/plugin.test.ts b/x-pack/plugins/actions/server/plugin.test.ts index 341a17889923..4fdf9f252356 100644 --- a/x-pack/plugins/actions/server/plugin.test.ts +++ b/x-pack/plugins/actions/server/plugin.test.ts @@ -32,7 +32,7 @@ describe('Actions Plugin', () => { context = coreMock.createPluginInitializerContext({ enabled: true, enabledActionTypes: ['*'], - whitelistedHosts: ['*'], + allowedHosts: ['*'], preconfigured: {}, rejectUnauthorizedCertificates: true, }); @@ -186,7 +186,7 @@ describe('Actions Plugin', () => { const context = coreMock.createPluginInitializerContext({ enabled: true, enabledActionTypes: ['*'], - whitelistedHosts: ['*'], + allowedHosts: ['*'], preconfigured: { preconfiguredServerLog: { actionTypeId: '.server-log', diff --git a/x-pack/plugins/actions/server/types.ts b/x-pack/plugins/actions/server/types.ts index bf7bd709a4a8..0a7d6bf01b7e 100644 --- a/x-pack/plugins/actions/server/types.ts +++ b/x-pack/plugins/actions/server/types.ts @@ -47,7 +47,7 @@ export interface ActionsPlugin { export interface ActionsConfigType { enabled: boolean; - whitelistedHosts: string[]; + allowedHosts: string[]; enabledActionTypes: string[]; } @@ -100,8 +100,8 @@ interface ValidatorType { } export interface ActionValidationService { - isWhitelistedHostname(hostname: string): boolean; - isWhitelistedUri(uri: string): boolean; + isHostnameAllowed(hostname: string): boolean; + isUriAllowed(uri: string): boolean; } export interface ActionType< diff --git a/x-pack/plugins/apm/public/components/shared/DatePicker/__test__/DatePicker.test.tsx b/x-pack/plugins/apm/public/components/shared/DatePicker/__test__/DatePicker.test.tsx index 2434d898389d..7a63b9e767fe 100644 --- a/x-pack/plugins/apm/public/components/shared/DatePicker/__test__/DatePicker.test.tsx +++ b/x-pack/plugins/apm/public/components/shared/DatePicker/__test__/DatePicker.test.tsx @@ -20,6 +20,7 @@ import { wait } from '@testing-library/react'; import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext'; const mockHistoryPush = jest.spyOn(history, 'push'); +const mockHistoryReplace = jest.spyOn(history, 'replace'); const mockRefreshTimeRange = jest.fn(); function MockUrlParamsProvider({ params = {}, @@ -69,8 +70,8 @@ describe('DatePicker', () => { it('sets default query params in the URL', () => { mountDatePicker(); - expect(mockHistoryPush).toHaveBeenCalledTimes(1); - expect(mockHistoryPush).toHaveBeenCalledWith( + expect(mockHistoryReplace).toHaveBeenCalledTimes(1); + expect(mockHistoryReplace).toHaveBeenCalledWith( expect.objectContaining({ search: 'rangeFrom=now-15m&rangeTo=now', }) @@ -82,8 +83,8 @@ describe('DatePicker', () => { rangeTo: 'now', refreshInterval: 5000, }); - expect(mockHistoryPush).toHaveBeenCalledTimes(1); - expect(mockHistoryPush).toHaveBeenCalledWith( + expect(mockHistoryReplace).toHaveBeenCalledTimes(1); + expect(mockHistoryReplace).toHaveBeenCalledWith( expect.objectContaining({ search: 'rangeFrom=now-15m&rangeTo=now&refreshInterval=5000', }) @@ -97,18 +98,19 @@ describe('DatePicker', () => { refreshPaused: false, refreshInterval: 5000, }); - expect(mockHistoryPush).toHaveBeenCalledTimes(0); + expect(mockHistoryReplace).toHaveBeenCalledTimes(0); }); it('updates the URL when the date range changes', () => { const datePicker = mountDatePicker(); + expect(mockHistoryReplace).toHaveBeenCalledTimes(1); datePicker.find(EuiSuperDatePicker).props().onTimeChange({ start: 'updated-start', end: 'updated-end', isInvalid: false, isQuickSelection: true, }); - expect(mockHistoryPush).toHaveBeenCalledTimes(2); + expect(mockHistoryPush).toHaveBeenCalledTimes(1); expect(mockHistoryPush).toHaveBeenLastCalledWith( expect.objectContaining({ search: 'rangeFrom=updated-start&rangeTo=updated-end', diff --git a/x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx b/x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx index 403a8cad854c..35b9525733e9 100644 --- a/x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx +++ b/x-pack/plugins/apm/public/components/shared/DatePicker/index.tsx @@ -89,7 +89,14 @@ export function DatePicker() { ...timePickerURLParams, }; if (!isEqual(nextParams, timePickerURLParams)) { - updateUrl(nextParams); + // When the default parameters are not availbale in the url, replace it adding the necessary parameters. + history.replace({ + ...location, + search: fromQuery({ + ...toQuery(location.search), + ...nextParams, + }), + }); } return ( diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.ts index 6b9464843fca..9cbd5ed3ee68 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/if.ts @@ -20,9 +20,10 @@ export function ifFn(): ExpressionFunctionDefinition<'if', unknown, Arguments, u help, args: { condition: { - types: ['boolean', 'null'], + types: ['boolean'], aliases: ['_'], help: argHelp.condition, + required: true, }, then: { resolve: false, diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.ts index 4066a35ea41f..c4ba5771408a 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/neq.ts @@ -20,6 +20,9 @@ export function neq(): ExpressionFunctionDefinition<'neq', Input, Arguments, boo name: 'neq', type: 'boolean', help, + context: { + types: ['boolean', 'number', 'string', 'null'], + }, args: { value: { aliases: ['_'], diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.ts index bb70bec561a1..453beb4c1106 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/switch.ts @@ -25,6 +25,7 @@ export function switchFn(): ExpressionFunctionDefinition<'switch', unknown, Argu aliases: ['_'], resolve: false, multi: true, + required: true, help: argHelp.case, }, default: { diff --git a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.ts b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.ts index 5105beb586f7..568e67db7f86 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/functions/common/tail.ts @@ -26,6 +26,7 @@ export function tail(): ExpressionFunctionDefinition<'tail', Datatable, Argument aliases: ['_'], types: ['number'], help: argHelp.count, + default: 1, }, }, fn: (input, args) => ({ diff --git a/x-pack/plugins/canvas/i18n/functions/dict/alter_column.ts b/x-pack/plugins/canvas/i18n/functions/dict/alter_column.ts index f201e73d717e..5f206399b42d 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/alter_column.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/alter_column.ts @@ -13,14 +13,14 @@ import { DATATABLE_COLUMN_TYPES } from '../../../common/lib/constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.alterColumnHelpText', { defaultMessage: - 'Converts between core types, including {list}, and {end}, and rename columns. ' + + 'Converts between core types, including {list}, and {end}, and renames columns. ' + 'See also {mapColumnFn} and {staticColumnFn}.', values: { list: Object.values(DATATABLE_COLUMN_TYPES) .slice(0, -1) .map((type) => `\`${type}\``) .join(', '), - end: Object.values(DATATABLE_COLUMN_TYPES).slice(-1)[0], + end: `\`${Object.values(DATATABLE_COLUMN_TYPES).slice(-1)[0]}\``, mapColumnFn: '`mapColumn`', staticColumnFn: '`staticColumn`', }, @@ -33,7 +33,7 @@ export const help: FunctionHelp> = { defaultMessage: 'The resultant column name. Leave blank to not rename.', }), type: i18n.translate('xpack.canvas.functions.alterColumn.args.typeHelpText', { - defaultMessage: 'The type to convert the column to. Leave blank to not change type.', + defaultMessage: 'The type to convert the column to. Leave blank to not change the type.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/as.ts b/x-pack/plugins/canvas/i18n/functions/dict/as.ts index e95aa641c71b..6154159d5e45 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/as.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/as.ts @@ -20,7 +20,7 @@ export const help: FunctionHelp> = { }), args: { name: i18n.translate('xpack.canvas.functions.as.args.nameHelpText', { - defaultMessage: 'A name to give the column.', + defaultMessage: 'The name to give the column.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/axis_config.ts b/x-pack/plugins/canvas/i18n/functions/dict/axis_config.ts index 7cf0ec6c5876..bedd677209ba 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/axis_config.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/axis_config.ts @@ -21,14 +21,14 @@ export const help: FunctionHelp> = { args: { max: i18n.translate('xpack.canvas.functions.axisConfig.args.maxHelpText', { defaultMessage: - 'The maximum value displayed in the axis. Must be a number or a date in milliseconds since epoch or {ISO8601} string.', + 'The maximum value displayed in the axis. Must be a number, a date in milliseconds since epoch, or an {ISO8601} string.', values: { ISO8601, }, }), min: i18n.translate('xpack.canvas.functions.axisConfig.args.minHelpText', { defaultMessage: - 'The minimum value displayed in the axis. Must be a number or a date in milliseconds since epoch or {ISO8601} string.', + 'The minimum value displayed in the axis. Must be a number, a date in milliseconds since epoch, or an {ISO8601} string.', values: { ISO8601, }, @@ -40,14 +40,14 @@ export const help: FunctionHelp> = { .slice(0, -1) .map((position) => `\`"${position}"\``) .join(', '), - end: Object.values(Position).slice(-1)[0], + end: `\`"${Object.values(Position).slice(-1)[0]}"\``, }, }), show: i18n.translate('xpack.canvas.functions.axisConfig.args.showHelpText', { defaultMessage: 'Show the axis labels?', }), tickSize: i18n.translate('xpack.canvas.functions.axisConfig.args.tickSizeHelpText', { - defaultMessage: 'The increment size between each tick. Use for `number` axes only', + defaultMessage: 'The increment size between each tick. Use for `number` axes only.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/case.ts b/x-pack/plugins/canvas/i18n/functions/dict/case.ts index 8f0689e5e383..884542420999 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/case.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/case.ts @@ -34,14 +34,14 @@ export const help: FunctionHelp> = { }), if: i18n.translate('xpack.canvas.functions.case.args.ifHelpText', { defaultMessage: - 'This value indicates whether the condition is met, usually using a sub-expression. The {IF_ARG} argument overrides the {WHEN_ARG} argument when both are provided.', + 'This value indicates whether the condition is met. The {IF_ARG} argument overrides the {WHEN_ARG} argument when both are provided.', values: { IF_ARG, WHEN_ARG, }, }), then: i18n.translate('xpack.canvas.functions.case.args.thenHelpText', { - defaultMessage: 'The value to return if the condition is met.', + defaultMessage: 'The value returned if the condition is met.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/compare.ts b/x-pack/plugins/canvas/i18n/functions/dict/compare.ts index 5697881503b8..cb57fde0cfcb 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/compare.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/compare.ts @@ -22,20 +22,20 @@ export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.compareHelpText', { defaultMessage: 'Compares the {CONTEXT} to specified value to determine {BOOLEAN_TRUE} or {BOOLEAN_FALSE}. Usually used in combination with `{ifFn}` or `{caseFn}`. ' + - 'This only works with primitive types, such as {examples}. See also `{eqFn}`, `{gtFn}`, `{gteFn}`, `{ltFn}`, `{lteFn}`, `{neqFn}`', + 'This only works with primitive types, such as {examples}. See also {eqFn}, {gtFn}, {gteFn}, {ltFn}, {lteFn}, {neqFn}', values: { CONTEXT, BOOLEAN_TRUE, BOOLEAN_FALSE, - ifFn: 'if', + ifFn: '`if`', caseFn: 'case', examples: [TYPE_NUMBER, TYPE_STRING, TYPE_BOOLEAN, TYPE_NULL].join(', '), - eqFn: 'eq', - gtFn: 'gt', - gteFn: 'gte', - ltFn: 'lt', - lteFn: 'lte', - neqFn: 'neq', + eqFn: '`eq`', + gtFn: '`gt`', + gteFn: '`gte`', + ltFn: '`lt`', + lteFn: '`lte`', + neqFn: '`neq`', }, }), args: { @@ -44,13 +44,13 @@ export const help: FunctionHelp> = { 'The operator to use in the comparison: {eq} (equal to), {gt} (greater than), {gte} (greater than or equal to)' + ', {lt} (less than), {lte} (less than or equal to), {ne} or {neq} (not equal to).', values: { - eq: Operation.EQ, - gt: Operation.GT, - gte: Operation.GTE, - lt: Operation.LT, - lte: Operation.LTE, - ne: Operation.NE, - neq: Operation.NEQ, + eq: `\`"${Operation.EQ}"\``, + gt: `\`"${Operation.GT}"\``, + gte: `\`"${Operation.GTE}"\``, + lt: `\`"${Operation.LT}"\``, + lte: `\`"${Operation.LTE}"\``, + ne: `\`"${Operation.NE}"\``, + neq: `\`"${Operation.NEQ}"\``, }, }), to: i18n.translate('xpack.canvas.functions.compare.args.toHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/container_style.ts b/x-pack/plugins/canvas/i18n/functions/dict/container_style.ts index bef2ccc2a8e3..f51206d7990a 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/container_style.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/container_style.ts @@ -74,7 +74,7 @@ export const help: FunctionHelp> = { }, }), padding: i18n.translate('xpack.canvas.functions.containerStyle.args.paddingHelpText', { - defaultMessage: 'The distance of the content, in pixels, from border.', + defaultMessage: 'The distance of the content, in pixels, from the border.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/date.ts b/x-pack/plugins/canvas/i18n/functions/dict/date.ts index 6964b62bcc58..1ccab1eb775a 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/date.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/date.ts @@ -29,7 +29,8 @@ export const help: FunctionHelp> = { }, }), format: i18n.translate('xpack.canvas.functions.date.args.formatHelpText', { - defaultMessage: 'The {MOMENTJS} format used to parse the specified date string. See {url}.', + defaultMessage: + 'The {MOMENTJS} format used to parse the specified date string. For more information, see {url}.', values: { MOMENTJS, url: 'https://momentjs.com/docs/#/displaying/', diff --git a/x-pack/plugins/canvas/i18n/functions/dict/dropdown_control.ts b/x-pack/plugins/canvas/i18n/functions/dict/dropdown_control.ts index 0d051a4f5f06..312e0e795ed0 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/dropdown_control.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/dropdown_control.ts @@ -11,7 +11,7 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.dropdownControlHelpText', { - defaultMessage: 'Configures a drop-down filter control element.', + defaultMessage: 'Configures a dropdown filter control element.', }), args: { filterColumn: i18n.translate( @@ -22,7 +22,7 @@ export const help: FunctionHelp> = { ), valueColumn: i18n.translate('xpack.canvas.functions.dropdownControl.args.valueColumnHelpText', { defaultMessage: - 'The column or field from which to extract the unique values for the drop-down control.', + 'The column or field from which to extract the unique values for the dropdown control.', }), filterGroup: i18n.translate('xpack.canvas.functions.dropdownControl.args.filterGroupHelpText', { defaultMessage: 'The group name for the filter.', diff --git a/x-pack/plugins/canvas/i18n/functions/dict/eq.ts b/x-pack/plugins/canvas/i18n/functions/dict/eq.ts index a856a81452cd..23f74068afa7 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/eq.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/eq.ts @@ -12,7 +12,7 @@ import { CONTEXT } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.eqHelpText', { - defaultMessage: 'Return whether the {CONTEXT} is equal to the argument.', + defaultMessage: 'Returns whether the {CONTEXT} is equal to the argument.', values: { CONTEXT, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/filterrows.ts b/x-pack/plugins/canvas/i18n/functions/dict/filterrows.ts index 3c1b6d87a9be..26f1cab51b45 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/filterrows.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/filterrows.ts @@ -12,7 +12,7 @@ import { DATATABLE, TYPE_BOOLEAN, BOOLEAN_TRUE, BOOLEAN_FALSE } from '../../cons export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.filterrowsHelpText', { - defaultMessage: 'Filter rows in a {DATATABLE} based on the return value of a sub-expression.', + defaultMessage: 'Filters rows in a {DATATABLE} based on the return value of a sub-expression.', values: { DATATABLE, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/formatdate.ts b/x-pack/plugins/canvas/i18n/functions/dict/formatdate.ts index 9b60c2f69f12..385403ce7557 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/formatdate.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/formatdate.ts @@ -25,7 +25,7 @@ export const help: FunctionHelp> = { defaultMessage: 'A {MOMENTJS} format. For example, {example}. See {url}.', values: { MOMENTJS, - example: `"MM/DD/YYYY"`, + example: '`"MM/DD/YYYY"`', url: 'https://momentjs.com/docs/#/displaying/', }, }), diff --git a/x-pack/plugins/canvas/i18n/functions/dict/formatnumber.ts b/x-pack/plugins/canvas/i18n/functions/dict/formatnumber.ts index f3e8a8858fc3..3dfcf3a9e476 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/formatnumber.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/formatnumber.ts @@ -12,7 +12,7 @@ import { NUMERALJS } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.formatnumberHelpText', { - defaultMessage: 'Formats a number into a formatted number string using {NUMERALJS}.', + defaultMessage: 'Formats a number into a formatted number string using the {NUMERALJS}.', values: { NUMERALJS, }, @@ -22,8 +22,8 @@ export const help: FunctionHelp> = { format: i18n.translate('xpack.canvas.functions.formatnumber.args.formatHelpText', { defaultMessage: 'A {NUMERALJS} format string. For example, {example1} or {example2}.', values: { - example1: `"0.0a"`, - example2: `"0%"`, + example1: '`"0.0a"`', + example2: '`"0%"`', NUMERALJS, }, }), diff --git a/x-pack/plugins/canvas/i18n/functions/dict/get_cell.ts b/x-pack/plugins/canvas/i18n/functions/dict/get_cell.ts index 79cc4f7e5c30..1cd4cd054d5d 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/get_cell.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/get_cell.ts @@ -12,7 +12,7 @@ import { DATATABLE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.getCellHelpText', { - defaultMessage: 'Fetchs a single cell from a {DATATABLE}.', + defaultMessage: 'Fetches a single cell from a {DATATABLE}.', values: { DATATABLE, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/head.ts b/x-pack/plugins/canvas/i18n/functions/dict/head.ts index 4c61339c29c2..8aef4afd63ef 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/head.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/head.ts @@ -12,7 +12,7 @@ import { DATATABLE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.headHelpText', { - defaultMessage: 'Retrieves the first {n} rows from the {DATATABLE}. See also {tailFn}', + defaultMessage: 'Retrieves the first {n} rows from the {DATATABLE}. See also {tailFn}.', values: { n: 'N', DATATABLE, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/if.ts b/x-pack/plugins/canvas/i18n/functions/dict/if.ts index 9cac3d10b283..5f840fad91e5 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/if.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/if.ts @@ -12,7 +12,7 @@ import { BOOLEAN_TRUE, BOOLEAN_FALSE, CONTEXT } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.ifHelpText', { - defaultMessage: 'Perform conditional logic', + defaultMessage: 'Performs conditional logic.', }), args: { condition: i18n.translate('xpack.canvas.functions.if.args.conditionHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/join_rows.ts b/x-pack/plugins/canvas/i18n/functions/dict/join_rows.ts index 59684f7cf1cd..36293d41a527 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/join_rows.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/join_rows.ts @@ -11,20 +11,20 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.joinRowsHelpText', { - defaultMessage: 'Join values from rows in a datatable into a string', + defaultMessage: 'Concatenates values from rows in a `datatable` into a single string.', }), args: { column: i18n.translate('xpack.canvas.functions.joinRows.args.columnHelpText', { - defaultMessage: 'The column to join values from', + defaultMessage: 'The column or field from which to extract the values.', }), separator: i18n.translate('xpack.canvas.functions.joinRows.args.separatorHelpText', { - defaultMessage: 'The separator to use between row values', + defaultMessage: 'The delimiter to insert between each extracted value.', }), quote: i18n.translate('xpack.canvas.functions.joinRows.args.quoteHelpText', { - defaultMessage: 'The quote character around values', + defaultMessage: 'The quote character to wrap around each extracted value.', }), distinct: i18n.translate('xpack.canvas.functions.joinRows.args.distinctHelpText', { - defaultMessage: 'Removes duplicate values?', + defaultMessage: 'Extract only unique values?', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/location.ts b/x-pack/plugins/canvas/i18n/functions/dict/location.ts index 7c0497da8361..3bd98914ecb1 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/location.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/location.ts @@ -14,10 +14,11 @@ export const help: FunctionHelp> = { defaultMessage: 'Find your current location using the {geolocationAPI} of the browser. ' + 'Performance can vary, but is fairly accurate. ' + - 'See {url}.', + 'See {url}. Don’t use {locationFn} if you plan to generate PDFs as this function requires user input.', values: { geolocationAPI: 'Geolocation API', url: 'https://developer.mozilla.org/en-US/docs/Web/API/Navigator/geolocation', + locationFn: '`location`', }, }), args: {}, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/map_center.ts b/x-pack/plugins/canvas/i18n/functions/dict/map_center.ts index 3022ad07089d..540980875268 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/map_center.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/map_center.ts @@ -11,7 +11,7 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.mapCenterHelpText', { - defaultMessage: `Returns an object with the center coordinates and zoom level of the map`, + defaultMessage: `Returns an object with the center coordinates and zoom level of the map.`, }), args: { lat: i18n.translate('xpack.canvas.functions.mapCenter.args.latHelpText', { @@ -21,7 +21,7 @@ export const help: FunctionHelp> = { defaultMessage: `Longitude for the center of the map`, }), zoom: i18n.translate('xpack.canvas.functions.savedMap.args.zoomHelpText', { - defaultMessage: `The zoom level of the map`, + defaultMessage: `Zoom level of the map`, }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/map_column.ts b/x-pack/plugins/canvas/i18n/functions/dict/map_column.ts index 589dd9b1dad8..2666a08999fb 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/map_column.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/map_column.ts @@ -14,10 +14,10 @@ export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.mapColumnHelpText', { defaultMessage: 'Adds a column calculated as the result of other columns. ' + - 'Changes are made only when you provide arguments. ' + - 'See also {mapColumnFn} and {staticColumnFn}.', + 'Changes are made only when you provide arguments.' + + 'See also {alterColumnFn} and {staticColumnFn}.', values: { - mapColumnFn: '`mapColumn`', + alterColumnFn: '`alterColumn`', staticColumnFn: '`staticColumn`', }, }), diff --git a/x-pack/plugins/canvas/i18n/functions/dict/markdown.ts b/x-pack/plugins/canvas/i18n/functions/dict/markdown.ts index aa2845ba4ec3..093bdaecccb3 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/markdown.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/markdown.ts @@ -33,13 +33,13 @@ export const help: FunctionHelp> = { 'The {CSS} font properties for the content. For example, {fontFamily} or {fontWeight}.', values: { CSS, - fontFamily: 'font-family', - fontWeight: 'font-weight', + fontFamily: '"font-family"', + fontWeight: '"font-weight"', }, }), openLinksInNewTab: i18n.translate('xpack.canvas.functions.markdown.args.openLinkHelpText', { defaultMessage: - 'A true/false value for opening links in a new tab. Default value is false. Setting to true will open all links in a new tab.', + 'A true or false value for opening links in a new tab. The default value is `false`. Setting to `true` opens all links in a new tab.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/math.ts b/x-pack/plugins/canvas/i18n/functions/dict/math.ts index 752009fb9c32..4469c629fa6f 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/math.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/math.ts @@ -8,12 +8,12 @@ import { i18n } from '@kbn/i18n'; import { math } from '../../../canvas_plugin_src/functions/common/math'; import { FunctionHelp } from '../function_help'; import { FunctionFactory } from '../../../types'; -import { DATATABLE, CONTEXT, TINYMATH, TINYMATH_URL } from '../../constants'; +import { DATATABLE, CONTEXT, TINYMATH, TINYMATH_URL, TYPE_NUMBER } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.mathHelpText', { defaultMessage: - 'Interprets a {TINYMATH} math expression using a number or {DATATABLE} as {CONTEXT}. ' + + 'Interprets a {TINYMATH} math expression using a {TYPE_NUMBER} or {DATATABLE} as {CONTEXT}. ' + 'The {DATATABLE} columns are available by their column name. ' + 'If the {CONTEXT} is a number it is available as {value}.', values: { @@ -21,6 +21,7 @@ export const help: FunctionHelp> = { CONTEXT, DATATABLE, value: '`value`', + TYPE_NUMBER, }, }), args: { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/metric.ts b/x-pack/plugins/canvas/i18n/functions/dict/metric.ts index 8258226e5dfc..f84456b03a86 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/metric.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/metric.ts @@ -40,8 +40,8 @@ export const help: FunctionHelp> = { metricFormat: i18n.translate('xpack.canvas.functions.metric.args.metricFormatHelpText', { defaultMessage: 'A {NUMERALJS} format string. For example, {example1} or {example2}.', values: { - example1: `"0.0a"`, - example2: `"0%"`, + example1: '`"0.0a"`', + example2: '`"0%"`', NUMERALJS, }, }), diff --git a/x-pack/plugins/canvas/i18n/functions/dict/pie.ts b/x-pack/plugins/canvas/i18n/functions/dict/pie.ts index 2e4bfc88a273..149c2f8f1e63 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/pie.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/pie.ts @@ -8,12 +8,12 @@ import { i18n } from '@kbn/i18n'; import { pie } from '../../../canvas_plugin_src/functions/common/pie'; import { FunctionHelp } from '../function_help'; import { FunctionFactory } from '../../../types'; -import { Position } from '../../../types'; +import { Legend } from '../../../types'; import { CSS, FONT_FAMILY, FONT_WEIGHT, BOOLEAN_FALSE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.pieHelpText', { - defaultMessage: 'Configure a pie chart element.', + defaultMessage: 'Configures a pie chart element.', }), args: { font: i18n.translate('xpack.canvas.functions.pie.args.fontHelpText', { @@ -38,20 +38,18 @@ export const help: FunctionHelp> = { }), legend: i18n.translate('xpack.canvas.functions.pie.args.legendHelpText', { defaultMessage: - 'The legend position. For example, {positions}, or {BOOLEAN_FALSE}. When {BOOLEAN_FALSE}, the legend is hidden.', + 'The legend position. For example, {legend}, or {BOOLEAN_FALSE}. When {BOOLEAN_FALSE}, the legend is hidden.', values: { - positions: Object.values(Position) + legend: Object.values(Legend) .map((position) => `\`"${position}"\``) .join(', '), BOOLEAN_FALSE, }, }), palette: i18n.translate('xpack.canvas.functions.pie.args.paletteHelpText', { - defaultMessage: - 'A {palette} object for describing the colors to use in this pie chart. See {paletteFn}.', + defaultMessage: 'A {palette} object for describing the colors to use in this pie chart.', values: { palette: '`palette`', - paletteFn: '`palette`', }, }), radius: i18n.translate('xpack.canvas.functions.pie.args.radiusHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/plot.ts b/x-pack/plugins/canvas/i18n/functions/dict/plot.ts index 068156f14c91..aca2476a6592 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/plot.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/plot.ts @@ -8,12 +8,12 @@ import { i18n } from '@kbn/i18n'; import { plot } from '../../../canvas_plugin_src/functions/common/plot'; import { FunctionHelp } from '../function_help'; import { FunctionFactory } from '../../../types'; -import { Position } from '../../../types'; +import { Legend } from '../../../types'; import { CSS, FONT_FAMILY, FONT_WEIGHT, BOOLEAN_FALSE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.plotHelpText', { - defaultMessage: 'Configure a chart element', + defaultMessage: 'Configures a chart element.', }), args: { defaultStyle: i18n.translate('xpack.canvas.functions.plot.args.defaultStyleHelpText', { @@ -30,20 +30,18 @@ export const help: FunctionHelp> = { }), legend: i18n.translate('xpack.canvas.functions.plot.args.legendHelpText', { defaultMessage: - 'The legend position. For example, {positions}, or {BOOLEAN_FALSE}. When {BOOLEAN_FALSE}, the legend is hidden.', + 'The legend position. For example, {legend}, or {BOOLEAN_FALSE}. When {BOOLEAN_FALSE}, the legend is hidden.', values: { - positions: Object.values(Position) + legend: Object.values(Legend) .map((position) => `\`"${position}"\``) .join(', '), BOOLEAN_FALSE, }, }), palette: i18n.translate('xpack.canvas.functions.plot.args.paletteHelpText', { - defaultMessage: - 'A {palette} object for describing the colors to use in this chart. See {paletteFn}.', + defaultMessage: 'A {palette} object for describing the colors to use in this chart.', values: { palette: '`palette`', - paletteFn: '`palette`', }, }), seriesStyle: i18n.translate('xpack.canvas.functions.plot.args.seriesStyleHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/ply.ts b/x-pack/plugins/canvas/i18n/functions/dict/ply.ts index f341965aaa8b..3bb9c1b3e46a 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/ply.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/ply.ts @@ -13,8 +13,8 @@ import { DATATABLE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.plyHelpText', { defaultMessage: - 'Subdivides a {DATATABLE} by the unique values of the specified column, ' + - 'and passes the resulting tables into an expression, then merges the outputs of each expression', + 'Subdivides a {DATATABLE} by the unique values of the specified columns, ' + + 'and passes the resulting tables into an expression, then merges the outputs of each expression.', values: { DATATABLE, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/pointseries.ts b/x-pack/plugins/canvas/i18n/functions/dict/pointseries.ts index 1e7c67bb750e..2579db77ff1b 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/pointseries.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/pointseries.ts @@ -35,10 +35,10 @@ export const help: FunctionHelp> = { defaultMessage: 'The text to show on the mark. Only applicable to supported elements.', }), x: i18n.translate('xpack.canvas.functions.pointseries.args.xHelpText', { - defaultMessage: 'The values along the x-axis.', + defaultMessage: 'The values along the X-axis.', }), y: i18n.translate('xpack.canvas.functions.pointseries.args.yHelpText', { - defaultMessage: 'The values along the y-axis.', + defaultMessage: 'The values along the Y-axis.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/progress.ts b/x-pack/plugins/canvas/i18n/functions/dict/progress.ts index 1880c5dc807f..199d5d926f27 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/progress.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/progress.ts @@ -34,7 +34,7 @@ export const help: FunctionHelp> = { }), label: i18n.translate('xpack.canvas.functions.progress.args.labelHelpText', { defaultMessage: - 'To show or hide labels, use {BOOLEAN_TRUE} or {BOOLEAN_FALSE}. Alternatively, provide a string to display as a label.', + 'To show or hide the label, use {BOOLEAN_TRUE} or {BOOLEAN_FALSE}. Alternatively, provide a string to display as a label.', values: { BOOLEAN_TRUE, BOOLEAN_FALSE, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/render.ts b/x-pack/plugins/canvas/i18n/functions/dict/render.ts index bf0a5a50b872..7ddb04de490e 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/render.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/render.ts @@ -13,7 +13,7 @@ import { CONTEXT, CSS } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.renderHelpText', { defaultMessage: - 'Render the {CONTEXT} as a specific element and sets element level options, such as background and border styling.', + 'Renders the {CONTEXT} as a specific element and sets element level options, such as background and border styling.', values: { CONTEXT, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/repeat_image.ts b/x-pack/plugins/canvas/i18n/functions/dict/repeat_image.ts index 222947779a75..4de92b0552bf 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/repeat_image.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/repeat_image.ts @@ -17,7 +17,7 @@ export const help: FunctionHelp> = { args: { emptyImage: i18n.translate('xpack.canvas.functions.repeatImage.args.emptyImageHelpText', { defaultMessage: - 'Fills the difference between the {CONTEXT} and {maxArg} parameter for the element with this image' + + 'Fills the difference between the {CONTEXT} and {maxArg} parameter for the element with this image. ' + 'Provide an image asset as a {BASE64} data {URL}, or pass in a sub-expression.', values: { BASE64, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/replace.ts b/x-pack/plugins/canvas/i18n/functions/dict/replace.ts index 085f42b439c4..e99c9740c57d 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/replace.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/replace.ts @@ -12,7 +12,7 @@ import { JS } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.replaceImageHelpText', { - defaultMessage: 'Use a regular expression to replace parts of a string.', + defaultMessage: 'Uses a regular expression to replace parts of a string.', }), args: { pattern: i18n.translate('xpack.canvas.functions.replace.args.patternHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts b/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts index 410ca29d7b4d..6a8909f4acdd 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/reveal_image.ts @@ -13,7 +13,7 @@ import { BASE64, URL } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.revealImageHelpText', { - defaultMessage: 'Configure an image reveal element.', + defaultMessage: 'Configures an image reveal element.', }), args: { image: i18n.translate('xpack.canvas.functions.revealImage.args.imageHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/rounddate.ts b/x-pack/plugins/canvas/i18n/functions/dict/rounddate.ts index 4805fe16a94f..d2728b637139 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/rounddate.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/rounddate.ts @@ -21,7 +21,7 @@ export const help: FunctionHelp> = { args: { format: i18n.translate('xpack.canvas.functions.rounddate.args.formatHelpText', { defaultMessage: - 'The {MOMENTJS} format to use for bucketing. For example, {example} would round each date to months. See {url}.', + 'The {MOMENTJS} format to use for bucketing. For example, {example} rounds to months. See {url}.', values: { example: '`"YYYY-MM"`', MOMENTJS, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/row_count.ts b/x-pack/plugins/canvas/i18n/functions/dict/row_count.ts index 5b0cecd47fd7..fd7c651238c2 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/row_count.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/row_count.ts @@ -12,7 +12,7 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.rowCountHelpText', { defaultMessage: - 'Returns the number of rows. Pair with {plyFn} to get the count of unique column ' + + 'Returns the number of rows. Pairs with {plyFn} to get the count of unique column ' + 'values, or combinations of unique column values.', values: { plyFn: '`ply`', diff --git a/x-pack/plugins/canvas/i18n/functions/dict/saved_lens.ts b/x-pack/plugins/canvas/i18n/functions/dict/saved_lens.ts index e146a6ca6844..1121aa43f350 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/saved_lens.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/saved_lens.ts @@ -11,17 +11,17 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.savedLensHelpText', { - defaultMessage: `Returns an embeddable for a saved lens object`, + defaultMessage: `Returns an embeddable for a saved Lens visualization object.`, }), args: { id: i18n.translate('xpack.canvas.functions.savedLens.args.idHelpText', { - defaultMessage: `The ID of the Saved Lens Object`, + defaultMessage: `The ID of the saved Lens visualization object`, }), timerange: i18n.translate('xpack.canvas.functions.savedLens.args.timerangeHelpText', { defaultMessage: `The timerange of data that should be included`, }), title: i18n.translate('xpack.canvas.functions.savedLens.args.titleHelpText', { - defaultMessage: `The title for the lens emebeddable`, + defaultMessage: `The title for the Lens visualization object`, }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/saved_map.ts b/x-pack/plugins/canvas/i18n/functions/dict/saved_map.ts index 861556589743..bacaca523ed2 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/saved_map.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/saved_map.ts @@ -11,11 +11,11 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.savedMapHelpText', { - defaultMessage: `Returns an embeddable for a saved map object`, + defaultMessage: `Returns an embeddable for a saved map object.`, }), args: { id: i18n.translate('xpack.canvas.functions.savedMap.args.idHelpText', { - defaultMessage: `The ID of the Saved Map Object`, + defaultMessage: `The ID of the saved map object`, }), center: i18n.translate('xpack.canvas.functions.savedMap.args.centerHelpText', { defaultMessage: `The center and zoom level the map should have`, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/saved_visualization.ts b/x-pack/plugins/canvas/i18n/functions/dict/saved_visualization.ts index 30f88b51e757..e8cbddc5c110 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/saved_visualization.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/saved_visualization.ts @@ -11,22 +11,22 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.savedVisualizationHelpText', { - defaultMessage: `Returns an embeddable for a saved visualization object`, + defaultMessage: `Returns an embeddable for a saved visualization object.`, }), args: { id: i18n.translate('xpack.canvas.functions.savedVisualization.args.idHelpText', { - defaultMessage: `The ID of the Saved Visualization Object`, + defaultMessage: `The ID of the saved visualization object`, }), timerange: i18n.translate('xpack.canvas.functions.savedVisualization.args.timerangeHelpText', { defaultMessage: `The timerange of data that should be included`, }), colors: i18n.translate('xpack.canvas.functions.savedVisualization.args.colorsHelpText', { - defaultMessage: `Define the color to use for a specific series`, + defaultMessage: `Defines the color to use for a specific series`, }), hideLegend: i18n.translate( 'xpack.canvas.functions.savedVisualization.args.hideLegendHelpText', { - defaultMessage: `Should the legend be hidden`, + defaultMessage: `Specifies the option to hide the legend`, } ), }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/series_style.ts b/x-pack/plugins/canvas/i18n/functions/dict/series_style.ts index 7b3855b52820..3f6daa588b73 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/series_style.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/series_style.ts @@ -43,7 +43,7 @@ export const help: FunctionHelp> = { defaultMessage: 'The width of the line.', }), points: i18n.translate('xpack.canvas.functions.seriesStyle.args.pointsHelpText', { - defaultMessage: 'Size of points on line', + defaultMessage: 'The size of points on line.', }), stack: i18n.translate('xpack.canvas.functions.seriesStyle.args.stackHelpText', { defaultMessage: diff --git a/x-pack/plugins/canvas/i18n/functions/dict/shape.ts b/x-pack/plugins/canvas/i18n/functions/dict/shape.ts index bcd6d90faa3f..ddc988873f11 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/shape.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/shape.ts @@ -12,7 +12,7 @@ import { SVG } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.shapeHelpText', { - defaultMessage: 'Create a shape.', + defaultMessage: 'Creates a shape.', }), args: { shape: i18n.translate('xpack.canvas.functions.shape.args.shapeHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/sort.ts b/x-pack/plugins/canvas/i18n/functions/dict/sort.ts index d53944925305..b768362dd077 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/sort.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/sort.ts @@ -12,12 +12,15 @@ import { DATATABLE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.sortHelpText', { - defaultMessage: 'Sorts a datatable by the specified column.', + defaultMessage: 'Sorts a {DATATABLE} by the specified column.', + values: { + DATATABLE, + }, }), args: { by: i18n.translate('xpack.canvas.functions.sort.args.byHelpText', { defaultMessage: - 'The column to sort by. When unspecified, the `{DATATABLE}` ' + + 'The column to sort by. When unspecified, the {DATATABLE} ' + 'is sorted by the first column.', values: { DATATABLE, @@ -25,7 +28,7 @@ export const help: FunctionHelp> = { }), reverse: i18n.translate('xpack.canvas.functions.sort.args.reverseHelpText', { defaultMessage: - 'Reverses the sorting order. When unspecified, the `{DATATABLE}` ' + + 'Reverses the sorting order. When unspecified, the {DATATABLE} ' + 'is sorted in ascending order.', values: { DATATABLE, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/static_column.ts b/x-pack/plugins/canvas/i18n/functions/dict/static_column.ts index 82dbd9910ea3..f0f7b46a2c0b 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/static_column.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/static_column.ts @@ -12,7 +12,7 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.staticColumnHelpText', { defaultMessage: - 'Add a column with the same static value in every row. See also {alterColumnFn} and {mapColumnFn}.', + 'Adds a column with the same static value in every row. See also {alterColumnFn} and {mapColumnFn}.', values: { alterColumnFn: '`alterColumn`', mapColumnFn: '`mapColumn`', @@ -20,11 +20,11 @@ export const help: FunctionHelp> = { }), args: { name: i18n.translate('xpack.canvas.functions.staticColumn.args.nameHelpText', { - defaultMessage: 'The name of the new column column.', + defaultMessage: 'The name of the new column.', }), value: i18n.translate('xpack.canvas.functions.staticColumn.args.valueHelpText', { defaultMessage: - 'The value to insert in each row in the new column. Tip: use a sub-expression to rollup ' + + 'The value to insert in each row in the new column. TIP: use a sub-expression to rollup ' + 'other columns into a static value.', }), }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/switch.ts b/x-pack/plugins/canvas/i18n/functions/dict/switch.ts index f65ff7c6fd24..aaf53d2c47c3 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/switch.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/switch.ts @@ -14,7 +14,7 @@ export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.switchHelpText', { defaultMessage: 'Performs conditional logic with multiple conditions. ' + - 'See also {caseFn} which builds a {case} to pass to the {switchFn} function.', + 'See also {caseFn}, which builds a {case} to pass to the {switchFn} function.', values: { case: '`case`', caseFn: '`case`', @@ -23,7 +23,7 @@ export const help: FunctionHelp> = { }), args: { case: i18n.translate('xpack.canvas.functions.switch.args.caseHelpText', { - defaultMessage: 'The conditions to check', + defaultMessage: 'The conditions to check.', }), default: i18n.translate('xpack.canvas.functions.switch.args.defaultHelpText', { defaultMessage: diff --git a/x-pack/plugins/canvas/i18n/functions/dict/table.ts b/x-pack/plugins/canvas/i18n/functions/dict/table.ts index 91a9ae748823..9fe93b2136fb 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/table.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/table.ts @@ -12,7 +12,7 @@ import { CSS, FONT_FAMILY, FONT_WEIGHT, BOOLEAN_FALSE } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.tableHelpText', { - defaultMessage: 'Configures a table element', + defaultMessage: 'Configures a table element.', }), args: { font: i18n.translate('xpack.canvas.functions.table.args.fontHelpText', { @@ -35,7 +35,7 @@ export const help: FunctionHelp> = { defaultMessage: 'The number of rows to display on each page.', }), showHeader: i18n.translate('xpack.canvas.functions.table.args.showHeaderHelpText', { - defaultMessage: 'Show/hide the header row with titles for each column.', + defaultMessage: 'Show or hide the header row with titles for each column.', }), }, }; diff --git a/x-pack/plugins/canvas/i18n/functions/dict/time_range.ts b/x-pack/plugins/canvas/i18n/functions/dict/time_range.ts index 476a9978800d..e3fa931a8f07 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/time_range.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/time_range.ts @@ -11,7 +11,7 @@ import { FunctionFactory } from '../../../types'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.timerangeHelpText', { - defaultMessage: `An object that represents a span of time`, + defaultMessage: `An object that represents a span of time.`, }), args: { from: i18n.translate('xpack.canvas.functions.timerange.args.fromHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/timefilter.ts b/x-pack/plugins/canvas/i18n/functions/dict/timefilter.ts index aedcdc944188..80f2544e11a4 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/timefilter.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/timefilter.ts @@ -12,7 +12,7 @@ import { ISO8601, ELASTICSEARCH, DATEMATH } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.timefilterHelpText', { - defaultMessage: 'Create a time filter for querying a source.', + defaultMessage: 'Creates a time filter for querying a source.', }), args: { column: i18n.translate('xpack.canvas.functions.timefilter.args.columnHelpText', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/timelion.ts b/x-pack/plugins/canvas/i18n/functions/dict/timelion.ts index 41bf86055f1e..d76e30c1ef81 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/timelion.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/timelion.ts @@ -12,7 +12,7 @@ import { ELASTICSEARCH, DATEMATH, MOMENTJS_TIMEZONE_URL } from '../../constants' export const help: FunctionHelp>> = { help: i18n.translate('xpack.canvas.functions.timelionHelpText', { - defaultMessage: 'Use Timelion to extract one or more timeseries from many sources.', + defaultMessage: 'Uses Timelion to extract one or more time series from many sources.', }), args: { query: i18n.translate('xpack.canvas.functions.timelion.args.query', { diff --git a/x-pack/plugins/canvas/i18n/functions/dict/to.ts b/x-pack/plugins/canvas/i18n/functions/dict/to.ts index c618f84aeaf2..177e4367b6ec 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/to.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/to.ts @@ -12,7 +12,8 @@ import { CONTEXT } from '../../constants'; export const help: FunctionHelp>> = { help: i18n.translate('xpack.canvas.functions.toHelpText', { - defaultMessage: 'Explicitly casts the type of the {CONTEXT} to the specified type.', + defaultMessage: + 'Explicitly casts the type of the {CONTEXT} from one type to the specified type.', values: { CONTEXT, }, diff --git a/x-pack/plugins/canvas/i18n/functions/dict/urlparam.ts b/x-pack/plugins/canvas/i18n/functions/dict/urlparam.ts index b8c044f52102..0331d239d48a 100644 --- a/x-pack/plugins/canvas/i18n/functions/dict/urlparam.ts +++ b/x-pack/plugins/canvas/i18n/functions/dict/urlparam.ts @@ -13,11 +13,11 @@ import { TYPE_STRING, URL } from '../../constants'; export const help: FunctionHelp> = { help: i18n.translate('xpack.canvas.functions.urlparamHelpText', { defaultMessage: - 'Retreives a {URL} parameter to use in an expression. ' + + 'Retrieves a {URL} parameter to use in an expression. ' + 'The {urlparamFn} function always returns a {TYPE_STRING}. ' + - 'For example, you can retrieve the value {value} from the parameter {myVar} from the {URL} {example}).', + 'For example, you can retrieve the value {value} from the parameter {myVar} from the {URL} {example}.', values: { - example: 'https://localhost:5601/app/canvas?myVar=20', + example: '`https://localhost:5601/app/canvas?myVar=20`', myVar: '`myVar`', TYPE_STRING, URL, diff --git a/x-pack/plugins/canvas/public/application.tsx b/x-pack/plugins/canvas/public/application.tsx index 482cd0437310..463fb1efbd3b 100644 --- a/x-pack/plugins/canvas/public/application.tsx +++ b/x-pack/plugins/canvas/public/application.tsx @@ -22,7 +22,6 @@ import { registerLanguage } from './lib/monaco_language_def'; import { SetupRegistries } from './plugin_api'; import { initRegistries, populateRegistries, destroyRegistries } from './registries'; import { getDocumentationLinks } from './lib/documentation_links'; -// @ts-expect-error untyped component import { HelpMenu } from './components/help_menu/help_menu'; import { createStore } from './store'; @@ -128,7 +127,10 @@ export const initializeCanvas = async ( }, ], content: (domNode) => { - ReactDOM.render(, domNode); + ReactDOM.render( + , + domNode + ); return () => ReactDOM.unmountComponentAtNode(domNode); }, }); diff --git a/x-pack/plugins/canvas/public/components/function_reference_generator/function_examples.ts b/x-pack/plugins/canvas/public/components/function_reference_generator/function_examples.ts new file mode 100644 index 000000000000..61c1c1588a29 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_reference_generator/function_examples.ts @@ -0,0 +1,444 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export interface FunctionExample { + syntax: string; + usage: { + expression: string; + help?: string; + }; +} + +interface FunctionExampleDict { + [key: string]: FunctionExample; +} + +export const getFunctionExamples = (): FunctionExampleDict => ({ + all: { + syntax: `all {neq "foo"} {neq "bar"} {neq "fizz"} +all condition={gt 10} condition={lt 20}`, + usage: { + expression: `filters +| demodata +| math "mean(percent_uptime)" +| formatnumber "0.0%" +| metric "Average uptime" + metricFont={ + font size=48 family="'Open Sans', Helvetica, Arial, sans-serif" + color={ + if {all {gte 0} {lt 0.8}} then="red" else="green" + } + align="center" lHeight=48 + } +| render`, + help: + 'This sets the color of the metric text to `"red"` if the context passed into `metric` is greater than or equal to 0 and less than 0.8. Otherwise, the color is set to `"green"`.', + }, + }, + alterColumn: { + syntax: `alterColumn "cost" type="string" +alterColumn column="@timestamp" name="foo"`, + usage: { + expression: `filters +| demodata +| alterColumn "time" name="time_in_ms" type="number" +| table +| render`, + help: + 'This renames the `time` column to `time_in_ms` and converts the type of the column’s values from `date` to `number`.', + }, + }, + any: { + syntax: `any {eq "foo"} {eq "bar"} {eq "fizz"} +any condition={lte 10} condition={gt 30}`, + usage: { + expression: `filters +| demodata +| filterrows { + getCell "project" | any {eq "elasticsearch"} {eq "kibana"} {eq "x-pack"} + } +| pointseries color="project" size="max(price)" +| pie +| render`, + help: + 'This filters out any rows that don’t contain `"elasticsearch"`, `"kibana"` or `"x-pack"` in the `project` field.', + }, + }, + as: { + syntax: `as +as "foo" +as name="bar"`, + usage: { + expression: `filters +| demodata +| ply by="project" fn={math "count(username)" | as "num_users"} fn={math "mean(price)" | as "price"} +| pointseries x="project" y="num_users" size="price" color="project" +| plot +| render`, + help: `\`as\` casts any primitive value (\`string\`, \`number\`, \`date\`, \`null\`) into a \`datatable\` with a single row and a single column with the given name (or defaults to \`"value"\` if no name is provided). This is useful when piping a primitive value into a function that only takes \`datatable\` as an input. + +In the example, \`ply\` expects each \`fn\` subexpression to return a \`datatable\` in order to merge the results of each \`fn\` back into a \`datatable\`, but using a \`math\` aggregation in the subexpressions returns a single \`math\` value, which is then cast into a \`datatable\` using \`as\`.`, + }, + }, + asset: { + syntax: `asset "asset-52f14f2b-fee6-4072-92e8-cd2642665d02" +asset id="asset-498f7429-4d56-42a2-a7e4-8bf08d98d114"`, + usage: { + expression: `image dataurl={asset "asset-c661a7cc-11be-45a1-a401-d7592ea7917a"} mode="contain" +| render`, + help: + 'The image asset stored with the ID `"asset-c661a7cc-11be-45a1-a401-d7592ea7917a"` is passed into the `dataurl` argument of the `image` function to display the stored asset.', + }, + }, + axisConfig: { + syntax: `axisConfig show=false +axisConfig position="right" min=0 max=10 tickSize=1`, + usage: { + expression: `filters +| demodata +| pointseries x="size(cost)" y="project" color="project" +| plot defaultStyle={seriesStyle bars=0.75 horizontalBars=true} + legend=false + xaxis={axisConfig position="top" min=0 max=400 tickSize=100} + yaxis={axisConfig position="right"} +| render`, + help: + 'This sets the `x-axis` to display on the top of the chart and sets the range of values to `0-400` with ticks displayed at `100` intervals. The `y-axis` is configured to display on the `right`.', + }, + }, + case: { + syntax: `case 0 then="red" +case when=5 then="yellow" +case if={lte 50} then="green"`, + usage: { + expression: `math "random()" +| progress shape="gauge" label={formatnumber "0%"} + font={ + font size=24 family="'Open Sans', Helvetica, Arial, sans-serif" align="center" + color={ + switch {case if={lte 0.5} then="green"} + {case if={all {gt 0.5} {lte 0.75}} then="orange"} + default="red" + } + } + valueColor={ + switch {case if={lte 0.5} then="green"} + {case if={all {gt 0.5} {lte 0.75}} then="orange"} + default="red" + } +| render`, + help: + 'This sets the color of the progress indicator and the color of the label to `"green"` if the value is less than or equal to `0.5`, `"orange"` if the value is greater than `0.5` and less than or equal to `0.75`, and `"red"` if `none` of the case conditions are met.', + }, + }, + columns: { + syntax: `columns include="@timestamp, projects, cost" +columns exclude="username, country, age"`, + usage: { + expression: `filters +| demodata +| columns include="price, cost, state, project" +| table +| render`, + help: + 'This only keeps the `price`, `cost`, `state`, and `project` columns from the `demodata` data source and removes all other columns.', + }, + }, + compare: { + syntax: `compare "neq" to="elasticsearch" +compare op="lte" to=100`, + usage: { + expression: `filters +| demodata +| mapColumn project + fn={getCell project | + switch + {case if={compare eq to=kibana} then=kibana} + {case if={compare eq to=elasticsearch} then=elasticsearch} + default="other" + } +| pointseries size="size(cost)" color="project" +| pie +| render`, + help: + 'This maps all `project` values that aren’t `"kibana"` and `"elasticsearch"` to `"other"`. Alternatively, you can use the individual comparator functions instead of compare.', + }, + }, + containerStyle: { + syntax: `containerStyle backgroundColor="red"’ +containerStyle borderRadius="50px" +containerStyle border="1px solid black" +containerStyle padding="5px" +containerStyle opacity="0.5" +containerStyle overflow="hidden" +containerStyle backgroundImage={asset id=asset-f40d2292-cf9e-4f2c-8c6f-a504a25e949c} + backgroundRepeat="no-repeat" + backgroundSize="cover"`, + usage: { + expression: `shape "star" fill="#E61D35" maintainAspect=true +| render containerStyle={ + containerStyle backgroundColor="#F8D546" + borderRadius="200px" + border="4px solid #05509F" + padding="0px" + opacity="0.9" + overflow="hidden" + }`, + }, + }, + context: { + syntax: `context`, + usage: { + expression: `date +| formatdate "LLLL" +| markdown "Last updated: " {context} +| render`, + help: + 'Using the `context` function allows us to pass the output, or _context_, of the previous function as a value to an argument in the next function. Here we get the formatted date string from the previous function and pass it as `content` for the markdown element.', + }, + }, + csv: { + syntax: `csv "fruit, stock + kiwi, 10 + Banana, 5"`, + usage: { + expression: `csv "fruit,stock + kiwi,10 + banana,5" +| pointseries color=fruit size=stock +| pie +| render`, + help: + 'This creates a `datatable` with `fruit` and `stock` columns with two rows. This is useful for quickly mocking data.', + }, + }, + date: { + syntax: `date +date value=1558735195 +date "2019-05-24T21:59:55+0000" +date "01/31/2019" format="MM/DD/YYYY"`, + usage: { + expression: `date +| formatdate "LLL" +| markdown {context} + font={font family="Arial, sans-serif" size=30 align="left" + color="#000000" + weight="normal" + underline=false + italic=false} +| render`, + help: 'Using `date` without passing any arguments will return the current date and time.', + }, + }, + demodata: { + syntax: `demodata +demodata "ci" +demodata type="shirts"`, + usage: { + expression: `filters +| demodata +| table +| render`, + help: '`demodata` is a mock data set that you can use to start playing around in Canvas.', + }, + }, + dropdownControl: { + syntax: `dropdownControl valueColumn=project filterColumn=project +dropdownControl valueColumn=agent filterColumn=agent.keyword filterGroup=group1`, + usage: { + expression: `demodata +| dropdownControl valueColumn=project filterColumn=project +| render`, + help: + 'This creates a dropdown filter element. It requires a data source and uses the unique values from the given `valueColumn` (i.e. `project`) and applies the filter to the `project` column. Note: `filterColumn` should point to a keyword type field for Elasticsearch data sources.', + }, + }, + eq: { + syntax: `eq true +eq null +eq 10 +eq "foo"`, + usage: { + expression: `filters +| demodata +| mapColumn project + fn={getCell project | + switch + {case if={eq kibana} then=kibana} + {case if={eq elasticsearch} then=elasticsearch} + default="other" + } +| pointseries size="size(cost)" color="project" +| pie +| render`, + help: + 'This changes all values in the project column that don’t equal `"kibana"` or `"elasticsearch"` to `"other"`.', + }, + }, + escount: { + syntax: `escount index="logstash-*" +escount "currency:\"EUR\"" index="kibana_sample_data_ecommerce" +escount query="response:404" index="kibana_sample_data_logs"`, + usage: { + expression: `filters +| escount "Cancelled:true" index="kibana_sample_data_flights" +| math "value" +| progress shape="semicircle" + label={formatnumber 0,0} + font={font size=24 family="'Open Sans', Helvetica, Arial, sans-serif" color="#000000" align=center} + max={filters | escount index="kibana_sample_data_flights"} +| render`, + help: + 'The first `escount` expression retrieves the number of flights that were cancelled. The second `escount` expression retrieves the total number of flights.', + }, + }, + esdocs: { + syntax: `esdocs index="logstash-*" +esdocs "currency:\"EUR\"" index="kibana_sample_data_ecommerce" +esdocs query="response:404" index="kibana_sample_data_logs" +esdocs index="kibana_sample_data_flights" count=100 +esdocs index="kibana_sample_data_flights" sort="AvgTicketPrice, asc"`, + usage: { + expression: `filters +| esdocs index="kibana_sample_data_ecommerce" + fields="customer_gender, taxful_total_price, order_date" + sort="order_date, asc" + count=10000 +| mapColumn "order_date" + fn={getCell "order_date" | date {context} | rounddate "YYYY-MM-DD"} +| alterColumn "order_date" type="date" +| pointseries x="order_date" y="sum(taxful_total_price)" color="customer_gender" +| plot defaultStyle={seriesStyle lines=3} + palette={palette "#7ECAE3" "#003A4D" gradient=true} +| render`, + help: + 'This retrieves the first 10000 documents data from the `kibana_sample_data_ecommerce` index sorted by `order_date` in ascending order, and only requests the `customer_gender`, `taxful_total_price`, and `order_date` fields.', + }, + }, + essql: { + syntax: `essql query="SELECT * FROM \"logstash*\"" +essql "SELECT * FROM \"apm*\"" count=10000`, + usage: { + expression: `filters +| essql query="SELECT Carrier, FlightDelayMin, AvgTicketPrice FROM \"kibana_sample_data_flights\"" +| table +| render`, + help: + 'This retrieves the `Carrier`, `FlightDelayMin`, and `AvgTicketPrice` fields from the "kibana_sample_data_flights" index.', + }, + }, + exactly: { + syntax: `exactly "state" value="running" +exactly "age" value=50 filterGroup="group2" +exactly column="project" value="beats"`, + usage: { + expression: `filters +| exactly column=project value=elasticsearch +| demodata +| pointseries x=project y="mean(age)" +| plot defaultStyle={seriesStyle bars=1} +| render`, + help: + 'The `exactly` filter here is added to existing filters retrieved by the `filters` function and further filters down the data to only have `"elasticsearch"` data. The `exactly` filter only applies to this one specific element and will not affect other elements in the workpad.', + }, + }, + filterrows: { + syntax: `filterrows {getCell "project" | eq "kibana"} +filterrows fn={getCell "age" | gt 50}`, + usage: { + expression: `filters +| demodata +| filterrows {getCell "country" | any {eq "IN"} {eq "US"} {eq "CN"}} +| mapColumn "@timestamp" + fn={getCell "@timestamp" | rounddate "YYYY-MM"} +| alterColumn "@timestamp" type="date" +| pointseries x="@timestamp" y="mean(cost)" color="country" +| plot defaultStyle={seriesStyle points="2" lines="1"} + palette={palette "#01A4A4" "#CC6666" "#D0D102" "#616161" "#00A1CB" "#32742C" "#F18D05" "#113F8C" "#61AE24" "#D70060" gradient=false} +| render`, + help: + 'This uses `filterrows` to only keep data from India (`IN`), the United States (`US`), and China (`CN`).', + }, + }, + filters: { + syntax: `filters +filters group="timefilter1" +filters group="timefilter2" group="dropdownfilter1" ungrouped=true`, + usage: { + expression: `filters group=group2 ungrouped=true +| demodata +| pointseries x="project" y="size(cost)" color="project" +| plot defaultStyle={seriesStyle bars=0.75} legend=false + font={ + font size=14 + family="'Open Sans', Helvetica, Arial, sans-serif" + align="left" + color="#FFFFFF" + weight="lighter" + underline=true + italic=true + } +| render`, + help: + '`filters` sets the existing filters as context and accepts a `group` parameter to opt into specific filter groups. Setting `ungrouped` to `true` opts out of using global filters.', + }, + }, + font: { + syntax: `font size=12 +font family=Arial +font align=middle +font color=pink +font weight=lighter +font underline=true +font italic=false +font lHeight=32`, + usage: { + expression: `filters +| demodata +| pointseries x="project" y="size(cost)" color="project" +| plot defaultStyle={seriesStyle bars=0.75} legend=false + font={ + font size=14 + family="'Open Sans', Helvetica, Arial, sans-serif" + align="left" + color="#FFFFFF" + weight="lighter" + underline=true + italic=true + } +| render`, + }, + }, + formatdate: { + syntax: `formatdate format="YYYY-MM-DD" +formatdate "MM/DD/YYYY"`, + usage: { + expression: `filters +| demodata +| mapColumn "time" fn={getCell time | formatdate "MMM 'YY"} +| pointseries x="time" y="sum(price)" color="state" +| plot defaultStyle={seriesStyle points=5} +| render`, + help: + 'This transforms the dates in the `time` field into strings that look like `"Jan ‘19"`, `"Feb ‘19"`, etc. using a MomentJS format.', + }, + }, + formatnumber: { + syntax: `formatnumber format="$0,0.00" +formatnumber "0.0a"`, + usage: { + expression: `filters +| demodata +| math "mean(percent_uptime)" +| progress shape="gauge" + label={formatnumber "0%"} + font={font size=24 family="'Open Sans', Helvetica, Arial, sans-serif" color="#000000" align="center"} +| render`, + help: + 'The `formatnumber` subexpression receives the same `context` as the `progress` function, which is the output of the `math` function. It formats the value into a percentage.', + }, + }, +}); diff --git a/x-pack/plugins/canvas/public/components/function_reference_generator/function_reference_generator.tsx b/x-pack/plugins/canvas/public/components/function_reference_generator/function_reference_generator.tsx new file mode 100644 index 000000000000..c527b322dba5 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_reference_generator/function_reference_generator.tsx @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { FC } from 'react'; +import { ExpressionFunction } from 'src/plugins/expressions'; +import { EuiButtonEmpty } from '@elastic/eui'; +import copy from 'copy-to-clipboard'; +import { notifyService } from '../../services'; +import { generateFunctionReference } from './generate_function_reference'; + +interface Props { + functionRegistry: Record; +} + +export const FunctionReferenceGenerator: FC = ({ functionRegistry }) => { + const functionDefinitions = Object.values(functionRegistry); + + const copyDocs = () => { + copy(generateFunctionReference(functionDefinitions)); + notifyService + .getService() + .success( + `Please paste updated docs into '/kibana/docs/canvas/canvas-function-reference.asciidoc' and commit your changes.`, + { title: 'Copied function docs to clipboard' } + ); + }; + + return ( + + Generate function reference + + ); +}; diff --git a/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts b/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts new file mode 100644 index 000000000000..bd77fbf62ec5 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_reference_generator/generate_function_reference.ts @@ -0,0 +1,259 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +// @ts-expect-error untyped lib +import pluralize from 'pluralize'; +import { ExpressionFunction, ExpressionFunctionParameter } from 'src/plugins/expressions'; +import { functions as browserFunctions } from '../../../canvas_plugin_src/functions/browser'; +import { functions as serverFunctions } from '../../../canvas_plugin_src/functions/server'; +import { isValidDataUrl, DATATABLE_COLUMN_TYPES } from '../../../common/lib'; +import { getFunctionExamples, FunctionExample } from './function_examples'; + +const ALPHABET = 'abcdefghijklmnopqrstuvwxyz'.split(''); +const REQUIRED_ARG_ANNOTATION = '***'; +const MULTI_ARG_ANNOTATION = '†'; +const UNNAMED_ARG = '_Unnamed_'; +const ANY_TYPE = '`any`'; + +const examplesDict = getFunctionExamples(); + +const fnList = [ + ...browserFunctions.map((fn) => fn().name), + ...serverFunctions.map((fn) => fn().name), + 'asset', + 'filters', + 'timelion', + 'to', + 'font', + 'var', + 'var_set', + // ignore unsupported embeddables functions for now +].filter((fn) => !['savedSearch'].includes(fn)); + +interface FunctionDictionary { + [key: string]: ExpressionFunction[]; +} + +const wrapInBackTicks = (str: string) => `\`${str}\``; +const wrapInDoubleQuotes = (str: string) => (str.includes('"') ? str : `"${str}"`); +const stringSorter = (a: string, b: string) => { + if (a < b) { + return -1; + } + if (a > b) { + return 1; + } + return 0; +}; + +// Converts reference to another function in a function's help text into an Asciidoc link +const addFunctionLinks = (help: string, options?: { ignoreList?: string[] }) => { + const { ignoreList = [] } = options || {}; + fnList.forEach((name: string) => { + const nameWithBackTicks = wrapInBackTicks(name); + + // ignore functions with the same name as data types, i.e. string, date + if ( + !ignoreList.includes(name) && + !DATATABLE_COLUMN_TYPES.includes(name) && + help.includes(nameWithBackTicks) + ) { + help = help.replace(nameWithBackTicks, `<<${name}_fn>>`); + } + }); + + return help; +}; + +export const generateFunctionReference = (functionDefinitions: ExpressionFunction[]) => { + const functionDefs = functionDefinitions.filter((fn: ExpressionFunction) => + fnList.includes(fn.name) + ); + const functionDictionary: FunctionDictionary = {}; + functionDefs.forEach((fn: ExpressionFunction) => { + const firstLetter = fn.name[0]; + + if (!functionDictionary[firstLetter]) { + functionDictionary[firstLetter] = []; + } + + functionDictionary[firstLetter].push(fn); + }); + return `[role="xpack"] +[[canvas-function-reference]] +== Canvas function reference + +Behind the scenes, Canvas is driven by a powerful expression language, +with dozens of functions and other capabilities, including table transforms, +type casting, and sub-expressions. + +The Canvas expression language also supports <>, which +perform complex math calculations. + +A ${REQUIRED_ARG_ANNOTATION} denotes a required argument. + +A ${MULTI_ARG_ANNOTATION} denotes an argument can be passed multiple times. + +${createAlphabetLinks(functionDictionary)} + +${createFunctionDocs(functionDictionary)}`; +}; + +const createAlphabetLinks = (functionDictionary: FunctionDictionary) => { + return ALPHABET.map((letter: string) => + functionDictionary[letter] ? `<<${letter}_fns>>` : letter.toUpperCase() + ).join(' | '); +}; + +const createFunctionDocs = (functionDictionary: FunctionDictionary) => { + return Object.keys(functionDictionary) + .sort() + .map( + (letter: string) => `[float] +[[${letter}_fns]] +== ${letter.toUpperCase()} + +${functionDictionary[letter] + .sort((a, b) => stringSorter(a.name, b.name)) + .map(getDocBlock) + .join('\n')}` + ) + .join(''); +}; + +const getDocBlock = (fn: ExpressionFunction) => { + const header = `[float] +[[${fn.name}_fn]] +=== \`${fn.name}\``; + + const input = fn.inputTypes; + const output = fn.type; + const args = fn.args; + const examples = examplesDict[fn.name]; + const help = addFunctionLinks(fn.help); + + const argBlock = + !args || Object.keys(args).length === 0 + ? '' + : `\n[cols="3*^<"] +|=== +|Argument |Type |Description + +${getArgsTable(args)} +|===\n`; + + const examplesBlock = !examples ? `` : `${getExamplesBlock(examples)}`; + + return `${header}\n +${help} +${examplesBlock} +*Accepts:* ${input ? input.map(wrapInBackTicks).join(', ') : ANY_TYPE}\n${argBlock} +*Returns:* ${output ? wrapInBackTicks(output) : 'Depends on your input and arguments'}\n\n`; +}; + +const getArgsTable = (args: { [key: string]: ExpressionFunctionParameter }) => { + if (!args || Object.keys(args).length === 0) { + return 'None'; + } + + const argNames = Object.keys(args); + + return argNames + .sort((a: string, b: string) => { + const argA = args[a]; + const argB = args[b]; + + // sorts unnamed arg to the front + if (a === '_' || (argA.aliases && argA.aliases.includes('_'))) { + return -1; + } + if (b === '_' || (argB.aliases && argB.aliases.includes('_'))) { + return 1; + } + return stringSorter(a, b); + }) + .map((argName: string) => { + const arg = args[argName]; + const types = arg.types; + const aliases = arg.aliases ? [...arg.aliases] : []; + let defaultValue = arg.default; + const requiredAnnotation = arg.required === true ? ` ${REQUIRED_ARG_ANNOTATION}` : ''; + const multiAnnotation = arg.multi === true ? ` ${MULTI_ARG_ANNOTATION}` : ''; + + if (typeof defaultValue === 'string') { + defaultValue = defaultValue.replace('{', '${').replace(/[\r\n/]+/g, ''); + if (types && types.includes('string')) { + defaultValue = wrapInDoubleQuotes(defaultValue); + } + } + + let displayName = ''; + + if (argName === '_') { + displayName = UNNAMED_ARG; + } else if (aliases && aliases.includes('_')) { + displayName = UNNAMED_ARG; + aliases[aliases.indexOf('_')] = argName; + } else { + displayName = wrapInBackTicks(argName); + } + + const aliasList = + aliases && aliases.length + ? `\n\n${pluralize('Alias', aliases.length)}: ${aliases + .sort() + .map(wrapInBackTicks) + .join(', ')}` + : ''; + + let defaultBlock = ''; + + if (isValidDataUrl(arg.default)) { + defaultBlock = getDataUrlExampleBlock(displayName, arg.default); + } else { + defaultBlock = + typeof defaultValue !== 'undefined' ? `\n\nDefault: \`${defaultValue}\`` : ''; + } + + return `|${displayName}${requiredAnnotation}${multiAnnotation}${aliasList} +|${types && types.length ? types.map(wrapInBackTicks).join(', ') : ANY_TYPE} +|${arg.help ? addFunctionLinks(arg.help, { ignoreList: argNames }) : ''}${defaultBlock}`; + }) + .join('\n\n'); +}; + +const getDataUrlExampleBlock = ( + argName: string, + value: string +) => `\n\nExample value for the ${argName} argument, formatted as a \`base64\` data URL: +[source, url] +------------ +${value} +------------`; + +const getExamplesBlock = (examples: FunctionExample) => { + const { syntax, usage } = examples; + const { expression, help } = usage || {}; + const syntaxBlock = syntax + ? `\n*Expression syntax* +[source,js] +---- +${syntax} +----\n` + : ''; + + const codeBlock = expression + ? `\n*Code example* +[source,text] +---- +${expression} +----\n` + : ''; + + const codeHelp = help ? `${help}\n` : ''; + + return `${syntaxBlock}${codeBlock}${codeHelp}`; +}; diff --git a/x-pack/plugins/canvas/public/components/function_reference_generator/index.ts b/x-pack/plugins/canvas/public/components/function_reference_generator/index.ts new file mode 100644 index 000000000000..337809238bb5 --- /dev/null +++ b/x-pack/plugins/canvas/public/components/function_reference_generator/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { FunctionReferenceGenerator } from './function_reference_generator'; diff --git a/x-pack/plugins/canvas/public/components/help_menu/help_menu.js b/x-pack/plugins/canvas/public/components/help_menu/help_menu.js deleted file mode 100644 index 4512ce2b4992..000000000000 --- a/x-pack/plugins/canvas/public/components/help_menu/help_menu.js +++ /dev/null @@ -1,45 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import React, { Fragment, PureComponent } from 'react'; -import { EuiButtonEmpty, EuiPortal } from '@elastic/eui'; -import { KeyboardShortcutsDoc } from '../keyboard_shortcuts_doc'; -import { ComponentStrings } from '../../../i18n'; - -const { HelpMenu: strings } = ComponentStrings; - -export class HelpMenu extends PureComponent { - state = { isFlyoutVisible: false }; - - showFlyout = () => { - this.setState({ isFlyoutVisible: true }); - }; - - hideFlyout = () => { - this.setState({ isFlyoutVisible: false }); - }; - - render() { - return ( - - - {strings.getKeyboardShortcutsLinkLabel()} - - - {this.state.isFlyoutVisible && ( - - - - )} - - ); - } -} diff --git a/x-pack/plugins/canvas/public/components/help_menu/help_menu.tsx b/x-pack/plugins/canvas/public/components/help_menu/help_menu.tsx new file mode 100644 index 000000000000..7122ec88f68a --- /dev/null +++ b/x-pack/plugins/canvas/public/components/help_menu/help_menu.tsx @@ -0,0 +1,59 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { FC, useState, lazy, Suspense } from 'react'; +import { EuiButtonEmpty, EuiPortal, EuiSpacer } from '@elastic/eui'; +import { ExpressionFunction } from 'src/plugins/expressions'; +import { ComponentStrings } from '../../../i18n'; +import { KeyboardShortcutsDoc } from '../keyboard_shortcuts_doc'; + +let FunctionReferenceGenerator: null | React.LazyExoticComponent = null; +if (process.env.NODE_ENV === 'development') { + FunctionReferenceGenerator = lazy(() => + import('../function_reference_generator').then((module) => ({ + default: module.FunctionReferenceGenerator, + })) + ); +} + +const { HelpMenu: strings } = ComponentStrings; + +interface Props { + functionRegistry: Record; +} + +export const HelpMenu: FC = ({ functionRegistry }) => { + const [isFlyoutVisible, setFlyoutVisible] = useState(false); + + const showFlyout = () => { + setFlyoutVisible(true); + }; + + const hideFlyout = () => { + setFlyoutVisible(false); + }; + + return ( + <> + + {strings.getKeyboardShortcutsLinkLabel()} + + + {FunctionReferenceGenerator ? ( + + + + + ) : null} + + {isFlyoutVisible && ( + + + + )} + + ); +}; diff --git a/x-pack/plugins/canvas/public/components/help_menu/index.js b/x-pack/plugins/canvas/public/components/help_menu/index.ts similarity index 100% rename from x-pack/plugins/canvas/public/components/help_menu/index.js rename to x-pack/plugins/canvas/public/components/help_menu/index.ts diff --git a/x-pack/plugins/dashboard_enhanced/README.asciidoc b/x-pack/plugins/dashboard_enhanced/README.asciidoc new file mode 100644 index 000000000000..2abeeb6a74e0 --- /dev/null +++ b/x-pack/plugins/dashboard_enhanced/README.asciidoc @@ -0,0 +1,5 @@ + +[[dashboard-enhanced-plugin]] +== Dashboard app enhancements plugin + +Adds drilldown capabilities to dashboard. Owned by the Kibana App team. diff --git a/x-pack/plugins/dashboard_enhanced/README.md b/x-pack/plugins/dashboard_enhanced/README.md deleted file mode 100644 index 0aeb156a99f1..000000000000 --- a/x-pack/plugins/dashboard_enhanced/README.md +++ /dev/null @@ -1 +0,0 @@ -Contains the enhancements to the OSS dashboard app. \ No newline at end of file diff --git a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx index a17d95c37c5c..056feeb2b216 100644 --- a/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx +++ b/x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx @@ -25,6 +25,7 @@ import { import { StartServicesGetter } from '../../../../../../../src/plugins/kibana_utils/public'; import { StartDependencies } from '../../../plugin'; import { Config, FactoryContext } from './types'; +import { SearchInput } from '../../../../../../../src/plugins/discover/public'; export interface Params { start: StartServicesGetter>; @@ -89,7 +90,7 @@ export class DashboardToDashboardDrilldown }; if (context.embeddable) { - const input = context.embeddable.getInput(); + const input = context.embeddable.getInput() as Readonly; if (isQuery(input.query) && config.useCurrentFilters) state.query = input.query; // if useCurrentDashboardDataRange is enabled, then preserve current time range diff --git a/x-pack/plugins/data_enhanced/common/index.ts b/x-pack/plugins/data_enhanced/common/index.ts index 1f1cd938c97d..d6a3c73aaf36 100644 --- a/x-pack/plugins/data_enhanced/common/index.ts +++ b/x-pack/plugins/data_enhanced/common/index.ts @@ -4,4 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './search'; +export { + EnhancedSearchParams, + IEnhancedEsSearchRequest, + IAsyncSearchRequest, + ENHANCED_ES_SEARCH_STRATEGY, +} from './search'; diff --git a/x-pack/plugins/data_enhanced/common/search/index.ts b/x-pack/plugins/data_enhanced/common/search/index.ts index 129e412a47cc..2ae422bd6b7d 100644 --- a/x-pack/plugins/data_enhanced/common/search/index.ts +++ b/x-pack/plugins/data_enhanced/common/search/index.ts @@ -4,4 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -export { EnhancedSearchParams, IEnhancedEsSearchRequest, IAsyncSearchRequest } from './types'; +export { + EnhancedSearchParams, + IEnhancedEsSearchRequest, + IAsyncSearchRequest, + ENHANCED_ES_SEARCH_STRATEGY, +} from './types'; diff --git a/x-pack/plugins/data_enhanced/common/search/types.ts b/x-pack/plugins/data_enhanced/common/search/types.ts index a5d7d326cecd..0d3d3a69e1e5 100644 --- a/x-pack/plugins/data_enhanced/common/search/types.ts +++ b/x-pack/plugins/data_enhanced/common/search/types.ts @@ -6,6 +6,8 @@ import { IEsSearchRequest, ISearchRequestParams } from '../../../../../src/plugins/data/common'; +export const ENHANCED_ES_SEARCH_STRATEGY = 'ese'; + export interface EnhancedSearchParams extends ISearchRequestParams { ignoreThrottled: boolean; } diff --git a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts index 47099e32fcc7..6f7899d1188b 100644 --- a/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts +++ b/x-pack/plugins/data_enhanced/public/search/search_interceptor.ts @@ -14,7 +14,7 @@ import { } from '../../../../../src/plugins/data/public'; import { AbortError, toPromise } from '../../../../../src/plugins/data/common'; import { IAsyncSearchOptions } from '.'; -import { IAsyncSearchRequest } from '../../common'; +import { IAsyncSearchRequest, ENHANCED_ES_SEARCH_STRATEGY } from '../../common'; export class EnhancedSearchInterceptor extends SearchInterceptor { /** @@ -76,10 +76,11 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { const { combinedSignal, cleanup } = this.setupTimers(options); const aborted$ = from(toPromise(combinedSignal)); + const strategy = options?.strategy || ENHANCED_ES_SEARCH_STRATEGY; this.pendingCount$.next(this.pendingCount$.getValue() + 1); - return this.runSearch(request, combinedSignal, options?.strategy).pipe( + return this.runSearch(request, combinedSignal, strategy).pipe( expand((response) => { // If the response indicates of an error, stop polling and complete the observable if (!response || (!response.isRunning && response.isPartial)) { @@ -96,7 +97,7 @@ export class EnhancedSearchInterceptor extends SearchInterceptor { return timer(pollInterval).pipe( // Send future requests using just the ID from the response mergeMap(() => { - return this.runSearch({ ...request, id }, combinedSignal, options?.strategy); + return this.runSearch({ ...request, id }, combinedSignal, strategy); }) ); }), diff --git a/x-pack/plugins/data_enhanced/server/plugin.ts b/x-pack/plugins/data_enhanced/server/plugin.ts index 0e9731a41411..f9b6fd4e9ad6 100644 --- a/x-pack/plugins/data_enhanced/server/plugin.ts +++ b/x-pack/plugins/data_enhanced/server/plugin.ts @@ -11,7 +11,6 @@ import { Plugin, Logger, } from '../../../../src/core/server'; -import { ES_SEARCH_STRATEGY } from '../../../../src/plugins/data/common'; import { PluginSetup as DataPluginSetup, PluginStart as DataPluginStart, @@ -19,6 +18,7 @@ import { } from '../../../../src/plugins/data/server'; import { enhancedEsSearchStrategyProvider } from './search'; import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server'; +import { ENHANCED_ES_SEARCH_STRATEGY } from '../common'; interface SetupDependencies { data: DataPluginSetup; @@ -36,13 +36,19 @@ export class EnhancedDataServerPlugin implements Plugin; if (input.timeRange && !state.timeRange) state.timeRange = input.timeRange; if (input.query) state.query = input.query; diff --git a/x-pack/plugins/discover_enhanced/public/plugin.ts b/x-pack/plugins/discover_enhanced/public/plugin.ts index 9e66925132a7..f1273ab00bdd 100644 --- a/x-pack/plugins/discover_enhanced/public/plugin.ts +++ b/x-pack/plugins/discover_enhanced/public/plugin.ts @@ -28,6 +28,7 @@ import { ACTION_EXPLORE_DATA_CHART, ExploreDataChartActionContext, } from './actions'; +import { Config } from '../common'; declare module '../../../../src/plugins/ui_actions/public' { export interface ActionContextMapping { @@ -55,10 +56,10 @@ export interface DiscoverEnhancedStartDependencies { export class DiscoverEnhancedPlugin implements Plugin { - public readonly config: { actions: { exploreDataInChart: { enabled: boolean } } }; + public readonly config: Config; constructor(protected readonly context: PluginInitializerContext) { - this.config = context.config.get(); + this.config = context.config.get(); } setup( diff --git a/x-pack/plugins/discover_enhanced/server/index.ts b/x-pack/plugins/discover_enhanced/server/index.ts index e361b9fb075e..461a2616efdb 100644 --- a/x-pack/plugins/discover_enhanced/server/index.ts +++ b/x-pack/plugins/discover_enhanced/server/index.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { PluginInitializerContext } from '../../../../src/core/server'; +import { DiscoverEnhancedPlugin } from './plugin'; + export { config } from './config'; -export const plugin = () => ({ - setup() {}, - start() {}, -}); +export const plugin = (context: PluginInitializerContext) => new DiscoverEnhancedPlugin(context); diff --git a/x-pack/plugins/discover_enhanced/server/plugin.ts b/x-pack/plugins/discover_enhanced/server/plugin.ts new file mode 100644 index 000000000000..9d80a6dc7dcd --- /dev/null +++ b/x-pack/plugins/discover_enhanced/server/plugin.ts @@ -0,0 +1,58 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { Observable } from 'rxjs'; +import { take } from 'rxjs/operators'; +import { + CoreSetup, + CoreStart, + Plugin, + PluginInitializerContext, +} from '../../../../src/core/server'; +import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server'; +import { Config } from '../common'; + +interface SetupDependencies { + usageCollection?: UsageCollectionSetup; +} + +interface StartDependencies { + usageCollection?: unknown; +} + +export class DiscoverEnhancedPlugin + implements Plugin { + private config$: Observable; + + constructor(protected readonly context: PluginInitializerContext) { + this.config$ = context.config.create(); + } + + public setup(core: CoreSetup, { usageCollection }: SetupDependencies) { + if (!!usageCollection) { + const collector = usageCollection.makeUsageCollector<{ + exploreDataInChartActionEnabled: boolean; + }>({ + type: 'discoverEnhanced', + schema: { + exploreDataInChartActionEnabled: { + type: 'boolean', + }, + }, + isReady: () => true, + fetch: async () => { + const config = await this.config$.pipe(take(1)).toPromise(); + return { + exploreDataInChartActionEnabled: config.actions.exploreDataInChart.enabled, + }; + }, + }); + usageCollection.registerCollector(collector); + } + } + + public start(core: CoreStart) {} +} diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.scss b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.scss similarity index 100% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.scss rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.scss diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.test.tsx similarity index 55% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.test.tsx index 25a9fa7430c4..7e6876bc9b3a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.test.tsx @@ -4,28 +4,19 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../__mocks__/shallow_usecontext.mock'; +import '../../../../__mocks__/shallow_usecontext.mock'; import React from 'react'; import { shallow } from 'enzyme'; -import { EuiEmptyPrompt, EuiButton, EuiLoadingContent } from '@elastic/eui'; -import { ErrorStatePrompt } from '../../../shared/error_state'; +import { EuiEmptyPrompt, EuiButton } from '@elastic/eui'; -jest.mock('../../../shared/telemetry', () => ({ +jest.mock('../../../../shared/telemetry', () => ({ sendTelemetry: jest.fn(), SendAppSearchTelemetry: jest.fn(), })); -import { sendTelemetry } from '../../../shared/telemetry'; +import { sendTelemetry } from '../../../../shared/telemetry'; -import { ErrorState, EmptyState, LoadingState } from './'; - -describe('ErrorState', () => { - it('renders', () => { - const wrapper = shallow(); - - expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1); - }); -}); +import { EmptyState } from './'; describe('EmptyState', () => { it('renders', () => { @@ -44,11 +35,3 @@ describe('EmptyState', () => { (sendTelemetry as jest.Mock).mockClear(); }); }); - -describe('LoadingState', () => { - it('renders', () => { - const wrapper = shallow(); - - expect(wrapper.find(EuiLoadingContent)).toHaveLength(2); - }); -}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx similarity index 84% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx index 9b0edb423bc5..58691cf09b4a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/empty_state.tsx @@ -8,14 +8,14 @@ import React, { useContext } from 'react'; import { EuiPageContent, EuiEmptyPrompt, EuiButton } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { sendTelemetry } from '../../../shared/telemetry'; -import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; -import { KibanaContext, IKibanaContext } from '../../../index'; -import { CREATE_ENGINES_PATH } from '../../routes'; +import { sendTelemetry } from '../../../../shared/telemetry'; +import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome'; +import { KibanaContext, IKibanaContext } from '../../../../index'; +import { CREATE_ENGINES_PATH } from '../../../routes'; -import { EngineOverviewHeader } from '../engine_overview_header'; +import { EngineOverviewHeader } from './header'; -import './empty_states.scss'; +import './empty_state.scss'; export const EmptyState: React.FC = () => { const { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.test.tsx similarity index 77% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.test.tsx index 7d2106f2a56f..7f22ce132d40 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.test.tsx @@ -4,15 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import '../../../__mocks__/shallow_usecontext.mock'; +import '../../../../__mocks__/shallow_usecontext.mock'; import React from 'react'; import { shallow } from 'enzyme'; -jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() })); -import { sendTelemetry } from '../../../shared/telemetry'; +jest.mock('../../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() })); +import { sendTelemetry } from '../../../../shared/telemetry'; -import { EngineOverviewHeader } from '../engine_overview_header'; +import { EngineOverviewHeader } from './'; describe('EngineOverviewHeader', () => { it('renders', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx similarity index 92% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx index 7f67d00f5df9..1a1ae295d482 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/header.tsx @@ -15,8 +15,8 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; -import { sendTelemetry } from '../../../shared/telemetry'; -import { KibanaContext, IKibanaContext } from '../../../index'; +import { sendTelemetry } from '../../../../shared/telemetry'; +import { KibanaContext, IKibanaContext } from '../../../../index'; export const EngineOverviewHeader: React.FC = () => { const { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts similarity index 87% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/index.ts rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts index e92bf214c4cc..794053f184f8 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts @@ -4,6 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ +export { EngineOverviewHeader } from './header'; export { LoadingState } from './loading_state'; export { EmptyState } from './empty_state'; -export { ErrorState } from './error_state'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.test.tsx new file mode 100644 index 000000000000..c894500550a0 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.test.tsx @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; +import { EuiLoadingContent } from '@elastic/eui'; + +import { LoadingState } from './'; + +describe('LoadingState', () => { + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiLoadingContent)).toHaveLength(2); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx similarity index 73% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx index 221091b79dc5..07643560df3c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/loading_state.tsx @@ -7,17 +7,15 @@ import React from 'react'; import { EuiPageContent, EuiSpacer, EuiLoadingContent } from '@elastic/eui'; -import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; -import { EngineOverviewHeader } from '../engine_overview_header'; - -import './empty_states.scss'; +import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome'; +import { EngineOverviewHeader } from './header'; export const LoadingState: React.FC = () => { return ( <> - + diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx index 45ab5dc5b9ab..c2379fb33bd7 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx @@ -12,7 +12,7 @@ import { shallow, ReactWrapper } from 'enzyme'; import { mountWithAsyncContext, mockKibanaContext } from '../../../__mocks__'; -import { LoadingState, EmptyState, ErrorState } from '../empty_states'; +import { LoadingState, EmptyState } from './components'; import { EngineTable } from './engine_table'; import { EngineOverview } from './'; @@ -40,16 +40,6 @@ describe('EngineOverview', () => { expect(wrapper.find(EmptyState)).toHaveLength(1); }); - - it('hasErrorConnecting', async () => { - const wrapper = await mountWithAsyncContext(, { - http: { - ...mockHttp, - get: () => ({ invalidPayload: true }), - }, - }); - expect(wrapper.find(ErrorState)).toHaveLength(1); - }); }); describe('happy-path states', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx index acac5d17665b..74bcd9aeafb2 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx @@ -22,8 +22,7 @@ import { KibanaContext, IKibanaContext } from '../../../index'; import EnginesIcon from '../../assets/engine.svg'; import MetaEnginesIcon from '../../assets/meta_engine.svg'; -import { LoadingState, EmptyState, ErrorState } from '../empty_states'; -import { EngineOverviewHeader } from '../engine_overview_header'; +import { EngineOverviewHeader, LoadingState, EmptyState } from './components'; import { EngineTable } from './engine_table'; import './engine_overview.scss'; @@ -42,8 +41,6 @@ export const EngineOverview: React.FC = () => { const { license } = useContext(LicenseContext) as ILicenseContext; const [isLoading, setIsLoading] = useState(true); - const [hasErrorConnecting, setHasErrorConnecting] = useState(false); - const [engines, setEngines] = useState([]); const [enginesPage, setEnginesPage] = useState(1); const [enginesTotal, setEnginesTotal] = useState(0); @@ -57,16 +54,12 @@ export const EngineOverview: React.FC = () => { }); }; const setEnginesData = async (params: IGetEnginesParams, callbacks: ISetEnginesCallbacks) => { - try { - const response = await getEnginesData(params); + const response = await getEnginesData(params); - callbacks.setResults(response.results); - callbacks.setResultsTotal(response.meta.page.total_results); + callbacks.setResults(response.results); + callbacks.setResultsTotal(response.meta.page.total_results); - setIsLoading(false); - } catch (error) { - setHasErrorConnecting(true); - } + setIsLoading(false); }; useEffect(() => { @@ -85,7 +78,6 @@ export const EngineOverview: React.FC = () => { } }, [license, metaEnginesPage]); - if (hasErrorConnecting) return ; if (isLoading) return ; if (!engines.length) return ; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.test.tsx new file mode 100644 index 000000000000..8d48875a8e1f --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.test.tsx @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { ErrorStatePrompt } from '../../../shared/error_state'; +import { ErrorConnecting } from './'; + +describe('ErrorConnecting', () => { + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.tsx similarity index 81% rename from x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx rename to x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.tsx index c5a5f1fbb921..34eb76d11a66 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/error_connecting.tsx @@ -10,17 +10,13 @@ import { EuiPageContent } from '@elastic/eui'; import { ErrorStatePrompt } from '../../../shared/error_state'; import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { SendAppSearchTelemetry as SendTelemetry } from '../../../shared/telemetry'; -import { EngineOverviewHeader } from '../engine_overview_header'; -import './empty_states.scss'; - -export const ErrorState: React.FC = () => { +export const ErrorConnecting: React.FC = () => { return ( <> - diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/index.ts new file mode 100644 index 000000000000..c8b71e1a6e79 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/error_connecting/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { ErrorConnecting } from './error_connecting'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx index 0f4072c591bc..94e9127bbed7 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx @@ -12,8 +12,10 @@ import { Redirect } from 'react-router-dom'; import { shallow } from 'enzyme'; import { useValues, useActions } from 'kea'; -import { SetupGuide } from './components/setup_guide'; import { Layout, SideNav, SideNavLink } from '../shared/layout'; +import { SetupGuide } from './components/setup_guide'; +import { ErrorConnecting } from './components/error_connecting'; +import { EngineOverview } from './components/engine_overview'; import { AppSearch, AppSearchUnconfigured, AppSearchConfigured, AppSearchNav } from './'; describe('AppSearch', () => { @@ -42,12 +44,17 @@ describe('AppSearchUnconfigured', () => { }); describe('AppSearchConfigured', () => { - it('renders with layout', () => { + beforeEach(() => { + // Mock resets + (useValues as jest.Mock).mockImplementation(() => ({})); (useActions as jest.Mock).mockImplementation(() => ({ initializeAppData: () => {} })); + }); + it('renders with layout', () => { const wrapper = shallow(); expect(wrapper.find(Layout)).toHaveLength(1); + expect(wrapper.find(EngineOverview)).toHaveLength(1); }); it('initializes app data with passed props', () => { @@ -62,12 +69,20 @@ describe('AppSearchConfigured', () => { it('does not re-initialize app data', () => { const initializeAppData = jest.fn(); (useActions as jest.Mock).mockImplementation(() => ({ initializeAppData })); - (useValues as jest.Mock).mockImplementationOnce(() => ({ hasInitialized: true })); + (useValues as jest.Mock).mockImplementation(() => ({ hasInitialized: true })); shallow(); expect(initializeAppData).not.toHaveBeenCalled(); }); + + it('renders ErrorConnecting', () => { + (useValues as jest.Mock).mockImplementation(() => ({ errorConnecting: true })); + + const wrapper = shallow(); + + expect(wrapper.find(ErrorConnecting)).toHaveLength(1); + }); }); describe('AppSearchNav', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx index 5f4734630624..234201a157ec 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx @@ -11,6 +11,7 @@ import { useActions, useValues } from 'kea'; import { i18n } from '@kbn/i18n'; import { KibanaContext, IKibanaContext } from '../index'; +import { HttpLogic, IHttpLogicValues } from '../shared/http'; import { AppLogic, IAppLogicActions, IAppLogicValues } from './app_logic'; import { IInitialAppData } from '../../../common/types'; @@ -27,6 +28,7 @@ import { } from './routes'; import { SetupGuide } from './components/setup_guide'; +import { ErrorConnecting } from './components/error_connecting'; import { EngineOverview } from './components/engine_overview'; export const AppSearch: React.FC = (props) => { @@ -48,6 +50,7 @@ export const AppSearchUnconfigured: React.FC = () => ( export const AppSearchConfigured: React.FC = (props) => { const { hasInitialized } = useValues(AppLogic) as IAppLogicValues; const { initializeAppData } = useActions(AppLogic) as IAppLogicActions; + const { errorConnecting } = useValues(HttpLogic) as IHttpLogicValues; useEffect(() => { if (!hasInitialized) initializeAppData(props); @@ -60,14 +63,18 @@ export const AppSearchConfigured: React.FC = (props) => { }> - - - - - - - - + {errorConnecting ? ( + + ) : ( + + + + + + + + + )} diff --git a/x-pack/plugins/enterprise_search/public/applications/index.tsx b/x-pack/plugins/enterprise_search/public/applications/index.tsx index d6cc6e81509b..60e4cedf413f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.tsx @@ -22,6 +22,7 @@ import { } from 'src/core/public'; import { ClientConfigType, ClientData, PluginsSetup } from '../plugin'; import { LicenseProvider } from './shared/licensing'; +import { HttpProvider } from './shared/http'; import { IExternalUrl } from './shared/enterprise_search_url'; import { IInitialAppData } from '../../common/types'; @@ -48,7 +49,7 @@ export const renderApp = ( core: CoreStart, plugins: PluginsSetup, config: ClientConfigType, - { externalUrl, ...initialData }: ClientData + { externalUrl, errorConnecting, ...initialData }: ClientData ) => { resetContext({ createStore: true }); const store = getContext().store as Store; @@ -67,6 +68,7 @@ export const renderApp = ( > + @@ -77,7 +79,6 @@ export const renderApp = ( params.element ); return () => { - resetContext({}); ReactDOM.unmountComponentAtNode(params.element); }; }; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.test.ts new file mode 100644 index 000000000000..a6957340d33d --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.test.ts @@ -0,0 +1,110 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { resetContext } from 'kea'; + +import { httpServiceMock } from 'src/core/public/mocks'; + +import { HttpLogic } from './http_logic'; + +describe('HttpLogic', () => { + const mockHttp = httpServiceMock.createSetupContract(); + const DEFAULT_VALUES = { + http: null, + httpInterceptors: [], + errorConnecting: false, + }; + + beforeEach(() => { + jest.clearAllMocks(); + resetContext({}); + }); + + it('has expected default values', () => { + HttpLogic.mount(); + expect(HttpLogic.values).toEqual(DEFAULT_VALUES); + }); + + describe('initializeHttp()', () => { + it('sets values based on passed props', () => { + HttpLogic.mount(); + HttpLogic.actions.initializeHttp({ http: mockHttp, errorConnecting: true }); + + expect(HttpLogic.values).toEqual({ + http: mockHttp, + httpInterceptors: [], + errorConnecting: true, + }); + }); + }); + + describe('setErrorConnecting()', () => { + it('sets errorConnecting value', () => { + HttpLogic.mount(); + HttpLogic.actions.setErrorConnecting(true); + expect(HttpLogic.values.errorConnecting).toEqual(true); + + HttpLogic.actions.setErrorConnecting(false); + expect(HttpLogic.values.errorConnecting).toEqual(false); + }); + }); + + describe('http interceptors', () => { + describe('initializeHttpInterceptors()', () => { + beforeEach(() => { + HttpLogic.mount(); + jest.spyOn(HttpLogic.actions, 'setHttpInterceptors'); + jest.spyOn(HttpLogic.actions, 'setErrorConnecting'); + HttpLogic.actions.initializeHttp({ http: mockHttp }); + + HttpLogic.actions.initializeHttpInterceptors(); + }); + + it('calls http.intercept and sets an array of interceptors', () => { + mockHttp.intercept.mockImplementationOnce(() => 'removeInterceptorFn' as any); + HttpLogic.actions.initializeHttpInterceptors(); + + expect(mockHttp.intercept).toHaveBeenCalled(); + expect(HttpLogic.actions.setHttpInterceptors).toHaveBeenCalledWith(['removeInterceptorFn']); + }); + + describe('errorConnectingInterceptor', () => { + it('handles errors connecting to Enterprise Search', async () => { + const { responseError } = mockHttp.intercept.mock.calls[0][0] as any; + await responseError({ response: { url: '/api/app_search/engines', status: 502 } }); + + expect(HttpLogic.actions.setErrorConnecting).toHaveBeenCalled(); + }); + + it('does not handle non-502 Enterprise Search errors', async () => { + const { responseError } = mockHttp.intercept.mock.calls[0][0] as any; + await responseError({ response: { url: '/api/workplace_search/overview', status: 404 } }); + + expect(HttpLogic.actions.setErrorConnecting).not.toHaveBeenCalled(); + }); + + it('does not handle errors for unrelated calls', async () => { + const { responseError } = mockHttp.intercept.mock.calls[0][0] as any; + await responseError({ response: { url: '/api/some_other_plugin/', status: 502 } }); + + expect(HttpLogic.actions.setErrorConnecting).not.toHaveBeenCalled(); + }); + }); + }); + + it('sets httpInterceptors and calls all valid remove functions on unmount', () => { + const unmount = HttpLogic.mount(); + const httpInterceptors = [jest.fn(), undefined, jest.fn()] as any; + + HttpLogic.actions.setHttpInterceptors(httpInterceptors); + expect(HttpLogic.values.httpInterceptors).toEqual(httpInterceptors); + + unmount(); + expect(httpInterceptors[0]).toHaveBeenCalledTimes(1); + expect(httpInterceptors[2]).toHaveBeenCalledTimes(1); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts new file mode 100644 index 000000000000..7bf7a19ed451 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_logic.ts @@ -0,0 +1,86 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { kea } from 'kea'; + +import { HttpSetup } from 'src/core/public'; + +import { IKeaLogic, IKeaParams, TKeaReducers } from '../../shared/types'; + +export interface IHttpLogicValues { + http: HttpSetup; + httpInterceptors: Function[]; + errorConnecting: boolean; +} +export interface IHttpLogicActions { + initializeHttp({ http, errorConnecting }: { http: HttpSetup; errorConnecting?: boolean }): void; + initializeHttpInterceptors(): void; + setHttpInterceptors(httpInterceptors: Function[]): void; + setErrorConnecting(errorConnecting: boolean): void; +} + +export const HttpLogic = kea({ + actions: (): IHttpLogicActions => ({ + initializeHttp: ({ http, errorConnecting }) => ({ http, errorConnecting }), + initializeHttpInterceptors: () => null, + setHttpInterceptors: (httpInterceptors) => ({ httpInterceptors }), + setErrorConnecting: (errorConnecting) => ({ errorConnecting }), + }), + reducers: (): TKeaReducers => ({ + http: [ + (null as unknown) as HttpSetup, + { + initializeHttp: (_, { http }) => http, + }, + ], + httpInterceptors: [ + [], + { + setHttpInterceptors: (_, { httpInterceptors }) => httpInterceptors, + }, + ], + errorConnecting: [ + false, + { + initializeHttp: (_, { errorConnecting }) => !!errorConnecting, + setErrorConnecting: (_, { errorConnecting }) => errorConnecting, + }, + ], + }), + listeners: ({ values, actions }) => ({ + initializeHttpInterceptors: () => { + const httpInterceptors = []; + + const errorConnectingInterceptor = values.http.intercept({ + responseError: async (httpResponse) => { + const { url, status } = httpResponse.response!; + const hasErrorConnecting = status === 502; + const isApiResponse = + url.includes('/api/app_search/') || url.includes('/api/workplace_search/'); + + if (isApiResponse && hasErrorConnecting) { + actions.setErrorConnecting(true); + } + return httpResponse; + }, + }); + httpInterceptors.push(errorConnectingInterceptor); + + // TODO: Read only mode interceptor + actions.setHttpInterceptors(httpInterceptors); + }, + }), + events: ({ values }) => ({ + beforeUnmount: () => { + values.httpInterceptors.forEach((removeInterceptorFn?: Function) => { + if (removeInterceptorFn) removeInterceptorFn(); + }); + }, + }), +} as IKeaParams) as IKeaLogic< + IHttpLogicValues, + IHttpLogicActions +>; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.test.tsx new file mode 100644 index 000000000000..81106235780d --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.test.tsx @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../__mocks__/shallow_usecontext.mock'; +import '../../__mocks__/kea.mock'; + +import React from 'react'; +import { shallow } from 'enzyme'; +import { useActions } from 'kea'; + +import { HttpProvider } from './'; + +describe('HttpProvider', () => { + const props = { + http: {} as any, + errorConnecting: false, + }; + const initializeHttp = jest.fn(); + const initializeHttpInterceptors = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + (useActions as jest.Mock).mockImplementationOnce(() => ({ + initializeHttp, + initializeHttpInterceptors, + })); + }); + + it('does not render', () => { + const wrapper = shallow(); + + expect(wrapper.isEmptyRender()).toBe(true); + }); + + it('calls initialization actions on mount', () => { + shallow(); + + expect(initializeHttp).toHaveBeenCalledWith(props); + expect(initializeHttpInterceptors).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.tsx new file mode 100644 index 000000000000..6febc1869054 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/http_provider.tsx @@ -0,0 +1,28 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React, { useEffect } from 'react'; +import { useActions } from 'kea'; + +import { HttpSetup } from 'src/core/public'; + +import { HttpLogic, IHttpLogicActions } from './http_logic'; + +interface IHttpProviderProps { + http: HttpSetup; + errorConnecting?: boolean; +} + +export const HttpProvider: React.FC = (props) => { + const { initializeHttp, initializeHttpInterceptors } = useActions(HttpLogic) as IHttpLogicActions; + + useEffect(() => { + initializeHttp(props); + initializeHttpInterceptors(); + }, []); + + return null; +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts new file mode 100644 index 000000000000..449ff9d56deb --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/shared/http/index.ts @@ -0,0 +1,8 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { HttpLogic, IHttpLogicValues, IHttpLogicActions } from './http_logic'; +export { HttpProvider } from './http_provider'; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/types.ts b/x-pack/plugins/enterprise_search/public/applications/shared/types.ts index 74bb53ef3a95..a8e08323c5e3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/types.ts @@ -14,7 +14,7 @@ export interface IFlashMessagesProps { } export interface IKeaLogic { - mount(): void; + mount(): Function; values: IKeaValues; actions: IKeaActions; } @@ -33,6 +33,7 @@ export interface IKeaLogic { export interface IKeaParams { selectors?(params: { selectors: IKeaValues }): void; listeners?(params: { actions: IKeaActions; values: IKeaValues }): void; + events?(params: { actions: IKeaActions; values: IKeaValues }): void; } /** @@ -47,7 +48,10 @@ export type TKeaReducers = { [Value in keyof IKeaValues]?: [ IKeaValues[Value], { - [Action in keyof IKeaActions]?: (state: IKeaValues, payload: IKeaValues) => IKeaValues[Value]; + [Action in keyof IKeaActions]?: ( + state: IKeaValues[Value], + payload: IKeaValues + ) => IKeaValues[Value]; } ]; }; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/__mocks__/overview_logic.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/__mocks__/overview_logic.mock.ts index 395d2044e7db..5588c4fc53b6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/__mocks__/overview_logic.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/__mocks__/overview_logic.mock.ts @@ -22,7 +22,6 @@ export const mockLogicValues = { personalSourcesCount: 0, sourcesCount: 0, dataLoading: true, - hasErrorConnecting: false, flashMessages: {}, } as IOverviewValues; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx index 744fd8aeb195..fee966a56923 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx @@ -11,7 +11,6 @@ import { mockLogicActions, setMockValues } from './__mocks__'; import React from 'react'; import { shallow, mount } from 'enzyme'; -import { ErrorState } from '../error_state'; import { Loading } from '../shared/loading'; import { ViewContentHeader } from '../shared/view_content_header'; @@ -27,13 +26,6 @@ describe('Overview', () => { expect(wrapper.find(Loading)).toHaveLength(1); }); - - it('hasErrorConnecting', () => { - setMockValues({ hasErrorConnecting: true }); - const wrapper = shallow(); - - expect(wrapper.find(ErrorState)).toHaveLength(1); - }); }); describe('happy-path states', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx index b816eb297320..6aa3e1e608bf 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx @@ -6,19 +6,16 @@ // TODO: Remove EuiPage & EuiPageBody before exposing full app -import React, { useContext, useEffect } from 'react'; +import React, { useEffect } from 'react'; import { EuiPage, EuiPageBody, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { useActions, useValues } from 'kea'; import { SetWorkplaceSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; import { SendWorkplaceSearchTelemetry as SendTelemetry } from '../../../shared/telemetry'; -import { KibanaContext, IKibanaContext } from '../../../index'; import { OverviewLogic, IOverviewActions, IOverviewValues } from './overview_logic'; -import { ErrorState } from '../error_state'; - import { Loading } from '../shared/loading'; import { ProductButton } from '../shared/product_button'; import { ViewContentHeader } from '../shared/view_content_header'; @@ -47,13 +44,10 @@ const HEADER_DESCRIPTION = i18n.translate( ); export const Overview: React.FC = () => { - const { http } = useContext(KibanaContext) as IKibanaContext; - const { initializeOverview } = useActions(OverviewLogic) as IOverviewActions; const { dataLoading, - hasErrorConnecting, hasUsers, hasOrgSources, isOldAccount, @@ -61,10 +55,9 @@ export const Overview: React.FC = () => { } = useValues(OverviewLogic) as IOverviewValues; useEffect(() => { - initializeOverview({ http }); + initializeOverview(); }, [initializeOverview]); - if (hasErrorConnecting) return ; if (dataLoading) return ; const hideOnboarding = hasUsers && hasOrgSources && isOldAccount && orgName !== defaultOrgName; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.test.ts index 7df4de4719f3..3fbf0e60b5b4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.test.ts @@ -5,24 +5,18 @@ */ import { resetContext } from 'kea'; -import { act } from 'react-dom/test-utils'; -import { mockKibanaContext } from '../../../__mocks__'; +jest.mock('../../../shared/http', () => ({ HttpLogic: { values: { http: { get: jest.fn() } } } })); +import { HttpLogic } from '../../../shared/http'; import { mockLogicValues } from './__mocks__'; import { OverviewLogic } from './overview_logic'; describe('OverviewLogic', () => { - let unmount: any; - beforeEach(() => { - resetContext({}); - unmount = OverviewLogic.mount() as any; jest.clearAllMocks(); - }); - - afterEach(() => { - unmount(); + resetContext({}); + OverviewLogic.mount(); }); it('has expected default values', () => { @@ -91,48 +85,14 @@ describe('OverviewLogic', () => { }); }); - describe('setHasErrorConnecting', () => { - it('will set `hasErrorConnecting`', () => { - OverviewLogic.actions.setHasErrorConnecting(true); - - expect(OverviewLogic.values.hasErrorConnecting).toEqual(true); - expect(OverviewLogic.values.dataLoading).toEqual(false); - }); - }); - describe('initializeOverview', () => { it('calls API and sets values', async () => { - const mockHttp = mockKibanaContext.http; - const mockApi = jest.fn(() => mockLogicValues as any); const setServerDataSpy = jest.spyOn(OverviewLogic.actions, 'setServerData'); - await act(async () => - OverviewLogic.actions.initializeOverview({ - http: { - ...mockHttp, - get: mockApi, - }, - }) - ); + await OverviewLogic.actions.initializeOverview(); - expect(mockApi).toHaveBeenCalledWith('/api/workplace_search/overview'); + expect(HttpLogic.values.http.get).toHaveBeenCalledWith('/api/workplace_search/overview'); expect(setServerDataSpy).toHaveBeenCalled(); }); - - it('handles error state', async () => { - const mockHttp = mockKibanaContext.http; - const setHasErrorConnectingSpy = jest.spyOn(OverviewLogic.actions, 'setHasErrorConnecting'); - - await act(async () => - OverviewLogic.actions.initializeOverview({ - http: { - ...mockHttp, - get: () => Promise.reject(), - }, - }) - ); - - expect(setHasErrorConnectingSpy).toHaveBeenCalled(); - }); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.ts index 8bb177a2e742..057bce1b4056 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview_logic.ts @@ -4,9 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { HttpSetup } from 'src/core/public'; - import { kea } from 'kea'; +import { HttpLogic } from '../../../shared/http'; import { IAccount, IOrganization } from '../../types'; import { IFlashMessagesProps, IKeaLogic, TKeaReducers, IKeaParams } from '../../../shared/types'; @@ -32,13 +31,11 @@ export interface IOverviewServerData { export interface IOverviewActions { setServerData(serverData: IOverviewServerData): void; setFlashMessages(flashMessages: IFlashMessagesProps): void; - setHasErrorConnecting(hasErrorConnecting: boolean): void; - initializeOverview({ http }: { http: HttpSetup }): void; + initializeOverview(): void; } export interface IOverviewValues extends IOverviewServerData { dataLoading: boolean; - hasErrorConnecting: boolean; flashMessages: IFlashMessagesProps; } @@ -46,8 +43,7 @@ export const OverviewLogic = kea({ actions: (): IOverviewActions => ({ setServerData: (serverData) => serverData, setFlashMessages: (flashMessages) => ({ flashMessages }), - setHasErrorConnecting: (hasErrorConnecting) => ({ hasErrorConnecting }), - initializeOverview: ({ http }) => ({ http }), + initializeOverview: () => null, }), reducers: (): TKeaReducers => ({ organization: [ @@ -138,24 +134,13 @@ export const OverviewLogic = kea({ true, { setServerData: () => false, - setHasErrorConnecting: () => false, - }, - ], - hasErrorConnecting: [ - false, - { - setHasErrorConnecting: (_, { hasErrorConnecting }) => hasErrorConnecting, }, ], }), listeners: ({ actions }): Partial => ({ - initializeOverview: async ({ http }: { http: HttpSetup }) => { - try { - const response = await http.get('/api/workplace_search/overview'); - actions.setServerData(response); - } catch (error) { - actions.setHasErrorConnecting(true); - } + initializeOverview: async () => { + const response = await HttpLogic.values.http.get('/api/workplace_search/overview'); + actions.setServerData(response); }, }), } as IKeaParams) as IKeaLogic; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx index a55ff6401413..654f4dce0ebf 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx @@ -5,35 +5,44 @@ */ import '../__mocks__/shallow_usecontext.mock'; +import '../__mocks__/kea.mock'; import React, { useContext } from 'react'; import { Redirect } from 'react-router-dom'; import { shallow } from 'enzyme'; +import { useValues } from 'kea'; import { Overview } from './components/overview'; +import { ErrorState } from './components/error_state'; import { WorkplaceSearch } from './'; describe('Workplace Search', () => { - describe('/', () => { - it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => { - (useContext as jest.Mock).mockImplementationOnce(() => ({ - config: { host: '' }, - })); - const wrapper = shallow(); - - expect(wrapper.find(Redirect)).toHaveLength(1); - expect(wrapper.find(Overview)).toHaveLength(0); - }); - - it('renders the Overview when enterpriseSearchUrl is set', () => { - (useContext as jest.Mock).mockImplementationOnce(() => ({ - config: { host: 'https://foo.bar' }, - })); - const wrapper = shallow(); - - expect(wrapper.find(Overview)).toHaveLength(1); - expect(wrapper.find(Redirect)).toHaveLength(0); - }); + it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => { + (useContext as jest.Mock).mockImplementationOnce(() => ({ + config: { host: '' }, + })); + const wrapper = shallow(); + + expect(wrapper.find(Redirect)).toHaveLength(1); + expect(wrapper.find(Overview)).toHaveLength(0); + }); + + it('renders the Overview when enterpriseSearchUrl is set', () => { + (useContext as jest.Mock).mockImplementationOnce(() => ({ + config: { host: 'https://foo.bar' }, + })); + const wrapper = shallow(); + + expect(wrapper.find(Overview)).toHaveLength(1); + expect(wrapper.find(Redirect)).toHaveLength(0); + }); + + it('renders ErrorState when the app cannot connect to Enterprise Search', () => { + (useValues as jest.Mock).mockImplementationOnce(() => ({ errorConnecting: true })); + const wrapper = shallow(); + + expect(wrapper.find(ErrorState).exists()).toBe(true); + expect(wrapper.find(Overview)).toHaveLength(0); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx index 94462aa8de7d..b261c83e30dd 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx @@ -6,19 +6,24 @@ import React, { useContext } from 'react'; import { Route, Redirect, Switch } from 'react-router-dom'; +import { useValues } from 'kea'; import { IInitialAppData } from '../../../common/types'; import { KibanaContext, IKibanaContext } from '../index'; +import { HttpLogic, IHttpLogicValues } from '../shared/http'; import { Layout } from '../shared/layout'; import { WorkplaceSearchNav } from './components/layout/nav'; import { SETUP_GUIDE_PATH } from './routes'; import { SetupGuide } from './components/setup_guide'; +import { ErrorState } from './components/error_state'; import { Overview } from './components/overview'; export const WorkplaceSearch: React.FC = (props) => { const { config } = useContext(KibanaContext) as IKibanaContext; + const { errorConnecting } = useValues(HttpLogic) as IHttpLogicValues; + if (!config.host) return ( @@ -37,16 +42,20 @@ export const WorkplaceSearch: React.FC = (props) => { - + {errorConnecting ? : } }> - - - {/* Will replace with groups component subsequent PR */} -
- - + {errorConnecting ? ( + + ) : ( + + + {/* Will replace with groups component subsequent PR */} +
+ + + )} diff --git a/x-pack/plugins/enterprise_search/public/plugin.ts b/x-pack/plugins/enterprise_search/public/plugin.ts index 148a50fb4a5c..881fe02af5b0 100644 --- a/x-pack/plugins/enterprise_search/public/plugin.ts +++ b/x-pack/plugins/enterprise_search/public/plugin.ts @@ -31,6 +31,7 @@ export interface ClientConfigType { } export interface ClientData extends IInitialAppData { externalUrl: IExternalUrl; + errorConnecting?: boolean; } export interface PluginsSetup { @@ -123,6 +124,7 @@ export class EnterpriseSearchPlugin implements Plugin { this.hasInitialized = true; } catch { + this.data.errorConnecting = true; // The plugin will attempt to re-fetch config data on page change } } diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts index 968ecb95fd93..1ea023ecacdb 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts @@ -68,10 +68,11 @@ describe('engine routes', () => { ).andReturnError(); }); - it('should return 404 with a message', async () => { + it('should return 502 with a message', async () => { await mockRouter.callRoute(mockRequest); - expect(mockRouter.response.notFound).toHaveBeenCalledWith({ + expect(mockRouter.response.customError).toHaveBeenCalledWith({ + statusCode: 502, body: 'cannot-connect', }); expect(mockLogger.error).toHaveBeenCalledWith('Cannot connect to App Search: Failed'); @@ -87,10 +88,11 @@ describe('engine routes', () => { ).andReturnInvalidData(); }); - it('should return 404 with a message', async () => { + it('should return 502 with a message', async () => { await mockRouter.callRoute(mockRequest); - expect(mockRouter.response.notFound).toHaveBeenCalledWith({ + expect(mockRouter.response.customError).toHaveBeenCalledWith({ + statusCode: 502, body: 'cannot-connect', }); expect(mockLogger.error).toHaveBeenCalledWith( diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts index ca83c0e187dd..7190772fb92b 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts @@ -52,7 +52,7 @@ export function registerEnginesRoute({ router, config, log }: IRouteDependencies log.error(`Cannot connect to App Search: ${e.toString()}`); if (e instanceof Error) log.debug(e.stack as string); - return response.notFound({ body: 'cannot-connect' }); + return response.customError({ statusCode: 502, body: 'cannot-connect' }); } } ); diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts index 3a4e28b0de5f..f6534b27b5da 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts @@ -63,10 +63,11 @@ describe('engine routes', () => { }).andReturnError(); }); - it('should return 404 with a message', async () => { + it('should return 502 with a message', async () => { await mockRouter.callRoute(mockRequest); - expect(mockRouter.response.notFound).toHaveBeenCalledWith({ + expect(mockRouter.response.customError).toHaveBeenCalledWith({ + statusCode: 502, body: 'cannot-connect', }); expect(mockLogger.error).toHaveBeenCalledWith('Cannot connect to Workplace Search: Failed'); @@ -81,10 +82,11 @@ describe('engine routes', () => { }).andReturnInvalidData(); }); - it('should return 404 with a message', async () => { + it('should return 502 with a message', async () => { await mockRouter.callRoute(mockRequest); - expect(mockRouter.response.notFound).toHaveBeenCalledWith({ + expect(mockRouter.response.customError).toHaveBeenCalledWith({ + statusCode: 502, body: 'cannot-connect', }); expect(mockLogger.error).toHaveBeenCalledWith( diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts index d1e2f4f5f180..9e5d94ac1b4f 100644 --- a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts +++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts @@ -39,7 +39,7 @@ export function registerWSOverviewRoute({ router, config, log }: IRouteDependenc log.error(`Cannot connect to Workplace Search: ${e.toString()}`); if (e instanceof Error) log.debug(e.stack as string); - return response.notFound({ body: 'cannot-connect' }); + return response.customError({ statusCode: 502, body: 'cannot-connect' }); } } ); diff --git a/x-pack/plugins/grokdebugger/README.md b/x-pack/plugins/grokdebugger/README.md deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/x-pack/plugins/ingest_manager/common/constants/epm.ts b/x-pack/plugins/ingest_manager/common/constants/epm.ts index 73cd8463bb6a..571580e81258 100644 --- a/x-pack/plugins/ingest_manager/common/constants/epm.ts +++ b/x-pack/plugins/ingest_manager/common/constants/epm.ts @@ -7,3 +7,4 @@ export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-packages'; export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern'; export const INDEX_PATTERN_PLACEHOLDER_SUFFIX = '-index_pattern_placeholder'; +export const MAX_TIME_COMPLETE_INSTALL = 60000; diff --git a/x-pack/plugins/ingest_manager/common/types/models/epm.ts b/x-pack/plugins/ingest_manager/common/types/models/epm.ts index 6ec5b73eaa43..140a76ac85e6 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts @@ -19,6 +19,8 @@ export enum InstallStatus { uninstalling = 'uninstalling', } +export type EpmPackageInstallStatus = 'installed' | 'installing'; + export type DetailViewPanelName = 'overview' | 'usages' | 'settings'; export type ServiceName = 'kibana' | 'elasticsearch'; export type AssetType = KibanaAssetType | ElasticsearchAssetType | AgentAssetType; @@ -234,6 +236,9 @@ export interface Installation extends SavedObjectAttributes { es_index_patterns: Record; name: string; version: string; + install_status: EpmPackageInstallStatus; + install_version: string; + install_started_at: string; } export type Installable = Installed | NotInstalled; diff --git a/x-pack/plugins/ingest_manager/server/constants/index.ts b/x-pack/plugins/ingest_manager/server/constants/index.ts index 54d2d876c75b..d677b79bb46f 100644 --- a/x-pack/plugins/ingest_manager/server/constants/index.ts +++ b/x-pack/plugins/ingest_manager/server/constants/index.ts @@ -14,6 +14,7 @@ export { AGENT_POLICY_ROLLOUT_RATE_LIMIT_INTERVAL_MS, AGENT_UPDATE_ACTIONS_INTERVAL_MS, INDEX_PATTERN_PLACEHOLDER_SUFFIX, + MAX_TIME_COMPLETE_INSTALL, // Routes LIMITED_CONCURRENCY_ROUTE_TAG, PLUGIN_ID, diff --git a/x-pack/plugins/ingest_manager/server/saved_objects/index.ts b/x-pack/plugins/ingest_manager/server/saved_objects/index.ts index 50957c48f70e..1bbe3b71bf91 100644 --- a/x-pack/plugins/ingest_manager/server/saved_objects/index.ts +++ b/x-pack/plugins/ingest_manager/server/saved_objects/index.ts @@ -285,6 +285,9 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = { type: { type: 'keyword' }, }, }, + install_started_at: { type: 'date' }, + install_version: { type: 'keyword' }, + install_status: { type: 'keyword' }, }, }, }, diff --git a/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/install.ts index 2a3120f06490..f4e8c3bfd99d 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/install.ts @@ -22,7 +22,6 @@ import { removeAssetsFromInstalledEsByType, saveInstalledEsRefs } from '../../pa export const installTemplates = async ( registryPackage: RegistryPackage, - isUpdate: boolean, callCluster: CallESAsCurrentUser, paths: string[], savedObjectsClient: SavedObjectsClientContract diff --git a/x-pack/plugins/ingest_manager/server/services/epm/kibana/assets/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/kibana/assets/install.ts index 84892d202784..ff1a91b00d84 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/kibana/assets/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/kibana/assets/install.ts @@ -48,7 +48,6 @@ export async function installKibanaAssets(options: { savedObjectsClient: SavedObjectsClientContract; pkgName: string; kibanaAssets: ArchiveAsset[]; - isUpdate: boolean; }): Promise { const { savedObjectsClient, kibanaAssets } = options; diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts index 1688900fc175..c4232247cc4b 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/get.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SavedObjectsClientContract } from 'src/core/server'; +import { SavedObjectsClientContract, SavedObjectsFindOptions } from 'src/core/server'; import { isPackageLimited } from '../../../../common'; import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants'; import { Installation, InstallationStatus, PackageInfo, KibanaAssetType } from '../../../types'; @@ -72,8 +72,12 @@ export async function getLimitedPackages(options: { return installedPackagesInfo.filter(isPackageLimited).map((pkgInfo) => pkgInfo.name); } -export async function getPackageSavedObjects(savedObjectsClient: SavedObjectsClientContract) { +export async function getPackageSavedObjects( + savedObjectsClient: SavedObjectsClientContract, + options?: Omit +) { return savedObjectsClient.find({ + ...(options || {}), type: PACKAGES_SAVED_OBJECT_TYPE, }); } diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts index 6bc461845f12..e49dbe8f0b5d 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/install.ts @@ -6,7 +6,7 @@ import { SavedObjectsClientContract } from 'src/core/server'; import semver from 'semver'; -import { PACKAGES_SAVED_OBJECT_TYPE } from '../../../constants'; +import { PACKAGES_SAVED_OBJECT_TYPE, MAX_TIME_COMPLETE_INSTALL } from '../../../constants'; import { AssetReference, Installation, @@ -33,6 +33,7 @@ import { import { updateCurrentWriteIndices } from '../elasticsearch/template/template'; import { deleteKibanaSavedObjectsAssets } from './remove'; import { PackageOutdatedError } from '../../../errors'; +import { getPackageSavedObjects } from './get'; export async function installLatestPackage(options: { savedObjectsClient: SavedObjectsClientContract; @@ -107,22 +108,24 @@ export async function installPackage({ // TODO: calls to getInstallationObject, Registry.fetchInfo, and Registry.fetchFindLatestPackge // and be replaced by getPackageInfo after adjusting for it to not group/use archive assets const latestPackage = await Registry.fetchFindLatestPackage(pkgName); - if (semver.lt(pkgVersion, latestPackage.version) && !force) - throw new PackageOutdatedError(`${pkgkey} is out-of-date and cannot be installed or updated`); + // get the currently installed package + const installedPkg = await getInstallationObject({ savedObjectsClient, pkgName }); + const reinstall = pkgVersion === installedPkg?.attributes.version; + const reupdate = pkgVersion === installedPkg?.attributes.install_version; + // let the user install if using the force flag or this is a reinstall or reupdate due to intallation interruption + if (semver.lt(pkgVersion, latestPackage.version) && !force && !reinstall && !reupdate) { + throw new PackageOutdatedError(`${pkgkey} is out-of-date and cannot be installed or updated`); + } const paths = await Registry.getArchiveInfo(pkgName, pkgVersion); const registryPackageInfo = await Registry.fetchInfo(pkgName, pkgVersion); - // get the currently installed package - const installedPkg = await getInstallationObject({ savedObjectsClient, pkgName }); - const isUpdate = installedPkg && installedPkg.attributes.version < pkgVersion ? true : false; - - const reinstall = pkgVersion === installedPkg?.attributes.version; const removable = !isRequiredPackage(pkgName); const { internal = false } = registryPackageInfo; const toSaveESIndexPatterns = generateESIndexPatterns(registryPackageInfo.datasets); - // add the package installation to the saved object + // add the package installation to the saved object. + // if some installation already exists, just update install info if (!installedPkg) { await createInstallation({ savedObjectsClient, @@ -134,6 +137,12 @@ export async function installPackage({ installed_es: [], toSaveESIndexPatterns, }); + } else { + await savedObjectsClient.update(PACKAGES_SAVED_OBJECT_TYPE, pkgName, { + install_version: pkgVersion, + install_status: 'installing', + install_started_at: new Date().toISOString(), + }); } const installIndexPatternPromise = installIndexPatterns(savedObjectsClient, pkgName, pkgVersion); const kibanaAssets = await getKibanaAssets(paths); @@ -152,7 +161,6 @@ export async function installPackage({ savedObjectsClient, pkgName, kibanaAssets, - isUpdate, }); // the rest of the installation must happen in sequential order @@ -172,7 +180,6 @@ export async function installPackage({ // install or update the templates referencing the newly installed pipelines const installedTemplates = await installTemplates( registryPackageInfo, - isUpdate, callCluster, paths, savedObjectsClient @@ -197,9 +204,14 @@ export async function installPackage({ })); await Promise.all([installKibanaAssetsPromise, installIndexPatternPromise]); // update to newly installed version when all assets are successfully installed - if (isUpdate) await updateVersion(savedObjectsClient, pkgName, pkgVersion); + if (installedPkg) await updateVersion(savedObjectsClient, pkgName, pkgVersion); + await savedObjectsClient.update(PACKAGES_SAVED_OBJECT_TYPE, pkgName, { + install_version: pkgVersion, + install_status: 'installed', + }); return [...installedKibanaAssetsRefs, ...installedPipelines, ...installedTemplateRefs]; } + const updateVersion = async ( savedObjectsClient: SavedObjectsClientContract, pkgName: string, @@ -239,6 +251,9 @@ export async function createInstallation(options: { version: pkgVersion, internal, removable, + install_version: pkgVersion, + install_status: 'installing', + install_started_at: new Date().toISOString(), }, { id: pkgName, overwrite: true } ); @@ -286,3 +301,28 @@ export const removeAssetsFromInstalledEsByType = async ( installed_es: installedAssetsToSave, }); }; + +export async function ensurePackagesCompletedInstall( + savedObjectsClient: SavedObjectsClientContract, + callCluster: CallESAsCurrentUser +) { + const installingPackages = await getPackageSavedObjects(savedObjectsClient, { + searchFields: ['install_status'], + search: 'installing', + }); + const installingPromises = installingPackages.saved_objects.reduce< + Array> + >((acc, pkg) => { + const startDate = pkg.attributes.install_started_at; + const nowDate = new Date().toISOString(); + const elapsedTime = Date.parse(nowDate) - Date.parse(startDate); + const pkgkey = `${pkg.attributes.name}-${pkg.attributes.install_version}`; + // reinstall package + if (elapsedTime > MAX_TIME_COMPLETE_INSTALL) { + acc.push(installPackage({ savedObjectsClient, pkgkey, callCluster })); + } + return acc; + }, []); + await Promise.all(installingPromises); + return installingPackages; +} diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts index fb4430f8cf72..fd5d94a71d67 100644 --- a/x-pack/plugins/ingest_manager/server/services/setup.ts +++ b/x-pack/plugins/ingest_manager/server/services/setup.ts @@ -10,7 +10,10 @@ import { SavedObjectsClientContract } from 'src/core/server'; import { CallESAsCurrentUser } from '../types'; import { agentPolicyService } from './agent_policy'; import { outputService } from './output'; -import { ensureInstalledDefaultPackages } from './epm/packages/install'; +import { + ensureInstalledDefaultPackages, + ensurePackagesCompletedInstall, +} from './epm/packages/install'; import { ensureDefaultIndices } from './epm/kibana/index_pattern/install'; import { packageToPackagePolicy, @@ -51,6 +54,7 @@ async function createSetupSideEffects( ensureInstalledDefaultPackages(soClient, callCluster), outputService.ensureDefaultOutput(soClient), agentPolicyService.ensureDefaultAgentPolicy(soClient), + ensurePackagesCompletedInstall(soClient, callCluster), ensureDefaultIndices(callCluster), settingsService.getSettings(soClient).catch((e: any) => { if (e.isBoom && e.output.statusCode === 404) { diff --git a/x-pack/plugins/ingest_manager/server/types/index.tsx b/x-pack/plugins/ingest_manager/server/types/index.tsx index 8e3219a8c08e..aabe4bd3e359 100644 --- a/x-pack/plugins/ingest_manager/server/types/index.tsx +++ b/x-pack/plugins/ingest_manager/server/types/index.tsx @@ -37,6 +37,7 @@ export { EnrollmentAPIKey, EnrollmentAPIKeySOAttributes, Installation, + EpmPackageInstallStatus, InstallationStatus, PackageInfo, RegistryVarsEntry, diff --git a/x-pack/plugins/lens/public/app_plugin/app.test.tsx b/x-pack/plugins/lens/public/app_plugin/app.test.tsx index 892058d82a80..2b979f064b8e 100644 --- a/x-pack/plugins/lens/public/app_plugin/app.test.tsx +++ b/x-pack/plugins/lens/public/app_plugin/app.test.tsx @@ -300,7 +300,7 @@ describe('Lens App', () => { ]); }); - it.skip('sets originatingApp breadcrumb when the document title changes', async () => { + it('sets originatingApp breadcrumb when the document title changes', async () => { const defaultArgs = makeDefaultArgs(); defaultArgs.originatingApp = 'ultraCoolDashboard'; defaultArgs.getAppNameFromId = () => 'The Coolest Container Ever Made'; @@ -315,11 +315,11 @@ describe('Lens App', () => { (defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({ id: '1234', title: 'Daaaaaaadaumching!', - expression: 'valid expression', state: { query: 'fake query', - datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] }, + filters: [], }, + references: [], }); await act(async () => { instance.setProps({ docId: '1234' }); diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx index 4f914bc65dc7..06cd858eda21 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx @@ -13,7 +13,6 @@ import { EuiIcon, EuiImage, EuiText, - EuiBetaBadge, EuiButtonEmpty, EuiLink, } from '@elastic/eui'; @@ -210,10 +209,6 @@ export function InnerWorkspacePanel({ } function renderEmptyWorkspace() { - const tooltipContent = i18n.translate('xpack.lens.editorFrame.tooltipContent', { - defaultMessage: - 'Lens is in beta and is subject to change. The design and code is less mature than official GA features and is being provided as-is with no warranties. Beta features are not subject to the support SLA of official GA features', - }); return (
@@ -232,8 +227,7 @@ export function InnerWorkspacePanel({ {' '} - + />

diff --git a/x-pack/plugins/lens/public/vis_type_alias.ts b/x-pack/plugins/lens/public/vis_type_alias.ts index 3bb2dbbae1f9..d0dceed03db2 100644 --- a/x-pack/plugins/lens/public/vis_type_alias.ts +++ b/x-pack/plugins/lens/public/vis_type_alias.ts @@ -27,7 +27,7 @@ export const getLensAliasConfig = (): VisTypeAlias => ({ defaultMessage: `Lens is a simpler way to create basic visualizations`, }), icon: 'lensApp', - stage: 'beta', + stage: 'production', appExtensions: { visualizations: { docTypes: ['lens'], @@ -42,7 +42,7 @@ export const getLensAliasConfig = (): VisTypeAlias => ({ editUrl: getEditPath(id), editApp: 'lens', icon: 'lensApp', - stage: 'beta', + stage: 'production', savedObjectType: type, typeTitle: i18n.translate('xpack.lens.visTypeAlias.type', { defaultMessage: 'Lens' }), }; diff --git a/x-pack/plugins/lists/public/common/mocks/kibana_core.ts b/x-pack/plugins/lists/public/common/mocks/kibana_core.ts deleted file mode 100644 index c078e8ccd5ea..000000000000 --- a/x-pack/plugins/lists/public/common/mocks/kibana_core.ts +++ /dev/null @@ -1,12 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { coreMock } from '../../../../../../src/core/public/mocks'; -import { CoreStart } from '../../../../../../src/core/public'; - -export type GlobalServices = Pick; - -export const createKibanaCoreStartMock = (): GlobalServices => coreMock.createStart(); diff --git a/x-pack/plugins/lists/public/exceptions/api.test.ts b/x-pack/plugins/lists/public/exceptions/api.test.ts index 9add15c533d1..457a8708ec34 100644 --- a/x-pack/plugins/lists/public/exceptions/api.test.ts +++ b/x-pack/plugins/lists/public/exceptions/api.test.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { createKibanaCoreStartMock } from '../common/mocks/kibana_core'; +import { coreMock } from '../../../../../src/core/public/mocks'; import { getExceptionListSchemaMock } from '../../common/schemas/response/exception_list_schema.mock'; import { getExceptionListItemSchemaMock } from '../../common/schemas/response/exception_list_item_schema.mock'; import { getCreateExceptionListSchemaMock } from '../../common/schemas/request/create_exception_list_schema.mock'; @@ -34,39 +34,28 @@ import { ApiCallByIdProps, ApiCallByListIdProps } from './types'; const abortCtrl = new AbortController(); -jest.mock('../common/mocks/kibana_core', () => ({ - createKibanaCoreStartMock: (): jest.Mock => jest.fn(), -})); -const fetchMock = jest.fn(); +describe('Exceptions Lists API', () => { + let httpMock: ReturnType['http']; -/* - This is a little funky, in order for typescript to not - yell at us for converting 'Pick' to type 'Mock' - have to first convert to type 'unknown' - */ -const mockKibanaHttpService = ((createKibanaCoreStartMock() as unknown) as jest.Mock).mockReturnValue( - { - fetch: fetchMock, - } -); + beforeEach(() => { + httpMock = coreMock.createStart().http; + }); -describe('Exceptions Lists API', () => { describe('#addExceptionList', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListSchemaMock()); }); test('it invokes "addExceptionList" with expected url and body values', async () => { const payload = getCreateExceptionListSchemaMock(); await addExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }); // TODO Would like to just use getExceptionListSchemaMock() here, but // validation returns object in different order, making the strings not match - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists', { body: JSON.stringify(payload), method: 'POST', signal: abortCtrl.signal, @@ -76,7 +65,7 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const payload = getCreateExceptionListSchemaMock(); const exceptionResponse = await addExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }); @@ -90,7 +79,7 @@ describe('Exceptions Lists API', () => { await expect( addExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: (payload as unknown) as ExceptionListSchema, signal: abortCtrl.signal, }) @@ -101,11 +90,11 @@ describe('Exceptions Lists API', () => { const payload = getCreateExceptionListSchemaMock(); const badPayload = getExceptionListSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( addExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }) @@ -115,20 +104,19 @@ describe('Exceptions Lists API', () => { describe('#addExceptionListItem', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListItemSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListItemSchemaMock()); }); test('it invokes "addExceptionListItem" with expected url and body values', async () => { const payload = getCreateExceptionListItemSchemaMock(); await addExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }); // TODO Would like to just use getExceptionListSchemaMock() here, but // validation returns object in different order, making the strings not match - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items', { body: JSON.stringify(payload), method: 'POST', signal: abortCtrl.signal, @@ -138,7 +126,7 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const payload = getCreateExceptionListItemSchemaMock(); const exceptionResponse = await addExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }); @@ -152,7 +140,7 @@ describe('Exceptions Lists API', () => { await expect( addExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: (payload as unknown) as ExceptionListItemSchema, signal: abortCtrl.signal, }) @@ -163,11 +151,11 @@ describe('Exceptions Lists API', () => { const payload = getCreateExceptionListItemSchemaMock(); const badPayload = getExceptionListItemSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( addExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }) @@ -177,20 +165,19 @@ describe('Exceptions Lists API', () => { describe('#updateExceptionList', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListSchemaMock()); }); test('it invokes "updateExceptionList" with expected url and body values', async () => { const payload = getUpdateExceptionListSchemaMock(); await updateExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }); // TODO Would like to just use getExceptionListSchemaMock() here, but // validation returns object in different order, making the strings not match - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists', { body: JSON.stringify(payload), method: 'PUT', signal: abortCtrl.signal, @@ -200,7 +187,7 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const payload = getUpdateExceptionListSchemaMock(); const exceptionResponse = await updateExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }); @@ -213,7 +200,7 @@ describe('Exceptions Lists API', () => { await expect( updateExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }) @@ -224,11 +211,11 @@ describe('Exceptions Lists API', () => { const payload = getUpdateExceptionListSchemaMock(); const badPayload = getExceptionListSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( updateExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, list: payload, signal: abortCtrl.signal, }) @@ -238,20 +225,19 @@ describe('Exceptions Lists API', () => { describe('#updateExceptionListItem', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListItemSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListItemSchemaMock()); }); test('it invokes "updateExceptionListItem" with expected url and body values', async () => { const payload = getUpdateExceptionListItemSchemaMock(); await updateExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }); // TODO Would like to just use getExceptionListSchemaMock() here, but // validation returns object in different order, making the strings not match - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items', { body: JSON.stringify(payload), method: 'PUT', signal: abortCtrl.signal, @@ -261,7 +247,7 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const payload = getUpdateExceptionListItemSchemaMock(); const exceptionResponse = await updateExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }); @@ -274,7 +260,7 @@ describe('Exceptions Lists API', () => { await expect( updateExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }) @@ -285,11 +271,11 @@ describe('Exceptions Lists API', () => { const payload = getUpdateExceptionListItemSchemaMock(); const badPayload = getExceptionListItemSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( updateExceptionListItem({ - http: mockKibanaHttpService(), + http: httpMock, listItem: payload, signal: abortCtrl.signal, }) @@ -299,18 +285,17 @@ describe('Exceptions Lists API', () => { describe('#fetchExceptionListById', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListSchemaMock()); }); test('it invokes "fetchExceptionListById" with expected url and body values', async () => { await fetchExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists', { method: 'GET', query: { id: '1', @@ -322,7 +307,7 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const exceptionResponse = await fetchExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -332,7 +317,7 @@ describe('Exceptions Lists API', () => { test('it returns error and does not make request if request payload fails decode', async () => { const payload = ({ - http: mockKibanaHttpService(), + http: httpMock, id: 1, namespaceType: 'single', signal: abortCtrl.signal, @@ -345,11 +330,11 @@ describe('Exceptions Lists API', () => { test('it returns error if response payload fails decode', async () => { const badPayload = getExceptionListSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( fetchExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -360,14 +345,13 @@ describe('Exceptions Lists API', () => { describe('#fetchExceptionListsItemsByListIds', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getFoundExceptionListItemSchemaMock()); + httpMock.fetch.mockResolvedValue(getFoundExceptionListItemSchemaMock()); }); test('it invokes "fetchExceptionListsItemsByListIds" with expected url and body values', async () => { await fetchExceptionListsItemsByListIds({ filterOptions: [], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList', 'myOtherListId'], namespaceTypes: ['single', 'single'], pagination: { @@ -377,7 +361,7 @@ describe('Exceptions Lists API', () => { signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items/_find', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items/_find', { method: 'GET', query: { list_id: 'myList,myOtherListId', @@ -397,7 +381,7 @@ describe('Exceptions Lists API', () => { tags: [], }, ], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['single'], pagination: { @@ -407,7 +391,7 @@ describe('Exceptions Lists API', () => { signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items/_find', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items/_find', { method: 'GET', query: { filter: 'exception-list.attributes.entries.field:hello world*', @@ -428,7 +412,7 @@ describe('Exceptions Lists API', () => { tags: [], }, ], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['agnostic'], pagination: { @@ -438,7 +422,7 @@ describe('Exceptions Lists API', () => { signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items/_find', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items/_find', { method: 'GET', query: { filter: 'exception-list-agnostic.attributes.entries.field:hello world*', @@ -459,7 +443,7 @@ describe('Exceptions Lists API', () => { tags: ['malware'], }, ], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['agnostic'], pagination: { @@ -469,7 +453,7 @@ describe('Exceptions Lists API', () => { signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items/_find', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items/_find', { method: 'GET', query: { filter: 'exception-list-agnostic.attributes.tags:malware', @@ -490,7 +474,7 @@ describe('Exceptions Lists API', () => { tags: ['malware'], }, ], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['agnostic'], pagination: { @@ -500,7 +484,7 @@ describe('Exceptions Lists API', () => { signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items/_find', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items/_find', { method: 'GET', query: { filter: @@ -517,7 +501,7 @@ describe('Exceptions Lists API', () => { test('it returns expected format when call succeeds', async () => { const exceptionResponse = await fetchExceptionListsItemsByListIds({ filterOptions: [], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['endpoint_list_id'], namespaceTypes: ['single'], pagination: { @@ -532,7 +516,7 @@ describe('Exceptions Lists API', () => { test('it returns error and does not make request if request payload fails decode', async () => { const payload = ({ filterOptions: [], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['not a namespace type'], pagination: { @@ -549,12 +533,12 @@ describe('Exceptions Lists API', () => { test('it returns error if response payload fails decode', async () => { const badPayload = getExceptionListItemSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( fetchExceptionListsItemsByListIds({ filterOptions: [], - http: mockKibanaHttpService(), + http: httpMock, listIds: ['myList'], namespaceTypes: ['single'], pagination: { @@ -571,18 +555,17 @@ describe('Exceptions Lists API', () => { describe('#fetchExceptionListItemById', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListItemSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListItemSchemaMock()); }); test('it invokes "fetchExceptionListItemById" with expected url and body values', async () => { await fetchExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items', { method: 'GET', query: { id: '1', @@ -594,7 +577,7 @@ describe('Exceptions Lists API', () => { test('it returns expected format when call succeeds', async () => { const exceptionResponse = await fetchExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -604,7 +587,7 @@ describe('Exceptions Lists API', () => { test('it returns error and does not make request if request payload fails decode', async () => { const payload = ({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'not a namespace type', signal: abortCtrl.signal, @@ -617,11 +600,11 @@ describe('Exceptions Lists API', () => { test('it returns error if response payload fails decode', async () => { const badPayload = getExceptionListItemSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( fetchExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -632,18 +615,17 @@ describe('Exceptions Lists API', () => { describe('#deleteExceptionListById', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListSchemaMock()); }); test('check parameter url, body when deleting exception item', async () => { await deleteExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists', { method: 'DELETE', query: { id: '1', @@ -655,7 +637,7 @@ describe('Exceptions Lists API', () => { test('it returns expected format when call succeeds', async () => { const exceptionResponse = await deleteExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -665,7 +647,7 @@ describe('Exceptions Lists API', () => { test('it returns error and does not make request if request payload fails decode', async () => { const payload = ({ - http: mockKibanaHttpService(), + http: httpMock, id: 1, namespaceType: 'single', signal: abortCtrl.signal, @@ -678,11 +660,11 @@ describe('Exceptions Lists API', () => { test('it returns error if response payload fails decode', async () => { const badPayload = getExceptionListSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( deleteExceptionListById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -693,18 +675,17 @@ describe('Exceptions Lists API', () => { describe('#deleteExceptionListItemById', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListItemSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListItemSchemaMock()); }); test('check parameter url, body when deleting exception item', async () => { await deleteExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/exception_lists/items', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/exception_lists/items', { method: 'DELETE', query: { id: '1', @@ -716,7 +697,7 @@ describe('Exceptions Lists API', () => { test('it returns expected format when call succeeds', async () => { const exceptionResponse = await deleteExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -726,7 +707,7 @@ describe('Exceptions Lists API', () => { test('it returns error and does not make request if request payload fails decode', async () => { const payload = ({ - http: mockKibanaHttpService(), + http: httpMock, id: 1, namespaceType: 'single', signal: abortCtrl.signal, @@ -739,11 +720,11 @@ describe('Exceptions Lists API', () => { test('it returns error if response payload fails decode', async () => { const badPayload = getExceptionListItemSchemaMock(); delete badPayload.id; - fetchMock.mockResolvedValue(badPayload); + httpMock.fetch.mockResolvedValue(badPayload); await expect( deleteExceptionListItemById({ - http: mockKibanaHttpService(), + http: httpMock, id: '1', namespaceType: 'single', signal: abortCtrl.signal, @@ -754,16 +735,15 @@ describe('Exceptions Lists API', () => { describe('#addEndpointExceptionList', () => { beforeEach(() => { - fetchMock.mockClear(); - fetchMock.mockResolvedValue(getExceptionListSchemaMock()); + httpMock.fetch.mockResolvedValue(getExceptionListSchemaMock()); }); test('it invokes "addEndpointExceptionList" with expected url and body values', async () => { await addEndpointExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, signal: abortCtrl.signal, }); - expect(fetchMock).toHaveBeenCalledWith('/api/endpoint_list', { + expect(httpMock.fetch).toHaveBeenCalledWith('/api/endpoint_list', { method: 'POST', signal: abortCtrl.signal, }); @@ -771,16 +751,16 @@ describe('Exceptions Lists API', () => { test('it returns expected exception list on success', async () => { const exceptionResponse = await addEndpointExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, signal: abortCtrl.signal, }); expect(exceptionResponse).toEqual(getExceptionListSchemaMock()); }); test('it returns an empty object when list already exists', async () => { - fetchMock.mockResolvedValue({}); + httpMock.fetch.mockResolvedValue({}); const exceptionResponse = await addEndpointExceptionList({ - http: mockKibanaHttpService(), + http: httpMock, signal: abortCtrl.signal, }); expect(exceptionResponse).toEqual({}); diff --git a/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_item.test.ts b/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_item.test.ts index ebee2cbace9c..9460432cbc9c 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_item.test.ts +++ b/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_item.test.ts @@ -6,16 +6,16 @@ import { act, renderHook } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../src/core/public/mocks'; import * as api from '../api'; import { getCreateExceptionListItemSchemaMock } from '../../../common/schemas/request/create_exception_list_item_schema.mock'; import { getUpdateExceptionListItemSchemaMock } from '../../../common/schemas/request/update_exception_list_item_schema.mock'; import { getExceptionListItemSchemaMock } from '../../../common/schemas/response/exception_list_item_schema.mock'; -import { createKibanaCoreStartMock } from '../../common/mocks/kibana_core'; import { PersistHookProps } from '../types'; import { ReturnPersistExceptionItem, usePersistExceptionItem } from './persist_exception_item'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; describe('usePersistExceptionItem', () => { const onError = jest.fn(); diff --git a/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_list.test.ts b/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_list.test.ts index 0541f893e279..d5dfe1174d00 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_list.test.ts +++ b/x-pack/plugins/lists/public/exceptions/hooks/persist_exception_list.test.ts @@ -6,16 +6,16 @@ import { act, renderHook } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../src/core/public/mocks'; import * as api from '../api'; import { getCreateExceptionListSchemaMock } from '../../../common/schemas/request/create_exception_list_schema.mock'; import { getUpdateExceptionListSchemaMock } from '../../../common/schemas/request/update_exception_list_schema.mock'; import { getExceptionListSchemaMock } from '../../../common/schemas/response/exception_list_schema.mock'; -import { createKibanaCoreStartMock } from '../../common/mocks/kibana_core'; import { PersistHookProps } from '../types'; import { ReturnPersistExceptionList, usePersistExceptionList } from './persist_exception_list'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; describe('usePersistExceptionList', () => { const onError = jest.fn(); diff --git a/x-pack/plugins/lists/public/exceptions/hooks/use_api.test.ts b/x-pack/plugins/lists/public/exceptions/hooks/use_api.test.ts index c93155274937..6469dc49c460 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/use_api.test.ts +++ b/x-pack/plugins/lists/public/exceptions/hooks/use_api.test.ts @@ -6,8 +6,8 @@ import { act, renderHook } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../src/core/public/mocks'; import * as api from '../api'; -import { createKibanaCoreStartMock } from '../../common/mocks/kibana_core'; import { getExceptionListSchemaMock } from '../../../common/schemas/response/exception_list_schema.mock'; import { getFoundExceptionListItemSchemaMock } from '../../../common/schemas/response/found_exception_list_item_schema.mock'; import { getExceptionListItemSchemaMock } from '../../../common/schemas/response/exception_list_item_schema.mock'; @@ -16,7 +16,7 @@ import { ApiCallByIdProps, ApiCallByListIdProps } from '../types'; import { ExceptionsApi, useApi } from './use_api'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; describe('useApi', () => { const onErrorMock = jest.fn(); diff --git a/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.test.ts b/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.test.ts index 3a8b1713b901..5c544c7e96e3 100644 --- a/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.test.ts +++ b/x-pack/plugins/lists/public/exceptions/hooks/use_exception_list.test.ts @@ -6,15 +6,15 @@ import { act, renderHook } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../src/core/public/mocks'; import * as api from '../api'; -import { createKibanaCoreStartMock } from '../../common/mocks/kibana_core'; import { getFoundExceptionListItemSchemaMock } from '../../../common/schemas/response/found_exception_list_item_schema.mock'; import { ExceptionListItemSchema } from '../../../common/schemas'; import { UseExceptionListProps, UseExceptionListSuccess } from '../types'; import { ReturnExceptionListAndItems, useExceptionList } from './use_exception_list'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; describe('useExceptionList', () => { const onErrorMock = jest.fn(); diff --git a/x-pack/plugins/maps/public/actions/data_request_actions.ts b/x-pack/plugins/maps/public/actions/data_request_actions.ts index 41d9f3fc13b5..2876f3d668a6 100644 --- a/x-pack/plugins/maps/public/actions/data_request_actions.ts +++ b/x-pack/plugins/maps/public/actions/data_request_actions.ts @@ -15,7 +15,6 @@ import { LAYER_STYLE_TYPE, LAYER_TYPE, SOURCE_DATA_REQUEST_ID } from '../../comm import { getDataFilters, getDataRequestDescriptor, - getFittableLayers, getLayerById, getLayerList, } from '../selectors/map_selectors'; @@ -324,13 +323,16 @@ export function fitToLayerExtent(layerId: string) { export function fitToDataBounds(onNoBounds?: () => void) { return async (dispatch: Dispatch, getState: () => MapStoreState) => { - const layerList = getFittableLayers(getState()); + const layerList = getLayerList(getState()); if (!layerList.length) { return; } const boundsPromises = layerList.map(async (layer: ILayer) => { + if (!(await layer.isFittable())) { + return null; + } return layer.getBounds(getDataRequestContext(dispatch, getState, layer.getId())); }); diff --git a/x-pack/plugins/maps/public/classes/layers/layer.test.ts b/x-pack/plugins/maps/public/classes/layers/layer.test.ts index f25ecd710645..7bc91d71f83e 100644 --- a/x-pack/plugins/maps/public/classes/layers/layer.test.ts +++ b/x-pack/plugins/maps/public/classes/layers/layer.test.ts @@ -21,6 +21,10 @@ jest.mock('uuid/v4', () => { class MockLayer extends AbstractLayer {} class MockSource { + private readonly _fitToBounds: boolean; + constructor({ fitToBounds = true } = {}) { + this._fitToBounds = fitToBounds; + } cloneDescriptor() { return {}; } @@ -28,6 +32,10 @@ class MockSource { getDisplayName() { return 'mySource'; } + + async supportsFitToBounds() { + return this._fitToBounds; + } } class MockStyle {} @@ -126,3 +134,40 @@ describe('cloneDescriptor', () => { }); }); }); + +describe('isFittable', () => { + [ + { + isVisible: true, + fitToBounds: true, + canFit: true, + }, + { + isVisible: false, + fitToBounds: true, + canFit: false, + }, + { + isVisible: true, + fitToBounds: false, + canFit: false, + }, + { + isVisible: false, + fitToBounds: false, + canFit: false, + }, + ].forEach((test) => { + it(`Should take into account layer visibility and bounds-retrieval: ${JSON.stringify( + test + )}`, async () => { + const layerDescriptor = AbstractLayer.createDescriptor({ visible: test.isVisible }); + const layer = new MockLayer({ + layerDescriptor, + source: (new MockSource({ fitToBounds: test.fitToBounds }) as unknown) as ISource, + style: (new MockStyle() as unknown) as IStyle, + }); + expect(await layer.isFittable()).toBe(test.canFit); + }); + }); +}); diff --git a/x-pack/plugins/maps/public/classes/layers/layer.tsx b/x-pack/plugins/maps/public/classes/layers/layer.tsx index 424100c5a7e3..8026f48fe609 100644 --- a/x-pack/plugins/maps/public/classes/layers/layer.tsx +++ b/x-pack/plugins/maps/public/classes/layers/layer.tsx @@ -90,6 +90,7 @@ export interface ILayer { supportsLabelsOnTop: () => boolean; showJoinEditor(): boolean; getJoinsDisabledReason(): string | null; + isFittable(): Promise; } export type Footnote = { icon: ReactElement; @@ -233,6 +234,10 @@ export class AbstractLayer implements ILayer { return await this.getSource().supportsFitToBounds(); } + async isFittable(): Promise { + return (await this.supportsFitToBounds()) && this.isVisible(); + } + async getDisplayName(source?: ISource): Promise { if (this._descriptor.label) { return this._descriptor.label; diff --git a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts index e6cb212dadda..ad4479d3a324 100644 --- a/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts +++ b/x-pack/plugins/maps/public/classes/layers/vector_layer/vector_layer.d.ts @@ -83,4 +83,5 @@ export class VectorLayer extends AbstractLayer implements IVectorLayer { getFeatureById(id: string | number): Feature | null; getPropertiesForTooltip(properties: GeoJsonProperties): Promise; hasJoins(): boolean; + isFittable(): Promise; } diff --git a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/fit_to_data.tsx b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/fit_to_data.tsx index ca75060c4f8d..3f56d8d50b0f 100644 --- a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/fit_to_data.tsx +++ b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/fit_to_data.tsx @@ -15,24 +15,59 @@ interface Props { fitToBounds: () => void; } -export const FitToData: React.FunctionComponent = ({ layerList, fitToBounds }: Props) => { - if (layerList.length === 0) { - return null; +interface State { + canFit: boolean; +} + +export class FitToData extends React.Component { + _isMounted: boolean = false; + + state = { canFit: false }; + + componentDidMount(): void { + this._isMounted = true; + this._loadCanFit(); } - return ( - - ); -}; + componentWillUnmount(): void { + this._isMounted = false; + } + + componentDidUpdate(): void { + this._loadCanFit(); + } + + async _loadCanFit() { + const promises = this.props.layerList.map(async (layer) => { + return await layer.isFittable(); + }); + const canFit = (await Promise.all(promises)).some((isFittable) => isFittable); + if (this._isMounted && this.state.canFit !== canFit) { + this.setState({ + canFit, + }); + } + } + + render() { + if (!this.state.canFit) { + return null; + } + + return ( + + ); + } +} diff --git a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/index.ts b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/index.ts index 51bf0a519e38..8790f6f35c57 100644 --- a/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/index.ts +++ b/x-pack/plugins/maps/public/connected_components/toolbar_overlay/fit_to_data/index.ts @@ -8,12 +8,12 @@ import { AnyAction, Dispatch } from 'redux'; import { connect } from 'react-redux'; import { MapStoreState } from '../../../reducers/store'; import { fitToDataBounds } from '../../../actions'; -import { getFittableLayers } from '../../../selectors/map_selectors'; +import { getLayerList } from '../../../selectors/map_selectors'; import { FitToData } from './fit_to_data'; function mapStateToProps(state: MapStoreState) { return { - layerList: getFittableLayers(state), + layerList: getLayerList(state), }; } diff --git a/x-pack/plugins/maps/public/selectors/map_selectors.ts b/x-pack/plugins/maps/public/selectors/map_selectors.ts index d48ee2402756..03e0f753812c 100644 --- a/x-pack/plugins/maps/public/selectors/map_selectors.ts +++ b/x-pack/plugins/maps/public/selectors/map_selectors.ts @@ -25,7 +25,6 @@ import { InnerJoin } from '../classes/joins/inner_join'; import { getSourceByType } from '../classes/sources/source_registry'; import { GeojsonFileSource } from '../classes/sources/geojson_file_source'; import { - LAYER_TYPE, SOURCE_DATA_REQUEST_ID, STYLE_TYPE, VECTOR_STYLES, @@ -307,19 +306,6 @@ export function getLayerById(layerId: string | null, state: MapStoreState): ILay }); } -export const getFittableLayers = createSelector(getLayerList, (layerList) => { - return layerList.filter((layer) => { - // These are the only layer-types that implement bounding-box retrieval reliably - // This will _not_ work if Maps will allow register custom layer types - const isFittable = - layer.getType() === LAYER_TYPE.VECTOR || - layer.getType() === LAYER_TYPE.BLENDED_VECTOR || - layer.getType() === LAYER_TYPE.HEATMAP; - - return isFittable && layer.isVisible(); - }); -}); - export const getHiddenLayerIds = createSelector(getLayerListRaw, (layers) => layers.filter((layer) => !layer.visible).map((layer) => layer.id) ); diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/analytics_list.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/analytics_list.tsx index 81494a43193d..c4c7a8a4ca11 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/analytics_list.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/analytics_list.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { FC, useState, useEffect } from 'react'; +import React, { FC, useCallback, useState, useEffect } from 'react'; import { i18n } from '@kbn/i18n'; @@ -119,11 +119,13 @@ export const DataFrameAnalyticsList: FC = ({ } }, [selectedIdFromUrlInitialized, analytics]); + const getAnalyticsCallback = useCallback(() => getAnalytics(true), []); + // Subscribe to the refresh observable to trigger reloading the analytics list. useRefreshAnalyticsList( { isLoading: setIsLoading, - onRefresh: () => getAnalytics(true), + onRefresh: getAnalyticsCallback, }, isManagementTable ); diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx index 0dd9eba172e1..942e335526d6 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { FC, useState } from 'react'; +import React, { FC, useState, useEffect, useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { ml } from '../../../../../services/ml_api_service'; import { useRefreshAnalyticsList } from '../../../../common'; @@ -20,45 +20,34 @@ export const ExpandedRowMessagesPane: FC = ({ analyticsId }) => { const [isLoading, setIsLoading] = useState(false); const [errorMessage, setErrorMessage] = useState(''); - const getMessagesFactory = () => { - let concurrentLoads = 0; - return async function getMessages() { - try { - concurrentLoads++; - - if (concurrentLoads > 1) { - return; - } - - setIsLoading(true); - const messagesResp = await ml.dataFrameAnalytics.getAnalyticsAuditMessages(analyticsId); - setIsLoading(false); - setMessages(messagesResp); - - concurrentLoads--; - - if (concurrentLoads > 0) { - concurrentLoads = 0; - getMessages(); - } - } catch (error) { - setIsLoading(false); - setErrorMessage( - i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', { - defaultMessage: 'Messages could not be loaded', - }) - ); - } - }; - }; - useRefreshAnalyticsList({ onRefresh: getMessagesFactory() }); + const getMessages = useCallback(async () => { + try { + setIsLoading(true); + const messagesResp = await ml.dataFrameAnalytics.getAnalyticsAuditMessages(analyticsId); + setIsLoading(false); + setMessages(messagesResp); + } catch (error) { + setIsLoading(false); + setErrorMessage( + i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', { + defaultMessage: 'Messages could not be loaded', + }) + ); + } + }, []); + + useEffect(() => { + getMessages(); + }, []); + + useRefreshAnalyticsList({ onRefresh: getMessages }); return ( ); }; diff --git a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/actions.tsx b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/actions.tsx index 081101e24199..c4508a8c19c5 100644 --- a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/actions.tsx +++ b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/actions.tsx @@ -14,6 +14,7 @@ import { getResultsUrl, DataFrameAnalyticsListRow, } from '../../../data_frame_analytics/pages/analytics_management/components/analytics_list/common'; +import { getViewLinkStatus } from '../../../data_frame_analytics/pages/analytics_management/components/action_view/get_view_link_status'; interface Props { item: DataFrameAnalyticsListRow; @@ -27,23 +28,28 @@ export const ViewLink: FC = ({ item }) => { navigateToPath(getResultsUrl(item.id, analysisType)); }, []); - const openJobsInAnomalyExplorerText = i18n.translate( + const { disabled, tooltipContent } = getViewLinkStatus(item); + + const viewJobResultsButtonText = i18n.translate( 'xpack.ml.overview.analytics.resultActions.openJobText', { defaultMessage: 'View job results', } ); + const tooltipText = disabled === false ? viewJobResultsButtonText : tooltipContent; + return ( - + {i18n.translate('xpack.ml.overview.analytics.viewActionName', { defaultMessage: 'View', diff --git a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts index 0a6473b83386..7340b1c021eb 100644 --- a/x-pack/plugins/security_solution/common/endpoint/generate_data.ts +++ b/x-pack/plugins/security_solution/common/endpoint/generate_data.ts @@ -1158,6 +1158,9 @@ export class EndpointDocGenerator { version: '0.5.0', internal: false, removable: false, + install_version: '0.5.0', + install_status: 'installed', + install_started_at: '2020-06-24T14:41:23.098Z', }, references: [], updated_at: '2020-06-24T14:41:23.098Z', diff --git a/x-pack/plugins/security_solution/cypress/integration/timeline_local_storage.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timeline_local_storage.spec.ts index 383ebe222058..c2ff2c58687f 100644 --- a/x-pack/plugins/security_solution/cypress/integration/timeline_local_storage.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/timeline_local_storage.spec.ts @@ -13,7 +13,8 @@ import { TABLE_COLUMN_EVENTS_MESSAGE } from '../screens/hosts/external_events'; import { waitsForEventsToBeLoaded, openEventsViewerFieldsBrowser } from '../tasks/hosts/events'; import { removeColumn, resetFields } from '../tasks/timeline'; -describe('persistent timeline', () => { +// FLAKY: https://github.com/elastic/kibana/issues/75794 +describe.skip('persistent timeline', () => { before(() => { loginAndWaitForPage(HOSTS_URL); openEvents(); diff --git a/x-pack/plugins/security_solution/cypress/integration/url_compatibility.spec.ts b/x-pack/plugins/security_solution/cypress/integration/url_compatibility.spec.ts index 7146cf70dc8c..d55a8faae021 100644 --- a/x-pack/plugins/security_solution/cypress/integration/url_compatibility.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/url_compatibility.spec.ts @@ -18,6 +18,7 @@ const ABSOLUTE_DATE = { startTime: '2019-08-01T20:03:29.186Z', }; +// FLAKY: https://github.com/elastic/kibana/issues/75697 describe.skip('URL compatibility', () => { it('Redirects to Detection alerts from old Detections URL', () => { loginAndWaitForPage(DETECTIONS); diff --git a/x-pack/plugins/security_solution/cypress/integration/url_state.spec.ts b/x-pack/plugins/security_solution/cypress/integration/url_state.spec.ts index cdcdde252d6d..6d605e1d577a 100644 --- a/x-pack/plugins/security_solution/cypress/integration/url_state.spec.ts +++ b/x-pack/plugins/security_solution/cypress/integration/url_state.spec.ts @@ -36,6 +36,7 @@ import { addNameToTimeline, closeTimeline, executeTimelineKQL, + waitForTimelineChanges, } from '../tasks/timeline'; import { HOSTS_URL } from '../urls/navigation'; @@ -217,7 +218,7 @@ describe('url state', () => { cy.get(KQL_INPUT).invoke('text').should('eq', 'source.ip: "10.142.0.9"'); }); - it.skip('sets and reads the url state for timeline by id', () => { + it('sets and reads the url state for timeline by id', () => { loginAndWaitForPage(HOSTS_URL); openTimeline(); executeTimelineKQL('host.name: *'); @@ -229,20 +230,24 @@ describe('url state', () => { cy.wrap(intCount).should('be.above', 0); }); + cy.server(); + cy.route('PATCH', '**/api/timeline').as('timeline'); + const timelineName = 'Security'; + const timelineDescription = 'This is the best timeline of the world'; addNameToTimeline(timelineName); - addDescriptionToTimeline('This is the best timeline of the world'); - cy.wait(5000); - - cy.url({ timeout: 30000 }).should('match', /\w*-\w*-\w*-\w*-\w*/); - cy.url().then((url) => { - const matched = url.match(/\w*-\w*-\w*-\w*-\w*/); - const newTimelineId = matched && matched.length > 0 ? matched[0] : 'null'; - expect(matched).to.have.lengthOf(1); + waitForTimelineChanges(); + addDescriptionToTimeline(timelineDescription); + waitForTimelineChanges(); + + cy.wait('@timeline').then((response) => { closeTimeline(); + cy.wrap(response.status).should('eql', 200); + const JsonResponse = JSON.parse(response.xhr.responseText); + const timelineId = JsonResponse.data.persistTimeline.timeline.savedObjectId; cy.visit('/app/home'); - cy.visit(`/app/security/timelines?timeline=(id:%27${newTimelineId}%27,isOpen:!t)`); - cy.contains('a', 'Security'); + cy.visit(`/app/security/timelines?timeline=(id:'${timelineId}',isOpen:!t)`); + cy.get(DATE_PICKER_APPLY_BUTTON_TIMELINE).should('exist'); cy.get(DATE_PICKER_APPLY_BUTTON_TIMELINE).invoke('text').should('not.equal', 'Updating'); cy.get(TIMELINE_TITLE).should('be.visible'); cy.get(TIMELINE_TITLE).should('have.attr', 'value', timelineName); diff --git a/x-pack/plugins/security_solution/cypress/screens/timeline.ts b/x-pack/plugins/security_solution/cypress/screens/timeline.ts index 135dea35ca0d..26203a8ca3b8 100644 --- a/x-pack/plugins/security_solution/cypress/screens/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/screens/timeline.ts @@ -39,6 +39,8 @@ export const TIMELINE = (id: string) => { return `[data-test-subj="title-${id}"]`; }; +export const TIMELINE_CHANGES_IN_PROGRESS = '[data-test-subj="timeline"] .euiProgress'; + export const TIMELINE_COLUMN_SPINNER = '[data-test-subj="timeline-loading-spinner"]'; export const TIMELINE_DATA_PROVIDERS = '[data-test-subj="dataProviders"]'; diff --git a/x-pack/plugins/security_solution/cypress/tasks/timeline.ts b/x-pack/plugins/security_solution/cypress/tasks/timeline.ts index 9eeb9fc8bdf8..08624df06e09 100644 --- a/x-pack/plugins/security_solution/cypress/tasks/timeline.ts +++ b/x-pack/plugins/security_solution/cypress/tasks/timeline.ts @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { DATE_PICKER_APPLY_BUTTON_TIMELINE } from '../screens/date_picker'; - import { CLOSE_TIMELINE_BTN, CREATE_NEW_TIMELINE, @@ -16,6 +14,7 @@ import { PIN_EVENT, SEARCH_OR_FILTER_CONTAINER, SERVER_SIDE_EVENT_COUNT, + TIMELINE_CHANGES_IN_PROGRESS, TIMELINE_DESCRIPTION, TIMELINE_FIELDS_BUTTON, TIMELINE_INSPECT_BUTTON, @@ -33,7 +32,7 @@ export const hostExistsQuery = 'host.name: *'; export const addDescriptionToTimeline = (description: string) => { cy.get(TIMELINE_DESCRIPTION).type(`${description}{enter}`); - cy.get(DATE_PICKER_APPLY_BUTTON_TIMELINE).click().invoke('text').should('not.equal', 'Updating'); + cy.get(TIMELINE_DESCRIPTION).should('have.attr', 'value', description); }; export const addNameToTimeline = (name: string) => { @@ -122,3 +121,8 @@ export const removeColumn = (column: number) => { export const resetFields = () => { cy.get(RESET_FIELDS).click({ force: true }); }; + +export const waitForTimelineChanges = () => { + cy.get(TIMELINE_CHANGES_IN_PROGRESS).should('exist'); + cy.get(TIMELINE_CHANGES_IN_PROGRESS).should('not.exist'); +}; diff --git a/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx index f5ed151ebac3..e6e082321419 100644 --- a/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/all_cases/index.test.tsx @@ -15,7 +15,6 @@ import { useGetCasesMockState } from '../../containers/mock'; import * as i18n from './translations'; import { useKibana } from '../../../common/lib/kibana'; -import { createUseKibanaMock } from '../../../common/mock/kibana_react'; import { getEmptyTagValue } from '../../../common/components/empty_value'; import { useDeleteCases } from '../../containers/use_delete_cases'; import { useGetCases } from '../../containers/use_get_cases'; @@ -28,7 +27,7 @@ jest.mock('../../containers/use_delete_cases'); jest.mock('../../containers/use_get_cases'); jest.mock('../../containers/use_get_cases_status'); -const useKibanaMock = useKibana as jest.Mock; +const useKibanaMock = useKibana as jest.Mocked; const useDeleteCasesMock = useDeleteCases as jest.Mock; const useGetCasesMock = useGetCases as jest.Mock; const useGetCasesStatusMock = useGetCasesStatus as jest.Mock; @@ -97,23 +96,16 @@ describe('AllCases', () => { }); /* eslint-enable no-console */ beforeEach(() => { - jest.resetAllMocks(); + jest.clearAllMocks(); navigateToApp = jest.fn(); - const kibanaMock = createUseKibanaMock()(); - useKibanaMock.mockReturnValue({ - ...kibanaMock, - services: { - application: { - navigateToApp, - }, - }, - }); + useKibanaMock().services.application.navigateToApp = navigateToApp; useUpdateCasesMock.mockReturnValue(defaultUpdateCases); useGetCasesMock.mockReturnValue(defaultGetCases); useDeleteCasesMock.mockReturnValue(defaultDeleteCases); useGetCasesStatusMock.mockReturnValue(defaultCasesStatus); moment.tz.setDefault('UTC'); }); + it('should render AllCases', () => { const wrapper = mount( diff --git a/x-pack/plugins/security_solution/public/cases/components/configure_cases/__mock__/index.tsx b/x-pack/plugins/security_solution/public/cases/components/configure_cases/__mock__/index.tsx index 23c76953a6a0..08303ddc9397 100644 --- a/x-pack/plugins/security_solution/public/cases/components/configure_cases/__mock__/index.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/configure_cases/__mock__/index.tsx @@ -8,10 +8,7 @@ import { Connector } from '../../../containers/configure/types'; import { ReturnConnectors } from '../../../containers/configure/use_connectors'; import { connectorsMock } from '../../../containers/configure/mock'; import { ReturnUseCaseConfigure } from '../../../containers/configure/use_configure'; -import { createUseKibanaMock } from '../../../../common/mock/kibana_react'; export { mapping } from '../../../containers/configure/mock'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { actionTypeRegistryMock } from '../../../../../../triggers_actions_ui/public/application/action_type_registry.mock'; export const connectors: Connector[] = connectorsMock; @@ -46,10 +43,3 @@ export const useConnectorsResponse: ReturnConnectors = { connectors, refetchConnectors: jest.fn(), }; - -export const kibanaMockImplementationArgs = { - services: { - ...createUseKibanaMock()().services, - triggers_actions_ui: { actionTypeRegistry: actionTypeRegistryMock.create() }, - }, -}; diff --git a/x-pack/plugins/security_solution/public/cases/components/configure_cases/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/configure_cases/index.test.tsx index 7974116f4dc4..3c17a9191d20 100644 --- a/x-pack/plugins/security_solution/public/cases/components/configure_cases/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/configure_cases/index.test.tsx @@ -15,38 +15,39 @@ import { ActionsConnectorsContextProvider, ConnectorAddFlyout, ConnectorEditFlyout, + TriggersAndActionsUIPublicPluginStart, } from '../../../../../triggers_actions_ui/public'; +import { actionTypeRegistryMock } from '../../../../../triggers_actions_ui/public/application/action_type_registry.mock'; import { useKibana } from '../../../common/lib/kibana'; import { useConnectors } from '../../containers/configure/use_connectors'; import { useCaseConfigure } from '../../containers/configure/use_configure'; import { useGetUrlSearch } from '../../../common/components/navigation/use_get_url_search'; -import { - connectors, - searchURL, - useCaseConfigureResponse, - useConnectorsResponse, - kibanaMockImplementationArgs, -} from './__mock__'; +import { connectors, searchURL, useCaseConfigureResponse, useConnectorsResponse } from './__mock__'; jest.mock('../../../common/lib/kibana'); jest.mock('../../containers/configure/use_connectors'); jest.mock('../../containers/configure/use_configure'); jest.mock('../../../common/components/navigation/use_get_url_search'); -const useKibanaMock = useKibana as jest.Mock; +const useKibanaMock = useKibana as jest.Mocked; const useConnectorsMock = useConnectors as jest.Mock; const useCaseConfigureMock = useCaseConfigure as jest.Mock; const useGetUrlSearchMock = useGetUrlSearch as jest.Mock; + describe('ConfigureCases', () => { + beforeEach(() => { + useKibanaMock().services.triggers_actions_ui = ({ + actionTypeRegistry: actionTypeRegistryMock.create(), + } as unknown) as TriggersAndActionsUIPublicPluginStart; + }); + describe('rendering', () => { let wrapper: ReactWrapper; beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => useCaseConfigureResponse); useConnectorsMock.mockImplementation(() => ({ ...useConnectorsResponse, connectors: [] })); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); @@ -84,8 +85,8 @@ describe('ConfigureCases', () => { describe('Unhappy path', () => { let wrapper: ReactWrapper; + beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, closureType: 'close-by-user', @@ -98,7 +99,6 @@ describe('ConfigureCases', () => { }, })); useConnectorsMock.mockImplementation(() => ({ ...useConnectorsResponse, connectors: [] })); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); }); @@ -122,7 +122,6 @@ describe('ConfigureCases', () => { let wrapper: ReactWrapper; beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, mapping: connectors[0].config.incidentConfiguration.mapping, @@ -136,7 +135,6 @@ describe('ConfigureCases', () => { }, })); useConnectorsMock.mockImplementation(() => useConnectorsResponse); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); @@ -211,9 +209,6 @@ describe('ConfigureCases', () => { let wrapper: ReactWrapper; beforeEach(() => { - jest.resetAllMocks(); - jest.restoreAllMocks(); - jest.clearAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, mapping: connectors[1].config.incidentConfiguration.mapping, @@ -230,7 +225,6 @@ describe('ConfigureCases', () => { ...useConnectorsResponse, loading: true, })); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); }); @@ -262,7 +256,6 @@ describe('ConfigureCases', () => { let wrapper: ReactWrapper; beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, connectorId: 'servicenow-1', @@ -270,7 +263,6 @@ describe('ConfigureCases', () => { })); useConnectorsMock.mockImplementation(() => useConnectorsResponse); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); }); @@ -305,7 +297,6 @@ describe('ConfigureCases', () => { let wrapper: ReactWrapper; beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, loading: true, @@ -313,7 +304,6 @@ describe('ConfigureCases', () => { useConnectorsMock.mockImplementation(() => ({ ...useConnectorsResponse, })); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); }); @@ -329,10 +319,10 @@ describe('ConfigureCases', () => { describe('connectors', () => { let wrapper: ReactWrapper; - const persistCaseConfigure = jest.fn(); + let persistCaseConfigure: jest.Mock; beforeEach(() => { - jest.resetAllMocks(); + persistCaseConfigure = jest.fn(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, mapping: connectors[0].config.incidentConfiguration.mapping, @@ -347,7 +337,6 @@ describe('ConfigureCases', () => { persistCaseConfigure, })); useConnectorsMock.mockImplementation(() => useConnectorsResponse); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); @@ -396,10 +385,10 @@ describe('ConfigureCases', () => { describe('closure options', () => { let wrapper: ReactWrapper; - const persistCaseConfigure = jest.fn(); + let persistCaseConfigure: jest.Mock; beforeEach(() => { - jest.resetAllMocks(); + persistCaseConfigure = jest.fn(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, mapping: connectors[0].config.incidentConfiguration.mapping, @@ -414,7 +403,6 @@ describe('closure options', () => { persistCaseConfigure, })); useConnectorsMock.mockImplementation(() => useConnectorsResponse); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); wrapper = mount(, { wrappingComponent: TestProviders }); @@ -435,7 +423,6 @@ describe('closure options', () => { describe('user interactions', () => { beforeEach(() => { - jest.resetAllMocks(); useCaseConfigureMock.mockImplementation(() => ({ ...useCaseConfigureResponse, mapping: connectors[1].config.incidentConfiguration.mapping, @@ -449,7 +436,6 @@ describe('user interactions', () => { }, })); useConnectorsMock.mockImplementation(() => useConnectorsResponse); - useKibanaMock.mockImplementation(() => kibanaMockImplementationArgs); useGetUrlSearchMock.mockImplementation(() => searchURL); }); diff --git a/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx b/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx index b5bf68cbf6dc..3b203e81cd07 100644 --- a/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/use_all_cases_modal/index.test.tsx @@ -14,26 +14,17 @@ import '../../../common/mock/match_media'; import { TimelineId } from '../../../../common/types/timeline'; import { useAllCasesModal, UseAllCasesModalProps, UseAllCasesModalReturnedValues } from '.'; import { TestProviders } from '../../../common/mock'; -import { createUseKibanaMock } from '../../../common/mock/kibana_react'; jest.mock('../../../common/lib/kibana'); -const useKibanaMock = useKibana as jest.Mock; +const useKibanaMock = useKibana as jest.Mocked; describe('useAllCasesModal', () => { - const navigateToApp = jest.fn(() => Promise.resolve()); + let navigateToApp: jest.Mock; beforeEach(() => { - jest.clearAllMocks(); - const kibanaMock = createUseKibanaMock()(); - useKibanaMock.mockImplementation(() => ({ - ...kibanaMock, - services: { - application: { - navigateToApp, - }, - }, - })); + navigateToApp = jest.fn(); + useKibanaMock().services.application.navigateToApp = navigateToApp; }); it('init', async () => { diff --git a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/draggable_wrapper_hover_content.test.tsx b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/draggable_wrapper_hover_content.test.tsx index 8e76a88572e4..b53da42da55f 100644 --- a/x-pack/plugins/security_solution/public/common/components/drag_and_drop/draggable_wrapper_hover_content.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/drag_and_drop/draggable_wrapper_hover_content.test.tsx @@ -7,12 +7,12 @@ import { mount, ReactWrapper } from 'enzyme'; import React from 'react'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; import { useWithSource } from '../../containers/source'; import { mockBrowserFields } from '../../containers/source/mock'; import '../../mock/match_media'; import { useKibana } from '../../lib/kibana'; import { TestProviders } from '../../mock'; -import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { FilterManager } from '../../../../../../../src/plugins/data/public'; import { useAddToTimeline } from '../../hooks/use_add_to_timeline'; @@ -60,7 +60,7 @@ jest.mock('../../../timelines/components/manage_timeline', () => { }; }); -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; const timelineId = TimelineId.active; const field = 'process.name'; const value = 'nice'; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.test.tsx index 2b713636862b..cef92ce2a781 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.test.tsx @@ -11,14 +11,13 @@ import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; import { act } from 'react-dom/test-utils'; import { AddExceptionModal } from './'; -import { useKibana, useCurrentUser } from '../../../../common/lib/kibana'; +import { useCurrentUser } from '../../../../common/lib/kibana'; import { getExceptionListSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_schema.mock'; import { useFetchIndexPatterns } from '../../../../detections/containers/detection_engine/rules'; import { stubIndexPattern } from 'src/plugins/data/common/index_patterns/index_pattern.stub'; import { useAddOrUpdateException } from '../use_add_exception'; import { useFetchOrCreateRuleExceptionList } from '../use_fetch_or_create_rule_exception_list'; import { useSignalIndex } from '../../../../detections/containers/detection_engine/alerts/use_signal_index'; -import { createUseKibanaMock } from '../../../mock/kibana_react'; import { TimelineNonEcsData, Ecs } from '../../../../graphql/types'; import * as builder from '../builder'; import * as helpers from '../helpers'; @@ -33,8 +32,6 @@ jest.mock('../use_add_exception'); jest.mock('../use_fetch_or_create_rule_exception_list'); jest.mock('../builder'); -const useKibanaMock = useKibana as jest.Mock; - describe('When the add exception modal is opened', () => { const ruleName = 'test rule'; let defaultEndpointItems: jest.SpyInstance { .spyOn(builder, 'ExceptionBuilderComponent') .mockReturnValue(<>); - const kibanaMock = createUseKibanaMock()(); - useKibanaMock.mockImplementation(() => ({ - ...kibanaMock, - })); (useAddOrUpdateException as jest.Mock).mockImplementation(() => [ { isLoading: false }, jest.fn(), diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.test.tsx index 8ad80eba569c..6ff218ca0605 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.test.tsx @@ -11,7 +11,7 @@ import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; import { act } from 'react-dom/test-utils'; import { EditExceptionModal } from './'; -import { useKibana, useCurrentUser } from '../../../../common/lib/kibana'; +import { useCurrentUser } from '../../../../common/lib/kibana'; import { useFetchIndexPatterns } from '../../../../detections/containers/detection_engine/rules'; import { stubIndexPattern, @@ -19,7 +19,6 @@ import { } from 'src/plugins/data/common/index_patterns/index_pattern.stub'; import { useAddOrUpdateException } from '../use_add_exception'; import { useSignalIndex } from '../../../../detections/containers/detection_engine/alerts/use_signal_index'; -import { createUseKibanaMock } from '../../../mock/kibana_react'; import { getExceptionListItemSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_item_schema.mock'; import { EntriesArray } from '../../../../../../lists/common/schemas/types'; import * as builder from '../builder'; @@ -31,8 +30,6 @@ jest.mock('../use_fetch_or_create_rule_exception_list'); jest.mock('../../../../detections/containers/detection_engine/alerts/use_signal_index'); jest.mock('../builder'); -const useKibanaMock = useKibana as jest.Mock; - describe('When the edit exception modal is opened', () => { const ruleName = 'test rule'; @@ -45,10 +42,6 @@ describe('When the edit exception modal is opened', () => { .spyOn(builder, 'ExceptionBuilderComponent') .mockReturnValue(<>); - const kibanaMock = createUseKibanaMock()(); - useKibanaMock.mockImplementation(() => ({ - ...kibanaMock, - })); (useSignalIndex as jest.Mock).mockReturnValue({ loading: false, signalIndexName: 'test-signal', diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx index cb1a80abedb2..6611ee2385d1 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx @@ -5,6 +5,7 @@ */ import { act, renderHook, RenderHookResult } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; import { KibanaServices } from '../../../common/lib/kibana'; import * as alertsApi from '../../../detections/containers/detection_engine/alerts/api'; @@ -14,7 +15,6 @@ import * as buildAlertStatusFilterHelper from '../../../detections/components/al import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock'; import { getCreateExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/request/create_exception_list_item_schema.mock'; import { getUpdateExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/request/update_exception_list_item_schema.mock'; -import { createKibanaCoreStartMock } from '../../../common/mock/kibana_core'; import { ExceptionListItemSchema, CreateExceptionListItemSchema, @@ -27,7 +27,7 @@ import { AddOrUpdateExceptionItemsFunc, } from './use_add_exception'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; const mockKibanaServices = KibanaServices.get as jest.Mock; jest.mock('../../../common/lib/kibana'); diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx index 6dbf5922e0a9..39d88bd8e472 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx @@ -6,11 +6,11 @@ import { act, renderHook, RenderHookResult } from '@testing-library/react-hooks'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; import * as rulesApi from '../../../detections/containers/detection_engine/rules/api'; import * as listsApi from '../../../../../lists/public/exceptions/api'; import { getExceptionListSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_schema.mock'; import { savedRuleMock } from '../../../detections/containers/detection_engine/rules/mock'; -import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { ExceptionListType } from '../../../lists_plugin_deps'; import { ListArray } from '../../../../common/detection_engine/schemas/types'; import { getListArrayMock } from '../../../../common/detection_engine/schemas/types/lists.mock'; @@ -20,7 +20,7 @@ import { ReturnUseFetchOrCreateRuleExceptionList, } from './use_fetch_or_create_rule_exception_list'; -const mockKibanaHttpService = createKibanaCoreStartMock().http; +const mockKibanaHttpService = coreMock.createStart().http; jest.mock('../../../detections/containers/detection_engine/rules/api'); describe('useFetchOrCreateRuleExceptionList', () => { diff --git a/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_installed_security_jobs.ts b/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_installed_security_jobs.ts index a9a728f81cc6..dde5eebe624b 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_installed_security_jobs.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml/hooks/use_installed_security_jobs.ts @@ -29,6 +29,9 @@ export interface UseInstalledSecurityJobsReturn { * Use the corresponding helper functions to filter the job list as * necessary (running jobs, etc). * + * NOTE: If you need to include jobs that are not currently installed, try the + * {@link useInstalledSecurityJobs} hook. + * */ export const useInstalledSecurityJobs = (): UseInstalledSecurityJobsReturn => { const [jobs, setJobs] = useState([]); diff --git a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_security_jobs.ts b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_security_jobs.ts index e8809e8366ee..2ba5cb84d272 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_security_jobs.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml_popover/hooks/use_security_jobs.ts @@ -32,6 +32,7 @@ export interface UseSecurityJobsReturn { * list as necessary. E.g. installed jobs, running jobs, etc. * * NOTE: If the user is not an ml admin, jobs will be empty and isMlAdmin will be false. + * If you only need installed jobs, try the {@link useInstalledSecurityJobs} hook. * * @param refetchData */ @@ -39,7 +40,7 @@ export const useSecurityJobs = (refetchData: boolean): UseSecurityJobsReturn => const [jobs, setJobs] = useState([]); const [loading, setLoading] = useState(true); const mlCapabilities = useMlCapabilities(); - const [siemDefaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); + const [securitySolutionDefaultIndex] = useUiSetting$(DEFAULT_INDEX_KEY); const http = useHttp(); const { addError } = useAppToasts(); @@ -54,12 +55,12 @@ export const useSecurityJobs = (refetchData: boolean): UseSecurityJobsReturn => async function fetchSecurityJobIdsFromGroupsData() { if (isMlAdmin && isLicensed) { try { - // Batch fetch all installed jobs, ML modules, and check which modules are compatible with siemDefaultIndex + // Batch fetch all installed jobs, ML modules, and check which modules are compatible with securitySolutionDefaultIndex const [jobSummaryData, modulesData, compatibleModules] = await Promise.all([ getJobsSummary({ http, signal: abortCtrl.signal }), getModules({ signal: abortCtrl.signal }), checkRecognizer({ - indexPatternName: siemDefaultIndex, + indexPatternName: securitySolutionDefaultIndex, signal: abortCtrl.signal, }), ]); @@ -89,7 +90,7 @@ export const useSecurityJobs = (refetchData: boolean): UseSecurityJobsReturn => isSubscribed = false; abortCtrl.abort(); }; - }, [refetchData, isMlAdmin, isLicensed, siemDefaultIndex, addError, http]); + }, [refetchData, isMlAdmin, isLicensed, securitySolutionDefaultIndex, addError, http]); return { isLicensed, isMlAdmin, jobs, loading }; }; diff --git a/x-pack/plugins/security_solution/public/common/components/ml_popover/types.ts b/x-pack/plugins/security_solution/public/common/components/ml_popover/types.ts index c839f5110fe7..7120fcf4a9e5 100644 --- a/x-pack/plugins/security_solution/public/common/components/ml_popover/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/ml_popover/types.ts @@ -111,7 +111,7 @@ export interface CustomURL { } /** - * Representation of an ML Job as used by the SIEM App -- a composition of ModuleJob and MlSummaryJob + * Representation of an ML Job as used by the Security Solution App -- a composition of ModuleJob and MlSummaryJob * that includes necessary metadata like moduleName, defaultIndexPattern, etc. */ export interface SecurityJob extends MlSummaryJob { diff --git a/x-pack/plugins/security_solution/public/common/components/query_bar/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/query_bar/index.test.tsx index aac83ce650d8..aa61688f1f98 100644 --- a/x-pack/plugins/security_solution/public/common/components/query_bar/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/query_bar/index.test.tsx @@ -7,14 +7,13 @@ import { mount } from 'enzyme'; import React from 'react'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../../common/constants'; import { TestProviders, mockIndexPattern } from '../../mock'; -import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { FilterManager, SearchBar } from '../../../../../../../src/plugins/data/public'; import { QueryBar, QueryBarComponentProps } from '.'; -import { createKibanaContextProviderMock } from '../../mock/kibana_react'; -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; describe('QueryBar ', () => { // We are doing that because we need to wrapped this component with redux @@ -187,13 +186,9 @@ describe('QueryBar ', () => { describe('state', () => { test('clears draftQuery when filterQueryDraft has been cleared', () => { - const KibanaWithStorageProvider = createKibanaContextProviderMock(); - const Proxy = (props: QueryBarComponentProps) => ( - - - + ); @@ -231,13 +226,9 @@ describe('QueryBar ', () => { describe('#onQueryChange', () => { test(' is the only reference that changed when filterQueryDraft props get updated', () => { - const KibanaWithStorageProvider = createKibanaContextProviderMock(); - const Proxy = (props: QueryBarComponentProps) => ( - - - + ); @@ -382,24 +373,9 @@ describe('QueryBar ', () => { describe('SavedQueryManagementComponent state', () => { test('popover should hidden when "Save current query" button was clicked', () => { - const KibanaWithStorageProvider = createKibanaContextProviderMock(); - const Proxy = (props: QueryBarComponentProps) => ( - - - + ); diff --git a/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx new file mode 100644 index 000000000000..356456c77779 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/components/search_bar/index.test.tsx @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; + +import { InputsModelId } from '../../store/inputs/constants'; +import { SearchBarComponent } from '.'; +import { TestProviders } from '../../mock'; + +jest.mock('../../lib/kibana'); + +describe('SearchBarComponent', () => { + const props = { + id: 'global' as InputsModelId, + indexPattern: { + fields: [], + title: '', + }, + updateSearch: jest.fn(), + setSavedQuery: jest.fn(), + setSearchBarFilter: jest.fn(), + end: '', + start: '', + toStr: '', + fromStr: '', + isLoading: false, + filterQuery: { + query: '', + language: '', + }, + queries: [], + savedQuery: undefined, + }; + + it('calls setSearchBarFilter on mount', () => { + mount(, { wrappingComponent: TestProviders }); + + expect(props.setSearchBarFilter).toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx b/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx index de60bca73ced..2dc44fd48e66 100644 --- a/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/search_bar/index.tsx @@ -33,7 +33,6 @@ import { filterQuerySelector, fromStrSelector, isLoadingSelector, - kindSelector, queriesSelector, savedQuerySelector, startSelector, @@ -44,6 +43,8 @@ import { networkActions } from '../../../network/store'; import { timelineActions } from '../../../timelines/store/timeline'; import { useKibana } from '../../lib/kibana'; +const APP_STATE_STORAGE_KEY = 'securitySolution.searchBar.appState'; + interface SiemSearchBarProps { id: InputsModelId; indexPattern: IIndexPattern; @@ -57,7 +58,7 @@ const SearchBarContainer = styled.div` } `; -const SearchBarComponent = memo( +export const SearchBarComponent = memo( ({ end, filterQuery, @@ -74,20 +75,27 @@ const SearchBarComponent = memo( updateSearch, dataTestSubj, }) => { - const { data } = useKibana().services; const { - timefilter: { timefilter }, - filterManager, - } = data.query; - - if (fromStr != null && toStr != null) { - timefilter.setTime({ from: fromStr, to: toStr }); - } else if (start != null && end != null) { - timefilter.setTime({ - from: new Date(start).toISOString(), - to: new Date(end).toISOString(), - }); - } + data: { + query: { + timefilter: { timefilter }, + filterManager, + }, + ui: { SearchBar }, + }, + storage, + } = useKibana().services; + + useEffect(() => { + if (fromStr != null && toStr != null) { + timefilter.setTime({ from: fromStr, to: toStr }); + } else if (start != null && end != null) { + timefilter.setTime({ + from: new Date(start).toISOString(), + to: new Date(end).toISOString(), + }); + } + }, [end, fromStr, start, timefilter, toStr]); const onQuerySubmit = useCallback( (payload: { dateRange: TimeRange; query?: Query }) => { @@ -135,8 +143,7 @@ const SearchBarComponent = memo( window.setTimeout(() => updateSearch(updateSearchBar), 0); }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [id, end, filterQuery, fromStr, queries, start, toStr] + [id, toStr, end, fromStr, start, filterManager, filterQuery, queries, updateSearch] ); const onRefresh = useCallback( @@ -155,16 +162,14 @@ const SearchBarComponent = memo( queries.forEach((q) => q.refetch && (q.refetch as inputsModel.Refetch)()); } }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [id, queries, filterManager] + [updateSearch, id, filterManager, queries] ); const onSaved = useCallback( (newSavedQuery: SavedQuery) => { setSavedQuery({ id, savedQuery: newSavedQuery }); }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [id] + [id, setSavedQuery] ); const onSavedQueryUpdated = useCallback( @@ -200,8 +205,7 @@ const SearchBarComponent = memo( updateSearch(updateSearchBar); }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [id, end, fromStr, start, toStr] + [id, toStr, end, fromStr, start, filterManager, updateSearch] ); const onClearSavedQuery = useCallback(() => { @@ -223,8 +227,16 @@ const SearchBarComponent = memo( filterManager, }); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [id, end, filterManager, fromStr, start, toStr, savedQuery]); + }, [savedQuery, updateSearch, id, toStr, end, fromStr, start, filterManager]); + + const saveAppStateToStorage = useCallback( + (filters: Filter[]) => storage.set(APP_STATE_STORAGE_KEY, filters), + [storage] + ); + + const getAppStateFromStorage = useCallback(() => storage.get(APP_STATE_STORAGE_KEY) ?? [], [ + storage, + ]); useEffect(() => { let isSubscribed = true; @@ -234,6 +246,7 @@ const SearchBarComponent = memo( filterManager.getUpdates$().subscribe({ next: () => { if (isSubscribed) { + saveAppStateToStorage(filterManager.getAppFilters()); setSearchBarFilter({ id, filters: filterManager.getFilters(), @@ -243,16 +256,25 @@ const SearchBarComponent = memo( }) ); + // for the initial state + filterManager.setAppFilters(getAppStateFromStorage()); + setSearchBarFilter({ + id, + filters: filterManager.getFilters(), + }); + return () => { isSubscribed = false; subscriptions.unsubscribe(); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); + return ( - { const getEndSelector = endSelector(); const getFromStrSelector = fromStrSelector(); const getIsLoadingSelector = isLoadingSelector(); - const getKindSelector = kindSelector(); const getQueriesSelector = queriesSelector(); const getStartSelector = startSelector(); const getToStrSelector = toStrSelector(); @@ -292,7 +313,6 @@ const makeMapStateToProps = () => { fromStr: getFromStrSelector(inputsRange), filterQuery: getFilterQuerySelector(inputsRange), isLoading: getIsLoadingSelector(inputsRange), - kind: getKindSelector(inputsRange), queries: getQueriesSelector(inputsRange), savedQuery: getSavedQuerySelector(inputsRange), start: getStartSelector(inputsRange), diff --git a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx index 0795e46c9e45..956ee4b05f9d 100644 --- a/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/super_date_picker/index.test.tsx @@ -17,7 +17,7 @@ import { kibanaObservable, createSecuritySolutionStorageMock, } from '../../mock'; -import { createUseUiSetting$Mock } from '../../mock/kibana_react'; +import { createUseUiSetting$Mock } from '../../lib/kibana/kibana_react.mock'; import { createStore, State } from '../../store'; import { SuperDatePicker, makeMapStateToProps } from '.'; diff --git a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx index 1e93fdb93672..31318122eb56 100644 --- a/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/top_n/index.test.tsx @@ -18,7 +18,6 @@ import { createSecuritySolutionStorageMock, mockIndexPattern, } from '../../mock'; -import { createKibanaCoreStartMock } from '../../mock/kibana_core'; import { FilterManager } from '../../../../../../../src/plugins/data/public'; import { createStore, State } from '../../store'; @@ -29,6 +28,7 @@ import { getTimelineDefaults, } from '../../../timelines/components/manage_timeline'; import { TimelineId } from '../../../../common/types/timeline'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; jest.mock('react-router-dom', () => { const original = jest.requireActual('react-router-dom'); @@ -45,7 +45,7 @@ jest.mock('../link_to'); jest.mock('../../lib/kibana'); jest.mock('../../../timelines/store/timeline/actions'); -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; const field = 'process.name'; const value = 'nice'; diff --git a/x-pack/plugins/security_solution/public/common/containers/local_storage/use_messages_storage.test.tsx b/x-pack/plugins/security_solution/public/common/containers/local_storage/use_messages_storage.test.tsx index 7085894e4a51..58f5c1a9beb2 100644 --- a/x-pack/plugins/security_solution/public/common/containers/local_storage/use_messages_storage.test.tsx +++ b/x-pack/plugins/security_solution/public/common/containers/local_storage/use_messages_storage.test.tsx @@ -6,17 +6,13 @@ import { renderHook, act } from '@testing-library/react-hooks'; import { useKibana } from '../../lib/kibana'; -import { createUseKibanaMock } from '../../mock/kibana_react'; import { useMessagesStorage, UseMessagesStorage } from './use_messages_storage'; jest.mock('../../lib/kibana'); -const useKibanaMock = useKibana as jest.Mock; describe('useLocalStorage', () => { beforeEach(() => { - const services = { ...createUseKibanaMock()().services }; - useKibanaMock.mockImplementation(() => ({ services })); - services.storage.store.clear(); + useKibana().services.storage.clear(); }); it('should return an empty array when there is no messages', async () => { diff --git a/x-pack/plugins/security_solution/public/common/lib/kibana/__mocks__/index.ts b/x-pack/plugins/security_solution/public/common/lib/kibana/__mocks__/index.ts index 5f4285f2747a..573ef92f7e06 100644 --- a/x-pack/plugins/security_solution/public/common/lib/kibana/__mocks__/index.ts +++ b/x-pack/plugins/security_solution/public/common/lib/kibana/__mocks__/index.ts @@ -9,19 +9,21 @@ import { createKibanaContextProviderMock, createUseUiSettingMock, createUseUiSetting$Mock, - createUseKibanaMock, + createStartServicesMock, createWithKibanaMock, -} from '../../../mock/kibana_react'; +} from '../kibana_react.mock'; export const KibanaServices = { get: jest.fn(), getKibanaVersion: jest.fn(() => '8.0.0') }; -export const useKibana = jest.fn(createUseKibanaMock()); +export const useKibana = jest.fn().mockReturnValue({ services: createStartServicesMock() }); export const useUiSetting = jest.fn(createUseUiSettingMock()); export const useUiSetting$ = jest.fn(createUseUiSetting$Mock()); -export const useHttp = jest.fn(() => useKibana().services.http); +export const useHttp = jest.fn().mockReturnValue(createStartServicesMock().http); export const useTimeZone = jest.fn(); export const useDateFormat = jest.fn(); export const useBasePath = jest.fn(() => '/test/base/path'); -export const useToasts = jest.fn(() => notificationServiceMock.createStartContract().toasts); +export const useToasts = jest + .fn() + .mockReturnValue(notificationServiceMock.createStartContract().toasts); export const useCurrentUser = jest.fn(); export const withKibana = jest.fn(createWithKibanaMock()); export const KibanaContextProvider = jest.fn(createKibanaContextProviderMock()); diff --git a/x-pack/plugins/security_solution/public/common/lib/kibana/kibana_react.mock.ts b/x-pack/plugins/security_solution/public/common/lib/kibana/kibana_react.mock.ts new file mode 100644 index 000000000000..c026b65853a4 --- /dev/null +++ b/x-pack/plugins/security_solution/public/common/lib/kibana/kibana_react.mock.ts @@ -0,0 +1,103 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +/* eslint-disable react/display-name */ + +import React from 'react'; + +import { coreMock } from '../../../../../../../src/core/public/mocks'; +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; +import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks'; +import { securityMock } from '../../../../../../plugins/security/public/mocks'; +import { + DEFAULT_APP_TIME_RANGE, + DEFAULT_APP_REFRESH_INTERVAL, + DEFAULT_INDEX_KEY, + DEFAULT_DATE_FORMAT, + DEFAULT_DATE_FORMAT_TZ, + DEFAULT_DARK_MODE, + DEFAULT_TIME_RANGE, + DEFAULT_REFRESH_RATE_INTERVAL, + DEFAULT_FROM, + DEFAULT_TO, + DEFAULT_INTERVAL_PAUSE, + DEFAULT_INTERVAL_VALUE, + DEFAULT_BYTES_FORMAT, + DEFAULT_INDEX_PATTERN, +} from '../../../../common/constants'; +import { StartServices } from '../../../types'; +import { createSecuritySolutionStorageMock } from '../../mock/mock_local_storage'; + +const mockUiSettings: Record = { + [DEFAULT_TIME_RANGE]: { from: 'now-15m', to: 'now', mode: 'quick' }, + [DEFAULT_REFRESH_RATE_INTERVAL]: { pause: false, value: 0 }, + [DEFAULT_APP_TIME_RANGE]: { + from: DEFAULT_FROM, + to: DEFAULT_TO, + }, + [DEFAULT_APP_REFRESH_INTERVAL]: { + pause: DEFAULT_INTERVAL_PAUSE, + value: DEFAULT_INTERVAL_VALUE, + }, + [DEFAULT_INDEX_KEY]: DEFAULT_INDEX_PATTERN, + [DEFAULT_BYTES_FORMAT]: '0,0.[0]b', + [DEFAULT_DATE_FORMAT_TZ]: 'UTC', + [DEFAULT_DATE_FORMAT]: 'MMM D, YYYY @ HH:mm:ss.SSS', + [DEFAULT_DARK_MODE]: false, +}; + +export const createUseUiSettingMock = () => (key: string, defaultValue?: unknown): unknown => { + const result = mockUiSettings[key]; + + if (typeof result != null) return result; + + if (defaultValue != null) { + return defaultValue; + } + + throw new TypeError(`Unexpected config key: ${key}`); +}; + +export const createUseUiSetting$Mock = () => { + const useUiSettingMock = createUseUiSettingMock(); + + return (key: string, defaultValue?: unknown): [unknown, () => void] | undefined => [ + useUiSettingMock(key, defaultValue), + jest.fn(), + ]; +}; + +export const createStartServicesMock = (): StartServices => { + const core = coreMock.createStart(); + core.uiSettings.get.mockImplementation(createUseUiSettingMock()); + const { storage } = createSecuritySolutionStorageMock(); + const data = dataPluginMock.createStartContract(); + const security = securityMock.createSetup(); + + const services = ({ + ...core, + data, + security, + storage, + } as unknown) as StartServices; + + return services; +}; + +export const createWithKibanaMock = () => { + const services = createStartServicesMock(); + + return (Component: unknown) => (props: unknown) => { + return React.createElement(Component as string, { ...(props as object), kibana: { services } }); + }; +}; + +export const createKibanaContextProviderMock = () => { + const services = createStartServicesMock(); + + return ({ children }: { children: React.ReactNode }) => + React.createElement(KibanaContextProvider, { services }, children); +}; diff --git a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx index 1ed459521cc7..1b9e95f7d073 100644 --- a/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/endpoint/app_context_render.tsx @@ -17,7 +17,7 @@ import { apolloClientObservable, kibanaObservable } from '../test_providers'; import { createStore, State } from '../../store'; import { AppRootProvider } from './app_root_provider'; import { managementMiddlewareFactory } from '../../../management/store/middleware'; -import { createKibanaContextProviderMock } from '../kibana_react'; +import { createKibanaContextProviderMock } from '../../lib/kibana/kibana_react.mock'; import { SUB_PLUGINS_REDUCER, mockGlobalState, createSecuritySolutionStorageMock } from '..'; type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult; diff --git a/x-pack/plugins/security_solution/public/common/mock/index.ts b/x-pack/plugins/security_solution/public/common/mock/index.ts index 678ad4d84b58..7e076772c42f 100644 --- a/x-pack/plugins/security_solution/public/common/mock/index.ts +++ b/x-pack/plugins/security_solution/public/common/mock/index.ts @@ -16,4 +16,3 @@ export * from './test_providers'; export * from './utils'; export * from './mock_ecs'; export * from './timeline_results'; -export * from './kibana_react'; diff --git a/x-pack/plugins/security_solution/public/common/mock/kibana_core.ts b/x-pack/plugins/security_solution/public/common/mock/kibana_core.ts deleted file mode 100644 index f8eed75cf9bf..000000000000 --- a/x-pack/plugins/security_solution/public/common/mock/kibana_core.ts +++ /dev/null @@ -1,15 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -import { coreMock } from '../../../../../../src/core/public/mocks'; -import { dataPluginMock } from '../../../../../../src/plugins/data/public/mocks'; -import { securityMock } from '../../../../../plugins/security/public/mocks'; - -export const createKibanaCoreStartMock = () => coreMock.createStart(); -export const createKibanaPluginsStartMock = () => ({ - data: dataPluginMock.createStartContract(), - security: securityMock.createSetup(), -}); diff --git a/x-pack/plugins/security_solution/public/common/mock/kibana_react.ts b/x-pack/plugins/security_solution/public/common/mock/kibana_react.ts deleted file mode 100644 index bdb8ca85b0d7..000000000000 --- a/x-pack/plugins/security_solution/public/common/mock/kibana_react.ts +++ /dev/null @@ -1,126 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -/* eslint-disable react/display-name */ - -import React from 'react'; -import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; - -import { - DEFAULT_APP_TIME_RANGE, - DEFAULT_APP_REFRESH_INTERVAL, - DEFAULT_INDEX_KEY, - DEFAULT_DATE_FORMAT, - DEFAULT_DATE_FORMAT_TZ, - DEFAULT_DARK_MODE, - DEFAULT_TIME_RANGE, - DEFAULT_REFRESH_RATE_INTERVAL, - DEFAULT_FROM, - DEFAULT_TO, - DEFAULT_INTERVAL_PAUSE, - DEFAULT_INTERVAL_VALUE, - DEFAULT_BYTES_FORMAT, - DEFAULT_INDEX_PATTERN, -} from '../../../common/constants'; -import { createKibanaCoreStartMock, createKibanaPluginsStartMock } from './kibana_core'; -import { StartServices } from '../../types'; -import { createSecuritySolutionStorageMock } from './mock_local_storage'; - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export const mockUiSettings: Record = { - [DEFAULT_TIME_RANGE]: { from: 'now-15m', to: 'now', mode: 'quick' }, - [DEFAULT_REFRESH_RATE_INTERVAL]: { pause: false, value: 0 }, - [DEFAULT_APP_TIME_RANGE]: { - from: DEFAULT_FROM, - to: DEFAULT_TO, - }, - [DEFAULT_APP_REFRESH_INTERVAL]: { - pause: DEFAULT_INTERVAL_PAUSE, - value: DEFAULT_INTERVAL_VALUE, - }, - [DEFAULT_INDEX_KEY]: DEFAULT_INDEX_PATTERN, - [DEFAULT_BYTES_FORMAT]: '0,0.[0]b', - [DEFAULT_DATE_FORMAT_TZ]: 'UTC', - [DEFAULT_DATE_FORMAT]: 'MMM D, YYYY @ HH:mm:ss.SSS', - [DEFAULT_DARK_MODE]: false, -}; - -export const createUseUiSettingMock = () => ( - key: string, - defaultValue?: T -): T => { - const result = mockUiSettings[key]; - - if (typeof result != null) return result; - - if (defaultValue != null) { - return defaultValue; - } - - throw new Error(`Unexpected config key: ${key}`); -}; - -export const createUseUiSetting$Mock = () => { - const useUiSettingMock = createUseUiSettingMock(); - - return ( - key: string, - defaultValue?: T - ): [T, () => void] | undefined => [useUiSettingMock(key, defaultValue), jest.fn()]; -}; - -export const createKibanaObservable$Mock = createKibanaCoreStartMock; - -export const createUseKibanaMock = () => { - const core = createKibanaCoreStartMock(); - const plugins = createKibanaPluginsStartMock(); - const useUiSetting = createUseUiSettingMock(); - const { storage } = createSecuritySolutionStorageMock(); - - const services = { - ...core, - ...plugins, - uiSettings: { - ...core.uiSettings, - get: useUiSetting, - }, - storage, - }; - - return () => ({ services }); -}; - -export const createStartServices = () => { - const core = createKibanaCoreStartMock(); - const plugins = createKibanaPluginsStartMock(); - - const services = ({ - ...core, - ...plugins, - } as unknown) as StartServices; - - return services; -}; - -export const createWithKibanaMock = () => { - const kibana = createUseKibanaMock()(); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return (Component: any) => (props: any) => { - return React.createElement(Component, { ...props, kibana }); - }; -}; - -export const createKibanaContextProviderMock = () => { - const kibana = createUseKibanaMock()(); - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return ({ services, ...rest }: any) => - React.createElement(KibanaContextProvider, { - ...rest, - services: { ...kibana.services, ...services }, - }); -}; diff --git a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx index 010d2fac18af..9ead8171bfef 100644 --- a/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/test_providers.tsx @@ -19,7 +19,10 @@ import { ThemeProvider } from 'styled-components'; import { createStore, State } from '../store'; import { mockGlobalState } from './global_state'; -import { createKibanaContextProviderMock, createStartServices } from './kibana_react'; +import { + createKibanaContextProviderMock, + createStartServicesMock, +} from '../lib/kibana/kibana_react.mock'; import { FieldHook, useForm } from '../../shared_imports'; import { SUB_PLUGINS_REDUCER } from './utils'; import { createSecuritySolutionStorageMock, localStorageMock } from './mock_local_storage'; @@ -38,7 +41,7 @@ export const apolloClient = new ApolloClient({ }); export const apolloClientObservable = new BehaviorSubject(apolloClient); -export const kibanaObservable = new BehaviorSubject(createStartServices()); +export const kibanaObservable = new BehaviorSubject(createStartServicesMock()); Object.defineProperty(window, 'localStorage', { value: localStorageMock(), diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/__mocks__/use_lists_config.tsx b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/__mocks__/use_lists_config.tsx index 0f8e0fba1e3a..291587e9f69c 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/__mocks__/use_lists_config.tsx +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/__mocks__/use_lists_config.tsx @@ -4,4 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export const useListsConfig = jest.fn().mockReturnValue({}); +import { getUseListsConfigMock } from '../use_lists_config.mock'; + +export const useListsConfig = jest.fn(getUseListsConfigMock); diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.mock.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.mock.ts new file mode 100644 index 000000000000..90f47972a3a2 --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.mock.ts @@ -0,0 +1,15 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { UseListsConfigReturn } from './use_lists_config'; + +export const getUseListsConfigMock: () => jest.Mocked = () => ({ + canManageIndex: null, + canWriteIndex: null, + enabled: true, + loading: false, + needsConfiguration: false, +}); diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.test.tsx b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.test.tsx new file mode 100644 index 000000000000..a5ff29e2091b --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_config.test.tsx @@ -0,0 +1,86 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { renderHook } from '@testing-library/react-hooks'; + +import { useKibana } from '../../../../common/lib/kibana'; +import { useListsIndex } from './use_lists_index'; +import { useListsPrivileges } from './use_lists_privileges'; +import { getUseListsIndexMock } from './use_lists_index.mock'; +import { getUseListsPrivilegesMock } from './use_lists_privileges.mock'; +import { useListsConfig } from './use_lists_config'; + +jest.mock('../../../../common/lib/kibana'); +jest.mock('./use_lists_index'); +jest.mock('./use_lists_privileges'); + +describe('useListsConfig', () => { + let listsIndexMock: ReturnType; + let listsPrivilegesMock: ReturnType; + + beforeEach(() => { + listsIndexMock = getUseListsIndexMock(); + listsPrivilegesMock = getUseListsPrivilegesMock(); + (useListsIndex as jest.Mock).mockReturnValue(listsIndexMock); + (useListsPrivileges as jest.Mock).mockReturnValue(listsPrivilegesMock); + }); + + it("returns the user's write permissions", () => { + listsPrivilegesMock.canWriteIndex = false; + const { result } = renderHook(() => useListsConfig()); + expect(result.current.canWriteIndex).toEqual(false); + + listsPrivilegesMock.canWriteIndex = true; + const { result: result2 } = renderHook(() => useListsConfig()); + expect(result2.current.canWriteIndex).toEqual(true); + }); + + describe('when lists are disabled', () => { + beforeEach(() => { + useKibana().services.lists = undefined; + }); + + it('indicates that lists are not enabled, and need configuration', () => { + const { result } = renderHook(() => useListsConfig()); + expect(result.current.enabled).toEqual(false); + expect(result.current.needsConfiguration).toEqual(true); + }); + }); + + describe('when lists are enabled but indexes do not exist', () => { + beforeEach(() => { + useKibana().services.lists = {}; + listsIndexMock.indexExists = false; + }); + + it('needs configuration if the user cannot manage indexes', () => { + listsPrivilegesMock.canManageIndex = false; + + const { result } = renderHook(() => useListsConfig()); + expect(result.current.needsConfiguration).toEqual(true); + expect(listsIndexMock.createIndex).not.toHaveBeenCalled(); + }); + + it('attempts to create the indexes if the user can manage indexes', () => { + listsPrivilegesMock.canManageIndex = true; + + renderHook(() => useListsConfig()); + expect(listsIndexMock.createIndex).toHaveBeenCalled(); + }); + }); + + describe('when lists are enabled and indexes exist', () => { + beforeEach(() => { + useKibana().services.lists = {}; + listsIndexMock.indexExists = true; + }); + + it('does not need configuration', () => { + const { result } = renderHook(() => useListsConfig()); + expect(result.current.needsConfiguration).toEqual(false); + }); + }); +}); diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_index.mock.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_index.mock.ts new file mode 100644 index 000000000000..e2169442d80e --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_index.mock.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { UseListsIndexReturn } from './use_lists_index'; + +export const getUseListsIndexMock: () => jest.Mocked = () => ({ + createIndex: jest.fn(), + indexExists: null, + error: null, + loading: false, +}); diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_privileges.mock.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_privileges.mock.ts new file mode 100644 index 000000000000..4f583a72460e --- /dev/null +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/lists/use_lists_privileges.mock.ts @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { UseListsPrivilegesReturn } from './use_lists_privileges'; + +export const getUseListsPrivilegesMock: () => jest.Mocked = () => ({ + isAuthenticated: null, + canManageIndex: null, + canWriteIndex: null, + loading: false, +}); diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.test.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.test.tsx index b07caa754aec..9f486dc11e99 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.test.tsx @@ -9,7 +9,6 @@ import { shallow, mount } from 'enzyme'; import { act } from 'react-dom/test-utils'; import '../../../../../common/mock/match_media'; -import { createKibanaContextProviderMock } from '../../../../../common/mock/kibana_react'; import { TestProviders } from '../../../../../common/mock'; // we don't have the types for waitFor just yet, so using "as waitFor" until when we do import { wait as waitFor } from '@testing-library/react'; @@ -182,23 +181,20 @@ describe('AllRules', () => { }); it('renders rules tab', async () => { - const KibanaContext = createKibanaContextProviderMock(); const wrapper = mount( - - - + ); @@ -211,24 +207,20 @@ describe('AllRules', () => { }); it('renders monitoring tab when monitoring tab clicked', async () => { - const KibanaContext = createKibanaContextProviderMock(); - const wrapper = mount( - - - + ); const monitoringTab = wrapper.find('[data-test-subj="allRulesTableTab-monitoring"] button'); diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/index.tsx b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/index.tsx index 40227ec24a9e..a37ddd0bd61d 100644 --- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/index.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/index.tsx @@ -81,9 +81,11 @@ export const EndpointDetailsFlyout = memo(() => { > -

- {loading ? : details?.host?.hostname} -

+ {loading ? ( + + ) : ( +

{details?.host?.hostname}

+ )} {details === undefined ? ( diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx index 5ab9df79ee14..6e3736793046 100644 --- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx @@ -246,7 +246,8 @@ describe('when on the list page', () => { }); }); - describe('when polling on Endpoint List', () => { + // FLAKY: https://github.com/elastic/kibana/issues/75721 + describe.skip('when polling on Endpoint List', () => { beforeEach(async () => { await reactTestingLibrary.act(() => { const hostListData = mockEndpointResultList({ total: 4 }).hosts; diff --git a/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx index 99902a31975d..446679ae26d9 100644 --- a/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/recent_cases/no_cases/index.test.tsx @@ -9,29 +9,19 @@ import { mount } from 'enzyme'; import { useKibana } from '../../../../common/lib/kibana'; import '../../../../common/mock/match_media'; -import { createUseKibanaMock, TestProviders } from '../../../../common/mock'; +import { TestProviders } from '../../../../common/mock'; import { NoCases } from '.'; jest.mock('../../../../common/lib/kibana'); -const useKibanaMock = useKibana as jest.Mock; - -let navigateToApp: jest.Mock; +const useKibanaMock = useKibana as jest.Mocked; describe('RecentCases', () => { + let navigateToApp: jest.Mock; + beforeEach(() => { - jest.resetAllMocks(); navigateToApp = jest.fn(); - const kibanaMock = createUseKibanaMock()(); - useKibanaMock.mockReturnValue({ - ...kibanaMock, - services: { - application: { - navigateToApp, - getUrlForApp: jest.fn(), - }, - }, - }); + useKibanaMock().services.application.navigateToApp = navigateToApp; }); it('if no cases, you should be able to create a case by clicking on the link "start a new case"', () => { diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/data_providers.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/data_providers.test.tsx index 754d7f9c47ed..d48be25b0889 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/data_providers.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/data_providers.test.tsx @@ -15,8 +15,9 @@ import { DataProvider } from './data_provider'; import { mockDataProviders } from './mock/mock_data_providers'; import { ManageGlobalTimeline, getTimelineDefaults } from '../../manage_timeline'; import { FilterManager } from '../../../../../../../../src/plugins/data/public/query/filter_manager'; -import { createKibanaCoreStartMock } from '../../../../common/mock/kibana_core'; -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +import { coreMock } from '../../../../../../../../src/core/public/mocks'; + +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; const filterManager = new FilterManager(mockUiSettingsForFilterManager); describe('DataProviders', () => { diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx index b788f70cb2e4..3f371349aa75 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/data_providers/providers.test.tsx @@ -7,7 +7,7 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { createKibanaCoreStartMock } from '../../../../common/mock/kibana_core'; +import { coreMock } from '../../../../../../../../src/core/public/mocks'; import { TestProviders } from '../../../../common/mock/test_providers'; import { DroppableWrapper } from '../../../../common/components/drag_and_drop/droppable_wrapper'; import { FilterManager } from '../../../../../../../../src/plugins/data/public'; @@ -18,7 +18,7 @@ import { DELETE_CLASS_NAME, ENABLE_CLASS_NAME, EXCLUDE_CLASS_NAME } from './prov import { useMountAppended } from '../../../../common/utils/use_mount_appended'; import { ManageGlobalTimeline, getTimelineDefaults } from '../../manage_timeline'; -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; describe('Providers', () => { const isLoading: boolean = true; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/header/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/header/index.test.tsx index e7b0ce7b7428..329bcf24ba7e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/header/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/header/index.test.tsx @@ -7,8 +7,8 @@ import { shallow } from 'enzyme'; import React from 'react'; +import { coreMock } from '../../../../../../../../src/core/public/mocks'; import { mockIndexPattern } from '../../../../common/mock'; -import { createKibanaCoreStartMock } from '../../../../common/mock/kibana_core'; import { TestProviders } from '../../../../common/mock/test_providers'; import { FilterManager } from '../../../../../../../../src/plugins/data/public'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; @@ -17,7 +17,7 @@ import { useMountAppended } from '../../../../common/utils/use_mount_appended'; import { TimelineHeader } from '.'; import { TimelineStatus, TimelineType } from '../../../../../common/types/timeline'; -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; jest.mock('../../../../common/lib/kibana'); diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_bar/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_bar/index.test.tsx index 75f684c629c7..6c8fd4975c65 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/query_bar/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/query_bar/index.test.tsx @@ -7,11 +7,11 @@ import { mount } from 'enzyme'; import React from 'react'; +import { coreMock } from '../../../../../../../../src/core/public/mocks'; import { DEFAULT_FROM, DEFAULT_TO } from '../../../../../common/constants'; import { mockBrowserFields } from '../../../../common/containers/source/mock'; import { convertKueryToElasticSearchQuery } from '../../../../common/lib/keury'; import { mockIndexPattern, TestProviders } from '../../../../common/mock'; -import { createKibanaCoreStartMock } from '../../../../common/mock/kibana_core'; import { QueryBar } from '../../../../common/components/query_bar'; import { FilterManager } from '../../../../../../../../src/plugins/data/public'; import { mockDataProviders } from '../data_providers/mock/mock_data_providers'; @@ -19,7 +19,7 @@ import { buildGlobalQuery } from '../helpers'; import { QueryBarTimeline, QueryBarTimelineComponentProps, getDataProviderFilter } from './index'; -const mockUiSettingsForFilterManager = createKibanaCoreStartMock().uiSettings; +const mockUiSettingsForFilterManager = coreMock.createStart().uiSettings; jest.mock('../../../../common/lib/kibana'); diff --git a/x-pack/plugins/security_solution/public/timelines/containers/local_storage/index.test.ts b/x-pack/plugins/security_solution/public/timelines/containers/local_storage/index.test.ts index e1bccbdff488..7a8750b279b8 100644 --- a/x-pack/plugins/security_solution/public/timelines/containers/local_storage/index.test.ts +++ b/x-pack/plugins/security_solution/public/timelines/containers/local_storage/index.test.ts @@ -15,23 +15,16 @@ import { import { TimelineId } from '../../../../common/types/timeline'; import { mockTimelineModel, createSecuritySolutionStorageMock } from '../../../common/mock'; import { useKibana } from '../../../common/lib/kibana'; -import { createUseKibanaMock } from '../../../common/mock/kibana_react'; jest.mock('../../../common/lib/kibana'); -const useKibanaMock = useKibana as jest.Mock; +const useKibanaMock = useKibana as jest.Mocked; describe('SiemLocalStorage', () => { const { localStorage, storage } = createSecuritySolutionStorageMock(); beforeEach(() => { - jest.resetAllMocks(); - useKibanaMock.mockImplementation(() => ({ - services: { - ...createUseKibanaMock()().services, - storage, - }, - })); + useKibanaMock().services.storage = storage; localStorage.clear(); }); diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json index fd21b70660bb..5280f094e3a5 100644 --- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json +++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json @@ -7,6 +7,13 @@ } } }, + "discoverEnhanced": { + "properties": { + "exploreDataInChartActionEnabled": { + "type": "boolean" + } + } + }, "app_search": { "properties": { "ui_viewed": { diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 8287f8f42abd..411aa3424c85 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -526,6 +526,47 @@ "core.ui.securityNavList.label": "セキュリティ", "core.ui.welcomeErrorMessage": "Elasticが正常に読み込まれませんでした。詳細はサーバーアウトプットを確認してください。", "core.ui.welcomeMessage": "Elasticの読み込み中", + "core.ui_settings.params.darkModeText": "Kibana UI のダークモードを有効にします。この設定を適用するにはページの更新が必要です。", + "core.ui_settings.params.darkModeTitle": "ダークモード", + "core.ui_settings.params.dateFormat.dayOfWeekText": "週の初めの曜日を設定します", + "core.ui_settings.params.dateFormat.dayOfWeekTitle": "曜日", + "core.ui_settings.params.dateFormat.optionsLinkText": "フォーマット", + "core.ui_settings.params.dateFormat.scaled.intervalsLinkText": "ISO8601 間隔", + "core.ui_settings.params.dateFormat.scaledText": "時間ベースのデータが順番にレンダリングされ、フォーマットされたタイムスタンプが測定値の間隔に適応すべき状況で使用されるフォーマットを定義する値です。キーは {intervalsLink}。", + "core.ui_settings.params.dateFormat.scaledTitle": "スケーリングされたデータフォーマットです", + "core.ui_settings.params.dateFormat.timezoneText": "使用されるタイムゾーンです。{defaultOption} ではご使用のブラウザにより検知されたタイムゾーンが使用されます。", + "core.ui_settings.params.dateFormat.timezoneTitle": "データフォーマットのタイムゾーン", + "core.ui_settings.params.dateFormatText": "きちんとフォーマットされたデータを表示する際、この {formatLink} を使用します", + "core.ui_settings.params.dateFormatTitle": "データフォーマット", + "core.ui_settings.params.dateNanosFormatText": "Elasticsearch の {dateNanosLink} データタイプに使用されます", + "core.ui_settings.params.dateNanosFormatTitle": "ナノ秒フォーマットでの日付", + "core.ui_settings.params.dateNanosLinkTitle": "date_nanos", + "core.ui_settings.params.defaultRoute.defaultRouteIsRelativeValidationMessage": "相対 URL でなければなりません。", + "core.ui_settings.params.defaultRoute.defaultRouteText": "この設定は、Kibana 起動時のデフォルトのルートを設定します。この設定で、Kibana 起動時のランディングページを変更できます。経路は相対 URL でなければなりません。", + "core.ui_settings.params.defaultRoute.defaultRouteTitle": "デフォルトのルート", + "core.ui_settings.params.disableAnimationsText": "Kibana UI の不要なアニメーションをオフにします。変更を適用するにはページを更新してください。", + "core.ui_settings.params.disableAnimationsTitle": "アニメーションを無効にする", + "core.ui_settings.params.maxCellHeightText": "表のセルが使用する高さの上限です。この切り捨てを無効にするには 0 に設定します", + "core.ui_settings.params.maxCellHeightTitle": "表のセルの高さの上限", + "core.ui_settings.params.notifications.banner.markdownLinkText": "マークダウン対応", + "core.ui_settings.params.notifications.bannerLifetimeText": "バナー通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定するとカウントダウンが無効になります。", + "core.ui_settings.params.notifications.bannerLifetimeTitle": "バナー通知時間", + "core.ui_settings.params.notifications.bannerText": "すべてのユーザーへの一時的な通知を目的としたカスタムバナーです。{markdownLink}", + "core.ui_settings.params.notifications.bannerTitle": "カスタムバナー通知", + "core.ui_settings.params.notifications.errorLifetimeText": "エラー通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", + "core.ui_settings.params.notifications.errorLifetimeTitle": "エラー通知時間", + "core.ui_settings.params.notifications.infoLifetimeText": "情報通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", + "core.ui_settings.params.notifications.infoLifetimeTitle": "情報通知時間", + "core.ui_settings.params.notifications.warningLifetimeText": "警告通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", + "core.ui_settings.params.notifications.warningLifetimeTitle": "警告通知時間", + "core.ui_settings.params.pageNavigationDesc": "ナビゲーションのスタイルを変更", + "core.ui_settings.params.pageNavigationLegacy": "レガシー", + "core.ui_settings.params.pageNavigationModern": "モダン", + "core.ui_settings.params.pageNavigationName": "サイドナビゲーションスタイル", + "core.ui_settings.params.themeVersionText": "現在のバージョンと次のバージョンのKibanaで使用されるテーマを切り替えます。この設定を適用するにはページの更新が必要です。", + "core.ui_settings.params.themeVersionTitle": "テーマバージョン", + "core.ui_settings.params.storeUrlText": "URL は長くなりすぎてブラウザが対応できない場合があります。セッションストレージに URL の一部を保存することがで この問題に対処できるかテストしています。結果を教えてください!", + "core.ui_settings.params.storeUrlTitle": "セッションストレージに URL を格納", "dashboard.actions.toggleExpandPanelMenuItem.expandedDisplayName": "最小化", "dashboard.actions.toggleExpandPanelMenuItem.notExpandedDisplayName": "全画面", "dashboard.addExistingVisualizationLinkText": "既存のユーザーを追加", @@ -2734,47 +2775,6 @@ "inspector.requests.statisticsTabLabel": "統計", "inspector.title": "インスペクター", "inspector.view": "{viewName} を表示", - "kbn.advancedSettings.darkModeText": "Kibana UI のダークモードを有効にします。この設定を適用するにはページの更新が必要です。", - "kbn.advancedSettings.darkModeTitle": "ダークモード", - "kbn.advancedSettings.dateFormat.dayOfWeekText": "週の初めの曜日を設定します", - "kbn.advancedSettings.dateFormat.dayOfWeekTitle": "曜日", - "kbn.advancedSettings.dateFormat.optionsLinkText": "フォーマット", - "kbn.advancedSettings.dateFormat.scaled.intervalsLinkText": "ISO8601 間隔", - "kbn.advancedSettings.dateFormat.scaledText": "時間ベースのデータが順番にレンダリングされ、フォーマットされたタイムスタンプが測定値の間隔に適応すべき状況で使用されるフォーマットを定義する値です。キーは {intervalsLink}。", - "kbn.advancedSettings.dateFormat.scaledTitle": "スケーリングされたデータフォーマットです", - "kbn.advancedSettings.dateFormat.timezoneText": "使用されるタイムゾーンです。{defaultOption} ではご使用のブラウザにより検知されたタイムゾーンが使用されます。", - "kbn.advancedSettings.dateFormat.timezoneTitle": "データフォーマットのタイムゾーン", - "kbn.advancedSettings.dateFormatText": "きちんとフォーマットされたデータを表示する際、この {formatLink} を使用します", - "kbn.advancedSettings.dateFormatTitle": "データフォーマット", - "kbn.advancedSettings.dateNanosFormatText": "Elasticsearch の {dateNanosLink} データタイプに使用されます", - "kbn.advancedSettings.dateNanosFormatTitle": "ナノ秒フォーマットでの日付", - "kbn.advancedSettings.dateNanosLinkTitle": "date_nanos", - "kbn.advancedSettings.defaultRoute.defaultRouteIsRelativeValidationMessage": "相対 URL でなければなりません。", - "kbn.advancedSettings.defaultRoute.defaultRouteText": "この設定は、Kibana 起動時のデフォルトのルートを設定します。この設定で、Kibana 起動時のランディングページを変更できます。経路は相対 URL でなければなりません。", - "kbn.advancedSettings.defaultRoute.defaultRouteTitle": "デフォルトのルート", - "kbn.advancedSettings.disableAnimationsText": "Kibana UI の不要なアニメーションをオフにします。変更を適用するにはページを更新してください。", - "kbn.advancedSettings.disableAnimationsTitle": "アニメーションを無効にする", - "kbn.advancedSettings.maxCellHeightText": "表のセルが使用する高さの上限です。この切り捨てを無効にするには 0 に設定します", - "kbn.advancedSettings.maxCellHeightTitle": "表のセルの高さの上限", - "kbn.advancedSettings.notifications.banner.markdownLinkText": "マークダウン対応", - "kbn.advancedSettings.notifications.bannerLifetimeText": "バナー通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定するとカウントダウンが無効になります。", - "kbn.advancedSettings.notifications.bannerLifetimeTitle": "バナー通知時間", - "kbn.advancedSettings.notifications.bannerText": "すべてのユーザーへの一時的な通知を目的としたカスタムバナーです。{markdownLink}", - "kbn.advancedSettings.notifications.bannerTitle": "カスタムバナー通知", - "kbn.advancedSettings.notifications.errorLifetimeText": "エラー通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", - "kbn.advancedSettings.notifications.errorLifetimeTitle": "エラー通知時間", - "kbn.advancedSettings.notifications.infoLifetimeText": "情報通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", - "kbn.advancedSettings.notifications.infoLifetimeTitle": "情報通知時間", - "kbn.advancedSettings.notifications.warningLifetimeText": "警告通知が画面に表示されるミリ秒単位での時間です。{infinityValue} に設定すると無効になります。", - "kbn.advancedSettings.notifications.warningLifetimeTitle": "警告通知時間", - "kbn.advancedSettings.pageNavigationDesc": "ナビゲーションのスタイルを変更", - "kbn.advancedSettings.pageNavigationLegacy": "レガシー", - "kbn.advancedSettings.pageNavigationModern": "モダン", - "kbn.advancedSettings.pageNavigationName": "サイドナビゲーションスタイル", - "kbn.advancedSettings.storeUrlText": "URL は長くなりすぎてブラウザが対応できない場合があります。セッションストレージに URL の一部を保存することがで この問題に対処できるかテストしています。結果を教えてください!", - "kbn.advancedSettings.storeUrlTitle": "セッションストレージに URL を格納", - "kbn.advancedSettings.themeVersionText": "現在のバージョンと次のバージョンのKibanaで使用されるテーマを切り替えます。この設定を適用するにはページの更新が必要です。", - "kbn.advancedSettings.themeVersionTitle": "テーマバージョン", "kbn.advancedSettings.visualization.showRegionMapWarningsText": "用語がマップの形に合わない場合に地域マップに警告を表示するかどうかです。", "kbn.advancedSettings.visualization.showRegionMapWarningsTitle": "地域マップに警告を表示", "kbn.advancedSettings.visualization.tileMap.maxPrecision.cellDimensionsLinkText": "ディメンションの説明", @@ -4599,7 +4599,7 @@ "xpack.actions.serverSideErrors.predefinedActionUpdateDisabled": "あらかじめ構成されたアクション{id}は更新できません。", "xpack.actions.serverSideErrors.unavailableLicenseErrorMessage": "現時点でライセンス情報を入手できないため、アクションタイプ {actionTypeId} は無効です。", "xpack.actions.serverSideErrors.unavailableLicenseInformationErrorMessage": "グラフを利用できません。現在ライセンス情報が利用できません。", - "xpack.actions.urlWhitelistConfigurationError": "target {field} \"{value}\" は Kibana 構成 xpack.actions.whitelistedHosts にはホワイトリスト化されていません。", + "xpack.actions.urlAllowedHostsConfigurationError": "target {field} \"{value}\" は Kibana 構成 xpack.actions.allowedHosts にはホワイトリスト化されていません。", "xpack.alertingBuiltins.indexThreshold.actionGroupThresholdMetTitle": "しきい値一致", "xpack.alertingBuiltins.indexThreshold.actionVariableContextDateLabel": "アラートがしきい値を超えた日付。", "xpack.alertingBuiltins.indexThreshold.actionVariableContextGroupLabel": "しきい値を超えたグループ。", @@ -5667,7 +5667,6 @@ "xpack.canvas.functions.joinRows.args.separatorHelpText": "行の値の間で使用する区切り文字", "xpack.canvas.functions.joinRows.columnNotFoundErrorMessage": "列が見つかりません。'{column}'", "xpack.canvas.functions.joinRowsHelpText": "データベースの行の値を文字列に結合", - "xpack.canvas.functions.locationHelpText": "ブラウザの {geolocationAPI} を使用して現在位置を取得します。パフォーマンスに違いはありますが、比較的正確です。{url} を参照。", "xpack.canvas.functions.lt.args.valueHelpText": "{CONTEXT} と比較される値です。", "xpack.canvas.functions.lte.args.valueHelpText": "{CONTEXT} と比較される値です。", "xpack.canvas.functions.lteHelpText": "{CONTEXT} が引数以下かを戻します。", @@ -5676,7 +5675,6 @@ "xpack.canvas.functions.mapCenterHelpText": "マップの中央座標とズームレベルのオブジェクトに戻ります。", "xpack.canvas.functions.mapColumn.args.expressionHelpText": "単一行 {DATATABLE} として各行に渡される {CANVAS} 表現です。", "xpack.canvas.functions.mapColumn.args.nameHelpText": "結果の列の名前です。", - "xpack.canvas.functions.mapColumnHelpText": "他の列の結果として計算された列を追加します。引数が提供された場合のみ変更が加えられます。{mapColumnFn} と {staticColumnFn} もご参照ください。", "xpack.canvas.functions.markdown.args.contentHelpText": "{MARKDOWN} を含むテキストの文字列です。連結させるには、{stringFn} 関数を複数回渡します。", "xpack.canvas.functions.markdown.args.fontHelpText": "コンテンツの {CSS} フォントプロパティです。例: {fontFamily} または {fontWeight}。", "xpack.canvas.functions.markdown.args.openLinkHelpText": "新しいタブでリンクを開くための true/false 値。デフォルト値は false です。true に設定するとすべてのリンクが新しいタブで開くようになります。", @@ -5686,7 +5684,6 @@ "xpack.canvas.functions.math.emptyExpressionErrorMessage": "空の表現", "xpack.canvas.functions.math.executionFailedErrorMessage": "数式の実行に失敗しました。列名を確認してください", "xpack.canvas.functions.math.tooManyResultsErrorMessage": "表現は 1 つの数字を返す必要があります。表現を {mean} または {sum} で囲んでみてください", - "xpack.canvas.functions.mathHelpText": "数字または {DATATABLE} を {CONTEXT} として使用して {TINYMATH} 数式を解釈します。{DATATABLE} 列は列名で表示されます。{CONTEXT} が数字の場合は、{value} と表示されます。", "xpack.canvas.functions.metric.args.labelFontHelpText": "ラベルの {CSS} フォントプロパティです。例: {FONT_FAMILY} または {FONT_WEIGHT}。", "xpack.canvas.functions.metric.args.labelHelpText": "メトリックを説明するテキストです。", "xpack.canvas.functions.metric.args.metricFontHelpText": "メトリックの {CSS} フォントプロパティです。例: {FONT_FAMILY} または {FONT_WEIGHT}。", @@ -5702,16 +5699,12 @@ "xpack.canvas.functions.pie.args.holeHelpText": "円グラフに穴をあけます、0~100 で円グラフの半径のパーセンテージを指定します。", "xpack.canvas.functions.pie.args.labelRadiusHelpText": "ラベルの円の半径として使用する、コンテナーの面積のパーセンテージです。", "xpack.canvas.functions.pie.args.labelsHelpText": "円グラフのラベルを表示しますか?", - "xpack.canvas.functions.pie.args.legendHelpText": "凡例の配置です。例: {positions}、または {BOOLEAN_FALSE}。{BOOLEAN_FALSE} の場合、凡例は非表示になります。", - "xpack.canvas.functions.pie.args.paletteHelpText": "この円グラフに使用されている色を説明する {palette} オブジェクトです。{paletteFn} をご覧ください。", "xpack.canvas.functions.pie.args.radiusHelpText": "利用可能なスペースのパーセンテージで示された円グラフの半径です (0 から 1 の間)。半径を自動的に設定するには {auto} を使用します。", "xpack.canvas.functions.pie.args.seriesStyleHelpText": "特定の数列のスタイルです", "xpack.canvas.functions.pie.args.tiltHelpText": "「1」 が完全に垂直、「0」が完全に水平を表す傾きのパーセンテージです。", "xpack.canvas.functions.pieHelpText": "円グラフのエレメントを構成します。", "xpack.canvas.functions.plot.args.defaultStyleHelpText": "すべての数列に使用するデフォルトのスタイルです。", "xpack.canvas.functions.plot.args.fontHelpText": "表の {CSS} フォントプロパティです。例: {FONT_FAMILY} または {FONT_WEIGHT}。", - "xpack.canvas.functions.plot.args.legendHelpText": "凡例の配置です。例: {positions}、または {BOOLEAN_FALSE}。{BOOLEAN_FALSE} の場合、凡例は非表示になります。", - "xpack.canvas.functions.plot.args.paletteHelpText": "このチャートに使用される色を説明する {palette} オブジェクトです。{paletteFn} をご覧ください。", "xpack.canvas.functions.plot.args.seriesStyleHelpText": "特定の数列のスタイルです", "xpack.canvas.functions.plot.args.xaxisHelpText": "軸の構成です。{BOOLEAN_FALSE} の場合、軸は非表示になります。", "xpack.canvas.functions.plot.args.yaxisHelpText": "軸の構成です。{BOOLEAN_FALSE} の場合、軸は非表示になります。", @@ -5795,7 +5788,6 @@ "xpack.canvas.functions.shapeHelpText": "図形を作成します。", "xpack.canvas.functions.sort.args.byHelpText": "並べ替えの基準となる列です。指定されていない場合、「{DATATABLE}」は初めの列で並べられます。", "xpack.canvas.functions.sort.args.reverseHelpText": "並び順を反転させます。指定されていない場合、「{DATATABLE}」は昇順で並べられます。", - "xpack.canvas.functions.sortHelpText": "データ表を指定された列で並べ替えます。", "xpack.canvas.functions.staticColumn.args.nameHelpText": "新しい列の名前です。", "xpack.canvas.functions.staticColumn.args.valueHelpText": "新しい列の各行に挿入する値です。ヒント: 部分式を使用して他の列を静的値にロールアップします。", "xpack.canvas.functions.staticColumnHelpText": "すべての行に同じ静的値の列を追加します。{alterColumnFn} および {mapColumnFn} もご参照ください。", @@ -9879,7 +9871,6 @@ "xpack.lens.editorFrame.quickFunctionsLabel": "クイック機能", "xpack.lens.editorFrame.requiredDimensionWarningLabel": "必要な次元", "xpack.lens.editorFrame.suggestionPanelTitle": "提案", - "xpack.lens.editorFrame.tooltipContent": "レンズはベータ段階で、変更される可能性があります。 デザインとコードはオフィシャル GA 機能よりも完成度が低く、現状のまま保証なしで提供されています。ベータ機能にはオフィシャル GA 機能の SLA が適用されません", "xpack.lens.embeddable.failure": "ビジュアライゼーションを表示できませんでした", "xpack.lens.embeddableDisplayName": "レンズ", "xpack.lens.excludeValueButtonAriaLabel": "{value}を除外", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index aff78ad79ae4..c46135633a3c 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -526,6 +526,47 @@ "core.ui.securityNavList.label": "安全", "core.ui.welcomeErrorMessage": "Elastic 未正确加载。检查服务器输出以了解详情。", "core.ui.welcomeMessage": "正在加载 Elastic", + "core.ui_settings.params.darkModeText": "为 Kibana UI 启用深色模式需要刷新页面,才能应用设置。", + "core.ui_settings.params.darkModeTitle": "深色模式", + "core.ui_settings.params.dateFormat.dayOfWeekText": "一周从哪一日开始?", + "core.ui_settings.params.dateFormat.dayOfWeekTitle": "周内日", + "core.ui_settings.params.dateFormat.optionsLinkText": "格式", + "core.ui_settings.params.dateFormat.scaled.intervalsLinkText": "ISO8601 时间间隔", + "core.ui_settings.params.dateFormat.scaledText": "定义在基于时间的数据按顺序呈现且格式化时间戳应适应度量时间间隔时所用格式的值。键是 {intervalsLink}。", + "core.ui_settings.params.dateFormat.scaledTitle": "缩放的日期格式", + "core.ui_settings.params.dateFormat.timezoneText": "应使用哪个时区。{defaultOption} 将使用您的浏览器检测到的时区。", + "core.ui_settings.params.dateFormat.timezoneTitle": "用于设置日期格式的时区", + "core.ui_settings.params.dateFormatText": "显示格式正确的日期时,请使用此{formatLink}", + "core.ui_settings.params.dateFormatTitle": "日期格式", + "core.ui_settings.params.dateNanosFormatText": "用于 Elasticsearch 的 {dateNanosLink} 数据类型", + "core.ui_settings.params.dateNanosFormatTitle": "纳秒格式的日期", + "core.ui_settings.params.dateNanosLinkTitle": "date_nanos", + "core.ui_settings.params.defaultRoute.defaultRouteIsRelativeValidationMessage": "必须是相对 URL。", + "core.ui_settings.params.defaultRoute.defaultRouteText": "此设置指定打开 Kibana 时的默认路由。您可以使用此设置修改打开 Kibana 时的登陆页面。路由必须是相对 URL。", + "core.ui_settings.params.defaultRoute.defaultRouteTitle": "默认路由", + "core.ui_settings.params.disableAnimationsText": "在 Kibana UI 中关闭所有没有必要的动画。刷新页面以应用更改。", + "core.ui_settings.params.disableAnimationsTitle": "禁用动画", + "core.ui_settings.params.maxCellHeightText": "表中单元格应占用的最大高度。设置为 0 可禁用截短", + "core.ui_settings.params.maxCellHeightTitle": "最大表单元格高度", + "core.ui_settings.params.notifications.banner.markdownLinkText": "Markdown 受支持", + "core.ui_settings.params.notifications.bannerLifetimeText": "在屏幕上显示横幅通知的时间(毫秒)。设置为 {infinityValue} 将禁用倒计时。", + "core.ui_settings.params.notifications.bannerLifetimeTitle": "横幅通知生存时间", + "core.ui_settings.params.notifications.bannerText": "用于向所有用户发送临时通知的定制横幅。{markdownLink}", + "core.ui_settings.params.notifications.bannerTitle": "定制横幅通知", + "core.ui_settings.params.notifications.errorLifetimeText": "在屏幕上显示错误通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", + "core.ui_settings.params.notifications.errorLifetimeTitle": "错误通知生存时间", + "core.ui_settings.params.notifications.infoLifetimeText": "在屏幕上显示信息通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", + "core.ui_settings.params.notifications.infoLifetimeTitle": "信息通知生存时间", + "core.ui_settings.params.notifications.warningLifetimeText": "在屏幕上显示警告通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", + "core.ui_settings.params.notifications.warningLifetimeTitle": "警告通知生存时间", + "core.ui_settings.params.pageNavigationDesc": "更改导航样式", + "core.ui_settings.params.pageNavigationLegacy": "旧版", + "core.ui_settings.params.pageNavigationModern": "现代", + "core.ui_settings.params.pageNavigationName": "侧边导航样式", + "core.ui_settings.params.themeVersionText": "在用于 Kibana 当前和下一版本的主题间切换。需要刷新页面,才能应用设置。", + "core.ui_settings.params.themeVersionTitle": "主题版本", + "core.ui_settings.params.storeUrlText": "URL 有时会变得过长,以使得某些浏览器无法处理。为此,我们正在测试将 URL 的各个组成部分存储在会话存储中是否会有帮助。请告知我们这样做的效果!", + "core.ui_settings.params.storeUrlTitle": "将 URL 存储在会话存储中", "dashboard.actions.toggleExpandPanelMenuItem.expandedDisplayName": "最小化", "dashboard.actions.toggleExpandPanelMenuItem.notExpandedDisplayName": "全屏", "dashboard.addExistingVisualizationLinkText": "将现有", @@ -2735,47 +2776,6 @@ "inspector.requests.statisticsTabLabel": "统计信息", "inspector.title": "检查器", "inspector.view": "视图:{viewName}", - "kbn.advancedSettings.darkModeText": "为 Kibana UI 启用深色模式需要刷新页面,才能应用设置。", - "kbn.advancedSettings.darkModeTitle": "深色模式", - "kbn.advancedSettings.dateFormat.dayOfWeekText": "一周从哪一日开始?", - "kbn.advancedSettings.dateFormat.dayOfWeekTitle": "周内日", - "kbn.advancedSettings.dateFormat.optionsLinkText": "格式", - "kbn.advancedSettings.dateFormat.scaled.intervalsLinkText": "ISO8601 时间间隔", - "kbn.advancedSettings.dateFormat.scaledText": "定义在基于时间的数据按顺序呈现且格式化时间戳应适应度量时间间隔时所用格式的值。键是 {intervalsLink}。", - "kbn.advancedSettings.dateFormat.scaledTitle": "缩放的日期格式", - "kbn.advancedSettings.dateFormat.timezoneText": "应使用哪个时区。{defaultOption} 将使用您的浏览器检测到的时区。", - "kbn.advancedSettings.dateFormat.timezoneTitle": "用于设置日期格式的时区", - "kbn.advancedSettings.dateFormatText": "显示格式正确的日期时,请使用此{formatLink}", - "kbn.advancedSettings.dateFormatTitle": "日期格式", - "kbn.advancedSettings.dateNanosFormatText": "用于 Elasticsearch 的 {dateNanosLink} 数据类型", - "kbn.advancedSettings.dateNanosFormatTitle": "纳秒格式的日期", - "kbn.advancedSettings.dateNanosLinkTitle": "date_nanos", - "kbn.advancedSettings.defaultRoute.defaultRouteIsRelativeValidationMessage": "必须是相对 URL。", - "kbn.advancedSettings.defaultRoute.defaultRouteText": "此设置指定打开 Kibana 时的默认路由。您可以使用此设置修改打开 Kibana 时的登陆页面。路由必须是相对 URL。", - "kbn.advancedSettings.defaultRoute.defaultRouteTitle": "默认路由", - "kbn.advancedSettings.disableAnimationsText": "在 Kibana UI 中关闭所有没有必要的动画。刷新页面以应用更改。", - "kbn.advancedSettings.disableAnimationsTitle": "禁用动画", - "kbn.advancedSettings.maxCellHeightText": "表中单元格应占用的最大高度。设置为 0 可禁用截短", - "kbn.advancedSettings.maxCellHeightTitle": "最大表单元格高度", - "kbn.advancedSettings.notifications.banner.markdownLinkText": "Markdown 受支持", - "kbn.advancedSettings.notifications.bannerLifetimeText": "在屏幕上显示横幅通知的时间(毫秒)。设置为 {infinityValue} 将禁用倒计时。", - "kbn.advancedSettings.notifications.bannerLifetimeTitle": "横幅通知生存时间", - "kbn.advancedSettings.notifications.bannerText": "用于向所有用户发送临时通知的定制横幅。{markdownLink}", - "kbn.advancedSettings.notifications.bannerTitle": "定制横幅通知", - "kbn.advancedSettings.notifications.errorLifetimeText": "在屏幕上显示错误通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", - "kbn.advancedSettings.notifications.errorLifetimeTitle": "错误通知生存时间", - "kbn.advancedSettings.notifications.infoLifetimeText": "在屏幕上显示信息通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", - "kbn.advancedSettings.notifications.infoLifetimeTitle": "信息通知生存时间", - "kbn.advancedSettings.notifications.warningLifetimeText": "在屏幕上显示警告通知的时间(毫秒)。设置为 {infinityValue} 将禁用。", - "kbn.advancedSettings.notifications.warningLifetimeTitle": "警告通知生存时间", - "kbn.advancedSettings.pageNavigationDesc": "更改导航样式", - "kbn.advancedSettings.pageNavigationLegacy": "旧版", - "kbn.advancedSettings.pageNavigationModern": "现代", - "kbn.advancedSettings.pageNavigationName": "侧边导航样式", - "kbn.advancedSettings.storeUrlText": "URL 有时会变得过长,以使得某些浏览器无法处理。为此,我们正在测试将 URL 的各个组成部分存储在会话存储中是否会有帮助。请告知我们这样做的效果!", - "kbn.advancedSettings.storeUrlTitle": "将 URL 存储在会话存储中", - "kbn.advancedSettings.themeVersionText": "在用于 Kibana 当前和下一版本的主题间切换。需要刷新页面,才能应用设置。", - "kbn.advancedSettings.themeVersionTitle": "主题版本", "kbn.advancedSettings.visualization.showRegionMapWarningsText": "词无法联接到地图上的形状时,区域地图是否显示警告。", "kbn.advancedSettings.visualization.showRegionMapWarningsTitle": "显示区域地图警告", "kbn.advancedSettings.visualization.tileMap.maxPrecision.cellDimensionsLinkText": "单元格维度的解释", @@ -4600,7 +4600,7 @@ "xpack.actions.serverSideErrors.predefinedActionUpdateDisabled": "不允许更新预配置的操作 {id}。", "xpack.actions.serverSideErrors.unavailableLicenseErrorMessage": "操作类型 {actionTypeId} 已禁用,因为许可证信息当前不可用。", "xpack.actions.serverSideErrors.unavailableLicenseInformationErrorMessage": "操作不可用 - 许可信息当前不可用。", - "xpack.actions.urlWhitelistConfigurationError": "目标 {field}“{value}”在 Kibana 配置 xpack.actions.whitelistedHosts 中未列入白名单", + "xpack.actions.urlAllowedHostsConfigurationError": "目标 {field}“{value}”在 Kibana 配置 xpack.actions.allowedHosts 中未列入白名单", "xpack.alertingBuiltins.indexThreshold.actionGroupThresholdMetTitle": "阈值已达到", "xpack.alertingBuiltins.indexThreshold.actionVariableContextDateLabel": "告警超过阈值的日期。", "xpack.alertingBuiltins.indexThreshold.actionVariableContextGroupLabel": "超过阈值的组。", @@ -5669,7 +5669,6 @@ "xpack.canvas.functions.joinRows.args.separatorHelpText": "用于分隔行值的分隔符", "xpack.canvas.functions.joinRows.columnNotFoundErrorMessage": "找不到列:“{column}”", "xpack.canvas.functions.joinRowsHelpText": "将数据库中的行的值联接成字符串", - "xpack.canvas.functions.locationHelpText": "使用浏览器的 {geolocationAPI} 查找您的当前位置。性能可能会因浏览器而异,但相当准确。请参见 {url}。", "xpack.canvas.functions.lt.args.valueHelpText": "与 {CONTEXT} 比较的值。", "xpack.canvas.functions.lte.args.valueHelpText": "与 {CONTEXT} 比较的值。", "xpack.canvas.functions.lteHelpText": "返回 {CONTEXT} 是否小于或等于参数。", @@ -5678,7 +5677,6 @@ "xpack.canvas.functions.mapCenterHelpText": "返回具有地图中心坐标和缩放级别的对象", "xpack.canvas.functions.mapColumn.args.expressionHelpText": "作为单行 {DATATABLE} 传递到每一行的 {CANVAS} 表达式。", "xpack.canvas.functions.mapColumn.args.nameHelpText": "结果列的名称。", - "xpack.canvas.functions.mapColumnHelpText": "添加计算为其他列的结果的列。只有提供参数时,才会进行更改。另请参见 {mapColumnFn} 和 {staticColumnFn}。", "xpack.canvas.functions.markdown.args.contentHelpText": "包含 {MARKDOWN} 的文本字符串。要进行串联,请传递 {stringFn} 函数多次。", "xpack.canvas.functions.markdown.args.fontHelpText": "内容的 {CSS} 字体属性。例如:{fontFamily} 或 {fontWeight}。", "xpack.canvas.functions.markdown.args.openLinkHelpText": "表示是否在新选项卡中打开链接的 true/false 值。默认值为 false。设置为 true 将在新选项卡中打开所有链接。", @@ -5688,7 +5686,6 @@ "xpack.canvas.functions.math.emptyExpressionErrorMessage": "空表达式", "xpack.canvas.functions.math.executionFailedErrorMessage": "无法执行数学表达式。检查您的列名称", "xpack.canvas.functions.math.tooManyResultsErrorMessage": "表达式必须返回单个数字。尝试将您的表达式包装在 {mean} 或 {sum} 中", - "xpack.canvas.functions.mathHelpText": "通过将数字或 {DATATABLE} 用作 {CONTEXT} 来解析 {TINYMATH} 数学表达式。{DATATABLE} 列可通过列名来使用。如果 {CONTEXT} 是数字,其可用作 {value}。", "xpack.canvas.functions.metric.args.labelFontHelpText": "标签的 {CSS} 字体属性。例如 {FONT_FAMILY} 或 {FONT_WEIGHT}。", "xpack.canvas.functions.metric.args.labelHelpText": "描述指标的文本。", "xpack.canvas.functions.metric.args.metricFontHelpText": "指标的 {CSS} 字体属性。例如 {FONT_FAMILY} 或 {FONT_WEIGHT}。", @@ -5704,16 +5701,12 @@ "xpack.canvas.functions.pie.args.holeHelpText": "在饼图中绘制介于 `0` and `100`(饼图半径的百分比)之间的孔洞。", "xpack.canvas.functions.pie.args.labelRadiusHelpText": "要用作标签圆形半径的容器面积百分比。", "xpack.canvas.functions.pie.args.labelsHelpText": "显示饼图标签?", - "xpack.canvas.functions.pie.args.legendHelpText": "图例位置。例如 {positions} 或 {BOOLEAN_FALSE}。为 {BOOLEAN_FALSE} 时,图例隐藏。", - "xpack.canvas.functions.pie.args.paletteHelpText": "用于描述要在饼图上使用的颜色的 {palette} 对象。请参见 {paletteFn}。", "xpack.canvas.functions.pie.args.radiusHelpText": "饼图的半径,表示为可用空间的百分比(介于 `0` 和 `1` 之间)。要自动设置半径,请使用 {auto}。", "xpack.canvas.functions.pie.args.seriesStyleHelpText": "特定序列的样式", "xpack.canvas.functions.pie.args.tiltHelpText": "倾斜百分比,其中 `1` 为完全垂直,`0` 为完全水平。", "xpack.canvas.functions.pieHelpText": "配置饼图元素。", "xpack.canvas.functions.plot.args.defaultStyleHelpText": "要用于每个序列的默认样式。", "xpack.canvas.functions.plot.args.fontHelpText": "标签的 {CSS} 字体属性。例如 {FONT_FAMILY} 或 {FONT_WEIGHT}。", - "xpack.canvas.functions.plot.args.legendHelpText": "图例位置。例如 {positions} 或 {BOOLEAN_FALSE}。为 {BOOLEAN_FALSE} 时,图例隐藏。", - "xpack.canvas.functions.plot.args.paletteHelpText": "用于描述要在此图表上使用的颜色的 {palette} 对象。请参见 {paletteFn}。", "xpack.canvas.functions.plot.args.seriesStyleHelpText": "特定序列的样式", "xpack.canvas.functions.plot.args.xaxisHelpText": "轴配置。为 {BOOLEAN_FALSE} 时,轴隐藏。", "xpack.canvas.functions.plot.args.yaxisHelpText": "轴配置。为 {BOOLEAN_FALSE} 时,轴隐藏。", @@ -5797,7 +5790,6 @@ "xpack.canvas.functions.shapeHelpText": "创建形状。", "xpack.canvas.functions.sort.args.byHelpText": "排序要依据的列。未指定时,将按第一列排序 `{DATATABLE}`。", "xpack.canvas.functions.sort.args.reverseHelpText": "反转排序顺序。未指定时,将升序排序 `{DATATABLE}`。", - "xpack.canvas.functions.sortHelpText": "按指定列排序数据库。", "xpack.canvas.functions.staticColumn.args.nameHelpText": "新列的名称。", "xpack.canvas.functions.staticColumn.args.valueHelpText": "在每一行新列中要插入的值。提示:使用子表达式将其他列汇总为静态值。", "xpack.canvas.functions.staticColumnHelpText": "在每一行添加具有相同静态值的列。另见 {alterColumnFn} 和 {mapColumnFn}。", @@ -9882,7 +9874,6 @@ "xpack.lens.editorFrame.quickFunctionsLabel": "快选函数", "xpack.lens.editorFrame.requiredDimensionWarningLabel": "所需尺寸", "xpack.lens.editorFrame.suggestionPanelTitle": "建议", - "xpack.lens.editorFrame.tooltipContent": "Lens 为公测版,可能会进行更改。 设计和代码相对于正式发行版功能还不够成熟,将按原样提供,且不提供任何保证。公测版功能不受正式发行版功能支持 SLA 的约束", "xpack.lens.embeddable.failure": "无法显示可视化", "xpack.lens.embeddableDisplayName": "lens", "xpack.lens.excludeValueButtonAriaLabel": "排除 {value}", diff --git a/x-pack/plugins/ui_actions_enhanced/README.md b/x-pack/plugins/ui_actions_enhanced/README.md index 1a72a431e397..a4a37b559ff8 100644 --- a/x-pack/plugins/ui_actions_enhanced/README.md +++ b/x-pack/plugins/ui_actions_enhanced/README.md @@ -1,3 +1,5 @@ # `ui_actions_enhanced` +Registers commercially licensed generic actions like per panel time range and contains some code that supports drilldown work. + - [__Dashboard drilldown user docs__](https://www.elastic.co/guide/en/kibana/master/drilldowns.html) diff --git a/x-pack/test/alerting_api_integration/common/config.ts b/x-pack/test/alerting_api_integration/common/config.ts index 34e23a2dba0b..67dd8c877e37 100644 --- a/x-pack/test/alerting_api_integration/common/config.ts +++ b/x-pack/test/alerting_api_integration/common/config.ts @@ -58,8 +58,13 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) fs.statSync(path.resolve(__dirname, 'fixtures', 'plugins', file)).isDirectory() ); + const proxyPort = + process.env.ALERTING_PROXY_PORT ?? (await getPort({ port: getPort.makeRange(6200, 6300) })); const actionsProxyUrl = options.enableActionsProxy - ? [`--xpack.actions.proxyUrl=http://localhost:${await getPort()}`] + ? [ + `--xpack.actions.proxyUrl=http://localhost:${proxyPort}`, + '--xpack.actions.rejectUnauthorizedCertificates=false', + ] : []; return { @@ -85,14 +90,10 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) ...xPackApiIntegrationTestsConfig.get('kbnTestServer'), serverArgs: [ ...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'), - `--xpack.actions.whitelistedHosts=${JSON.stringify([ - 'localhost', - 'some.non.existent.com', - ])}`, + `--xpack.actions.allowedHosts=${JSON.stringify(['localhost', 'some.non.existent.com'])}`, '--xpack.encryptedSavedObjects.encryptionKey="wuGNaIhoMpk5sO4UBxgr3NyW1sFcLgIf"', `--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`, ...actionsProxyUrl, - '--xpack.actions.rejectUnauthorizedCertificates=false', '--xpack.eventLog.logEntries=true', `--xpack.actions.preconfigured=${JSON.stringify({ diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/server/slack_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/server/slack_simulation.ts index 5032112e702e..8f5b1ea75d18 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/server/slack_simulation.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/server/slack_simulation.ts @@ -64,6 +64,9 @@ export async function initPlugin() { response.statusCode = 400; response.end('unknown request to slack simulator'); }); + } else { + response.writeHead(400, { 'Content-Type': 'text/plain' }); + response.end('Not supported http method to request slack simulator'); } }); } diff --git a/x-pack/test/alerting_api_integration/common/lib/get_proxy_server.ts b/x-pack/test/alerting_api_integration/common/lib/get_proxy_server.ts index 4540556e73c5..7528b00f926d 100644 --- a/x-pack/test/alerting_api_integration/common/lib/get_proxy_server.ts +++ b/x-pack/test/alerting_api_integration/common/lib/get_proxy_server.ts @@ -4,27 +4,42 @@ * you may not use this file except in compliance with the Elastic License. */ +import http from 'http'; import httpProxy from 'http-proxy'; +import { ToolingLog } from '@kbn/dev-utils'; -export const getHttpProxyServer = ( - targetUrl: string, - onProxyResHandler: (proxyRes?: unknown, req?: unknown, res?: unknown) => void -): httpProxy => { - const proxyServer = httpProxy.createProxyServer({ - target: targetUrl, - secure: false, - selfHandleResponse: false, - }); - proxyServer.on('proxyRes', (proxyRes: unknown, req: unknown, res: unknown) => { - onProxyResHandler(proxyRes, req, res); +export const getHttpProxyServer = async ( + defaultKibanaTargetUrl: string, + kbnTestServerConfig: any, + log: ToolingLog +): Promise => { + const proxy = httpProxy.createProxyServer({ secure: false, selfHandleResponse: false }); + + const proxyPort = getProxyPort(kbnTestServerConfig); + const proxyServer = http.createServer((req: http.IncomingMessage, res: http.ServerResponse) => { + const targetUrl = new URL(req.url ?? defaultKibanaTargetUrl); + + if (targetUrl.hostname !== 'some.non.existent.com') { + proxy.web(req, res, { + target: `${targetUrl.protocol}//${targetUrl.hostname}:${targetUrl.port}`, + }); + } else { + res.writeHead(500, { 'Content-Type': 'text/plain' }); + res.write('error on call some.non.existent.com'); + res.end(); + } }); + + proxyServer.listen(proxyPort); + return proxyServer; }; -export const getProxyUrl = (kbnTestServerConfig: any) => { +export const getProxyPort = (kbnTestServerConfig: any): number => { const proxyUrl = kbnTestServerConfig .find((val: string) => val.startsWith('--xpack.actions.proxyUrl=')) .replace('--xpack.actions.proxyUrl=', ''); - return new URL(proxyUrl); + const urlObject = new URL(proxyUrl); + return Number(urlObject.port); }; diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/email.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/email.ts index 1c3d3e3d713e..329bd3433d38 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/email.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/email.ts @@ -153,7 +153,7 @@ export default function emailTest({ getService }: FtrProviderContext) { }); }); - it('should respond with a 400 Bad Request when creating an email action with non-whitelisted server', async () => { + it('should respond with a 400 Bad Request when creating an email action with a server not added to allowedHosts', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -161,7 +161,7 @@ export default function emailTest({ getService }: FtrProviderContext) { name: 'An email action', actionTypeId: '.email', config: { - service: 'gmail', // not whitelisted in the config for this test + service: 'gmail', // not added to allowedHosts in the config for this test from: 'bob@example.com', }, secrets: { @@ -175,7 +175,7 @@ export default function emailTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - "error validating action type config: [service] value 'gmail' resolves to host 'smtp.gmail.com' which is not in the whitelistedHosts configuration", + "error validating action type config: [service] value 'gmail' resolves to host 'smtp.gmail.com' which is not in the allowedHosts configuration", }); }); @@ -186,7 +186,7 @@ export default function emailTest({ getService }: FtrProviderContext) { name: 'An email action', actionTypeId: '.email', config: { - host: 'stmp.gmail.com', // not whitelisted in the config for this test + host: 'stmp.gmail.com', // not added to allowedHosts in the config for this test port: 666, from: 'bob@example.com', }, @@ -201,12 +201,12 @@ export default function emailTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - "error validating action type config: [host] value 'stmp.gmail.com' is not in the whitelistedHosts configuration", + "error validating action type config: [host] value 'stmp.gmail.com' is not in the allowedHosts configuration", }); }); }); - it('should handle creating an email action with a whitelisted server', async () => { + it('should handle creating an email action with a server added to allowedHosts', async () => { const { body: createdAction } = await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -214,7 +214,7 @@ export default function emailTest({ getService }: FtrProviderContext) { name: 'An email action', actionTypeId: '.email', config: { - host: 'some.non.existent.com', // whitelisted in the config for this test + host: 'some.non.existent.com', // added to allowedHosts in the config for this test port: 666, from: 'bob@example.com', }, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts index a0ba5331105b..78a1df0b9c1c 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/jira.ts @@ -6,7 +6,6 @@ import expect from '@kbn/expect'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -36,7 +35,6 @@ const mapping = [ export default function jiraTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const kibanaServer = getService('kibanaServer'); - const config = getService('config'); const mockJira = { config: { @@ -75,19 +73,12 @@ export default function jiraTest({ getService }: FtrProviderContext) { }; let jiraSimulatorURL: string = ''; - let proxyServer: any; - let proxyHaveBeenCalled = false; describe('Jira', () => { before(() => { jiraSimulatorURL = kibanaServer.resolveUrl( getExternalServiceSimulatorPath(ExternalServiceSimulator.JIRA) ); - proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); }); describe('Jira - Action Creation', () => { @@ -175,7 +166,7 @@ export default function jiraTest({ getService }: FtrProviderContext) { }); }); - it('should respond with a 400 Bad Request when creating a jira action with a non whitelisted apiUrl', async () => { + it('should respond with a 400 Bad Request when creating a jira action with a not present in allowedHosts apiUrl', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -195,7 +186,7 @@ export default function jiraTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type config: error configuring connector action: target url "http://jira.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'error validating action type config: error configuring connector action: target url "http://jira.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', }); }); }); @@ -538,8 +529,6 @@ export default function jiraTest({ getService }: FtrProviderContext) { }) .expect(200); - expect(proxyHaveBeenCalled).to.equal(true); - expect(body).to.eql({ status: 'ok', actionId: simulatedActionId, @@ -553,9 +542,5 @@ export default function jiraTest({ getService }: FtrProviderContext) { }); }); }); - - after(() => { - proxyServer.close(); - }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/pagerduty.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/pagerduty.ts index e81219152c24..76b3e8e39791 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/pagerduty.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/pagerduty.ts @@ -6,7 +6,6 @@ import expect from '@kbn/expect'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -18,26 +17,16 @@ import { export default function pagerdutyTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const kibanaServer = getService('kibanaServer'); - const config = getService('config'); - // FLAKY: https://github.com/elastic/kibana/issues/75386 - describe.skip('pagerduty action', () => { + describe('pagerduty action', () => { let simulatedActionId = ''; let pagerdutySimulatorURL: string = ''; - let proxyServer: any; - let proxyHaveBeenCalled = false; // need to wait for kibanaServer to settle ... before(() => { pagerdutySimulatorURL = kibanaServer.resolveUrl( getExternalServiceSimulatorPath(ExternalServiceSimulator.PAGERDUTY) ); - - proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); }); it('should return successfully when passed valid create parameters', async () => { @@ -106,7 +95,7 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) { }); }); - it('should return unsuccessfully when default pagerduty url is not whitelisted', async () => { + it('should return unsuccessfully when default pagerduty url is not present in allowedHosts', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -121,7 +110,7 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type config: error configuring pagerduty action: target url "https://events.pagerduty.com/v2/enqueue" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'error validating action type config: error configuring pagerduty action: target url "https://events.pagerduty.com/v2/enqueue" is not added to the Kibana config xpack.actions.allowedHosts', }); }); }); @@ -155,7 +144,6 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) { }, }) .expect(200); - expect(proxyHaveBeenCalled).to.equal(true); expect(result).to.eql({ status: 'ok', @@ -215,9 +203,5 @@ export default function pagerdutyTest({ getService }: FtrProviderContext) { expect(result.message).to.match(/error posting pagerduty event: http status 502/); expect(result.retry).to.equal(true); }); - - after(() => { - proxyServer.close(); - }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts index 5085c87550d0..8adaf9f12193 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/resilient.ts @@ -6,7 +6,6 @@ import expect from '@kbn/expect'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -36,7 +35,6 @@ const mapping = [ export default function resilientTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const kibanaServer = getService('kibanaServer'); - const config = getService('config'); const mockResilient = { config: { @@ -75,19 +73,12 @@ export default function resilientTest({ getService }: FtrProviderContext) { }; let resilientSimulatorURL: string = ''; - let proxyServer: any; - let proxyHaveBeenCalled = false; describe('IBM Resilient', () => { before(() => { resilientSimulatorURL = kibanaServer.resolveUrl( getExternalServiceSimulatorPath(ExternalServiceSimulator.RESILIENT) ); - proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); }); describe('IBM Resilient - Action Creation', () => { @@ -175,7 +166,7 @@ export default function resilientTest({ getService }: FtrProviderContext) { }); }); - it('should respond with a 400 Bad Request when creating a ibm resilient action with a non whitelisted apiUrl', async () => { + it('should respond with a 400 Bad Request when creating a ibm resilient action with a not present in allowedHosts apiUrl', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -195,7 +186,7 @@ export default function resilientTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type config: error configuring connector action: target url "http://resilient.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'error validating action type config: error configuring connector action: target url "http://resilient.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', }); }); }); @@ -538,8 +529,6 @@ export default function resilientTest({ getService }: FtrProviderContext) { }) .expect(200); - expect(proxyHaveBeenCalled).to.equal(true); - expect(body).to.eql({ status: 'ok', actionId: simulatedActionId, @@ -553,9 +542,5 @@ export default function resilientTest({ getService }: FtrProviderContext) { }); }); }); - - after(() => { - proxyServer.close(); - }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts index 3c8fc78b7f87..2dad6f2c425e 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts @@ -6,7 +6,6 @@ import expect from '@kbn/expect'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -36,7 +35,6 @@ const mapping = [ export default function servicenowTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); const kibanaServer = getService('kibanaServer'); - const config = getService('config'); const mockServiceNow = { config: { @@ -74,21 +72,12 @@ export default function servicenowTest({ getService }: FtrProviderContext) { }; let servicenowSimulatorURL: string = ''; - let proxyServer: any; - let proxyHaveBeenCalled = false; - // FLAKY: https://github.com/elastic/kibana/issues/75522 - describe.skip('ServiceNow', () => { + describe('ServiceNow', () => { before(() => { servicenowSimulatorURL = kibanaServer.resolveUrl( getExternalServiceSimulatorPath(ExternalServiceSimulator.SERVICENOW) ); - - proxyServer = getHttpProxyServer(kibanaServer.resolveUrl('/'), () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); }); describe('ServiceNow - Action Creation', () => { @@ -157,7 +146,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) { }); }); - it('should respond with a 400 Bad Request when creating a servicenow action with a non whitelisted apiUrl', async () => { + it('should respond with a 400 Bad Request when creating a servicenow action with a not present in allowedHosts apiUrl', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -177,7 +166,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type config: error configuring connector action: target url "http://servicenow.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'error validating action type config: error configuring connector action: target url "http://servicenow.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', }); }); }); @@ -459,7 +448,6 @@ export default function servicenowTest({ getService }: FtrProviderContext) { }, }) .expect(200); - expect(proxyHaveBeenCalled).to.equal(true); expect(result).to.eql({ status: 'ok', @@ -474,9 +462,5 @@ export default function servicenowTest({ getService }: FtrProviderContext) { }); }); }); - - after(() => { - proxyServer.close(); - }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/slack.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/slack.ts index 45f9ba369dc2..1712c31187b0 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/slack.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/slack.ts @@ -7,7 +7,6 @@ import expect from '@kbn/expect'; import http from 'http'; import getPort from 'get-port'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { getSlackServer } from '../../../../common/fixtures/plugins/actions_simulators/server/plugin'; @@ -15,27 +14,20 @@ import { getSlackServer } from '../../../../common/fixtures/plugins/actions_simu // eslint-disable-next-line import/no-default-export export default function slackTest({ getService }: FtrProviderContext) { const supertest = getService('supertest'); - const config = getService('config'); describe('slack action', () => { let simulatedActionId = ''; - let slackSimulatorURL: string = ''; let slackServer: http.Server; - let proxyServer: any; - let proxyHaveBeenCalled = false; + // need to wait for kibanaServer to settle ... before(async () => { slackServer = await getSlackServer(); - const availablePort = await getPort({ port: 9000 }); - slackServer.listen(availablePort); + const availablePort = await getPort({ port: getPort.makeRange(9000, 9100) }); + if (!slackServer.listening) { + slackServer.listen(availablePort); + } slackSimulatorURL = `http://localhost:${availablePort}`; - - proxyServer = getHttpProxyServer(slackSimulatorURL, () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(config.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); }); it('should return 200 when creating a slack action successfully', async () => { @@ -94,7 +86,7 @@ export default function slackTest({ getService }: FtrProviderContext) { }); }); - it('should respond with a 400 Bad Request when creating a slack action with a non whitelisted webhookUrl', async () => { + it('should respond with a 400 Bad Request when creating a slack action with not present in allowedHosts webhookUrl', async () => { await supertest .post('/api/actions/action') .set('kbn-xsrf', 'foo') @@ -111,7 +103,7 @@ export default function slackTest({ getService }: FtrProviderContext) { statusCode: 400, error: 'Bad Request', message: - 'error validating action type secrets: error configuring slack action: target hostname "slack.mynonexistent.com" is not whitelisted in the Kibana config xpack.actions.whitelistedHosts', + 'error validating action type secrets: error configuring slack action: target hostname "slack.mynonexistent.com" is not added to the Kibana config xpack.actions.allowedHosts', }); }); }); @@ -165,7 +157,6 @@ export default function slackTest({ getService }: FtrProviderContext) { }) .expect(200); expect(result.status).to.eql('ok'); - expect(proxyHaveBeenCalled).to.equal(true); }); it('should handle an empty message error', async () => { @@ -233,7 +224,6 @@ export default function slackTest({ getService }: FtrProviderContext) { after(() => { slackServer.close(); - proxyServer.close(); }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/webhook.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/webhook.ts index 896026611043..abebb2650ad0 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/webhook.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/webhook.ts @@ -5,10 +5,9 @@ */ import http from 'http'; -import getPort from 'get-port'; import expect from '@kbn/expect'; import { URL, format as formatUrl } from 'url'; -import { getHttpProxyServer, getProxyUrl } from '../../../../common/lib/get_proxy_server'; +import getPort from 'get-port'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { getExternalServiceSimulatorPath, @@ -32,7 +31,6 @@ function parsePort(url: Record): Record { webhookServer = await getWebhookServer(); - const availablePort = await getPort({ port: 9000 }); + const availablePort = await getPort({ port: getPort.makeRange(9000, 9100) }); webhookServer.listen(availablePort); webhookSimulatorURL = `http://localhost:${availablePort}`; - proxyServer = getHttpProxyServer(webhookSimulatorURL, () => { - proxyHaveBeenCalled = true; - }); - const proxyUrl = getProxyUrl(configService.get('kbnTestServer.serverArgs')); - proxyServer.listen(Number(proxyUrl.port)); - kibanaURL = kibanaServer.resolveUrl( getExternalServiceSimulatorPath(ExternalServiceSimulator.WEBHOOK) ); @@ -150,7 +141,6 @@ export default function webhookTest({ getService }: FtrProviderContext) { .expect(200); expect(result.status).to.eql('ok'); - expect(proxyHaveBeenCalled).to.equal(true); }); it('should support the POST method against webhook target', async () => { @@ -191,7 +181,7 @@ export default function webhookTest({ getService }: FtrProviderContext) { expect(result.status).to.eql('ok'); }); - it('should handle target webhooks that are not whitelisted', async () => { + it('should handle target webhooks that are not added to allowedHosts', async () => { const { body: result } = await supertest .post('/api/actions/action') .set('kbn-xsrf', 'test') @@ -203,13 +193,13 @@ export default function webhookTest({ getService }: FtrProviderContext) { password: 'mypassphrase', }, config: { - url: 'http://a.none.whitelisted.webhook/endpoint', + url: 'http://a.none.allowedHosts.webhook/endpoint', }, }) .expect(400); expect(result.error).to.eql('Bad Request'); - expect(result.message).to.match(/is not whitelisted in the Kibana config/); + expect(result.message).to.match(/is not added to the Kibana config/); }); it('should handle unreachable webhook targets', async () => { @@ -251,7 +241,6 @@ export default function webhookTest({ getService }: FtrProviderContext) { after(() => { webhookServer.close(); - proxyServer.close(); }); }); } diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/execute.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/execute.ts index a45eee400b44..5c4eb5f5d4c5 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/execute.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/execute.ts @@ -344,7 +344,7 @@ export default function ({ getService }: FtrProviderContext) { actionTypeId: '.email', config: { from: 'email-from-1@example.com', - // this host is specifically whitelisted in: + // this host is specifically added to allowedHosts in: // x-pack/test/alerting_api_integration/common/config.ts host: 'some.non.existent.com', port: 666, diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts index 9cdc0c9fa663..54484ba34636 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/index.ts @@ -4,11 +4,24 @@ * you may not use this file except in compliance with the Elastic License. */ +import http from 'http'; +import { getHttpProxyServer } from '../../../common/lib/get_proxy_server'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; // eslint-disable-next-line import/no-default-export -export default function actionsTests({ loadTestFile }: FtrProviderContext) { +export default function actionsTests({ loadTestFile, getService }: FtrProviderContext) { + const configService = getService('config'); + const kibanaServer = getService('kibanaServer'); + const log = getService('log'); describe('Actions', () => { + let proxyServer: http.Server | undefined; + before(async () => { + proxyServer = await getHttpProxyServer( + kibanaServer.resolveUrl('/'), + configService.get('kbnTestServer.serverArgs'), + log + ); + }); loadTestFile(require.resolve('./builtin_action_types/email')); loadTestFile(require.resolve('./builtin_action_types/es_index')); loadTestFile(require.resolve('./builtin_action_types/es_index_preconfigured')); @@ -26,5 +39,11 @@ export default function actionsTests({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./get')); loadTestFile(require.resolve('./list_action_types')); loadTestFile(require.resolve('./update')); + + after(() => { + if (proxyServer) { + proxyServer.close(); + } + }); }); } diff --git a/x-pack/test/case_api_integration/common/config.ts b/x-pack/test/case_api_integration/common/config.ts index 9b048813b479..5d34f8b04981 100644 --- a/x-pack/test/case_api_integration/common/config.ts +++ b/x-pack/test/case_api_integration/common/config.ts @@ -74,10 +74,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) ...xPackApiIntegrationTestsConfig.get('kbnTestServer'), serverArgs: [ ...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'), - `--xpack.actions.whitelistedHosts=${JSON.stringify([ - 'localhost', - 'some.non.existent.com', - ])}`, + `--xpack.actions.allowedHosts=${JSON.stringify(['localhost', 'some.non.existent.com'])}`, `--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`, '--xpack.eventLog.logEntries=true', ...disabledPlugins.map((key) => `--xpack.${key}.enabled=false`), diff --git a/x-pack/test/detection_engine_api_integration/common/config.ts b/x-pack/test/detection_engine_api_integration/common/config.ts index 46fb877e94f2..c21e6d0fdecf 100644 --- a/x-pack/test/detection_engine_api_integration/common/config.ts +++ b/x-pack/test/detection_engine_api_integration/common/config.ts @@ -67,10 +67,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) ...xPackApiIntegrationTestsConfig.get('kbnTestServer'), serverArgs: [ ...xPackApiIntegrationTestsConfig.get('kbnTestServer.serverArgs'), - `--xpack.actions.whitelistedHosts=${JSON.stringify([ - 'localhost', - 'some.non.existent.com', - ])}`, + `--xpack.actions.allowedHosts=${JSON.stringify(['localhost', 'some.non.existent.com'])}`, `--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`, '--xpack.eventLog.logEntries=true', ...disabledPlugins.map((key) => `--xpack.${key}.enabled=false`), diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/index.js b/x-pack/test/ingest_manager_api_integration/apis/epm/index.js index 0a259cb96bf5..855581424590 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/epm/index.js +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/index.js @@ -17,5 +17,6 @@ export default function loadTests({ loadTestFile }) { loadTestFile(require.resolve('./install_update')); loadTestFile(require.resolve('./update_assets')); loadTestFile(require.resolve('./data_stream')); + loadTestFile(require.resolve('./package_install_complete')); }); } diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/install_remove_assets.ts b/x-pack/test/ingest_manager_api_integration/apis/epm/install_remove_assets.ts index e575d7b68030..c7cfee565b2e 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/epm/install_remove_assets.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/install_remove_assets.ts @@ -170,6 +170,9 @@ export default function (providerContext: FtrProviderContext) { version: '0.1.0', internal: false, removable: true, + install_version: '0.1.0', + install_status: 'installed', + install_started_at: res.attributes.install_started_at, }); }); }); diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/install_update.ts b/x-pack/test/ingest_manager_api_integration/apis/epm/install_update.ts index 9de6cd9118fe..bdcd202d8c46 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/epm/install_update.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/install_update.ts @@ -7,6 +7,10 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { skipIfNoDockerRegistry } from '../../helpers'; +import { + PACKAGES_SAVED_OBJECT_TYPE, + MAX_TIME_COMPLETE_INSTALL, +} from '../../../../plugins/ingest_manager/common'; export default function (providerContext: FtrProviderContext) { const { getService } = providerContext; @@ -62,6 +66,12 @@ export default function (providerContext: FtrProviderContext) { .send({ force: true }) .expect(200); }); + it('should return 200 if trying to reinstall an out-of-date package', async function () { + await supertest + .post(`/api/ingest_manager/epm/packages/multiple_versions-0.1.0`) + .set('kbn-xsrf', 'xxxx') + .expect(200); + }); it('should return 400 if trying to update to an out-of-date package', async function () { await supertest .post(`/api/ingest_manager/epm/packages/multiple_versions-0.2.0`) @@ -75,6 +85,24 @@ export default function (providerContext: FtrProviderContext) { .send({ force: true }) .expect(200); }); + it('should return 200 if trying to reupdate an out-of-date package', async function () { + const previousInstallDate = new Date(Date.now() - MAX_TIME_COMPLETE_INSTALL).toISOString(); + // mock package to be stuck installing an update + await kibanaServer.savedObjects.update({ + id: 'multiple_versions', + type: PACKAGES_SAVED_OBJECT_TYPE, + attributes: { + install_status: 'installing', + install_started_at: previousInstallDate, + install_version: '0.2.0', + version: '0.1.0', + }, + }); + await supertest + .post(`/api/ingest_manager/epm/packages/multiple_versions-0.2.0`) + .set('kbn-xsrf', 'xxxx') + .expect(200); + }); it('should return 200 if trying to update to the latest package', async function () { await supertest .post(`/api/ingest_manager/epm/packages/multiple_versions-0.3.0`) diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/package_install_complete.ts b/x-pack/test/ingest_manager_api_integration/apis/epm/package_install_complete.ts new file mode 100644 index 000000000000..dc311c9db191 --- /dev/null +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/package_install_complete.ts @@ -0,0 +1,167 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import expect from '@kbn/expect'; +import { + PACKAGES_SAVED_OBJECT_TYPE, + MAX_TIME_COMPLETE_INSTALL, +} from '../../../../plugins/ingest_manager/common'; +import { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; + +export default function (providerContext: FtrProviderContext) { + const { getService } = providerContext; + const supertest = getService('supertest'); + const kibanaServer = getService('kibanaServer'); + const pkgName = 'multiple_versions'; + const pkgVersion = '0.1.0'; + const pkgUpdateVersion = '0.2.0'; + describe('setup checks packages completed install', async () => { + describe('package install', async () => { + before(async () => { + await supertest + .post(`/api/ingest_manager/epm/packages/${pkgName}-0.1.0`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }); + }); + it('should have not reinstalled if package install completed', async function () { + const packageBeforeSetup = await kibanaServer.savedObjects.get({ + type: 'epm-packages', + id: pkgName, + }); + const installStartedAtBeforeSetup = packageBeforeSetup.attributes.install_started_at; + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(installStartedAtBeforeSetup).equal(installStartedAfterSetup); + }); + it('should have reinstalled if package installing did not complete in elapsed time', async function () { + // change the saved object to installing to mock kibana crashing and not finishing the install + const previousInstallDate = new Date(Date.now() - MAX_TIME_COMPLETE_INSTALL).toISOString(); + await kibanaServer.savedObjects.update({ + id: pkgName, + type: PACKAGES_SAVED_OBJECT_TYPE, + attributes: { + install_status: 'installing', + install_started_at: previousInstallDate, + }, + }); + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(Date.parse(installStartedAfterSetup)).greaterThan(Date.parse(previousInstallDate)); + expect(packageAfterSetup.attributes.install_status).equal('installed'); + }); + it('should have not reinstalled if package installing did not surpass elapsed time', async function () { + // change the saved object to installing to mock package still installing, but a time less than the max time allowable + const previousInstallDate = new Date(Date.now()).toISOString(); + await kibanaServer.savedObjects.update({ + id: pkgName, + type: PACKAGES_SAVED_OBJECT_TYPE, + attributes: { + install_status: 'installing', + install_started_at: previousInstallDate, + }, + }); + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(Date.parse(installStartedAfterSetup)).equal(Date.parse(previousInstallDate)); + expect(packageAfterSetup.attributes.install_status).equal('installing'); + }); + after(async () => { + await supertest + .delete(`/api/ingest_manager/epm/packages/multiple_versions-0.1.0`) + .set('kbn-xsrf', 'xxxx'); + }); + }); + describe('package update', async () => { + before(async () => { + await supertest + .post(`/api/ingest_manager/epm/packages/${pkgName}-0.1.0`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }); + await supertest + .post(`/api/ingest_manager/epm/packages/${pkgName}-0.2.0`) + .set('kbn-xsrf', 'xxxx') + .send({ force: true }); + }); + it('should have not reinstalled if package update completed', async function () { + const packageBeforeSetup = await kibanaServer.savedObjects.get({ + type: 'epm-packages', + id: pkgName, + }); + const installStartedAtBeforeSetup = packageBeforeSetup.attributes.install_started_at; + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(installStartedAtBeforeSetup).equal(installStartedAfterSetup); + }); + it('should have reinstalled if package updating did not complete in elapsed time', async function () { + // change the saved object to installing to mock kibana crashing and not finishing the update + const previousInstallDate = new Date(Date.now() - MAX_TIME_COMPLETE_INSTALL).toISOString(); + await kibanaServer.savedObjects.update({ + id: pkgName, + type: PACKAGES_SAVED_OBJECT_TYPE, + attributes: { + version: pkgVersion, + install_status: 'installing', + install_started_at: previousInstallDate, + install_version: pkgUpdateVersion, // set version back + }, + }); + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(Date.parse(installStartedAfterSetup)).greaterThan(Date.parse(previousInstallDate)); + expect(packageAfterSetup.attributes.install_status).equal('installed'); + expect(packageAfterSetup.attributes.version).equal(pkgUpdateVersion); + expect(packageAfterSetup.attributes.install_version).equal(pkgUpdateVersion); + }); + it('should have not reinstalled if package updating did not surpass elapsed time', async function () { + // change the saved object to installing to mock package still installing, but a time less than the max time allowable + const previousInstallDate = new Date(Date.now()).toISOString(); + await kibanaServer.savedObjects.update({ + id: pkgName, + type: PACKAGES_SAVED_OBJECT_TYPE, + attributes: { + install_status: 'installing', + install_started_at: previousInstallDate, + version: pkgVersion, // set version back + }, + }); + await supertest.post(`/api/ingest_manager/setup`).set('kbn-xsrf', 'xxx').send(); + const packageAfterSetup = await kibanaServer.savedObjects.get({ + type: PACKAGES_SAVED_OBJECT_TYPE, + id: pkgName, + }); + const installStartedAfterSetup = packageAfterSetup.attributes.install_started_at; + expect(Date.parse(installStartedAfterSetup)).equal(Date.parse(previousInstallDate)); + expect(packageAfterSetup.attributes.install_status).equal('installing'); + expect(packageAfterSetup.attributes.version).equal(pkgVersion); + }); + after(async () => { + await supertest + .delete(`/api/ingest_manager/epm/packages/multiple_versions-0.1.0`) + .set('kbn-xsrf', 'xxxx'); + }); + }); + }); +} diff --git a/x-pack/test/ingest_manager_api_integration/apis/epm/update_assets.ts b/x-pack/test/ingest_manager_api_integration/apis/epm/update_assets.ts index 8ad6fe12dcd4..9af27f5f9855 100644 --- a/x-pack/test/ingest_manager_api_integration/apis/epm/update_assets.ts +++ b/x-pack/test/ingest_manager_api_integration/apis/epm/update_assets.ts @@ -322,6 +322,9 @@ export default function (providerContext: FtrProviderContext) { version: '0.2.0', internal: false, removable: true, + install_version: '0.2.0', + install_status: 'installed', + install_started_at: res.attributes.install_started_at, }); }); }); diff --git a/yarn.lock b/yarn.lock index f00bee1d13dc..845685ff36f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13694,10 +13694,10 @@ get-own-enumerable-property-symbols@^3.0.0: resolved "https://registry.yarnpkg.com/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.0.tgz#b877b49a5c16aefac3655f2ed2ea5b684df8d203" integrity sha512-CIJYJC4GGF06TakLg8z4GQKvDsx9EMspVxOYih7LerEL/WosUnFIww45CGfxfeKHqlg3twgUrYRT1O3WQqjGCg== -get-port@^4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119" - integrity sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw== +get-port@^5.0.0: + version "5.1.1" + resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193" + integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ== get-stdin@^4.0.1: version "4.0.1"