From e67cc8514aa7aeb2e5a54bc1af2a61da19470fe3 Mon Sep 17 00:00:00 2001 From: spalger Date: Thu, 23 Jan 2020 23:32:10 -0700 Subject: [PATCH 01/43] Revert "[csp] allow blob styles when running from source (#54991)" This reverts commit 375f0b42a7b449cc5d0b73f15595f40de8fa998b. --- ...lugin-server.coresetup.getstartservices.md | 34 +++++----- .../server/kibana-plugin-server.coresetup.md | 64 +++++++++---------- ...kibana-plugin-server.cspconfig.default.md} | 6 +- .../server/kibana-plugin-server.cspconfig.md | 2 +- .../server/kibana-plugin-server.icspconfig.md | 1 - ...rver.icspconfig.ruleschangedfromdefault.md | 13 ---- .../src/kbn_client/kbn_client_status.ts | 6 -- packages/kbn-pm/dist/index.js | 4 -- src/core/server/config/env.mock.ts | 29 --------- src/core/server/csp/csp_config.test.ts | 47 ++++++-------- src/core/server/csp/csp_config.ts | 31 ++------- src/core/server/http/http_config.ts | 5 +- src/core/server/http/http_service.mock.ts | 3 +- src/core/server/http/http_service.ts | 2 +- src/core/server/http/http_tools.test.ts | 7 +- src/core/server/legacy/legacy_service.ts | 4 +- src/core/server/mocks.ts | 3 +- src/core/server/server.api.md | 7 +- .../csp_usage_collector/csp_collector.test.ts | 6 +- .../lib/csp_usage_collector/csp_collector.ts | 9 +-- .../status/routes/api/register_status.js | 3 - test/api_integration/apis/general/csp.js | 4 +- .../apis/implicit_flow/oidc_auth.ts | 8 +-- .../apis/security/saml_login.ts | 8 +-- x-pack/test/saml_api_integration/config.ts | 1 - 25 files changed, 96 insertions(+), 211 deletions(-) rename docs/development/core/server/{kibana-plugin-server.cspconfig.ruleschangedfromdefault.md => kibana-plugin-server.cspconfig.default.md} (56%) delete mode 100644 docs/development/core/server/kibana-plugin-server.icspconfig.ruleschangedfromdefault.md delete mode 100644 src/core/server/config/env.mock.ts diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.getstartservices.md b/docs/development/core/server/kibana-plugin-server.coresetup.getstartservices.md index 589529cf2a7f7..b05d28899f9d2 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.getstartservices.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.getstartservices.md @@ -1,17 +1,17 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CoreSetup](./kibana-plugin-server.coresetup.md) > [getStartServices](./kibana-plugin-server.coresetup.getstartservices.md) - -## CoreSetup.getStartServices() method - -Allows plugins to get access to APIs available in start inside async handlers. Promise will not resolve until Core and plugin dependencies have completed `start`. This should only be used inside handlers registered during `setup` that will only be executed after `start` lifecycle. - -Signature: - -```typescript -getStartServices(): Promise<[CoreStart, TPluginsStart]>; -``` -Returns: - -`Promise<[CoreStart, TPluginsStart]>` - + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CoreSetup](./kibana-plugin-server.coresetup.md) > [getStartServices](./kibana-plugin-server.coresetup.getstartservices.md) + +## CoreSetup.getStartServices() method + +Allows plugins to get access to APIs available in start inside async handlers. Promise will not resolve until Core and plugin dependencies have completed `start`. This should only be used inside handlers registered during `setup` that will only be executed after `start` lifecycle. + +Signature: + +```typescript +getStartServices(): Promise<[CoreStart, TPluginsStart]>; +``` +Returns: + +`Promise<[CoreStart, TPluginsStart]>` + diff --git a/docs/development/core/server/kibana-plugin-server.coresetup.md b/docs/development/core/server/kibana-plugin-server.coresetup.md index 325f7216122b5..c36d649837e8a 100644 --- a/docs/development/core/server/kibana-plugin-server.coresetup.md +++ b/docs/development/core/server/kibana-plugin-server.coresetup.md @@ -1,32 +1,32 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CoreSetup](./kibana-plugin-server.coresetup.md) - -## CoreSetup interface - -Context passed to the plugins `setup` method. - -Signature: - -```typescript -export interface CoreSetup -``` - -## Properties - -| Property | Type | Description | -| --- | --- | --- | -| [capabilities](./kibana-plugin-server.coresetup.capabilities.md) | CapabilitiesSetup | [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | -| [context](./kibana-plugin-server.coresetup.context.md) | ContextSetup | [ContextSetup](./kibana-plugin-server.contextsetup.md) | -| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | ElasticsearchServiceSetup | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | -| [http](./kibana-plugin-server.coresetup.http.md) | HttpServiceSetup | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | -| [savedObjects](./kibana-plugin-server.coresetup.savedobjects.md) | SavedObjectsServiceSetup | [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) | -| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | UiSettingsServiceSetup | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | -| [uuid](./kibana-plugin-server.coresetup.uuid.md) | UuidServiceSetup | [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) | - -## Methods - -| Method | Description | -| --- | --- | -| [getStartServices()](./kibana-plugin-server.coresetup.getstartservices.md) | Allows plugins to get access to APIs available in start inside async handlers. Promise will not resolve until Core and plugin dependencies have completed start. This should only be used inside handlers registered during setup that will only be executed after start lifecycle. | - + + +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CoreSetup](./kibana-plugin-server.coresetup.md) + +## CoreSetup interface + +Context passed to the plugins `setup` method. + +Signature: + +```typescript +export interface CoreSetup +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [capabilities](./kibana-plugin-server.coresetup.capabilities.md) | CapabilitiesSetup | [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | +| [context](./kibana-plugin-server.coresetup.context.md) | ContextSetup | [ContextSetup](./kibana-plugin-server.contextsetup.md) | +| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | ElasticsearchServiceSetup | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) | +| [http](./kibana-plugin-server.coresetup.http.md) | HttpServiceSetup | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) | +| [savedObjects](./kibana-plugin-server.coresetup.savedobjects.md) | SavedObjectsServiceSetup | [SavedObjectsServiceSetup](./kibana-plugin-server.savedobjectsservicesetup.md) | +| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | UiSettingsServiceSetup | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | +| [uuid](./kibana-plugin-server.coresetup.uuid.md) | UuidServiceSetup | [UuidServiceSetup](./kibana-plugin-server.uuidservicesetup.md) | + +## Methods + +| Method | Description | +| --- | --- | +| [getStartServices()](./kibana-plugin-server.coresetup.getstartservices.md) | Allows plugins to get access to APIs available in start inside async handlers. Promise will not resolve until Core and plugin dependencies have completed start. This should only be used inside handlers registered during setup that will only be executed after start lifecycle. | + diff --git a/docs/development/core/server/kibana-plugin-server.cspconfig.ruleschangedfromdefault.md b/docs/development/core/server/kibana-plugin-server.cspconfig.default.md similarity index 56% rename from docs/development/core/server/kibana-plugin-server.cspconfig.ruleschangedfromdefault.md rename to docs/development/core/server/kibana-plugin-server.cspconfig.default.md index 3320785935b21..56e6cf35cdd13 100644 --- a/docs/development/core/server/kibana-plugin-server.cspconfig.ruleschangedfromdefault.md +++ b/docs/development/core/server/kibana-plugin-server.cspconfig.default.md @@ -1,11 +1,11 @@ -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [rulesChangedFromDefault](./kibana-plugin-server.cspconfig.ruleschangedfromdefault.md) +[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [CspConfig](./kibana-plugin-server.cspconfig.md) > [DEFAULT](./kibana-plugin-server.cspconfig.default.md) -## CspConfig.rulesChangedFromDefault property +## CspConfig.DEFAULT property Signature: ```typescript -readonly rulesChangedFromDefault: boolean; +static readonly DEFAULT: CspConfig; ``` diff --git a/docs/development/core/server/kibana-plugin-server.cspconfig.md b/docs/development/core/server/kibana-plugin-server.cspconfig.md index 6f12d64676ce9..7e491cb0df912 100644 --- a/docs/development/core/server/kibana-plugin-server.cspconfig.md +++ b/docs/development/core/server/kibana-plugin-server.cspconfig.md @@ -20,9 +20,9 @@ The constructor for this class is marked as internal. Third-party code should no | Property | Modifiers | Type | Description | | --- | --- | --- | --- | +| [DEFAULT](./kibana-plugin-server.cspconfig.default.md) | static | CspConfig | | | [header](./kibana-plugin-server.cspconfig.header.md) | | string | | | [rules](./kibana-plugin-server.cspconfig.rules.md) | | string[] | | -| [rulesChangedFromDefault](./kibana-plugin-server.cspconfig.ruleschangedfromdefault.md) | | boolean | | | [strict](./kibana-plugin-server.cspconfig.strict.md) | | boolean | | | [warnLegacyBrowsers](./kibana-plugin-server.cspconfig.warnlegacybrowsers.md) | | boolean | | diff --git a/docs/development/core/server/kibana-plugin-server.icspconfig.md b/docs/development/core/server/kibana-plugin-server.icspconfig.md index 00107d561873f..fb8188386a376 100644 --- a/docs/development/core/server/kibana-plugin-server.icspconfig.md +++ b/docs/development/core/server/kibana-plugin-server.icspconfig.md @@ -18,7 +18,6 @@ export interface ICspConfig | --- | --- | --- | | [header](./kibana-plugin-server.icspconfig.header.md) | string | The CSP rules in a formatted directives string for use in a Content-Security-Policy header. | | [rules](./kibana-plugin-server.icspconfig.rules.md) | string[] | The CSP rules used for Kibana. | -| [rulesChangedFromDefault](./kibana-plugin-server.icspconfig.ruleschangedfromdefault.md) | boolean | Flag indicating that the configuraion changes the csp rules from the defaults | | [strict](./kibana-plugin-server.icspconfig.strict.md) | boolean | Specify whether browsers that do not support CSP should be able to use Kibana. Use true to block and false to allow. | | [warnLegacyBrowsers](./kibana-plugin-server.icspconfig.warnlegacybrowsers.md) | boolean | Specify whether users with legacy browsers should be warned about their lack of Kibana security compliance. | diff --git a/docs/development/core/server/kibana-plugin-server.icspconfig.ruleschangedfromdefault.md b/docs/development/core/server/kibana-plugin-server.icspconfig.ruleschangedfromdefault.md deleted file mode 100644 index 427c07d2d1e4d..0000000000000 --- a/docs/development/core/server/kibana-plugin-server.icspconfig.ruleschangedfromdefault.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-server](./kibana-plugin-server.md) > [ICspConfig](./kibana-plugin-server.icspconfig.md) > [rulesChangedFromDefault](./kibana-plugin-server.icspconfig.ruleschangedfromdefault.md) - -## ICspConfig.rulesChangedFromDefault property - -Flag indicating that the configuraion changes the csp rules from the defaults - -Signature: - -```typescript -readonly rulesChangedFromDefault: boolean; -``` diff --git a/packages/kbn-dev-utils/src/kbn_client/kbn_client_status.ts b/packages/kbn-dev-utils/src/kbn_client/kbn_client_status.ts index 3775aecb2db09..22baf4a330416 100644 --- a/packages/kbn-dev-utils/src/kbn_client/kbn_client_status.ts +++ b/packages/kbn-dev-utils/src/kbn_client/kbn_client_status.ts @@ -32,7 +32,6 @@ interface Status { interface ApiResponseStatus { name: string; uuid: string; - running_from_source?: true; version: { number: string; build_hash: string; @@ -59,11 +58,6 @@ export class KbnClientStatus { }); } - public async isDistributable() { - const status = await this.get(); - return !status.running_from_source; - } - /** * Get the overall/merged state */ diff --git a/packages/kbn-pm/dist/index.js b/packages/kbn-pm/dist/index.js index 364b91a30841c..8bded9d403c21 100644 --- a/packages/kbn-pm/dist/index.js +++ b/packages/kbn-pm/dist/index.js @@ -43639,10 +43639,6 @@ class KbnClientStatus { path: 'api/status', }); } - async isDistributable() { - const status = await this.get(); - return !status.running_from_source; - } /** * Get the overall/merged state */ diff --git a/src/core/server/config/env.mock.ts b/src/core/server/config/env.mock.ts deleted file mode 100644 index f9b4e0732c1cb..0000000000000 --- a/src/core/server/config/env.mock.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 { Env } from './env'; - -export function createMockEnv(options: { dist?: boolean } = {}): Env { - return { - // required by CspConfig - packageInfo: { - dist: options.dist ?? true, - }, - } as any; -} diff --git a/src/core/server/csp/csp_config.test.ts b/src/core/server/csp/csp_config.test.ts index 15cddc6fccd34..45fa8445791b0 100644 --- a/src/core/server/csp/csp_config.test.ts +++ b/src/core/server/csp/csp_config.test.ts @@ -18,7 +18,6 @@ */ import { CspConfig } from '.'; -import { createMockEnv } from '../config/env.mock'; // CSP rules aren't strictly additive, so any change can potentially expand or // restrict the policy in a way we consider a breaking change. For that reason, @@ -34,10 +33,23 @@ import { createMockEnv } from '../config/env.mock'; // the nature of a change in defaults during a PR review. describe('CspConfig', () => { - test('defaults from config', () => { - const cspConfig = new CspConfig(createMockEnv()); + test('DEFAULT', () => { + expect(CspConfig.DEFAULT).toMatchInlineSnapshot(` + CspConfig { + "header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", + "rules": Array [ + "script-src 'unsafe-eval' 'self'", + "worker-src blob: 'self'", + "style-src 'unsafe-inline' 'self'", + ], + "strict": true, + "warnLegacyBrowsers": true, + } + `); + }); - expect(cspConfig).toMatchInlineSnapshot(` + test('defaults from config', () => { + expect(new CspConfig()).toMatchInlineSnapshot(` CspConfig { "header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", "rules": Array [ @@ -45,7 +57,6 @@ describe('CspConfig', () => { "worker-src blob: 'self'", "style-src 'unsafe-inline' 'self'", ], - "rulesChangedFromDefault": false, "strict": true, "warnLegacyBrowsers": true, } @@ -53,9 +64,7 @@ describe('CspConfig', () => { }); test('creates from partial config', () => { - const cspConfig = new CspConfig(createMockEnv(), { strict: false, warnLegacyBrowsers: false }); - - expect(cspConfig).toMatchInlineSnapshot(` + expect(new CspConfig({ strict: false, warnLegacyBrowsers: false })).toMatchInlineSnapshot(` CspConfig { "header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'", "rules": Array [ @@ -63,7 +72,6 @@ describe('CspConfig', () => { "worker-src blob: 'self'", "style-src 'unsafe-inline' 'self'", ], - "rulesChangedFromDefault": false, "strict": false, "warnLegacyBrowsers": false, } @@ -71,7 +79,7 @@ describe('CspConfig', () => { }); test('computes header from rules', () => { - const cspConfig = new CspConfig(createMockEnv(), { rules: ['alpha', 'beta', 'gamma'] }); + const cspConfig = new CspConfig({ rules: ['alpha', 'beta', 'gamma'] }); expect(cspConfig).toMatchInlineSnapshot(` CspConfig { @@ -81,25 +89,6 @@ describe('CspConfig', () => { "beta", "gamma", ], - "rulesChangedFromDefault": true, - "strict": true, - "warnLegacyBrowsers": true, - } - `); - }); - - test(`includes blob: style-src if env indicates we're running from source`, () => { - const cspConfig = new CspConfig(createMockEnv({ dist: false })); - - expect(cspConfig).toMatchInlineSnapshot(` - CspConfig { - "header": "script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src blob: 'unsafe-inline' 'self'", - "rules": Array [ - "script-src 'unsafe-eval' 'self'", - "worker-src blob: 'self'", - "style-src blob: 'unsafe-inline' 'self'", - ], - "rulesChangedFromDefault": false, "strict": true, "warnLegacyBrowsers": true, } diff --git a/src/core/server/csp/csp_config.ts b/src/core/server/csp/csp_config.ts index 592a7209f4364..bb57702a4a241 100644 --- a/src/core/server/csp/csp_config.ts +++ b/src/core/server/csp/csp_config.ts @@ -18,7 +18,6 @@ */ import { config } from './config'; -import { Env } from '../config'; const DEFAULT_CONFIG = Object.freeze(config.schema.validate({})); @@ -49,12 +48,6 @@ export interface ICspConfig { * in a `Content-Security-Policy` header. */ readonly header: string; - - /** - * Flag indicating that the configuraion changes the csp - * rules from the defaults - */ - readonly rulesChangedFromDefault: boolean; } /** @@ -62,37 +55,23 @@ export interface ICspConfig { * @public */ export class CspConfig implements ICspConfig { + static readonly DEFAULT = new CspConfig(); + public readonly rules: string[]; public readonly strict: boolean; public readonly warnLegacyBrowsers: boolean; public readonly header: string; - public readonly rulesChangedFromDefault: boolean; /** * Returns the default CSP configuration when passed with no config * @internal */ - constructor(env: Env, rawCspConfig?: Partial>) { + constructor(rawCspConfig: Partial> = {}) { const source = { ...DEFAULT_CONFIG, ...rawCspConfig }; - this.rules = source.rules.map(rule => { - // if we receive an env, and it indicates that this isn't a distributable, add `blob:` to the style csp rules - if (env && !env.packageInfo.dist && rule.startsWith('style-src ')) { - return rule.replace(/^style-src /, 'style-src blob: '); - } - - return rule; - }); + this.rules = source.rules; this.strict = source.strict; this.warnLegacyBrowsers = source.warnLegacyBrowsers; - this.header = this.rules.join('; '); - - // only check to see if the csp values are customized when `rawCspConfig` was received. - if (!rawCspConfig) { - this.rulesChangedFromDefault = false; - } else { - const defaultCsp = new CspConfig(env); - this.rulesChangedFromDefault = defaultCsp.header !== this.header; - } + this.header = source.rules.join('; '); } } diff --git a/src/core/server/http/http_config.ts b/src/core/server/http/http_config.ts index b249dbb5b6a04..73f44f3c5ab5c 100644 --- a/src/core/server/http/http_config.ts +++ b/src/core/server/http/http_config.ts @@ -22,7 +22,6 @@ import { hostname } from 'os'; import { CspConfigType, CspConfig, ICspConfig } from '../csp'; import { SslConfig, sslSchema } from './ssl_config'; -import { Env } from '../config'; const validBasePathRegex = /(^$|^\/.*[^\/]$)/; const uuidRegexp = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i; @@ -149,7 +148,7 @@ export class HttpConfig { /** * @internal */ - constructor(rawHttpConfig: HttpConfigType, rawCspConfig: CspConfigType, env: Env) { + constructor(rawHttpConfig: HttpConfigType, rawCspConfig: CspConfigType) { this.autoListen = rawHttpConfig.autoListen; this.host = rawHttpConfig.host; this.port = rawHttpConfig.port; @@ -163,7 +162,7 @@ export class HttpConfig { this.rewriteBasePath = rawHttpConfig.rewriteBasePath; this.ssl = new SslConfig(rawHttpConfig.ssl || {}); this.compression = rawHttpConfig.compression; - this.csp = new CspConfig(env, rawCspConfig); + this.csp = new CspConfig(rawCspConfig); this.xsrf = rawHttpConfig.xsrf; } } diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts index 7fc2f5d990824..6db1ca80ab437 100644 --- a/src/core/server/http/http_service.mock.ts +++ b/src/core/server/http/http_service.mock.ts @@ -21,7 +21,6 @@ import { Server } from 'hapi'; import { CspConfig } from '../csp'; import { mockRouter } from './router/router.mock'; import { configMock } from '../config/config.mock'; -import { createMockEnv } from '../config/env.mock'; import { InternalHttpServiceSetup } from './types'; import { HttpService } from './http_service'; import { OnPreAuthToolkit } from './lifecycle/on_pre_auth'; @@ -62,7 +61,7 @@ const createSetupContractMock = () => { registerOnPreResponse: jest.fn(), createRouter: jest.fn().mockImplementation(() => mockRouter.create({})), basePath: createBasePathMock(), - csp: new CspConfig(createMockEnv()), + csp: CspConfig.DEFAULT, auth: { get: jest.fn(), isAuthenticated: jest.fn(), diff --git a/src/core/server/http/http_service.ts b/src/core/server/http/http_service.ts index 8a86667a1a6bc..ae9d53f9fd3db 100644 --- a/src/core/server/http/http_service.ts +++ b/src/core/server/http/http_service.ts @@ -70,7 +70,7 @@ export class HttpService implements CoreService(httpConfig.path), configService.atPath(cspConfig.path), - ]).pipe(map(([http, csp]) => new HttpConfig(http, csp, env))); + ]).pipe(map(([http, csp]) => new HttpConfig(http, csp))); this.httpServer = new HttpServer(logger, 'Kibana'); this.httpsRedirectServer = new HttpsRedirectServer(logger.get('http', 'redirect', 'server')); } diff --git a/src/core/server/http/http_tools.test.ts b/src/core/server/http/http_tools.test.ts index d552339f1ea1c..c1322a5aa94db 100644 --- a/src/core/server/http/http_tools.test.ts +++ b/src/core/server/http/http_tools.test.ts @@ -29,7 +29,6 @@ import { defaultValidationErrorHandler, HapiValidationError, getServerOptions } import { HttpServer } from './http_server'; import { HttpConfig, config } from './http_config'; import { Router } from './router'; -import { createMockEnv } from '../config/env.mock'; import { loggingServiceMock } from '../logging/logging_service.mock'; import { ByteSizeValue } from '@kbn/config-schema'; @@ -121,8 +120,7 @@ describe('getServerOptions', () => { certificate: 'some-certificate-path', }, }), - {} as any, - createMockEnv() + {} as any ); expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(` @@ -151,8 +149,7 @@ describe('getServerOptions', () => { clientAuthentication: 'required', }, }), - {} as any, - createMockEnv() + {} as any ); expect(getServerOptions(httpConfig).tls).toMatchInlineSnapshot(` diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts index ca1204f0ac05c..0cb717e3832aa 100644 --- a/src/core/server/legacy/legacy_service.ts +++ b/src/core/server/legacy/legacy_service.ts @@ -86,7 +86,7 @@ export class LegacyService implements CoreService { public legacyInternals?: ILegacyInternals; constructor(private readonly coreContext: CoreContext) { - const { logger, configService, env } = coreContext; + const { logger, configService } = coreContext; this.log = logger.get('legacy-service'); this.devConfig$ = configService @@ -95,7 +95,7 @@ export class LegacyService implements CoreService { this.httpConfig$ = combineLatest( configService.atPath(httpConfig.path), configService.atPath(cspConfig.path) - ).pipe(map(([http, csp]) => new HttpConfig(http, csp, env))); + ).pipe(map(([http, csp]) => new HttpConfig(http, csp))); } public async discoverPlugins(): Promise { diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 846c2e4d8c507..c0a8973d98a54 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -33,7 +33,6 @@ import { capabilitiesServiceMock } from './capabilities/capabilities_service.moc export { httpServerMock } from './http/http_server.mocks'; export { sessionStorageMock } from './http/cookie_session_storage.mocks'; export { configServiceMock } from './config/config_service.mock'; -import { createMockEnv } from './config/env.mock'; export { elasticsearchServiceMock } from './elasticsearch/elasticsearch_service.mock'; export { httpServiceMock } from './http/http_service.mock'; export { loggingServiceMock } from './logging/logging_service.mock'; @@ -98,7 +97,7 @@ function createCoreSetupMock() { registerOnPostAuth: httpService.registerOnPostAuth, registerOnPreResponse: httpService.registerOnPreResponse, basePath: httpService.basePath, - csp: new CspConfig(createMockEnv()), + csp: CspConfig.DEFAULT, isTlsEnabled: httpService.isTlsEnabled, createRouter: jest.fn(), registerRouteHandlerContext: jest.fn(), diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 629e6a881199b..a179e1f35a937 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -583,14 +583,14 @@ export interface CoreStart { // @public export class CspConfig implements ICspConfig { // @internal - constructor(env: Env, rawCspConfig?: Partial>); + constructor(rawCspConfig?: Partial>); + // (undocumented) + static readonly DEFAULT: CspConfig; // (undocumented) readonly header: string; // (undocumented) readonly rules: string[]; // (undocumented) - readonly rulesChangedFromDefault: boolean; - // (undocumented) readonly strict: boolean; // (undocumented) readonly warnLegacyBrowsers: boolean; @@ -774,7 +774,6 @@ export type IContextProvider, TContextName export interface ICspConfig { readonly header: string; readonly rules: string[]; - readonly rulesChangedFromDefault: boolean; readonly strict: boolean; readonly warnLegacyBrowsers: boolean; } diff --git a/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.test.ts b/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.test.ts index 584621a1ce13f..395cb60587832 100644 --- a/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.test.ts +++ b/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.test.ts @@ -18,8 +18,6 @@ */ import { CspConfig, ICspConfig } from '../../../../../../core/server'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { createMockEnv } from '../../../../../../core/server/config/env.mock'; import { createCspCollector } from './csp_collector'; const createMockKbnServer = () => ({ @@ -27,7 +25,7 @@ const createMockKbnServer = () => ({ setup: { core: { http: { - csp: new CspConfig(createMockEnv()), + csp: new CspConfig(), }, }, }, @@ -38,7 +36,7 @@ describe('csp collector', () => { let kbnServer: ReturnType; function updateCsp(config: Partial) { - kbnServer.newPlatform.setup.core.http.csp = new CspConfig(createMockEnv(), config); + kbnServer.newPlatform.setup.core.http.csp = new CspConfig(config); } beforeEach(() => { diff --git a/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.ts b/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.ts index dce4c7fe6fefc..6622ed4bef478 100644 --- a/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.ts +++ b/src/legacy/core_plugins/kibana/server/lib/csp_usage_collector/csp_collector.ts @@ -18,6 +18,7 @@ */ import { Server } from 'hapi'; +import { CspConfig } from '../../../../../../core/server'; import { UsageCollectionSetup } from '../../../../../../plugins/usage_collection/server'; export function createCspCollector(server: Server) { @@ -25,11 +26,7 @@ export function createCspCollector(server: Server) { type: 'csp', isReady: () => true, async fetch() { - const { - strict, - warnLegacyBrowsers, - rulesChangedFromDefault, - } = server.newPlatform.setup.core.http.csp; + const { strict, warnLegacyBrowsers, header } = server.newPlatform.setup.core.http.csp; return { strict, @@ -37,7 +34,7 @@ export function createCspCollector(server: Server) { // It's important that we do not send the value of csp.header here as it // can be customized with values that can be identifiable to given // installs, such as URLs - rulesChangedFromDefault, + rulesChangedFromDefault: header !== CspConfig.DEFAULT.header, }; }, }; diff --git a/src/legacy/server/status/routes/api/register_status.js b/src/legacy/server/status/routes/api/register_status.js index 55bf81f2c5f9a..259a00667810f 100644 --- a/src/legacy/server/status/routes/api/register_status.js +++ b/src/legacy/server/status/routes/api/register_status.js @@ -18,7 +18,6 @@ */ import { wrapAuthConfig } from '../../wrap_auth_config'; -import { IS_KIBANA_DISTRIBUTABLE } from '../../../../utils/artifact_type'; const matchSnapshot = /-SNAPSHOT$/; @@ -36,8 +35,6 @@ export function registerStatusApi(kbnServer, server, config) { return { name: config.get('server.name'), uuid: config.get('server.uuid'), - // flag to help tests know that kibana is running from source, not included in distributable response - ...(IS_KIBANA_DISTRIBUTABLE ? {} : { running_from_source: true }), version: { number: config.get('pkg.version').replace(matchSnapshot, ''), build_hash: config.get('pkg.buildSha'), diff --git a/test/api_integration/apis/general/csp.js b/test/api_integration/apis/general/csp.js index 38893c371fb52..8c191703070d8 100644 --- a/test/api_integration/apis/general/csp.js +++ b/test/api_integration/apis/general/csp.js @@ -21,7 +21,6 @@ import expect from '@kbn/expect'; export default function({ getService }) { const supertest = getService('supertest'); - const kibanaServer = getService('kibanaServer'); describe('csp smoke test', () => { it('app response sends content security policy headers', async () => { @@ -37,12 +36,11 @@ export default function({ getService }) { }) ); - const isDist = await kibanaServer.status.isDistributable(); const entries = Array.from(parsed.entries()); expect(entries).to.eql([ ['script-src', ["'unsafe-eval'", "'self'"]], ['worker-src', ['blob:', "'self'"]], - ['style-src', [...(isDist ? [] : ['blob:']), "'unsafe-inline'", "'self'"]], + ['style-src', ["'unsafe-inline'", "'self'"]], ]); }); }); diff --git a/x-pack/test/oidc_api_integration/apis/implicit_flow/oidc_auth.ts b/x-pack/test/oidc_api_integration/apis/implicit_flow/oidc_auth.ts index 87979ca643a19..1f5a64835416a 100644 --- a/x-pack/test/oidc_api_integration/apis/implicit_flow/oidc_auth.ts +++ b/x-pack/test/oidc_api_integration/apis/implicit_flow/oidc_auth.ts @@ -15,7 +15,6 @@ import { FtrProviderContext } from '../../ftr_provider_context'; export default function({ getService }: FtrProviderContext) { const supertest = getService('supertestWithoutAuth'); const config = getService('config'); - const kibanaServer = getService('kibanaServer'); describe('OpenID Connect Implicit Flow authentication', () => { describe('finishing handshake', () => { @@ -57,17 +56,12 @@ export default function({ getService }: FtrProviderContext) { }); await (dom.window as Record).__isScriptExecuted__; - const isDist = await kibanaServer.status.isDistributable(); // Check that proxy page is returned with proper headers. expect(response.headers['content-type']).to.be('text/html; charset=utf-8'); expect(response.headers['cache-control']).to.be('private, no-cache, no-store'); expect(response.headers['content-security-policy']).to.be( - [ - `script-src 'unsafe-eval' 'self';`, - `worker-src blob: 'self';`, - `style-src ${isDist ? '' : 'blob: '}'unsafe-inline' 'self'`, - ].join(' ') + `script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'` ); // Check that script that forwards URL fragment worked correctly. diff --git a/x-pack/test/saml_api_integration/apis/security/saml_login.ts b/x-pack/test/saml_api_integration/apis/security/saml_login.ts index d4de4d601a36c..0436d59906ea8 100644 --- a/x-pack/test/saml_api_integration/apis/security/saml_login.ts +++ b/x-pack/test/saml_api_integration/apis/security/saml_login.ts @@ -17,7 +17,6 @@ export default function({ getService }: FtrProviderContext) { const randomness = getService('randomness'); const supertest = getService('supertestWithoutAuth'); const config = getService('config'); - const kibanaServer = getService('kibanaServer'); const kibanaServerConfig = config.get('servers.kibana'); @@ -138,17 +137,12 @@ export default function({ getService }: FtrProviderContext) { }); await (dom.window as Record).__isScriptExecuted__; - const isDist = await kibanaServer.status.isDistributable(); // Check that proxy page is returned with proper headers. expect(response.headers['content-type']).to.be('text/html; charset=utf-8'); expect(response.headers['cache-control']).to.be('private, no-cache, no-store'); expect(response.headers['content-security-policy']).to.be( - [ - `script-src 'unsafe-eval' 'self';`, - `worker-src blob: 'self';`, - `style-src ${isDist ? '' : 'blob: '}'unsafe-inline' 'self'`, - ].join(' ') + `script-src 'unsafe-eval' 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'` ); // Check that script that forwards URL fragment worked correctly. diff --git a/x-pack/test/saml_api_integration/config.ts b/x-pack/test/saml_api_integration/config.ts index 1d83f374e966c..6ea29b0d9e56e 100644 --- a/x-pack/test/saml_api_integration/config.ts +++ b/x-pack/test/saml_api_integration/config.ts @@ -20,7 +20,6 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) { testFiles: [require.resolve('./apis')], servers: xPackAPITestsConfig.get('servers'), services: { - kibanaServer: kibanaAPITestsConfig.get('services.kibanaServer'), randomness: kibanaAPITestsConfig.get('services.randomness'), legacyEs: kibanaAPITestsConfig.get('services.legacyEs'), supertestWithoutAuth: xPackAPITestsConfig.get('services.supertestWithoutAuth'), From 2f1628784ab42372b93b8cab320d26c8baa9a9d0 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Fri, 24 Jan 2020 07:54:06 +0100 Subject: [PATCH 02/43] [NP] add platform main principles (#53866) * add platform main principles * update docs * unify styles * remove guidelines. principles should cover this * Apply suggestions from code review Co-Authored-By: Josh Dover * Apply suggestions from code review Co-Authored-By: Rudolf Meijering * address comments Co-authored-by: Josh Dover Co-authored-by: Rudolf Meijering --- src/core/PRINCIPLES.md | 47 ++++++++++++++++++++++++++++++++++++++++++ src/core/TESTING.md | 5 ----- 2 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 src/core/PRINCIPLES.md diff --git a/src/core/PRINCIPLES.md b/src/core/PRINCIPLES.md new file mode 100644 index 0000000000000..fa832a59a3b12 --- /dev/null +++ b/src/core/PRINCIPLES.md @@ -0,0 +1,47 @@ +## Common dictionary +Plugin - a piece of software expressing specific subject of the business unit within the code. + +Platform - functionality required to run all the Kibana plugins. + +## New platform principles +### Explicit business domains separation +The plugins code should be structured on the top level to reflect business units. +```js +// GOOD +src/plugins + - apm + - server + - public + - search + .. +// BAD +src/plugins + - server + - apm + - search +``` +### Explicit dependencies +Each plugin should declare dependencies on the other plugins explicitly. Plugins cannot have circular dependencies. Plugins shouldn't access runtime objects, HTTP endpoints, DOM nodes, etc. created by a third party plugin without declaring a dependency on this plugin. +```json +"requiredPlugins": ["search"], +"optionalPlugins": ["apm"], +``` +### Explicit API declaration +Each plugin has to define an explicit API. Any other API's that has not been declared explicitly as public should be considered private. HTTP endpoints belonging to other plugins are considered private. Plugins should expose a JavaScript client on top of these HTTP endpoints for other plugins to consume. +```js +// GOOD +deps.plugin.getData(); +// BAD. +`GET /api/plugin/data` +``` +### Encapsulated state +Each plugin encapsulates its internal state. It doesn't rely on any kind of global state. Plugins provide an internal state via explicit API, reflecting the dynamic nature of the state (an event bus, observables, getter/setter functions). A plugin can change other plugin state by calling its public API method. +```js +// GOOD +deps.plugin.getData(); +deps.plugin.data$.subscribe(); +deps.plugin.setAddress('...'); +// BAD. +deps.plugin._data; +deps.plugin.data = '...'; +``` diff --git a/src/core/TESTING.md b/src/core/TESTING.md index 6139820d02a14..467110b3874b8 100644 --- a/src/core/TESTING.md +++ b/src/core/TESTING.md @@ -247,8 +247,3 @@ _How to test against specific plugin APIs (eg. data plugin)_ ## Plugin Contracts _How to test your plugin's exposed API_ - -Guidelines: -- Plugins should never interact with other plugins' REST API directly -- Plugins should interact with other plugins via JavaScript contracts -- Exposed contracts need to be well tested to ensure breaking changes are detected easily From 14a559bfc45f48c6104012f6b68d5a793396d574 Mon Sep 17 00:00:00 2001 From: Maryia Lapata Date: Fri, 24 Jan 2020 10:45:46 +0300 Subject: [PATCH 03/43] [Discover] DocViews uses local angular (#55389) * DocViews uses local angular * Clean up * Create embeddableInjector only when it's used * Revert occasional changes * Update unit test Co-authored-by: Elastic Machine --- .../kibana/public/discover/kibana_services.ts | 1 - .../kibana/public/discover/legacy.ts | 7 +-- .../np_ready/doc_views/doc_views_helpers.tsx | 23 +++++---- .../np_ready/doc_views/doc_views_registry.ts | 7 +-- .../np_ready/doc_views/doc_views_types.ts | 2 - .../embeddable/search_embeddable_factory.ts | 12 +++-- .../kibana/public/discover/plugin.ts | 48 ++++++++++++------- 7 files changed, 54 insertions(+), 46 deletions(-) diff --git a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts index d2eefba2cecdd..eb39bdd3ad84b 100644 --- a/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/discover/kibana_services.ts @@ -99,6 +99,5 @@ export { } from '../../../../../plugins/data/public'; export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types'; export { Adapters } from 'ui/inspector/types'; -export { Chrome, IInjector } from 'ui/chrome'; export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router'; export { FieldName } from 'ui/directives/field_name/field_name'; diff --git a/src/legacy/core_plugins/kibana/public/discover/legacy.ts b/src/legacy/core_plugins/kibana/public/discover/legacy.ts index 2ec64177156f9..ff44fbbe115d5 100644 --- a/src/legacy/core_plugins/kibana/public/discover/legacy.ts +++ b/src/legacy/core_plugins/kibana/public/discover/legacy.ts @@ -16,17 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -import chrome from 'ui/chrome'; + import { PluginInitializerContext } from 'kibana/public'; import { npSetup, npStart } from 'ui/new_platform'; import { plugin } from './index'; -// Legacy compatiblity part - to be removed at cutover, replaced by a kibana.json file +// Legacy compatibility part - to be removed at cutover, replaced by a kibana.json file export const pluginInstance = plugin({} as PluginInitializerContext); export const setup = pluginInstance.setup(npSetup.core, { ...npSetup.plugins, - __LEGACY: { - chrome, - }, }); export const start = pluginInstance.start(npStart.core, npStart.plugins); diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx index fb4f0c6056a83..b9932da0523f8 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_helpers.tsx @@ -16,17 +16,13 @@ * specific language governing permissions and limitations * under the License. */ + +import { auto, IController } from 'angular'; import React from 'react'; import { render } from 'react-dom'; import angular, { ICompileService } from 'angular'; -import { - DocViewRenderProps, - AngularScope, - AngularController, - AngularDirective, -} from './doc_views_types'; +import { DocViewRenderProps, AngularScope, AngularDirective } from './doc_views_types'; import { DocViewerError } from '../components/doc_viewer/doc_viewer_render_error'; -import { Chrome } from '../../kibana_services'; /** * Compiles and injects the give angular template into the given dom node @@ -36,10 +32,10 @@ export async function injectAngularElement( domNode: Element, template: string, scopeProps: DocViewRenderProps, - Controller: AngularController, - chrome: Chrome + Controller: IController, + getInjector: () => Promise ): Promise<() => void> { - const $injector = await chrome.dangerouslyGetActiveInjector(); + const $injector = await getInjector(); const rootScope: AngularScope = $injector.get('$rootScope'); const $compile: ICompileService = $injector.get('$compile'); const newScope = Object.assign(rootScope.$new(), scopeProps); @@ -69,7 +65,10 @@ export async function injectAngularElement( * Converts a given legacy angular directive to a render function * for usage in a react component. Note that the rendering is async */ -export function convertDirectiveToRenderFn(directive: AngularDirective, chrome: Chrome) { +export function convertDirectiveToRenderFn( + directive: AngularDirective, + getInjector: () => Promise +) { return (domNode: Element, props: DocViewRenderProps) => { let rejected = false; @@ -78,7 +77,7 @@ export function convertDirectiveToRenderFn(directive: AngularDirective, chrome: directive.template, props, directive.controller, - chrome + getInjector ); cleanupFnPromise.catch(e => { rejected = true; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts index 1952ec3af2f6c..91acf1c7ac4ae 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_registry.ts @@ -16,14 +16,15 @@ * specific language governing permissions and limitations * under the License. */ + +import { auto } from 'angular'; import { convertDirectiveToRenderFn } from './doc_views_helpers'; import { DocView, DocViewInput, ElasticSearchHit, DocViewInputFn } from './doc_views_types'; -import { Chrome } from '../../kibana_services'; export class DocViewsRegistry { private docViews: DocView[] = []; - constructor(private legacyChrome: Chrome) {} + constructor(private getInjector: () => Promise) {} /** * Extends and adds the given doc view to the registry array @@ -32,7 +33,7 @@ export class DocViewsRegistry { const docView = typeof docViewRaw === 'function' ? docViewRaw() : docViewRaw; if (docView.directive) { // convert angular directive to render function for backwards compatibility - docView.render = convertDirectiveToRenderFn(docView.directive, this.legacyChrome); + docView.render = convertDirectiveToRenderFn(docView.directive, this.getInjector); } if (typeof docView.shouldShow !== 'function') { docView.shouldShow = () => true; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts index 92e18e7ea7b88..a7828f9f0e7ed 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/doc_views/doc_views_types.ts @@ -27,8 +27,6 @@ export interface AngularDirective { export type AngularScope = IScope; -export type AngularController = (scope: AngularScope) => void; - export type ElasticSearchHit = Record>; export interface FieldMapping { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts index 3226b3af93cee..842ef2bf9c825 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/search_embeddable_factory.ts @@ -16,9 +16,11 @@ * specific language governing permissions and limitations * under the License. */ + +import { auto } from 'angular'; import { i18n } from '@kbn/i18n'; import { TExecuteTriggerActions } from 'src/plugins/ui_actions/public'; -import { getServices, IInjector } from '../../kibana_services'; +import { getServices } from '../../kibana_services'; import { EmbeddableFactory, ErrorEmbeddable, @@ -36,13 +38,13 @@ export class SearchEmbeddableFactory extends EmbeddableFactory< SearchEmbeddable > { public readonly type = SEARCH_EMBEDDABLE_TYPE; - private $injector: IInjector | null; - private getInjector: () => Promise | null; + private $injector: auto.IInjectorService | null; + private getInjector: () => Promise | null; public isEditable: () => boolean; constructor( private readonly executeTriggerActions: TExecuteTriggerActions, - getInjector: () => Promise, + getInjector: () => Promise, isEditable: () => boolean ) { super({ @@ -77,7 +79,7 @@ export class SearchEmbeddableFactory extends EmbeddableFactory< if (!this.$injector) { this.$injector = await this.getInjector(); } - const $injector = this.$injector as IInjector; + const $injector = this.$injector as auto.IInjectorService; const $compile = $injector.get('$compile'); const $rootScope = $injector.get('$rootScope'); diff --git a/src/legacy/core_plugins/kibana/public/discover/plugin.ts b/src/legacy/core_plugins/kibana/public/discover/plugin.ts index 8f1eb7ef75559..0897f62574e93 100644 --- a/src/legacy/core_plugins/kibana/public/discover/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/discover/plugin.ts @@ -18,14 +18,14 @@ */ import { i18n } from '@kbn/i18n'; import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public'; -import angular from 'angular'; +import angular, { auto } from 'angular'; import { IUiActionsSetup, IUiActionsStart } from 'src/plugins/ui_actions/public'; import { DataPublicPluginStart } from 'src/plugins/data/public'; import { registerFeature } from './np_ready/register_feature'; import './kibana_services'; import { IEmbeddableStart, IEmbeddableSetup } from '../../../../../plugins/embeddable/public'; import { getInnerAngularModule, getInnerAngularModuleEmbeddable } from './get_inner_angular'; -import { Chrome, setAngularModule, setServices } from './kibana_services'; +import { setAngularModule, setServices } from './kibana_services'; import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public'; import { EuiUtilsStart } from '../../../../../plugins/eui_utils/public'; import { buildServices } from './build_services'; @@ -50,9 +50,6 @@ export interface DiscoverSetupPlugins { uiActions: IUiActionsSetup; embeddable: IEmbeddableSetup; kibana_legacy: KibanaLegacySetup; - __LEGACY: { - chrome: Chrome; - }; home: HomePublicPluginSetup; } export interface DiscoverStartPlugins { @@ -76,15 +73,18 @@ export class DiscoverPlugin implements Plugin { private servicesInitialized: boolean = false; private innerAngularInitialized: boolean = false; private docViewsRegistry: DocViewsRegistry | null = null; + private embeddableInjector: auto.IInjectorService | null = null; + private getEmbeddableInjector: (() => Promise) | null = null; /** * why are those functions public? they are needed for some mocha tests * can be removed once all is Jest */ public initializeInnerAngular?: () => void; - public initializeServices?: () => void; + public initializeServices?: () => Promise<{ core: CoreStart; plugins: DiscoverStartPlugins }>; setup(core: CoreSetup, plugins: DiscoverSetupPlugins): DiscoverSetup { - this.docViewsRegistry = new DocViewsRegistry(plugins.__LEGACY.chrome); + this.getEmbeddableInjector = this.getInjector.bind(this); + this.docViewsRegistry = new DocViewsRegistry(this.getEmbeddableInjector); this.docViewsRegistry.addDocView({ title: i18n.translate('kbn.discover.docViews.table.tableTitle', { defaultMessage: 'Table', @@ -113,6 +113,7 @@ export class DiscoverPlugin implements Plugin { } await this.initializeServices(); await this.initializeInnerAngular(); + const { renderApp } = await import('./np_ready/application'); return renderApp(innerAngularName, params.element); }, @@ -141,11 +142,13 @@ export class DiscoverPlugin implements Plugin { this.initializeServices = async () => { if (this.servicesInitialized) { - return; + return { core, plugins }; } const services = await buildServices(core, plugins, this.docViewsRegistry!); setServices(services); this.servicesInitialized = true; + + return { core, plugins }; }; this.registerEmbeddable(core, plugins); @@ -156,22 +159,31 @@ export class DiscoverPlugin implements Plugin { */ private async registerEmbeddable(core: CoreStart, plugins: DiscoverStartPlugins) { const { SearchEmbeddableFactory } = await import('./np_ready/embeddable'); - const getInjector = async () => { - if (!this.initializeServices) { - throw Error('Discover plugin registerEmbeddable: initializeServices is undefined'); - } - await this.initializeServices(); - getInnerAngularModuleEmbeddable(embeddableAngularName, core, plugins); - const mountpoint = document.createElement('div'); - return angular.bootstrap(mountpoint, [embeddableAngularName]); - }; const isEditable = () => core.application.capabilities.discover.save as boolean; + if (!this.getEmbeddableInjector) { + throw Error('Discover plugin method getEmbeddableInjector is undefined'); + } + const factory = new SearchEmbeddableFactory( plugins.uiActions.executeTriggerActions, - getInjector, + this.getEmbeddableInjector, isEditable ); plugins.embeddable.registerEmbeddableFactory(factory.type, factory); } + + private async getInjector() { + if (!this.embeddableInjector) { + if (!this.initializeServices) { + throw Error('Discover plugin getEmbeddableInjector: initializeServices is undefined'); + } + const { core, plugins } = await this.initializeServices(); + getInnerAngularModuleEmbeddable(embeddableAngularName, core, plugins); + const mountpoint = document.createElement('div'); + this.embeddableInjector = angular.bootstrap(mountpoint, [embeddableAngularName]); + } + + return this.embeddableInjector; + } } From d25d1bd84e6db02ddc6059a00e5a04b027edf719 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Fri, 24 Jan 2020 09:13:17 +0100 Subject: [PATCH 04/43] [Uptime] Clean Url to remove undefined/empty query params (#55386) * fix usage of useParams * update code * update defaults * update snaps --- .../common/constants/client_defaults.ts | 15 ++++++-- .../common/constants/context_defaults.ts | 16 --------- .../most_recent_error.test.tsx.snap | 2 +- .../monitor_list_drawer/most_recent_error.tsx | 2 +- .../contexts/uptime_settings_context.tsx | 12 ++++--- .../stringify_url_params.test.ts.snap | 2 ++ .../__tests__/stringify_url_params.test.ts | 22 ++++++++++++ .../public/lib/helper/stringify_url_params.ts | 36 +++++++++++++++++-- .../plugins/uptime/public/pages/overview.tsx | 7 +--- .../uptime/public/pages/page_header.tsx | 8 +++-- .../legacy/plugins/uptime/public/routes.tsx | 2 +- 11 files changed, 88 insertions(+), 36 deletions(-) diff --git a/x-pack/legacy/plugins/uptime/common/constants/client_defaults.ts b/x-pack/legacy/plugins/uptime/common/constants/client_defaults.ts index e991e0c6b82e1..d8a3ef8d7cbbb 100644 --- a/x-pack/legacy/plugins/uptime/common/constants/client_defaults.ts +++ b/x-pack/legacy/plugins/uptime/common/constants/client_defaults.ts @@ -8,17 +8,28 @@ export const CLIENT_DEFAULTS = { ABSOLUTE_DATE_RANGE_START: 0, // 15 minutes ABSOLUTE_DATE_RANGE_END: 1000 * 60 * 15, - // 60 seconds + /** + * The application auto refreshes every 60s by default. + */ AUTOREFRESH_INTERVAL: 60 * 1000, - // polling defaults to "on" + /** + * The application's autorefresh feature is enabled. + */ AUTOREFRESH_IS_PAUSED: false, + COMMONLY_USED_DATE_RANGES: [ { start: 'now/d', end: 'now', label: 'Today' }, { start: 'now/w', end: 'now', label: 'Week to date' }, { start: 'now/M', end: 'now', label: 'Month to date' }, { start: 'now/y', end: 'now', label: 'Year to date' }, ], + /** + * The beginning of the default date range is 15m ago. + */ DATE_RANGE_START: 'now-15m', + /** + * The end of the default date range is now. + */ DATE_RANGE_END: 'now', FILTERS: '', MONITOR_LIST_PAGE_INDEX: 0, diff --git a/x-pack/legacy/plugins/uptime/common/constants/context_defaults.ts b/x-pack/legacy/plugins/uptime/common/constants/context_defaults.ts index 4c32769d73e84..e0f0333bb8cfd 100644 --- a/x-pack/legacy/plugins/uptime/common/constants/context_defaults.ts +++ b/x-pack/legacy/plugins/uptime/common/constants/context_defaults.ts @@ -10,26 +10,10 @@ import { SortOrder, CursorDirection } from '../graphql/types'; * The Uptime UI utilizes a settings context, the defaults for which are stored here. */ export const CONTEXT_DEFAULTS = { - /** - * The application's autorefresh feature is enabled. - */ - AUTOREFRESH_IS_PAUSED: true, - /** - * The application autorefreshes every 10s by default. - */ - AUTOREFRESH_INTERVAL: 10000, /** * The application cannot assume a basepath. */ BASE_PATH: '', - /** - * The beginning of the default date range is 15m ago. - */ - DATE_RANGE_START: 'now-15m', - /** - * The end of the default date range is now. - */ - DATE_RANGE_END: 'now', CURSOR_PAGINATION: { cursorDirection: CursorDirection.AFTER, diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/__tests__/__snapshots__/most_recent_error.test.tsx.snap b/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/__tests__/__snapshots__/most_recent_error.test.tsx.snap index 389afa27fd21f..0a280ac6b24b8 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/__tests__/__snapshots__/most_recent_error.test.tsx.snap +++ b/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/__tests__/__snapshots__/most_recent_error.test.tsx.snap @@ -21,7 +21,7 @@ Array [ > Get https://expired.badssl.com: x509: certificate has expired or is not yet valid diff --git a/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/most_recent_error.tsx b/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/most_recent_error.tsx index c2df9253ec8dc..036882b49359f 100644 --- a/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/most_recent_error.tsx +++ b/x-pack/legacy/plugins/uptime/public/components/functional/monitor_list/monitor_list_drawer/most_recent_error.tsx @@ -33,7 +33,7 @@ export const MostRecentError = ({ error, monitorId, timestamp }: MostRecentError const [getUrlParams] = useUrlParams(); const { absoluteDateRangeStart, absoluteDateRangeEnd, ...params } = getUrlParams(); params.selectedPingStatus = 'down'; - const linkParameters = stringifyUrlParams(params); + const linkParameters = stringifyUrlParams(params, true); const timestampStr = timestamp ? moment(new Date(timestamp).valueOf()).fromNow() : ''; diff --git a/x-pack/legacy/plugins/uptime/public/contexts/uptime_settings_context.tsx b/x-pack/legacy/plugins/uptime/public/contexts/uptime_settings_context.tsx index 4b3abb46ac1e4..9f50849703562 100644 --- a/x-pack/legacy/plugins/uptime/public/contexts/uptime_settings_context.tsx +++ b/x-pack/legacy/plugins/uptime/public/contexts/uptime_settings_context.tsx @@ -5,10 +5,10 @@ */ import React, { createContext, useMemo } from 'react'; -import { useParams } from 'react-router-dom'; import { UptimeAppProps } from '../uptime_app'; -import { CONTEXT_DEFAULTS } from '../../common/constants'; +import { CLIENT_DEFAULTS, CONTEXT_DEFAULTS } from '../../common/constants'; import { CommonlyUsedRange } from '../components/functional/uptime_date_picker'; +import { useUrlParams } from '../hooks'; export interface UptimeSettingsContextValues { basePath: string; @@ -20,7 +20,9 @@ export interface UptimeSettingsContextValues { commonlyUsedRanges?: CommonlyUsedRange[]; } -const { BASE_PATH, DATE_RANGE_START, DATE_RANGE_END } = CONTEXT_DEFAULTS; +const { BASE_PATH } = CONTEXT_DEFAULTS; + +const { DATE_RANGE_START, DATE_RANGE_END } = CLIENT_DEFAULTS; /** * These are default values for the context. These defaults are typically @@ -39,7 +41,9 @@ export const UptimeSettingsContext = createContext(defaultContext); export const UptimeSettingsContextProvider: React.FC = ({ children, ...props }) => { const { basePath, isApmAvailable, isInfraAvailable, isLogsAvailable, commonlyUsedRanges } = props; - const { dateRangeStart, dateRangeEnd } = useParams(); + const [getUrlParams] = useUrlParams(); + + const { dateRangeStart, dateRangeEnd } = getUrlParams(); const value = useMemo(() => { return { diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/__snapshots__/stringify_url_params.test.ts.snap b/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/__snapshots__/stringify_url_params.test.ts.snap index 57add60bebe9a..31f5ceff7d046 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/__snapshots__/stringify_url_params.test.ts.snap +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/__snapshots__/stringify_url_params.test.ts.snap @@ -1,3 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`stringifyUrlParams creates expected string value 1`] = `"?autorefreshInterval=50000&autorefreshIsPaused=false&dateRangeStart=now-15m&dateRangeEnd=now&filters=monitor.id%3A%20bar&search=monitor.id%3A%20foo&selectedPingStatus=down&statusFilter=up"`; + +exports[`stringifyUrlParams creates expected string value when ignore empty is true 1`] = `"?autorefreshInterval=50000&filters=monitor.id%3A%20bar"`; diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/stringify_url_params.test.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/stringify_url_params.test.ts index 4c999680fa53e..a2f9b29c4ff58 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/stringify_url_params.test.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/__tests__/stringify_url_params.test.ts @@ -20,4 +20,26 @@ describe('stringifyUrlParams', () => { }); expect(result).toMatchSnapshot(); }); + + it('creates expected string value when ignore empty is true', () => { + const result = stringifyUrlParams( + { + autorefreshInterval: 50000, + autorefreshIsPaused: false, + dateRangeStart: 'now-15m', + dateRangeEnd: 'now', + filters: 'monitor.id: bar', + search: undefined, + selectedPingStatus: undefined, + statusFilter: '', + pagination: undefined, + }, + true + ); + expect(result).toMatchSnapshot(); + + expect(result.includes('pagination')).toBeFalsy(); + expect(result.includes('search')).toBeFalsy(); + expect(result.includes('selectedPingStatus')).toBeFalsy(); + }); }); diff --git a/x-pack/legacy/plugins/uptime/public/lib/helper/stringify_url_params.ts b/x-pack/legacy/plugins/uptime/public/lib/helper/stringify_url_params.ts index f1e9069126708..7d00a27d69032 100644 --- a/x-pack/legacy/plugins/uptime/public/lib/helper/stringify_url_params.ts +++ b/x-pack/legacy/plugins/uptime/public/lib/helper/stringify_url_params.ts @@ -5,6 +5,38 @@ */ import qs from 'querystring'; -import { UptimeUrlParams } from './url_params/get_supported_url_params'; +import { UptimeUrlParams } from './url_params'; +import { CLIENT_DEFAULTS } from '../../../common/constants'; -export const stringifyUrlParams = (params: Partial) => `?${qs.stringify(params)}`; +const { + AUTOREFRESH_INTERVAL, + AUTOREFRESH_IS_PAUSED, + DATE_RANGE_START, + DATE_RANGE_END, +} = CLIENT_DEFAULTS; + +export const stringifyUrlParams = (params: Partial, ignoreEmpty = false) => { + if (ignoreEmpty) { + Object.keys(params).forEach((key: string) => { + // @ts-ignore + const val = params[key]; + if (val == null || val === '') { + // @ts-ignore + delete params[key]; + } + if (key === 'dateRangeStart' && val === DATE_RANGE_START) { + delete params[key]; + } + if (key === 'dateRangeEnd' && val === DATE_RANGE_END) { + delete params[key]; + } + if (key === 'autorefreshIsPaused' && val === AUTOREFRESH_IS_PAUSED) { + delete params[key]; + } + if (key === 'autorefreshInterval' && val === AUTOREFRESH_INTERVAL) { + delete params[key]; + } + }); + } + return `?${qs.stringify(params)}`; +}; diff --git a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx index 1c14d971120be..36abee673b682 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/overview.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/overview.tsx @@ -33,11 +33,6 @@ interface OverviewPageProps { type Props = OverviewPageProps; -export type UptimeSearchBarQueryChangeHandler = (queryChangedEvent: { - query?: { text: string }; - queryText?: string; -}) => void; - const EuiFlexItemStyled = styled(EuiFlexItem)` && { min-width: 598px; @@ -109,7 +104,7 @@ export const OverviewPage = ({ autocomplete, setBreadcrumbs }: Props) => { statusFilter, }; - const linkParameters = stringifyUrlParams(params); + const linkParameters = stringifyUrlParams(params, true); return ( diff --git a/x-pack/legacy/plugins/uptime/public/pages/page_header.tsx b/x-pack/legacy/plugins/uptime/public/pages/page_header.tsx index d341a22bc583b..e8705a2eb8eb3 100644 --- a/x-pack/legacy/plugins/uptime/public/pages/page_header.tsx +++ b/x-pack/legacy/plugins/uptime/public/pages/page_header.tsx @@ -7,7 +7,7 @@ import { EuiTitle, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; import React, { useEffect, useState } from 'react'; import { connect } from 'react-redux'; -import { useRouteMatch, useParams } from 'react-router-dom'; +import { useRouteMatch } from 'react-router-dom'; import { i18n } from '@kbn/i18n'; import { UptimeDatePicker } from '../components/functional/uptime_date_picker'; import { AppState } from '../state'; @@ -17,6 +17,7 @@ import { stringifyUrlParams } from '../lib/helper/stringify_url_params'; import { getTitle } from '../lib/helper/get_title'; import { UMUpdateBreadcrumbs } from '../lib/lib'; import { MONITOR_ROUTE } from '../routes'; +import { useUrlParams } from '../hooks'; interface PageHeaderProps { monitorStatus?: any; @@ -28,7 +29,8 @@ export const PageHeaderComponent = ({ monitorStatus, setBreadcrumbs }: PageHeade path: MONITOR_ROUTE, }); - const { absoluteDateRangeStart, absoluteDateRangeEnd, ...params } = useParams(); + const [getUrlParams] = useUrlParams(); + const { absoluteDateRangeStart, absoluteDateRangeEnd, ...params } = getUrlParams(); const headingText = i18n.translate('xpack.uptime.overviewPage.headerText', { defaultMessage: 'Overview', @@ -52,7 +54,7 @@ export const PageHeaderComponent = ({ monitorStatus, setBreadcrumbs }: PageHeade useEffect(() => { if (monitorPage) { if (headerText) { - setBreadcrumbs(getMonitorPageBreadcrumb(headerText, stringifyUrlParams(params))); + setBreadcrumbs(getMonitorPageBreadcrumb(headerText, stringifyUrlParams(params, true))); } } else { setBreadcrumbs(getOverviewPageBreadcrumbs()); diff --git a/x-pack/legacy/plugins/uptime/public/routes.tsx b/x-pack/legacy/plugins/uptime/public/routes.tsx index 028f2d5958325..07bba5163922e 100644 --- a/x-pack/legacy/plugins/uptime/public/routes.tsx +++ b/x-pack/legacy/plugins/uptime/public/routes.tsx @@ -10,7 +10,7 @@ import { MonitorPage, OverviewPage, NotFoundPage } from './pages'; import { DataPublicPluginStart } from '../../../../../src/plugins/data/public'; import { UMUpdateBreadcrumbs } from './lib/lib'; -export const MONITOR_ROUTE = '/monitor/:monitorId/:location?'; +export const MONITOR_ROUTE = '/monitor/:monitorId?'; export const OVERVIEW_ROUTE = '/'; interface RouterProps { From d3151327de1b637991aecdc0bd6b214b677d8b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loix?= Date: Fri, 24 Jan 2020 14:52:46 +0530 Subject: [PATCH 05/43] Fix text highlight in search result (#55695) --- .../app/components/mappings_editor/lib/search_fields.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/search_fields.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/search_fields.tsx index 807bf233b0da0..5a277073c5f1a 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/search_fields.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/lib/search_fields.tsx @@ -125,6 +125,7 @@ const getJSXdisplayFromMeta = ( const charIndex = path.lastIndexOf(stringMatch!); const startString = path.substr(0, charIndex); const endString = path.substr(charIndex + stringMatch!.length); + display = ( {startString} @@ -164,7 +165,7 @@ const getSearchMetadata = (searchData: SearchData, fieldData: FieldData): Search .sort((a, b) => b![0].length - a![0].length); if (arrayMatch.length) { - stringMatch = arrayMatch[0]![0].toLowerCase(); + stringMatch = arrayMatch[0]![0]; } } @@ -244,7 +245,7 @@ export const searchFields = (term: string, fields: NormalizedFields['byId']): Se field, metadata: getSearchMetadata(searchData, { name: field.source.name, - path: field.path.join(' > ').toLowerCase(), + path: field.path.join(' > '), type: field.source.type, }), })) From d40269c748bbfc793c08c0a74dd1b404a689f96c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez?= Date: Fri, 24 Jan 2020 11:16:11 +0100 Subject: [PATCH 06/43] Fix the scale of the search markers (#55731) The search markers where placed on the minimap using a different scale than the density chart and time ruler. That made the log stream jump to unexpected time positions when the user clicked on a search marker. This also fixes an problem where the search markers didn't move alongside the rest of the minimap when the user dragged and dropped it. --- .../logging/log_minimap/log_minimap.tsx | 19 +++++++++---------- .../logging/log_minimap/search_markers.tsx | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/x-pack/legacy/plugins/infra/public/components/logging/log_minimap/log_minimap.tsx b/x-pack/legacy/plugins/infra/public/components/logging/log_minimap/log_minimap.tsx index ad47d17fe3db9..75d8c5a47d32d 100644 --- a/x-pack/legacy/plugins/infra/public/components/logging/log_minimap/log_minimap.tsx +++ b/x-pack/legacy/plugins/infra/public/components/logging/log_minimap/log_minimap.tsx @@ -215,6 +215,15 @@ export class LogMinimap extends React.Component + + {highlightedInterval ? ( ) : null} - - - { .range([0, height]); return ( - + {buckets.map(bucket => ( Date: Fri, 24 Jan 2020 11:22:31 +0100 Subject: [PATCH 07/43] [ML] Singel Metric Viewer: Fix full refresh check. (#55726) Fixes the check whether to do a full refresh of the page or not. lastRefresh was mistakenly part of the check. This fixes keeping the flyout open for rules editing. --- .../application/timeseriesexplorer/timeseriesexplorer.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js index 02cb2e3f4e25a..44b9fbc71f71a 100644 --- a/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js +++ b/x-pack/legacy/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js @@ -965,16 +965,15 @@ export class TimeSeriesExplorer extends React.Component { !isEqual(previousProps.lastRefresh, this.props.lastRefresh) || !isEqual(previousProps.selectedDetectorIndex, this.props.selectedDetectorIndex) || !isEqual(previousProps.selectedEntities, this.props.selectedEntities) || - !isEqual(previousProps.selectedForecastId, this.props.selectedForecastId) || + previousProps.selectedForecastId !== this.props.selectedForecastId || previousProps.selectedJobId !== this.props.selectedJobId ) { const fullRefresh = previousProps === undefined || !isEqual(previousProps.bounds, this.props.bounds) || - !isEqual(previousProps.lastRefresh, this.props.lastRefresh) || !isEqual(previousProps.selectedDetectorIndex, this.props.selectedDetectorIndex) || !isEqual(previousProps.selectedEntities, this.props.selectedEntities) || - !isEqual(previousProps.selectedForecastId, this.props.selectedForecastId) || + previousProps.selectedForecastId !== this.props.selectedForecastId || previousProps.selectedJobId !== this.props.selectedJobId; this.loadSingleMetricData(fullRefresh); } From fee22e8d94177202b84bb1225133de36f0903049 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Fri, 24 Jan 2020 11:25:55 +0100 Subject: [PATCH 08/43] [ML] Anomaly Explorer: Fix view by selection when filter is active. (#55717) Fixes the view-by selection when a KQL filter gets active and restores previous behavior: - If the filter includes AND view-by switches to Job ID. - Otherwise the view-by selection switches to the first available option present in the KQL filter - Additionally, the view-by dropdown options get filtered down to the options present in the KQL filter --- .../explorer_reducer/set_influencer_filter_settings.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts b/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts index 8d083a396582a..0d84179c572d2 100644 --- a/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts +++ b/x-pack/legacy/plugins/ml/public/application/explorer/reducers/explorer_reducer/set_influencer_filter_settings.ts @@ -23,17 +23,20 @@ export function setInfluencerFilterSettings( const { selectedCells, viewBySwimlaneOptions } = state; let selectedViewByFieldName = state.viewBySwimlaneFieldName; + const filteredViewBySwimlaneOptions = viewBySwimlaneOptions.filter(d => + filteredFields.includes(d) + ); // if it's an AND filter set view by swimlane to job ID as the others will have no results - if (isAndOperator && selectedCells === null) { + if (isAndOperator && selectedCells === undefined) { selectedViewByFieldName = VIEW_BY_JOB_LABEL; } else { // Set View by dropdown to first relevant fieldName based on incoming filter if there's no cell selection already // or if selected cell is from overall swimlane as this won't include an additional influencer filter for (let i = 0; i < filteredFields.length; i++) { if ( - viewBySwimlaneOptions.includes(filteredFields[i]) && - (selectedCells === null || (selectedCells && selectedCells.type === 'overall')) + filteredViewBySwimlaneOptions.includes(filteredFields[i]) && + (selectedCells === undefined || (selectedCells && selectedCells.type === 'overall')) ) { selectedViewByFieldName = filteredFields[i]; break; @@ -53,5 +56,6 @@ export function setInfluencerFilterSettings( selectedViewByFieldName === VIEW_BY_JOB_LABEL || filteredFields.includes(selectedViewByFieldName) === false, viewBySwimlaneFieldName: selectedViewByFieldName, + viewBySwimlaneOptions: filteredViewBySwimlaneOptions, }; } From 43a7aa7fc0769cf109cf2282f9a214dd758da749 Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Fri, 24 Jan 2020 12:26:25 +0100 Subject: [PATCH 09/43] [Console] Remove z-index from editor panes and move it to the resizer (#55813) * Remove z-index from editor panes and move it to the resizer * Update comment --- .../console/public/np_ready/application/styles/_app.scss | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/legacy/core_plugins/console/public/np_ready/application/styles/_app.scss b/src/legacy/core_plugins/console/public/np_ready/application/styles/_app.scss index b89a43f7455a5..3b6297f9cdbff 100644 --- a/src/legacy/core_plugins/console/public/np_ready/application/styles/_app.scss +++ b/src/legacy/core_plugins/console/public/np_ready/application/styles/_app.scss @@ -27,9 +27,6 @@ // Required on IE11 to render ace editor correctly after first input. position: relative; - // Give the aria selection border priority when the divider is selected - z-index: 0; - &__spinner { width: 100%; } @@ -38,8 +35,6 @@ .conApp__output { display: flex; flex: 1 1 1px; - // Give the aria selection border priority when the divider is selected - z-index: -1; } .conApp__textAreaLabelHack, @@ -76,6 +71,8 @@ .conApp__resizer { @include kbnResizer; + // Give the aria selection border priority when the divider is selected on IE11 and Chrome + z-index: $euiZLevel1; } // SASSTODO: This component seems to not be used anymore? From 6984cf1711371d86b1ad8d7abcafc751a105743c Mon Sep 17 00:00:00 2001 From: Jean-Louis Leysens Date: Fri, 24 Jan 2020 13:10:59 +0100 Subject: [PATCH 10/43] Move SplitPanel to kibana_react (#55529) * split_panel component -> kibana_react * Update useEffect for console warning * `console` -> `kibana-react` i18n namespace * Update when warning about children is emitted in split panel component Co-authored-by: Elastic Machine --- .../np_ready/application/components/index.ts | 1 - .../application/containers/editor/editor.tsx | 2 +- .../vis/editors/default/default_editor.tsx | 5 +---- src/plugins/kibana_react/public/index.ts | 1 + .../__snapshots__/split_panel.test.tsx.snap | 0 .../public}/split_panel/components/resizer.tsx | 2 +- .../public}/split_panel/containers/panel.tsx | 0 .../split_panel/containers/panel_container.tsx | 17 +++++++++++++++-- .../public}/split_panel/context.tsx | 0 .../kibana_react/public}/split_panel/index.ts | 0 .../public}/split_panel/registry.ts | 4 ---- .../public}/split_panel/split_panel.test.tsx | 0 12 files changed, 19 insertions(+), 13 deletions(-) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/__snapshots__/split_panel.test.tsx.snap (100%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/components/resizer.tsx (94%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/containers/panel.tsx (100%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/containers/panel_container.tsx (89%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/context.tsx (100%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/index.ts (100%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/registry.ts (92%) rename src/{legacy/core_plugins/console/public/np_ready/application/components => plugins/kibana_react/public}/split_panel/split_panel.test.tsx (100%) diff --git a/src/legacy/core_plugins/console/public/np_ready/application/components/index.ts b/src/legacy/core_plugins/console/public/np_ready/application/components/index.ts index 4669e210e7c2d..eccde899a2640 100644 --- a/src/legacy/core_plugins/console/public/np_ready/application/components/index.ts +++ b/src/legacy/core_plugins/console/public/np_ready/application/components/index.ts @@ -17,7 +17,6 @@ * under the License. */ -export * from './split_panel'; export { SomethingWentWrongCallout } from './something_went_wrong_callout'; export { TopNavMenuItem, TopNavMenu } from './top_nav_menu'; export { ConsoleMenu } from './console_menu'; diff --git a/src/legacy/core_plugins/console/public/np_ready/application/containers/editor/editor.tsx b/src/legacy/core_plugins/console/public/np_ready/application/containers/editor/editor.tsx index 7be1382760eb9..b42d791e5acd8 100644 --- a/src/legacy/core_plugins/console/public/np_ready/application/containers/editor/editor.tsx +++ b/src/legacy/core_plugins/console/public/np_ready/application/containers/editor/editor.tsx @@ -21,7 +21,7 @@ import React, { useCallback } from 'react'; import { debounce } from 'lodash'; import { EditorContentSpinner } from '../../components'; -import { Panel, PanelsContainer } from '../../components/split_panel'; +import { Panel, PanelsContainer } from '../../../../../../../../plugins/kibana_react/public'; import { Editor as EditorUI, EditorOutput } from './legacy/console_editor'; import { StorageKeys } from '../../../services'; import { useEditorReadContext, useServicesContext } from '../../contexts'; diff --git a/src/legacy/ui/public/vis/editors/default/default_editor.tsx b/src/legacy/ui/public/vis/editors/default/default_editor.tsx index 3e99bb83d224f..efe5a79cd027e 100644 --- a/src/legacy/ui/public/vis/editors/default/default_editor.tsx +++ b/src/legacy/ui/public/vis/editors/default/default_editor.tsx @@ -23,10 +23,7 @@ import { start as embeddables } from '../../../../../core_plugins/embeddable_api import { EditorRenderProps } from '../../../../../core_plugins/kibana/public/visualize/np_ready/types'; import { VisualizeEmbeddable } from '../../../../../core_plugins/visualizations/public/embeddable'; import { VisualizeEmbeddableFactory } from '../../../../../core_plugins/visualizations/public/embeddable/visualize_embeddable_factory'; -import { - PanelsContainer, - Panel, -} from '../../../../../core_plugins/console/public/np_ready/application/components/split_panel'; +import { PanelsContainer, Panel } from '../../../../../../plugins/kibana_react/public'; import './vis_type_agg_filter'; import { DefaultEditorSideBar } from './components/sidebar'; diff --git a/src/plugins/kibana_react/public/index.ts b/src/plugins/kibana_react/public/index.ts index cfe89f16e99dd..81f2e694e8e5b 100644 --- a/src/plugins/kibana_react/public/index.ts +++ b/src/plugins/kibana_react/public/index.ts @@ -25,5 +25,6 @@ export * from './overlays'; export * from './ui_settings'; export * from './field_icon'; export * from './table_list_view'; +export * from './split_panel'; export { useUrlTracker } from './use_url_tracker'; export { toMountPoint } from './util'; diff --git a/src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/__snapshots__/split_panel.test.tsx.snap b/src/plugins/kibana_react/public/split_panel/__snapshots__/split_panel.test.tsx.snap similarity index 100% rename from src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/__snapshots__/split_panel.test.tsx.snap rename to src/plugins/kibana_react/public/split_panel/__snapshots__/split_panel.test.tsx.snap diff --git a/src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/components/resizer.tsx b/src/plugins/kibana_react/public/split_panel/components/resizer.tsx similarity index 94% rename from src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/components/resizer.tsx rename to src/plugins/kibana_react/public/split_panel/components/resizer.tsx index 67fe92b7eb03a..306db4c7d9a63 100644 --- a/src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/components/resizer.tsx +++ b/src/plugins/kibana_react/public/split_panel/components/resizer.tsx @@ -35,7 +35,7 @@ export function Resizer(props: Props) {