= async ({
callES,
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_filter_bar.ts b/x-pack/plugins/uptime/server/lib/requests/get_filter_bar.ts
index 95d23ddcbf466..dbe71cf689214 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_filter_bar.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_filter_bar.ts
@@ -5,7 +5,7 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { OverviewFilters } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { OverviewFilters } from '../../../common/runtime_types';
import { generateFilterAggs } from './generate_filter_aggs';
export interface GetFilterBarParams {
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_index_status.ts b/x-pack/plugins/uptime/server/lib/requests/get_index_status.ts
index 6f7854d35b308..7688f04f1acd9 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_index_status.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_index_status.ts
@@ -5,7 +5,7 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { StatesIndexStatus } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { StatesIndexStatus } from '../../../common/runtime_types';
export const getIndexStatus: UMElasticsearchQueryFn<{}, StatesIndexStatus> = async ({
callES,
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts
index a8e9ccb875a08..98ce449002f21 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_latest_monitor.ts
@@ -5,7 +5,7 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { Ping } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { Ping } from '../../../common/runtime_types';
export interface GetLatestMonitorParams {
/** @member dateRangeStart timestamp bounds */
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts
index 4ce7176b57b19..cf4ffa339ddfc 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_details.ts
@@ -5,10 +5,7 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import {
- MonitorDetails,
- MonitorError,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { MonitorDetails, MonitorError } from '../../../common/runtime_types';
export interface GetMonitorDetailsParams {
monitorId: string;
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts
index e9c745b0a8713..ea2a7e790652b 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_duration.ts
@@ -5,11 +5,8 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { QUERY } from '../../../../../legacy/plugins/uptime/common/constants';
-import {
- LocationDurationLine,
- MonitorDurationResult,
-} from '../../../../../legacy/plugins/uptime/common/types';
+import { LocationDurationLine, MonitorDurationResult } from '../../../common/types';
+import { QUERY } from '../../../common/constants';
export interface GetMonitorChartsParams {
/** @member monitorId ID value for the selected monitor */
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
index f49e404ffb084..c8d3ca043edc5 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_locations.ts
@@ -5,11 +5,8 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { UNNAMED_LOCATION } from '../../../../../legacy/plugins/uptime/common/constants';
-import {
- MonitorLocations,
- MonitorLocation,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { MonitorLocations, MonitorLocation } from '../../../common/runtime_types';
+import { UNNAMED_LOCATION } from '../../../common/constants';
/**
* Fetch data for the monitor page title.
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts b/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts
index 4b40943a85705..b1791dd04861c 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_monitor_states.ts
@@ -4,15 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { CONTEXT_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { CONTEXT_DEFAULTS } from '../../../common/constants';
import { fetchPage } from './search';
import { UMElasticsearchQueryFn } from '../adapters';
-import {
- SortOrder,
- CursorDirection,
- MonitorSummary,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
-
+import { MonitorSummary, SortOrder, CursorDirection } from '../../../common/runtime_types';
import { QueryContext } from './search';
export interface CursorPagination {
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts
index 5a8927764ea5c..299913c8dff08 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_ping_histogram.ts
@@ -5,12 +5,9 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { QUERY } from '../../../../../legacy/plugins/uptime/common/constants';
import { getFilterClause } from '../helper';
-import {
- HistogramResult,
- HistogramQueryResult,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { HistogramResult, HistogramQueryResult } from '../../../common/runtime_types';
+import { QUERY } from '../../../common/constants';
export interface GetPingHistogramParams {
/** @member dateRangeStart timestamp bounds */
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_pings.ts b/x-pack/plugins/uptime/server/lib/requests/get_pings.ts
index 6eccfdb13cef7..a6a0e3c3d6542 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_pings.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_pings.ts
@@ -10,7 +10,7 @@ import {
HttpResponseBody,
PingsResponse,
Ping,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
+} from '../../../common/runtime_types';
const DEFAULT_PAGE_SIZE = 25;
diff --git a/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts b/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts
index 01f2ad88161cf..b57bc87d45418 100644
--- a/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/get_snapshot_counts.ts
@@ -5,8 +5,8 @@
*/
import { UMElasticsearchQueryFn } from '../adapters';
-import { Snapshot } from '../../../../../legacy/plugins/uptime/common/runtime_types';
-import { CONTEXT_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { CONTEXT_DEFAULTS } from '../../../common/constants';
+import { Snapshot } from '../../../common/runtime_types';
import { QueryContext } from './search';
export interface GetSnapshotCountParams {
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/fetch_page.test.ts b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/fetch_page.test.ts
index 2a8f681ab3453..d4ad80c85ec3d 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/fetch_page.test.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/fetch_page.test.ts
@@ -12,7 +12,7 @@ import {
MonitorGroupsPage,
} from '../fetch_page';
import { QueryContext } from '../query_context';
-import { MonitorSummary } from '../../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { MonitorSummary } from '../../../../../common/runtime_types';
import { nextPagination, prevPagination, simpleQueryContext } from './test_helpers';
const simpleFixture: MonitorGroups[] = [
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/query_context.test.ts b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/query_context.test.ts
index 84774cdeed856..e53fff429dd8d 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/query_context.test.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/query_context.test.ts
@@ -6,10 +6,7 @@
import { QueryContext } from '../query_context';
import { CursorPagination } from '../types';
-import {
- CursorDirection,
- SortOrder,
-} from '../../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection, SortOrder } from '../../../../../common/runtime_types';
describe(QueryContext, () => {
// 10 minute range
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/test_helpers.ts b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/test_helpers.ts
index 47034c2130116..40775bde1c7f5 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/__tests__/test_helpers.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/__tests__/test_helpers.ts
@@ -5,10 +5,7 @@
*/
import { CursorPagination } from '../types';
-import {
- CursorDirection,
- SortOrder,
-} from '../../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection, SortOrder } from '../../../../../common/runtime_types';
import { QueryContext } from '../query_context';
export const prevPagination = (key: any): CursorPagination => {
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts b/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts
index 4739c804d24e7..d21259fad77a6 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/enrich_monitor_groups.ts
@@ -6,14 +6,14 @@
import { get, sortBy } from 'lodash';
import { QueryContext } from './query_context';
-import { QUERY, STATES } from '../../../../../../legacy/plugins/uptime/common/constants';
+import { QUERY, STATES } from '../../../../common/constants';
import {
Check,
Histogram,
MonitorSummary,
CursorDirection,
SortOrder,
-} from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+} from '../../../../common/runtime_types';
import { MonitorEnricher } from './fetch_page';
export const enrichMonitorGroups: MonitorEnricher = async (
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/fetch_page.ts b/x-pack/plugins/uptime/server/lib/requests/search/fetch_page.ts
index 84167840d5d9b..bef8106ad1896 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/fetch_page.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/fetch_page.ts
@@ -7,12 +7,8 @@
import { flatten } from 'lodash';
import { CursorPagination } from './types';
import { QueryContext } from './query_context';
-import { QUERY } from '../../../../../../legacy/plugins/uptime/common/constants';
-import {
- CursorDirection,
- MonitorSummary,
- SortOrder,
-} from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { QUERY } from '../../../../common/constants';
+import { CursorDirection, MonitorSummary, SortOrder } from '../../../../common/runtime_types';
import { enrichMonitorGroups } from './enrich_monitor_groups';
import { MonitorGroupIterator } from './monitor_group_iterator';
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts b/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts
index 3449febfa5b05..e60c52660915a 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/find_potential_matches.ts
@@ -5,7 +5,7 @@
*/
import { get, set } from 'lodash';
-import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection } from '../../../../common/runtime_types';
import { QueryContext } from './query_context';
// This is the first phase of the query. In it, we find the most recent check groups that matched the given query.
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/monitor_group_iterator.ts b/x-pack/plugins/uptime/server/lib/requests/search/monitor_group_iterator.ts
index 31d9166eb1e73..2fb9562028258 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/monitor_group_iterator.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/monitor_group_iterator.ts
@@ -6,7 +6,7 @@
import { QueryContext } from './query_context';
import { fetchChunk } from './fetch_chunk';
-import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection } from '../../../../common/runtime_types';
import { MonitorGroups } from './fetch_page';
import { CursorPagination } from './types';
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts b/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts
index 43fc54fb25808..977c32ad1f984 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/refine_potential_matches.ts
@@ -5,7 +5,7 @@
*/
import { QueryContext } from './query_context';
-import { CursorDirection } from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection } from '../../../../common/runtime_types';
import { MonitorGroups, MonitorLocCheckGroup } from './fetch_page';
/**
diff --git a/x-pack/plugins/uptime/server/lib/requests/search/types.ts b/x-pack/plugins/uptime/server/lib/requests/search/types.ts
index 2ec52d400b597..35e9647196454 100644
--- a/x-pack/plugins/uptime/server/lib/requests/search/types.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/search/types.ts
@@ -4,10 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import {
- CursorDirection,
- SortOrder,
-} from '../../../../../../legacy/plugins/uptime/common/runtime_types';
+import { CursorDirection, SortOrder } from '../../../../common/runtime_types';
export interface CursorPagination {
cursorKey?: any;
diff --git a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts
index 84154429b9188..69507d2950cd8 100644
--- a/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts
+++ b/x-pack/plugins/uptime/server/lib/requests/uptime_requests.ts
@@ -8,10 +8,17 @@ import { UMElasticsearchQueryFn } from '../adapters';
import {
HistogramResult,
Ping,
- PingsResponse as PingResults,
+ PingsResponse,
GetCertsParams,
GetPingsParams,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
+ Cert,
+ OverviewFilters,
+ MonitorDetails,
+ MonitorLocations,
+ Snapshot,
+ StatesIndexStatus,
+} from '../../../common/runtime_types';
+import { MonitorDurationResult } from '../../../common/types';
import {
GetFilterBarParams,
GetLatestMonitorParams,
@@ -23,17 +30,8 @@ import {
GetMonitorStatusParams,
GetMonitorStatusResult,
} from '.';
-import {
- OverviewFilters,
- MonitorDetails,
- MonitorLocations,
- Snapshot,
- StatesIndexStatus,
- Cert,
-} from '../../../../../legacy/plugins/uptime/common/runtime_types';
import { GetMonitorStatesResult } from './get_monitor_states';
import { GetSnapshotCountParams } from './get_snapshot_counts';
-import { MonitorDurationResult } from '../../../../../legacy/plugins/uptime/common/types';
type ESQ = UMElasticsearchQueryFn
;
@@ -47,7 +45,7 @@ export interface UptimeRequests {
getMonitorLocations: ESQ;
getMonitorStates: ESQ;
getMonitorStatus: ESQ;
- getPings: ESQ;
+ getPings: ESQ;
getPingHistogram: ESQ;
getSnapshotCount: ESQ;
getIndexStatus: ESQ<{}, StatesIndexStatus>;
diff --git a/x-pack/plugins/uptime/server/lib/saved_objects.ts b/x-pack/plugins/uptime/server/lib/saved_objects.ts
index d849fbd8ce0a8..28b9eaad2cf6f 100644
--- a/x-pack/plugins/uptime/server/lib/saved_objects.ts
+++ b/x-pack/plugins/uptime/server/lib/saved_objects.ts
@@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { DynamicSettings } from '../../../../legacy/plugins/uptime/common/runtime_types';
-import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../legacy/plugins/uptime/common/constants';
+import { DYNAMIC_SETTINGS_DEFAULTS } from '../../common/constants';
+import { DynamicSettings } from '../../common/runtime_types';
import { SavedObjectsType, SavedObjectsErrorHelpers } from '../../../../../src/core/server';
import { UMSavedObjectsQueryFn } from './adapters';
diff --git a/x-pack/plugins/uptime/server/plugin.ts b/x-pack/plugins/uptime/server/plugin.ts
index 7cc591a6b2db1..13d1ae216f204 100644
--- a/x-pack/plugins/uptime/server/plugin.ts
+++ b/x-pack/plugins/uptime/server/plugin.ts
@@ -8,19 +8,20 @@ import {
PluginInitializerContext,
CoreStart,
CoreSetup,
+ Plugin as PluginType,
ISavedObjectsRepository,
} from '../../../../src/core/server';
import { initServerWithKibana } from './kibana.index';
import { KibanaTelemetryAdapter, UptimeCorePlugins } from './lib/adapters';
import { umDynamicSettings } from './lib/saved_objects';
-export class Plugin {
+export class Plugin implements PluginType {
private savedObjectsClient?: ISavedObjectsRepository;
constructor(_initializerContext: PluginInitializerContext) {}
public setup(core: CoreSetup, plugins: UptimeCorePlugins) {
- initServerWithKibana({ route: core.http.createRouter() }, plugins);
+ initServerWithKibana({ router: core.http.createRouter() }, plugins);
core.savedObjects.registerType(umDynamicSettings);
KibanaTelemetryAdapter.registerUsageCollector(
plugins.usageCollection,
@@ -28,7 +29,9 @@ export class Plugin {
);
}
- public start(_core: CoreStart, _plugins: any) {
- this.savedObjectsClient = _core.savedObjects.createInternalRepository();
+ public start(core: CoreStart, _plugins: any) {
+ this.savedObjectsClient = core.savedObjects.createInternalRepository();
}
+
+ public stop() {}
}
diff --git a/x-pack/plugins/uptime/server/rest_api/certs.ts b/x-pack/plugins/uptime/server/rest_api/certs.ts
index 31fb3f4ab96a7..f2e1700b23e7d 100644
--- a/x-pack/plugins/uptime/server/rest_api/certs.ts
+++ b/x-pack/plugins/uptime/server/rest_api/certs.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../lib/lib';
import { UMRestApiRouteFactory } from '.';
-import { API_URLS } from '../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../common/constants';
const DEFAULT_INDEX = 0;
const DEFAULT_SIZE = 25;
diff --git a/x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts b/x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts
index 3f4e2fc345182..31833a25ee8ac 100644
--- a/x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts
+++ b/x-pack/plugins/uptime/server/rest_api/dynamic_settings.ts
@@ -8,10 +8,7 @@ import { schema } from '@kbn/config-schema';
import { isRight } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { UMServerLibs } from '../lib/lib';
-import {
- DynamicSettings,
- DynamicSettingsType,
-} from '../../../../legacy/plugins/uptime/common/runtime_types';
+import { DynamicSettings, DynamicSettingsType } from '../../common/runtime_types';
import { UMRestApiRouteFactory } from '.';
import { savedObjectsAdapter } from '../lib/saved_objects';
diff --git a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_pattern.ts b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_pattern.ts
index 689a75c5903a6..26715f0ff37b6 100644
--- a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_pattern.ts
+++ b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_pattern.ts
@@ -6,7 +6,7 @@
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
export const createGetIndexPatternRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts
index 8ed73d90b2389..9a4280efa98f9 100644
--- a/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts
+++ b/x-pack/plugins/uptime/server/rest_api/index_state/get_index_status.ts
@@ -6,7 +6,7 @@
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../common/constants';
export const createGetIndexStatusRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts
index 5cb4e8a6241b7..60b3eafaa765e 100644
--- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts
+++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_list.ts
@@ -6,8 +6,7 @@
import { schema } from '@kbn/config-schema';
import { UMRestApiRouteFactory } from '../types';
-import { CONTEXT_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS, CONTEXT_DEFAULTS } from '../../../common/constants';
export const createMonitorListRoute: UMRestApiRouteFactory = libs => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts
index 66ce9871506d4..a110209043a7e 100644
--- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts
+++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_locations.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
export const createGetMonitorLocationsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts
index 9cf1340fb9409..bb002f8a8c286 100644
--- a/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts
+++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitor_status.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../common/constants';
export const createGetStatusBarRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts
index 1cc010781457e..69e719efb0719 100644
--- a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts
+++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_details.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
export const createGetMonitorDetailsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts
index 9743ced13350a..34313211061b0 100644
--- a/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts
+++ b/x-pack/plugins/uptime/server/rest_api/monitors/monitors_durations.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
export const createGetMonitorDurationRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/overview_filters/get_overview_filters.ts b/x-pack/plugins/uptime/server/rest_api/overview_filters/get_overview_filters.ts
index deac05f36c8dc..00cbaf0d16723 100644
--- a/x-pack/plugins/uptime/server/rest_api/overview_filters/get_overview_filters.ts
+++ b/x-pack/plugins/uptime/server/rest_api/overview_filters/get_overview_filters.ts
@@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
import { objectValuesToArrays } from '../../lib/helper';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
const arrayOrStringType = schema.maybe(
schema.oneOf([schema.string(), schema.arrayOf(schema.string())])
diff --git a/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts b/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts
index dceef5ecb7848..41078f735920b 100644
--- a/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts
+++ b/x-pack/plugins/uptime/server/rest_api/pings/get_ping_histogram.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
+import { API_URLS } from '../../../common/constants';
export const createGetPingHistogramRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts b/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts
index 80a887a7f64a9..d97195a7fe2b1 100644
--- a/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts
+++ b/x-pack/plugins/uptime/server/rest_api/pings/get_pings.ts
@@ -9,8 +9,8 @@ import { isLeft } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants/rest_api';
-import { GetPingsParamsType } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { API_URLS } from '../../../common/constants';
+import { GetPingsParamsType } from '../../../common/runtime_types';
export const createGetPingsRoute: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts b/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts
index d870f49280117..7809e102a499f 100644
--- a/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts
+++ b/x-pack/plugins/uptime/server/rest_api/snapshot/get_snapshot_count.ts
@@ -7,7 +7,7 @@
import { schema } from '@kbn/config-schema';
import { UMServerLibs } from '../../lib/lib';
import { UMRestApiRouteFactory } from '../types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../common/constants';
export const createGetSnapshotCount: UMRestApiRouteFactory = (libs: UMServerLibs) => ({
method: 'GET',
diff --git a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts
index 4b2db71037071..d8387e79e9089 100644
--- a/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts
+++ b/x-pack/plugins/uptime/server/rest_api/telemetry/log_page_view.ts
@@ -8,7 +8,7 @@ import { schema } from '@kbn/config-schema';
import { KibanaTelemetryAdapter } from '../../lib/adapters/telemetry';
import { UMRestApiRouteFactory } from '../types';
import { PageViewParams } from '../../lib/adapters/telemetry/types';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../common/constants';
export const createLogPageViewRoute: UMRestApiRouteFactory = () => ({
method: 'POST',
diff --git a/x-pack/plugins/uptime/server/rest_api/types.ts b/x-pack/plugins/uptime/server/rest_api/types.ts
index e05e7a4d7faf1..8720b9dc60b12 100644
--- a/x-pack/plugins/uptime/server/rest_api/types.ts
+++ b/x-pack/plugins/uptime/server/rest_api/types.ts
@@ -15,8 +15,8 @@ import {
KibanaRequest,
KibanaResponseFactory,
IKibanaResponse,
-} from 'src/core/server';
-import { DynamicSettings } from '../../../../legacy/plugins/uptime/common/runtime_types';
+} from 'kibana/server';
+import { DynamicSettings } from '../../common/runtime_types';
import { UMServerLibs } from '../lib/lib';
/**
diff --git a/x-pack/test/api_integration/apis/uptime/feature_controls.ts b/x-pack/test/api_integration/apis/uptime/feature_controls.ts
index 6d125807e169d..6c566ec7cb23b 100644
--- a/x-pack/test/api_integration/apis/uptime/feature_controls.ts
+++ b/x-pack/test/api_integration/apis/uptime/feature_controls.ts
@@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { PINGS_DATE_RANGE_END, PINGS_DATE_RANGE_START } from './constants';
-import { API_URLS } from '../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../../plugins/uptime/common/constants';
export default function featureControlsTests({ getService }: FtrProviderContext) {
const supertest = getService('supertestWithoutAuth');
diff --git a/x-pack/test/api_integration/apis/uptime/rest/certs.ts b/x-pack/test/api_integration/apis/uptime/rest/certs.ts
index 7510ea3f34d28..a3a15d8f8b014 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/certs.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/certs.ts
@@ -8,8 +8,8 @@ import expect from '@kbn/expect';
import moment from 'moment';
import { isRight } from 'fp-ts/lib/Either';
import { FtrProviderContext } from '../../../ftr_provider_context';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
-import { CertType } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { API_URLS } from '../../../../../plugins/uptime/common/constants';
+import { CertType } from '../../../../../plugins/uptime/common/runtime_types';
import { makeChecksWithStatus } from './helper/make_checks';
export default function({ getService }: FtrProviderContext) {
diff --git a/x-pack/test/api_integration/apis/uptime/rest/doc_count.ts b/x-pack/test/api_integration/apis/uptime/rest/doc_count.ts
index 5258426cf193c..f343cd1da8788 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/doc_count.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/doc_count.ts
@@ -5,7 +5,7 @@
*/
import { FtrProviderContext } from '../../../ftr_provider_context';
import { expectFixtureEql } from './helper/expect_fixture_eql';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../../../plugins/uptime/common/constants';
export default function({ getService }: FtrProviderContext) {
describe('docCount query', () => {
diff --git a/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts b/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts
index ea980721b831b..95caf50d1ca7a 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/dynamic_settings.ts
@@ -7,9 +7,8 @@
import expect from '@kbn/expect';
import { isRight } from 'fp-ts/lib/Either';
import { FtrProviderContext } from '../../../ftr_provider_context';
-import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../legacy/plugins/uptime/common/constants';
-import { DynamicSettingsType } from '../../../../../legacy/plugins/uptime/common/runtime_types';
-
+import { DynamicSettingsType } from '../../../../../plugins/uptime/common/runtime_types';
+import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../plugins/uptime/common/constants';
export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
diff --git a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_generated.ts b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_generated.ts
index 3c17370532f91..c3d5849e028ab 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_generated.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_generated.ts
@@ -7,8 +7,8 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { makeChecksWithStatus } from './helper/make_checks';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
-import { MonitorSummary } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { MonitorSummary } from '../../../../../plugins/uptime/common/runtime_types';
+import { API_URLS } from '../../../../../plugins/uptime/common/constants';
export default function({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
diff --git a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts
index f1e37bff405fd..c5a691312f525 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/monitor_states_real_data.ts
@@ -7,8 +7,8 @@
import expect from '@kbn/expect';
import { isRight } from 'fp-ts/lib/Either';
import { FtrProviderContext } from '../../../ftr_provider_context';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
-import { MonitorSummaryResultType } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { MonitorSummaryResultType } from '../../../../../plugins/uptime/common/runtime_types';
+import { API_URLS } from '../../../../../plugins/uptime/common/constants';
interface ExpectedMonitorStatesPage {
response: any;
diff --git a/x-pack/test/api_integration/apis/uptime/rest/ping_list.ts b/x-pack/test/api_integration/apis/uptime/rest/ping_list.ts
index a261763d5991f..3d754d89cf9be 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/ping_list.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/ping_list.ts
@@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import { isLeft } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
-import { PingsResponseType } from '../../../../../legacy/plugins/uptime/common/runtime_types';
+import { PingsResponseType } from '../../../../../plugins/uptime/common/runtime_types';
import { FtrProviderContext } from '../../../ftr_provider_context';
function decodePingsResponseData(response: any) {
diff --git a/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts b/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts
index 017ef02afe5ea..99e09aa5ce886 100644
--- a/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts
+++ b/x-pack/test/api_integration/apis/uptime/rest/telemetry_collectors.ts
@@ -6,7 +6,7 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';
-import { API_URLS } from '../../../../../legacy/plugins/uptime/common/constants';
+import { API_URLS } from '../../../../../plugins/uptime/common/constants';
import { makeChecksWithStatus } from './helper/make_checks';
export default function({ getService }: FtrProviderContext) {
diff --git a/x-pack/test/functional/apps/uptime/settings.ts b/x-pack/test/functional/apps/uptime/settings.ts
index 64b6300e0df63..7a813a5cdfb52 100644
--- a/x-pack/test/functional/apps/uptime/settings.ts
+++ b/x-pack/test/functional/apps/uptime/settings.ts
@@ -6,8 +6,8 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
-import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../legacy/plugins/uptime/common/constants';
-import { DynamicSettings } from '../../../../legacy/plugins/uptime/common/runtime_types';
+import { DynamicSettings } from '../../../../plugins/uptime/common/runtime_types';
+import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../plugins/uptime/common/constants';
import { makeChecks } from '../../../api_integration/apis/uptime/rest/helper/make_checks';
export default ({ getPageObjects, getService }: FtrProviderContext) => {
diff --git a/x-pack/test/functional/services/uptime/settings.ts b/x-pack/test/functional/services/uptime/settings.ts
index 9719152b62d35..96f5e45ce2ca4 100644
--- a/x-pack/test/functional/services/uptime/settings.ts
+++ b/x-pack/test/functional/services/uptime/settings.ts
@@ -5,7 +5,7 @@
*/
import { FtrProviderContext } from '../../ftr_provider_context';
-import { DynamicSettings } from '../../../../legacy/plugins/uptime/common/runtime_types';
+import { DynamicSettings } from '../../../../plugins/uptime/common/runtime_types';
export function UptimeSettingsProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
From a38c11cd10577a69d3c06ba7829358531a29ac90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?=
Date: Wed, 29 Apr 2020 13:58:27 +0200
Subject: [PATCH 11/33] [ML] Changes Machine learning overview UI text (#64625)
Co-Authored-By: Lisa Cawley
---
.../components/analytics_panel/analytics_panel.tsx | 4 ++--
.../anomaly_detection_panel.tsx | 2 +-
.../application/overview/components/sidebar.tsx | 13 ++-----------
x-pack/plugins/translations/translations/ja-JP.json | 3 +--
x-pack/plugins/translations/translations/zh-CN.json | 3 +--
5 files changed, 7 insertions(+), 18 deletions(-)
diff --git a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/analytics_panel.tsx b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/analytics_panel.tsx
index b2eda12abc578..c379cd702daee 100644
--- a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/analytics_panel.tsx
+++ b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/analytics_panel.tsx
@@ -82,14 +82,14 @@ export const AnalyticsPanel: FC = ({ jobCreationDisabled }) => {
title={
{i18n.translate('xpack.ml.overview.analyticsList.createFirstJobMessage', {
- defaultMessage: 'Create your first analytics job',
+ defaultMessage: 'Create your first data frame analytics job',
})}
}
body={
{i18n.translate('xpack.ml.overview.analyticsList.emptyPromptText', {
- defaultMessage: `Data frame analytics enable you to perform different analyses of your data and annotate it with the results. The analytics job stores the annotated data, as well as a copy of the source data, in a new index.`,
+ defaultMessage: `Data frame analytics enable you to perform different analyses of your data and annotates it with the results. The job puts the annotated data and a copy of the source data in a new index.`,
})}
}
diff --git a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/anomaly_detection_panel.tsx b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/anomaly_detection_panel.tsx
index 5f5c3f7c28670..dac39b1a2071d 100644
--- a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/anomaly_detection_panel.tsx
+++ b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/anomaly_detection_panel.tsx
@@ -172,7 +172,7 @@ export const AnomalyDetectionPanel: FC = ({ jobCreationDisabled }) => {
{i18n.translate('xpack.ml.overview.anomalyDetection.emptyPromptText', {
- defaultMessage: `Machine learning makes it easy to detect anomalies in time series data stored in Elasticsearch. Track one metric from a single machine or hundreds of metrics across thousands of machines. Start automatically spotting the anomalies hiding in your data and resolve issues faster.`,
+ defaultMessage: `Anomaly detection enables you to find unusual behavior in time series data. Start automatically spotting the anomalies hiding in your data and resolve issues faster.`,
})}
diff --git a/x-pack/plugins/ml/public/application/overview/components/sidebar.tsx b/x-pack/plugins/ml/public/application/overview/components/sidebar.tsx
index 219c195bab111..3e4e9cfbd2b66 100644
--- a/x-pack/plugins/ml/public/application/overview/components/sidebar.tsx
+++ b/x-pack/plugins/ml/public/application/overview/components/sidebar.tsx
@@ -11,7 +11,6 @@ import { useMlKibana } from '../../contexts/kibana';
const createJobLink = '#/jobs/new_job/step/index_or_search';
const feedbackLink = 'https://www.elastic.co/community/';
-const whatIsMachineLearningLink = 'https://www.elastic.co/what-is/elasticsearch-machine-learning';
interface Props {
createAnomalyDetectionJobDisabled: boolean;
@@ -60,7 +59,7 @@ export const OverviewSideBar: FC = ({ createAnomalyDetectionJobDisabled }
@@ -79,14 +78,6 @@ export const OverviewSideBar: FC = ({ createAnomalyDetectionJobDisabled }
/>
),
- whatIsMachineLearning: (
-
-
-
- ),
}}
/>
@@ -96,7 +87,7 @@ export const OverviewSideBar: FC = ({ createAnomalyDetectionJobDisabled }
diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json
index fd986ca0851d6..8974f0b5b4d58 100644
--- a/x-pack/plugins/translations/translations/ja-JP.json
+++ b/x-pack/plugins/translations/translations/ja-JP.json
@@ -10505,10 +10505,9 @@
"xpack.ml.overview.feedbackSectionTitle": "フィードバック",
"xpack.ml.overview.gettingStartedSectionCreateJob": "新規ジョブを作成中",
"xpack.ml.overview.gettingStartedSectionDocs": "ドキュメンテーション",
- "xpack.ml.overview.gettingStartedSectionText": "機械学習へようこそ。はじめに{docs}や{createJob}をご参照ください。Elastic Stackの機械学習の詳細については、{whatIsMachineLearning}をご覧ください。{transforms}を使用して、分析ジョブの機能インデックスを作成することをお勧めします。",
+ "xpack.ml.overview.gettingStartedSectionText": "機械学習へようこそ。はじめに{docs}や{createJob}をご参照ください。{transforms}を使用して、分析ジョブの機能インデックスを作成することをお勧めします。",
"xpack.ml.overview.gettingStartedSectionTitle": "はじめて使う",
"xpack.ml.overview.gettingStartedSectionTransforms": "Elasticsearchの変換",
- "xpack.ml.overview.gettingStartedSectionWhatIsMachineLearning": "こちら",
"xpack.ml.overview.overviewLabel": "概要",
"xpack.ml.overview.statsBar.failedAnalyticsLabel": "失敗",
"xpack.ml.overview.statsBar.runningAnalyticsLabel": "実行中",
diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json
index 162251f20c5c0..d36a62f15aee9 100644
--- a/x-pack/plugins/translations/translations/zh-CN.json
+++ b/x-pack/plugins/translations/translations/zh-CN.json
@@ -10508,10 +10508,9 @@
"xpack.ml.overview.feedbackSectionTitle": "反馈",
"xpack.ml.overview.gettingStartedSectionCreateJob": "创建新作业",
"xpack.ml.overview.gettingStartedSectionDocs": "文档",
- "xpack.ml.overview.gettingStartedSectionText": "欢迎使用 Machine Learning。首先阅读我们的{docs}或{createJob}。有关 Elastic Stack 中的机器学习的详情,请参阅{whatIsMachineLearning}。建议使用 {transforms}为分析作业创建功能索引。",
+ "xpack.ml.overview.gettingStartedSectionText": "欢迎使用 Machine Learning。首先阅读我们的{docs}或{createJob}。建议使用 {transforms}为分析作业创建功能索引。",
"xpack.ml.overview.gettingStartedSectionTitle": "入门",
"xpack.ml.overview.gettingStartedSectionTransforms": "Elasticsearch 的转换",
- "xpack.ml.overview.gettingStartedSectionWhatIsMachineLearning": "此处",
"xpack.ml.overview.overviewLabel": "概览",
"xpack.ml.overview.statsBar.failedAnalyticsLabel": "失败",
"xpack.ml.overview.statsBar.runningAnalyticsLabel": "正在运行",
From da4c33b022096b7d72930acea7ee1ce49d5230bc Mon Sep 17 00:00:00 2001
From: Marta Bondyra
Date: Wed, 29 Apr 2020 14:47:45 +0200
Subject: [PATCH 12/33] [Lens] Don't use auto interval to get interval for
single bar (#64502)
* feat: don't use auto interval to get interval for single bar
* fix: fixing non auto intervals
Co-authored-by: Elastic Machine
---
.../lens/public/xy_visualization/index.ts | 1 +
.../xy_visualization/xy_expression.test.tsx | 32 +++++++++++++++++--
.../public/xy_visualization/xy_expression.tsx | 25 +++++++++++----
3 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/x-pack/plugins/lens/public/xy_visualization/index.ts b/x-pack/plugins/lens/public/xy_visualization/index.ts
index 5dfae097be834..3a280fb045b06 100644
--- a/x-pack/plugins/lens/public/xy_visualization/index.ts
+++ b/x-pack/plugins/lens/public/xy_visualization/index.ts
@@ -53,6 +53,7 @@ export class XyVisualization {
? EUI_CHARTS_THEME_DARK.theme
: EUI_CHARTS_THEME_LIGHT.theme,
timeZone: getTimeZone(core.uiSettings),
+ histogramBarTarget: core.uiSettings.get('histogram:barTarget'),
})
);
diff --git a/x-pack/plugins/lens/public/xy_visualization/xy_expression.test.tsx b/x-pack/plugins/lens/public/xy_visualization/xy_expression.test.tsx
index e75e5fe763d6a..8db00aba0e36d 100644
--- a/x-pack/plugins/lens/public/xy_visualization/xy_expression.test.tsx
+++ b/x-pack/plugins/lens/public/xy_visualization/xy_expression.test.tsx
@@ -40,7 +40,7 @@ const createSampleDatatableWithRows = (rows: KibanaDatatableRow[]): KibanaDatata
id: 'c',
name: 'c',
formatHint: { id: 'string' },
- meta: { type: 'date-histogram', aggConfigParams: { interval: '10s' } },
+ meta: { type: 'date-histogram', aggConfigParams: { interval: 'auto' } },
},
{ id: 'd', name: 'ColD', formatHint: { id: 'string' } },
],
@@ -156,6 +156,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -203,6 +204,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -237,15 +239,17 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
+ // real auto interval is 30mins = 1800000
expect(component.find(Settings).prop('xDomain')).toMatchInlineSnapshot(`
Object {
"max": 1546491600000,
"min": 1546405200000,
- "minInterval": 10000,
+ "minInterval": 1728000,
}
`);
});
@@ -271,6 +275,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -279,7 +284,7 @@ describe('xy_expression', () => {
Object {
"max": 1546491600000,
"min": 1546405200000,
- "minInterval": 10000,
+ "minInterval": 1728000,
}
`);
});
@@ -307,6 +312,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -350,6 +356,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -383,6 +390,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -398,6 +406,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -414,6 +423,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -430,6 +440,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -472,6 +483,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -510,6 +522,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -527,6 +540,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -547,6 +561,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -565,6 +580,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="CEST"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -582,6 +598,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -606,6 +623,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -624,6 +642,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -684,6 +703,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -878,6 +898,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -894,6 +915,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -910,6 +932,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -927,6 +950,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
@@ -943,6 +967,7 @@ describe('xy_expression', () => {
args={{ ...args, layers: [{ ...args.layers[0], accessors: ['a'] }] }}
formatFactory={getFormatSpy}
chartTheme={{}}
+ histogramBarTarget={50}
timeZone="UTC"
executeTriggerActions={executeTriggerActions}
/>
@@ -963,6 +988,7 @@ describe('xy_expression', () => {
formatFactory={getFormatSpy}
timeZone="UTC"
chartTheme={{}}
+ histogramBarTarget={50}
executeTriggerActions={executeTriggerActions}
/>
);
diff --git a/x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx b/x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
index d6b6de479acfb..85cf5753befd7 100644
--- a/x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
+++ b/x-pack/plugins/lens/public/xy_visualization/xy_expression.tsx
@@ -6,6 +6,7 @@
import React, { useState, useEffect } from 'react';
import ReactDOM from 'react-dom';
+import moment from 'moment';
import {
Chart,
Settings,
@@ -35,8 +36,8 @@ import { XYArgs, SeriesType, visualizationTypes } from './types';
import { VisualizationContainer } from '../visualization_container';
import { isHorizontalChart } from './state_helpers';
import { UiActionsStart } from '../../../../../src/plugins/ui_actions/public';
-import { parseInterval } from '../../../../../src/plugins/data/common';
import { getExecuteTriggerActions } from './services';
+import { parseInterval } from '../../../../../src/plugins/data/common';
type InferPropType = T extends React.FunctionComponent ? P : T;
type SeriesSpec = InferPropType &
@@ -58,6 +59,7 @@ type XYChartRenderProps = XYChartProps & {
chartTheme: PartialTheme;
formatFactory: FormatFactory;
timeZone: string;
+ histogramBarTarget: number;
executeTriggerActions: UiActionsStart['executeTriggerActions'];
};
@@ -110,6 +112,7 @@ export const xyChart: ExpressionFunctionDefinition<
export const getXyChartRenderer = (dependencies: {
formatFactory: Promise;
chartTheme: PartialTheme;
+ histogramBarTarget: number;
timeZone: string;
}): ExpressionRenderDefinition => ({
name: 'lens_xy_chart_renderer',
@@ -130,6 +133,7 @@ export const getXyChartRenderer = (dependencies: {
formatFactory={formatFactory}
chartTheme={dependencies.chartTheme}
timeZone={dependencies.timeZone}
+ histogramBarTarget={dependencies.histogramBarTarget}
executeTriggerActions={executeTriggerActions}
/>
,
@@ -169,6 +173,7 @@ export function XYChart({
formatFactory,
timeZone,
chartTheme,
+ histogramBarTarget,
executeTriggerActions,
}: XYChartRenderProps) {
const { legend, layers } = args;
@@ -212,18 +217,26 @@ export function XYChart({
const xTitle = (xAxisColumn && xAxisColumn.name) || args.xTitle;
- // add minInterval only for single row value as it cannot be determined from dataset
+ function calculateMinInterval() {
+ // add minInterval only for single row value as it cannot be determined from dataset
+ if (data.dateRange && layers.every(layer => data.tables[layer.layerId].rows.length <= 1)) {
+ if (xAxisColumn?.meta?.aggConfigParams?.interval !== 'auto')
+ return parseInterval(xAxisColumn?.meta?.aggConfigParams?.interval)?.asMilliseconds();
- const minInterval = layers.every(layer => data.tables[layer.layerId].rows.length <= 1)
- ? parseInterval(xAxisColumn?.meta?.aggConfigParams?.interval)?.asMilliseconds()
- : undefined;
+ const { fromDate, toDate } = data.dateRange;
+ const duration = moment(toDate).diff(moment(fromDate));
+ const targetMs = duration / histogramBarTarget;
+ return isNaN(targetMs) ? 0 : Math.max(Math.floor(targetMs), 1);
+ }
+ return undefined;
+ }
const xDomain =
data.dateRange && layers.every(l => l.xScaleType === 'time')
? {
min: data.dateRange.fromDate.getTime(),
max: data.dateRange.toDate.getTime(),
- minInterval,
+ minInterval: calculateMinInterval(),
}
: undefined;
return (
From f1d72ad1274d0a442747ae450dc08380769d8000 Mon Sep 17 00:00:00 2001
From: Larry Gregory
Date: Wed, 29 Apr 2020 08:52:33 -0400
Subject: [PATCH 13/33] Expose security license on setup (#64651)
---
x-pack/legacy/plugins/security/index.ts | 4 +--
x-pack/plugins/security/server/mocks.ts | 2 ++
x-pack/plugins/security/server/plugin.test.ts | 30 +++++++++----------
x-pack/plugins/security/server/plugin.ts | 6 ++--
4 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/x-pack/legacy/plugins/security/index.ts b/x-pack/legacy/plugins/security/index.ts
index 5b2218af1fd52..b1dec2ce82c52 100644
--- a/x-pack/legacy/plugins/security/index.ts
+++ b/x-pack/legacy/plugins/security/index.ts
@@ -78,9 +78,7 @@ export const security = (kibana: Record) =>
// features are up to date.
xpackInfo
.feature(this.id)
- .registerLicenseCheckResultsGenerator(() =>
- securityPlugin.__legacyCompat.license.getFeatures()
- );
+ .registerLicenseCheckResultsGenerator(() => securityPlugin.license.getFeatures());
server.expose({
getUser: async (request: LegacyRequest) =>
diff --git a/x-pack/plugins/security/server/mocks.ts b/x-pack/plugins/security/server/mocks.ts
index ababf12c2be60..a6407366bbd3b 100644
--- a/x-pack/plugins/security/server/mocks.ts
+++ b/x-pack/plugins/security/server/mocks.ts
@@ -8,6 +8,7 @@ import { SecurityPluginSetup } from './plugin';
import { authenticationMock } from './authentication/index.mock';
import { authorizationMock } from './authorization/index.mock';
+import { licenseMock } from '../common/licensing/index.mock';
function createSetupMock() {
const mockAuthz = authorizationMock.create();
@@ -19,6 +20,7 @@ function createSetupMock() {
mode: mockAuthz.mode,
},
registerSpacesService: jest.fn(),
+ license: licenseMock.create(),
__legacyCompat: {} as SecurityPluginSetup['__legacyCompat'],
};
}
diff --git a/x-pack/plugins/security/server/plugin.test.ts b/x-pack/plugins/security/server/plugin.test.ts
index 22a30f03c646a..d58c999ddccdf 100644
--- a/x-pack/plugins/security/server/plugin.test.ts
+++ b/x-pack/plugins/security/server/plugin.test.ts
@@ -50,21 +50,6 @@ describe('Security Plugin', () => {
await expect(plugin.setup(mockCoreSetup, mockDependencies)).resolves.toMatchInlineSnapshot(`
Object {
"__legacyCompat": Object {
- "license": Object {
- "features$": Observable {
- "_isScalar": false,
- "operator": MapOperator {
- "project": [Function],
- "thisArg": undefined,
- },
- "source": Observable {
- "_isScalar": false,
- "_subscribe": [Function],
- },
- },
- "getFeatures": [Function],
- "isEnabled": [Function],
- },
"registerLegacyAPI": [Function],
"registerPrivilegesWithCluster": [Function],
},
@@ -103,6 +88,21 @@ describe('Security Plugin', () => {
"useRbacForRequest": [Function],
},
},
+ "license": Object {
+ "features$": Observable {
+ "_isScalar": false,
+ "operator": MapOperator {
+ "project": [Function],
+ "thisArg": undefined,
+ },
+ "source": Observable {
+ "_isScalar": false,
+ "_subscribe": [Function],
+ },
+ },
+ "getFeatures": [Function],
+ "isEnabled": [Function],
+ },
"registerSpacesService": [Function],
}
`);
diff --git a/x-pack/plugins/security/server/plugin.ts b/x-pack/plugins/security/server/plugin.ts
index e30b0caf76ddc..97f5aea888dc7 100644
--- a/x-pack/plugins/security/server/plugin.ts
+++ b/x-pack/plugins/security/server/plugin.ts
@@ -59,6 +59,7 @@ export interface SecurityPluginSetup {
| 'invalidateAPIKeyAsInternalUser'
>;
authz: Pick;
+ license: SecurityLicense;
/**
* If Spaces plugin is available it's supposed to register its SpacesService with Security plugin
@@ -73,7 +74,6 @@ export interface SecurityPluginSetup {
__legacyCompat: {
registerLegacyAPI: (legacyAPI: LegacyAPI) => void;
registerPrivilegesWithCluster: () => void;
- license: SecurityLicense;
};
}
@@ -194,6 +194,8 @@ export class Plugin {
mode: authz.mode,
},
+ license,
+
registerSpacesService: service => {
if (this.wasSpacesServiceAccessed()) {
throw new Error('Spaces service has been accessed before registration.');
@@ -206,8 +208,6 @@ export class Plugin {
registerLegacyAPI: (legacyAPI: LegacyAPI) => (this.legacyAPI = legacyAPI),
registerPrivilegesWithCluster: async () => await authz.registerPrivilegesWithCluster(),
-
- license,
},
});
}
From 2c7741bba335aa3d91fc073ac88cfebc57263efb Mon Sep 17 00:00:00 2001
From: Sonja Krause-Harder
Date: Wed, 29 Apr 2020 15:36:39 +0200
Subject: [PATCH 14/33] [EPM] Handle object type fields with properties in
mappings (#64745)
* Generate correct mapping for object type field with properties
* Add test for fields definition in reverse order
---
.../elasticsearch/template/template.test.ts | 50 +++++++++++++++++++
.../server/services/epm/fields/field.test.ts | 31 ++++++++++++
.../server/services/epm/fields/field.ts | 10 +++-
3 files changed, 90 insertions(+), 1 deletion(-)
diff --git a/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/template.test.ts b/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/template.test.ts
index 1a73c9581a2de..3679c577ee571 100644
--- a/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/template.test.ts
+++ b/x-pack/plugins/ingest_manager/server/services/epm/elasticsearch/template/template.test.ts
@@ -259,3 +259,53 @@ test('tests processing object field with dynamic set to strict', () => {
const mappings = generateMappings(processedFields);
expect(JSON.stringify(mappings)).toEqual(JSON.stringify(objectFieldDynamicStrictMapping));
});
+
+test('tests processing object field with property', () => {
+ const objectFieldWithPropertyLiteralYml = `
+- name: a
+ type: object
+- name: a.b
+ type: keyword
+ `;
+ const objectFieldWithPropertyMapping = {
+ properties: {
+ a: {
+ properties: {
+ b: {
+ ignore_above: 1024,
+ type: 'keyword',
+ },
+ },
+ },
+ },
+ };
+ const fields: Field[] = safeLoad(objectFieldWithPropertyLiteralYml);
+ const processedFields = processFields(fields);
+ const mappings = generateMappings(processedFields);
+ expect(JSON.stringify(mappings)).toEqual(JSON.stringify(objectFieldWithPropertyMapping));
+});
+
+test('tests processing object field with property, reverse order', () => {
+ const objectFieldWithPropertyReversedLiteralYml = `
+- name: a.b
+ type: keyword
+- name: a
+ type: object
+ `;
+ const objectFieldWithPropertyReversedMapping = {
+ properties: {
+ a: {
+ properties: {
+ b: {
+ ignore_above: 1024,
+ type: 'keyword',
+ },
+ },
+ },
+ },
+ };
+ const fields: Field[] = safeLoad(objectFieldWithPropertyReversedLiteralYml);
+ const processedFields = processFields(fields);
+ const mappings = generateMappings(processedFields);
+ expect(JSON.stringify(mappings)).toEqual(JSON.stringify(objectFieldWithPropertyReversedMapping));
+});
diff --git a/x-pack/plugins/ingest_manager/server/services/epm/fields/field.test.ts b/x-pack/plugins/ingest_manager/server/services/epm/fields/field.test.ts
index e3aef6077dbc3..42989bb1e3ac9 100644
--- a/x-pack/plugins/ingest_manager/server/services/epm/fields/field.test.ts
+++ b/x-pack/plugins/ingest_manager/server/services/epm/fields/field.test.ts
@@ -179,4 +179,35 @@ describe('processFields', () => {
JSON.stringify(mixedFieldsExpanded)
);
});
+
+ const objectFieldWithProperty = [
+ {
+ name: 'a',
+ type: 'object',
+ dynamic: true,
+ },
+ {
+ name: 'a.b',
+ type: 'keyword',
+ },
+ ];
+
+ const objectFieldWithPropertyExpanded = [
+ {
+ name: 'a',
+ type: 'group',
+ dynamic: true,
+ fields: [
+ {
+ name: 'b',
+ type: 'keyword',
+ },
+ ],
+ },
+ ];
+ test('correctly handles properties of object type fields', () => {
+ expect(JSON.stringify(processFields(objectFieldWithProperty))).toEqual(
+ JSON.stringify(objectFieldWithPropertyExpanded)
+ );
+ });
});
diff --git a/x-pack/plugins/ingest_manager/server/services/epm/fields/field.ts b/x-pack/plugins/ingest_manager/server/services/epm/fields/field.ts
index 9c9843e0454ab..edf7624d3f0d5 100644
--- a/x-pack/plugins/ingest_manager/server/services/epm/fields/field.ts
+++ b/x-pack/plugins/ingest_manager/server/services/epm/fields/field.ts
@@ -108,7 +108,15 @@ function dedupFields(fields: Fields): Fields {
return f.name === field.name;
});
if (found) {
- if (found.type === 'group' && field.type === 'group' && found.fields && field.fields) {
+ if (
+ (found.type === 'group' || found.type === 'object') &&
+ field.type === 'group' &&
+ field.fields
+ ) {
+ if (!found.fields) {
+ found.fields = [];
+ }
+ found.type = 'group';
found.fields = dedupFields(found.fields.concat(field.fields));
} else {
// only 'group' fields can be merged in this way
From ac61783a2d70b3a6c7184a1a6591ec74ddb9ffbc Mon Sep 17 00:00:00 2001
From: Corey Robertson
Date: Wed, 29 Apr 2020 09:49:25 -0400
Subject: [PATCH 15/33] [CANVAS] Adds Canvas Platform Service (#64453)
* Adds Canvas Platform Service
* Fix type check
Co-authored-by: Elastic Machine
---
.../components/app/track_route_change.js | 18 ++++++++-----
x-pack/legacy/plugins/canvas/public/legacy.ts | 2 --
.../plugins/canvas/public/lib/breadcrumbs.ts | 4 +--
.../public/lib/custom_element_service.ts | 4 +--
.../canvas/public/lib/documentation_links.ts | 10 +++----
.../plugins/canvas/public/lib/es_service.ts | 8 +++---
.../canvas/public/lib/workpad_service.js | 8 +++---
.../legacy/plugins/canvas/public/plugin.tsx | 19 +++++++++++---
.../plugins/canvas/public/services/index.ts | 4 ++-
.../canvas/public/services/platform.ts | 24 +++++++++++++++++
.../canvas/public/state/initial_state.js | 4 +--
.../canvas/public/state/reducers/workpad.js | 26 +++++++++++--------
12 files changed, 88 insertions(+), 43 deletions(-)
create mode 100644 x-pack/legacy/plugins/canvas/public/services/platform.ts
diff --git a/x-pack/legacy/plugins/canvas/public/components/app/track_route_change.js b/x-pack/legacy/plugins/canvas/public/components/app/track_route_change.js
index e837f5200a159..2886aa868eb9e 100644
--- a/x-pack/legacy/plugins/canvas/public/components/app/track_route_change.js
+++ b/x-pack/legacy/plugins/canvas/public/components/app/track_route_change.js
@@ -7,13 +7,17 @@
import { get } from 'lodash';
import { getWindow } from '../../lib/get_window';
import { CANVAS_APP } from '../../../common/lib/constants';
-import { getCoreStart, getStartPlugins } from '../../legacy';
+import { platformService } from '../../services';
export function trackRouteChange() {
- const basePath = getCoreStart().http.basePath.get();
- // storage.set(LOCALSTORAGE_LASTPAGE, pathname);
- getStartPlugins().__LEGACY.trackSubUrlForApp(
- CANVAS_APP,
- getStartPlugins().__LEGACY.absoluteToParsedUrl(get(getWindow(), 'location.href'), basePath)
- );
+ const basePath = platformService.getService().coreStart.http.basePath.get();
+
+ platformService
+ .getService()
+ .startPlugins.__LEGACY.trackSubUrlForApp(
+ CANVAS_APP,
+ platformService
+ .getService()
+ .startPlugins.__LEGACY.absoluteToParsedUrl(get(getWindow(), 'location.href'), basePath)
+ );
}
diff --git a/x-pack/legacy/plugins/canvas/public/legacy.ts b/x-pack/legacy/plugins/canvas/public/legacy.ts
index 5bb628909c32e..f83887bbcbdfd 100644
--- a/x-pack/legacy/plugins/canvas/public/legacy.ts
+++ b/x-pack/legacy/plugins/canvas/public/legacy.ts
@@ -35,8 +35,6 @@ const shimStartPlugins: CanvasStartDeps = {
__LEGACY: {
// ToDo: Copy directly into canvas
absoluteToParsedUrl,
- // ToDo: Copy directly into canvas
- formatMsg,
// ToDo: Won't be a part of New Platform. Will need to handle internally
trackSubUrlForApp: chrome.trackSubUrlForApp,
},
diff --git a/x-pack/legacy/plugins/canvas/public/lib/breadcrumbs.ts b/x-pack/legacy/plugins/canvas/public/lib/breadcrumbs.ts
index 834d5868c35ea..57b513affd781 100644
--- a/x-pack/legacy/plugins/canvas/public/lib/breadcrumbs.ts
+++ b/x-pack/legacy/plugins/canvas/public/lib/breadcrumbs.ts
@@ -5,7 +5,7 @@
*/
import { ChromeBreadcrumb } from '../../../../../../src/core/public';
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
export const getBaseBreadcrumb = () => ({
text: 'Canvas',
@@ -24,6 +24,6 @@ export const getWorkpadBreadcrumb = ({
};
export const setBreadcrumb = (paths: ChromeBreadcrumb | ChromeBreadcrumb[]) => {
- const setBreadCrumbs = getCoreStart().chrome.setBreadcrumbs;
+ const setBreadCrumbs = platformService.getService().coreStart.chrome.setBreadcrumbs;
setBreadCrumbs(Array.isArray(paths) ? paths : [paths]);
};
diff --git a/x-pack/legacy/plugins/canvas/public/lib/custom_element_service.ts b/x-pack/legacy/plugins/canvas/public/lib/custom_element_service.ts
index 4118bb81b8363..8952802dc2f2b 100644
--- a/x-pack/legacy/plugins/canvas/public/lib/custom_element_service.ts
+++ b/x-pack/legacy/plugins/canvas/public/lib/custom_element_service.ts
@@ -8,10 +8,10 @@ import { AxiosPromise } from 'axios';
import { API_ROUTE_CUSTOM_ELEMENT } from '../../common/lib/constants';
import { fetch } from '../../common/lib/fetch';
import { CustomElement } from '../../types';
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
const getApiPath = function() {
- const basePath = getCoreStart().http.basePath.get();
+ const basePath = platformService.getService().coreStart.http.basePath.get();
return `${basePath}${API_ROUTE_CUSTOM_ELEMENT}`;
};
diff --git a/x-pack/legacy/plugins/canvas/public/lib/documentation_links.ts b/x-pack/legacy/plugins/canvas/public/lib/documentation_links.ts
index 40e09ee39d714..6430f7d87d4f7 100644
--- a/x-pack/legacy/plugins/canvas/public/lib/documentation_links.ts
+++ b/x-pack/legacy/plugins/canvas/public/lib/documentation_links.ts
@@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
export const getDocumentationLinks = () => ({
- canvas: `${getCoreStart().docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${
- getCoreStart().docLinks.DOC_LINK_VERSION
+ canvas: `${platformService.getService().coreStart.docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${
+ platformService.getService().coreStart.docLinks.DOC_LINK_VERSION
}/canvas.html`,
- numeral: `${getCoreStart().docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${
- getCoreStart().docLinks.DOC_LINK_VERSION
+ numeral: `${platformService.getService().coreStart.docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${
+ platformService.getService().coreStart.docLinks.DOC_LINK_VERSION
}/guide/numeral.html`,
});
diff --git a/x-pack/legacy/plugins/canvas/public/lib/es_service.ts b/x-pack/legacy/plugins/canvas/public/lib/es_service.ts
index 6aa4968f29155..184f4f3c8af7c 100644
--- a/x-pack/legacy/plugins/canvas/public/lib/es_service.ts
+++ b/x-pack/legacy/plugins/canvas/public/lib/es_service.ts
@@ -11,21 +11,21 @@ import { API_ROUTE } from '../../common/lib/constants';
import { fetch } from '../../common/lib/fetch';
import { ErrorStrings } from '../../i18n';
import { notifyService } from '../services';
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
const { esService: strings } = ErrorStrings;
const getApiPath = function() {
- const basePath = getCoreStart().http.basePath.get();
+ const basePath = platformService.getService().coreStart.http.basePath.get();
return basePath + API_ROUTE;
};
const getSavedObjectsClient = function() {
- return getCoreStart().savedObjects.client;
+ return platformService.getService().coreStart.savedObjects.client;
};
const getAdvancedSettings = function() {
- return getCoreStart().uiSettings;
+ return platformService.getService().coreStart.uiSettings;
};
export const getFields = (index = '_all') => {
diff --git a/x-pack/legacy/plugins/canvas/public/lib/workpad_service.js b/x-pack/legacy/plugins/canvas/public/lib/workpad_service.js
index f3681f50c56a5..e6628399f53c2 100644
--- a/x-pack/legacy/plugins/canvas/public/lib/workpad_service.js
+++ b/x-pack/legacy/plugins/canvas/public/lib/workpad_service.js
@@ -11,7 +11,7 @@ import {
DEFAULT_WORKPAD_CSS,
} from '../../common/lib/constants';
import { fetch } from '../../common/lib/fetch';
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
/*
Remove any top level keys from the workpad which will be rejected by validation
*/
@@ -43,17 +43,17 @@ const sanitizeWorkpad = function(workpad) {
};
const getApiPath = function() {
- const basePath = getCoreStart().http.basePath.get();
+ const basePath = platformService.getService().coreStart.http.basePath.get();
return `${basePath}${API_ROUTE_WORKPAD}`;
};
const getApiPathStructures = function() {
- const basePath = getCoreStart().http.basePath.get();
+ const basePath = platformService.getService().coreStart.http.basePath.get();
return `${basePath}${API_ROUTE_WORKPAD_STRUCTURES}`;
};
const getApiPathAssets = function() {
- const basePath = getCoreStart().http.basePath.get();
+ const basePath = platformService.getService().coreStart.http.basePath.get();
return `${basePath}${API_ROUTE_WORKPAD_ASSETS}`;
};
diff --git a/x-pack/legacy/plugins/canvas/public/plugin.tsx b/x-pack/legacy/plugins/canvas/public/plugin.tsx
index 36ce1974be272..baeb4ebd453d2 100644
--- a/x-pack/legacy/plugins/canvas/public/plugin.tsx
+++ b/x-pack/legacy/plugins/canvas/public/plugin.tsx
@@ -44,7 +44,6 @@ export interface CanvasStartDeps {
uiActions: UiActionsStart;
__LEGACY: {
absoluteToParsedUrl: (url: string, basePath: string) => any;
- formatMsg: any;
trackSubUrlForApp: Chrome['trackSubUrlForApp'];
};
}
@@ -64,6 +63,7 @@ export class CanvasPlugin
implements Plugin {
// TODO: Do we want to completely move canvas_plugin_src into it's own plugin?
private srcPlugin = new CanvasSrcPlugin();
+ private startPlugins: CanvasStartDeps | undefined;
public setup(core: CoreSetup, plugins: CanvasSetupDeps) {
const { api: canvasApi, registries } = getPluginApi(plugins.expressions);
@@ -73,14 +73,26 @@ export class CanvasPlugin
core.application.register({
id: 'canvas',
title: 'Canvas App',
- async mount(context, params) {
+ mount: async (context, params) => {
// Load application bundle
const { renderApp, initializeCanvas, teardownCanvas } = await import('./application');
// Get start services
const [coreStart, depsStart] = await core.getStartServices();
- const canvasStore = await initializeCanvas(core, coreStart, plugins, depsStart, registries);
+ // TODO: We only need this to get the __LEGACY stuff that isn't coming from getStartSevices.
+ // We won't need this as soon as we move over to NP Completely
+ if (!this.startPlugins) {
+ throw new Error('Start Plugins not ready at mount time');
+ }
+
+ const canvasStore = await initializeCanvas(
+ core,
+ coreStart,
+ plugins,
+ this.startPlugins,
+ registries
+ );
const unmount = renderApp(coreStart, depsStart, params, canvasStore);
@@ -115,6 +127,7 @@ export class CanvasPlugin
}
public start(core: CoreStart, plugins: CanvasStartDeps) {
+ this.startPlugins = plugins;
this.srcPlugin.start(core, plugins);
initLoadingIndicator(core.http.addLoadingCountSource);
}
diff --git a/x-pack/legacy/plugins/canvas/public/services/index.ts b/x-pack/legacy/plugins/canvas/public/services/index.ts
index 12c0a687bf308..17d836f1441c9 100644
--- a/x-pack/legacy/plugins/canvas/public/services/index.ts
+++ b/x-pack/legacy/plugins/canvas/public/services/index.ts
@@ -7,6 +7,7 @@
import { CoreSetup, CoreStart } from '../../../../../../src/core/public';
import { CanvasSetupDeps, CanvasStartDeps } from '../plugin';
import { notifyServiceFactory } from './notify';
+import { platformServiceFactory } from './platform';
export type CanvasServiceFactory = (
coreSetup: CoreSetup,
@@ -49,6 +50,7 @@ export type ServiceFromProvider = P extends CanvasServiceProvider ?
export const services = {
notify: new CanvasServiceProvider(notifyServiceFactory),
+ platform: new CanvasServiceProvider(platformServiceFactory),
};
export interface CanvasServices {
@@ -70,4 +72,4 @@ export const stopServices = () => {
Object.entries(services).forEach(([key, provider]) => provider.stop());
};
-export const { notify: notifyService } = services;
+export const { notify: notifyService, platform: platformService } = services;
diff --git a/x-pack/legacy/plugins/canvas/public/services/platform.ts b/x-pack/legacy/plugins/canvas/public/services/platform.ts
new file mode 100644
index 0000000000000..440e9523044c1
--- /dev/null
+++ b/x-pack/legacy/plugins/canvas/public/services/platform.ts
@@ -0,0 +1,24 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { CanvasServiceFactory } from '.';
+import { CoreStart, CoreSetup, CanvasSetupDeps, CanvasStartDeps } from '../plugin';
+
+interface PlatformService {
+ coreSetup: CoreSetup;
+ coreStart: CoreStart;
+ setupPlugins: CanvasSetupDeps;
+ startPlugins: CanvasStartDeps;
+}
+
+export const platformServiceFactory: CanvasServiceFactory = (
+ coreSetup,
+ coreStart,
+ setupPlugins,
+ startPlugins
+) => {
+ return { coreSetup, coreStart, setupPlugins, startPlugins };
+};
diff --git a/x-pack/legacy/plugins/canvas/public/state/initial_state.js b/x-pack/legacy/plugins/canvas/public/state/initial_state.js
index 40c017543147f..bfa68b33908e0 100644
--- a/x-pack/legacy/plugins/canvas/public/state/initial_state.js
+++ b/x-pack/legacy/plugins/canvas/public/state/initial_state.js
@@ -5,7 +5,7 @@
*/
import { get } from 'lodash';
-import { getCoreStart } from '../legacy';
+import { platformService } from '../services';
import { getDefaultWorkpad } from './defaults';
export const getInitialState = path => {
@@ -13,7 +13,7 @@ export const getInitialState = path => {
app: {}, // Kibana stuff in here
assets: {}, // assets end up here
transient: {
- canUserWrite: getCoreStart().application.capabilities.canvas.save,
+ canUserWrite: platformService.getService().coreStart.application.capabilities.canvas.save,
zoomScale: 1,
elementStats: {
total: 0,
diff --git a/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js b/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js
index 12733680ed32d..30f9c638a054f 100644
--- a/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js
+++ b/x-pack/legacy/plugins/canvas/public/state/reducers/workpad.js
@@ -5,7 +5,7 @@
*/
import { handleActions } from 'redux-actions';
-import { getCoreStart } from '../../legacy';
+import { platformService } from '../../services';
import { getDefaultWorkpad } from '../defaults';
import {
setWorkpad,
@@ -22,11 +22,13 @@ import { APP_ROUTE_WORKPAD } from '../../../common/lib/constants';
export const workpadReducer = handleActions(
{
[setWorkpad]: (workpadState, { payload }) => {
- getCoreStart().chrome.recentlyAccessed.add(
- `${APP_ROUTE_WORKPAD}/${payload.id}`,
- payload.name,
- payload.id
- );
+ platformService
+ .getService()
+ .coreStart.chrome.recentlyAccessed.add(
+ `${APP_ROUTE_WORKPAD}/${payload.id}`,
+ payload.name,
+ payload.id
+ );
return payload;
},
@@ -39,11 +41,13 @@ export const workpadReducer = handleActions(
},
[setName]: (workpadState, { payload }) => {
- getCoreStart().chrome.recentlyAccessed.add(
- `${APP_ROUTE_WORKPAD}/${workpadState.id}`,
- payload,
- workpadState.id
- );
+ platformService
+ .getService()
+ .coreStart.chrome.recentlyAccessed.add(
+ `${APP_ROUTE_WORKPAD}/${workpadState.id}`,
+ payload,
+ workpadState.id
+ );
return { ...workpadState, name: payload };
},
From 30e41c5d8f9ebf9fcc5dade55d277314b7aee1ee Mon Sep 17 00:00:00 2001
From: Frank Hassanabad
Date: Wed, 29 Apr 2020 08:25:12 -0600
Subject: [PATCH 16/33] Update codeowners for endpoint and siem
## Summary
* Update codeowners for endpoint and SIEM
* Remove legacy stuff
---
.github/CODEOWNERS | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index cee2f32c2cb9e..9e74daa13513d 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -208,22 +208,21 @@
/x-pack/plugins/watcher/ @elastic/es-ui
# Endpoint
-/x-pack/plugins/endpoint/ @elastic/endpoint-app-team
-/x-pack/test/api_integration/apis/endpoint/ @elastic/endpoint-app-team
-/x-pack/test/endpoint_api_integration_no_ingest/ @elastic/endpoint-app-team
-/x-pack/test/functional_endpoint/ @elastic/endpoint-app-team
-/x-pack/test/functional_endpoint_ingest_failure/ @elastic/endpoint-app-team
-/x-pack/test/functional/es_archives/endpoint/ @elastic/endpoint-app-team
-/x-pack/test/plugin_functional/plugins/resolver_test/ @elastic/endpoint-app-team
-/x-pack/test/plugin_functional/test_suites/resolver/ @elastic/endpoint-app-team
+/x-pack/plugins/endpoint/ @elastic/endpoint-app-team @elastic/siem
+/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/functional_endpoint/ @elastic/endpoint-app-team @elastic/siem
+/x-pack/test/functional_endpoint_ingest_failure/ @elastic/endpoint-app-team @elastic/siem
+/x-pack/test/functional/es_archives/endpoint/ @elastic/endpoint-app-team @elastic/siem
+/x-pack/test/plugin_functional/plugins/resolver_test/ @elastic/endpoint-app-team @elastic/siem
+/x-pack/test/plugin_functional/test_suites/resolver/ @elastic/endpoint-app-team @elastic/siem
# SIEM
-/x-pack/legacy/plugins/siem/ @elastic/siem
-/x-pack/plugins/siem/ @elastic/siem
-/x-pack/test/detection_engine_api_integration @elastic/siem
-/x-pack/test/api_integration/apis/siem @elastic/siem
-/x-pack/plugins/case @elastic/siem
-/x-pack/plugins/lists @elastic/siem
+/x-pack/plugins/siem/ @elastic/siem @elastic/endpoint-app-team
+/x-pack/test/detection_engine_api_integration @elastic/siem @elastic/endpoint-app-team
+/x-pack/test/api_integration/apis/siem @elastic/siem @elastic/endpoint-app-team
+/x-pack/plugins/case @elastic/siem @elastic/endpoint-app-team
+/x-pack/plugins/lists @elastic/siem @elastic/endpoint-app-team
# Security Intelligence And Analytics
/x-pack/plugins/siem/server/lib/detection_engine/rules/prepackaged_rules @elastic/security-intelligence-analytics
From 9fe722935738de887d8fa244d556cc41e55a38bd Mon Sep 17 00:00:00 2001
From: Gidi Meir Morris
Date: Wed, 29 Apr 2020 15:46:54 +0100
Subject: [PATCH 17/33] [Alerting] migrates all remaining plugins to new
platform (#64335)
Completes the migration of all Alerting Services plugins onto the Kibana Platform
It includes:
1. Actions plugin
2. Alerting plugin
3. Task Manager plugin
4. Triggers UI plugin
And touches the Uptime and Siem plugins as their use of the Task Manager relied on some of the legacy lifecycle to work (registering AlertTypes and Telemetry tasks after the Start stage has already began). The fix was simply to moves these registrations to the Setup stage.
---
.github/CODEOWNERS | 3 -
x-pack/index.js | 6 -
x-pack/legacy/plugins/actions/server/index.ts | 38 ---
x-pack/legacy/plugins/alerting/index.ts | 7 -
.../legacy/plugins/alerting/server/index.ts | 40 ---
.../plugins/monitoring/common/constants.ts | 2 +-
.../plugins/task_manager/server/index.ts | 22 +-
.../plugins/triggers_actions_ui/index.ts | 34 ---
.../triggers_actions_ui/public/index.scss | 2 -
x-pack/plugins/actions/server/plugin.ts | 15 +-
.../actions/server/saved_objects/index.ts | 42 +++
.../server/saved_objects}/mappings.json | 0
x-pack/plugins/alerting/server/plugin.ts | 13 +-
.../alerting/server/saved_objects/index.ts | 33 +++
.../server/saved_objects}/mappings.json | 0
x-pack/plugins/monitoring/common/constants.ts | 2 +-
.../scripts/get_action_instances.sh | 2 +-
.../scripts/get_action_types.sh | 2 +-
x-pack/plugins/task_manager/server/plugin.ts | 21 +-
.../server/saved_objects/index.ts | 23 ++
.../server/saved_objects}/mappings.json | 0
.../server/saved_objects}/migrations.ts | 0
.../task_manager/server/task_manager.ts | 8 +-
.../builtin_action_types/servicenow.ts | 2 +-
.../actions/builtin_action_types/slack.ts | 2 +-
.../actions/builtin_action_types/webhook.ts | 2 +-
.../alerting_api_integration/common/config.ts | 5 +-
.../common/fixtures/plugins/aad/index.ts | 2 +-
.../{actions => actions_simulators}/README.md | 0
.../{actions => actions_simulators}/index.ts | 2 +-
.../package.json | 0
.../pagerduty_simulation.ts | 0
.../servicenow_simulation.ts | 0
.../slack_simulation.ts | 0
.../webhook_simulation.ts | 0
.../common/fixtures/plugins/alerts/index.ts | 4 +-
.../fixtures/plugins/task_manager/index.ts | 2 +-
.../actions/builtin_action_types/pagerduty.ts | 2 +-
.../builtin_action_types/servicenow.ts | 2 +-
.../actions/builtin_action_types/slack.ts | 2 +-
.../actions/builtin_action_types/webhook.ts | 2 +-
.../actions/builtin_action_types/webhook.ts | 2 +-
.../common/config.ts | 1 -
x-pack/test/functional_with_es_ssl/config.ts | 2 -
.../plugins/sample_task_plugin/kibana.json | 9 +
.../plugins/sample_task_plugin/package.json | 18 ++
.../sample_task_plugin/server}/index.ts | 4 +-
.../sample_task_plugin/server/init_routes.ts | 252 ++++++++++++++++++
.../sample_task_plugin/server/plugin.ts | 164 ++++++++++++
.../plugins/task_manager/index.js | 150 -----------
.../plugins/task_manager/init_routes.js | 236 ----------------
.../plugins/task_manager/package.json | 12 -
.../task_manager/task_manager_integration.js | 21 +-
53 files changed, 587 insertions(+), 628 deletions(-)
delete mode 100644 x-pack/legacy/plugins/actions/server/index.ts
delete mode 100644 x-pack/legacy/plugins/alerting/index.ts
delete mode 100644 x-pack/legacy/plugins/alerting/server/index.ts
delete mode 100644 x-pack/legacy/plugins/triggers_actions_ui/index.ts
delete mode 100644 x-pack/legacy/plugins/triggers_actions_ui/public/index.scss
create mode 100644 x-pack/plugins/actions/server/saved_objects/index.ts
rename x-pack/{legacy/plugins/actions/server => plugins/actions/server/saved_objects}/mappings.json (100%)
create mode 100644 x-pack/plugins/alerting/server/saved_objects/index.ts
rename x-pack/{legacy/plugins/alerting/server => plugins/alerting/server/saved_objects}/mappings.json (100%)
create mode 100644 x-pack/plugins/task_manager/server/saved_objects/index.ts
rename x-pack/{legacy/plugins/task_manager/server => plugins/task_manager/server/saved_objects}/mappings.json (100%)
rename x-pack/{legacy/plugins/task_manager/server => plugins/task_manager/server/saved_objects}/migrations.ts (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/README.md (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/index.ts (98%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/package.json (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/pagerduty_simulation.ts (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/servicenow_simulation.ts (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/slack_simulation.ts (100%)
rename x-pack/test/alerting_api_integration/common/fixtures/plugins/{actions => actions_simulators}/webhook_simulation.ts (100%)
create mode 100644 x-pack/test/plugin_api_integration/plugins/sample_task_plugin/kibana.json
create mode 100644 x-pack/test/plugin_api_integration/plugins/sample_task_plugin/package.json
rename x-pack/{legacy/plugins/actions => test/plugin_api_integration/plugins/sample_task_plugin/server}/index.ts (65%)
create mode 100644 x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/init_routes.ts
create mode 100644 x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/plugin.ts
delete mode 100644 x-pack/test/plugin_api_integration/plugins/task_manager/index.js
delete mode 100644 x-pack/test/plugin_api_integration/plugins/task_manager/init_routes.js
delete mode 100644 x-pack/test/plugin_api_integration/plugins/task_manager/package.json
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 9e74daa13513d..a97400ee09c0e 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -166,8 +166,6 @@
/x-pack/plugins/telemetry_collection_xpack/ @elastic/pulse
# Kibana Alerting Services
-/x-pack/legacy/plugins/alerting/ @elastic/kibana-alerting-services
-/x-pack/legacy/plugins/actions/ @elastic/kibana-alerting-services
/x-pack/plugins/alerting/ @elastic/kibana-alerting-services
/x-pack/plugins/actions/ @elastic/kibana-alerting-services
/x-pack/plugins/event_log/ @elastic/kibana-alerting-services
@@ -175,7 +173,6 @@
/x-pack/test/alerting_api_integration/ @elastic/kibana-alerting-services
/x-pack/test/plugin_api_integration/plugins/task_manager/ @elastic/kibana-alerting-services
/x-pack/test/plugin_api_integration/test_suites/task_manager/ @elastic/kibana-alerting-services
-/x-pack/legacy/plugins/triggers_actions_ui/ @elastic/kibana-alerting-services
/x-pack/plugins/triggers_actions_ui/ @elastic/kibana-alerting-services
/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
diff --git a/x-pack/index.js b/x-pack/index.js
index a4142e24e4aeb..cfadddac3994a 100644
--- a/x-pack/index.js
+++ b/x-pack/index.js
@@ -17,10 +17,7 @@ import { canvas } from './legacy/plugins/canvas';
import { infra } from './legacy/plugins/infra';
import { taskManager } from './legacy/plugins/task_manager';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
-import { actions } from './legacy/plugins/actions';
-import { alerting } from './legacy/plugins/alerting';
import { ingestManager } from './legacy/plugins/ingest_manager';
-import { triggersActionsUI } from './legacy/plugins/triggers_actions_ui';
module.exports = function(kibana) {
return [
@@ -37,9 +34,6 @@ module.exports = function(kibana) {
infra(kibana),
taskManager(kibana),
encryptedSavedObjects(kibana),
- actions(kibana),
- alerting(kibana),
ingestManager(kibana),
- triggersActionsUI(kibana),
];
};
diff --git a/x-pack/legacy/plugins/actions/server/index.ts b/x-pack/legacy/plugins/actions/server/index.ts
deleted file mode 100644
index 63dd6f99f9c24..0000000000000
--- a/x-pack/legacy/plugins/actions/server/index.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-import { Root } from 'joi';
-import { Legacy } from 'kibana';
-import mappings from './mappings.json';
-import {
- LegacyPluginApi,
- LegacyPluginSpec,
- ArrayOrItem,
-} from '../../../../../src/legacy/plugin_discovery/types';
-
-export function actions(kibana: LegacyPluginApi): ArrayOrItem {
- return new kibana.Plugin({
- id: 'actions',
- configPrefix: 'xpack.actions',
- config(Joi: Root) {
- return Joi.object({
- enabled: Joi.boolean().default(true),
- })
- .unknown(true)
- .default();
- },
- require: ['kibana', 'elasticsearch'],
- isEnabled(config: Legacy.KibanaConfig) {
- return (
- config.get('xpack.encryptedSavedObjects.enabled') === true &&
- config.get('xpack.actions.enabled') === true &&
- config.get('xpack.task_manager.enabled') === true
- );
- },
- uiExports: {
- mappings,
- },
- } as Legacy.PluginSpecOptions);
-}
diff --git a/x-pack/legacy/plugins/alerting/index.ts b/x-pack/legacy/plugins/alerting/index.ts
deleted file mode 100644
index 0d0a698841269..0000000000000
--- a/x-pack/legacy/plugins/alerting/index.ts
+++ /dev/null
@@ -1,7 +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.
- */
-
-export * from './server';
diff --git a/x-pack/legacy/plugins/alerting/server/index.ts b/x-pack/legacy/plugins/alerting/server/index.ts
deleted file mode 100644
index 065af7dedebd9..0000000000000
--- a/x-pack/legacy/plugins/alerting/server/index.ts
+++ /dev/null
@@ -1,40 +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 { Legacy } from 'kibana';
-import { Root } from 'joi';
-import mappings from './mappings.json';
-import {
- LegacyPluginApi,
- LegacyPluginSpec,
- ArrayOrItem,
-} from '../../../../../src/legacy/plugin_discovery/types';
-
-export function alerting(kibana: LegacyPluginApi): ArrayOrItem {
- return new kibana.Plugin({
- id: 'alerting',
- configPrefix: 'xpack.alerting',
- require: ['kibana', 'elasticsearch', 'actions', 'task_manager', 'encryptedSavedObjects'],
- isEnabled(config: Legacy.KibanaConfig) {
- return (
- config.get('xpack.alerting.enabled') === true &&
- config.get('xpack.actions.enabled') === true &&
- config.get('xpack.encryptedSavedObjects.enabled') === true &&
- config.get('xpack.task_manager.enabled') === true
- );
- },
- config(Joi: Root) {
- return Joi.object()
- .keys({
- enabled: Joi.boolean().default(true),
- })
- .default();
- },
- uiExports: {
- mappings,
- },
- } as Legacy.PluginSpecOptions);
-}
diff --git a/x-pack/legacy/plugins/monitoring/common/constants.ts b/x-pack/legacy/plugins/monitoring/common/constants.ts
index 3a4c7b71dcd03..36030e1fa7f2a 100644
--- a/x-pack/legacy/plugins/monitoring/common/constants.ts
+++ b/x-pack/legacy/plugins/monitoring/common/constants.ts
@@ -251,7 +251,7 @@ export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION, ALERT_TYPE_CLUSTER_ST
/**
* Matches the id for the built-in in email action type
- * See x-pack/legacy/plugins/actions/server/builtin_action_types/email.ts
+ * See x-pack/plugins/actions/server/builtin_action_types/email.ts
*/
export const ALERT_ACTION_TYPE_EMAIL = '.email';
diff --git a/x-pack/legacy/plugins/task_manager/server/index.ts b/x-pack/legacy/plugins/task_manager/server/index.ts
index 3ea687f7003f4..a3167920efa06 100644
--- a/x-pack/legacy/plugins/task_manager/server/index.ts
+++ b/x-pack/legacy/plugins/task_manager/server/index.ts
@@ -6,8 +6,6 @@
import { Root } from 'joi';
import { Legacy } from 'kibana';
-import mappings from './mappings.json';
-import { migrations } from './migrations';
import { createLegacyApi, getTaskManagerSetup } from './legacy';
export { LegacyTaskManagerApi, getTaskManagerSetup, getTaskManagerStart } from './legacy';
@@ -21,19 +19,6 @@ import {
ArrayOrItem,
} from '../../../../../src/legacy/plugin_discovery/types';
-const savedObjectSchemas = {
- task: {
- hidden: true,
- isNamespaceAgnostic: true,
- convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
- // legacy config is marked as any in core, no choice here
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
- indexPattern(config: any) {
- return config.get('xpack.task_manager.index');
- },
- },
-};
-
export function taskManager(kibana: LegacyPluginApi): ArrayOrItem {
return new kibana.Plugin({
id: 'task_manager',
@@ -58,7 +43,7 @@ export function taskManager(kibana: LegacyPluginApi): ArrayOrItem {
// we can't tell the Kibana Platform Task Manager plugin to
// to wait to `start` as that happens before legacy plugins
@@ -77,10 +62,5 @@ export function taskManager(kibana: LegacyPluginApi): ArrayOrItem, Plugi
);
}
- // Encrypted attributes
- // - `secrets` properties will be encrypted
- // - `config` will be included in AAD
- // - everything else excluded from AAD
- plugins.encryptedSavedObjects.registerType({
- type: 'action',
- attributesToEncrypt: new Set(['secrets']),
- attributesToExcludeFromAAD: new Set(['name']),
- });
- plugins.encryptedSavedObjects.registerType({
- type: 'action_task_params',
- attributesToEncrypt: new Set(['apiKey']),
- });
+ setupSavedObjects(core.savedObjects, plugins.encryptedSavedObjects);
plugins.eventLog.registerProviderActions(EVENT_LOG_PROVIDER, Object.values(EVENT_LOG_ACTIONS));
this.eventLogger = plugins.eventLog.getLogger({
diff --git a/x-pack/plugins/actions/server/saved_objects/index.ts b/x-pack/plugins/actions/server/saved_objects/index.ts
new file mode 100644
index 0000000000000..dbd7925f96871
--- /dev/null
+++ b/x-pack/plugins/actions/server/saved_objects/index.ts
@@ -0,0 +1,42 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { SavedObjectsServiceSetup } from 'kibana/server';
+import mappings from './mappings.json';
+import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
+
+export function setupSavedObjects(
+ savedObjects: SavedObjectsServiceSetup,
+ encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
+) {
+ savedObjects.registerType({
+ name: 'action',
+ hidden: false,
+ namespaceType: 'single',
+ mappings: mappings.action,
+ });
+
+ // Encrypted attributes
+ // - `secrets` properties will be encrypted
+ // - `config` will be included in AAD
+ // - everything else excluded from AAD
+ encryptedSavedObjects.registerType({
+ type: 'action',
+ attributesToEncrypt: new Set(['secrets']),
+ attributesToExcludeFromAAD: new Set(['name']),
+ });
+
+ savedObjects.registerType({
+ name: 'action_task_params',
+ hidden: false,
+ namespaceType: 'single',
+ mappings: mappings.action_task_params,
+ });
+ encryptedSavedObjects.registerType({
+ type: 'action_task_params',
+ attributesToEncrypt: new Set(['apiKey']),
+ });
+}
diff --git a/x-pack/legacy/plugins/actions/server/mappings.json b/x-pack/plugins/actions/server/saved_objects/mappings.json
similarity index 100%
rename from x-pack/legacy/plugins/actions/server/mappings.json
rename to x-pack/plugins/actions/server/saved_objects/mappings.json
diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts
index c03d3506a051d..8cdde2eeb9877 100644
--- a/x-pack/plugins/alerting/server/plugin.ts
+++ b/x-pack/plugins/alerting/server/plugin.ts
@@ -58,6 +58,7 @@ import { Services } from './types';
import { registerAlertsUsageCollector } from './usage';
import { initializeAlertingTelemetry, scheduleAlertingTelemetry } from './usage/task';
import { IEventLogger, IEventLogService } from '../../event_log/server';
+import { setupSavedObjects } from './saved_objects';
const EVENT_LOG_PROVIDER = 'alerting';
export const EVENT_LOG_ACTIONS = {
@@ -134,17 +135,7 @@ export class AlertingPlugin {
);
}
- // Encrypted attributes
- plugins.encryptedSavedObjects.registerType({
- type: 'alert',
- attributesToEncrypt: new Set(['apiKey']),
- attributesToExcludeFromAAD: new Set([
- 'scheduledTaskId',
- 'muteAll',
- 'mutedInstanceIds',
- 'updatedBy',
- ]),
- });
+ setupSavedObjects(core.savedObjects, plugins.encryptedSavedObjects);
plugins.eventLog.registerProviderActions(EVENT_LOG_PROVIDER, Object.values(EVENT_LOG_ACTIONS));
this.eventLogger = plugins.eventLog.getLogger({
diff --git a/x-pack/plugins/alerting/server/saved_objects/index.ts b/x-pack/plugins/alerting/server/saved_objects/index.ts
new file mode 100644
index 0000000000000..4efec2fe55ef0
--- /dev/null
+++ b/x-pack/plugins/alerting/server/saved_objects/index.ts
@@ -0,0 +1,33 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { SavedObjectsServiceSetup } from 'kibana/server';
+import mappings from './mappings.json';
+import { EncryptedSavedObjectsPluginSetup } from '../../../encrypted_saved_objects/server';
+
+export function setupSavedObjects(
+ savedObjects: SavedObjectsServiceSetup,
+ encryptedSavedObjects: EncryptedSavedObjectsPluginSetup
+) {
+ savedObjects.registerType({
+ name: 'alert',
+ hidden: false,
+ namespaceType: 'single',
+ mappings: mappings.alert,
+ });
+
+ // Encrypted attributes
+ encryptedSavedObjects.registerType({
+ type: 'alert',
+ attributesToEncrypt: new Set(['apiKey']),
+ attributesToExcludeFromAAD: new Set([
+ 'scheduledTaskId',
+ 'muteAll',
+ 'mutedInstanceIds',
+ 'updatedBy',
+ ]),
+ });
+}
diff --git a/x-pack/legacy/plugins/alerting/server/mappings.json b/x-pack/plugins/alerting/server/saved_objects/mappings.json
similarity index 100%
rename from x-pack/legacy/plugins/alerting/server/mappings.json
rename to x-pack/plugins/alerting/server/saved_objects/mappings.json
diff --git a/x-pack/plugins/monitoring/common/constants.ts b/x-pack/plugins/monitoring/common/constants.ts
index edd6142455dfb..eeed7b4d5acf6 100644
--- a/x-pack/plugins/monitoring/common/constants.ts
+++ b/x-pack/plugins/monitoring/common/constants.ts
@@ -245,7 +245,7 @@ export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION, ALERT_TYPE_CLUSTER_ST
/**
* Matches the id for the built-in in email action type
- * See x-pack/legacy/plugins/actions/server/builtin_action_types/email.ts
+ * See x-pack/plugins/actions/server/builtin_action_types/email.ts
*/
export const ALERT_ACTION_TYPE_EMAIL = '.email';
diff --git a/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_instances.sh b/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_instances.sh
index 750c5574f4a72..2028216e6770f 100755
--- a/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_instances.sh
+++ b/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_instances.sh
@@ -10,7 +10,7 @@ set -e
./check_env_variables.sh
# Example: ./get_action_instances.sh
-# https://github.com/elastic/kibana/blob/master/x-pack/legacy/plugins/actions/README.md#get-apiaction_find-find-actions
+# https://github.com/elastic/kibana/blob/master/x-pack/plugins/actions/README.md#get-apiaction_find-find-actions
curl -s -k \
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-X GET ${KIBANA_URL}${SPACE_URL}/api/action/_getAll \
diff --git a/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_types.sh b/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_types.sh
index 8d8cbdd70a803..c587e9a204182 100755
--- a/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_types.sh
+++ b/x-pack/plugins/siem/server/lib/detection_engine/scripts/get_action_types.sh
@@ -10,7 +10,7 @@ set -e
./check_env_variables.sh
# Example: ./get_action_types.sh
-# https://github.com/elastic/kibana/blob/master/x-pack/legacy/plugins/actions/README.md
+# https://github.com/elastic/kibana/blob/master/x-pack/plugins/actions/README.md
curl -s -k \
-u ${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD} \
-X GET ${KIBANA_URL}${SPACE_URL}/api/action/types \
diff --git a/x-pack/plugins/task_manager/server/plugin.ts b/x-pack/plugins/task_manager/server/plugin.ts
index a70fbdb18c30b..0f6e3fc31d96d 100644
--- a/x-pack/plugins/task_manager/server/plugin.ts
+++ b/x-pack/plugins/task_manager/server/plugin.ts
@@ -12,11 +12,10 @@ import { TaskManager } from './task_manager';
import { createTaskManager } from './create_task_manager';
import { TaskManagerConfig } from './config';
import { Middleware } from './lib/middleware';
+import { setupSavedObjects } from './saved_objects';
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-export interface PluginLegacyDependencies {}
export type TaskManagerSetupContract = {
- registerLegacyAPI: (legacyDependencies: PluginLegacyDependencies) => Promise;
+ registerLegacyAPI: () => Promise;
} & Pick;
export type TaskManagerStartContract = Pick<
@@ -35,12 +34,18 @@ export class TaskManagerPlugin
this.currentConfig = {} as TaskManagerConfig;
}
- public setup(core: CoreSetup, plugins: unknown): TaskManagerSetupContract {
+ public async setup(core: CoreSetup, plugins: unknown): Promise {
const logger = this.initContext.logger.get('taskManager');
- const config$ = this.initContext.config.create();
+ const config = await this.initContext.config
+ .create()
+ .pipe(first())
+ .toPromise();
+
+ setupSavedObjects(core.savedObjects, config);
+
return {
- registerLegacyAPI: once((__LEGACY: PluginLegacyDependencies) => {
- config$.subscribe(async config => {
+ registerLegacyAPI: once(() => {
+ (async () => {
const [{ savedObjects, elasticsearch }] = await core.getStartServices();
const savedObjectsRepository = savedObjects.createInternalRepository(['task']);
this.legacyTaskManager$.next(
@@ -53,7 +58,7 @@ export class TaskManagerPlugin
})
);
this.legacyTaskManager$.complete();
- });
+ })();
return this.taskManager;
}),
addMiddleware: (middleware: Middleware) => {
diff --git a/x-pack/plugins/task_manager/server/saved_objects/index.ts b/x-pack/plugins/task_manager/server/saved_objects/index.ts
new file mode 100644
index 0000000000000..0ad9021cd7f39
--- /dev/null
+++ b/x-pack/plugins/task_manager/server/saved_objects/index.ts
@@ -0,0 +1,23 @@
+/*
+ * 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 { SavedObjectsServiceSetup } from 'kibana/server';
+import mappings from './mappings.json';
+import { TaskManagerConfig } from '../config.js';
+
+export function setupSavedObjects(
+ savedObjects: SavedObjectsServiceSetup,
+ config: TaskManagerConfig
+) {
+ savedObjects.registerType({
+ name: 'task',
+ namespaceType: 'agnostic',
+ hidden: true,
+ convertToAliasScript: `ctx._id = ctx._source.type + ':' + ctx._id`,
+ mappings: mappings.task,
+ indexPattern: config.index,
+ });
+}
diff --git a/x-pack/legacy/plugins/task_manager/server/mappings.json b/x-pack/plugins/task_manager/server/saved_objects/mappings.json
similarity index 100%
rename from x-pack/legacy/plugins/task_manager/server/mappings.json
rename to x-pack/plugins/task_manager/server/saved_objects/mappings.json
diff --git a/x-pack/legacy/plugins/task_manager/server/migrations.ts b/x-pack/plugins/task_manager/server/saved_objects/migrations.ts
similarity index 100%
rename from x-pack/legacy/plugins/task_manager/server/migrations.ts
rename to x-pack/plugins/task_manager/server/saved_objects/migrations.ts
diff --git a/x-pack/plugins/task_manager/server/task_manager.ts b/x-pack/plugins/task_manager/server/task_manager.ts
index 24ceea0fe71ef..2a45a599120dd 100644
--- a/x-pack/plugins/task_manager/server/task_manager.ts
+++ b/x-pack/plugins/task_manager/server/task_manager.ts
@@ -240,7 +240,7 @@ export class TaskManager {
* @param taskDefinitions - The Kibana task definitions dictionary
*/
public registerTaskDefinitions(taskDefinitions: TaskDictionary) {
- this.assertUninitialized('register task definitions');
+ this.assertUninitialized('register task definitions', Object.keys(taskDefinitions).join(', '));
const duplicate = Object.keys(taskDefinitions).find(k => !!this.definitions[k]);
if (duplicate) {
throw new Error(`Task ${duplicate} is already defined!`);
@@ -360,9 +360,11 @@ export class TaskManager {
* @param {string} message shown if task manager is already initialized
* @returns void
*/
- private assertUninitialized(message: string) {
+ private assertUninitialized(message: string, context?: string) {
if (this.isStarted) {
- throw new Error(`Cannot ${message} after the task manager is initialized!`);
+ throw new Error(
+ `${context ? `[${context}] ` : ''}Cannot ${message} after the task manager is initialized`
+ );
}
}
}
diff --git a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/servicenow.ts b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/servicenow.ts
index a7551ad7e2fad..1244657ed9988 100644
--- a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/servicenow.ts
+++ b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/servicenow.ts
@@ -9,7 +9,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// node ../scripts/functional_test_runner.js --grep "Actions.servicenddd" --config=test/alerting_api_integration/security_and_spaces/config.ts
diff --git a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/slack.ts b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/slack.ts
index 46258e41d5d69..4151deab45213 100644
--- a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/slack.ts
+++ b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/slack.ts
@@ -9,7 +9,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// eslint-disable-next-line import/no-default-export
export default function slackTest({ getService }: FtrProviderContext) {
diff --git a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/webhook.ts b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/webhook.ts
index 338610e9243a4..bae6dada48fb7 100644
--- a/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/webhook.ts
+++ b/x-pack/test/alerting_api_integration/basic/tests/actions/builtin_action_types/webhook.ts
@@ -8,7 +8,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// eslint-disable-next-line import/no-default-export
export default function webhookTest({ getService }: FtrProviderContext) {
diff --git a/x-pack/test/alerting_api_integration/common/config.ts b/x-pack/test/alerting_api_integration/common/config.ts
index 457b7621e84bd..870ed3cf0cc0f 100644
--- a/x-pack/test/alerting_api_integration/common/config.ts
+++ b/x-pack/test/alerting_api_integration/common/config.ts
@@ -8,7 +8,7 @@ import path from 'path';
import { CA_CERT_PATH } from '@kbn/dev-utils';
import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
import { services } from './services';
-import { getAllExternalServiceSimulatorPaths } from './fixtures/plugins/actions';
+import { getAllExternalServiceSimulatorPaths } from './fixtures/plugins/actions_simulators';
interface CreateTestConfigOptions {
license: string;
@@ -75,7 +75,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
'some.non.existent.com',
])}`,
`--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`,
- '--xpack.alerting.enabled=true',
'--xpack.eventLog.logEntries=true',
`--xpack.actions.preconfigured=${JSON.stringify([
{
@@ -124,7 +123,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
])}`,
...disabledPlugins.map(key => `--xpack.${key}.enabled=false`),
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'alerts')}`,
- `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'actions')}`,
+ `--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'actions_simulators')}`,
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'task_manager')}`,
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'aad')}`,
`--server.xsrf.whitelist=${JSON.stringify(getAllExternalServiceSimulatorPaths())}`,
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/index.ts
index 05139213b76b9..400aec7e11c8d 100644
--- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/index.ts
+++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/aad/index.ts
@@ -21,7 +21,7 @@ interface CheckAADRequest extends Hapi.Request {
// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
- require: ['actions', 'alerting', 'encryptedSavedObjects'],
+ require: ['encryptedSavedObjects'],
name: 'aad-fixtures',
init(server: Legacy.Server) {
const newPlatform = ((server as unknown) as KbnServer).newPlatform;
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/README.md b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/README.md
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/README.md
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/README.md
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/index.ts
similarity index 98%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/index.ts
index 019b15cc1862a..45edd4c092da9 100644
--- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts
+++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/index.ts
@@ -36,7 +36,7 @@ export function getAllExternalServiceSimulatorPaths(): string[] {
// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
- require: ['xpack_main', 'actions'],
+ require: ['xpack_main'],
name: NAME,
init: (server: Hapi.Server) => {
// this action is specifically NOT enabled in ../../config.ts
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/package.json b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/package.json
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/package.json
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/package.json
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/pagerduty_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/pagerduty_simulation.ts
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/pagerduty_simulation.ts
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/pagerduty_simulation.ts
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/servicenow_simulation.ts
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/servicenow_simulation.ts
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/slack_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/slack_simulation.ts
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/slack_simulation.ts
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/slack_simulation.ts
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/webhook_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/webhook_simulation.ts
similarity index 100%
rename from x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/webhook_simulation.ts
rename to x-pack/test/alerting_api_integration/common/fixtures/plugins/actions_simulators/webhook_simulation.ts
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts
index 43d533ad3ae14..1a47addf36ab3 100644
--- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts
+++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts
@@ -11,8 +11,8 @@ import { ActionTypeExecutorOptions, ActionType } from '../../../../../../plugins
// eslint-disable-next-line import/no-default-export
export default function(kibana: any) {
return new kibana.Plugin({
- require: ['xpack_main', 'actions', 'alerting', 'elasticsearch'],
- name: 'alerts',
+ require: ['xpack_main', 'elasticsearch'],
+ name: 'alerts-fixture',
init(server: any) {
const clusterClient = server.newPlatform.start.core.elasticsearch.legacy.client;
server.plugins.xpack_main.registerFeature({
diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/task_manager/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/task_manager/index.ts
index 29708f86b0a9b..ac32f05805e4a 100644
--- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/task_manager/index.ts
+++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/task_manager/index.ts
@@ -31,7 +31,7 @@ const taskByIdQuery = (id: string) => ({
export default function(kibana: any) {
return new kibana.Plugin({
name: 'taskManagerHelpers',
- require: ['elasticsearch', 'task_manager'],
+ require: ['elasticsearch'],
config(Joi: any) {
return Joi.object({
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 eeb0818b5fbab..4c76ebfb93b0b 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
@@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// eslint-disable-next-line import/no-default-export
export default function pagerdutyTest({ getService }: FtrProviderContext) {
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 054f8f6141817..399ae0f27f5b1 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
@@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// node ../scripts/functional_test_runner.js --grep "servicenow" --config=test/alerting_api_integration/security_and_spaces/config.ts
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 e00589b7e85b7..386254e49c19c 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
@@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// eslint-disable-next-line import/no-default-export
export default function slackTest({ getService }: FtrProviderContext) {
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 fd996ea4507ba..9b66326fa6157 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
@@ -10,7 +10,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
const defaultValues: Record = {
headers: null,
diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/builtin_action_types/webhook.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/builtin_action_types/webhook.ts
index 5122a74d53b72..112149a32649a 100644
--- a/x-pack/test/alerting_api_integration/spaces_only/tests/actions/builtin_action_types/webhook.ts
+++ b/x-pack/test/alerting_api_integration/spaces_only/tests/actions/builtin_action_types/webhook.ts
@@ -10,7 +10,7 @@ import { FtrProviderContext } from '../../../../common/ftr_provider_context';
import {
getExternalServiceSimulatorPath,
ExternalServiceSimulator,
-} from '../../../../common/fixtures/plugins/actions';
+} from '../../../../common/fixtures/plugins/actions_simulators';
// eslint-disable-next-line import/no-default-export
export default function webhookTest({ getService }: FtrProviderContext) {
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 e89352118990a..1e6600c7cd2c0 100644
--- a/x-pack/test/detection_engine_api_integration/common/config.ts
+++ b/x-pack/test/detection_engine_api_integration/common/config.ts
@@ -78,7 +78,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
'some.non.existent.com',
])}`,
`--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`,
- '--xpack.alerting.enabled=true',
'--xpack.eventLog.logEntries=true',
...disabledPlugins.map(key => `--xpack.${key}.enabled=false`),
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'alerts')}`,
diff --git a/x-pack/test/functional_with_es_ssl/config.ts b/x-pack/test/functional_with_es_ssl/config.ts
index a620b1d953376..71b22a336f6b9 100644
--- a/x-pack/test/functional_with_es_ssl/config.ts
+++ b/x-pack/test/functional_with_es_ssl/config.ts
@@ -50,8 +50,6 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
`--elasticsearch.hosts=https://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
`--plugin-path=${join(__dirname, 'fixtures', 'plugins', 'alerts')}`,
- '--xpack.actions.enabled=true',
- '--xpack.alerting.enabled=true',
`--xpack.actions.preconfigured=${JSON.stringify([
{
id: 'my-slack1',
diff --git a/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/kibana.json b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/kibana.json
new file mode 100644
index 0000000000000..416ef7fa34591
--- /dev/null
+++ b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/kibana.json
@@ -0,0 +1,9 @@
+{
+ "id": "sample_task_plugin",
+ "version": "1.0.0",
+ "kibanaVersion": "kibana",
+ "configPath": ["xpack"],
+ "requiredPlugins": ["taskManager"],
+ "server": true,
+ "ui": false
+}
diff --git a/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/package.json b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/package.json
new file mode 100644
index 0000000000000..c8d47decd94c1
--- /dev/null
+++ b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/package.json
@@ -0,0 +1,18 @@
+{
+ "name": "sample_task_plugin",
+ "version": "1.0.0",
+ "kibana": {
+ "version": "kibana",
+ "templateVersion": "1.0.0"
+ },
+ "main": "target/test/plugin_api_integration/plugins/sample_task_plugin",
+ "scripts": {
+ "kbn": "node ../../../../../scripts/kbn.js",
+ "build": "rm -rf './target' && tsc"
+ },
+ "devDependencies": {
+ "typescript": "3.7.2"
+ },
+ "license": "Apache-2.0",
+ "dependencies": {}
+}
diff --git a/x-pack/legacy/plugins/actions/index.ts b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/index.ts
similarity index 65%
rename from x-pack/legacy/plugins/actions/index.ts
rename to x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/index.ts
index 276d1ea3accea..77233f463734a 100644
--- a/x-pack/legacy/plugins/actions/index.ts
+++ b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/index.ts
@@ -4,4 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
-export * from './server/';
+import { SampleTaskManagerFixturePlugin } from './plugin';
+
+export const plugin = () => new SampleTaskManagerFixturePlugin();
diff --git a/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/init_routes.ts b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/init_routes.ts
new file mode 100644
index 0000000000000..1fee2decbcba9
--- /dev/null
+++ b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/init_routes.ts
@@ -0,0 +1,252 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+import { schema } from '@kbn/config-schema';
+import {
+ RequestHandlerContext,
+ KibanaRequest,
+ KibanaResponseFactory,
+ IKibanaResponse,
+ IRouter,
+ CoreSetup,
+} from 'kibana/server';
+import { EventEmitter } from 'events';
+import { TaskManagerStartContract } from '../../../../../plugins/task_manager/server';
+
+const scope = 'testing';
+const taskManagerQuery = {
+ bool: {
+ filter: {
+ bool: {
+ must: [
+ {
+ term: {
+ 'task.scope': scope,
+ },
+ },
+ ],
+ },
+ },
+ },
+};
+
+export function initRoutes(
+ router: IRouter,
+ core: CoreSetup,
+ taskManagerStart: Promise,
+ taskTestingEvents: EventEmitter
+) {
+ async function ensureIndexIsRefreshed() {
+ return await core.elasticsearch.adminClient.callAsInternalUser('indices.refresh', {
+ index: '.kibana_task_manager',
+ });
+ }
+
+ router.post(
+ {
+ path: `/api/sample_tasks/schedule`,
+ validate: {
+ body: schema.object({
+ task: schema.object({
+ taskType: schema.string(),
+ schedule: schema.maybe(
+ schema.object({
+ interval: schema.string(),
+ })
+ ),
+ interval: schema.maybe(schema.string()),
+ params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
+ state: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
+ id: schema.maybe(schema.string()),
+ }),
+ }),
+ },
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ const taskManager = await taskManagerStart;
+ const { task: taskFields } = req.body;
+ const task = {
+ ...taskFields,
+ scope: [scope],
+ };
+
+ const taskResult = await taskManager.schedule(task, { req });
+
+ return res.ok({ body: taskResult });
+ } catch (err) {
+ return res.internalError({ body: err });
+ }
+ }
+ );
+
+ router.post(
+ {
+ path: `/api/sample_tasks/run_now`,
+ validate: {
+ body: schema.object({
+ task: schema.object({
+ id: schema.string({}),
+ }),
+ }),
+ },
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ const {
+ task: { id },
+ } = req.body;
+ try {
+ const taskManager = await taskManagerStart;
+ return res.ok({ body: await taskManager.runNow(id) });
+ } catch (err) {
+ return res.ok({ body: { id, error: `${err}` } });
+ }
+ }
+ );
+
+ router.post(
+ {
+ path: `/api/sample_tasks/ensure_scheduled`,
+ validate: {
+ body: schema.object({
+ task: schema.object({
+ taskType: schema.string(),
+ params: schema.object({}),
+ state: schema.maybe(schema.object({})),
+ id: schema.maybe(schema.string()),
+ }),
+ }),
+ },
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ const { task: taskFields } = req.body;
+ const task = {
+ ...taskFields,
+ scope: [scope],
+ };
+
+ const taskManager = await taskManagerStart;
+ const taskResult = await taskManager.ensureScheduled(task, { req });
+
+ return res.ok({ body: taskResult });
+ } catch (err) {
+ return res.ok({ body: err });
+ }
+ }
+ );
+
+ router.post(
+ {
+ path: `/api/sample_tasks/event`,
+ validate: {
+ body: schema.object({
+ event: schema.string(),
+ data: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
+ }),
+ },
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ const { event, data } = req.body;
+ taskTestingEvents.emit(event, data);
+ return res.ok({ body: event });
+ } catch (err) {
+ return res.ok({ body: err });
+ }
+ }
+ );
+
+ router.get(
+ {
+ path: `/api/sample_tasks`,
+ validate: {},
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ const taskManager = await taskManagerStart;
+ return res.ok({
+ body: await taskManager.fetch({
+ query: taskManagerQuery,
+ }),
+ });
+ } catch (err) {
+ return res.ok({ body: err });
+ }
+ }
+ );
+
+ router.get(
+ {
+ path: `/api/sample_tasks/task/{taskId}`,
+ validate: {
+ params: schema.object({
+ taskId: schema.string(),
+ }),
+ },
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ await ensureIndexIsRefreshed();
+ const taskManager = await taskManagerStart;
+ return res.ok({ body: await taskManager.get(req.params.taskId) });
+ } catch (err) {
+ return res.ok({ body: err });
+ }
+ return res.ok({ body: {} });
+ }
+ );
+
+ router.delete(
+ {
+ path: `/api/sample_tasks`,
+ validate: {},
+ },
+ async function(
+ context: RequestHandlerContext,
+ req: KibanaRequest,
+ res: KibanaResponseFactory
+ ): Promise> {
+ try {
+ let tasksFound = 0;
+ const taskManager = await taskManagerStart;
+ do {
+ const { docs: tasks } = await taskManager.fetch({
+ query: taskManagerQuery,
+ });
+ tasksFound = tasks.length;
+ await Promise.all(tasks.map(task => taskManager.remove(task.id)));
+ } while (tasksFound > 0);
+ return res.ok({ body: 'OK' });
+ } catch (err) {
+ return res.ok({ body: err });
+ }
+ }
+ );
+}
diff --git a/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/plugin.ts b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/plugin.ts
new file mode 100644
index 0000000000000..508d58b8f0ca9
--- /dev/null
+++ b/x-pack/test/plugin_api_integration/plugins/sample_task_plugin/server/plugin.ts
@@ -0,0 +1,164 @@
+/*
+ * 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 { Plugin, CoreSetup, CoreStart } from 'kibana/server';
+import { EventEmitter } from 'events';
+import { Subject } from 'rxjs';
+import { first } from 'rxjs/operators';
+import { initRoutes } from './init_routes';
+import {
+ TaskManagerSetupContract,
+ TaskManagerStartContract,
+ ConcreteTaskInstance,
+} from '../../../../../plugins/task_manager/server';
+import { DEFAULT_MAX_WORKERS } from '../../../../../plugins/task_manager/server/config';
+
+// this plugin's dependendencies
+export interface SampleTaskManagerFixtureSetupDeps {
+ taskManager: TaskManagerSetupContract;
+}
+export interface SampleTaskManagerFixtureStartDeps {
+ taskManager: TaskManagerStartContract;
+}
+
+export class SampleTaskManagerFixturePlugin
+ implements
+ Plugin {
+ taskManagerStart$: Subject = new Subject();
+ taskManagerStart: Promise = this.taskManagerStart$
+ .pipe(first())
+ .toPromise();
+
+ public setup(core: CoreSetup, { taskManager }: SampleTaskManagerFixtureSetupDeps) {
+ const taskTestingEvents = new EventEmitter();
+ taskTestingEvents.setMaxListeners(DEFAULT_MAX_WORKERS * 2);
+
+ const defaultSampleTaskConfig = {
+ timeout: '1m',
+ // This task allows tests to specify its behavior (whether it reschedules itself, whether it errors, etc)
+ // taskInstance.params has the following optional fields:
+ // nextRunMilliseconds: number - If specified, the run method will return a runAt that is now + nextRunMilliseconds
+ // failWith: string - If specified, the task will throw an error with the specified message
+ // failOn: number - If specified, the task will only throw the `failWith` error when `count` equals to the failOn value
+ // waitForParams : boolean - should the task stall ands wait to receive params asynchronously before using the default params
+ // waitForEvent : string - if provided, the task will stall (after completing the run) and wait for an asyn event before completing
+ createTaskRunner: ({ taskInstance }: { taskInstance: ConcreteTaskInstance }) => ({
+ async run() {
+ const { params, state, id } = taskInstance;
+ const prevState = state || { count: 0 };
+
+ const count = (prevState.count || 0) + 1;
+
+ const runParams = {
+ ...params,
+ // if this task requires custom params provided async - wait for them
+ ...(params.waitForParams ? await once(taskTestingEvents, id) : {}),
+ };
+
+ if (runParams.failWith) {
+ if (!runParams.failOn || (runParams.failOn && count === runParams.failOn)) {
+ throw new Error(runParams.failWith);
+ }
+ }
+
+ await core.elasticsearch.adminClient.callAsInternalUser('index', {
+ index: '.kibana_task_manager_test_result',
+ body: {
+ type: 'task',
+ taskId: taskInstance.id,
+ params: JSON.stringify(runParams),
+ state: JSON.stringify(state),
+ ranAt: new Date(),
+ },
+ refresh: true,
+ });
+
+ // Stall task run until a certain event is triggered
+ if (runParams.waitForEvent) {
+ await once(taskTestingEvents, runParams.waitForEvent);
+ }
+
+ return {
+ state: { count },
+ runAt: millisecondsFromNow(runParams.nextRunMilliseconds),
+ };
+ },
+ }),
+ };
+
+ taskManager.registerTaskDefinitions({
+ sampleTask: {
+ ...defaultSampleTaskConfig,
+ type: 'sampleTask',
+ title: 'Sample Task',
+ description: 'A sample task for testing the task_manager.',
+ },
+ singleAttemptSampleTask: {
+ ...defaultSampleTaskConfig,
+ type: 'singleAttemptSampleTask',
+ title: 'Failing Sample Task',
+ description:
+ 'A sample task for testing the task_manager that fails on the first attempt to run.',
+ // fail after the first failed run
+ maxAttempts: 1,
+ },
+ });
+
+ taskManager.addMiddleware({
+ async beforeSave({ taskInstance, ...opts }) {
+ const modifiedInstance = {
+ ...taskInstance,
+ params: {
+ originalParams: taskInstance.params,
+ superFly: 'My middleware param!',
+ },
+ };
+
+ return {
+ ...opts,
+ taskInstance: modifiedInstance,
+ };
+ },
+
+ async beforeRun({ taskInstance, ...opts }) {
+ return {
+ ...opts,
+ taskInstance: {
+ ...taskInstance,
+ params: taskInstance.params.originalParams,
+ },
+ };
+ },
+
+ async beforeMarkRunning(context) {
+ return context;
+ },
+ });
+ initRoutes(core.http.createRouter(), core, this.taskManagerStart, taskTestingEvents);
+ }
+
+ public start(core: CoreStart, { taskManager }: SampleTaskManagerFixtureStartDeps) {
+ this.taskManagerStart$.next(taskManager);
+ this.taskManagerStart$.complete();
+ }
+ public stop() {}
+}
+
+function millisecondsFromNow(ms: number) {
+ if (!ms) {
+ return;
+ }
+
+ const dt = new Date();
+ dt.setTime(dt.getTime() + ms);
+ return dt;
+}
+
+const once = function(emitter: EventEmitter, event: string): Promise> {
+ return new Promise(resolve => {
+ emitter.once(event, data => resolve(data || {}));
+ });
+};
diff --git a/x-pack/test/plugin_api_integration/plugins/task_manager/index.js b/x-pack/test/plugin_api_integration/plugins/task_manager/index.js
deleted file mode 100644
index e5b645367b8b7..0000000000000
--- a/x-pack/test/plugin_api_integration/plugins/task_manager/index.js
+++ /dev/null
@@ -1,150 +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.
- */
-
-const { DEFAULT_MAX_WORKERS } = require('../../../../plugins/task_manager/server/config.ts');
-const { EventEmitter } = require('events');
-
-import { initRoutes } from './init_routes';
-
-const once = function(emitter, event) {
- return new Promise(resolve => {
- emitter.once(event, data => resolve(data || {}));
- });
-};
-
-export default function TaskTestingAPI(kibana) {
- const taskTestingEvents = new EventEmitter();
- taskTestingEvents.setMaxListeners(DEFAULT_MAX_WORKERS * 2);
-
- return new kibana.Plugin({
- name: 'sampleTask',
- require: ['elasticsearch', 'task_manager'],
-
- config(Joi) {
- return Joi.object({
- enabled: Joi.boolean().default(true),
- }).default();
- },
-
- init(server) {
- const taskManager = {
- ...server.newPlatform.setup.plugins.taskManager,
- ...server.newPlatform.start.plugins.taskManager,
- };
- const legacyTaskManager = server.plugins.task_manager;
-
- const defaultSampleTaskConfig = {
- timeout: '1m',
- // This task allows tests to specify its behavior (whether it reschedules itself, whether it errors, etc)
- // taskInstance.params has the following optional fields:
- // nextRunMilliseconds: number - If specified, the run method will return a runAt that is now + nextRunMilliseconds
- // failWith: string - If specified, the task will throw an error with the specified message
- // failOn: number - If specified, the task will only throw the `failWith` error when `count` equals to the failOn value
- // waitForParams : boolean - should the task stall ands wait to receive params asynchronously before using the default params
- // waitForEvent : string - if provided, the task will stall (after completing the run) and wait for an asyn event before completing
- createTaskRunner: ({ taskInstance }) => ({
- async run() {
- const { params, state, id } = taskInstance;
- const prevState = state || { count: 0 };
-
- const count = (prevState.count || 0) + 1;
-
- const runParams = {
- ...params,
- // if this task requires custom params provided async - wait for them
- ...(params.waitForParams ? await once(taskTestingEvents, id) : {}),
- };
-
- if (runParams.failWith) {
- if (!runParams.failOn || (runParams.failOn && count === runParams.failOn)) {
- throw new Error(runParams.failWith);
- }
- }
-
- const callCluster = server.plugins.elasticsearch.getCluster('admin')
- .callWithInternalUser;
- await callCluster('index', {
- index: '.kibana_task_manager_test_result',
- body: {
- type: 'task',
- taskId: taskInstance.id,
- params: JSON.stringify(runParams),
- state: JSON.stringify(state),
- ranAt: new Date(),
- },
- refresh: true,
- });
-
- // Stall task run until a certain event is triggered
- if (runParams.waitForEvent) {
- await once(taskTestingEvents, runParams.waitForEvent);
- }
-
- return {
- state: { count },
- runAt: millisecondsFromNow(runParams.nextRunMilliseconds),
- };
- },
- }),
- };
-
- taskManager.registerTaskDefinitions({
- sampleTask: {
- ...defaultSampleTaskConfig,
- title: 'Sample Task',
- description: 'A sample task for testing the task_manager.',
- },
- singleAttemptSampleTask: {
- ...defaultSampleTaskConfig,
- title: 'Failing Sample Task',
- description:
- 'A sample task for testing the task_manager that fails on the first attempt to run.',
- // fail after the first failed run
- maxAttempts: 1,
- },
- });
-
- taskManager.addMiddleware({
- async beforeSave({ taskInstance, ...opts }) {
- const modifiedInstance = {
- ...taskInstance,
- params: {
- originalParams: taskInstance.params,
- superFly: 'My middleware param!',
- },
- };
-
- return {
- ...opts,
- taskInstance: modifiedInstance,
- };
- },
-
- async beforeRun({ taskInstance, ...opts }) {
- return {
- ...opts,
- taskInstance: {
- ...taskInstance,
- params: taskInstance.params.originalParams,
- },
- };
- },
- });
-
- initRoutes(server, taskManager, legacyTaskManager, taskTestingEvents);
- },
- });
-}
-
-function millisecondsFromNow(ms) {
- if (!ms) {
- return;
- }
-
- const dt = new Date();
- dt.setTime(dt.getTime() + ms);
- return dt;
-}
diff --git a/x-pack/test/plugin_api_integration/plugins/task_manager/init_routes.js b/x-pack/test/plugin_api_integration/plugins/task_manager/init_routes.js
deleted file mode 100644
index 785fbed341423..0000000000000
--- a/x-pack/test/plugin_api_integration/plugins/task_manager/init_routes.js
+++ /dev/null
@@ -1,236 +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 Joi from 'joi';
-
-const scope = 'testing';
-const taskManagerQuery = {
- bool: {
- filter: {
- bool: {
- must: [
- {
- term: {
- 'task.scope': scope,
- },
- },
- ],
- },
- },
- },
-};
-
-export function initRoutes(server, taskManager, legacyTaskManager, taskTestingEvents) {
- const callCluster = server.plugins.elasticsearch.getCluster('admin').callWithInternalUser;
-
- async function ensureIndexIsRefreshed() {
- return await callCluster('indices.refresh', {
- index: '.kibana_task_manager',
- });
- }
-
- server.route({
- path: '/api/sample_tasks/schedule',
- method: 'POST',
- config: {
- validate: {
- payload: Joi.object({
- task: Joi.object({
- taskType: Joi.string().required(),
- schedule: Joi.object({
- interval: Joi.string(),
- }).optional(),
- interval: Joi.string().optional(),
- params: Joi.object().required(),
- state: Joi.object().optional(),
- id: Joi.string().optional(),
- }),
- }),
- },
- },
- async handler(request) {
- try {
- const { task: taskFields } = request.payload;
- const task = {
- ...taskFields,
- scope: [scope],
- };
-
- const taskResult = await taskManager.schedule(task, { request });
-
- return taskResult;
- } catch (err) {
- return err;
- }
- },
- });
-
- /*
- Schedule using legacy Api
- */
- server.route({
- path: '/api/sample_tasks/schedule_legacy',
- method: 'POST',
- config: {
- validate: {
- payload: Joi.object({
- task: Joi.object({
- taskType: Joi.string().required(),
- schedule: Joi.object({
- interval: Joi.string(),
- }).optional(),
- interval: Joi.string().optional(),
- params: Joi.object().required(),
- state: Joi.object().optional(),
- id: Joi.string().optional(),
- }),
- }),
- },
- },
- async handler(request) {
- try {
- const { task: taskFields } = request.payload;
- const task = {
- ...taskFields,
- scope: [scope],
- };
-
- const taskResult = await legacyTaskManager.schedule(task, { request });
-
- return taskResult;
- } catch (err) {
- return err;
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks/run_now',
- method: 'POST',
- config: {
- validate: {
- payload: Joi.object({
- task: Joi.object({
- id: Joi.string().optional(),
- }),
- }),
- },
- },
- async handler(request) {
- const {
- task: { id },
- } = request.payload;
- try {
- return await taskManager.runNow(id);
- } catch (err) {
- return { id, error: `${err}` };
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks/ensure_scheduled',
- method: 'POST',
- config: {
- validate: {
- payload: Joi.object({
- task: Joi.object({
- taskType: Joi.string().required(),
- params: Joi.object().required(),
- state: Joi.object().optional(),
- id: Joi.string().optional(),
- }),
- }),
- },
- },
- async handler(request) {
- try {
- const { task: taskFields } = request.payload;
- const task = {
- ...taskFields,
- scope: [scope],
- };
-
- const taskResult = await taskManager.ensureScheduled(task, { request });
-
- return taskResult;
- } catch (err) {
- return err;
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks/event',
- method: 'POST',
- config: {
- validate: {
- payload: Joi.object({
- event: Joi.string().required(),
- data: Joi.object()
- .optional()
- .default({}),
- }),
- },
- },
- async handler(request) {
- try {
- const { event, data } = request.payload;
- taskTestingEvents.emit(event, data);
- return { event };
- } catch (err) {
- return err;
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks',
- method: 'GET',
- async handler() {
- try {
- return taskManager.fetch({
- query: taskManagerQuery,
- });
- } catch (err) {
- return err;
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks/task/{taskId}',
- method: 'GET',
- async handler(request) {
- try {
- await ensureIndexIsRefreshed();
- return await taskManager.get(request.params.taskId);
- } catch (err) {
- return err;
- }
- },
- });
-
- server.route({
- path: '/api/sample_tasks',
- method: 'DELETE',
- async handler() {
- try {
- let tasksFound = 0;
- do {
- const { docs: tasks } = await taskManager.fetch({
- query: taskManagerQuery,
- });
- tasksFound = tasks.length;
- await Promise.all(tasks.map(task => taskManager.remove(task.id)));
- } while (tasksFound > 0);
- return 'OK';
- } catch (err) {
- return err;
- }
- },
- });
-}
diff --git a/x-pack/test/plugin_api_integration/plugins/task_manager/package.json b/x-pack/test/plugin_api_integration/plugins/task_manager/package.json
deleted file mode 100644
index ec63c512e9cd7..0000000000000
--- a/x-pack/test/plugin_api_integration/plugins/task_manager/package.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "name": "sample_task_plugin",
- "version": "1.0.0",
- "kibana": {
- "version": "kibana",
- "templateVersion": "1.0.0"
- },
- "license": "Apache-2.0",
- "dependencies": {
- "joi": "^13.5.2"
- }
-}
diff --git a/x-pack/test/plugin_api_integration/test_suites/task_manager/task_manager_integration.js b/x-pack/test/plugin_api_integration/test_suites/task_manager/task_manager_integration.js
index e8f976d5ae6e3..00cefa42711c9 100644
--- a/x-pack/test/plugin_api_integration/test_suites/task_manager/task_manager_integration.js
+++ b/x-pack/test/plugin_api_integration/test_suites/task_manager/task_manager_integration.js
@@ -11,7 +11,7 @@ import supertestAsPromised from 'supertest-as-promised';
const {
task: { properties: taskManagerIndexMapping },
-} = require('../../../../legacy/plugins/task_manager/server/mappings.json');
+} = require('../../../../plugins/task_manager/server/saved_objects/mappings.json');
const {
DEFAULT_MAX_WORKERS,
@@ -90,15 +90,6 @@ export default function({ getService }) {
.then(response => response.body);
}
- function scheduleTaskUsingLegacyApi(task) {
- return supertest
- .post('/api/sample_tasks/schedule_legacy')
- .set('kbn-xsrf', 'xxx')
- .send({ task })
- .expect(200)
- .then(response => response.body);
- }
-
function runTaskNow(task) {
return supertest
.post('/api/sample_tasks/run_now')
@@ -587,15 +578,5 @@ export default function({ getService }) {
expect(getTaskById(tasks, longRunningTask.id).state.count).to.eql(1);
});
});
-
- it('should retain the legacy api until v8.0.0', async () => {
- const result = await scheduleTaskUsingLegacyApi({
- id: 'task-with-legacy-api',
- taskType: 'sampleTask',
- params: {},
- });
-
- expect(result.id).to.be('task-with-legacy-api');
- });
});
}
From af2e86f949b989d7dcbcd05d5af46ffa831e1e84 Mon Sep 17 00:00:00 2001
From: Wylie Conlon
Date: Wed, 29 Apr 2020 10:50:03 -0400
Subject: [PATCH 18/33] [Lens] Fix flaky test by closing options after use
(#64714)
Co-authored-by: Elastic Machine
---
.../test/functional/page_objects/lens_page.ts | 20 +++++++++----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/x-pack/test/functional/page_objects/lens_page.ts b/x-pack/test/functional/page_objects/lens_page.ts
index 1bf637c50b0ba..57b2847cc2e50 100644
--- a/x-pack/test/functional/page_objects/lens_page.ts
+++ b/x-pack/test/functional/page_objects/lens_page.ts
@@ -12,6 +12,7 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const find = getService('find');
+ const comboBox = getService('comboBox');
const PageObjects = getPageObjects([
'header',
'common',
@@ -107,20 +108,17 @@ export function LensPageProvider({ getService, getPageObjects }: FtrProviderCont
* @param opts.operation - the desired operation ID for the dimension
* @param opts.field - the desired field for the dimension
*/
- async configureDimension(opts: { dimension: string; operation?: string; field?: string }) {
+ async configureDimension(opts: { dimension: string; operation: string; field: string }) {
await find.clickByCssSelector(opts.dimension);
- if (opts.operation) {
- await find.clickByCssSelector(
- `[data-test-subj="lns-indexPatternDimensionIncompatible-${opts.operation}"],
- [data-test-subj="lns-indexPatternDimension-${opts.operation}"]`
- );
- }
+ await find.clickByCssSelector(
+ `[data-test-subj="lns-indexPatternDimensionIncompatible-${opts.operation}"],
+ [data-test-subj="lns-indexPatternDimension-${opts.operation}"]`
+ );
- if (opts.field) {
- await testSubjects.click('indexPattern-dimension-field');
- await testSubjects.click(`lns-fieldOption-${opts.field}`);
- }
+ const target = await testSubjects.find('indexPattern-dimension-field');
+ await comboBox.openOptionsList(target);
+ await comboBox.setElement(target, opts.field);
},
/**
From f8dc041b855569bcfe422992e898812c10ef94d0 Mon Sep 17 00:00:00 2001
From: Nicolas Chaulet
Date: Wed, 29 Apr 2020 11:31:35 -0400
Subject: [PATCH 19/33] [Ingest] Use agent template embeded in the pkg registry
response (#64705)
---
.../ingest_manager/common/types/models/epm.ts | 1 +
.../server/routes/datasource/handlers.ts | 28 ++++----
.../server/services/datasource.test.ts | 64 +++++++++++--------
.../server/services/datasource.ts | 37 +++++++----
.../ingest_manager/server/services/setup.ts | 2 +-
5 files changed, 79 insertions(+), 53 deletions(-)
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 fb6bf235d1e26..05e160cdfb81a 100644
--- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts
+++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts
@@ -97,6 +97,7 @@ export interface RegistryStream {
description?: string;
enabled?: boolean;
vars?: RegistryVarsEntry[];
+ template?: string;
}
export type RequirementVersion = string;
diff --git a/x-pack/plugins/ingest_manager/server/routes/datasource/handlers.ts b/x-pack/plugins/ingest_manager/server/routes/datasource/handlers.ts
index 56d6053a1451b..8f07e3ed1de02 100644
--- a/x-pack/plugins/ingest_manager/server/routes/datasource/handlers.ts
+++ b/x-pack/plugins/ingest_manager/server/routes/datasource/handlers.ts
@@ -7,7 +7,7 @@ import { TypeOf } from '@kbn/config-schema';
import Boom from 'boom';
import { RequestHandler } from 'src/core/server';
import { appContextService, datasourceService } from '../../services';
-import { ensureInstalledPackage } from '../../services/epm/packages';
+import { ensureInstalledPackage, getPackageInfo } from '../../services/epm/packages';
import {
GetDatasourcesRequestSchema,
GetOneDatasourceRequestSchema,
@@ -85,12 +85,13 @@ export const createDatasourceHandler: RequestHandler<
pkgName: request.body.package.name,
callCluster,
});
-
+ const pkgInfo = await getPackageInfo({
+ savedObjectsClient: soClient,
+ pkgName: request.body.package.name,
+ pkgVersion: request.body.package.version,
+ });
newData.inputs = (await datasourceService.assignPackageStream(
- {
- pkgName: request.body.package.name,
- pkgVersion: request.body.package.version,
- },
+ pkgInfo,
request.body.inputs
)) as TypeOf['inputs'];
}
@@ -127,13 +128,14 @@ export const updateDatasourceHandler: RequestHandler<
const pkg = newData.package || datasource.package;
const inputs = newData.inputs || datasource.inputs;
if (pkg && (newData.inputs || newData.package)) {
- newData.inputs = (await datasourceService.assignPackageStream(
- {
- pkgName: pkg.name,
- pkgVersion: pkg.version,
- },
- inputs
- )) as TypeOf['inputs'];
+ const pkgInfo = await getPackageInfo({
+ savedObjectsClient: soClient,
+ pkgName: pkg.name,
+ pkgVersion: pkg.version,
+ });
+ newData.inputs = (await datasourceService.assignPackageStream(pkgInfo, inputs)) as TypeOf<
+ typeof CreateDatasourceRequestSchema.body
+ >['inputs'];
}
const updatedDatasource = await datasourceService.update(
diff --git a/x-pack/plugins/ingest_manager/server/services/datasource.test.ts b/x-pack/plugins/ingest_manager/server/services/datasource.test.ts
index 4cbbadce7f5bb..3682ae6d1167b 100644
--- a/x-pack/plugins/ingest_manager/server/services/datasource.test.ts
+++ b/x-pack/plugins/ingest_manager/server/services/datasource.test.ts
@@ -5,39 +5,38 @@
*/
import { datasourceService } from './datasource';
+import { PackageInfo } from '../types';
-async function mockedGetAssetsData(_a: any, _b: any, dataset: string) {
- if (dataset === 'dataset1') {
- return [
- {
- buffer: Buffer.from(`
+const TEMPLATE = `
type: log
metricset: ["dataset1"]
paths:
{{#each paths}}
- {{this}}
{{/each}}
-`),
- },
- ];
- }
- return [];
-}
-
-jest.mock('./epm/packages/assets', () => {
- return {
- getAssetsDataForPackageKey: mockedGetAssetsData,
- };
-});
+`;
describe('Datasource service', () => {
describe('assignPackageStream', () => {
- it('should work with cofig variables from the stream', async () => {
+ it('should work with config variables from the stream', async () => {
const inputs = await datasourceService.assignPackageStream(
- {
- pkgName: 'package',
- pkgVersion: '1.0.0',
- },
+ ({
+ datasources: [
+ {
+ inputs: [
+ {
+ type: 'log',
+ streams: [
+ {
+ dataset: 'package.dataset1',
+ template: TEMPLATE,
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ } as unknown) as PackageInfo,
[
{
type: 'log',
@@ -85,10 +84,23 @@ describe('Datasource service', () => {
it('should work with config variables at the input level', async () => {
const inputs = await datasourceService.assignPackageStream(
- {
- pkgName: 'package',
- pkgVersion: '1.0.0',
- },
+ ({
+ datasources: [
+ {
+ inputs: [
+ {
+ type: 'log',
+ streams: [
+ {
+ dataset: 'package.dataset1',
+ template: TEMPLATE,
+ },
+ ],
+ },
+ ],
+ },
+ ],
+ } as unknown) as PackageInfo,
[
{
type: 'log',
diff --git a/x-pack/plugins/ingest_manager/server/services/datasource.ts b/x-pack/plugins/ingest_manager/server/services/datasource.ts
index 55edfe67e540a..0a5ba43e40fba 100644
--- a/x-pack/plugins/ingest_manager/server/services/datasource.ts
+++ b/x-pack/plugins/ingest_manager/server/services/datasource.ts
@@ -10,13 +10,13 @@ import {
packageToConfigDatasource,
DatasourceInput,
DatasourceInputStream,
+ PackageInfo,
} from '../../common';
import { DATASOURCE_SAVED_OBJECT_TYPE } from '../constants';
import { NewDatasource, Datasource, ListWithKuery } from '../types';
import { agentConfigService } from './agent_config';
import { getPackageInfo, getInstallation } from './epm/packages';
import { outputService } from './output';
-import { getAssetsDataForPackageKey } from './epm/packages/assets';
import { createStream } from './epm/agent/agent';
const SAVED_OBJECT_TYPE = DATASOURCE_SAVED_OBJECT_TYPE;
@@ -200,20 +200,16 @@ class DatasourceService {
}
public async assignPackageStream(
- pkgInfo: { pkgName: string; pkgVersion: string },
+ pkgInfo: PackageInfo,
inputs: DatasourceInput[]
): Promise {
const inputsPromises = inputs.map(input => _assignPackageStreamToInput(pkgInfo, input));
+
return Promise.all(inputsPromises);
}
}
-const _isAgentStream = (p: string) => !!p.match(/agent\/stream\/stream\.yml/);
-
-async function _assignPackageStreamToInput(
- pkgInfo: { pkgName: string; pkgVersion: string },
- input: DatasourceInput
-) {
+async function _assignPackageStreamToInput(pkgInfo: PackageInfo, input: DatasourceInput) {
const streamsPromises = input.streams.map(stream =>
_assignPackageStreamToStream(pkgInfo, input, stream)
);
@@ -223,7 +219,7 @@ async function _assignPackageStreamToInput(
}
async function _assignPackageStreamToStream(
- pkgInfo: { pkgName: string; pkgVersion: string },
+ pkgInfo: PackageInfo,
input: DatasourceInput,
stream: DatasourceInputStream
) {
@@ -231,18 +227,33 @@ async function _assignPackageStreamToStream(
return { ...stream, agent_stream: undefined };
}
const dataset = getDataset(stream.dataset);
- const assetsData = await getAssetsDataForPackageKey(pkgInfo, _isAgentStream, dataset);
+ const datasource = pkgInfo.datasources?.[0];
+ if (!datasource) {
+ throw new Error('Stream template not found, no datasource');
+ }
+
+ const inputFromPkg = datasource.inputs.find(pkgInput => pkgInput.type === input.type);
+ if (!inputFromPkg) {
+ throw new Error(`Stream template not found, unable to found input ${input.type}`);
+ }
- const [pkgStream] = assetsData;
- if (!pkgStream || !pkgStream.buffer) {
+ const streamFromPkg = inputFromPkg.streams.find(
+ pkgStream => pkgStream.dataset === stream.dataset
+ );
+ if (!streamFromPkg) {
+ throw new Error(`Stream template not found, unable to found stream ${stream.dataset}`);
+ }
+
+ if (!streamFromPkg.template) {
throw new Error(`Stream template not found for dataset ${dataset}`);
}
const yaml = createStream(
// Populate template variables from input vars and stream vars
Object.assign({}, input.vars, stream.vars),
- pkgStream.buffer.toString()
+ streamFromPkg.template
);
+
stream.agent_stream = yaml;
return { ...stream };
diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts
index 206ad76703cf5..390e240841611 100644
--- a/x-pack/plugins/ingest_manager/server/services/setup.ts
+++ b/x-pack/plugins/ingest_manager/server/services/setup.ts
@@ -145,7 +145,7 @@ async function addPackageToConfig(
config.namespace
);
newDatasource.inputs = await datasourceService.assignPackageStream(
- { pkgName: packageToInstall.name, pkgVersion: packageToInstall.version },
+ packageInfo,
newDatasource.inputs
);
From 7354ff667649336b5960bc7a0dd72273b9aaa02f Mon Sep 17 00:00:00 2001
From: Tiago Costa
Date: Wed, 29 Apr 2020 16:38:41 +0100
Subject: [PATCH 20/33] Revert "chore(NA): add async import into infra plugin
to reduce apm bundle size (#63292)" (#64764)
This reverts commit 30439f6df0778582e53a6d51ec5f2b2f9885697f.
---
x-pack/plugins/infra/public/plugin.ts | 29 +++++----------------------
1 file changed, 5 insertions(+), 24 deletions(-)
diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts
index 26f206c06203b..40366b2a54f24 100644
--- a/x-pack/plugins/infra/public/plugin.ts
+++ b/x-pack/plugins/infra/public/plugin.ts
@@ -21,6 +21,8 @@ import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/p
import { DataEnhancedSetup, DataEnhancedStart } from '../../data_enhanced/public';
import { TriggersAndActionsUIPublicPluginSetup } from '../../../plugins/triggers_actions_ui/public';
+import { getAlertType as getMetricsAlertType } from './components/alerting/metrics/metric_threshold_alert_type';
+import { getAlertType as getLogsAlertType } from './components/alerting/logs/log_threshold_alert_type';
export type ClientSetup = void;
export type ClientStart = void;
@@ -51,6 +53,9 @@ export class Plugin
setup(core: CoreSetup, pluginsSetup: ClientPluginsSetup) {
registerFeatures(pluginsSetup.home);
+ pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getMetricsAlertType());
+ pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getLogsAlertType());
+
core.application.register({
id: 'logs',
title: i18n.translate('xpack.infra.logs.pluginTitle', {
@@ -65,8 +70,6 @@ export class Plugin
const plugins = getMergedPlugins(pluginsSetup, pluginsStart as ClientPluginsStart);
const { startApp, composeLibs, LogsRouter } = await this.downloadAssets();
- await this.registerLogsAlertType(pluginsSetup);
-
return startApp(
composeLibs(coreStart),
coreStart,
@@ -92,8 +95,6 @@ export class Plugin
const plugins = getMergedPlugins(pluginsSetup, pluginsStart as ClientPluginsStart);
const { startApp, composeLibs, MetricsRouter } = await this.downloadAssets();
- await this.registerMetricsAlertType(pluginsSetup);
-
return startApp(
composeLibs(coreStart),
coreStart,
@@ -137,24 +138,4 @@ export class Plugin
MetricsRouter,
};
}
-
- // NOTE: apm is importing from `infra/public` and async importing that
- // allow us to reduce the apm bundle size
- private async registerLogsAlertType(pluginsSetup: ClientPluginsSetup) {
- const { getAlertType } = await import('./components/alerting/logs/log_threshold_alert_type');
-
- if (!pluginsSetup.triggers_actions_ui.alertTypeRegistry.has(getAlertType().id)) {
- pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getAlertType());
- }
- }
-
- private async registerMetricsAlertType(pluginsSetup: ClientPluginsSetup) {
- const { getAlertType } = await import(
- './components/alerting/metrics/metric_threshold_alert_type'
- );
-
- if (!pluginsSetup.triggers_actions_ui.alertTypeRegistry.has(getAlertType().id)) {
- pluginsSetup.triggers_actions_ui.alertTypeRegistry.register(getAlertType());
- }
- }
}
From 5ee6dcd14d3734f3a9be3867f2cf0ac0e58df33f Mon Sep 17 00:00:00 2001
From: Aleh Zasypkin
Date: Wed, 29 Apr 2020 18:15:57 +0200
Subject: [PATCH 21/33] Lazy load Security plugin management apps. (#64511)
---
.../account_management_app.ts | 8 +++--
.../access_agreement/_index.scss | 1 -
...t_page.scss => access_agreement_page.scss} | 0
.../access_agreement_page.tsx | 2 +-
...ge.scss => authentication_state_page.scss} | 0
.../authentication_state_page.tsx | 2 +-
.../{_login_page.scss => login_page.scss} | 0
.../authentication/login/login_page.tsx | 2 +-
x-pack/plugins/security/public/index.scss | 4 ---
x-pack/plugins/security/public/index.ts | 1 -
.../security/public/management/_index.scss | 3 --
.../api_keys/api_keys_management_app.tsx | 13 ++++++--
.../management/role_mappings/_index.scss | 1 -
.../edit_role_mapping/_index.scss | 1 -
.../rule_editor_panel/_index.scss | 1 -
...itor_group.scss => rule_group_editor.scss} | 0
.../rule_editor_panel/rule_group_editor.tsx | 2 ++
.../role_mappings_management_app.tsx | 19 ++++++++---
.../public/management/roles/_index.scss | 1 -
.../management/roles/edit_role/_index.scss | 3 --
.../edit_role/collapsible_panel/_index.scss | 1 -
...ible_panel.scss => collapsible_panel.scss} | 0
.../collapsible_panel/collapsible_panel.tsx | 2 ++
.../roles/edit_role/privileges/_index.scss | 2 --
.../edit_role/privileges/kibana/_index.scss | 2 --
.../kibana/feature_table/_index.scss | 1 -
...ileges.scss => change_all_privileges.scss} | 0
.../feature_table/change_all_privileges.tsx | 3 ++
.../feature_table_cell.scss} | 0
.../feature_table_cell/feature_table_cell.tsx | 2 ++
.../space_aware_privilege_section/_index.scss | 1 -
.../_privilege_matrix.scss | 14 --------
.../privilege_space_table.scss | 3 ++
.../privilege_space_table.tsx | 3 ++
.../edit_role/spaces_popover_list/_index.scss | 1 -
...ver_list.scss => spaces_popover_list.scss} | 0
.../spaces_popover_list.tsx | 2 ++
.../management/roles/roles_management_app.tsx | 32 ++++++++++++-------
.../public/management/users/_index.scss | 1 -
.../management/users/edit_user/_index.scss | 1 -
...dit_user_page.scss => edit_user_page.scss} | 2 +-
.../users/edit_user/edit_user_page.tsx | 3 ++
.../management/users/users_management_app.tsx | 19 ++++++++---
43 files changed, 89 insertions(+), 70 deletions(-)
delete mode 100644 x-pack/plugins/security/public/authentication/access_agreement/_index.scss
rename x-pack/plugins/security/public/authentication/access_agreement/{_access_agreement_page.scss => access_agreement_page.scss} (100%)
rename x-pack/plugins/security/public/authentication/components/authentication_state_page/{_authentication_state_page.scss => authentication_state_page.scss} (100%)
rename x-pack/plugins/security/public/authentication/login/{_login_page.scss => login_page.scss} (100%)
delete mode 100644 x-pack/plugins/security/public/index.scss
delete mode 100644 x-pack/plugins/security/public/management/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/role_mappings/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/_index.scss
rename x-pack/plugins/security/public/management/role_mappings/edit_role_mapping/rule_editor_panel/{_rule_editor_group.scss => rule_group_editor.scss} (100%)
delete mode 100644 x-pack/plugins/security/public/management/roles/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_index.scss
rename x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/{_collapsible_panel.scss => collapsible_panel.scss} (100%)
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_index.scss
rename x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/{_change_all_privileges.scss => change_all_privileges.scss} (100%)
rename x-pack/plugins/security/public/management/roles/edit_role/privileges/{_privilege_feature_icon.scss => kibana/feature_table_cell/feature_table_cell.scss} (100%)
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_privilege_matrix.scss
create mode 100644 x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.scss
delete mode 100644 x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_index.scss
rename x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/{_spaces_popover_list.scss => spaces_popover_list.scss} (100%)
delete mode 100644 x-pack/plugins/security/public/management/users/_index.scss
delete mode 100644 x-pack/plugins/security/public/management/users/edit_user/_index.scss
rename x-pack/plugins/security/public/management/users/edit_user/{_edit_user_page.scss => edit_user_page.scss} (76%)
diff --git a/x-pack/plugins/security/public/account_management/account_management_app.ts b/x-pack/plugins/security/public/account_management/account_management_app.ts
index cd3ef34858b19..41567a04fe030 100644
--- a/x-pack/plugins/security/public/account_management/account_management_app.ts
+++ b/x-pack/plugins/security/public/account_management/account_management_app.ts
@@ -7,7 +7,6 @@
import { i18n } from '@kbn/i18n';
import { StartServicesAccessor, ApplicationSetup, AppMountParameters } from 'src/core/public';
import { AuthenticationServiceSetup } from '../authentication';
-import { UserAPIClient } from '../management';
interface CreateDeps {
application: ApplicationSetup;
@@ -28,9 +27,14 @@ export const accountManagementApp = Object.freeze({
navLinkStatus: 3,
appRoute: '/security/account',
async mount({ element }: AppMountParameters) {
- const [[coreStart], { renderAccountManagementPage }] = await Promise.all([
+ const [
+ [coreStart],
+ { renderAccountManagementPage },
+ { UserAPIClient },
+ ] = await Promise.all([
getStartServices(),
import('./account_management_page'),
+ import('../management'),
]);
coreStart.chrome.setBreadcrumbs([{ text: title }]);
diff --git a/x-pack/plugins/security/public/authentication/access_agreement/_index.scss b/x-pack/plugins/security/public/authentication/access_agreement/_index.scss
deleted file mode 100644
index dbab8347b096f..0000000000000
--- a/x-pack/plugins/security/public/authentication/access_agreement/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './access_agreement_page';
diff --git a/x-pack/plugins/security/public/authentication/access_agreement/_access_agreement_page.scss b/x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.scss
similarity index 100%
rename from x-pack/plugins/security/public/authentication/access_agreement/_access_agreement_page.scss
rename to x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.scss
diff --git a/x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.tsx b/x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.tsx
index 0315e229c678b..a34dcb18d2b9c 100644
--- a/x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.tsx
+++ b/x-pack/plugins/security/public/authentication/access_agreement/access_agreement_page.tsx
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import './_index.scss';
+import './access_agreement_page.scss';
import React, { FormEvent, MouseEvent, useCallback, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
diff --git a/x-pack/plugins/security/public/authentication/components/authentication_state_page/_authentication_state_page.scss b/x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.scss
similarity index 100%
rename from x-pack/plugins/security/public/authentication/components/authentication_state_page/_authentication_state_page.scss
rename to x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.scss
diff --git a/x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.tsx b/x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.tsx
index 7567f455bcca6..35be650d127fb 100644
--- a/x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.tsx
+++ b/x-pack/plugins/security/public/authentication/components/authentication_state_page/authentication_state_page.tsx
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import './_authentication_state_page.scss';
+import './authentication_state_page.scss';
import { EuiIcon, EuiSpacer, EuiTitle } from '@elastic/eui';
import React from 'react';
diff --git a/x-pack/plugins/security/public/authentication/login/_login_page.scss b/x-pack/plugins/security/public/authentication/login/login_page.scss
similarity index 100%
rename from x-pack/plugins/security/public/authentication/login/_login_page.scss
rename to x-pack/plugins/security/public/authentication/login/login_page.scss
diff --git a/x-pack/plugins/security/public/authentication/login/login_page.tsx b/x-pack/plugins/security/public/authentication/login/login_page.tsx
index b7ac70f2aaf89..d24a301ed24ec 100644
--- a/x-pack/plugins/security/public/authentication/login/login_page.tsx
+++ b/x-pack/plugins/security/public/authentication/login/login_page.tsx
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import './_login_page.scss';
+import './login_page.scss';
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
diff --git a/x-pack/plugins/security/public/index.scss b/x-pack/plugins/security/public/index.scss
deleted file mode 100644
index 1bdb8cc178fdf..0000000000000
--- a/x-pack/plugins/security/public/index.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-$secFormWidth: 460px;
-
-// Management styles
-@import './management/index';
diff --git a/x-pack/plugins/security/public/index.ts b/x-pack/plugins/security/public/index.ts
index fc4e158652a0a..8016c94224060 100644
--- a/x-pack/plugins/security/public/index.ts
+++ b/x-pack/plugins/security/public/index.ts
@@ -4,7 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import './index.scss';
import { PluginInitializer, PluginInitializerContext } from 'src/core/public';
import {
SecurityPlugin,
diff --git a/x-pack/plugins/security/public/management/_index.scss b/x-pack/plugins/security/public/management/_index.scss
deleted file mode 100644
index 5d419b5323079..0000000000000
--- a/x-pack/plugins/security/public/management/_index.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-@import './roles/index';
-@import './users/index';
-@import './role_mappings/index';
diff --git a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx
index 272fc9cfc2fe6..b9ec5b35b3f9d 100644
--- a/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx
+++ b/x-pack/plugins/security/public/management/api_keys/api_keys_management_app.tsx
@@ -10,8 +10,6 @@ import { i18n } from '@kbn/i18n';
import { StartServicesAccessor } from 'src/core/public';
import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public';
import { PluginStartDependencies } from '../../plugin';
-import { APIKeysGridPage } from './api_keys_grid';
-import { APIKeysAPIClient } from './api_keys_api_client';
import { DocumentationLinksService } from './documentation_links';
interface CreateParams {
@@ -28,7 +26,6 @@ export const apiKeysManagementApp = Object.freeze({
defaultMessage: 'API Keys',
}),
async mount({ basePath, element, setBreadcrumbs }) {
- const [{ docLinks, http, notifications, i18n: i18nStart }] = await getStartServices();
setBreadcrumbs([
{
text: i18n.translate('xpack.security.apiKeys.breadcrumb', {
@@ -38,6 +35,16 @@ export const apiKeysManagementApp = Object.freeze({
},
]);
+ const [
+ [{ docLinks, http, notifications, i18n: i18nStart }],
+ { APIKeysGridPage },
+ { APIKeysAPIClient },
+ ] = await Promise.all([
+ getStartServices(),
+ import('./api_keys_grid'),
+ import('./api_keys_api_client'),
+ ]);
+
render(
;
@@ -31,7 +27,6 @@ export const roleMappingsManagementApp = Object.freeze({
defaultMessage: 'Role Mappings',
}),
async mount({ basePath, element, setBreadcrumbs }) {
- const [{ docLinks, http, notifications, i18n: i18nStart }] = await getStartServices();
const roleMappingsBreadcrumbs = [
{
text: i18n.translate('xpack.security.roleMapping.breadcrumb', {
@@ -41,6 +36,20 @@ export const roleMappingsManagementApp = Object.freeze({
},
];
+ const [
+ [{ docLinks, http, notifications, i18n: i18nStart }],
+ { RoleMappingsGridPage },
+ { EditRoleMappingPage },
+ { RoleMappingsAPIClient },
+ { RolesAPIClient },
+ ] = await Promise.all([
+ getStartServices(),
+ import('./role_mappings_grid'),
+ import('./edit_role_mapping'),
+ import('./role_mappings_api_client'),
+ import('../roles'),
+ ]);
+
const roleMappingsAPIClient = new RoleMappingsAPIClient(http);
const dockLinksService = new DocumentationLinksService(docLinks);
const RoleMappingsGridPageWithBreadcrumbs = () => {
diff --git a/x-pack/plugins/security/public/management/roles/_index.scss b/x-pack/plugins/security/public/management/roles/_index.scss
deleted file mode 100644
index 5256c79f01f10..0000000000000
--- a/x-pack/plugins/security/public/management/roles/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './edit_role/index';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/_index.scss
deleted file mode 100644
index 0153b1734ceba..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/_index.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-@import './collapsible_panel/index';
-@import './spaces_popover_list/index';
-@import './privileges/index';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_index.scss
deleted file mode 100644
index c0f4f8ab9a870..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './collapsible_panel';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_collapsible_panel.scss b/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.scss
similarity index 100%
rename from x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/_collapsible_panel.scss
rename to x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.scss
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.tsx b/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.tsx
index 01af7cb4509f6..eb1417600e19b 100644
--- a/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.tsx
+++ b/x-pack/plugins/security/public/management/roles/edit_role/collapsible_panel/collapsible_panel.tsx
@@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import './collapsible_panel.scss';
+
import {
EuiFlexGroup,
EuiFlexItem,
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/_index.scss
deleted file mode 100644
index a1a9d038065e6..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/_index.scss
+++ /dev/null
@@ -1,2 +0,0 @@
-@import './privilege_feature_icon';
-@import './kibana/index';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/_index.scss
deleted file mode 100644
index 19547c0e1953e..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/_index.scss
+++ /dev/null
@@ -1,2 +0,0 @@
-@import './feature_table/index';
-@import './space_aware_privilege_section/index';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_index.scss
deleted file mode 100644
index 6a96553742819..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './change_all_privileges';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_change_all_privileges.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.scss
similarity index 100%
rename from x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/_change_all_privileges.scss
rename to x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.scss
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.tsx b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.tsx
index 2083778e53998..5d7b13acf79da 100644
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.tsx
+++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table/change_all_privileges.tsx
@@ -3,6 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
+
+import './change_all_privileges.scss';
+
import { EuiContextMenuItem, EuiContextMenuPanel, EuiLink, EuiPopover } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import _ from 'lodash';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/_privilege_feature_icon.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.scss
similarity index 100%
rename from x-pack/plugins/security/public/management/roles/edit_role/privileges/_privilege_feature_icon.scss
rename to x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.scss
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.tsx b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.tsx
index 9e4a3a8a99b56..77445952f3d69 100644
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.tsx
+++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/feature_table_cell/feature_table_cell.tsx
@@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import './feature_table_cell.scss';
+
import React from 'react';
import { EuiText, EuiIconTip, EuiIcon, IconType } from '@elastic/eui';
import { SecuredFeature } from '../../../../model';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_index.scss
deleted file mode 100644
index 3f40f21e102a1..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './privilege_matrix';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_privilege_matrix.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_privilege_matrix.scss
deleted file mode 100644
index 8f47727fdf8d6..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/_privilege_matrix.scss
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * 1. Allow table to scroll both directions
- */
-
-.secPrivilegeMatrix__modal,
-.secPrivilegeMatrix__modal .euiModal__flex {
- overflow: hidden; /* 1 */
-}
-
-.secPrivilegeMatrix__row--isBasePrivilege,
-.secPrivilegeMatrix__cell--isGlobalPrivilege,
-.secPrivilegeTable__row--isGlobalSpace {
- background-color: $euiColorLightestShade;
-}
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.scss b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.scss
new file mode 100644
index 0000000000000..8e2a3b0512afb
--- /dev/null
+++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.scss
@@ -0,0 +1,3 @@
+.secPrivilegeTable__row--isGlobalSpace {
+ background-color: $euiColorLightestShade;
+}
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.tsx b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.tsx
index ccb5398a11b23..30a275876fdc7 100644
--- a/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.tsx
+++ b/x-pack/plugins/security/public/management/roles/edit_role/privileges/kibana/space_aware_privilege_section/privilege_space_table.tsx
@@ -3,6 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
+
+import './privilege_space_table.scss';
+
import {
EuiBadge,
EuiBadgeProps,
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_index.scss b/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_index.scss
deleted file mode 100644
index b40a32cb8df96..0000000000000
--- a/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './spaces_popover_list';
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_spaces_popover_list.scss b/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.scss
similarity index 100%
rename from x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/_spaces_popover_list.scss
rename to x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.scss
diff --git a/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.tsx b/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.tsx
index 92e42ec811afc..63ee311f3155e 100644
--- a/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.tsx
+++ b/x-pack/plugins/security/public/management/roles/edit_role/spaces_popover_list/spaces_popover_list.tsx
@@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import './spaces_popover_list.scss';
+
import {
EuiButtonEmpty,
EuiContextMenuItem,
diff --git a/x-pack/plugins/security/public/management/roles/roles_management_app.tsx b/x-pack/plugins/security/public/management/roles/roles_management_app.tsx
index e1a10fdc2b8c3..9aaa3b47f3b19 100644
--- a/x-pack/plugins/security/public/management/roles/roles_management_app.tsx
+++ b/x-pack/plugins/security/public/management/roles/roles_management_app.tsx
@@ -12,13 +12,7 @@ import { StartServicesAccessor, FatalErrorsSetup } from 'src/core/public';
import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public';
import { SecurityLicense } from '../../../common/licensing';
import { PluginStartDependencies } from '../../plugin';
-import { UserAPIClient } from '../users';
-import { RolesAPIClient } from './roles_api_client';
-import { RolesGridPage } from './roles_grid';
-import { EditRolePage } from './edit_role';
import { DocumentationLinksService } from './documentation_links';
-import { IndicesAPIClient } from './indices_api_client';
-import { PrivilegesAPIClient } from './privileges_api_client';
interface CreateParams {
fatalErrors: FatalErrorsSetup;
@@ -34,11 +28,6 @@ export const rolesManagementApp = Object.freeze({
order: 20,
title: i18n.translate('xpack.security.management.rolesTitle', { defaultMessage: 'Roles' }),
async mount({ basePath, element, setBreadcrumbs }) {
- const [
- { application, docLinks, http, i18n: i18nStart, injectedMetadata, notifications },
- { data, features },
- ] = await getStartServices();
-
const rolesBreadcrumbs = [
{
text: i18n.translate('xpack.security.roles.breadcrumb', { defaultMessage: 'Roles' }),
@@ -46,6 +35,27 @@ export const rolesManagementApp = Object.freeze({
},
];
+ const [
+ [
+ { application, docLinks, http, i18n: i18nStart, injectedMetadata, notifications },
+ { data, features },
+ ],
+ { RolesGridPage },
+ { EditRolePage },
+ { RolesAPIClient },
+ { IndicesAPIClient },
+ { PrivilegesAPIClient },
+ { UserAPIClient },
+ ] = await Promise.all([
+ getStartServices(),
+ import('./roles_grid'),
+ import('./edit_role'),
+ import('./roles_api_client'),
+ import('./indices_api_client'),
+ import('./privileges_api_client'),
+ import('../users'),
+ ]);
+
const rolesAPIClient = new RolesAPIClient(http);
const RolesGridPageWithBreadcrumbs = () => {
setBreadcrumbs(rolesBreadcrumbs);
diff --git a/x-pack/plugins/security/public/management/users/_index.scss b/x-pack/plugins/security/public/management/users/_index.scss
deleted file mode 100644
index 35df0c1b96583..0000000000000
--- a/x-pack/plugins/security/public/management/users/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './edit_user/index';
diff --git a/x-pack/plugins/security/public/management/users/edit_user/_index.scss b/x-pack/plugins/security/public/management/users/edit_user/_index.scss
deleted file mode 100644
index 734ba7882ba72..0000000000000
--- a/x-pack/plugins/security/public/management/users/edit_user/_index.scss
+++ /dev/null
@@ -1 +0,0 @@
-@import './edit_user_page';
diff --git a/x-pack/plugins/security/public/management/users/edit_user/_edit_user_page.scss b/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.scss
similarity index 76%
rename from x-pack/plugins/security/public/management/users/edit_user/_edit_user_page.scss
rename to x-pack/plugins/security/public/management/users/edit_user/edit_user_page.scss
index 7b24b74aceba0..727fac4782752 100644
--- a/x-pack/plugins/security/public/management/users/edit_user/_edit_user_page.scss
+++ b/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.scss
@@ -1,5 +1,5 @@
.secUsersEditPage__content {
- max-width: $secFormWidth;
+ max-width: 460px;
margin-left: auto;
margin-right: auto;
flex-grow: 0;
diff --git a/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.tsx b/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.tsx
index 6417ce81b647d..1c8130029bb50 100644
--- a/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.tsx
+++ b/x-pack/plugins/security/public/management/users/edit_user/edit_user_page.tsx
@@ -3,6 +3,9 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
+
+import './edit_user_page.scss';
+
import { get } from 'lodash';
import React, { Component, Fragment, ChangeEvent } from 'react';
import {
diff --git a/x-pack/plugins/security/public/management/users/users_management_app.tsx b/x-pack/plugins/security/public/management/users/users_management_app.tsx
index 82a2b8d2a98ad..9d337c1508ad4 100644
--- a/x-pack/plugins/security/public/management/users/users_management_app.tsx
+++ b/x-pack/plugins/security/public/management/users/users_management_app.tsx
@@ -12,10 +12,6 @@ import { StartServicesAccessor } from 'src/core/public';
import { RegisterManagementAppArgs } from '../../../../../../src/plugins/management/public';
import { AuthenticationServiceSetup } from '../../authentication';
import { PluginStartDependencies } from '../../plugin';
-import { RolesAPIClient } from '../roles';
-import { UserAPIClient } from './user_api_client';
-import { UsersGridPage } from './users_grid';
-import { EditUserPage } from './edit_user';
interface CreateParams {
authc: AuthenticationServiceSetup;
@@ -30,7 +26,6 @@ export const usersManagementApp = Object.freeze({
order: 10,
title: i18n.translate('xpack.security.management.usersTitle', { defaultMessage: 'Users' }),
async mount({ basePath, element, setBreadcrumbs }) {
- const [{ http, notifications, i18n: i18nStart }] = await getStartServices();
const usersBreadcrumbs = [
{
text: i18n.translate('xpack.security.users.breadcrumb', { defaultMessage: 'Users' }),
@@ -38,6 +33,20 @@ export const usersManagementApp = Object.freeze({
},
];
+ const [
+ [{ http, notifications, i18n: i18nStart }],
+ { UsersGridPage },
+ { EditUserPage },
+ { UserAPIClient },
+ { RolesAPIClient },
+ ] = await Promise.all([
+ getStartServices(),
+ import('./users_grid'),
+ import('./edit_user'),
+ import('./user_api_client'),
+ import('../roles'),
+ ]);
+
const userAPIClient = new UserAPIClient(http);
const rolesAPIClient = new RolesAPIClient(http);
const UsersGridPageWithBreadcrumbs = () => {
From 5082ff3252f60f2ed6f4ed3789a1f142e1667e1f Mon Sep 17 00:00:00 2001
From: Mikhail Shustov
Date: Wed, 29 Apr 2020 18:43:15 +0200
Subject: [PATCH 22/33] use cache busting for KP bundles (#64414)
* convert into TS
* load plugin scripts in html body
* use buildNum as a unique Id for cache busting
* add tests for caching
* fix tests
* remove the last TODO. url should be inlined with assetss server
* this logic handled by publicPathMap on the client
* cache kbn-shared-deps as well
* attempt to fix karma tests
* always run file through replace stream
* place buildHash at begining of path, include all static files
* update bundles_route tests to inject buildNum everywhere
* fix karma config to point to right prefix
* use isDist naming throughout
* explain magic number with variables
* restore replacePublicPath option from #64226
* replace one more instance of replacePublicPath
* use promisify instead of bluebird + non-null assertions
* remove one more magic number
Co-authored-by: spalger
Co-authored-by: Elastic Machine
---
src/legacy/ui/ui_render/ui_render_mixin.js | 15 ++-
.../bundles_route/__tests__/bundles_route.js | 119 +++++++++++++++---
src/optimize/bundles_route/bundles_route.ts | 35 ++++--
.../bundles_route/dynamic_asset_response.ts | 25 +++-
.../bundles_route/proxy_bundles_route.ts | 16 ++-
src/optimize/np_ui_plugin_public_dirs.ts | 1 -
src/optimize/optimize_mixin.ts | 2 +
src/optimize/watch/optmzr_role.js | 3 +-
src/optimize/watch/proxy_role.js | 1 +
src/optimize/watch/watch_optimizer.js | 3 +-
src/optimize/watch/watch_server.js | 10 +-
tasks/config/karma.js | 26 ++--
12 files changed, 195 insertions(+), 61 deletions(-)
diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js
index d42d6d556b37b..692b787ccf405 100644
--- a/src/legacy/ui/ui_render/ui_render_mixin.js
+++ b/src/legacy/ui/ui_render/ui_render_mixin.js
@@ -96,9 +96,12 @@ export function uiRenderMixin(kbnServer, server, config) {
? await uiSettings.get('theme:darkMode')
: false;
+ const buildHash = server.newPlatform.env.packageInfo.buildNum;
const basePath = config.get('server.basePath');
- const regularBundlePath = `${basePath}/bundles`;
- const dllBundlePath = `${basePath}/built_assets/dlls`;
+
+ const regularBundlePath = `${basePath}/${buildHash}/bundles`;
+ const dllBundlePath = `${basePath}/${buildHash}/built_assets/dlls`;
+
const dllStyleChunks = DllCompiler.getRawDllConfig().chunks.map(
chunk => `${dllBundlePath}/vendors${chunk}.style.dll.css`
);
@@ -108,15 +111,15 @@ export function uiRenderMixin(kbnServer, server, config) {
const styleSheetPaths = [
...(isCore ? [] : dllStyleChunks),
- `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.baseCssDistFilename}`,
+ `${regularBundlePath}/kbn-ui-shared-deps/${UiSharedDeps.baseCssDistFilename}`,
...(darkMode
? [
- `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.darkCssDistFilename}`,
+ `${regularBundlePath}/kbn-ui-shared-deps/${UiSharedDeps.darkCssDistFilename}`,
`${basePath}/node_modules/@kbn/ui-framework/dist/kui_dark.css`,
`${regularBundlePath}/dark_theme.style.css`,
]
: [
- `${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`,
+ `${regularBundlePath}/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`,
`${basePath}/node_modules/@kbn/ui-framework/dist/kui_light.css`,
`${regularBundlePath}/light_theme.style.css`,
]),
@@ -131,7 +134,7 @@ export function uiRenderMixin(kbnServer, server, config) {
)
.map(path =>
path.localPath.endsWith('.scss')
- ? `${basePath}/built_assets/css/${path.publicPath}`
+ ? `${basePath}/${buildHash}/built_assets/css/${path.publicPath}`
: `${basePath}/${path.publicPath}`
)
.reverse(),
diff --git a/src/optimize/bundles_route/__tests__/bundles_route.js b/src/optimize/bundles_route/__tests__/bundles_route.js
index 0b2aeda11fb0e..902fa59b20569 100644
--- a/src/optimize/bundles_route/__tests__/bundles_route.js
+++ b/src/optimize/bundles_route/__tests__/bundles_route.js
@@ -32,6 +32,7 @@ import { PUBLIC_PATH_PLACEHOLDER } from '../../public_path_placeholder';
const chance = new Chance();
const outputFixture = resolve(__dirname, './fixtures/output');
+const pluginNoPlaceholderFixture = resolve(__dirname, './fixtures/plugin/no_placeholder');
const randomWordsCache = new Set();
const uniqueRandomWord = () => {
@@ -58,6 +59,9 @@ describe('optimizer/bundle route', () => {
dllBundlesPath = outputFixture,
basePublicPath = '',
builtCssPath = outputFixture,
+ npUiPluginPublicDirs = [],
+ buildHash = '1234',
+ isDist = false,
} = options;
const server = new Hapi.Server();
@@ -69,6 +73,9 @@ describe('optimizer/bundle route', () => {
dllBundlesPath,
basePublicPath,
builtCssPath,
+ npUiPluginPublicDirs,
+ buildHash,
+ isDist,
})
);
@@ -158,7 +165,7 @@ describe('optimizer/bundle route', () => {
it('responds with exact file data', async () => {
const server = createServer();
const response = await server.inject({
- url: '/bundles/image.png',
+ url: '/1234/bundles/image.png',
});
expect(response.statusCode).to.be(200);
@@ -173,7 +180,7 @@ describe('optimizer/bundle route', () => {
it('responds with no content-length and exact file data', async () => {
const server = createServer();
const response = await server.inject({
- url: '/bundles/no_placeholder.js',
+ url: '/1234/bundles/no_placeholder.js',
});
expect(response.statusCode).to.be(200);
@@ -187,12 +194,12 @@ describe('optimizer/bundle route', () => {
});
describe('js file with placeholder', () => {
- it('responds with no content-length and modified file data', async () => {
+ it('responds with no content-length and modifiedfile data ', async () => {
const basePublicPath = `/${uniqueRandomWord()}`;
const server = createServer({ basePublicPath });
const response = await server.inject({
- url: '/bundles/with_placeholder.js',
+ url: '/1234/bundles/with_placeholder.js',
});
expect(response.statusCode).to.be(200);
@@ -204,7 +211,7 @@ describe('optimizer/bundle route', () => {
);
expect(response.result.indexOf(source)).to.be(-1);
expect(response.result).to.be(
- replaceAll(source, PUBLIC_PATH_PLACEHOLDER, `${basePublicPath}/bundles/`)
+ replaceAll(source, PUBLIC_PATH_PLACEHOLDER, `${basePublicPath}/1234/bundles/`)
);
});
});
@@ -213,7 +220,7 @@ describe('optimizer/bundle route', () => {
it('responds with no content-length and exact file data', async () => {
const server = createServer();
const response = await server.inject({
- url: '/bundles/no_placeholder.css',
+ url: '/1234/bundles/no_placeholder.css',
});
expect(response.statusCode).to.be(200);
@@ -231,7 +238,7 @@ describe('optimizer/bundle route', () => {
const server = createServer({ basePublicPath });
const response = await server.inject({
- url: '/bundles/with_placeholder.css',
+ url: '/1234/bundles/with_placeholder.css',
});
expect(response.statusCode).to.be(200);
@@ -240,7 +247,7 @@ describe('optimizer/bundle route', () => {
expect(response.headers).to.have.property('content-type', 'text/css; charset=utf-8');
expect(response.result.indexOf(source)).to.be(-1);
expect(response.result).to.be(
- replaceAll(source, PUBLIC_PATH_PLACEHOLDER, `${basePublicPath}/bundles/`)
+ replaceAll(source, PUBLIC_PATH_PLACEHOLDER, `${basePublicPath}/1234/bundles/`)
);
});
});
@@ -250,7 +257,7 @@ describe('optimizer/bundle route', () => {
const server = createServer();
const response = await server.inject({
- url: '/bundles/../outside_output.js',
+ url: '/1234/bundles/../outside_output.js',
});
expect(response.statusCode).to.be(404);
@@ -267,7 +274,7 @@ describe('optimizer/bundle route', () => {
const server = createServer();
const response = await server.inject({
- url: '/bundles/non_existent.js',
+ url: '/1234/bundles/non_existent.js',
});
expect(response.statusCode).to.be(404);
@@ -286,7 +293,7 @@ describe('optimizer/bundle route', () => {
});
const response = await server.inject({
- url: '/bundles/with_placeholder.js',
+ url: '/1234/bundles/with_placeholder.js',
});
expect(response.statusCode).to.be(404);
@@ -306,7 +313,7 @@ describe('optimizer/bundle route', () => {
sinon.assert.notCalled(createHash);
const resp1 = await server.inject({
- url: '/bundles/no_placeholder.js',
+ url: '/1234/bundles/no_placeholder.js',
});
sinon.assert.calledOnce(createHash);
@@ -314,23 +321,23 @@ describe('optimizer/bundle route', () => {
expect(resp1.statusCode).to.be(200);
const resp2 = await server.inject({
- url: '/bundles/no_placeholder.js',
+ url: '/1234/bundles/no_placeholder.js',
});
sinon.assert.notCalled(createHash);
expect(resp2.statusCode).to.be(200);
});
- it('is unique per basePublicPath although content is the same', async () => {
+ it('is unique per basePublicPath although content is the same (by default)', async () => {
const basePublicPath1 = `/${uniqueRandomWord()}`;
const basePublicPath2 = `/${uniqueRandomWord()}`;
const [resp1, resp2] = await Promise.all([
createServer({ basePublicPath: basePublicPath1 }).inject({
- url: '/bundles/no_placeholder.js',
+ url: '/1234/bundles/no_placeholder.js',
}),
createServer({ basePublicPath: basePublicPath2 }).inject({
- url: '/bundles/no_placeholder.js',
+ url: '/1234/bundles/no_placeholder.js',
}),
]);
@@ -349,13 +356,13 @@ describe('optimizer/bundle route', () => {
it('responds with 304 when etag and last modified are sent back', async () => {
const server = createServer();
const resp = await server.inject({
- url: '/bundles/with_placeholder.js',
+ url: '/1234/bundles/with_placeholder.js',
});
expect(resp.statusCode).to.be(200);
const resp2 = await server.inject({
- url: '/bundles/with_placeholder.js',
+ url: '/1234/bundles/with_placeholder.js',
headers: {
'if-modified-since': resp.headers['last-modified'],
'if-none-match': resp.headers.etag,
@@ -366,4 +373,80 @@ describe('optimizer/bundle route', () => {
expect(resp2.result).to.have.length(0);
});
});
+
+ describe('kibana platform assets', () => {
+ describe('caching', () => {
+ describe('for non-distributable mode', () => {
+ it('uses "etag" header to invalidate cache', async () => {
+ const basePublicPath = `/${uniqueRandomWord()}`;
+
+ const npUiPluginPublicDirs = [
+ {
+ id: 'no_placeholder',
+ path: pluginNoPlaceholderFixture,
+ },
+ ];
+ const responce = await createServer({ basePublicPath, npUiPluginPublicDirs }).inject({
+ url: '/1234/bundles/plugin/no_placeholder/no_placeholder.plugin.js',
+ });
+
+ expect(responce.statusCode).to.be(200);
+
+ expect(responce.headers.etag).to.be.a('string');
+ expect(responce.headers['cache-control']).to.be('must-revalidate');
+ });
+
+ it('creates the same "etag" header for the same content with the same basePath', async () => {
+ const npUiPluginPublicDirs = [
+ {
+ id: 'no_placeholder',
+ path: pluginNoPlaceholderFixture,
+ },
+ ];
+ const [resp1, resp2] = await Promise.all([
+ createServer({ basePublicPath: '', npUiPluginPublicDirs }).inject({
+ url: '/1234/bundles/plugin/no_placeholder/no_placeholder.plugin.js',
+ }),
+ createServer({ basePublicPath: '', npUiPluginPublicDirs }).inject({
+ url: '/1234/bundles/plugin/no_placeholder/no_placeholder.plugin.js',
+ }),
+ ]);
+
+ expect(resp1.statusCode).to.be(200);
+ expect(resp2.statusCode).to.be(200);
+
+ expect(resp1.rawPayload).to.eql(resp2.rawPayload);
+
+ expect(resp1.headers.etag).to.be.a('string');
+ expect(resp2.headers.etag).to.be.a('string');
+ expect(resp1.headers.etag).to.eql(resp2.headers.etag);
+ });
+ });
+
+ describe('for distributable mode', () => {
+ it('commands to cache assets for each release for a year', async () => {
+ const basePublicPath = `/${uniqueRandomWord()}`;
+
+ const npUiPluginPublicDirs = [
+ {
+ id: 'no_placeholder',
+ path: pluginNoPlaceholderFixture,
+ },
+ ];
+ const responce = await createServer({
+ basePublicPath,
+ npUiPluginPublicDirs,
+ isDist: true,
+ }).inject({
+ url: '/1234/bundles/plugin/no_placeholder/no_placeholder.plugin.js',
+ });
+
+ expect(responce.statusCode).to.be(200);
+
+ expect(responce.headers.etag).to.be(undefined);
+ expect(responce.headers['cache-control']).to.be('max-age=31536000');
+ });
+ });
+ });
+ });
});
diff --git a/src/optimize/bundles_route/bundles_route.ts b/src/optimize/bundles_route/bundles_route.ts
index 5605ec5338969..e9cfba0130d95 100644
--- a/src/optimize/bundles_route/bundles_route.ts
+++ b/src/optimize/bundles_route/bundles_route.ts
@@ -47,12 +47,16 @@ export function createBundlesRoute({
basePublicPath,
builtCssPath,
npUiPluginPublicDirs = [],
+ buildHash,
+ isDist = false,
}: {
regularBundlesPath: string;
dllBundlesPath: string;
basePublicPath: string;
builtCssPath: string;
npUiPluginPublicDirs?: NpUiPluginPublicDirs;
+ buildHash: string;
+ isDist?: boolean;
}) {
// rather than calculate the fileHash on every request, we
// provide a cache object to `resolveDynamicAssetResponse()` that
@@ -82,45 +86,51 @@ export function createBundlesRoute({
return [
buildRouteForBundles({
- publicPath: `${basePublicPath}/bundles/kbn-ui-shared-deps/`,
- routePath: '/bundles/kbn-ui-shared-deps/',
+ publicPath: `${basePublicPath}/${buildHash}/bundles/kbn-ui-shared-deps/`,
+ routePath: `/${buildHash}/bundles/kbn-ui-shared-deps/`,
bundlesPath: UiSharedDeps.distDir,
fileHashCache,
replacePublicPath: false,
+ isDist,
}),
...npUiPluginPublicDirs.map(({ id, path }) =>
buildRouteForBundles({
- publicPath: `${basePublicPath}/bundles/plugin/${id}/`,
- routePath: `/bundles/plugin/${id}/`,
+ publicPath: `${basePublicPath}/${buildHash}/bundles/plugin/${id}/`,
+ routePath: `/${buildHash}/bundles/plugin/${id}/`,
bundlesPath: path,
fileHashCache,
replacePublicPath: false,
+ isDist,
})
),
buildRouteForBundles({
- publicPath: `${basePublicPath}/bundles/core/`,
- routePath: `/bundles/core/`,
+ publicPath: `${basePublicPath}/${buildHash}/bundles/core/`,
+ routePath: `/${buildHash}/bundles/core/`,
bundlesPath: fromRoot(join('src', 'core', 'target', 'public')),
fileHashCache,
replacePublicPath: false,
+ isDist,
}),
buildRouteForBundles({
- publicPath: `${basePublicPath}/bundles/`,
- routePath: '/bundles/',
+ publicPath: `${basePublicPath}/${buildHash}/bundles/`,
+ routePath: `/${buildHash}/bundles/`,
bundlesPath: regularBundlesPath,
fileHashCache,
+ isDist,
}),
buildRouteForBundles({
- publicPath: `${basePublicPath}/built_assets/dlls/`,
- routePath: '/built_assets/dlls/',
+ publicPath: `${basePublicPath}/${buildHash}/built_assets/dlls/`,
+ routePath: `/${buildHash}/built_assets/dlls/`,
bundlesPath: dllBundlesPath,
fileHashCache,
+ isDist,
}),
buildRouteForBundles({
publicPath: `${basePublicPath}/`,
- routePath: '/built_assets/css/',
+ routePath: `/${buildHash}/built_assets/css/`,
bundlesPath: builtCssPath,
fileHashCache,
+ isDist,
}),
];
}
@@ -131,12 +141,14 @@ function buildRouteForBundles({
bundlesPath,
fileHashCache,
replacePublicPath = true,
+ isDist,
}: {
publicPath: string;
routePath: string;
bundlesPath: string;
fileHashCache: FileHashCache;
replacePublicPath?: boolean;
+ isDist: boolean;
}) {
return {
method: 'GET',
@@ -159,6 +171,7 @@ function buildRouteForBundles({
fileHashCache,
publicPath,
replacePublicPath,
+ isDist,
});
},
},
diff --git a/src/optimize/bundles_route/dynamic_asset_response.ts b/src/optimize/bundles_route/dynamic_asset_response.ts
index bebc062ee949d..a020c6935eeec 100644
--- a/src/optimize/bundles_route/dynamic_asset_response.ts
+++ b/src/optimize/bundles_route/dynamic_asset_response.ts
@@ -17,8 +17,8 @@
* under the License.
*/
-import { resolve } from 'path';
import Fs from 'fs';
+import { resolve } from 'path';
import { promisify } from 'util';
import Boom from 'boom';
@@ -26,8 +26,13 @@ import Hapi from 'hapi';
import { FileHashCache } from './file_hash_cache';
import { getFileHash } from './file_hash';
+// @ts-ignore
import { replacePlaceholder } from '../public_path_placeholder';
+const MINUTE = 60;
+const HOUR = 60 * MINUTE;
+const DAY = 24 * HOUR;
+
const asyncOpen = promisify(Fs.open);
const asyncClose = promisify(Fs.close);
const asyncFstat = promisify(Fs.fstat);
@@ -58,6 +63,7 @@ export async function createDynamicAssetResponse({
publicPath,
fileHashCache,
replacePublicPath,
+ isDist,
}: {
request: Hapi.Request;
h: Hapi.ResponseToolkit;
@@ -65,6 +71,7 @@ export async function createDynamicAssetResponse({
publicPath: string;
fileHashCache: FileHashCache;
replacePublicPath: boolean;
+ isDist: boolean;
}) {
let fd: number | undefined;
@@ -82,7 +89,7 @@ export async function createDynamicAssetResponse({
fd = await asyncOpen(path, 'r');
const stat = await asyncFstat(fd);
- const hash = await getFileHash(fileHashCache, path, stat, fd);
+ const hash = isDist ? undefined : await getFileHash(fileHashCache, path, stat, fd);
const read = Fs.createReadStream(null as any, {
fd,
@@ -92,15 +99,21 @@ export async function createDynamicAssetResponse({
fd = undefined; // read stream is now responsible for fd
const content = replacePublicPath ? replacePlaceholder(read, publicPath) : read;
- const etag = replacePublicPath ? `${hash}-${publicPath}` : hash;
- return h
+ const response = h
.response(content)
.takeover()
.code(200)
- .etag(etag)
- .header('cache-control', 'must-revalidate')
.type(request.server.mime.path(path).type);
+
+ if (isDist) {
+ response.header('cache-control', `max-age=${365 * DAY}`);
+ } else {
+ response.etag(`${hash}-${publicPath}`);
+ response.header('cache-control', 'must-revalidate');
+ }
+
+ return response;
} catch (error) {
if (fd) {
try {
diff --git a/src/optimize/bundles_route/proxy_bundles_route.ts b/src/optimize/bundles_route/proxy_bundles_route.ts
index 97616f7041f1c..1d189054324a1 100644
--- a/src/optimize/bundles_route/proxy_bundles_route.ts
+++ b/src/optimize/bundles_route/proxy_bundles_route.ts
@@ -17,11 +17,19 @@
* under the License.
*/
-export function createProxyBundlesRoute({ host, port }: { host: string; port: number }) {
+export function createProxyBundlesRoute({
+ host,
+ port,
+ buildHash,
+}: {
+ host: string;
+ port: number;
+ buildHash: string;
+}) {
return [
- buildProxyRouteForBundles('/bundles/', host, port),
- buildProxyRouteForBundles('/built_assets/dlls/', host, port),
- buildProxyRouteForBundles('/built_assets/css/', host, port),
+ buildProxyRouteForBundles(`/${buildHash}/bundles/`, host, port),
+ buildProxyRouteForBundles(`/${buildHash}/built_assets/dlls/`, host, port),
+ buildProxyRouteForBundles(`/${buildHash}/built_assets/css/`, host, port),
];
}
diff --git a/src/optimize/np_ui_plugin_public_dirs.ts b/src/optimize/np_ui_plugin_public_dirs.ts
index 268d9b1485dd8..e7c3207948f6a 100644
--- a/src/optimize/np_ui_plugin_public_dirs.ts
+++ b/src/optimize/np_ui_plugin_public_dirs.ts
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
import KbnServer from '../legacy/server/kbn_server';
export type NpUiPluginPublicDirs = Array<{
diff --git a/src/optimize/optimize_mixin.ts b/src/optimize/optimize_mixin.ts
index 5abe43ca1577a..9a3f08e2f667e 100644
--- a/src/optimize/optimize_mixin.ts
+++ b/src/optimize/optimize_mixin.ts
@@ -57,6 +57,8 @@ export const optimizeMixin = async (
basePublicPath: config.get('server.basePath'),
builtCssPath: fromRoot('built_assets/css'),
npUiPluginPublicDirs: getNpUiPluginPublicDirs(kbnServer),
+ buildHash: kbnServer.newPlatform.env.packageInfo.buildNum.toString(),
+ isDist: kbnServer.newPlatform.env.packageInfo.dist,
})
);
diff --git a/src/optimize/watch/optmzr_role.js b/src/optimize/watch/optmzr_role.js
index a31ef7229e5da..1f6107996277c 100644
--- a/src/optimize/watch/optmzr_role.js
+++ b/src/optimize/watch/optmzr_role.js
@@ -49,7 +49,8 @@ export default async (kbnServer, kibanaHapiServer, config) => {
config.get('optimize.watchPort'),
config.get('server.basePath'),
watchOptimizer,
- getNpUiPluginPublicDirs(kbnServer)
+ getNpUiPluginPublicDirs(kbnServer),
+ kbnServer.newPlatform.env.packageInfo.buildNum.toString()
);
watchOptimizer.status$.subscribe({
diff --git a/src/optimize/watch/proxy_role.js b/src/optimize/watch/proxy_role.js
index 6093658ae1a2d..0f6f3b2d4b622 100644
--- a/src/optimize/watch/proxy_role.js
+++ b/src/optimize/watch/proxy_role.js
@@ -26,6 +26,7 @@ export default (kbnServer, server, config) => {
createProxyBundlesRoute({
host: config.get('optimize.watchHost'),
port: config.get('optimize.watchPort'),
+ buildHash: kbnServer.newPlatform.env.packageInfo.buildNum.toString(),
})
);
diff --git a/src/optimize/watch/watch_optimizer.js b/src/optimize/watch/watch_optimizer.js
index 6c20f21c7768e..cdff57a00c2e0 100644
--- a/src/optimize/watch/watch_optimizer.js
+++ b/src/optimize/watch/watch_optimizer.js
@@ -106,7 +106,7 @@ export default class WatchOptimizer extends BaseOptimizer {
});
}
- bindToServer(server, basePath, npUiPluginPublicDirs) {
+ bindToServer(server, basePath, npUiPluginPublicDirs, buildHash) {
// pause all requests received while the compiler is running
// and continue once an outcome is reached (aborting the request
// with an error if it was a failure).
@@ -118,6 +118,7 @@ export default class WatchOptimizer extends BaseOptimizer {
server.route(
createBundlesRoute({
npUiPluginPublicDirs: npUiPluginPublicDirs,
+ buildHash,
regularBundlesPath: this.compiler.outputPath,
dllBundlesPath: DllCompiler.getRawDllConfig().outputPath,
basePublicPath: basePath,
diff --git a/src/optimize/watch/watch_server.js b/src/optimize/watch/watch_server.js
index 74a96dc8aea6e..81e04a5b83956 100644
--- a/src/optimize/watch/watch_server.js
+++ b/src/optimize/watch/watch_server.js
@@ -21,10 +21,11 @@ import { Server } from 'hapi';
import { registerHapiPlugins } from '../../legacy/server/http/register_hapi_plugins';
export default class WatchServer {
- constructor(host, port, basePath, optimizer, npUiPluginPublicDirs) {
+ constructor(host, port, basePath, optimizer, npUiPluginPublicDirs, buildHash) {
this.basePath = basePath;
this.optimizer = optimizer;
this.npUiPluginPublicDirs = npUiPluginPublicDirs;
+ this.buildHash = buildHash;
this.server = new Server({
host: host,
port: port,
@@ -35,7 +36,12 @@ export default class WatchServer {
async init() {
await this.optimizer.init();
- this.optimizer.bindToServer(this.server, this.basePath, this.npUiPluginPublicDirs);
+ this.optimizer.bindToServer(
+ this.server,
+ this.basePath,
+ this.npUiPluginPublicDirs,
+ this.buildHash
+ );
await this.server.start();
}
}
diff --git a/tasks/config/karma.js b/tasks/config/karma.js
index 1ec7c831b4864..f87edbf04f220 100644
--- a/tasks/config/karma.js
+++ b/tasks/config/karma.js
@@ -25,6 +25,7 @@ import { DllCompiler } from '../../src/optimize/dynamic_dll_plugin';
const TOTAL_CI_SHARDS = 4;
const ROOT = dirname(require.resolve('../../package.json'));
+const buildHash = String(Number.MAX_SAFE_INTEGER);
module.exports = function(grunt) {
function pickBrowser() {
@@ -57,27 +58,30 @@ module.exports = function(grunt) {
'http://localhost:5610/test_bundle/karma/globals.js',
...UiSharedDeps.jsDepFilenames.map(
- chunkFilename => `http://localhost:5610/bundles/kbn-ui-shared-deps/${chunkFilename}`
+ chunkFilename =>
+ `http://localhost:5610/${buildHash}/bundles/kbn-ui-shared-deps/${chunkFilename}`
),
- `http://localhost:5610/bundles/kbn-ui-shared-deps/${UiSharedDeps.jsFilename}`,
+ `http://localhost:5610/${buildHash}/bundles/kbn-ui-shared-deps/${UiSharedDeps.jsFilename}`,
- 'http://localhost:5610/built_assets/dlls/vendors_runtime.bundle.dll.js',
+ `http://localhost:5610/${buildHash}/built_assets/dlls/vendors_runtime.bundle.dll.js`,
...DllCompiler.getRawDllConfig().chunks.map(
- chunk => `http://localhost:5610/built_assets/dlls/vendors${chunk}.bundle.dll.js`
+ chunk =>
+ `http://localhost:5610/${buildHash}/built_assets/dlls/vendors${chunk}.bundle.dll.js`
),
shardNum === undefined
- ? `http://localhost:5610/bundles/tests.bundle.js`
- : `http://localhost:5610/bundles/tests.bundle.js?shards=${TOTAL_CI_SHARDS}&shard_num=${shardNum}`,
+ ? `http://localhost:5610/${buildHash}/bundles/tests.bundle.js`
+ : `http://localhost:5610/${buildHash}/bundles/tests.bundle.js?shards=${TOTAL_CI_SHARDS}&shard_num=${shardNum}`,
- `http://localhost:5610/bundles/kbn-ui-shared-deps/${UiSharedDeps.baseCssDistFilename}`,
+ `http://localhost:5610/${buildHash}/bundles/kbn-ui-shared-deps/${UiSharedDeps.baseCssDistFilename}`,
// this causes tilemap tests to fail, probably because the eui styles haven't been
// included in the karma harness a long some time, if ever
// `http://localhost:5610/bundles/kbn-ui-shared-deps/${UiSharedDeps.lightCssDistFilename}`,
...DllCompiler.getRawDllConfig().chunks.map(
- chunk => `http://localhost:5610/built_assets/dlls/vendors${chunk}.style.dll.css`
+ chunk =>
+ `http://localhost:5610/${buildHash}/built_assets/dlls/vendors${chunk}.style.dll.css`
),
- 'http://localhost:5610/bundles/tests.style.css',
+ `http://localhost:5610/${buildHash}/bundles/tests.style.css`,
];
}
@@ -127,9 +131,9 @@ module.exports = function(grunt) {
proxies: {
'/tests/': 'http://localhost:5610/tests/',
- '/bundles/': 'http://localhost:5610/bundles/',
- '/built_assets/dlls/': 'http://localhost:5610/built_assets/dlls/',
'/test_bundle/': 'http://localhost:5610/test_bundle/',
+ [`/${buildHash}/bundles/`]: `http://localhost:5610/${buildHash}/bundles/`,
+ [`/${buildHash}/built_assets/dlls/`]: `http://localhost:5610/${buildHash}/built_assets/dlls/`,
},
client: {
From 0d4cfba4b44db847600cc6a34cb697deae7675a9 Mon Sep 17 00:00:00 2001
From: Spencer
Date: Wed, 29 Apr 2020 09:44:56 -0700
Subject: [PATCH 23/33] share single data plugin bundle (#64549)
---
packages/kbn-optimizer/src/worker/webpack.config.ts | 11 +++--------
src/legacy/ui/ui_render/ui_render_mixin.js | 3 ++-
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/packages/kbn-optimizer/src/worker/webpack.config.ts b/packages/kbn-optimizer/src/worker/webpack.config.ts
index 7411e2df1b613..cc3fa8c2720de 100644
--- a/packages/kbn-optimizer/src/worker/webpack.config.ts
+++ b/packages/kbn-optimizer/src/worker/webpack.config.ts
@@ -37,7 +37,7 @@ const ISTANBUL_PRESET_PATH = require.resolve('@kbn/babel-preset/istanbul_preset'
const BABEL_PRESET_PATH = require.resolve('@kbn/babel-preset/webpack_preset');
const STATIC_BUNDLE_PLUGINS = [
- // { id: 'data', dirname: 'data' },
+ { id: 'data', dirname: 'data' },
{ id: 'kibanaReact', dirname: 'kibana_react' },
{ id: 'kibanaUtils', dirname: 'kibana_utils' },
{ id: 'esUiShared', dirname: 'es_ui_shared' },
@@ -60,13 +60,8 @@ function dynamicExternals(bundle: Bundle, context: string, request: string) {
return;
}
- // don't allow any static bundle to rely on other static bundles
- if (STATIC_BUNDLE_PLUGINS.some(p => bundle.id === p.id)) {
- return;
- }
-
- // ignore requests that don't include a /data/public, /kibana_react/public, or
- // /kibana_utils/public segment as a cheap way to avoid doing path resolution
+ // ignore requests that don't include a /{dirname}/public for one of our
+ // "static" bundles as a cheap way to avoid doing path resolution
// for paths that couldn't possibly resolve to what we're looking for
const reqToStaticBundle = STATIC_BUNDLE_PLUGINS.some(p =>
request.includes(`/${p.dirname}/public`)
diff --git a/src/legacy/ui/ui_render/ui_render_mixin.js b/src/legacy/ui/ui_render/ui_render_mixin.js
index 692b787ccf405..9b44395fa9c68 100644
--- a/src/legacy/ui/ui_render/ui_render_mixin.js
+++ b/src/legacy/ui/ui_render/ui_render_mixin.js
@@ -145,8 +145,9 @@ export function uiRenderMixin(kbnServer, server, config) {
// load these plugins first, they are "shared" and other bundles access their
// public/index exports without considering topographic sorting by plugin deps (for now)
'kibanaUtils',
- 'esUiShared',
'kibanaReact',
+ 'data',
+ 'esUiShared',
...kbnServer.newPlatform.__internals.uiPlugins.public.keys()
);
From f8e01bd3a14f606c2086955539e588484b0ab379 Mon Sep 17 00:00:00 2001
From: Ryland Herrick
Date: Wed, 29 Apr 2020 11:58:46 -0500
Subject: [PATCH 24/33] [SIEM][NP] Fixes bug in ML signals promotion (#64720)
* Add set-value as an explicit dependency
This is a more robust solution than lodash's set().
* Replace lodash.set() with set-value's equivalent
* Rebuild renovate config
We added set-value to our dependencies.
Co-authored-by: Elastic Machine
---
renovate.json5 | 8 ++++++++
x-pack/package.json | 2 ++
.../signals/bulk_create_ml_signals.ts | 10 +++++++---
yarn.lock | 12 ++++++++++++
4 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/renovate.json5 b/renovate.json5
index ffa006264873d..c0ddcaf4f23c8 100644
--- a/renovate.json5
+++ b/renovate.json5
@@ -846,6 +846,14 @@
'@types/semver',
],
},
+ {
+ groupSlug: 'set-value',
+ groupName: 'set-value related packages',
+ packageNames: [
+ 'set-value',
+ '@types/set-value',
+ ],
+ },
{
groupSlug: 'sinon',
groupName: 'sinon related packages',
diff --git a/x-pack/package.json b/x-pack/package.json
index 604889c6094b9..dcc9b8c61cb96 100644
--- a/x-pack/package.json
+++ b/x-pack/package.json
@@ -105,6 +105,7 @@
"@types/recompose": "^0.30.6",
"@types/reduce-reducers": "^1.0.0",
"@types/redux-actions": "^2.6.1",
+ "@types/set-value": "^2.0.0",
"@types/sinon": "^7.0.13",
"@types/styled-components": "^4.4.2",
"@types/supertest": "^2.0.5",
@@ -344,6 +345,7 @@
"rison-node": "0.3.1",
"rxjs": "^6.5.3",
"semver": "5.7.0",
+ "set-value": "^3.0.2",
"squel": "^5.13.0",
"stats-lite": "^2.2.0",
"style-it": "^2.1.3",
diff --git a/x-pack/plugins/siem/server/lib/detection_engine/signals/bulk_create_ml_signals.ts b/x-pack/plugins/siem/server/lib/detection_engine/signals/bulk_create_ml_signals.ts
index d298f1cc7cbc6..a8cc6dc680410 100644
--- a/x-pack/plugins/siem/server/lib/detection_engine/signals/bulk_create_ml_signals.ts
+++ b/x-pack/plugins/siem/server/lib/detection_engine/signals/bulk_create_ml_signals.ts
@@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { flow, set, omit } from 'lodash/fp';
+import { flow, omit } from 'lodash/fp';
+import set from 'set-value';
import { SearchResponse } from 'elasticsearch';
import { Logger } from '../../../../../../../src/core/server';
@@ -55,8 +56,11 @@ export const transformAnomalyFieldsToEcs = (anomaly: Anomaly): EcsAnomaly => {
}
const omitDottedFields = omit(errantFields.map(field => field.name));
- const setNestedFields = errantFields.map(field => set(field.name, field.value));
- const setTimestamp = set('@timestamp', new Date(timestamp).toISOString());
+ const setNestedFields = errantFields.map(field => (_anomaly: Anomaly) =>
+ set(_anomaly, field.name, field.value)
+ );
+ const setTimestamp = (_anomaly: Anomaly) =>
+ set(_anomaly, '@timestamp', new Date(timestamp).toISOString());
return flow(omitDottedFields, setNestedFields, setTimestamp)(anomaly);
};
diff --git a/yarn.lock b/yarn.lock
index ee00ef283f07c..94e6a0a11aa99 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4798,6 +4798,11 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-5.5.0.tgz#146c2a29ee7d3bae4bf2fcb274636e264c813c45"
integrity sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==
+"@types/set-value@^2.0.0":
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/@types/set-value/-/set-value-2.0.0.tgz#63d386b103926dcf49b50e16e0f6dd49983046be"
+ integrity sha512-k8dCJEC80F/mbsIOZ5Hj3YSzTVVVBwMdtP/M9Rtc2TM4F5etVd+2UG8QUiAUfbXm4fABedL2tBZnrBheY7UwpA==
+
"@types/shot@*":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/shot/-/shot-4.0.0.tgz#7545500c489b65c69b5bc5446ba4fef3bd26af92"
@@ -26910,6 +26915,13 @@ set-value@^2.0.0, set-value@^2.0.1:
is-plain-object "^2.0.3"
split-string "^3.0.1"
+set-value@^3.0.2:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/set-value/-/set-value-3.0.2.tgz#74e8ecd023c33d0f77199d415409a40f21e61b90"
+ integrity sha512-npjkVoz+ank0zjlV9F47Fdbjfj/PfXyVhZvGALWsyIYU/qrMzpi6avjKW3/7KeSU2Df3I46BrN1xOI1+6vW0hA==
+ dependencies:
+ is-plain-object "^2.0.4"
+
setimmediate@^1.0.4, setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
From bac638a37e5dc670cd1c6c535e1f9fcd77ef8f64 Mon Sep 17 00:00:00 2001
From: Dmitry Lemeshko
Date: Wed, 29 Apr 2020 20:00:14 +0300
Subject: [PATCH 25/33] Update jest config for coverage (#64648)
* set files to track for coverage collection
* increase timeout to 4h
* trying to add detectOpenHandles to avoid worker stuck
* update config
* make config paths more common
* update configs
* update jest oss config
* exclude 'tests' folder for coverage
---
.ci/Jenkinsfile_coverage | 2 +-
src/dev/jest/config.js | 1 +
test/scripts/jenkins_xpack.sh | 2 +-
x-pack/dev-tools/jest/create_jest_config.js | 14 ++++++++++++++
4 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/.ci/Jenkinsfile_coverage b/.ci/Jenkinsfile_coverage
index f2a58e7b6a7ac..c474998e6fd3d 100644
--- a/.ci/Jenkinsfile_coverage
+++ b/.ci/Jenkinsfile_coverage
@@ -3,7 +3,7 @@
library 'kibana-pipeline-library'
kibanaLibrary.load() // load from the Jenkins instance
-kibanaPipeline(timeoutMinutes: 180) {
+kibanaPipeline(timeoutMinutes: 240) {
catchErrors {
withEnv([
'CODE_COVERAGE=1', // Needed for multiple ci scripts, such as remote.ts, test/scripts/*.sh, schema.js, etc.
diff --git a/src/dev/jest/config.js b/src/dev/jest/config.js
index 43a2cbd78c502..c5387590fcf66 100644
--- a/src/dev/jest/config.js
+++ b/src/dev/jest/config.js
@@ -40,6 +40,7 @@ export default {
],
collectCoverageFrom: [
'src/plugins/**/*.{ts,tsx}',
+ '!src/plugins/**/{__test__,__snapshots__,__examples__,mocks,tests}/**/*',
'!src/plugins/**/*.d.ts',
'packages/kbn-ui-framework/src/components/**/*.js',
'!packages/kbn-ui-framework/src/components/index.js',
diff --git a/test/scripts/jenkins_xpack.sh b/test/scripts/jenkins_xpack.sh
index 67d88b308ed91..951ba8e22d885 100755
--- a/test/scripts/jenkins_xpack.sh
+++ b/test/scripts/jenkins_xpack.sh
@@ -39,7 +39,7 @@ else
# build runtime for canvas
echo "NODE_ENV=$NODE_ENV"
node ./legacy/plugins/canvas/scripts/shareable_runtime
- node --max-old-space-size=6144 scripts/jest --ci --verbose --coverage
+ node --max-old-space-size=6144 scripts/jest --ci --verbose --detectOpenHandles --coverage
# rename file in order to be unique one
test -f ../target/kibana-coverage/jest/coverage-final.json \
&& mv ../target/kibana-coverage/jest/coverage-final.json \
diff --git a/x-pack/dev-tools/jest/create_jest_config.js b/x-pack/dev-tools/jest/create_jest_config.js
index af5ace8e3cd3b..4f1251321b005 100644
--- a/x-pack/dev-tools/jest/create_jest_config.js
+++ b/x-pack/dev-tools/jest/create_jest_config.js
@@ -34,6 +34,20 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
'^test_utils/stub_web_worker': `${xPackKibanaDirectory}/test_utils/stub_web_worker.ts`,
'^(!!)?file-loader!': fileMockPath,
},
+ collectCoverageFrom: [
+ 'legacy/plugins/**/*.{js,jsx,ts,tsx}',
+ 'legacy/server/**/*.{js,jsx,ts,tsx}',
+ 'plugins/**/*.{js,jsx,ts,tsx}',
+ '!**/{__test__,__snapshots__,__examples__,integration_tests,tests}/**',
+ '!**/*.test.{js,ts,tsx}',
+ '!**/flot-charts/**',
+ '!**/test/**',
+ '!**/build/**',
+ '!**/scripts/**',
+ '!**/mocks/**',
+ '!**/plugins/apm/e2e/**',
+ ],
+ coveragePathIgnorePatterns: ['.*\\.d\\.ts'],
coverageDirectory: '/../target/kibana-coverage/jest',
coverageReporters: !!process.env.CODE_COVERAGE ? ['json'] : ['html'],
setupFiles: [
From d8c15f5ad38c0ed480fc90cf7c8381aad04f0609 Mon Sep 17 00:00:00 2001
From: James Gowdy
Date: Wed, 29 Apr 2020 18:25:48 +0100
Subject: [PATCH 26/33] [ML] Adding endpoint capability checks (#64662)
* [ML] Adding endpoint capability checks
* adding missing capability checks
* fixing test
* removing commented code
* fixing functional test
* fixing functional tests
* changes based on review
Co-authored-by: Elastic Machine
---
.../plugins/ml/common/types/capabilities.ts | 32 +++-
.../capabilities/check_capabilities.test.ts | 159 ++++++++++++++----
.../lib/capabilities/check_capabilities.ts | 2 +
x-pack/plugins/ml/server/plugin.ts | 14 +-
.../plugins/ml/server/routes/annotations.ts | 9 +
.../ml/server/routes/anomaly_detectors.ts | 45 +++++
x-pack/plugins/ml/server/routes/calendars.ts | 15 ++
.../ml/server/routes/data_frame_analytics.ts | 33 ++++
.../ml/server/routes/data_visualizer.ts | 6 +
x-pack/plugins/ml/server/routes/datafeeds.ts | 30 ++++
.../ml/server/routes/fields_service.ts | 7 +-
.../ml/server/routes/file_data_visualizer.ts | 2 +
x-pack/plugins/ml/server/routes/filters.ts | 18 ++
x-pack/plugins/ml/server/routes/indices.ts | 3 +
.../ml/server/routes/job_audit_messages.ts | 6 +
.../plugins/ml/server/routes/job_service.ts | 80 ++++++---
.../ml/server/routes/job_validation.ts | 12 ++
x-pack/plugins/ml/server/routes/modules.ts | 12 ++
.../ml/server/routes/notification_settings.ts | 3 +
.../ml/server/routes/results_service.ts | 15 ++
x-pack/plugins/ml/server/routes/system.ts | 16 ++
x-pack/plugins/ml/server/types.ts | 4 -
.../apis/ml/anomaly_detectors/create.ts | 9 +-
.../apis/ml/jobs/jobs_summary.ts | 4 +-
.../apis/ml/modules/setup_module.ts | 7 +-
25 files changed, 456 insertions(+), 87 deletions(-)
diff --git a/x-pack/plugins/ml/common/types/capabilities.ts b/x-pack/plugins/ml/common/types/capabilities.ts
index 2a449c95faa5b..da5fd3ac25209 100644
--- a/x-pack/plugins/ml/common/types/capabilities.ts
+++ b/x-pack/plugins/ml/common/types/capabilities.ts
@@ -7,6 +7,7 @@
import { KibanaRequest } from 'kibana/server';
export const userMlCapabilities = {
+ canAccessML: false,
// Anomaly Detection
canGetJobs: false,
canGetDatafeeds: false,
@@ -18,6 +19,10 @@ export const userMlCapabilities = {
canGetFilters: false,
// Data Frame Analytics
canGetDataFrameAnalytics: false,
+ // Annotations
+ canGetAnnotations: false,
+ canCreateAnnotation: false,
+ canDeleteAnnotation: false,
};
export const adminMlCapabilities = {
@@ -26,9 +31,11 @@ export const adminMlCapabilities = {
canDeleteJob: false,
canOpenJob: false,
canCloseJob: false,
+ canUpdateJob: false,
canForecastJob: false,
+ canCreateDatafeed: false,
+ canDeleteDatafeed: false,
canStartStopDatafeed: false,
- canUpdateJob: false,
canUpdateDatafeed: false,
canPreviewDatafeed: false,
// Calendars
@@ -38,8 +45,8 @@ export const adminMlCapabilities = {
canCreateFilter: false,
canDeleteFilter: false,
// Data Frame Analytics
- canDeleteDataFrameAnalytics: false,
canCreateDataFrameAnalytics: false,
+ canDeleteDataFrameAnalytics: false,
canStartStopDataFrameAnalytics: false,
};
@@ -47,7 +54,9 @@ export type UserMlCapabilities = typeof userMlCapabilities;
export type AdminMlCapabilities = typeof adminMlCapabilities;
export type MlCapabilities = UserMlCapabilities & AdminMlCapabilities;
-export const basicLicenseMlCapabilities = ['canFindFileStructure'] as Array;
+export const basicLicenseMlCapabilities = ['canAccessML', 'canFindFileStructure'] as Array<
+ keyof MlCapabilities
+>;
export function getDefaultCapabilities(): MlCapabilities {
return {
@@ -56,6 +65,23 @@ export function getDefaultCapabilities(): MlCapabilities {
};
}
+export function getPluginPrivileges() {
+ const userMlCapabilitiesKeys = Object.keys(userMlCapabilities);
+ const adminMlCapabilitiesKeys = Object.keys(adminMlCapabilities);
+ const allMlCapabilities = [...adminMlCapabilitiesKeys, ...userMlCapabilitiesKeys];
+
+ return {
+ user: {
+ ui: userMlCapabilitiesKeys,
+ api: userMlCapabilitiesKeys.map(k => `ml:${k}`),
+ },
+ admin: {
+ ui: allMlCapabilities,
+ api: allMlCapabilities.map(k => `ml:${k}`),
+ },
+ };
+}
+
export interface MlCapabilitiesResponse {
capabilities: MlCapabilities;
upgradeInProgress: boolean;
diff --git a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.test.ts b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.test.ts
index 5093801d2d184..b6e95ae8373ee 100644
--- a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.test.ts
+++ b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.test.ts
@@ -36,7 +36,7 @@ describe('check_capabilities', () => {
);
const { capabilities } = await getCapabilities();
const count = Object.keys(capabilities).length;
- expect(count).toBe(22);
+ expect(count).toBe(28);
done();
});
});
@@ -49,28 +49,42 @@ describe('check_capabilities', () => {
mlLicense,
mlIsEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
expect(upgradeInProgress).toBe(false);
expect(mlFeatureEnabledInSpace).toBe(true);
+ expect(isPlatinumOrTrialLicense).toBe(true);
+
+ expect(capabilities.canAccessML).toBe(true);
expect(capabilities.canGetJobs).toBe(true);
+ expect(capabilities.canGetDatafeeds).toBe(true);
+ expect(capabilities.canGetCalendars).toBe(true);
+ expect(capabilities.canFindFileStructure).toBe(true);
+ expect(capabilities.canGetFilters).toBe(true);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(true);
+ expect(capabilities.canGetAnnotations).toBe(true);
+ expect(capabilities.canCreateAnnotation).toBe(true);
+ expect(capabilities.canDeleteAnnotation).toBe(true);
+
expect(capabilities.canCreateJob).toBe(false);
expect(capabilities.canDeleteJob).toBe(false);
expect(capabilities.canOpenJob).toBe(false);
expect(capabilities.canCloseJob).toBe(false);
expect(capabilities.canForecastJob).toBe(false);
- expect(capabilities.canGetDatafeeds).toBe(true);
expect(capabilities.canStartStopDatafeed).toBe(false);
expect(capabilities.canUpdateJob).toBe(false);
+ expect(capabilities.canCreateDatafeed).toBe(false);
+ expect(capabilities.canDeleteDatafeed).toBe(false);
expect(capabilities.canUpdateDatafeed).toBe(false);
expect(capabilities.canPreviewDatafeed).toBe(false);
- expect(capabilities.canGetCalendars).toBe(true);
expect(capabilities.canCreateCalendar).toBe(false);
expect(capabilities.canDeleteCalendar).toBe(false);
- expect(capabilities.canGetFilters).toBe(true);
expect(capabilities.canCreateFilter).toBe(false);
expect(capabilities.canDeleteFilter).toBe(false);
- expect(capabilities.canFindFileStructure).toBe(true);
- expect(capabilities.canGetDataFrameAnalytics).toBe(true);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(false);
expect(capabilities.canCreateDataFrameAnalytics).toBe(false);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(false);
@@ -84,28 +98,42 @@ describe('check_capabilities', () => {
mlLicense,
mlIsEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
expect(upgradeInProgress).toBe(false);
expect(mlFeatureEnabledInSpace).toBe(true);
+ expect(isPlatinumOrTrialLicense).toBe(true);
+
+ expect(capabilities.canAccessML).toBe(true);
expect(capabilities.canGetJobs).toBe(true);
+ expect(capabilities.canGetDatafeeds).toBe(true);
+ expect(capabilities.canGetCalendars).toBe(true);
+ expect(capabilities.canFindFileStructure).toBe(true);
+ expect(capabilities.canGetFilters).toBe(true);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(true);
+ expect(capabilities.canGetAnnotations).toBe(true);
+ expect(capabilities.canCreateAnnotation).toBe(true);
+ expect(capabilities.canDeleteAnnotation).toBe(true);
+
expect(capabilities.canCreateJob).toBe(true);
expect(capabilities.canDeleteJob).toBe(true);
expect(capabilities.canOpenJob).toBe(true);
expect(capabilities.canCloseJob).toBe(true);
expect(capabilities.canForecastJob).toBe(true);
- expect(capabilities.canGetDatafeeds).toBe(true);
expect(capabilities.canStartStopDatafeed).toBe(true);
expect(capabilities.canUpdateJob).toBe(true);
+ expect(capabilities.canCreateDatafeed).toBe(true);
+ expect(capabilities.canDeleteDatafeed).toBe(true);
expect(capabilities.canUpdateDatafeed).toBe(true);
expect(capabilities.canPreviewDatafeed).toBe(true);
- expect(capabilities.canGetCalendars).toBe(true);
expect(capabilities.canCreateCalendar).toBe(true);
expect(capabilities.canDeleteCalendar).toBe(true);
- expect(capabilities.canGetFilters).toBe(true);
expect(capabilities.canCreateFilter).toBe(true);
expect(capabilities.canDeleteFilter).toBe(true);
- expect(capabilities.canFindFileStructure).toBe(true);
- expect(capabilities.canGetDataFrameAnalytics).toBe(true);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(true);
expect(capabilities.canCreateDataFrameAnalytics).toBe(true);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(true);
@@ -119,28 +147,42 @@ describe('check_capabilities', () => {
mlLicense,
mlIsEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
expect(upgradeInProgress).toBe(true);
expect(mlFeatureEnabledInSpace).toBe(true);
+ expect(isPlatinumOrTrialLicense).toBe(true);
+
+ expect(capabilities.canAccessML).toBe(true);
expect(capabilities.canGetJobs).toBe(true);
+ expect(capabilities.canGetDatafeeds).toBe(true);
+ expect(capabilities.canGetCalendars).toBe(true);
+ expect(capabilities.canFindFileStructure).toBe(true);
+ expect(capabilities.canGetFilters).toBe(true);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(true);
+ expect(capabilities.canGetAnnotations).toBe(true);
+ expect(capabilities.canCreateAnnotation).toBe(false);
+ expect(capabilities.canDeleteAnnotation).toBe(false);
+
expect(capabilities.canCreateJob).toBe(false);
expect(capabilities.canDeleteJob).toBe(false);
expect(capabilities.canOpenJob).toBe(false);
expect(capabilities.canCloseJob).toBe(false);
expect(capabilities.canForecastJob).toBe(false);
- expect(capabilities.canGetDatafeeds).toBe(true);
expect(capabilities.canStartStopDatafeed).toBe(false);
expect(capabilities.canUpdateJob).toBe(false);
+ expect(capabilities.canCreateDatafeed).toBe(false);
+ expect(capabilities.canDeleteDatafeed).toBe(false);
expect(capabilities.canUpdateDatafeed).toBe(false);
expect(capabilities.canPreviewDatafeed).toBe(false);
- expect(capabilities.canGetCalendars).toBe(true);
expect(capabilities.canCreateCalendar).toBe(false);
expect(capabilities.canDeleteCalendar).toBe(false);
- expect(capabilities.canGetFilters).toBe(true);
expect(capabilities.canCreateFilter).toBe(false);
expect(capabilities.canDeleteFilter).toBe(false);
- expect(capabilities.canFindFileStructure).toBe(true);
- expect(capabilities.canGetDataFrameAnalytics).toBe(true);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(false);
expect(capabilities.canCreateDataFrameAnalytics).toBe(false);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(false);
@@ -154,28 +196,42 @@ describe('check_capabilities', () => {
mlLicense,
mlIsEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
expect(upgradeInProgress).toBe(true);
expect(mlFeatureEnabledInSpace).toBe(true);
+ expect(isPlatinumOrTrialLicense).toBe(true);
+
+ expect(capabilities.canAccessML).toBe(true);
expect(capabilities.canGetJobs).toBe(true);
+ expect(capabilities.canGetDatafeeds).toBe(true);
+ expect(capabilities.canGetCalendars).toBe(true);
+ expect(capabilities.canFindFileStructure).toBe(true);
+ expect(capabilities.canGetFilters).toBe(true);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(true);
+ expect(capabilities.canGetAnnotations).toBe(true);
+ expect(capabilities.canCreateAnnotation).toBe(false);
+ expect(capabilities.canDeleteAnnotation).toBe(false);
+
expect(capabilities.canCreateJob).toBe(false);
expect(capabilities.canDeleteJob).toBe(false);
expect(capabilities.canOpenJob).toBe(false);
expect(capabilities.canCloseJob).toBe(false);
expect(capabilities.canForecastJob).toBe(false);
- expect(capabilities.canGetDatafeeds).toBe(true);
expect(capabilities.canStartStopDatafeed).toBe(false);
expect(capabilities.canUpdateJob).toBe(false);
+ expect(capabilities.canCreateDatafeed).toBe(false);
+ expect(capabilities.canDeleteDatafeed).toBe(false);
expect(capabilities.canUpdateDatafeed).toBe(false);
expect(capabilities.canPreviewDatafeed).toBe(false);
- expect(capabilities.canGetCalendars).toBe(true);
expect(capabilities.canCreateCalendar).toBe(false);
expect(capabilities.canDeleteCalendar).toBe(false);
- expect(capabilities.canGetFilters).toBe(true);
expect(capabilities.canCreateFilter).toBe(false);
expect(capabilities.canDeleteFilter).toBe(false);
- expect(capabilities.canFindFileStructure).toBe(true);
- expect(capabilities.canGetDataFrameAnalytics).toBe(true);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(false);
expect(capabilities.canCreateDataFrameAnalytics).toBe(false);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(false);
@@ -189,28 +245,42 @@ describe('check_capabilities', () => {
mlLicense,
mlIsNotEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
expect(upgradeInProgress).toBe(false);
expect(mlFeatureEnabledInSpace).toBe(false);
+ expect(isPlatinumOrTrialLicense).toBe(true);
+
+ expect(capabilities.canAccessML).toBe(false);
expect(capabilities.canGetJobs).toBe(false);
+ expect(capabilities.canGetDatafeeds).toBe(false);
+ expect(capabilities.canGetCalendars).toBe(false);
+ expect(capabilities.canFindFileStructure).toBe(false);
+ expect(capabilities.canGetFilters).toBe(false);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(false);
+ expect(capabilities.canGetAnnotations).toBe(false);
+ expect(capabilities.canCreateAnnotation).toBe(false);
+ expect(capabilities.canDeleteAnnotation).toBe(false);
+
expect(capabilities.canCreateJob).toBe(false);
expect(capabilities.canDeleteJob).toBe(false);
expect(capabilities.canOpenJob).toBe(false);
expect(capabilities.canCloseJob).toBe(false);
expect(capabilities.canForecastJob).toBe(false);
- expect(capabilities.canGetDatafeeds).toBe(false);
expect(capabilities.canStartStopDatafeed).toBe(false);
expect(capabilities.canUpdateJob).toBe(false);
+ expect(capabilities.canCreateDatafeed).toBe(false);
+ expect(capabilities.canDeleteDatafeed).toBe(false);
expect(capabilities.canUpdateDatafeed).toBe(false);
expect(capabilities.canPreviewDatafeed).toBe(false);
- expect(capabilities.canGetCalendars).toBe(false);
expect(capabilities.canCreateCalendar).toBe(false);
expect(capabilities.canDeleteCalendar).toBe(false);
- expect(capabilities.canGetFilters).toBe(false);
expect(capabilities.canCreateFilter).toBe(false);
expect(capabilities.canDeleteFilter).toBe(false);
- expect(capabilities.canFindFileStructure).toBe(false);
- expect(capabilities.canGetDataFrameAnalytics).toBe(false);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(false);
expect(capabilities.canCreateDataFrameAnalytics).toBe(false);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(false);
@@ -225,28 +295,43 @@ describe('check_capabilities', () => {
mlLicenseBasic,
mlIsNotEnabled
);
- const { capabilities, upgradeInProgress, mlFeatureEnabledInSpace } = await getCapabilities();
+ const {
+ capabilities,
+ upgradeInProgress,
+ mlFeatureEnabledInSpace,
+ isPlatinumOrTrialLicense,
+ } = await getCapabilities();
+
expect(upgradeInProgress).toBe(false);
expect(mlFeatureEnabledInSpace).toBe(false);
+ expect(isPlatinumOrTrialLicense).toBe(false);
+
+ expect(capabilities.canAccessML).toBe(false);
expect(capabilities.canGetJobs).toBe(false);
+ expect(capabilities.canGetDatafeeds).toBe(false);
+ expect(capabilities.canGetCalendars).toBe(false);
+ expect(capabilities.canFindFileStructure).toBe(false);
+ expect(capabilities.canGetFilters).toBe(false);
+ expect(capabilities.canGetDataFrameAnalytics).toBe(false);
+ expect(capabilities.canGetAnnotations).toBe(false);
+ expect(capabilities.canCreateAnnotation).toBe(false);
+ expect(capabilities.canDeleteAnnotation).toBe(false);
+
expect(capabilities.canCreateJob).toBe(false);
expect(capabilities.canDeleteJob).toBe(false);
expect(capabilities.canOpenJob).toBe(false);
expect(capabilities.canCloseJob).toBe(false);
expect(capabilities.canForecastJob).toBe(false);
- expect(capabilities.canGetDatafeeds).toBe(false);
expect(capabilities.canStartStopDatafeed).toBe(false);
expect(capabilities.canUpdateJob).toBe(false);
+ expect(capabilities.canCreateDatafeed).toBe(false);
+ expect(capabilities.canDeleteDatafeed).toBe(false);
expect(capabilities.canUpdateDatafeed).toBe(false);
expect(capabilities.canPreviewDatafeed).toBe(false);
- expect(capabilities.canGetCalendars).toBe(false);
expect(capabilities.canCreateCalendar).toBe(false);
expect(capabilities.canDeleteCalendar).toBe(false);
- expect(capabilities.canGetFilters).toBe(false);
expect(capabilities.canCreateFilter).toBe(false);
expect(capabilities.canDeleteFilter).toBe(false);
- expect(capabilities.canFindFileStructure).toBe(false);
- expect(capabilities.canGetDataFrameAnalytics).toBe(false);
expect(capabilities.canDeleteDataFrameAnalytics).toBe(false);
expect(capabilities.canCreateDataFrameAnalytics).toBe(false);
expect(capabilities.canStartStopDataFrameAnalytics).toBe(false);
diff --git a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts
index a2ad83c5522de..d955cf981faca 100644
--- a/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts
+++ b/x-pack/plugins/ml/server/lib/capabilities/check_capabilities.ts
@@ -44,4 +44,6 @@ function disableAdminPrivileges(capabilities: MlCapabilities) {
Object.keys(adminMlCapabilities).forEach(k => {
capabilities[k as keyof MlCapabilities] = false;
});
+ capabilities.canCreateAnnotation = false;
+ capabilities.canDeleteAnnotation = false;
}
diff --git a/x-pack/plugins/ml/server/plugin.ts b/x-pack/plugins/ml/server/plugin.ts
index 64f8eb4b0acd3..969b74194148b 100644
--- a/x-pack/plugins/ml/server/plugin.ts
+++ b/x-pack/plugins/ml/server/plugin.ts
@@ -45,7 +45,7 @@ import { systemRoutes } from './routes/system';
import { MlLicense } from '../common/license';
import { MlServerLicense } from './lib/license';
import { createSharedServices, SharedServices } from './shared_services';
-import { userMlCapabilities, adminMlCapabilities } from '../common/types/capabilities';
+import { getPluginPrivileges } from '../common/types/capabilities';
import { setupCapabilitiesSwitcher } from './lib/capabilities';
import { registerKibanaSettings } from './lib/register_settings';
@@ -75,8 +75,7 @@ export class MlServerPlugin implements Plugin {
try {
@@ -86,6 +89,9 @@ export function annotationRoutes(
validate: {
body: indexAnnotationSchema,
},
+ options: {
+ tags: ['access:ml:canCreateAnnotation'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -130,6 +136,9 @@ export function annotationRoutes(
validate: {
params: deleteAnnotationSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteAnnotation'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/anomaly_detectors.ts b/x-pack/plugins/ml/server/routes/anomaly_detectors.ts
index ca63d69f403f6..63cd5498231af 100644
--- a/x-pack/plugins/ml/server/routes/anomaly_detectors.ts
+++ b/x-pack/plugins/ml/server/routes/anomaly_detectors.ts
@@ -37,6 +37,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/anomaly_detectors',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -65,6 +68,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: jobIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -93,6 +99,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/anomaly_detectors/_stats',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -121,6 +130,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: jobIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -154,6 +166,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: jobIdSchema,
body: schema.object(anomalyDetectionJobSchema),
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -188,6 +203,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: jobIdSchema,
body: anomalyDetectionUpdateJobSchema,
},
+ options: {
+ tags: ['access:ml:canUpdateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -220,6 +238,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: jobIdSchema,
},
+ options: {
+ tags: ['access:ml:canOpenJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -251,6 +272,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: jobIdSchema,
},
+ options: {
+ tags: ['access:ml:canCloseJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -286,6 +310,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: jobIdSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -319,6 +346,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
body: schema.any(),
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -351,6 +381,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: jobIdSchema,
body: forecastAnomalyDetector,
},
+ options: {
+ tags: ['access:ml:canForecastJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -389,6 +422,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: jobIdSchema,
body: getRecordsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -425,6 +461,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: getBucketParamsSchema,
body: getBucketsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -462,6 +501,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
params: jobIdSchema,
body: getOverallBucketsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -496,6 +538,9 @@ export function jobRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: getCategoriesSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/calendars.ts b/x-pack/plugins/ml/server/routes/calendars.ts
index a17601f74ae93..9c80651a13999 100644
--- a/x-pack/plugins/ml/server/routes/calendars.ts
+++ b/x-pack/plugins/ml/server/routes/calendars.ts
@@ -52,6 +52,9 @@ export function calendars({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/calendars',
validate: false,
+ options: {
+ tags: ['access:ml:canGetCalendars'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -81,6 +84,9 @@ export function calendars({ router, mlLicense }: RouteInitialization) {
validate: {
params: calendarIdsSchema,
},
+ options: {
+ tags: ['access:ml:canGetCalendars'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
let returnValue;
@@ -117,6 +123,9 @@ export function calendars({ router, mlLicense }: RouteInitialization) {
validate: {
body: calendarSchema,
},
+ options: {
+ tags: ['access:ml:canCreateCalendar'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -149,6 +158,9 @@ export function calendars({ router, mlLicense }: RouteInitialization) {
params: calendarIdSchema,
body: calendarSchema,
},
+ options: {
+ tags: ['access:ml:canCreateCalendar'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -180,6 +192,9 @@ export function calendars({ router, mlLicense }: RouteInitialization) {
validate: {
params: calendarIdSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteCalendar'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/data_frame_analytics.ts b/x-pack/plugins/ml/server/routes/data_frame_analytics.ts
index dd9e0ea66aa9d..32cb2b343f876 100644
--- a/x-pack/plugins/ml/server/routes/data_frame_analytics.ts
+++ b/x-pack/plugins/ml/server/routes/data_frame_analytics.ts
@@ -33,6 +33,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
{
path: '/api/ml/data_frame/analytics',
validate: false,
+ options: {
+ tags: ['access:ml:canGetDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -61,6 +64,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
params: analyticsIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -88,6 +94,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
{
path: '/api/ml/data_frame/analytics/_stats',
validate: false,
+ options: {
+ tags: ['access:ml:canGetDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -118,6 +127,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
params: analyticsIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -155,6 +167,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
params: analyticsIdSchema,
body: dataAnalyticsJobConfigSchema,
},
+ options: {
+ tags: ['access:ml:canCreateDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -190,6 +205,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
body: dataAnalyticsEvaluateSchema,
},
+ options: {
+ tags: ['access:ml:canCreateDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -224,6 +242,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
body: dataAnalyticsExplainSchema,
},
+ options: {
+ tags: ['access:ml:canCreateDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -257,6 +278,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
params: analyticsIdSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -291,6 +315,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
params: analyticsIdSchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -324,6 +351,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
params: analyticsIdSchema,
query: stopsDataFrameAnalyticsJobQuerySchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -364,6 +394,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense }: RouteInitializat
validate: {
params: analyticsIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetDataFrameAnalytics'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/data_visualizer.ts b/x-pack/plugins/ml/server/routes/data_visualizer.ts
index 20029fbd8d1a6..04008a896a1a2 100644
--- a/x-pack/plugins/ml/server/routes/data_visualizer.ts
+++ b/x-pack/plugins/ml/server/routes/data_visualizer.ts
@@ -88,6 +88,9 @@ export function dataVisualizerRoutes({ router, mlLicense }: RouteInitialization)
params: indexPatternTitleSchema,
body: dataVisualizerFieldStatsSchema,
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
@@ -150,6 +153,9 @@ export function dataVisualizerRoutes({ router, mlLicense }: RouteInitialization)
params: indexPatternTitleSchema,
body: dataVisualizerOverallStatsSchema,
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/datafeeds.ts b/x-pack/plugins/ml/server/routes/datafeeds.ts
index ec667e1d305f5..1fa1d408372da 100644
--- a/x-pack/plugins/ml/server/routes/datafeeds.ts
+++ b/x-pack/plugins/ml/server/routes/datafeeds.ts
@@ -28,6 +28,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/datafeeds',
validate: false,
+ options: {
+ tags: ['access:ml:canGetDatafeeds'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -57,6 +60,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: datafeedIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetDatafeeds'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -83,6 +89,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/datafeeds/_stats',
validate: false,
+ options: {
+ tags: ['access:ml:canGetDatafeeds'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -112,6 +121,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: datafeedIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetDatafeeds'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -146,6 +158,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
params: datafeedIdSchema,
body: datafeedConfigSchema,
},
+ options: {
+ tags: ['access:ml:canCreateDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -181,6 +196,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
params: datafeedIdSchema,
body: datafeedConfigSchema,
},
+ options: {
+ tags: ['access:ml:canUpdateDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -216,6 +234,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
params: datafeedIdSchema,
query: deleteDatafeedQuerySchema,
},
+ options: {
+ tags: ['access:ml:canDeleteDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -255,6 +276,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
params: datafeedIdSchema,
body: startDatafeedSchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -291,6 +315,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: datafeedIdSchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -324,6 +351,9 @@ export function dataFeedRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: datafeedIdSchema,
},
+ options: {
+ tags: ['access:ml:canPreviewDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/fields_service.ts b/x-pack/plugins/ml/server/routes/fields_service.ts
index 577e8e0161342..b0f13df294145 100644
--- a/x-pack/plugins/ml/server/routes/fields_service.ts
+++ b/x-pack/plugins/ml/server/routes/fields_service.ts
@@ -46,8 +46,10 @@ export function fieldsService({ router, mlLicense }: RouteInitialization) {
validate: {
body: getCardinalityOfFieldsSchema,
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
-
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
const resp = await getCardinalityOfFields(context, request.body);
@@ -79,6 +81,9 @@ export function fieldsService({ router, mlLicense }: RouteInitialization) {
validate: {
body: getTimeFieldRangeSchema,
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/file_data_visualizer.ts b/x-pack/plugins/ml/server/routes/file_data_visualizer.ts
index 3f3fc3f547b6a..0f389f9505943 100644
--- a/x-pack/plugins/ml/server/routes/file_data_visualizer.ts
+++ b/x-pack/plugins/ml/server/routes/file_data_visualizer.ts
@@ -71,6 +71,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
accepts: ['text/*', 'application/json'],
maxBytes: MAX_FILE_SIZE_BYTES,
},
+ tags: ['access:ml:canFindFileStructure'],
},
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
@@ -105,6 +106,7 @@ export function fileDataVisualizerRoutes({ router, mlLicense }: RouteInitializat
accepts: ['application/json'],
maxBytes: MAX_FILE_SIZE_BYTES,
},
+ tags: ['access:ml:canFindFileStructure'],
},
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
diff --git a/x-pack/plugins/ml/server/routes/filters.ts b/x-pack/plugins/ml/server/routes/filters.ts
index 738c25070358d..d5287c349a8fc 100644
--- a/x-pack/plugins/ml/server/routes/filters.ts
+++ b/x-pack/plugins/ml/server/routes/filters.ts
@@ -57,6 +57,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/filters',
validate: false,
+ options: {
+ tags: ['access:ml:canGetFilters'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -89,6 +92,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: filterIdSchema,
},
+ options: {
+ tags: ['access:ml:canGetFilters'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -120,6 +126,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
body: createFilterSchema,
},
+ options: {
+ tags: ['access:ml:canCreateFilter'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -155,6 +164,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
params: filterIdSchema,
body: updateFilterSchema,
},
+ options: {
+ tags: ['access:ml:canCreateFilter'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -186,6 +198,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
params: filterIdSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteFilter'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -216,6 +231,9 @@ export function filtersRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/filters/_stats',
validate: false,
+ options: {
+ tags: ['access:ml:canGetFilters'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/indices.ts b/x-pack/plugins/ml/server/routes/indices.ts
index e434936beba63..fb3ef7fc41c76 100644
--- a/x-pack/plugins/ml/server/routes/indices.ts
+++ b/x-pack/plugins/ml/server/routes/indices.ts
@@ -27,6 +27,9 @@ export function indicesRoutes({ router, mlLicense }: RouteInitialization) {
validate: {
body: indicesSchema,
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/job_audit_messages.ts b/x-pack/plugins/ml/server/routes/job_audit_messages.ts
index 1fe5a7af95d4f..5acc89e7d13be 100644
--- a/x-pack/plugins/ml/server/routes/job_audit_messages.ts
+++ b/x-pack/plugins/ml/server/routes/job_audit_messages.ts
@@ -33,6 +33,9 @@ export function jobAuditMessagesRoutes({ router, mlLicense }: RouteInitializatio
params: jobAuditMessagesJobIdSchema,
query: jobAuditMessagesQuerySchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -67,6 +70,9 @@ export function jobAuditMessagesRoutes({ router, mlLicense }: RouteInitializatio
validate: {
query: jobAuditMessagesQuerySchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/job_service.ts b/x-pack/plugins/ml/server/routes/job_service.ts
index 149ca2591fd76..05c44e1da9757 100644
--- a/x-pack/plugins/ml/server/routes/job_service.ts
+++ b/x-pack/plugins/ml/server/routes/job_service.ts
@@ -4,11 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import Boom from 'boom';
import { schema } from '@kbn/config-schema';
-import { KibanaRequest } from 'kibana/server';
import { wrapError } from '../client/error_wrapper';
-import { RouteInitialization, JobServiceRouteDeps } from '../types';
+import { RouteInitialization } from '../types';
import {
categorizationFieldExamplesSchema,
chartSchema,
@@ -27,19 +25,7 @@ import { categorizationExamplesProvider } from '../models/job_service/new_job';
/**
* Routes for job service
*/
-export function jobServiceRoutes(
- { router, mlLicense }: RouteInitialization,
- { resolveMlCapabilities }: JobServiceRouteDeps
-) {
- async function hasPermissionToCreateJobs(request: KibanaRequest) {
- const mlCapabilities = await resolveMlCapabilities(request);
- if (mlCapabilities === null) {
- throw new Error('resolveMlCapabilities is not defined');
- }
-
- return mlCapabilities.canCreateJob;
- }
-
+export function jobServiceRoutes({ router, mlLicense }: RouteInitialization) {
/**
* @apiGroup JobService
*
@@ -55,6 +41,9 @@ export function jobServiceRoutes(
validate: {
body: forceStartDatafeedSchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -86,6 +75,9 @@ export function jobServiceRoutes(
validate: {
body: datafeedIdsSchema,
},
+ options: {
+ tags: ['access:ml:canStartStopDatafeed'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -117,6 +109,9 @@ export function jobServiceRoutes(
validate: {
body: jobIdsSchema,
},
+ options: {
+ tags: ['access:ml:canDeleteJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -148,6 +143,9 @@ export function jobServiceRoutes(
validate: {
body: jobIdsSchema,
},
+ options: {
+ tags: ['access:ml:canCloseJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -184,6 +182,9 @@ export function jobServiceRoutes(
validate: {
body: jobIdsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -215,6 +216,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(jobsWithTimerangeSchema),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -245,6 +249,9 @@ export function jobServiceRoutes(
validate: {
body: jobIdsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -272,6 +279,9 @@ export function jobServiceRoutes(
{
path: '/api/ml/jobs/groups',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -302,6 +312,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(updateGroupsSchema),
},
+ options: {
+ tags: ['access:ml:canUpdateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -329,6 +342,9 @@ export function jobServiceRoutes(
{
path: '/api/ml/jobs/deleting_jobs_tasks',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -359,6 +375,9 @@ export function jobServiceRoutes(
validate: {
body: jobIdsSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -389,6 +408,9 @@ export function jobServiceRoutes(
params: schema.object({ indexPattern: schema.string() }),
query: schema.maybe(schema.object({ rollup: schema.maybe(schema.string()) })),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -422,6 +444,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(chartSchema),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -474,6 +499,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(chartSchema),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -522,6 +550,9 @@ export function jobServiceRoutes(
{
path: '/api/ml/jobs/all_jobs_and_group_ids',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -552,6 +583,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(lookBackProgressSchema),
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -583,17 +617,12 @@ export function jobServiceRoutes(
validate: {
body: schema.object(categorizationFieldExamplesSchema),
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
- // due to the use of the _analyze endpoint which is called by the kibana user,
- // basic job creation privileges are required to use this endpoint
- if ((await hasPermissionToCreateJobs(request)) === false) {
- throw Boom.forbidden(
- 'Insufficient privileges, the machine_learning_admin role is required.'
- );
- }
-
const { validateCategoryExamples } = categorizationExamplesProvider(
context.ml!.mlClient.callAsCurrentUser,
context.ml!.mlClient.callAsInternalUser
@@ -644,6 +673,9 @@ export function jobServiceRoutes(
validate: {
body: schema.object(topCategoriesSchema),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/job_validation.ts b/x-pack/plugins/ml/server/routes/job_validation.ts
index dd2bd9deadf43..632166d6d5fb8 100644
--- a/x-pack/plugins/ml/server/routes/job_validation.ts
+++ b/x-pack/plugins/ml/server/routes/job_validation.ts
@@ -57,6 +57,9 @@ export function jobValidationRoutes({ router, mlLicense }: RouteInitialization,
validate: {
body: estimateBucketSpanSchema,
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -106,6 +109,9 @@ export function jobValidationRoutes({ router, mlLicense }: RouteInitialization,
validate: {
body: modelMemoryLimitSchema,
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -135,6 +141,9 @@ export function jobValidationRoutes({ router, mlLicense }: RouteInitialization,
validate: {
body: validateCardinalitySchema,
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -167,6 +176,9 @@ export function jobValidationRoutes({ router, mlLicense }: RouteInitialization,
validate: {
body: validateJobSchema,
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/modules.ts b/x-pack/plugins/ml/server/routes/modules.ts
index 2891144fc4574..622ae66ede426 100644
--- a/x-pack/plugins/ml/server/routes/modules.ts
+++ b/x-pack/plugins/ml/server/routes/modules.ts
@@ -97,6 +97,9 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
indexPatternTitle: schema.string(),
}),
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -127,6 +130,9 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
...getModuleIdParamSchema(true),
}),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -161,6 +167,9 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
params: schema.object(getModuleIdParamSchema()),
body: setupModuleBodySchema,
},
+ options: {
+ tags: ['access:ml:canCreateJob'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -218,6 +227,9 @@ export function dataRecognizer({ router, mlLicense }: RouteInitialization) {
validate: {
params: schema.object(getModuleIdParamSchema()),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/notification_settings.ts b/x-pack/plugins/ml/server/routes/notification_settings.ts
index 59458b1e486db..e4a9abb0784be 100644
--- a/x-pack/plugins/ml/server/routes/notification_settings.ts
+++ b/x-pack/plugins/ml/server/routes/notification_settings.ts
@@ -22,6 +22,9 @@ export function notificationRoutes({ router, mlLicense }: RouteInitialization) {
{
path: '/api/ml/notification_settings',
validate: false,
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/results_service.ts b/x-pack/plugins/ml/server/routes/results_service.ts
index 89c267340fe52..94ca0827ccfa5 100644
--- a/x-pack/plugins/ml/server/routes/results_service.ts
+++ b/x-pack/plugins/ml/server/routes/results_service.ts
@@ -88,6 +88,9 @@ export function resultsServiceRoutes({ router, mlLicense }: RouteInitialization)
validate: {
body: anomaliesTableDataSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -117,6 +120,9 @@ export function resultsServiceRoutes({ router, mlLicense }: RouteInitialization)
validate: {
body: categoryDefinitionSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -146,6 +152,9 @@ export function resultsServiceRoutes({ router, mlLicense }: RouteInitialization)
validate: {
body: maxAnomalyScoreSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -175,6 +184,9 @@ export function resultsServiceRoutes({ router, mlLicense }: RouteInitialization)
validate: {
body: categoryExamplesSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
@@ -204,6 +216,9 @@ export function resultsServiceRoutes({ router, mlLicense }: RouteInitialization)
validate: {
body: partitionFieldValuesSchema,
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/routes/system.ts b/x-pack/plugins/ml/server/routes/system.ts
index d5fe45728c56c..7ae7dd8eef065 100644
--- a/x-pack/plugins/ml/server/routes/system.ts
+++ b/x-pack/plugins/ml/server/routes/system.ts
@@ -54,6 +54,9 @@ export function systemRoutes(
validate: {
body: schema.maybe(schema.any()),
},
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
@@ -110,6 +113,9 @@ export function systemRoutes(
{
path: '/api/ml/ml_capabilities',
validate: false,
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
@@ -150,7 +156,11 @@ export function systemRoutes(
{
path: '/api/ml/ml_node_count',
validate: false,
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
+
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
// check for basic license first for consistency with other
@@ -201,6 +211,9 @@ export function systemRoutes(
{
path: '/api/ml/info',
validate: false,
+ options: {
+ tags: ['access:ml:canAccessML'],
+ },
},
mlLicense.basicLicenseAPIGuard(async (context, request, response) => {
try {
@@ -229,6 +242,9 @@ export function systemRoutes(
validate: {
body: schema.maybe(schema.any()),
},
+ options: {
+ tags: ['access:ml:canGetJobs'],
+ },
},
mlLicense.fullLicenseAPIGuard(async (context, request, response) => {
try {
diff --git a/x-pack/plugins/ml/server/types.ts b/x-pack/plugins/ml/server/types.ts
index d4cd61a7fa4f7..678e81d3526ac 100644
--- a/x-pack/plugins/ml/server/types.ts
+++ b/x-pack/plugins/ml/server/types.ts
@@ -30,10 +30,6 @@ export interface SystemRouteDeps {
resolveMlCapabilities: ResolveMlCapabilities;
}
-export interface JobServiceRouteDeps {
- resolveMlCapabilities: ResolveMlCapabilities;
-}
-
export interface PluginsSetup {
cloud: CloudSetup;
features: FeaturesPluginSetup;
diff --git a/x-pack/test/api_integration/apis/ml/anomaly_detectors/create.ts b/x-pack/test/api_integration/apis/ml/anomaly_detectors/create.ts
index bbc766df34dcf..10857caab98e2 100644
--- a/x-pack/test/api_integration/apis/ml/anomaly_detectors/create.ts
+++ b/x-pack/test/api_integration/apis/ml/anomaly_detectors/create.ts
@@ -91,12 +91,11 @@ export default ({ getService }: FtrProviderContext) => {
model_plot_config: { enabled: true },
},
expected: {
- responseCode: 403,
+ responseCode: 404,
responseBody: {
- statusCode: 403,
- error: 'Forbidden',
- message:
- '[security_exception] action [cluster:admin/xpack/ml/job/put] is unauthorized for user [ml_viewer]',
+ statusCode: 404,
+ error: 'Not Found',
+ message: 'Not Found',
},
},
},
diff --git a/x-pack/test/api_integration/apis/ml/jobs/jobs_summary.ts b/x-pack/test/api_integration/apis/ml/jobs/jobs_summary.ts
index 6a57db1687868..a5cb68d782126 100644
--- a/x-pack/test/api_integration/apis/ml/jobs/jobs_summary.ts
+++ b/x-pack/test/api_integration/apis/ml/jobs/jobs_summary.ts
@@ -197,8 +197,8 @@ export default ({ getService }: FtrProviderContext) => {
requestBody: {},
// Note that the jobs and datafeeds are loaded async so the actual error message is not deterministic.
expected: {
- responseCode: 403,
- error: 'Forbidden',
+ responseCode: 404,
+ error: 'Not Found',
},
},
];
diff --git a/x-pack/test/api_integration/apis/ml/modules/setup_module.ts b/x-pack/test/api_integration/apis/ml/modules/setup_module.ts
index 23ddd3b63a2ef..c42fc95c1bc7f 100644
--- a/x-pack/test/api_integration/apis/ml/modules/setup_module.ts
+++ b/x-pack/test/api_integration/apis/ml/modules/setup_module.ts
@@ -84,10 +84,9 @@ export default ({ getService }: FtrProviderContext) => {
startDatafeed: false,
},
expected: {
- responseCode: 403,
- error: 'Forbidden',
- message:
- '[security_exception] action [cluster:monitor/xpack/ml/info/get] is unauthorized for user [ml_unauthorized]',
+ responseCode: 404,
+ error: 'Not Found',
+ message: 'Not Found',
},
},
];
From 1512859e56d5196665ffbfaefd9b7a25d8b24100 Mon Sep 17 00:00:00 2001
From: "Christiane (Tina) Heiligers"
Date: Wed, 29 Apr 2020 10:54:19 -0700
Subject: [PATCH 27/33] [Telemetry] oss api tests (#64602)
* Adds telemetry API tests for oss
* Modifies test expectations to match that within oss
Co-authored-by: Elastic Machine
---
test/api_integration/apis/index.js | 1 +
test/api_integration/apis/telemetry/index.js | 26 ++++
test/api_integration/apis/telemetry/opt_in.ts | 123 ++++++++++++++++
.../apis/telemetry/telemetry_local.js | 133 ++++++++++++++++++
.../telemetry/telemetry_optin_notice_seen.ts | 59 ++++++++
5 files changed, 342 insertions(+)
create mode 100644 test/api_integration/apis/telemetry/index.js
create mode 100644 test/api_integration/apis/telemetry/opt_in.ts
create mode 100644 test/api_integration/apis/telemetry/telemetry_local.js
create mode 100644 test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts
diff --git a/test/api_integration/apis/index.js b/test/api_integration/apis/index.js
index c5bfc847d0041..0c4028905657d 100644
--- a/test/api_integration/apis/index.js
+++ b/test/api_integration/apis/index.js
@@ -33,5 +33,6 @@ export default function({ loadTestFile }) {
loadTestFile(require.resolve('./status'));
loadTestFile(require.resolve('./stats'));
loadTestFile(require.resolve('./ui_metric'));
+ loadTestFile(require.resolve('./telemetry'));
});
}
diff --git a/test/api_integration/apis/telemetry/index.js b/test/api_integration/apis/telemetry/index.js
new file mode 100644
index 0000000000000..c79f5cb470890
--- /dev/null
+++ b/test/api_integration/apis/telemetry/index.js
@@ -0,0 +1,26 @@
+/*
+ * 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 default function({ loadTestFile }) {
+ describe('Telemetry', () => {
+ loadTestFile(require.resolve('./telemetry_local'));
+ loadTestFile(require.resolve('./opt_in'));
+ loadTestFile(require.resolve('./telemetry_optin_notice_seen'));
+ });
+}
diff --git a/test/api_integration/apis/telemetry/opt_in.ts b/test/api_integration/apis/telemetry/opt_in.ts
new file mode 100644
index 0000000000000..e4654ee3985f3
--- /dev/null
+++ b/test/api_integration/apis/telemetry/opt_in.ts
@@ -0,0 +1,123 @@
+/*
+ * 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 expect from '@kbn/expect';
+
+import { TelemetrySavedObjectAttributes } from 'src/plugins/telemetry/server/telemetry_repository';
+import { FtrProviderContext } from '../../ftr_provider_context';
+
+export default function optInTest({ getService }: FtrProviderContext) {
+ const supertest = getService('supertest');
+ const kibanaServer = getService('kibanaServer');
+ describe('/api/telemetry/v2/optIn API', () => {
+ let defaultAttributes: TelemetrySavedObjectAttributes;
+ let kibanaVersion: any;
+ before(async () => {
+ const kibanaVersionAccessor = kibanaServer.version;
+ kibanaVersion = await kibanaVersionAccessor.get();
+ defaultAttributes =
+ (await getSavedObjectAttributes(supertest).catch(err => {
+ if (err.message === 'expected 200 "OK", got 404 "Not Found"') {
+ return null;
+ }
+ throw err;
+ })) || {};
+
+ expect(typeof kibanaVersion).to.eql('string');
+ expect(kibanaVersion.length).to.be.greaterThan(0);
+ });
+
+ afterEach(async () => {
+ await updateSavedObjectAttributes(supertest, defaultAttributes);
+ });
+
+ it('should support sending false with allowChangingOptInStatus true', async () => {
+ await updateSavedObjectAttributes(supertest, {
+ ...defaultAttributes,
+ allowChangingOptInStatus: true,
+ });
+ await postTelemetryV2Optin(supertest, false, 200);
+ const { enabled, lastVersionChecked } = await getSavedObjectAttributes(supertest);
+ expect(enabled).to.be(false);
+ expect(lastVersionChecked).to.be(kibanaVersion);
+ });
+
+ it('should support sending true with allowChangingOptInStatus true', async () => {
+ await updateSavedObjectAttributes(supertest, {
+ ...defaultAttributes,
+ allowChangingOptInStatus: true,
+ });
+ await postTelemetryV2Optin(supertest, true, 200);
+ const { enabled, lastVersionChecked } = await getSavedObjectAttributes(supertest);
+ expect(enabled).to.be(true);
+ expect(lastVersionChecked).to.be(kibanaVersion);
+ });
+
+ it('should not support sending false with allowChangingOptInStatus false', async () => {
+ await updateSavedObjectAttributes(supertest, {
+ ...defaultAttributes,
+ allowChangingOptInStatus: false,
+ });
+ await postTelemetryV2Optin(supertest, false, 400);
+ });
+
+ it('should not support sending true with allowChangingOptInStatus false', async () => {
+ await updateSavedObjectAttributes(supertest, {
+ ...defaultAttributes,
+ allowChangingOptInStatus: false,
+ });
+ await postTelemetryV2Optin(supertest, true, 400);
+ });
+
+ it('should not support sending null', async () => {
+ await postTelemetryV2Optin(supertest, null, 400);
+ });
+
+ it('should not support sending junk', async () => {
+ await postTelemetryV2Optin(supertest, 42, 400);
+ });
+ });
+}
+
+async function postTelemetryV2Optin(supertest: any, value: any, statusCode: number): Promise {
+ const { body } = await supertest
+ .post('/api/telemetry/v2/optIn')
+ .set('kbn-xsrf', 'xxx')
+ .send({ enabled: value })
+ .expect(statusCode);
+
+ return body;
+}
+
+async function updateSavedObjectAttributes(
+ supertest: any,
+ attributes: TelemetrySavedObjectAttributes
+): Promise {
+ return await supertest
+ .post('/api/saved_objects/telemetry/telemetry')
+ .query({ overwrite: true })
+ .set('kbn-xsrf', 'xxx')
+ .send({ attributes })
+ .expect(200);
+}
+
+async function getSavedObjectAttributes(supertest: any): Promise {
+ const { body } = await supertest.get('/api/saved_objects/telemetry/telemetry').expect(200);
+ return body.attributes;
+}
diff --git a/test/api_integration/apis/telemetry/telemetry_local.js b/test/api_integration/apis/telemetry/telemetry_local.js
new file mode 100644
index 0000000000000..84bfd8a755c11
--- /dev/null
+++ b/test/api_integration/apis/telemetry/telemetry_local.js
@@ -0,0 +1,133 @@
+/*
+ * 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 expect from '@kbn/expect';
+import _ from 'lodash';
+
+/*
+ * Create a single-level array with strings for all the paths to values in the
+ * source object, up to 3 deep. Going deeper than 3 causes a bit too much churn
+ * in the tests.
+ */
+function flatKeys(source) {
+ const recursivelyFlatKeys = (obj, path = [], depth = 0) => {
+ return depth < 3 && _.isObject(obj)
+ ? _.map(obj, (v, k) => recursivelyFlatKeys(v, [...path, k], depth + 1))
+ : path.join('.');
+ };
+
+ return _.uniq(_.flattenDeep(recursivelyFlatKeys(source))).sort((a, b) => a.localeCompare(b));
+}
+
+export default function({ getService }) {
+ const supertest = getService('supertest');
+
+ describe('/api/telemetry/v2/clusters/_stats', () => {
+ it('should pull local stats and validate data types', async () => {
+ const timeRange = {
+ min: '2018-07-23T22:07:00Z',
+ max: '2018-07-23T22:13:00Z',
+ };
+
+ const { body } = await supertest
+ .post('/api/telemetry/v2/clusters/_stats')
+ .set('kbn-xsrf', 'xxx')
+ .send({ timeRange, unencrypted: true })
+ .expect(200);
+
+ expect(body.length).to.be(1);
+ const stats = body[0];
+ expect(stats.collection).to.be('local');
+ expect(stats.stack_stats.kibana.count).to.be.a('number');
+ expect(stats.stack_stats.kibana.indices).to.be.a('number');
+ expect(stats.stack_stats.kibana.os.platforms[0].platform).to.be.a('string');
+ expect(stats.stack_stats.kibana.os.platforms[0].count).to.be(1);
+ expect(stats.stack_stats.kibana.os.platformReleases[0].platformRelease).to.be.a('string');
+ expect(stats.stack_stats.kibana.os.platformReleases[0].count).to.be(1);
+ expect(stats.stack_stats.kibana.plugins.telemetry.opt_in_status).to.be(false);
+ expect(stats.stack_stats.kibana.plugins.telemetry.usage_fetcher).to.be.a('string');
+ expect(stats.stack_stats.kibana.plugins.stack_management).to.be.an('object');
+ expect(stats.stack_stats.kibana.plugins.ui_metric).to.be.an('object');
+ expect(stats.stack_stats.kibana.plugins.application_usage).to.be.an('object');
+ expect(stats.stack_stats.kibana.plugins.kql.defaultQueryLanguage).to.be.a('string');
+ expect(stats.stack_stats.kibana.plugins['tsvb-validation']).to.be.an('object');
+ expect(stats.stack_stats.kibana.plugins.localization).to.be.an('object');
+ expect(stats.stack_stats.kibana.plugins.csp.strict).to.be(true);
+ expect(stats.stack_stats.kibana.plugins.csp.warnLegacyBrowsers).to.be(true);
+ expect(stats.stack_stats.kibana.plugins.csp.rulesChangedFromDefault).to.be(false);
+ });
+
+ it('should pull local stats and validate fields', async () => {
+ const timeRange = {
+ min: '2018-07-23T22:07:00Z',
+ max: '2018-07-23T22:13:00Z',
+ };
+
+ const { body } = await supertest
+ .post('/api/telemetry/v2/clusters/_stats')
+ .set('kbn-xsrf', 'xxx')
+ .send({ timeRange, unencrypted: true })
+ .expect(200);
+
+ const stats = body[0];
+
+ const actual = flatKeys(stats);
+ expect(actual).to.be.an('array');
+ const expected = [
+ 'cluster_name',
+ 'cluster_stats.cluster_uuid',
+ 'cluster_stats.indices.analysis',
+ 'cluster_stats.indices.completion',
+ 'cluster_stats.indices.count',
+ 'cluster_stats.indices.docs',
+ 'cluster_stats.indices.fielddata',
+ 'cluster_stats.indices.mappings',
+ 'cluster_stats.indices.query_cache',
+ 'cluster_stats.indices.segments',
+ 'cluster_stats.indices.shards',
+ 'cluster_stats.indices.store',
+ 'cluster_stats.nodes.count',
+ 'cluster_stats.nodes.discovery_types',
+ 'cluster_stats.nodes.fs',
+ 'cluster_stats.nodes.ingest',
+ 'cluster_stats.nodes.jvm',
+ 'cluster_stats.nodes.network_types',
+ 'cluster_stats.nodes.os',
+ 'cluster_stats.nodes.packaging_types',
+ 'cluster_stats.nodes.plugins',
+ 'cluster_stats.nodes.process',
+ 'cluster_stats.nodes.versions',
+ 'cluster_stats.status',
+ 'cluster_stats.timestamp',
+ 'cluster_uuid',
+ 'collection',
+ 'collectionSource',
+ 'stack_stats.kibana.count',
+ 'stack_stats.kibana.indices',
+ 'stack_stats.kibana.os',
+ 'stack_stats.kibana.plugins',
+ 'stack_stats.kibana.versions',
+ 'timestamp',
+ 'version',
+ ];
+
+ expect(expected.every(m => actual.includes(m))).to.be.ok();
+ });
+ });
+}
diff --git a/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts b/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts
new file mode 100644
index 0000000000000..4413c672fb46c
--- /dev/null
+++ b/test/api_integration/apis/telemetry/telemetry_optin_notice_seen.ts
@@ -0,0 +1,59 @@
+/*
+ * 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 expect from '@kbn/expect';
+import { Client, DeleteDocumentParams, GetParams, GetResponse } from 'elasticsearch';
+import { TelemetrySavedObjectAttributes } from 'src/plugins/telemetry/server/telemetry_repository';
+import { FtrProviderContext } from '../../ftr_provider_context';
+
+export default function optInTest({ getService }: FtrProviderContext) {
+ const client: Client = getService('legacyEs');
+ const supertest = getService('supertest');
+
+ describe('/api/telemetry/v2/userHasSeenNotice API Telemetry User has seen OptIn Notice', () => {
+ it('should update telemetry setting field via PUT', async () => {
+ try {
+ await client.delete({
+ index: '.kibana',
+ id: 'telemetry:telemetry',
+ } as DeleteDocumentParams);
+ } catch (err) {
+ if (err.statusCode !== 404) {
+ throw err;
+ }
+ }
+
+ await supertest
+ .put('/api/telemetry/v2/userHasSeenNotice')
+ .set('kbn-xsrf', 'xxx')
+ .expect(200);
+
+ const {
+ _source: { telemetry },
+ }: GetResponse<{
+ telemetry: TelemetrySavedObjectAttributes;
+ }> = await client.get({
+ index: '.kibana',
+ id: 'telemetry:telemetry',
+ } as GetParams);
+
+ expect(telemetry.userHasSeenNotice).to.be(true);
+ });
+ });
+}
From 3adab851380f4a368b9aa14cb227ef9f61e16e93 Mon Sep 17 00:00:00 2001
From: Ryland Herrick
Date: Wed, 29 Apr 2020 13:01:23 -0500
Subject: [PATCH 28/33] Minimize dependencies required by our telemetry
middleware (#64665)
1. we need our redux actions for our telemetry middleware, which:
2. require types from an index file, which:
3. includes all of our model types, and everything involved in them
By moving these types to a separate file and importing _that_instead, we
bypass inclusion of 2 and 3 in our plugin, which equates to ~550kB (of a
total of ~600kB).
---
.../siem/public/lib/telemetry/middleware.ts | 2 +-
x-pack/plugins/siem/public/store/model.ts | 13 +------------
.../siem/public/store/timeline/actions.ts | 2 +-
x-pack/plugins/siem/public/store/types.ts | 17 +++++++++++++++++
4 files changed, 20 insertions(+), 14 deletions(-)
create mode 100644 x-pack/plugins/siem/public/store/types.ts
diff --git a/x-pack/plugins/siem/public/lib/telemetry/middleware.ts b/x-pack/plugins/siem/public/lib/telemetry/middleware.ts
index 59c6cb3566907..ca889e20e695f 100644
--- a/x-pack/plugins/siem/public/lib/telemetry/middleware.ts
+++ b/x-pack/plugins/siem/public/lib/telemetry/middleware.ts
@@ -7,7 +7,7 @@
import { Action, Dispatch, MiddlewareAPI } from 'redux';
import { track, METRIC_TYPE, TELEMETRY_EVENT } from './';
-import { timelineActions } from '../../store/actions';
+import * as timelineActions from '../../store/timeline/actions';
export const telemetryMiddleware = (api: MiddlewareAPI) => (next: Dispatch) => (action: Action) => {
if (timelineActions.endTimelineSaving.match(action)) {
diff --git a/x-pack/plugins/siem/public/store/model.ts b/x-pack/plugins/siem/public/store/model.ts
index 9e9e663a59fe0..686dc096e61b0 100644
--- a/x-pack/plugins/siem/public/store/model.ts
+++ b/x-pack/plugins/siem/public/store/model.ts
@@ -9,15 +9,4 @@ export { dragAndDropModel } from './drag_and_drop';
export { hostsModel } from './hosts';
export { inputsModel } from './inputs';
export { networkModel } from './network';
-
-export type KueryFilterQueryKind = 'kuery' | 'lucene';
-
-export interface KueryFilterQuery {
- kind: KueryFilterQueryKind;
- expression: string;
-}
-
-export interface SerializedFilterQuery {
- kuery: KueryFilterQuery | null;
- serializedQuery: string;
-}
+export * from './types';
diff --git a/x-pack/plugins/siem/public/store/timeline/actions.ts b/x-pack/plugins/siem/public/store/timeline/actions.ts
index a03cc2643e014..12155decf40d4 100644
--- a/x-pack/plugins/siem/public/store/timeline/actions.ts
+++ b/x-pack/plugins/siem/public/store/timeline/actions.ts
@@ -12,7 +12,7 @@ import {
DataProvider,
QueryOperator,
} from '../../components/timeline/data_providers/data_provider';
-import { KueryFilterQuery, SerializedFilterQuery } from '../model';
+import { KueryFilterQuery, SerializedFilterQuery } from '../types';
import { EventType, KqlMode, TimelineModel, ColumnHeaderOptions } from './model';
import { TimelineNonEcsData } from '../../graphql/types';
diff --git a/x-pack/plugins/siem/public/store/types.ts b/x-pack/plugins/siem/public/store/types.ts
new file mode 100644
index 0000000000000..2c679ba41116e
--- /dev/null
+++ b/x-pack/plugins/siem/public/store/types.ts
@@ -0,0 +1,17 @@
+/*
+ * 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 type KueryFilterQueryKind = 'kuery' | 'lucene';
+
+export interface KueryFilterQuery {
+ kind: KueryFilterQueryKind;
+ expression: string;
+}
+
+export interface SerializedFilterQuery {
+ kuery: KueryFilterQuery | null;
+ serializedQuery: string;
+}
From 53ff22997a1401ccbd2808831b26b92fa174de92 Mon Sep 17 00:00:00 2001
From: Sandra Gonzales
Date: Wed, 29 Apr 2020 14:06:08 -0400
Subject: [PATCH 29/33] [EPM] Update UI to handle package versions and updates
(#64689)
* link to installed version of detail page
* add latestVersion property to EPM get package endpoint
* add updates available notices
* add update package button
* handle various states and send installedVersion from package endpoint
* fix type errors
* fix install error because not returning promises
* track version in state
* handle unsuccessful update attempt
* remove unused variable
---
.../common/services/package_to_config.test.ts | 1 +
.../ingest_manager/common/types/models/epm.ts | 2 +
.../sections/epm/components/icons.tsx | 15 ++
.../sections/epm/components/package_card.tsx | 8 +-
.../epm/hooks/use_package_install.tsx | 63 +++--
.../sections/epm/screens/detail/content.tsx | 3 +-
.../epm/screens/detail/data_sources_panel.tsx | 2 +-
.../sections/epm/screens/detail/header.tsx | 17 +-
.../sections/epm/screens/detail/index.tsx | 4 +-
.../screens/detail/installation_button.tsx | 23 +-
.../epm/screens/detail/settings_panel.tsx | 236 ++++++++++++------
.../epm/screens/detail/side_nav_links.tsx | 2 +-
.../server/services/epm/packages/get.ts | 4 +-
.../server/services/epm/packages/index.ts | 1 +
.../server/services/epm/packages/install.ts | 2 +-
.../server/services/epm/packages/remove.ts | 8 +-
16 files changed, 277 insertions(+), 114 deletions(-)
create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/icons.tsx
diff --git a/x-pack/plugins/ingest_manager/common/services/package_to_config.test.ts b/x-pack/plugins/ingest_manager/common/services/package_to_config.test.ts
index cb290e61b17e5..a977a1a66e059 100644
--- a/x-pack/plugins/ingest_manager/common/services/package_to_config.test.ts
+++ b/x-pack/plugins/ingest_manager/common/services/package_to_config.test.ts
@@ -11,6 +11,7 @@ describe('Ingest Manager - packageToConfig', () => {
name: 'mock-package',
title: 'Mock package',
version: '0.0.0',
+ latestVersion: '0.0.0',
description: 'description',
type: 'mock',
categories: [],
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 05e160cdfb81a..f8779a879a049 100644
--- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts
+++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts
@@ -204,6 +204,8 @@ export interface RegistryVarsEntry {
// internal until we need them
interface PackageAdditions {
title: string;
+ latestVersion: string;
+ installedVersion?: string;
assets: AssetsGroupedByServiceByType;
}
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/icons.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/icons.tsx
new file mode 100644
index 0000000000000..64223efefaab8
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/icons.tsx
@@ -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 { EuiIcon } from '@elastic/eui';
+import React from 'react';
+import styled from 'styled-components';
+
+export const StyledAlert = styled(EuiIcon)`
+ color: ${props => props.theme.eui.euiColorWarning};
+ padding: 0 5px;
+`;
+
+export const UpdateIcon = () => ;
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/package_card.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/package_card.tsx
index 8ad081cbbabe4..ab7e87b3ad06c 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/package_card.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/components/package_card.tsx
@@ -30,9 +30,15 @@ export function PackageCard({
showInstalledBadge,
status,
icons,
+ ...restProps
}: PackageCardProps) {
const { toDetailView } = useLinks();
- const url = toDetailView({ name, version });
+ let urlVersion = version;
+ // if this is an installed package, link to the version installed
+ if ('savedObject' in restProps) {
+ urlVersion = restProps.savedObject.attributes.version || version;
+ }
+ const url = toDetailView({ name, version: urlVersion });
return (
;
+type InstallPackageProps = Pick & {
+ fromUpdate?: boolean;
+};
+type SetPackageInstallStatusProps = Pick & PackageInstallItem;
function usePackageInstall({ notifications }: { notifications: NotificationsStart }) {
+ const { toDetailView } = useLinks();
const [packages, setPackage] = useState({});
const setPackageInstallStatus = useCallback(
- ({ name, status }: { name: PackageInfo['name']; status: InstallStatus }) => {
+ ({ name, status, version }: SetPackageInstallStatusProps) => {
+ const packageProps: PackageInstallItem = {
+ status,
+ version,
+ };
setPackage((prev: PackagesInstall) => ({
...prev,
- [name]: { status },
+ [name]: packageProps,
}));
},
[]
);
+ const getPackageInstallStatus = useCallback(
+ (pkg: string): PackageInstallItem => {
+ return packages[pkg];
+ },
+ [packages]
+ );
+
const installPackage = useCallback(
- async ({ name, version, title }: InstallPackageProps) => {
- setPackageInstallStatus({ name, status: InstallStatus.installing });
+ async ({ name, version, title, fromUpdate = false }: InstallPackageProps) => {
+ const currStatus = getPackageInstallStatus(name);
+ const newStatus = { ...currStatus, name, status: InstallStatus.installing };
+ setPackageInstallStatus(newStatus);
const pkgkey = `${name}-${version}`;
const res = await sendInstallPackage(pkgkey);
if (res.error) {
- setPackageInstallStatus({ name, status: InstallStatus.notInstalled });
+ if (fromUpdate) {
+ // if there is an error during update, set it back to the previous version
+ // as handling of bad update is not implemented yet
+ setPackageInstallStatus({ ...currStatus, name });
+ } else {
+ setPackageInstallStatus({ name, status: InstallStatus.notInstalled, version });
+ }
notifications.toasts.addWarning({
title: toMountPoint(
{
- return packages[pkg].status;
- },
- [packages]
+ [getPackageInstallStatus, notifications.toasts, setPackageInstallStatus, toDetailView]
);
const uninstallPackage = useCallback(
async ({ name, version, title }: Pick) => {
- setPackageInstallStatus({ name, status: InstallStatus.uninstalling });
+ setPackageInstallStatus({ name, status: InstallStatus.uninstalling, version });
const pkgkey = `${name}-${version}`;
const res = await sendRemovePackage(pkgkey);
if (res.error) {
- setPackageInstallStatus({ name, status: InstallStatus.installed });
+ setPackageInstallStatus({ name, status: InstallStatus.installed, version });
notifications.toasts.addWarning({
title: toMountPoint(
;
export function ContentPanel(props: ContentPanelProps) {
- const { panel, name, version, assets, title, removable } = props;
+ const { panel, name, version, assets, title, removable, latestVersion } = props;
switch (panel) {
case 'settings':
return (
@@ -60,6 +60,7 @@ export function ContentPanel(props: ContentPanelProps) {
assets={assets}
title={title}
removable={removable}
+ latestVersion={latestVersion}
/>
);
case 'data-sources':
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/data_sources_panel.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/data_sources_panel.tsx
index fa3245aec02c5..c82b7ed2297a7 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/data_sources_panel.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/data_sources_panel.tsx
@@ -20,7 +20,7 @@ export const DataSourcesPanel = ({ name, version }: DataSourcesPanelProps) => {
const packageInstallStatus = getPackageInstallStatus(name);
// if they arrive at this page and the package is not installed, send them to overview
// this happens if they arrive with a direct url or they uninstall while on this tab
- if (packageInstallStatus !== InstallStatus.installed)
+ if (packageInstallStatus.status !== InstallStatus.installed)
return (
props.theme.eui.euiSizeM};
`;
-const StyledVersion = styled(Version)`
- font-size: ${props => props.theme.eui.euiFontSizeS};
- color: ${props => props.theme.eui.euiColorDarkShade};
-`;
-
type HeaderProps = PackageInfo & { iconType?: IconType };
export function Header(props: HeaderProps) {
- const { iconType, name, title, version } = props;
+ const { iconType, name, title, version, installedVersion, latestVersion } = props;
const hasWriteCapabilites = useCapabilities().write;
const { toListView } = useLinks();
const ADD_DATASOURCE_URI = useLink(`${EPM_PATH}/${name}-${version}/add-datasource`);
-
+ const updateAvailable = installedVersion && installedVersion < latestVersion ? true : false;
return (
@@ -59,7 +54,11 @@ export function Header(props: HeaderProps) {
{title}
-
+
+
+ {version} {updateAvailable && }
+
+
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/index.tsx
index 3239d7b90e3c3..1f3eb2cc9362e 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/index.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/index.tsx
@@ -32,11 +32,12 @@ export function Detail() {
const packageInfo = response.data?.response;
const title = packageInfo?.title;
const name = packageInfo?.name;
+ const installedVersion = packageInfo?.installedVersion;
const status: InstallStatus = packageInfo?.status as any;
// track install status state
if (name) {
- setPackageInstallStatus({ name, status });
+ setPackageInstallStatus({ name, status, version: installedVersion || null });
}
if (packageInfo) {
setInfo({ ...packageInfo, title: title || '' });
@@ -64,7 +65,6 @@ type LayoutProps = PackageInfo & Pick & Pick
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/installation_button.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/installation_button.tsx
index cbbf1ce53c4ea..cdad67fd87548 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/installation_button.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/installation_button.tsx
@@ -13,19 +13,21 @@ import { ConfirmPackageUninstall } from './confirm_package_uninstall';
import { ConfirmPackageInstall } from './confirm_package_install';
type InstallationButtonProps = Pick & {
- disabled: boolean;
+ disabled?: boolean;
+ isUpdate?: boolean;
};
export function InstallationButton(props: InstallationButtonProps) {
- const { assets, name, title, version, disabled = true } = props;
+ const { assets, name, title, version, disabled = true, isUpdate = false } = props;
const hasWriteCapabilites = useCapabilities().write;
const installPackage = useInstallPackage();
const uninstallPackage = useUninstallPackage();
const getPackageInstallStatus = useGetPackageInstallStatus();
- const installationStatus = getPackageInstallStatus(name);
+ const { status: installationStatus } = getPackageInstallStatus(name);
const isInstalling = installationStatus === InstallStatus.installing;
const isRemoving = installationStatus === InstallStatus.uninstalling;
const isInstalled = installationStatus === InstallStatus.installed;
+ const showUninstallButton = isInstalled || isRemoving;
const [isModalVisible, setModalVisible] = useState(false);
const toggleModal = useCallback(() => {
setModalVisible(!isModalVisible);
@@ -36,6 +38,10 @@ export function InstallationButton(props: InstallationButtonProps) {
toggleModal();
}, [installPackage, name, title, toggleModal, version]);
+ const handleClickUpdate = useCallback(() => {
+ installPackage({ name, version, title, fromUpdate: true });
+ }, [installPackage, name, title, version]);
+
const handleClickUninstall = useCallback(() => {
uninstallPackage({ name, version, title });
toggleModal();
@@ -78,6 +84,15 @@ export function InstallationButton(props: InstallationButtonProps) {
);
+ const updateButton = (
+
+
+
+ );
+
const uninstallButton = (
- {isInstalled || isRemoving ? uninstallButton : installButton}
+ {isUpdate ? updateButton : showUninstallButton ? uninstallButton : installButton}
{isModalVisible && (isInstalled ? uninstallModal : installModal)}
) : null;
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/settings_panel.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/settings_panel.tsx
index 3589a1a9444e1..4d4dba2a64e5a 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/settings_panel.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/settings_panel.tsx
@@ -8,11 +8,22 @@ import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTitle, EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
import { EuiSpacer } from '@elastic/eui';
+import styled from 'styled-components';
import { InstallStatus, PackageInfo } from '../../../../types';
import { useGetDatasources } from '../../../../hooks';
import { DATASOURCE_SAVED_OBJECT_TYPE } from '../../../../constants';
import { useGetPackageInstallStatus } from '../../hooks';
import { InstallationButton } from './installation_button';
+import { UpdateIcon } from '../../components/icons';
+
+const SettingsTitleCell = styled.td`
+ padding-right: ${props => props.theme.eui.spacerSizes.xl};
+ padding-bottom: ${props => props.theme.eui.spacerSizes.m};
+`;
+
+const UpdatesAvailableMsgContainer = styled.span`
+ padding-left: ${props => props.theme.eui.spacerSizes.s};
+`;
const NoteLabel = () => (
(
defaultMessage="Note:"
/>
);
+const UpdatesAvailableMsg = () => (
+
+
+
+
+);
+
export const SettingsPanel = (
- props: Pick
+ props: Pick
) => {
+ const { name, title, removable, latestVersion, version } = props;
const getPackageInstallStatus = useGetPackageInstallStatus();
const { data: datasourcesData } = useGetDatasources({
perPage: 0,
page: 1,
kuery: `${DATASOURCE_SAVED_OBJECT_TYPE}.package.name:${props.name}`,
});
- const { name, title, removable } = props;
- const packageInstallStatus = getPackageInstallStatus(name);
+ const { status: installationStatus, version: installedVersion } = getPackageInstallStatus(name);
const packageHasDatasources = !!datasourcesData?.total;
+ const updateAvailable = installedVersion && installedVersion < latestVersion ? true : false;
+ const isViewingOldPackage = version < latestVersion;
+ // hide install/remove options if the user has version of the package is installed
+ // and this package is out of date or if they do have a version installed but it's not this one
+ const hideInstallOptions =
+ (installationStatus === InstallStatus.notInstalled && isViewingOldPackage) ||
+ (installationStatus === InstallStatus.installed && installedVersion !== version);
+
+ const isUpdating = installationStatus === InstallStatus.installing && installedVersion;
return (
@@ -43,14 +73,13 @@ export const SettingsPanel = (
- {packageInstallStatus === InstallStatus.notInstalled ||
- packageInstallStatus === InstallStatus.installing ? (
+ {installedVersion !== null && (
-
-
-
+
+
+
+
+
+
+
+
+ {installedVersion}
+
+ {updateAvailable && }
+ |
+
+
+
+
+
+
+
+ {latestVersion}
+
+ |
+
+
+
+ {updateAvailable && (
+
+
+
+ )}
- ) : (
+ )}
+ {!hideInstallOptions && !isUpdating && (
-
-
+
+ {installationStatus === InstallStatus.notInstalled ||
+ installationStatus === InstallStatus.installing ? (
+
+ ) : (
+
+ )}
+
+
+
+
+
+
+
+ {packageHasDatasources && removable === true && (
+
+
+
+ ),
}}
/>
-
-
-
-
-
-
+
+ )}
+ {removable === false && (
+
+
+
+
+ ),
+ }}
+ />
+
+ )}
)}
-
-
-
-
-
-
-
- {packageHasDatasources && removable === true && (
-
-
-
-
- ),
- }}
- />
-
- )}
- {removable === false && (
-
-
-
-
- ),
- }}
- />
-
- )}
);
};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/side_nav_links.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/side_nav_links.tsx
index 05729ccfc1af4..ab168ef1530bd 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/side_nav_links.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/epm/screens/detail/side_nav_links.tsx
@@ -37,7 +37,7 @@ export function SideNavLinks({ name, version, active }: NavLinkProps) {
: p.theme.eui.euiFontWeightRegular};
`;
// don't display Data Sources tab if the package is not installed
- if (packageInstallStatus !== InstallStatus.installed && panel === 'data-sources')
+ if (packageInstallStatus.status !== InstallStatus.installed && panel === 'data-sources')
return null;
return (
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 d76584225877c..da8d79a04b97c 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
@@ -67,9 +67,10 @@ export async function getPackageInfo(options: {
pkgVersion: string;
}): Promise {
const { savedObjectsClient, pkgName, pkgVersion } = options;
- const [item, savedObject, assets] = await Promise.all([
+ const [item, savedObject, latestPackage, assets] = await Promise.all([
Registry.fetchInfo(pkgName, pkgVersion),
getInstallationObject({ savedObjectsClient, pkgName }),
+ Registry.fetchFindLatestPackage(pkgName),
Registry.getArchiveInfo(pkgName, pkgVersion),
] as const);
// adding `as const` due to regression in TS 3.7.2
@@ -79,6 +80,7 @@ export async function getPackageInfo(options: {
// add properties that aren't (or aren't yet) on Registry response
const updated = {
...item,
+ latestVersion: latestPackage.version,
title: item.title || nameAsTitle(item.name),
assets: Registry.groupPathsByService(assets || []),
};
diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts
index d49e0e661440f..c67cccd044bf5 100644
--- a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts
+++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts
@@ -43,6 +43,7 @@ export function createInstallableFrom(
? {
...from,
status: InstallationStatus.installed,
+ installedVersion: savedObject.attributes.version,
savedObject,
}
: {
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 06f3decdbbe6f..8f51c4d78305c 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
@@ -106,7 +106,7 @@ export async function installPackage(options: {
try {
await deleteKibanaSavedObjectsAssets(savedObjectsClient, installedPkg.attributes.installed);
} catch (err) {
- // some assets may not exist if deleting during a failed update
+ // log these errors, some assets may not exist if deleted during a failed update
}
}
diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/remove.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/remove.ts
index ac2c869f3b9e9..befb4722b6504 100644
--- a/x-pack/plugins/ingest_manager/server/services/epm/packages/remove.ts
+++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/remove.ts
@@ -121,8 +121,12 @@ export async function deleteKibanaSavedObjectsAssets(
const deletePromises = installedObjects.map(({ id, type }) => {
const assetType = type as AssetType;
if (savedObjectTypes.includes(assetType)) {
- savedObjectsClient.delete(assetType, id);
+ return savedObjectsClient.delete(assetType, id);
}
});
- await Promise.all(deletePromises);
+ try {
+ await Promise.all(deletePromises);
+ } catch (err) {
+ throw new Error('error deleting saved object asset');
+ }
}
From f5a8d8e6c27958dacc16a36b24bded57b4313f9d Mon Sep 17 00:00:00 2001
From: Lee Drengenberg
Date: Wed, 29 Apr 2020 19:05:45 +0000
Subject: [PATCH 30/33] make inserting timestamp with navigate methods optional
with default true (#64655)
---
test/functional/page_objects/common_page.ts | 23 +++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts
index 862e5127bb670..93debdcc37f0a 100644
--- a/test/functional/page_objects/common_page.ts
+++ b/test/functional/page_objects/common_page.ts
@@ -44,6 +44,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
ensureCurrentUrl: boolean;
shouldLoginIfPrompted: boolean;
useActualUrl: boolean;
+ insertTimestamp: boolean;
}
class CommonPage {
@@ -65,7 +66,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
* Logins to Kibana as default user and navigates to provided app
* @param appUrl Kibana URL
*/
- private async loginIfPrompted(appUrl: string) {
+ private async loginIfPrompted(appUrl: string, insertTimestamp: boolean) {
let currentUrl = await browser.getCurrentUrl();
log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`);
await testSubjects.find('kibanaChrome', 6 * defaultFindTimeout); // 60 sec waiting
@@ -87,7 +88,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
'[data-test-subj="kibanaChrome"] nav:not(.ng-hide)',
6 * defaultFindTimeout
);
- await browser.get(appUrl);
+ await browser.get(appUrl, insertTimestamp);
currentUrl = await browser.getCurrentUrl();
log.debug(`Finished login process currentUrl = ${currentUrl}`);
}
@@ -95,7 +96,13 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}
private async navigate(navigateProps: NavigateProps) {
- const { appConfig, ensureCurrentUrl, shouldLoginIfPrompted, useActualUrl } = navigateProps;
+ const {
+ appConfig,
+ ensureCurrentUrl,
+ shouldLoginIfPrompted,
+ useActualUrl,
+ insertTimestamp,
+ } = navigateProps;
const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig);
await retry.try(async () => {
@@ -111,7 +118,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
}
const currentUrl = shouldLoginIfPrompted
- ? await this.loginIfPrompted(appUrl)
+ ? await this.loginIfPrompted(appUrl, insertTimestamp)
: await browser.getCurrentUrl();
if (ensureCurrentUrl && !currentUrl.includes(appUrl)) {
@@ -134,6 +141,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
useActualUrl = false,
+ insertTimestamp = true,
} = {}
) {
const appConfig = {
@@ -146,6 +154,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
ensureCurrentUrl,
shouldLoginIfPrompted,
useActualUrl,
+ insertTimestamp,
});
}
@@ -165,6 +174,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
ensureCurrentUrl = true,
shouldLoginIfPrompted = true,
useActualUrl = true,
+ insertTimestamp = true,
} = {}
) {
const appConfig = {
@@ -178,6 +188,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
ensureCurrentUrl,
shouldLoginIfPrompted,
useActualUrl,
+ insertTimestamp,
});
}
@@ -208,7 +219,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
async navigateToApp(
appName: string,
- { basePath = '', shouldLoginIfPrompted = true, hash = '' } = {}
+ { basePath = '', shouldLoginIfPrompted = true, hash = '', insertTimestamp = true } = {}
) {
let appUrl: string;
if (config.has(['apps', appName])) {
@@ -239,7 +250,7 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo
log.debug('returned from get, calling refresh');
await browser.refresh();
let currentUrl = shouldLoginIfPrompted
- ? await this.loginIfPrompted(appUrl)
+ ? await this.loginIfPrompted(appUrl, insertTimestamp)
: await browser.getCurrentUrl();
if (currentUrl.includes('app/kibana')) {
From 02ba5fcb131dc82c4d253a8e49e40d3d9e600037 Mon Sep 17 00:00:00 2001
From: Tim Sullivan
Date: Wed, 29 Apr 2020 12:19:31 -0700
Subject: [PATCH 31/33] [Reporting/Test] Convert functional test code to
Typescript (#64601)
* Convert the tests to typescript
* remove outdated comment
* fix typescript
* fix "as any"
Co-authored-by: Elastic Machine
---
.../reporting/{index.js => index.ts} | 9 ++---
.../lib/{compare_pngs.js => compare_pngs.ts} | 13 ++++---
.../discover/{reporting.js => reporting.ts} | 3 +-
.../visualize/{reporting.js => reporting.ts} | 3 +-
x-pack/test/functional/page_objects/index.ts | 1 -
.../{reporting_page.js => reporting_page.ts} | 35 ++++++++-----------
6 files changed, 33 insertions(+), 31 deletions(-)
rename x-pack/test/functional/apps/dashboard/reporting/{index.js => index.ts} (94%)
rename x-pack/test/functional/apps/dashboard/reporting/lib/{compare_pngs.js => compare_pngs.ts} (90%)
rename x-pack/test/functional/apps/discover/{reporting.js => reporting.ts} (96%)
rename x-pack/test/functional/apps/visualize/{reporting.js => reporting.ts} (94%)
rename x-pack/test/functional/page_objects/{reporting_page.js => reporting_page.ts} (84%)
diff --git a/x-pack/test/functional/apps/dashboard/reporting/index.js b/x-pack/test/functional/apps/dashboard/reporting/index.ts
similarity index 94%
rename from x-pack/test/functional/apps/dashboard/reporting/index.js
rename to x-pack/test/functional/apps/dashboard/reporting/index.ts
index 99be084d80d74..796e15b4e270f 100644
--- a/x-pack/test/functional/apps/dashboard/reporting/index.js
+++ b/x-pack/test/functional/apps/dashboard/reporting/index.ts
@@ -5,9 +5,10 @@
*/
import expect from '@kbn/expect';
-import path from 'path';
import fs from 'fs';
+import path from 'path';
import { promisify } from 'util';
+import { FtrProviderContext } from '../../../ftr_provider_context';
import { checkIfPngsMatch } from './lib/compare_pngs';
const writeFileAsync = promisify(fs.writeFile);
@@ -15,7 +16,7 @@ const mkdirAsync = promisify(fs.mkdir);
const REPORTS_FOLDER = path.resolve(__dirname, 'reports');
-export default function({ getService, getPageObjects }) {
+export default function({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const log = getService('log');
@@ -85,14 +86,14 @@ export default function({ getService, getPageObjects }) {
describe('Preserve Layout', () => {
it('matches baseline report', async function() {
- const writeSessionReport = async (name, rawPdf, reportExt) => {
+ const writeSessionReport = async (name: string, rawPdf: Buffer, reportExt: string) => {
const sessionDirectory = path.resolve(REPORTS_FOLDER, 'session');
await mkdirAsync(sessionDirectory, { recursive: true });
const sessionReportPath = path.resolve(sessionDirectory, `${name}.${reportExt}`);
await writeFileAsync(sessionReportPath, rawPdf);
return sessionReportPath;
};
- const getBaselineReportPath = (fileName, reportExt) => {
+ const getBaselineReportPath = (fileName: string, reportExt: string) => {
const baselineFolder = path.resolve(REPORTS_FOLDER, 'baseline');
const fullPath = path.resolve(baselineFolder, `${fileName}.${reportExt}`);
log.debug(`getBaselineReportPath (${fullPath})`);
diff --git a/x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.js b/x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.ts
similarity index 90%
rename from x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.js
rename to x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.ts
index 13c97a7fce785..b2eb645c8372c 100644
--- a/x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.js
+++ b/x-pack/test/functional/apps/dashboard/reporting/lib/compare_pngs.ts
@@ -4,14 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import path from 'path';
-import fs from 'fs';
import { promisify } from 'bluebird';
+import fs from 'fs';
+import path from 'path';
import { comparePngs } from '../../../../../../../test/functional/services/lib/compare_pngs';
-const mkdirAsync = promisify(fs.mkdir);
+const mkdirAsync = promisify(fs.mkdir);
-export async function checkIfPngsMatch(actualpngPath, baselinepngPath, screenshotsDirectory, log) {
+export async function checkIfPngsMatch(
+ actualpngPath: string,
+ baselinepngPath: string,
+ screenshotsDirectory: string,
+ log: any
+) {
log.debug(`checkIfpngsMatch: ${actualpngPath} vs ${baselinepngPath}`);
// Copy the pngs into the screenshot session directory, as that's where the generated pngs will automatically be
// stored.
diff --git a/x-pack/test/functional/apps/discover/reporting.js b/x-pack/test/functional/apps/discover/reporting.ts
similarity index 96%
rename from x-pack/test/functional/apps/discover/reporting.js
rename to x-pack/test/functional/apps/discover/reporting.ts
index 4aa005fc2db55..7a33e7f5135d4 100644
--- a/x-pack/test/functional/apps/discover/reporting.js
+++ b/x-pack/test/functional/apps/discover/reporting.ts
@@ -5,8 +5,9 @@
*/
import expect from '@kbn/expect';
+import { FtrProviderContext } from '../../ftr_provider_context';
-export default function({ getService, getPageObjects }) {
+export default function({ getService, getPageObjects }: FtrProviderContext) {
const log = getService('log');
const esArchiver = getService('esArchiver');
const browser = getService('browser');
diff --git a/x-pack/test/functional/apps/visualize/reporting.js b/x-pack/test/functional/apps/visualize/reporting.ts
similarity index 94%
rename from x-pack/test/functional/apps/visualize/reporting.js
rename to x-pack/test/functional/apps/visualize/reporting.ts
index bc252e1ad4134..5ef954e334d81 100644
--- a/x-pack/test/functional/apps/visualize/reporting.js
+++ b/x-pack/test/functional/apps/visualize/reporting.ts
@@ -5,8 +5,9 @@
*/
import expect from '@kbn/expect';
+import { FtrProviderContext } from '../../ftr_provider_context';
-export default function({ getService, getPageObjects }) {
+export default function({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const browser = getService('browser');
const log = getService('log');
diff --git a/x-pack/test/functional/page_objects/index.ts b/x-pack/test/functional/page_objects/index.ts
index 782d57adea770..4b8c2944ef190 100644
--- a/x-pack/test/functional/page_objects/index.ts
+++ b/x-pack/test/functional/page_objects/index.ts
@@ -19,7 +19,6 @@ import { GraphPageProvider } from './graph_page';
import { GrokDebuggerPageProvider } from './grok_debugger_page';
// @ts-ignore not ts yet
import { WatcherPageProvider } from './watcher_page';
-// @ts-ignore not ts yet
import { ReportingPageProvider } from './reporting_page';
// @ts-ignore not ts yet
import { AccountSettingProvider } from './accountsetting_page';
diff --git a/x-pack/test/functional/page_objects/reporting_page.js b/x-pack/test/functional/page_objects/reporting_page.ts
similarity index 84%
rename from x-pack/test/functional/page_objects/reporting_page.js
rename to x-pack/test/functional/page_objects/reporting_page.ts
index b24ba8cf95d1c..2c20519a8d214 100644
--- a/x-pack/test/functional/page_objects/reporting_page.js
+++ b/x-pack/test/functional/page_objects/reporting_page.ts
@@ -4,25 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import http, { IncomingMessage } from 'http';
+import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import { parse } from 'url';
-import http from 'http';
-/*
- * NOTE: Reporting is a service, not an app. The page objects that are
- * important for generating reports belong to the apps that integrate with the
- * Reporting service. Eventually, this file should be dissolved across the
- * apps that need it for testing their integration.
- * Issue: https://github.com/elastic/kibana/issues/52927
- */
-export function ReportingPageProvider({ getService, getPageObjects }) {
+export function ReportingPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const log = getService('log');
const testSubjects = getService('testSubjects');
const browser = getService('browser');
- const PageObjects = getPageObjects(['common', 'security', 'share', 'timePicker']);
+ const PageObjects = getPageObjects(['common', 'security' as any, 'share', 'timePicker']); // FIXME: Security PageObject is not Typescript
class ReportingPage {
- async forceSharedItemsContainerSize({ width }) {
+ async forceSharedItemsContainerSize({ width }: { width: number }) {
await browser.execute(`
var el = document.querySelector('[data-shared-items-container]');
el.style.flex="none";
@@ -30,7 +24,7 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
`);
}
- async getReportURL(timeout) {
+ async getReportURL(timeout: number) {
log.debug('getReportURL');
const url = await testSubjects.getAttribute('downloadCompletedReportButton', 'href', timeout);
@@ -48,7 +42,7 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
`);
}
- getResponse(url) {
+ getResponse(url: string): Promise {
log.debug(`getResponse for ${url}`);
const auth = 'test_user:changeme'; // FIXME not sure why there is no config that can be read for this
const headers = {
@@ -62,29 +56,30 @@ export function ReportingPageProvider({ getService, getPageObjects }) {
hostname: parsedUrl.hostname,
path: parsedUrl.path,
port: parsedUrl.port,
- responseType: 'arraybuffer',
headers,
},
- res => {
+ (res: IncomingMessage) => {
resolve(res);
}
)
- .on('error', e => {
+ .on('error', (e: Error) => {
log.error(e);
reject(e);
});
});
}
- async getRawPdfReportData(url) {
- const data = []; // List of Buffer objects
+ async getRawPdfReportData(url: string): Promise {
+ const data: Buffer[] = []; // List of Buffer objects
log.debug(`getRawPdfReportData for ${url}`);
return new Promise(async (resolve, reject) => {
const response = await this.getResponse(url).catch(reject);
- response.on('data', chunk => data.push(chunk));
- response.on('end', () => resolve(Buffer.concat(data)));
+ if (response) {
+ response.on('data', (chunk: Buffer) => data.push(chunk));
+ response.on('end', () => resolve(Buffer.concat(data)));
+ }
});
}
From d6f0c785d916660b9347f25bb6e3034989f8432a Mon Sep 17 00:00:00 2001
From: Nathan Reese
Date: Wed, 29 Apr 2020 13:27:55 -0600
Subject: [PATCH 32/33] [Maps] do not display EMS or kibana layer wizards when
not configured (#64554)
* [Maps] do not display EMS or kibana layer wizards when not configured
* default tilemap to empty object instead of array
* fix typo
Co-authored-by: Elastic Machine
---
x-pack/legacy/plugins/maps/index.js | 2 +-
.../plugins/maps/public/layers/layer_wizard_registry.ts | 5 ++++-
.../ems_file_source/ems_boundaries_layer_wizard.tsx | 5 +++++
.../sources/ems_tms_source/ems_base_map_layer_wizard.tsx | 5 +++++
.../kibana_regionmap_layer_wizard.tsx | 6 ++++++
.../kibana_base_map_layer_wizard.tsx | 6 ++++++
x-pack/plugins/maps/public/meta.js | 9 ++++++---
7 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/x-pack/legacy/plugins/maps/index.js b/x-pack/legacy/plugins/maps/index.js
index d1e8892fa2c98..a1186e04ee27a 100644
--- a/x-pack/legacy/plugins/maps/index.js
+++ b/x-pack/legacy/plugins/maps/index.js
@@ -54,7 +54,7 @@ export function maps(kibana) {
emsLandingPageUrl: mapConfig.emsLandingPageUrl,
kbnPkgVersion: serverConfig.get('pkg.version'),
regionmapLayers: _.get(mapConfig, 'regionmap.layers', []),
- tilemap: _.get(mapConfig, 'tilemap', []),
+ tilemap: _.get(mapConfig, 'tilemap', {}),
};
},
styleSheetPaths: `${__dirname}/public/index.scss`,
diff --git a/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts b/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
index 633e8c86d8c94..7715541b1c52d 100644
--- a/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
+++ b/x-pack/plugins/maps/public/layers/layer_wizard_registry.ts
@@ -20,6 +20,7 @@ export type RenderWizardArguments = {
};
export type LayerWizard = {
+ checkVisibility?: () => boolean;
description: string;
icon: string;
isIndexingSource?: boolean;
@@ -34,5 +35,7 @@ export function registerLayerWizard(layerWizard: LayerWizard) {
}
export function getLayerWizards(): LayerWizard[] {
- return [...registry];
+ return registry.filter(layerWizard => {
+ return layerWizard.checkVisibility ? layerWizard.checkVisibility() : true;
+ });
}
diff --git a/x-pack/plugins/maps/public/layers/sources/ems_file_source/ems_boundaries_layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/ems_file_source/ems_boundaries_layer_wizard.tsx
index f31e770df2d95..a6e2e7f42657c 100644
--- a/x-pack/plugins/maps/public/layers/sources/ems_file_source/ems_boundaries_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/layers/sources/ems_file_source/ems_boundaries_layer_wizard.tsx
@@ -12,8 +12,13 @@ import { LayerWizard, RenderWizardArguments } from '../../layer_wizard_registry'
import { EMSFileCreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { EMSFileSource, sourceTitle } from './ems_file_source';
+// @ts-ignore
+import { isEmsEnabled } from '../../../meta';
export const emsBoundariesLayerWizardConfig: LayerWizard = {
+ checkVisibility: () => {
+ return isEmsEnabled();
+ },
description: i18n.translate('xpack.maps.source.emsFileDescription', {
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
}),
diff --git a/x-pack/plugins/maps/public/layers/sources/ems_tms_source/ems_base_map_layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/ems_tms_source/ems_base_map_layer_wizard.tsx
index ced33a0bcf84a..fc745edbabee8 100644
--- a/x-pack/plugins/maps/public/layers/sources/ems_tms_source/ems_base_map_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/layers/sources/ems_tms_source/ems_base_map_layer_wizard.tsx
@@ -12,8 +12,13 @@ import { EMSTMSSource, sourceTitle } from './ems_tms_source';
import { VectorTileLayer } from '../../vector_tile_layer';
// @ts-ignore
import { TileServiceSelect } from './tile_service_select';
+// @ts-ignore
+import { isEmsEnabled } from '../../../meta';
export const emsBaseMapLayerWizardConfig: LayerWizard = {
+ checkVisibility: () => {
+ return isEmsEnabled();
+ },
description: i18n.translate('xpack.maps.source.emsTileDescription', {
defaultMessage: 'Tile map service from Elastic Maps Service',
}),
diff --git a/x-pack/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_layer_wizard.tsx
index 4321501760faf..a9adec2bda2c8 100644
--- a/x-pack/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/layers/sources/kibana_regionmap_source/kibana_regionmap_layer_wizard.tsx
@@ -12,8 +12,14 @@ import { KibanaRegionmapSource, sourceTitle } from './kibana_regionmap_source';
import { VectorLayer } from '../../vector_layer';
// @ts-ignore
import { CreateSourceEditor } from './create_source_editor';
+// @ts-ignore
+import { getKibanaRegionList } from '../../../meta';
export const kibanaRegionMapLayerWizardConfig: LayerWizard = {
+ checkVisibility: () => {
+ const regions = getKibanaRegionList();
+ return regions.length;
+ },
description: i18n.translate('xpack.maps.source.kbnRegionMapDescription', {
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
}),
diff --git a/x-pack/plugins/maps/public/layers/sources/kibana_tilemap_source/kibana_base_map_layer_wizard.tsx b/x-pack/plugins/maps/public/layers/sources/kibana_tilemap_source/kibana_base_map_layer_wizard.tsx
index aeea2d6084f84..141fabeedd3e5 100644
--- a/x-pack/plugins/maps/public/layers/sources/kibana_tilemap_source/kibana_base_map_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/layers/sources/kibana_tilemap_source/kibana_base_map_layer_wizard.tsx
@@ -12,8 +12,14 @@ import { CreateSourceEditor } from './create_source_editor';
// @ts-ignore
import { KibanaTilemapSource, sourceTitle } from './kibana_tilemap_source';
import { TileLayer } from '../../tile_layer';
+// @ts-ignore
+import { getKibanaTileMap } from '../../../meta';
export const kibanaBasemapLayerWizardConfig: LayerWizard = {
+ checkVisibility: () => {
+ const tilemap = getKibanaTileMap();
+ return !!tilemap.url;
+ },
description: i18n.translate('xpack.maps.source.kbnTMSDescription', {
defaultMessage: 'Tile map service configured in kibana.yml',
}),
diff --git a/x-pack/plugins/maps/public/meta.js b/x-pack/plugins/maps/public/meta.js
index d4612554cf00b..c3245e8e98db2 100644
--- a/x-pack/plugins/maps/public/meta.js
+++ b/x-pack/plugins/maps/public/meta.js
@@ -36,12 +36,15 @@ function fetchFunction(...args) {
return fetch(...args);
}
+export function isEmsEnabled() {
+ return getInjectedVarFunc()('isEmsEnabled', true);
+}
+
let emsClient = null;
let latestLicenseId = null;
export function getEMSClient() {
if (!emsClient) {
- const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
- if (isEmsEnabled) {
+ if (isEmsEnabled()) {
const proxyElasticMapsServiceInMaps = getInjectedVarFunc()(
'proxyElasticMapsServiceInMaps',
false
@@ -86,7 +89,7 @@ export function getEMSClient() {
}
export function getGlyphUrl() {
- if (!getInjectedVarFunc()('isEmsEnabled', true)) {
+ if (!isEmsEnabled()) {
return '';
}
return getInjectedVarFunc()('proxyElasticMapsServiceInMaps', false)
From 2e410d8952324efdc43dd60e5470d4db3bd5257f Mon Sep 17 00:00:00 2001
From: spalger
Date: Wed, 29 Apr 2020 12:53:06 -0700
Subject: [PATCH 33/33] skip flaky suite (#64812) (#64723)
---
.../test_suites/event_log/public_api_integration.ts | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts b/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts
index e5b840b335846..d7bbc29bd861e 100644
--- a/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts
+++ b/x-pack/test/plugin_api_integration/test_suites/event_log/public_api_integration.ts
@@ -19,7 +19,9 @@ export default function({ getService }: FtrProviderContext) {
const log = getService('log');
const retry = getService('retry');
- describe('Event Log public API', () => {
+ // FLAKY: https://github.com/elastic/kibana/issues/64723
+ // FLAKY: https://github.com/elastic/kibana/issues/64812
+ describe.skip('Event Log public API', () => {
it('should allow querying for events by Saved Object', async () => {
const id = uuid.v4();