/config` for archive distributions
+and `/etc/kibana` for package distributions. If a pre-existing keystore exists in the data directory that path will continue to be used.
+
[float]
[[breaking_80_user_role_changes]]
=== User role changes
[float]
-==== `kibana_user` role has been removed and `kibana_admin` has been added.
+=== `kibana_user` role has been removed and `kibana_admin` has been added.
*Details:* The `kibana_user` role has been removed and `kibana_admin` has been added to better
reflect its intended use. This role continues to grant all access to every
diff --git a/docs/setup/production.asciidoc b/docs/setup/production.asciidoc
index 72f275e237490..afb4b37df6a28 100644
--- a/docs/setup/production.asciidoc
+++ b/docs/setup/production.asciidoc
@@ -167,9 +167,9 @@ These can be used to automatically update the list of hosts as a cluster is resi
Kibana has a default maximum memory limit of 1.4 GB, and in most cases, we recommend leaving this unconfigured. In some scenarios, such as large reporting jobs,
it may make sense to tweak limits to meet more specific requirements.
-You can modify this limit by setting `--max-old-space-size` in the `NODE_OPTIONS` environment variable. For deb and rpm, packages this is passed in via `/etc/default/kibana` and can be appended to the bottom of the file.
+You can modify this limit by setting `--max-old-space-size` in the `node.options` config file that can be found inside `kibana/config` folder or any other configured with the environment variable `KIBANA_PATH_CONF` (for example in debian based system would be `/etc/kibana`).
The option accepts a limit in MB:
--------
-NODE_OPTIONS="--max-old-space-size=2048" bin/kibana
+--max-old-space-size=2048
--------
diff --git a/package.json b/package.json
index 7889909b15244..55a099b4e5c0c 100644
--- a/package.json
+++ b/package.json
@@ -67,7 +67,7 @@
"uiFramework:documentComponent": "cd packages/kbn-ui-framework && yarn documentComponent",
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "tsc --p tsconfig.types.json",
- "docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
+ "docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"kbn:bootstrap": "node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
"backport-skip-ci": "backport --prDescription \"[skip-ci]\"",
@@ -87,7 +87,6 @@
"**/@types/hoist-non-react-statics": "^3.3.1",
"**/@types/chai": "^4.2.11",
"**/cypress/@types/lodash": "^4.14.155",
- "**/cypress/lodash": "^4.15.19",
"**/typescript": "3.9.5",
"**/graphql-toolkit/lodash": "^4.17.15",
"**/hoist-non-react-statics": "^3.3.2",
diff --git a/packages/kbn-test/src/failed_tests_reporter/README.md b/packages/kbn-test/src/failed_tests_reporter/README.md
index 20592ecd733b6..0473ae7357def 100644
--- a/packages/kbn-test/src/failed_tests_reporter/README.md
+++ b/packages/kbn-test/src/failed_tests_reporter/README.md
@@ -7,15 +7,15 @@ A little CLI that runs in CI to find the failed tests in the JUnit reports, then
To fetch some JUnit reports from a recent build on CI, visit its `Google Cloud Storage Upload Report` and execute the following in the JS Console:
```js
-copy(`wget "${Array.from($$('a[href$=".xml"]')).filter(a => a.innerText === 'Download').map(a => a.href.replace('https://storage.cloud.google.com/', 'https://storage.googleapis.com/')).join('" "')}"`)
+copy(`wget -x -nH --cut-dirs 5 -P "target/downloaded_junit" "${Array.from($$('a[href$=".xml"]')).filter(a => a.innerText === 'Download').map(a => a.href.replace('https://storage.cloud.google.com/', 'https://storage.googleapis.com/')).join('" "')}"`)
```
-This copies a script to download the reports, which you should execute in the `test/junit` directory.
+This copies a script to download the reports, which you should execute in the root of the Kibana repository.
Next, run the CLI in `--no-github-update` mode so that it doesn't actually communicate with Github and `--no-report-update` to prevent the script from mutating the reports on disk and instead log the updated report.
```sh
-node scripts/report_failed_tests.js --verbose --no-github-update --no-report-update
+node scripts/report_failed_tests.js --verbose --no-github-update --no-report-update target/downloaded_junit/**/*.xml
```
Unless you specify the `GITHUB_TOKEN` environment variable requests to read existing issues will use anonymous access which is limited to 60 requests per hour.
\ No newline at end of file
diff --git a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts
index 3bcea44cf73b6..8a951ac969199 100644
--- a/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts
+++ b/packages/kbn-test/src/failed_tests_reporter/run_failed_tests_reporter_cli.ts
@@ -17,6 +17,8 @@
* under the License.
*/
+import Path from 'path';
+
import { REPO_ROOT, run, createFailError, createFlagError } from '@kbn/dev-utils';
import globby from 'globby';
@@ -28,6 +30,8 @@ import { readTestReport } from './test_report';
import { addMessagesToReport } from './add_messages_to_report';
import { getReportMessageIter } from './report_metadata';
+const DEFAULT_PATTERNS = [Path.resolve(REPO_ROOT, 'target/junit/**/*.xml')];
+
export function runFailedTestsReporterCli() {
run(
async ({ log, flags }) => {
@@ -67,11 +71,15 @@ export function runFailedTestsReporterCli() {
throw createFlagError('Missing --build-url or process.env.BUILD_URL');
}
- const reportPaths = await globby(['target/junit/**/*.xml'], {
- cwd: REPO_ROOT,
+ const patterns = flags._.length ? flags._ : DEFAULT_PATTERNS;
+ const reportPaths = await globby(patterns, {
absolute: true,
});
+ if (!reportPaths.length) {
+ throw createFailError(`Unable to find any junit reports with patterns [${patterns}]`);
+ }
+
const newlyCreatedIssues: Array<{
failure: TestFailure;
newIssue: GithubIssueMini;
diff --git a/src/cli_keystore/cli_keystore.js b/src/cli_keystore/cli_keystore.js
index e1561b343ef39..d12c80b361c92 100644
--- a/src/cli_keystore/cli_keystore.js
+++ b/src/cli_keystore/cli_keystore.js
@@ -18,20 +18,16 @@
*/
import _ from 'lodash';
-import { join } from 'path';
import { pkg } from '../core/server/utils';
import Command from '../cli/command';
-import { getDataPath } from '../core/server/path';
import { Keystore } from '../legacy/server/keystore';
-const path = join(getDataPath(), 'kibana.keystore');
-const keystore = new Keystore(path);
-
import { createCli } from './create';
import { listCli } from './list';
import { addCli } from './add';
import { removeCli } from './remove';
+import { getKeystore } from './get_keystore';
const argv = process.env.kbnWorkerArgv
? JSON.parse(process.env.kbnWorkerArgv)
@@ -42,6 +38,8 @@ program
.version(pkg.version)
.description('A tool for managing settings stored in the Kibana keystore');
+const keystore = new Keystore(getKeystore());
+
createCli(program, keystore);
listCli(program, keystore);
addCli(program, keystore);
diff --git a/src/cli_keystore/get_keystore.js b/src/cli_keystore/get_keystore.js
new file mode 100644
index 0000000000000..c8ff2555563ad
--- /dev/null
+++ b/src/cli_keystore/get_keystore.js
@@ -0,0 +1,40 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { existsSync } from 'fs';
+import { join } from 'path';
+
+import Logger from '../cli_plugin/lib/logger';
+import { getConfigDirectory, getDataPath } from '../core/server/path';
+
+export function getKeystore() {
+ const configKeystore = join(getConfigDirectory(), 'kibana.keystore');
+ const dataKeystore = join(getDataPath(), 'kibana.keystore');
+ let keystorePath = null;
+ if (existsSync(dataKeystore)) {
+ const logger = new Logger();
+ logger.log(
+ `kibana.keystore located in the data folder is deprecated. Future versions will use the config folder.`
+ );
+ keystorePath = dataKeystore;
+ } else {
+ keystorePath = configKeystore;
+ }
+ return keystorePath;
+}
diff --git a/src/cli_keystore/get_keystore.test.js b/src/cli_keystore/get_keystore.test.js
new file mode 100644
index 0000000000000..88102b8f51d57
--- /dev/null
+++ b/src/cli_keystore/get_keystore.test.js
@@ -0,0 +1,57 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { getKeystore } from './get_keystore';
+import Logger from '../cli_plugin/lib/logger';
+import fs from 'fs';
+import sinon from 'sinon';
+
+describe('get_keystore', () => {
+ const sandbox = sinon.createSandbox();
+
+ beforeEach(() => {
+ sandbox.stub(Logger.prototype, 'log');
+ });
+
+ afterEach(() => {
+ sandbox.restore();
+ });
+
+ it('uses the config directory if there is no pre-existing keystore', () => {
+ sandbox.stub(fs, 'existsSync').returns(false);
+ expect(getKeystore()).toContain('config');
+ expect(getKeystore()).not.toContain('data');
+ });
+
+ it('uses the data directory if there is a pre-existing keystore in the data directory', () => {
+ sandbox.stub(fs, 'existsSync').returns(true);
+ expect(getKeystore()).toContain('data');
+ expect(getKeystore()).not.toContain('config');
+ });
+
+ it('logs a deprecation warning if the data directory is used', () => {
+ sandbox.stub(fs, 'existsSync').returns(true);
+ getKeystore();
+ sandbox.assert.calledOnce(Logger.prototype.log);
+ sandbox.assert.calledWith(
+ Logger.prototype.log,
+ 'kibana.keystore located in the data folder is deprecated. Future versions will use the config folder.'
+ );
+ });
+});
diff --git a/src/core/server/elasticsearch/legacy/cluster_client.test.ts b/src/core/server/elasticsearch/legacy/cluster_client.test.ts
index 2f0f80728c707..fd57d06e61eee 100644
--- a/src/core/server/elasticsearch/legacy/cluster_client.test.ts
+++ b/src/core/server/elasticsearch/legacy/cluster_client.test.ts
@@ -130,7 +130,7 @@ describe('#callAsInternalUser', () => {
expect(mockEsClientInstance.security.authenticate).toHaveBeenLastCalledWith(mockParams);
});
- test('does not wrap errors if `wrap401Errors` is not set', async () => {
+ test('does not wrap errors if `wrap401Errors` is set to `false`', async () => {
const mockError = { message: 'some error' };
mockEsClientInstance.ping.mockRejectedValue(mockError);
@@ -146,7 +146,7 @@ describe('#callAsInternalUser', () => {
).rejects.toBe(mockAuthenticationError);
});
- test('wraps only 401 errors by default or when `wrap401Errors` is set', async () => {
+ test('wraps 401 errors when `wrap401Errors` is set to `true` or unspecified', async () => {
const mockError = { message: 'some error' };
mockEsClientInstance.ping.mockRejectedValue(mockError);
diff --git a/src/core/server/http/http_server.mocks.ts b/src/core/server/http/http_server.mocks.ts
index bbef0a105c089..7d37af833d4c1 100644
--- a/src/core/server/http/http_server.mocks.ts
+++ b/src/core/server/http/http_server.mocks.ts
@@ -33,7 +33,7 @@ import {
} from './router';
import { OnPreResponseToolkit } from './lifecycle/on_pre_response';
import { OnPostAuthToolkit } from './lifecycle/on_post_auth';
-import { OnPreAuthToolkit } from './lifecycle/on_pre_auth';
+import { OnPreRoutingToolkit } from './lifecycle/on_pre_routing';
interface RequestFixtureOptions {
auth?: { isAuthenticated: boolean };
@@ -161,7 +161,7 @@ const createLifecycleResponseFactoryMock = (): jest.Mocked;
+type ToolkitMock = jest.Mocked;
const createToolkitMock = (): ToolkitMock => {
return {
diff --git a/src/core/server/http/http_server.test.ts b/src/core/server/http/http_server.test.ts
index 72cb0b2821c5c..601eba835a54e 100644
--- a/src/core/server/http/http_server.test.ts
+++ b/src/core/server/http/http_server.test.ts
@@ -1089,6 +1089,16 @@ describe('setup contract', () => {
});
});
+ describe('#registerOnPreRouting', () => {
+ test('does not throw if called after stop', async () => {
+ const { registerOnPreRouting } = await server.setup(config);
+ await server.stop();
+ expect(() => {
+ registerOnPreRouting((req, res) => res.unauthorized());
+ }).not.toThrow();
+ });
+ });
+
describe('#registerOnPreAuth', () => {
test('does not throw if called after stop', async () => {
const { registerOnPreAuth } = await server.setup(config);
diff --git a/src/core/server/http/http_server.ts b/src/core/server/http/http_server.ts
index 1abf5c0c133bb..9c16162d69334 100644
--- a/src/core/server/http/http_server.ts
+++ b/src/core/server/http/http_server.ts
@@ -24,8 +24,9 @@ import { Logger, LoggerFactory } from '../logging';
import { HttpConfig } from './http_config';
import { createServer, getListenerOptions, getServerOptions } from './http_tools';
import { adoptToHapiAuthFormat, AuthenticationHandler } from './lifecycle/auth';
+import { adoptToHapiOnPreAuth, OnPreAuthHandler } from './lifecycle/on_pre_auth';
import { adoptToHapiOnPostAuthFormat, OnPostAuthHandler } from './lifecycle/on_post_auth';
-import { adoptToHapiOnPreAuthFormat, OnPreAuthHandler } from './lifecycle/on_pre_auth';
+import { adoptToHapiOnRequest, OnPreRoutingHandler } from './lifecycle/on_pre_routing';
import { adoptToHapiOnPreResponseFormat, OnPreResponseHandler } from './lifecycle/on_pre_response';
import { IRouter, RouteConfigOptions, KibanaRouteState, isSafeMethod } from './router';
import {
@@ -49,8 +50,9 @@ export interface HttpServerSetup {
basePath: HttpServiceSetup['basePath'];
csp: HttpServiceSetup['csp'];
createCookieSessionStorageFactory: HttpServiceSetup['createCookieSessionStorageFactory'];
- registerAuth: HttpServiceSetup['registerAuth'];
+ registerOnPreRouting: HttpServiceSetup['registerOnPreRouting'];
registerOnPreAuth: HttpServiceSetup['registerOnPreAuth'];
+ registerAuth: HttpServiceSetup['registerAuth'];
registerOnPostAuth: HttpServiceSetup['registerOnPostAuth'];
registerOnPreResponse: HttpServiceSetup['registerOnPreResponse'];
getAuthHeaders: GetAuthHeaders;
@@ -64,7 +66,11 @@ export interface HttpServerSetup {
/** @internal */
export type LifecycleRegistrar = Pick<
HttpServerSetup,
- 'registerAuth' | 'registerOnPreAuth' | 'registerOnPostAuth' | 'registerOnPreResponse'
+ | 'registerOnPreRouting'
+ | 'registerOnPreAuth'
+ | 'registerAuth'
+ | 'registerOnPostAuth'
+ | 'registerOnPreResponse'
>;
export class HttpServer {
@@ -113,12 +119,13 @@ export class HttpServer {
return {
registerRouter: this.registerRouter.bind(this),
registerStaticDir: this.registerStaticDir.bind(this),
+ registerOnPreRouting: this.registerOnPreRouting.bind(this),
registerOnPreAuth: this.registerOnPreAuth.bind(this),
+ registerAuth: this.registerAuth.bind(this),
registerOnPostAuth: this.registerOnPostAuth.bind(this),
registerOnPreResponse: this.registerOnPreResponse.bind(this),
createCookieSessionStorageFactory: (cookieOptions: SessionStorageCookieOptions) =>
this.createCookieSessionStorageFactory(cookieOptions, config.basePath),
- registerAuth: this.registerAuth.bind(this),
basePath: basePathService,
csp: config.csp,
auth: {
@@ -222,7 +229,7 @@ export class HttpServer {
return;
}
- this.registerOnPreAuth((request, response, toolkit) => {
+ this.registerOnPreRouting((request, response, toolkit) => {
const oldUrl = request.url.href!;
const newURL = basePathService.remove(oldUrl);
const shouldRedirect = newURL !== oldUrl;
@@ -263,6 +270,17 @@ export class HttpServer {
}
}
+ private registerOnPreAuth(fn: OnPreAuthHandler) {
+ if (this.server === undefined) {
+ throw new Error('Server is not created yet');
+ }
+ if (this.stopped) {
+ this.log.warn(`registerOnPreAuth called after stop`);
+ }
+
+ this.server.ext('onPreAuth', adoptToHapiOnPreAuth(fn, this.log));
+ }
+
private registerOnPostAuth(fn: OnPostAuthHandler) {
if (this.server === undefined) {
throw new Error('Server is not created yet');
@@ -274,15 +292,15 @@ export class HttpServer {
this.server.ext('onPostAuth', adoptToHapiOnPostAuthFormat(fn, this.log));
}
- private registerOnPreAuth(fn: OnPreAuthHandler) {
+ private registerOnPreRouting(fn: OnPreRoutingHandler) {
if (this.server === undefined) {
throw new Error('Server is not created yet');
}
if (this.stopped) {
- this.log.warn(`registerOnPreAuth called after stop`);
+ this.log.warn(`registerOnPreRouting called after stop`);
}
- this.server.ext('onRequest', adoptToHapiOnPreAuthFormat(fn, this.log));
+ this.server.ext('onRequest', adoptToHapiOnRequest(fn, this.log));
}
private registerOnPreResponse(fn: OnPreResponseHandler) {
diff --git a/src/core/server/http/http_service.mock.ts b/src/core/server/http/http_service.mock.ts
index 5e7ee7b658eca..51f11b15f2e09 100644
--- a/src/core/server/http/http_service.mock.ts
+++ b/src/core/server/http/http_service.mock.ts
@@ -29,7 +29,7 @@ import {
} from './types';
import { HttpService } from './http_service';
import { AuthStatus } from './auth_state_storage';
-import { OnPreAuthToolkit } from './lifecycle/on_pre_auth';
+import { OnPreRoutingToolkit } from './lifecycle/on_pre_routing';
import { AuthToolkit } from './lifecycle/auth';
import { sessionStorageMock } from './cookie_session_storage.mocks';
import { OnPostAuthToolkit } from './lifecycle/on_post_auth';
@@ -87,6 +87,7 @@ const createInternalSetupContractMock = () => {
config: jest.fn().mockReturnValue(configMock.create()),
} as unknown) as jest.MockedClass,
createCookieSessionStorageFactory: jest.fn(),
+ registerOnPreRouting: jest.fn(),
registerOnPreAuth: jest.fn(),
registerAuth: jest.fn(),
registerOnPostAuth: jest.fn(),
@@ -117,7 +118,8 @@ const createSetupContractMock = () => {
const mock: HttpServiceSetupMock = {
createCookieSessionStorageFactory: internalMock.createCookieSessionStorageFactory,
- registerOnPreAuth: internalMock.registerOnPreAuth,
+ registerOnPreRouting: internalMock.registerOnPreRouting,
+ registerOnPreAuth: jest.fn(),
registerAuth: internalMock.registerAuth,
registerOnPostAuth: internalMock.registerOnPostAuth,
registerOnPreResponse: internalMock.registerOnPreResponse,
@@ -173,7 +175,7 @@ const createHttpServiceMock = () => {
return mocked;
};
-const createOnPreAuthToolkitMock = (): jest.Mocked => ({
+const createOnPreAuthToolkitMock = (): jest.Mocked => ({
next: jest.fn(),
rewriteUrl: jest.fn(),
});
diff --git a/src/core/server/http/index.ts b/src/core/server/http/index.ts
index 65d633260a791..e91f7d9375842 100644
--- a/src/core/server/http/index.ts
+++ b/src/core/server/http/index.ts
@@ -64,7 +64,7 @@ export {
SafeRouteMethod,
} from './router';
export { BasePathProxyServer } from './base_path_proxy_server';
-export { OnPreAuthHandler, OnPreAuthToolkit } from './lifecycle/on_pre_auth';
+export { OnPreRoutingHandler, OnPreRoutingToolkit } from './lifecycle/on_pre_routing';
export {
AuthenticationHandler,
AuthHeaders,
@@ -78,6 +78,7 @@ export {
AuthResultType,
} from './lifecycle/auth';
export { OnPostAuthHandler, OnPostAuthToolkit } from './lifecycle/on_post_auth';
+export { OnPreAuthHandler, OnPreAuthToolkit } from './lifecycle/on_pre_auth';
export {
OnPreResponseHandler,
OnPreResponseToolkit,
diff --git a/src/core/server/http/integration_tests/core_service.test.mocks.ts b/src/core/server/http/integration_tests/core_service.test.mocks.ts
index f7ebd18b9c488..c23724b7d332f 100644
--- a/src/core/server/http/integration_tests/core_service.test.mocks.ts
+++ b/src/core/server/http/integration_tests/core_service.test.mocks.ts
@@ -19,10 +19,9 @@
import { elasticsearchServiceMock } from '../../elasticsearch/elasticsearch_service.mock';
export const clusterClientMock = jest.fn();
+export const clusterClientInstanceMock = elasticsearchServiceMock.createLegacyScopedClusterClient();
jest.doMock('../../elasticsearch/legacy/scoped_cluster_client', () => ({
- LegacyScopedClusterClient: clusterClientMock.mockImplementation(function () {
- return elasticsearchServiceMock.createLegacyScopedClusterClient();
- }),
+ LegacyScopedClusterClient: clusterClientMock.mockImplementation(() => clusterClientInstanceMock),
}));
jest.doMock('elasticsearch', () => {
diff --git a/src/core/server/http/integration_tests/core_services.test.ts b/src/core/server/http/integration_tests/core_services.test.ts
index ba39effa77016..3c5f22500e5e0 100644
--- a/src/core/server/http/integration_tests/core_services.test.ts
+++ b/src/core/server/http/integration_tests/core_services.test.ts
@@ -16,9 +16,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+
+import { clusterClientMock, clusterClientInstanceMock } from './core_service.test.mocks';
+
import Boom from 'boom';
import { Request } from 'hapi';
-import { clusterClientMock } from './core_service.test.mocks';
+import { errors as esErrors } from 'elasticsearch';
+import { LegacyElasticsearchErrorHelpers } from '../../elasticsearch/legacy';
import * as kbnTestServer from '../../../../test_utils/kbn_server';
@@ -333,7 +337,7 @@ describe('http service', () => {
it('basePath information for an incoming request is available in legacy server', async () => {
const reqBasePath = '/requests-specific-base-path';
const { http } = await root.setup();
- http.registerOnPreAuth((req, res, toolkit) => {
+ http.registerOnPreRouting((req, res, toolkit) => {
http.basePath.set(req, reqBasePath);
return toolkit.next();
});
@@ -352,7 +356,7 @@ describe('http service', () => {
});
});
});
- describe('elasticsearch', () => {
+ describe('legacy elasticsearch client', () => {
let root: ReturnType;
beforeEach(async () => {
root = kbnTestServer.createRoot({ plugins: { initialize: false } });
@@ -410,5 +414,31 @@ describe('http service', () => {
const [, , clientHeaders] = client;
expect(clientHeaders).toEqual({ authorization: authorizationHeader });
});
+
+ it('forwards 401 errors returned from elasticsearch', async () => {
+ const { http } = await root.setup();
+ const { createRouter } = http;
+
+ const authenticationError = LegacyElasticsearchErrorHelpers.decorateNotAuthorizedError(
+ new (esErrors.AuthenticationException as any)('Authentication Exception', {
+ body: { error: { header: { 'WWW-Authenticate': 'authenticate header' } } },
+ statusCode: 401,
+ })
+ );
+
+ clusterClientInstanceMock.callAsCurrentUser.mockRejectedValue(authenticationError);
+
+ const router = createRouter('/new-platform');
+ router.get({ path: '/', validate: false }, async (context, req, res) => {
+ await context.core.elasticsearch.legacy.client.callAsCurrentUser('ping');
+ return res.ok();
+ });
+
+ await root.start();
+
+ const response = await kbnTestServer.request.get(root, '/new-platform/').expect(401);
+
+ expect(response.header['www-authenticate']).toEqual('authenticate header');
+ });
});
});
diff --git a/src/core/server/http/integration_tests/lifecycle.test.ts b/src/core/server/http/integration_tests/lifecycle.test.ts
index cbab14115ba6b..b9548bf7a8d70 100644
--- a/src/core/server/http/integration_tests/lifecycle.test.ts
+++ b/src/core/server/http/integration_tests/lifecycle.test.ts
@@ -57,20 +57,22 @@ interface StorageData {
expires: number;
}
-describe('OnPreAuth', () => {
+describe('OnPreRouting', () => {
it('supports registering a request interceptor', async () => {
- const { registerOnPreAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
const router = createRouter('/');
router.get({ path: '/', validate: false }, (context, req, res) => res.ok({ body: 'ok' }));
const callingOrder: string[] = [];
- registerOnPreAuth((req, res, t) => {
+ registerOnPreRouting((req, res, t) => {
callingOrder.push('first');
return t.next();
});
- registerOnPreAuth((req, res, t) => {
+ registerOnPreRouting((req, res, t) => {
callingOrder.push('second');
return t.next();
});
@@ -82,7 +84,9 @@ describe('OnPreAuth', () => {
});
it('supports request forwarding to specified url', async () => {
- const { registerOnPreAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
const router = createRouter('/');
router.get({ path: '/initial', validate: false }, (context, req, res) =>
@@ -93,13 +97,13 @@ describe('OnPreAuth', () => {
);
let urlBeforeForwarding;
- registerOnPreAuth((req, res, t) => {
+ registerOnPreRouting((req, res, t) => {
urlBeforeForwarding = ensureRawRequest(req).raw.req.url;
return t.rewriteUrl('/redirectUrl');
});
let urlAfterForwarding;
- registerOnPreAuth((req, res, t) => {
+ registerOnPreRouting((req, res, t) => {
// used by legacy platform
urlAfterForwarding = ensureRawRequest(req).raw.req.url;
return t.next();
@@ -113,6 +117,152 @@ describe('OnPreAuth', () => {
expect(urlAfterForwarding).toBe('/redirectUrl');
});
+ it('supports redirection from the interceptor', async () => {
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
+ const router = createRouter('/');
+
+ const redirectUrl = '/redirectUrl';
+ router.get({ path: '/initial', validate: false }, (context, req, res) => res.ok());
+
+ registerOnPreRouting((req, res, t) =>
+ res.redirected({
+ headers: {
+ location: redirectUrl,
+ },
+ })
+ );
+ await server.start();
+
+ const result = await supertest(innerServer.listener).get('/initial').expect(302);
+
+ expect(result.header.location).toBe(redirectUrl);
+ });
+
+ it('supports rejecting request and adjusting response headers', async () => {
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
+ const router = createRouter('/');
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok());
+
+ registerOnPreRouting((req, res, t) =>
+ res.unauthorized({
+ headers: {
+ 'www-authenticate': 'challenge',
+ },
+ })
+ );
+ await server.start();
+
+ const result = await supertest(innerServer.listener).get('/').expect(401);
+
+ expect(result.header['www-authenticate']).toBe('challenge');
+ });
+
+ it('does not expose error details if interceptor throws', async () => {
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
+ const router = createRouter('/');
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok());
+
+ registerOnPreRouting((req, res, t) => {
+ throw new Error('reason');
+ });
+ await server.start();
+
+ const result = await supertest(innerServer.listener).get('/').expect(500);
+
+ expect(result.body.message).toBe('An internal server error occurred.');
+ expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(`
+ Array [
+ Array [
+ [Error: reason],
+ ],
+ ]
+ `);
+ });
+
+ it('returns internal error if interceptor returns unexpected result', async () => {
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
+ const router = createRouter('/');
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok());
+
+ registerOnPreRouting((req, res, t) => ({} as any));
+ await server.start();
+
+ const result = await supertest(innerServer.listener).get('/').expect(500);
+
+ expect(result.body.message).toBe('An internal server error occurred.');
+ expect(loggingSystemMock.collect(logger).error).toMatchInlineSnapshot(`
+ Array [
+ Array [
+ [Error: Unexpected result from OnPreRouting. Expected OnPreRoutingResult or KibanaResponse, but given: [object Object].],
+ ],
+ ]
+ `);
+ });
+
+ it(`doesn't share request object between interceptors`, async () => {
+ const { registerOnPreRouting, server: innerServer, createRouter } = await server.setup(
+ setupDeps
+ );
+ const router = createRouter('/');
+
+ registerOnPreRouting((req, res, t) => {
+ // don't complain customField is not defined on Request type
+ (req as any).customField = { value: 42 };
+ return t.next();
+ });
+ registerOnPreRouting((req, res, t) => {
+ // don't complain customField is not defined on Request type
+ if (typeof (req as any).customField !== 'undefined') {
+ throw new Error('Request object was mutated');
+ }
+ return t.next();
+ });
+ router.get({ path: '/', validate: false }, (context, req, res) =>
+ // don't complain customField is not defined on Request type
+ res.ok({ body: { customField: String((req as any).customField) } })
+ );
+
+ await server.start();
+
+ await supertest(innerServer.listener).get('/').expect(200, { customField: 'undefined' });
+ });
+});
+
+describe('OnPreAuth', () => {
+ it('supports registering a request interceptor', async () => {
+ const { registerOnPreAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
+ const router = createRouter('/');
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok({ body: 'ok' }));
+
+ const callingOrder: string[] = [];
+ registerOnPreAuth((req, res, t) => {
+ callingOrder.push('first');
+ return t.next();
+ });
+
+ registerOnPreAuth((req, res, t) => {
+ callingOrder.push('second');
+ return t.next();
+ });
+ await server.start();
+
+ await supertest(innerServer.listener).get('/').expect(200, 'ok');
+
+ expect(callingOrder).toEqual(['first', 'second']);
+ });
+
it('supports redirection from the interceptor', async () => {
const { registerOnPreAuth, server: innerServer, createRouter } = await server.setup(setupDeps);
const router = createRouter('/');
@@ -203,20 +353,20 @@ describe('OnPreAuth', () => {
const router = createRouter('/');
registerOnPreAuth((req, res, t) => {
- // don't complain customField is not defined on Request type
- (req as any).customField = { value: 42 };
+ // @ts-expect-error customField property is not defined on request object
+ req.customField = { value: 42 };
return t.next();
});
registerOnPreAuth((req, res, t) => {
- // don't complain customField is not defined on Request type
- if (typeof (req as any).customField !== 'undefined') {
+ // @ts-expect-error customField property is not defined on request object
+ if (typeof req.customField !== 'undefined') {
throw new Error('Request object was mutated');
}
return t.next();
});
router.get({ path: '/', validate: false }, (context, req, res) =>
- // don't complain customField is not defined on Request type
- res.ok({ body: { customField: String((req as any).customField) } })
+ // @ts-expect-error customField property is not defined on request object
+ res.ok({ body: { customField: String(req.customField) } })
);
await server.start();
@@ -664,7 +814,7 @@ describe('Auth', () => {
it.skip('is the only place with access to the authorization header', async () => {
const {
- registerOnPreAuth,
+ registerOnPreRouting,
registerAuth,
registerOnPostAuth,
server: innerServer,
@@ -672,9 +822,9 @@ describe('Auth', () => {
} = await server.setup(setupDeps);
const router = createRouter('/');
- let fromRegisterOnPreAuth;
- await registerOnPreAuth((req, res, toolkit) => {
- fromRegisterOnPreAuth = req.headers.authorization;
+ let fromregisterOnPreRouting;
+ await registerOnPreRouting((req, res, toolkit) => {
+ fromregisterOnPreRouting = req.headers.authorization;
return toolkit.next();
});
@@ -701,7 +851,7 @@ describe('Auth', () => {
const token = 'Basic: user:password';
await supertest(innerServer.listener).get('/').set('Authorization', token).expect(200);
- expect(fromRegisterOnPreAuth).toEqual({});
+ expect(fromregisterOnPreRouting).toEqual({});
expect(fromRegisterAuth).toEqual({ authorization: token });
expect(fromRegisterOnPostAuth).toEqual({});
expect(fromRouteHandler).toEqual({});
@@ -1137,3 +1287,135 @@ describe('OnPreResponse', () => {
expect(requestBody).toStrictEqual({});
});
});
+
+describe('run interceptors in the right order', () => {
+ it('with Auth registered', async () => {
+ const {
+ registerOnPreRouting,
+ registerOnPreAuth,
+ registerAuth,
+ registerOnPostAuth,
+ registerOnPreResponse,
+ server: innerServer,
+ createRouter,
+ } = await server.setup(setupDeps);
+
+ const router = createRouter('/');
+
+ const executionOrder: string[] = [];
+ registerOnPreRouting((req, res, t) => {
+ executionOrder.push('onPreRouting');
+ return t.next();
+ });
+ registerOnPreAuth((req, res, t) => {
+ executionOrder.push('onPreAuth');
+ return t.next();
+ });
+ registerAuth((req, res, t) => {
+ executionOrder.push('auth');
+ return t.authenticated({});
+ });
+ registerOnPostAuth((req, res, t) => {
+ executionOrder.push('onPostAuth');
+ return t.next();
+ });
+ registerOnPreResponse((req, res, t) => {
+ executionOrder.push('onPreResponse');
+ return t.next();
+ });
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok({ body: 'ok' }));
+
+ await server.start();
+
+ await supertest(innerServer.listener).get('/').expect(200);
+ expect(executionOrder).toEqual([
+ 'onPreRouting',
+ 'onPreAuth',
+ 'auth',
+ 'onPostAuth',
+ 'onPreResponse',
+ ]);
+ });
+
+ it('with no Auth registered', async () => {
+ const {
+ registerOnPreRouting,
+ registerOnPreAuth,
+ registerOnPostAuth,
+ registerOnPreResponse,
+ server: innerServer,
+ createRouter,
+ } = await server.setup(setupDeps);
+
+ const router = createRouter('/');
+
+ const executionOrder: string[] = [];
+ registerOnPreRouting((req, res, t) => {
+ executionOrder.push('onPreRouting');
+ return t.next();
+ });
+ registerOnPreAuth((req, res, t) => {
+ executionOrder.push('onPreAuth');
+ return t.next();
+ });
+ registerOnPostAuth((req, res, t) => {
+ executionOrder.push('onPostAuth');
+ return t.next();
+ });
+ registerOnPreResponse((req, res, t) => {
+ executionOrder.push('onPreResponse');
+ return t.next();
+ });
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok({ body: 'ok' }));
+
+ await server.start();
+
+ await supertest(innerServer.listener).get('/').expect(200);
+ expect(executionOrder).toEqual(['onPreRouting', 'onPreAuth', 'onPostAuth', 'onPreResponse']);
+ });
+
+ it('when a user failed auth', async () => {
+ const {
+ registerOnPreRouting,
+ registerOnPreAuth,
+ registerOnPostAuth,
+ registerAuth,
+ registerOnPreResponse,
+ server: innerServer,
+ createRouter,
+ } = await server.setup(setupDeps);
+
+ const router = createRouter('/');
+
+ const executionOrder: string[] = [];
+ registerOnPreRouting((req, res, t) => {
+ executionOrder.push('onPreRouting');
+ return t.next();
+ });
+ registerOnPreAuth((req, res, t) => {
+ executionOrder.push('onPreAuth');
+ return t.next();
+ });
+ registerAuth((req, res, t) => {
+ executionOrder.push('auth');
+ return res.forbidden();
+ });
+ registerOnPostAuth((req, res, t) => {
+ executionOrder.push('onPostAuth');
+ return t.next();
+ });
+ registerOnPreResponse((req, res, t) => {
+ executionOrder.push('onPreResponse');
+ return t.next();
+ });
+
+ router.get({ path: '/', validate: false }, (context, req, res) => res.ok({ body: 'ok' }));
+
+ await server.start();
+
+ await supertest(innerServer.listener).get('/').expect(403);
+ expect(executionOrder).toEqual(['onPreRouting', 'onPreAuth', 'auth', 'onPreResponse']);
+ });
+});
diff --git a/src/core/server/http/lifecycle/on_pre_auth.ts b/src/core/server/http/lifecycle/on_pre_auth.ts
index dc2ae6922fb94..f76fe87fd14a3 100644
--- a/src/core/server/http/lifecycle/on_pre_auth.ts
+++ b/src/core/server/http/lifecycle/on_pre_auth.ts
@@ -29,33 +29,21 @@ import {
enum ResultType {
next = 'next',
- rewriteUrl = 'rewriteUrl',
}
interface Next {
type: ResultType.next;
}
-interface RewriteUrl {
- type: ResultType.rewriteUrl;
- url: string;
-}
-
-type OnPreAuthResult = Next | RewriteUrl;
+type OnPreAuthResult = Next;
const preAuthResult = {
next(): OnPreAuthResult {
return { type: ResultType.next };
},
- rewriteUrl(url: string): OnPreAuthResult {
- return { type: ResultType.rewriteUrl, url };
- },
isNext(result: OnPreAuthResult): result is Next {
return result && result.type === ResultType.next;
},
- isRewriteUrl(result: OnPreAuthResult): result is RewriteUrl {
- return result && result.type === ResultType.rewriteUrl;
- },
};
/**
@@ -65,13 +53,10 @@ const preAuthResult = {
export interface OnPreAuthToolkit {
/** To pass request to the next handler */
next: () => OnPreAuthResult;
- /** Rewrite requested resources url before is was authenticated and routed to a handler */
- rewriteUrl: (url: string) => OnPreAuthResult;
}
const toolkit: OnPreAuthToolkit = {
next: preAuthResult.next,
- rewriteUrl: preAuthResult.rewriteUrl,
};
/**
@@ -88,9 +73,9 @@ export type OnPreAuthHandler = (
* @public
* Adopt custom request interceptor to Hapi lifecycle system.
* @param fn - an extension point allowing to perform custom logic for
- * incoming HTTP requests.
+ * incoming HTTP requests before a user has been authenticated.
*/
-export function adoptToHapiOnPreAuthFormat(fn: OnPreAuthHandler, log: Logger) {
+export function adoptToHapiOnPreAuth(fn: OnPreAuthHandler, log: Logger) {
return async function interceptPreAuthRequest(
request: Request,
responseToolkit: HapiResponseToolkit
@@ -107,13 +92,6 @@ export function adoptToHapiOnPreAuthFormat(fn: OnPreAuthHandler, log: Logger) {
return responseToolkit.continue;
}
- if (preAuthResult.isRewriteUrl(result)) {
- const { url } = result;
- request.setUrl(url);
- // We should update raw request as well since it can be proxied to the old platform
- request.raw.req.url = url;
- return responseToolkit.continue;
- }
throw new Error(
`Unexpected result from OnPreAuth. Expected OnPreAuthResult or KibanaResponse, but given: ${result}.`
);
diff --git a/src/core/server/http/lifecycle/on_pre_response.ts b/src/core/server/http/lifecycle/on_pre_response.ts
index 9c8c6fba690d1..4d1b53313a51f 100644
--- a/src/core/server/http/lifecycle/on_pre_response.ts
+++ b/src/core/server/http/lifecycle/on_pre_response.ts
@@ -64,7 +64,7 @@ const preResponseResult = {
};
/**
- * A tool set defining an outcome of OnPreAuth interceptor for incoming request.
+ * A tool set defining an outcome of OnPreResponse interceptor for incoming request.
* @public
*/
export interface OnPreResponseToolkit {
@@ -77,7 +77,7 @@ const toolkit: OnPreResponseToolkit = {
};
/**
- * See {@link OnPreAuthToolkit}.
+ * See {@link OnPreRoutingToolkit}.
* @public
*/
export type OnPreResponseHandler = (
diff --git a/src/core/server/http/lifecycle/on_pre_routing.ts b/src/core/server/http/lifecycle/on_pre_routing.ts
new file mode 100644
index 0000000000000..e62eb54f2398f
--- /dev/null
+++ b/src/core/server/http/lifecycle/on_pre_routing.ts
@@ -0,0 +1,125 @@
+/*
+ * 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 { Lifecycle, Request, ResponseToolkit as HapiResponseToolkit } from 'hapi';
+import { Logger } from '../../logging';
+import {
+ HapiResponseAdapter,
+ KibanaRequest,
+ KibanaResponse,
+ lifecycleResponseFactory,
+ LifecycleResponseFactory,
+} from '../router';
+
+enum ResultType {
+ next = 'next',
+ rewriteUrl = 'rewriteUrl',
+}
+
+interface Next {
+ type: ResultType.next;
+}
+
+interface RewriteUrl {
+ type: ResultType.rewriteUrl;
+ url: string;
+}
+
+type OnPreRoutingResult = Next | RewriteUrl;
+
+const preRoutingResult = {
+ next(): OnPreRoutingResult {
+ return { type: ResultType.next };
+ },
+ rewriteUrl(url: string): OnPreRoutingResult {
+ return { type: ResultType.rewriteUrl, url };
+ },
+ isNext(result: OnPreRoutingResult): result is Next {
+ return result && result.type === ResultType.next;
+ },
+ isRewriteUrl(result: OnPreRoutingResult): result is RewriteUrl {
+ return result && result.type === ResultType.rewriteUrl;
+ },
+};
+
+/**
+ * @public
+ * A tool set defining an outcome of OnPreRouting interceptor for incoming request.
+ */
+export interface OnPreRoutingToolkit {
+ /** To pass request to the next handler */
+ next: () => OnPreRoutingResult;
+ /** Rewrite requested resources url before is was authenticated and routed to a handler */
+ rewriteUrl: (url: string) => OnPreRoutingResult;
+}
+
+const toolkit: OnPreRoutingToolkit = {
+ next: preRoutingResult.next,
+ rewriteUrl: preRoutingResult.rewriteUrl,
+};
+
+/**
+ * See {@link OnPreRoutingToolkit}.
+ * @public
+ */
+export type OnPreRoutingHandler = (
+ request: KibanaRequest,
+ response: LifecycleResponseFactory,
+ toolkit: OnPreRoutingToolkit
+) => OnPreRoutingResult | KibanaResponse | Promise;
+
+/**
+ * @public
+ * Adopt custom request interceptor to Hapi lifecycle system.
+ * @param fn - an extension point allowing to perform custom logic for
+ * incoming HTTP requests.
+ */
+export function adoptToHapiOnRequest(fn: OnPreRoutingHandler, log: Logger) {
+ return async function interceptPreRoutingRequest(
+ request: Request,
+ responseToolkit: HapiResponseToolkit
+ ): Promise {
+ const hapiResponseAdapter = new HapiResponseAdapter(responseToolkit);
+
+ try {
+ const result = await fn(KibanaRequest.from(request), lifecycleResponseFactory, toolkit);
+ if (result instanceof KibanaResponse) {
+ return hapiResponseAdapter.handle(result);
+ }
+
+ if (preRoutingResult.isNext(result)) {
+ return responseToolkit.continue;
+ }
+
+ if (preRoutingResult.isRewriteUrl(result)) {
+ const { url } = result;
+ request.setUrl(url);
+ // We should update raw request as well since it can be proxied to the old platform
+ request.raw.req.url = url;
+ return responseToolkit.continue;
+ }
+ throw new Error(
+ `Unexpected result from OnPreRouting. Expected OnPreRoutingResult or KibanaResponse, but given: ${result}.`
+ );
+ } catch (error) {
+ log.error(error);
+ return hapiResponseAdapter.toInternalError();
+ }
+ };
+}
diff --git a/src/core/server/http/router/router.ts b/src/core/server/http/router/router.ts
index 69402a74eda5f..35eec746163ce 100644
--- a/src/core/server/http/router/router.ts
+++ b/src/core/server/http/router/router.ts
@@ -22,6 +22,7 @@ import Boom from 'boom';
import { isConfigSchema } from '@kbn/config-schema';
import { Logger } from '../../logging';
+import { LegacyElasticsearchErrorHelpers } from '../../elasticsearch/legacy/errors';
import { KibanaRequest } from './request';
import { KibanaResponseFactory, kibanaResponseFactory, IKibanaResponse } from './response';
import { RouteConfig, RouteConfigOptions, RouteMethod, validBodyOutput } from './route';
@@ -263,6 +264,10 @@ export class Router implements IRouter {
return hapiResponseAdapter.handle(kibanaResponse);
} catch (e) {
this.log.error(e);
+ // forward 401 (boom) error from ES
+ if (LegacyElasticsearchErrorHelpers.isNotAuthorizedError(e)) {
+ return e;
+ }
return hapiResponseAdapter.toInternalError();
}
}
diff --git a/src/core/server/http/types.ts b/src/core/server/http/types.ts
index 241af1a3020cb..3df098a1df00d 100644
--- a/src/core/server/http/types.ts
+++ b/src/core/server/http/types.ts
@@ -25,6 +25,7 @@ import { HttpServerSetup } from './http_server';
import { SessionStorageCookieOptions } from './cookie_session_storage';
import { SessionStorageFactory } from './session_storage';
import { AuthenticationHandler } from './lifecycle/auth';
+import { OnPreRoutingHandler } from './lifecycle/on_pre_routing';
import { OnPreAuthHandler } from './lifecycle/on_pre_auth';
import { OnPostAuthHandler } from './lifecycle/on_post_auth';
import { OnPreResponseHandler } from './lifecycle/on_pre_response';
@@ -145,15 +146,26 @@ export interface HttpServiceSetup {
) => Promise>;
/**
- * To define custom logic to perform for incoming requests.
+ * To define custom logic to perform for incoming requests before server performs a route lookup.
*
* @remarks
- * Runs the handler before Auth interceptor performs a check that user has access to requested resources, so it's the
- * only place when you can forward a request to another URL right on the server.
- * Can register any number of registerOnPostAuth, which are called in sequence
+ * It's the only place when you can forward a request to another URL right on the server.
+ * Can register any number of registerOnPreRouting, which are called in sequence
+ * (from the first registered to the last). See {@link OnPreRoutingHandler}.
+ *
+ * @param handler {@link OnPreRoutingHandler} - function to call.
+ */
+ registerOnPreRouting: (handler: OnPreRoutingHandler) => void;
+
+ /**
+ * To define custom logic to perform for incoming requests before
+ * the Auth interceptor performs a check that user has access to requested resources.
+ *
+ * @remarks
+ * Can register any number of registerOnPreAuth, which are called in sequence
* (from the first registered to the last). See {@link OnPreAuthHandler}.
*
- * @param handler {@link OnPreAuthHandler} - function to call.
+ * @param handler {@link OnPreRoutingHandler} - function to call.
*/
registerOnPreAuth: (handler: OnPreAuthHandler) => void;
@@ -170,13 +182,11 @@ export interface HttpServiceSetup {
registerAuth: (handler: AuthenticationHandler) => void;
/**
- * To define custom logic to perform for incoming requests.
+ * To define custom logic after Auth interceptor did make sure a user has access to the requested resource.
*
* @remarks
- * Runs the handler after Auth interceptor
- * did make sure a user has access to the requested resource.
* The auth state is available at stage via http.auth.get(..)
- * Can register any number of registerOnPreAuth, which are called in sequence
+ * Can register any number of registerOnPostAuth, which are called in sequence
* (from the first registered to the last). See {@link OnPostAuthHandler}.
*
* @param handler {@link OnPostAuthHandler} - function to call.
diff --git a/src/core/server/index.ts b/src/core/server/index.ts
index dcaa5f2367214..706ec88c6ebfd 100644
--- a/src/core/server/index.ts
+++ b/src/core/server/index.ts
@@ -148,6 +148,8 @@ export {
LegacyRequest,
OnPreAuthHandler,
OnPreAuthToolkit,
+ OnPreRoutingHandler,
+ OnPreRoutingToolkit,
OnPostAuthHandler,
OnPostAuthToolkit,
OnPreResponseHandler,
diff --git a/src/core/server/legacy/legacy_service.ts b/src/core/server/legacy/legacy_service.ts
index 6b34a4eb58319..fada40e773f12 100644
--- a/src/core/server/legacy/legacy_service.ts
+++ b/src/core/server/legacy/legacy_service.ts
@@ -301,6 +301,7 @@ export class LegacyService implements CoreService {
),
createRouter: () => router,
resources: setupDeps.core.httpResources.createRegistrar(router),
+ registerOnPreRouting: setupDeps.core.http.registerOnPreRouting,
registerOnPreAuth: setupDeps.core.http.registerOnPreAuth,
registerAuth: setupDeps.core.http.registerAuth,
registerOnPostAuth: setupDeps.core.http.registerOnPostAuth,
diff --git a/src/core/server/path/index.test.ts b/src/core/server/path/index.test.ts
index 048622e1f7eab..522e100d85e5d 100644
--- a/src/core/server/path/index.test.ts
+++ b/src/core/server/path/index.test.ts
@@ -18,7 +18,7 @@
*/
import { accessSync, constants } from 'fs';
-import { getConfigPath, getDataPath } from './';
+import { getConfigPath, getDataPath, getConfigDirectory } from './';
describe('Default path finder', () => {
it('should find a kibana.yml', () => {
@@ -30,4 +30,9 @@ describe('Default path finder', () => {
const dataPath = getDataPath();
expect(() => accessSync(dataPath, constants.R_OK)).not.toThrow();
});
+
+ it('should find a config directory', () => {
+ const configDirectory = getConfigDirectory();
+ expect(() => accessSync(configDirectory, constants.R_OK)).not.toThrow();
+ });
});
diff --git a/src/core/server/path/index.ts b/src/core/server/path/index.ts
index 2e05e3856bd4c..1bb650518c47a 100644
--- a/src/core/server/path/index.ts
+++ b/src/core/server/path/index.ts
@@ -30,6 +30,10 @@ const CONFIG_PATHS = [
fromRoot('config/kibana.yml'),
].filter(isString);
+const CONFIG_DIRECTORIES = [process.env.KIBANA_PATH_CONF, fromRoot('config'), '/etc/kibana'].filter(
+ isString
+);
+
const DATA_PATHS = [
process.env.DATA_PATH, // deprecated
fromRoot('data'),
@@ -49,12 +53,19 @@ function findFile(paths: string[]) {
}
/**
- * Get the path where the config files are stored
+ * Get the path of kibana.yml
* @internal
*/
export const getConfigPath = () => findFile(CONFIG_PATHS);
+
+/**
+ * Get the directory containing configuration files
+ * @internal
+ */
+export const getConfigDirectory = () => findFile(CONFIG_DIRECTORIES);
+
/**
- * Get the path where the data can be stored
+ * Get the directory containing runtime data
* @internal
*/
export const getDataPath = () => findFile(DATA_PATHS);
diff --git a/src/core/server/plugins/plugin_context.ts b/src/core/server/plugins/plugin_context.ts
index a6dd13a12b527..c17b8df8bb52c 100644
--- a/src/core/server/plugins/plugin_context.ts
+++ b/src/core/server/plugins/plugin_context.ts
@@ -157,6 +157,7 @@ export function createPluginSetupContext(
),
createRouter: () => router,
resources: deps.httpResources.createRegistrar(router),
+ registerOnPreRouting: deps.http.registerOnPreRouting,
registerOnPreAuth: deps.http.registerOnPreAuth,
registerAuth: deps.http.registerAuth,
registerOnPostAuth: deps.http.registerOnPostAuth,
diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md
index 3d3e1905577d9..886544a4df317 100644
--- a/src/core/server/server.api.md
+++ b/src/core/server/server.api.md
@@ -811,6 +811,7 @@ export interface HttpServiceSetup {
registerOnPostAuth: (handler: OnPostAuthHandler) => void;
registerOnPreAuth: (handler: OnPreAuthHandler) => void;
registerOnPreResponse: (handler: OnPreResponseHandler) => void;
+ registerOnPreRouting: (handler: OnPreRoutingHandler) => void;
registerRouteHandlerContext: (contextName: T, provider: RequestHandlerContextProvider) => RequestHandlerContextContainer;
}
@@ -1536,7 +1537,6 @@ export type OnPreAuthHandler = (request: KibanaRequest, response: LifecycleRespo
// @public
export interface OnPreAuthToolkit {
next: () => OnPreAuthResult;
- rewriteUrl: (url: string) => OnPreAuthResult;
}
// @public
@@ -1560,6 +1560,17 @@ export interface OnPreResponseToolkit {
next: (responseExtensions?: OnPreResponseExtensions) => OnPreResponseResult;
}
+// Warning: (ae-forgotten-export) The symbol "OnPreRoutingResult" needs to be exported by the entry point index.d.ts
+//
+// @public
+export type OnPreRoutingHandler = (request: KibanaRequest, response: LifecycleResponseFactory, toolkit: OnPreRoutingToolkit) => OnPreRoutingResult | KibanaResponse | Promise;
+
+// @public
+export interface OnPreRoutingToolkit {
+ next: () => OnPreRoutingResult;
+ rewriteUrl: (url: string) => OnPreRoutingResult;
+}
+
// @public
export interface OpsMetrics {
concurrent_connections: OpsServerMetrics['concurrent_connections'];
diff --git a/src/dev/build/tasks/bin/scripts/kibana b/src/dev/build/tasks/bin/scripts/kibana
index 558facb9da32b..3283e17008e7c 100755
--- a/src/dev/build/tasks/bin/scripts/kibana
+++ b/src/dev/build/tasks/bin/scripts/kibana
@@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do
done
DIR="$(dirname "${SCRIPT}")/.."
+CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"}
NODE="${DIR}/node/bin/node"
test -x "$NODE"
if [ ! -x "$NODE" ]; then
@@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then
exit 1
fi
-NODE_OPTIONS="--no-warnings --max-http-header-size=65536 ${NODE_OPTIONS}" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli" ${@}
+if [ -f "${CONFIG_DIR}/node.options" ]; then
+ KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)"
+fi
+
+NODE_OPTIONS="--no-warnings --max-http-header-size=65536 $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli" ${@}
diff --git a/src/dev/build/tasks/bin/scripts/kibana-keystore b/src/dev/build/tasks/bin/scripts/kibana-keystore
index 43800c7b895d3..f83df118d24e8 100755
--- a/src/dev/build/tasks/bin/scripts/kibana-keystore
+++ b/src/dev/build/tasks/bin/scripts/kibana-keystore
@@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do
done
DIR="$(dirname "${SCRIPT}")/.."
+CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"}
NODE="${DIR}/node/bin/node"
test -x "$NODE"
if [ ! -x "$NODE" ]; then
@@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then
exit 1
fi
-"${NODE}" "${DIR}/src/cli_keystore" "$@"
+if [ -f "${CONFIG_DIR}/node.options" ]; then
+ KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)"
+fi
+
+NODE_OPTIONS="$KBN_NODE_OPTS $NODE_OPTIONS" "${NODE}" "${DIR}/src/cli_keystore" "$@"
diff --git a/src/dev/build/tasks/bin/scripts/kibana-keystore.bat b/src/dev/build/tasks/bin/scripts/kibana-keystore.bat
old mode 100644
new mode 100755
index b8311db2cfae5..389eb5bf488e4
--- a/src/dev/build/tasks/bin/scripts/kibana-keystore.bat
+++ b/src/dev/build/tasks/bin/scripts/kibana-keystore.bat
@@ -1,6 +1,6 @@
@echo off
-SETLOCAL
+SETLOCAL ENABLEDELAYEDEXPANSION
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI
@@ -12,6 +12,21 @@ If Not Exist "%NODE%" (
Exit /B 1
)
+set CONFIG_DIR=%KIBANA_PATH_CONF%
+If [%KIBANA_PATH_CONF%] == [] (
+ set CONFIG_DIR=%DIR%\config
+)
+
+IF EXIST "%CONFIG_DIR%\node.options" (
+ for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do (
+ If [!NODE_OPTIONS!] == [] (
+ set "NODE_OPTIONS=%%i"
+ ) Else (
+ set "NODE_OPTIONS=!NODE_OPTIONS! %%i"
+ )
+ )
+)
+
TITLE Kibana Keystore
"%NODE%" "%DIR%\src\cli_keystore" %*
diff --git a/src/dev/build/tasks/bin/scripts/kibana-plugin b/src/dev/build/tasks/bin/scripts/kibana-plugin
index b843d4966c6d1..f1102e1ef5a32 100755
--- a/src/dev/build/tasks/bin/scripts/kibana-plugin
+++ b/src/dev/build/tasks/bin/scripts/kibana-plugin
@@ -14,6 +14,7 @@ while [ -h "$SCRIPT" ] ; do
done
DIR="$(dirname "${SCRIPT}")/.."
+CONFIG_DIR=${KIBANA_PATH_CONF:-"$DIR/config"}
NODE="${DIR}/node/bin/node"
test -x "$NODE"
if [ ! -x "$NODE" ]; then
@@ -21,4 +22,8 @@ if [ ! -x "$NODE" ]; then
exit 1
fi
-NODE_OPTIONS="--no-warnings ${NODE_OPTIONS}" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli_plugin" "$@"
+if [ -f "${CONFIG_DIR}/node.options" ]; then
+ KBN_NODE_OPTS="$(grep -v ^# < ${CONFIG_DIR}/node.options | xargs)"
+fi
+
+NODE_OPTIONS="--no-warnings $KBN_NODE_OPTS $NODE_OPTIONS" NODE_ENV=production exec "${NODE}" "${DIR}/src/cli_plugin" "$@"
diff --git a/src/dev/build/tasks/bin/scripts/kibana-plugin.bat b/src/dev/build/tasks/bin/scripts/kibana-plugin.bat
index bf382a0657ade..6815b1b9eab8c 100755
--- a/src/dev/build/tasks/bin/scripts/kibana-plugin.bat
+++ b/src/dev/build/tasks/bin/scripts/kibana-plugin.bat
@@ -1,6 +1,6 @@
@echo off
-SETLOCAL
+SETLOCAL ENABLEDELAYEDEXPANSION
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI
@@ -13,9 +13,26 @@ If Not Exist "%NODE%" (
Exit /B 1
)
-TITLE Kibana Server
+set CONFIG_DIR=%KIBANA_PATH_CONF%
+If [%KIBANA_PATH_CONF%] == [] (
+ set CONFIG_DIR=%DIR%\config
+)
+
+IF EXIST "%CONFIG_DIR%\node.options" (
+ for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do (
+ If [!NODE_OPTIONS!] == [] (
+ set "NODE_OPTIONS=%%i"
+ ) Else (
+ set "NODE_OPTIONS=!NODE_OPTIONS! %%i"
+ )
+ )
+)
+
+:: Include pre-defined node option
+set "NODE_OPTIONS=--no-warnings %NODE_OPTIONS%"
-set "NODE_OPTIONS=--no-warnings %NODE_OPTIONS%" && "%NODE%" "%DIR%\src\cli_plugin" %*
+TITLE Kibana Server
+"%NODE%" "%DIR%\src\cli_plugin" %*
:finally
diff --git a/src/dev/build/tasks/bin/scripts/kibana.bat b/src/dev/build/tasks/bin/scripts/kibana.bat
index 9d8ba359e53af..d3edc92f110a5 100755
--- a/src/dev/build/tasks/bin/scripts/kibana.bat
+++ b/src/dev/build/tasks/bin/scripts/kibana.bat
@@ -1,6 +1,6 @@
@echo off
-SETLOCAL
+SETLOCAL ENABLEDELAYEDEXPANSION
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI
@@ -14,7 +14,27 @@ If Not Exist "%NODE%" (
Exit /B 1
)
-set "NODE_OPTIONS=--no-warnings --max-http-header-size=65536 %NODE_OPTIONS%" && "%NODE%" "%DIR%\src\cli" %*
+set CONFIG_DIR=%KIBANA_PATH_CONF%
+If [%KIBANA_PATH_CONF%] == [] (
+ set CONFIG_DIR=%DIR%\config
+)
+
+IF EXIST "%CONFIG_DIR%\node.options" (
+ for /F "eol=# tokens=*" %%i in (%CONFIG_DIR%\node.options) do (
+ If [!NODE_OPTIONS!] == [] (
+ set "NODE_OPTIONS=%%i"
+ ) Else (
+ set "NODE_OPTIONS=!NODE_OPTIONS! %%i"
+ )
+ )
+)
+
+:: Include pre-defined node option
+set "NODE_OPTIONS=--no-warnings --max-http-header-size=65536 %NODE_OPTIONS%"
+
+:: This should run independently as the last instruction
+:: as we need NODE_OPTIONS previously set to expand
+"%NODE%" "%DIR%\src\cli" %*
:finally
diff --git a/src/dev/build/tasks/copy_source_task.js b/src/dev/build/tasks/copy_source_task.js
index 32eb7bf8712e3..e34f05bd6cfff 100644
--- a/src/dev/build/tasks/copy_source_task.js
+++ b/src/dev/build/tasks/copy_source_task.js
@@ -43,6 +43,7 @@ export const CopySourceTask = {
'typings/**',
'webpackShims/**',
'config/kibana.yml',
+ 'config/node.options',
'tsconfig*.json',
'.i18nrc.json',
'kibana.d.ts',
diff --git a/src/dev/build/tasks/os_packages/package_scripts/post_install.sh b/src/dev/build/tasks/os_packages/package_scripts/post_install.sh
index 9cf08ea38254d..10f11ff51874e 100644
--- a/src/dev/build/tasks/os_packages/package_scripts/post_install.sh
+++ b/src/dev/build/tasks/os_packages/package_scripts/post_install.sh
@@ -1,6 +1,8 @@
#!/bin/sh
set -e
+export KBN_PATH_CONF=${KBN_PATH_CONF:-<%= configDir %>}
+
case $1 in
# Debian
configure)
@@ -35,4 +37,10 @@ case $1 in
esac
chown -R <%= user %>:<%= group %> <%= dataDir %>
-chown <%= user %>:<%= group %> <%= pluginsDir %>
+chmod 2750 <%= dataDir %>
+chmod -R 2755 <%= dataDir %>/*
+
+chown :<%= group %> ${KBN_PATH_CONF}
+chown :<%= group %> ${KBN_PATH_CONF}/kibana.yml
+chmod 2750 ${KBN_PATH_CONF}
+chmod 660 ${KBN_PATH_CONF}/kibana.yml
diff --git a/src/dev/build/tasks/os_packages/service_templates/sysv/etc/init.d/kibana b/src/dev/build/tasks/os_packages/service_templates/sysv/etc/init.d/kibana
index d935dc6e31f80..8facbb709cc5c 100755
--- a/src/dev/build/tasks/os_packages/service_templates/sysv/etc/init.d/kibana
+++ b/src/dev/build/tasks/os_packages/service_templates/sysv/etc/init.d/kibana
@@ -39,7 +39,7 @@ emit() {
start() {
[ ! -d "/var/log/kibana/" ] && mkdir "/var/log/kibana/"
chown "$user":"$group" "/var/log/kibana/"
- chmod 755 "/var/log/kibana/"
+ chmod 2750 "/var/log/kibana/"
[ ! -d "/var/run/kibana/" ] && mkdir "/var/run/kibana/"
chown "$user":"$group" "/var/run/kibana/"
diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts
index 8e862b5692ca3..e9b4629ba88cf 100644
--- a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts
+++ b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.test.ts
@@ -316,6 +316,83 @@ describe('Terms Agg Other bucket helper', () => {
}
});
+ test('excludes exists filter for scripted fields', () => {
+ const aggConfigs = getAggConfigs(nestedTerm.aggs);
+ aggConfigs.aggs[1].params.field.scripted = true;
+ const agg = buildOtherBucketAgg(
+ aggConfigs,
+ aggConfigs.aggs[1] as IBucketAggConfig,
+ nestedTermResponse
+ );
+ const expectedResponse = {
+ 'other-filter': {
+ aggs: undefined,
+ filters: {
+ filters: {
+ '-IN': {
+ bool: {
+ must: [],
+ filter: [{ match_phrase: { 'geo.src': 'IN' } }],
+ should: [],
+ must_not: [
+ {
+ script: {
+ script: {
+ lang: undefined,
+ params: { value: 'ios' },
+ source: '(undefined) == value',
+ },
+ },
+ },
+ {
+ script: {
+ script: {
+ lang: undefined,
+ params: { value: 'win xp' },
+ source: '(undefined) == value',
+ },
+ },
+ },
+ ],
+ },
+ },
+ '-US': {
+ bool: {
+ must: [],
+ filter: [{ match_phrase: { 'geo.src': 'US' } }],
+ should: [],
+ must_not: [
+ {
+ script: {
+ script: {
+ lang: undefined,
+ params: { value: 'ios' },
+ source: '(undefined) == value',
+ },
+ },
+ },
+ {
+ script: {
+ script: {
+ lang: undefined,
+ params: { value: 'win xp' },
+ source: '(undefined) == value',
+ },
+ },
+ },
+ ],
+ },
+ },
+ },
+ },
+ },
+ };
+ expect(agg).toBeDefined();
+ if (agg) {
+ expect(agg()).toEqual(expectedResponse);
+ }
+ });
+
test('returns false when nested terms agg has no buckets', () => {
const aggConfigs = getAggConfigs(nestedTerm.aggs);
const agg = buildOtherBucketAgg(
diff --git a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts
index fba3d35f002af..1a7deafb548ae 100644
--- a/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts
+++ b/src/plugins/data/public/search/aggs/buckets/_terms_other_bucket_helper.ts
@@ -202,10 +202,12 @@ export const buildOtherBucketAgg = (
return;
}
- if (
- !aggWithOtherBucket.params.missingBucket ||
- agg.buckets.some((bucket: { key: string }) => bucket.key === '__missing__')
- ) {
+ const hasScriptedField = !!aggWithOtherBucket.params.field.scripted;
+ const hasMissingBucket = !!aggWithOtherBucket.params.missingBucket;
+ const hasMissingBucketKey = agg.buckets.some(
+ (bucket: { key: string }) => bucket.key === '__missing__'
+ );
+ if (!hasScriptedField && (!hasMissingBucket || hasMissingBucketKey)) {
filters.push(
buildExistsFilter(
aggWithOtherBucket.params.field,
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
index 12cdf13caeb55..e2caca7895c42 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.test.ts
@@ -177,11 +177,27 @@ describe('Filter editor utils', () => {
it('should return true for range filter with from/to', () => {
const isValid = isFilterValid(stubIndexPattern, stubFields[0], isBetweenOperator, {
from: 'foo',
- too: 'goo',
+ to: 'goo',
});
expect(isValid).toBe(true);
});
+ it('should return false for date range filter with bad from', () => {
+ const isValid = isFilterValid(stubIndexPattern, stubFields[4], isBetweenOperator, {
+ from: 'foo',
+ to: 'now',
+ });
+ expect(isValid).toBe(false);
+ });
+
+ it('should return false for date range filter with bad to', () => {
+ const isValid = isFilterValid(stubIndexPattern, stubFields[4], isBetweenOperator, {
+ from: '2020-01-01',
+ to: 'mau',
+ });
+ expect(isValid).toBe(false);
+ });
+
it('should return true for exists filter without params', () => {
const isValid = isFilterValid(stubIndexPattern, stubFields[0], existsOperator);
expect(isValid).toBe(true);
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
index 114be67e490cf..97a59fa69f458 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/lib/filter_editor_utils.ts
@@ -85,7 +85,10 @@ export function isFilterValid(
if (typeof params !== 'object') {
return false;
}
- return validateParams(params.from, field.type) || validateParams(params.to, field.type);
+ return (
+ (!params.from || validateParams(params.from, field.type)) &&
+ (!params.to || validateParams(params.to, field.type))
+ );
case 'exists':
return true;
default:
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx
index 65b842f0bd4aa..bdfd1014625d8 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/range_value_input.tsx
@@ -17,8 +17,9 @@
* under the License.
*/
-import { EuiIcon, EuiLink, EuiFormHelpText, EuiFormControlLayoutDelimited } from '@elastic/eui';
-import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
+import moment from 'moment';
+import { EuiFormControlLayoutDelimited } from '@elastic/eui';
+import { InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { get } from 'lodash';
import React from 'react';
import { useKibana } from '../../../../../kibana_react/public';
@@ -41,8 +42,17 @@ interface Props {
function RangeValueInputUI(props: Props) {
const kibana = useKibana();
- const dataMathDocLink = kibana.services.docLinks!.links.date.dateMath;
const type = props.field ? props.field.type : 'string';
+ const tzConfig = kibana.services.uiSettings!.get('dateFormat:tz');
+
+ const formatDateChange = (value: string | number | boolean) => {
+ if (typeof value !== 'string' && typeof value !== 'number') return value;
+
+ const momentParsedValue = moment(value).tz(tzConfig);
+ if (momentParsedValue.isValid()) return momentParsedValue?.format('YYYY-MM-DDTHH:mm:ss.SSSZ');
+
+ return value;
+ };
const onFromChange = (value: string | number | boolean) => {
if (typeof value !== 'string' && typeof value !== 'number') {
@@ -71,6 +81,9 @@ function RangeValueInputUI(props: Props) {
type={type}
value={props.value ? props.value.from : undefined}
onChange={onFromChange}
+ onBlur={(value) => {
+ onFromChange(formatDateChange(value));
+ }}
placeholder={props.intl.formatMessage({
id: 'data.filter.filterEditor.rangeStartInputPlaceholder',
defaultMessage: 'Start of the range',
@@ -83,6 +96,9 @@ function RangeValueInputUI(props: Props) {
type={type}
value={props.value ? props.value.to : undefined}
onChange={onToChange}
+ onBlur={(value) => {
+ onToChange(formatDateChange(value));
+ }}
placeholder={props.intl.formatMessage({
id: 'data.filter.filterEditor.rangeEndInputPlaceholder',
defaultMessage: 'End of the range',
@@ -90,19 +106,6 @@ function RangeValueInputUI(props: Props) {
/>
}
/>
- {type === 'date' ? (
-
-
- {' '}
-
-
-
- ) : (
- ''
- )}
);
}
diff --git a/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx b/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx
index 3737dae1bf9ef..1a165c78d4d79 100644
--- a/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx
+++ b/src/plugins/data/public/ui/filter_bar/filter_editor/value_input_type.tsx
@@ -27,6 +27,7 @@ interface Props {
value?: string | number;
type: string;
onChange: (value: string | number | boolean) => void;
+ onBlur?: (value: string | number | boolean) => void;
placeholder: string;
intl: InjectedIntl;
controlOnly?: boolean;
@@ -66,6 +67,7 @@ class ValueInputTypeUI extends Component {
placeholder={this.props.placeholder}
value={value}
onChange={this.onChange}
+ onBlur={this.onBlur}
isInvalid={!isEmpty(value) && !validateParams(value, this.props.type)}
controlOnly={this.props.controlOnly}
className={this.props.className}
@@ -126,6 +128,13 @@ class ValueInputTypeUI extends Component {
const params = event.target.value;
this.props.onChange(params);
};
+
+ private onBlur = (event: React.ChangeEvent) => {
+ if (this.props.onBlur) {
+ const params = event.target.value;
+ this.props.onBlur(params);
+ }
+ };
}
export const ValueInputType = injectI18n(ValueInputTypeUI);
diff --git a/src/plugins/maps_legacy/server/index.ts b/src/plugins/maps_legacy/server/index.ts
index 18f58189fc607..5da3ce1a84408 100644
--- a/src/plugins/maps_legacy/server/index.ts
+++ b/src/plugins/maps_legacy/server/index.ts
@@ -17,8 +17,9 @@
* under the License.
*/
-import { PluginConfigDescriptor } from 'kibana/server';
-import { PluginInitializerContext } from 'kibana/public';
+import { Plugin, PluginConfigDescriptor } from 'kibana/server';
+import { PluginInitializerContext } from 'src/core/server';
+import { Observable } from 'rxjs';
import { configSchema, ConfigSchema } from '../config';
export const config: PluginConfigDescriptor = {
@@ -37,13 +38,27 @@ export const config: PluginConfigDescriptor = {
schema: configSchema,
};
-export const plugin = (initializerContext: PluginInitializerContext) => ({
- setup() {
+export interface MapsLegacyPluginSetup {
+ config$: Observable;
+}
+
+export class MapsLegacyPlugin implements Plugin {
+ readonly _initializerContext: PluginInitializerContext;
+
+ constructor(initializerContext: PluginInitializerContext) {
+ this._initializerContext = initializerContext;
+ }
+
+ public setup() {
// @ts-ignore
- const config$ = initializerContext.config.create();
+ const config$ = this._initializerContext.config.create();
return {
- config: config$,
+ config$,
};
- },
- start() {},
-});
+ }
+
+ public start() {}
+}
+
+export const plugin = (initializerContext: PluginInitializerContext) =>
+ new MapsLegacyPlugin(initializerContext);
diff --git a/src/plugins/vis_type_timeseries/common/metric_types.js b/src/plugins/vis_type_timeseries/common/metric_types.js
index 9dc6085b080e9..05836a6df410a 100644
--- a/src/plugins/vis_type_timeseries/common/metric_types.js
+++ b/src/plugins/vis_type_timeseries/common/metric_types.js
@@ -27,6 +27,9 @@ export const METRIC_TYPES = {
VARIANCE: 'variance',
SUM_OF_SQUARES: 'sum_of_squares',
CARDINALITY: 'cardinality',
+ VALUE_COUNT: 'value_count',
+ AVERAGE: 'avg',
+ SUM: 'sum',
};
export const EXTENDED_STATS_TYPES = [
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.test.tsx b/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.test.tsx
new file mode 100644
index 0000000000000..968fa5384e1d8
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.test.tsx
@@ -0,0 +1,184 @@
+/*
+ * 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 React from 'react';
+import { mountWithIntl } from 'test_utils/enzyme_helpers';
+import { AggSelect } from './agg_select';
+import { METRIC, SERIES } from '../../../test_utils';
+import { EuiComboBox } from '@elastic/eui';
+
+describe('TSVB AggSelect', () => {
+ const setup = (panelType: string, value: string) => {
+ const metric = {
+ ...METRIC,
+ type: 'filter_ratio',
+ field: 'histogram_value',
+ };
+ const series = { ...SERIES, metrics: [metric] };
+
+ const wrapper = mountWithIntl(
+
+ );
+ return wrapper;
+ };
+
+ it('should only display filter ratio compattible aggs', () => {
+ const wrapper = setup('filter_ratio', 'avg');
+ expect(wrapper.find(EuiComboBox).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "Average",
+ "value": "avg",
+ },
+ Object {
+ "label": "Cardinality",
+ "value": "cardinality",
+ },
+ Object {
+ "label": "Count",
+ "value": "count",
+ },
+ Object {
+ "label": "Positive Rate",
+ "value": "positive_rate",
+ },
+ Object {
+ "label": "Max",
+ "value": "max",
+ },
+ Object {
+ "label": "Min",
+ "value": "min",
+ },
+ Object {
+ "label": "Sum",
+ "value": "sum",
+ },
+ Object {
+ "label": "Value Count",
+ "value": "value_count",
+ },
+ ]
+ `);
+ });
+
+ it('should only display histogram compattible aggs', () => {
+ const wrapper = setup('histogram', 'avg');
+ expect(wrapper.find(EuiComboBox).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "Average",
+ "value": "avg",
+ },
+ Object {
+ "label": "Count",
+ "value": "count",
+ },
+ Object {
+ "label": "Sum",
+ "value": "sum",
+ },
+ Object {
+ "label": "Value Count",
+ "value": "value_count",
+ },
+ ]
+ `);
+ });
+
+ it('should only display metrics compattible aggs', () => {
+ const wrapper = setup('metrics', 'avg');
+ expect(wrapper.find(EuiComboBox).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "Average",
+ "value": "avg",
+ },
+ Object {
+ "label": "Cardinality",
+ "value": "cardinality",
+ },
+ Object {
+ "label": "Count",
+ "value": "count",
+ },
+ Object {
+ "label": "Filter Ratio",
+ "value": "filter_ratio",
+ },
+ Object {
+ "label": "Positive Rate",
+ "value": "positive_rate",
+ },
+ Object {
+ "label": "Max",
+ "value": "max",
+ },
+ Object {
+ "label": "Min",
+ "value": "min",
+ },
+ Object {
+ "label": "Percentile",
+ "value": "percentile",
+ },
+ Object {
+ "label": "Percentile Rank",
+ "value": "percentile_rank",
+ },
+ Object {
+ "label": "Static Value",
+ "value": "static",
+ },
+ Object {
+ "label": "Std. Deviation",
+ "value": "std_deviation",
+ },
+ Object {
+ "label": "Sum",
+ "value": "sum",
+ },
+ Object {
+ "label": "Sum of Squares",
+ "value": "sum_of_squares",
+ },
+ Object {
+ "label": "Top Hit",
+ "value": "top_hit",
+ },
+ Object {
+ "label": "Value Count",
+ "value": "value_count",
+ },
+ Object {
+ "label": "Variance",
+ "value": "variance",
+ },
+ ]
+ `);
+ });
+});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.tsx b/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.tsx
index 6fa1a2adaa08e..7701d351e5478 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/agg_select.tsx
@@ -225,6 +225,19 @@ const specialAggs: AggSelectOption[] = [
},
];
+const FILTER_RATIO_AGGS = [
+ 'avg',
+ 'cardinality',
+ 'count',
+ 'positive_rate',
+ 'max',
+ 'min',
+ 'sum',
+ 'value_count',
+];
+
+const HISTOGRAM_AGGS = ['avg', 'count', 'sum', 'value_count'];
+
const allAggOptions = [...metricAggs, ...pipelineAggs, ...siblingAggs, ...specialAggs];
function filterByPanelType(panelType: string) {
@@ -257,6 +270,10 @@ export function AggSelect(props: AggSelectUiProps) {
let options: EuiComboBoxOptionOption[];
if (panelType === 'metrics') {
options = metricAggs;
+ } else if (panelType === 'filter_ratio') {
+ options = metricAggs.filter((m) => FILTER_RATIO_AGGS.includes(`${m.value}`));
+ } else if (panelType === 'histogram') {
+ options = metricAggs.filter((m) => HISTOGRAM_AGGS.includes(`${m.value}`));
} else {
const disableSiblingAggs = (agg: AggSelectOption) => ({
...agg,
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/filter_ratio.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/filter_ratio.js
index b5311e3832da4..2aa994c09a2ad 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/filter_ratio.js
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/filter_ratio.js
@@ -36,7 +36,15 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { KBN_FIELD_TYPES } from '../../../../../../plugins/data/public';
-import { METRIC_TYPES } from '../../../../../../plugins/vis_type_timeseries/common/metric_types';
+import { getSupportedFieldsByMetricType } from '../lib/get_supported_fields_by_metric_type';
+
+const isFieldHistogram = (fields, indexPattern, field) => {
+ const indexFields = fields[indexPattern];
+ if (!indexFields) return false;
+ const fieldObject = indexFields.find((f) => f.name === field);
+ if (!fieldObject) return false;
+ return fieldObject.type === KBN_FIELD_TYPES.HISTOGRAM;
+};
export const FilterRatioAgg = (props) => {
const { series, fields, panel } = props;
@@ -56,9 +64,6 @@ export const FilterRatioAgg = (props) => {
const model = { ...defaults, ...props.model };
const htmlId = htmlIdGenerator();
- const restrictFields =
- model.metric_agg === METRIC_TYPES.CARDINALITY ? [] : [KBN_FIELD_TYPES.NUMBER];
-
return (
{
@@ -149,7 +156,7 @@ export const FilterRatioAgg = (props) => {
{
+ const setup = (metric) => {
+ const series = { ...SERIES, metrics: [metric] };
+ const panel = { ...PANEL, series };
+
+ const wrapper = mountWithIntl(
+
+
+
+ );
+ return wrapper;
+ };
+
+ describe('histogram support', () => {
+ it('should only display histogram compattible aggs', () => {
+ const metric = {
+ ...METRIC,
+ metric_agg: 'avg',
+ field: 'histogram_value',
+ };
+ const wrapper = setup(metric);
+ expect(wrapper.find(EuiComboBox).at(1).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "Average",
+ "value": "avg",
+ },
+ Object {
+ "label": "Count",
+ "value": "count",
+ },
+ Object {
+ "label": "Sum",
+ "value": "sum",
+ },
+ Object {
+ "label": "Value Count",
+ "value": "value_count",
+ },
+ ]
+ `);
+ });
+ const shouldNotHaveHistogramField = (agg) => {
+ it(`should not have histogram fields for ${agg}`, () => {
+ const metric = {
+ ...METRIC,
+ metric_agg: agg,
+ field: '',
+ };
+ const wrapper = setup(metric);
+ expect(wrapper.find(EuiComboBox).at(2).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "number",
+ "options": Array [
+ Object {
+ "label": "system.cpu.user.pct",
+ "value": "system.cpu.user.pct",
+ },
+ ],
+ },
+ ]
+ `);
+ });
+ };
+ shouldNotHaveHistogramField('max');
+ shouldNotHaveHistogramField('min');
+ shouldNotHaveHistogramField('positive_rate');
+
+ it(`should not have histogram fields for cardinality`, () => {
+ const metric = {
+ ...METRIC,
+ metric_agg: 'cardinality',
+ field: '',
+ };
+ const wrapper = setup(metric);
+ expect(wrapper.find(EuiComboBox).at(2).props().options).toMatchInlineSnapshot(`
+ Array [
+ Object {
+ "label": "date",
+ "options": Array [
+ Object {
+ "label": "@timestamp",
+ "value": "@timestamp",
+ },
+ ],
+ },
+ Object {
+ "label": "number",
+ "options": Array [
+ Object {
+ "label": "system.cpu.user.pct",
+ "value": "system.cpu.user.pct",
+ },
+ ],
+ },
+ ]
+ `);
+ });
+ });
+});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/histogram_support.test.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/histogram_support.test.js
new file mode 100644
index 0000000000000..7af33ba11f247
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/histogram_support.test.js
@@ -0,0 +1,94 @@
+/*
+ * 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 React from 'react';
+import { mountWithIntl } from 'test_utils/enzyme_helpers';
+import { Agg } from './agg';
+import { FieldSelect } from './field_select';
+import { FIELDS, METRIC, SERIES, PANEL } from '../../../test_utils';
+const runTest = (aggType, name, test, additionalProps = {}) => {
+ describe(aggType, () => {
+ const metric = {
+ ...METRIC,
+ type: aggType,
+ field: 'histogram_value',
+ ...additionalProps,
+ };
+ const series = { ...SERIES, metrics: [metric] };
+ const panel = { ...PANEL, series };
+
+ it(name, () => {
+ const wrapper = mountWithIntl(
+
+ );
+ test(wrapper);
+ });
+ });
+};
+
+describe('Histogram Types', () => {
+ describe('supported', () => {
+ const shouldHaveHistogramSupport = (aggType, additionalProps = {}) => {
+ runTest(
+ aggType,
+ 'supports',
+ (wrapper) =>
+ expect(wrapper.find(FieldSelect).at(0).props().restrict).toContain('histogram'),
+ additionalProps
+ );
+ };
+ shouldHaveHistogramSupport('avg');
+ shouldHaveHistogramSupport('sum');
+ shouldHaveHistogramSupport('value_count');
+ shouldHaveHistogramSupport('percentile');
+ shouldHaveHistogramSupport('percentile_rank');
+ shouldHaveHistogramSupport('filter_ratio', { metric_agg: 'avg' });
+ });
+ describe('not supported', () => {
+ const shouldNotHaveHistogramSupport = (aggType, additionalProps = {}) => {
+ runTest(
+ aggType,
+ 'does not support',
+ (wrapper) =>
+ expect(wrapper.find(FieldSelect).at(0).props().restrict).not.toContain('histogram'),
+ additionalProps
+ );
+ };
+ shouldNotHaveHistogramSupport('cardinality');
+ shouldNotHaveHistogramSupport('max');
+ shouldNotHaveHistogramSupport('min');
+ shouldNotHaveHistogramSupport('variance');
+ shouldNotHaveHistogramSupport('sum_of_squares');
+ shouldNotHaveHistogramSupport('std_deviation');
+ shouldNotHaveHistogramSupport('positive_rate');
+ shouldNotHaveHistogramSupport('top_hit');
+ });
+});
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile.js
index 6a7bf1bffe83c..f12c0c8f6f465 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile.js
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile.js
@@ -36,7 +36,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { KBN_FIELD_TYPES } from '../../../../../../plugins/data/public';
import { Percentiles, newPercentile } from './percentile_ui';
-const RESTRICT_FIELDS = [KBN_FIELD_TYPES.NUMBER];
+const RESTRICT_FIELDS = [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM];
const checkModel = (model) => Array.isArray(model.percentiles);
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile_rank/percentile_rank.tsx b/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile_rank/percentile_rank.tsx
index a16f5aeefc49c..d02a16ade2bba 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile_rank/percentile_rank.tsx
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/percentile_rank/percentile_rank.tsx
@@ -41,7 +41,7 @@ import { IFieldType, KBN_FIELD_TYPES } from '../../../../../../../plugins/data/p
import { MetricsItemsSchema, PanelSchema, SeriesItemsSchema } from '../../../../../common/types';
import { DragHandleProps } from '../../../../types';
-const RESTRICT_FIELDS = [KBN_FIELD_TYPES.NUMBER];
+const RESTRICT_FIELDS = [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM];
interface PercentileRankAggProps {
disableDelete: boolean;
diff --git a/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_rate.js b/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_rate.js
index 3ca89f7289d65..c20bcc1babc1d 100644
--- a/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_rate.js
+++ b/src/plugins/vis_type_timeseries/public/application/components/aggs/positive_rate.js
@@ -123,7 +123,7 @@ export const PositiveRateAgg = (props) => {
t !== KBN_FIELD_TYPES.HISTOGRAM);
+ case METRIC_TYPES.VALUE_COUNT:
+ case METRIC_TYPES.AVERAGE:
+ case METRIC_TYPES.SUM:
+ return [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.HISTOGRAM];
+ default:
+ return [KBN_FIELD_TYPES.NUMBER];
+ }
+}
diff --git a/src/plugins/vis_type_timeseries/public/application/components/lib/get_supported_fields_by_metric_type.test.js b/src/plugins/vis_type_timeseries/public/application/components/lib/get_supported_fields_by_metric_type.test.js
new file mode 100644
index 0000000000000..3cd3fac191bf1
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/application/components/lib/get_supported_fields_by_metric_type.test.js
@@ -0,0 +1,44 @@
+/*
+ * Licensed to Elasticsearch B.V. under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch B.V. licenses this file to you under
+ * the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { getSupportedFieldsByMetricType } from './get_supported_fields_by_metric_type';
+
+describe('getSupportedFieldsByMetricType', () => {
+ const shouldHaveHistogramAndNumbers = (type) =>
+ it(`should return numbers and histogram for ${type}`, () => {
+ expect(getSupportedFieldsByMetricType(type)).toEqual(['number', 'histogram']);
+ });
+ const shouldHaveOnlyNumbers = (type) =>
+ it(`should return only numbers for ${type}`, () => {
+ expect(getSupportedFieldsByMetricType(type)).toEqual(['number']);
+ });
+
+ shouldHaveHistogramAndNumbers('value_count');
+ shouldHaveHistogramAndNumbers('avg');
+ shouldHaveHistogramAndNumbers('sum');
+
+ shouldHaveOnlyNumbers('positive_rate');
+ shouldHaveOnlyNumbers('std_deviation');
+ shouldHaveOnlyNumbers('max');
+ shouldHaveOnlyNumbers('min');
+
+ it(`should return everything but histogram for cardinality`, () => {
+ expect(getSupportedFieldsByMetricType('cardinality')).not.toContain('histogram');
+ });
+});
diff --git a/src/plugins/vis_type_timeseries/public/test_utils/index.ts b/src/plugins/vis_type_timeseries/public/test_utils/index.ts
new file mode 100644
index 0000000000000..96ecc89b70c2d
--- /dev/null
+++ b/src/plugins/vis_type_timeseries/public/test_utils/index.ts
@@ -0,0 +1,50 @@
+/*
+ * 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 const UI_RESTRICTIONS = { '*': true };
+export const INDEX_PATTERN = 'some-pattern';
+export const FIELDS = {
+ [INDEX_PATTERN]: [
+ {
+ type: 'date',
+ name: '@timestamp',
+ },
+ {
+ type: 'number',
+ name: 'system.cpu.user.pct',
+ },
+ {
+ type: 'histogram',
+ name: 'histogram_value',
+ },
+ ],
+};
+export const METRIC = {
+ id: 'sample_metric',
+ type: 'avg',
+ field: 'system.cpu.user.pct',
+};
+export const SERIES = {
+ metrics: [METRIC],
+};
+export const PANEL = {
+ type: 'timeseries',
+ index_pattern: INDEX_PATTERN,
+ series: SERIES,
+};
diff --git a/test/functional/apps/management/_create_index_pattern_wizard.js b/test/functional/apps/management/_create_index_pattern_wizard.js
index cb8b5a6ddc65f..97f2641b51d13 100644
--- a/test/functional/apps/management/_create_index_pattern_wizard.js
+++ b/test/functional/apps/management/_create_index_pattern_wizard.js
@@ -25,7 +25,8 @@ export default function ({ getService, getPageObjects }) {
const es = getService('legacyEs');
const PageObjects = getPageObjects(['settings', 'common']);
- describe('"Create Index Pattern" wizard', function () {
+ // Flaky: https://github.com/elastic/kibana/issues/71501
+ describe.skip('"Create Index Pattern" wizard', function () {
before(async function () {
// delete .kibana index and then wait for Kibana to re-create it
await kibanaServer.uiSettings.replace({});
diff --git a/test/functional/apps/saved_objects_management/edit_saved_object.ts b/test/functional/apps/saved_objects_management/edit_saved_object.ts
index 2c9200c2f8d93..0e2ff44ff62ef 100644
--- a/test/functional/apps/saved_objects_management/edit_saved_object.ts
+++ b/test/functional/apps/saved_objects_management/edit_saved_object.ts
@@ -66,6 +66,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await button.click();
};
+ // Flaky: https://github.com/elastic/kibana/issues/68400
describe('saved objects edition page', () => {
beforeEach(async () => {
await esArchiver.load('saved_objects_management/edit_saved_object');
diff --git a/vars/kibanaPipeline.groovy b/vars/kibanaPipeline.groovy
index f3fc5f84583c9..f43fe9f96c3ef 100644
--- a/vars/kibanaPipeline.groovy
+++ b/vars/kibanaPipeline.groovy
@@ -209,7 +209,7 @@ def runErrorReporter() {
bash(
"""
source src/dev/ci_setup/setup_env.sh
- node scripts/report_failed_tests ${dryRun}
+ node scripts/report_failed_tests ${dryRun} target/junit/**/*.xml
""",
"Report failed tests, if necessary"
)
diff --git a/x-pack/.gitignore b/x-pack/.gitignore
index e181caf2b1a49..0c916ef0e9b91 100644
--- a/x-pack/.gitignore
+++ b/x-pack/.gitignore
@@ -6,6 +6,7 @@
/test/page_load_metrics/screenshots
/test/functional/apps/reporting/reports/session
/test/reporting/configs/failure_debug/
+/plugins/reporting/.chromium/
/legacy/plugins/reporting/.chromium/
/legacy/plugins/reporting/.phantom/
/plugins/reporting/chromium/
diff --git a/x-pack/plugins/apm/common/environment_filter_values.ts b/x-pack/plugins/apm/common/environment_filter_values.ts
index 239378d0ea94a..38b6f480ca3d3 100644
--- a/x-pack/plugins/apm/common/environment_filter_values.ts
+++ b/x-pack/plugins/apm/common/environment_filter_values.ts
@@ -4,5 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { i18n } from '@kbn/i18n';
+
export const ENVIRONMENT_ALL = 'ENVIRONMENT_ALL';
export const ENVIRONMENT_NOT_DEFINED = 'ENVIRONMENT_NOT_DEFINED';
+
+export function getEnvironmentLabel(environment: string) {
+ if (environment === ENVIRONMENT_NOT_DEFINED) {
+ return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', {
+ defaultMessage: 'Not defined',
+ });
+ }
+ return environment;
+}
diff --git a/x-pack/plugins/apm/public/components/app/Home/index.tsx b/x-pack/plugins/apm/public/components/app/Home/index.tsx
index f612ac0d383ef..bcc834fef6a6a 100644
--- a/x-pack/plugins/apm/public/components/app/Home/index.tsx
+++ b/x-pack/plugins/apm/public/components/app/Home/index.tsx
@@ -20,6 +20,7 @@ import { EuiTabLink } from '../../shared/EuiTabLink';
import { ServiceMapLink } from '../../shared/Links/apm/ServiceMapLink';
import { ServiceOverviewLink } from '../../shared/Links/apm/ServiceOverviewLink';
import { SettingsLink } from '../../shared/Links/apm/SettingsLink';
+import { AnomalyDetectionSetupLink } from '../../shared/Links/apm/AnomalyDetectionSetupLink';
import { TraceOverviewLink } from '../../shared/Links/apm/TraceOverviewLink';
import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink';
import { ServiceMap } from '../ServiceMap';
@@ -118,6 +119,9 @@ export function Home({ tab }: Props) {
+
+
+
diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx
index 2da3c12563104..4c056d48f4b14 100644
--- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx
+++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/add_environments.tsx
@@ -22,7 +22,7 @@ import { i18n } from '@kbn/i18n';
import { useFetcher, FETCH_STATUS } from '../../../../hooks/useFetcher';
import { useApmPluginContext } from '../../../../hooks/useApmPluginContext';
import { createJobs } from './create_jobs';
-import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values';
+import { getEnvironmentLabel } from '../../../../../common/environment_filter_values';
interface Props {
currentEnvironments: string[];
@@ -45,11 +45,13 @@ export const AddEnvironments = ({
);
const environmentOptions = data.map((env) => ({
- label: env === ENVIRONMENT_NOT_DEFINED ? NOT_DEFINED_OPTION_LABEL : env,
+ label: getEnvironmentLabel(env),
value: env,
disabled: currentEnvironments.includes(env),
}));
+ const [isSaving, setIsSaving] = useState(false);
+
const [selectedOptions, setSelected] = useState<
Array>
>([]);
@@ -127,9 +129,12 @@ export const AddEnvironments = ({
{
+ setIsSaving(true);
+
const selectedEnvironments = selectedOptions.map(
({ value }) => value as string
);
@@ -140,6 +145,7 @@ export const AddEnvironments = ({
if (success) {
onCreateJobSuccess();
}
+ setIsSaving(false);
}}
>
{i18n.translate(
@@ -155,10 +161,3 @@ export const AddEnvironments = ({
);
};
-
-const NOT_DEFINED_OPTION_LABEL = i18n.translate(
- 'xpack.apm.filter.environment.notDefinedLabel',
- {
- defaultMessage: 'Not defined',
- }
-);
diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx
index 6f985d06dba9d..f02350fafbabb 100644
--- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx
+++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/index.tsx
@@ -15,7 +15,11 @@ import { LicensePrompt } from '../../../shared/LicensePrompt';
import { useLicense } from '../../../../hooks/useLicense';
import { APIReturnType } from '../../../../services/rest/createCallApmApi';
-const DEFAULT_VALUE: APIReturnType<'/api/apm/settings/anomaly-detection'> = {
+export type AnomalyDetectionApiResponse = APIReturnType<
+ '/api/apm/settings/anomaly-detection'
+>;
+
+const DEFAULT_VALUE: AnomalyDetectionApiResponse = {
jobs: [],
hasLegacyJobs: false,
};
@@ -80,7 +84,7 @@ export const AnomalyDetection = () => {
) : (
{
setViewAddEnvironments(true);
diff --git a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx
index 83d19aa27ac11..5954b82f3b9e7 100644
--- a/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx
+++ b/x-pack/plugins/apm/public/components/app/Settings/anomaly_detection/jobs_list.tsx
@@ -19,27 +19,22 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { FETCH_STATUS } from '../../../../hooks/useFetcher';
import { ITableColumn, ManagedTable } from '../../../shared/ManagedTable';
import { LoadingStatePrompt } from '../../../shared/LoadingStatePrompt';
-import { AnomalyDetectionJobByEnv } from '../../../../../typings/anomaly_detection';
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink';
import { MLLink } from '../../../shared/Links/MachineLearningLinks/MLLink';
-import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values';
+import { getEnvironmentLabel } from '../../../../../common/environment_filter_values';
import { LegacyJobsCallout } from './legacy_jobs_callout';
+import { AnomalyDetectionApiResponse } from './index';
-const columns: Array> = [
+type Jobs = AnomalyDetectionApiResponse['jobs'];
+
+const columns: Array> = [
{
field: 'environment',
name: i18n.translate(
'xpack.apm.settings.anomalyDetection.jobList.environmentColumnLabel',
{ defaultMessage: 'Environment' }
),
- render: (environment: string) => {
- if (environment === ENVIRONMENT_NOT_DEFINED) {
- return i18n.translate('xpack.apm.filter.environment.notDefinedLabel', {
- defaultMessage: 'Not defined',
- });
- }
- return environment;
- },
+ render: getEnvironmentLabel,
},
{
field: 'job_id',
@@ -64,13 +59,13 @@ const columns: Array> = [
interface Props {
status: FETCH_STATUS;
onAddEnvironments: () => void;
- anomalyDetectionJobsByEnv: AnomalyDetectionJobByEnv[];
+ jobs: Jobs;
hasLegacyJobs: boolean;
}
export const JobsList = ({
status,
onAddEnvironments,
- anomalyDetectionJobsByEnv,
+ jobs,
hasLegacyJobs,
}: Props) => {
const isLoading =
@@ -135,7 +130,7 @@ export const JobsList = ({
)
}
columns={columns}
- items={isLoading || hasFetchFailure ? [] : anomalyDetectionJobsByEnv}
+ items={jobs}
/>
diff --git a/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx b/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx
index 620ae6708eda0..c56b7b9aaa720 100644
--- a/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx
+++ b/x-pack/plugins/apm/public/components/app/TransactionDetails/index.tsx
@@ -89,7 +89,6 @@ export function TransactionDetails() {
+ callApmApi({ pathname: `/api/apm/settings/anomaly-detection` }),
+ [],
+ { preservePreviousData: false }
+ );
+ const isFetchSuccess = status === FETCH_STATUS.SUCCESS;
+
+ // Show alert if there are no jobs OR if no job matches the current environment
+ const showAlert =
+ isFetchSuccess && !data.jobs.some((job) => environment === job.environment);
+
+ return (
+
+
+ {ANOMALY_DETECTION_LINK_LABEL}
+
+ {showAlert && (
+
+
+
+ )}
+
+ );
+}
+
+function getTooltipText(environment?: string) {
+ if (!environment) {
+ return i18n.translate('xpack.apm.anomalyDetectionSetup.notEnabledText', {
+ defaultMessage: `Anomaly detection is not yet enabled. Click to continue setup.`,
+ });
+ }
+
+ return i18n.translate(
+ 'xpack.apm.anomalyDetectionSetup.notEnabledForEnvironmentText',
+ {
+ defaultMessage: `Anomaly detection is not yet enabled for the "{currentEnvironment}" environment. Click to continue setup.`,
+ values: { currentEnvironment: getEnvironmentLabel(environment) },
+ }
+ );
+}
+
+const ANOMALY_DETECTION_LINK_LABEL = i18n.translate(
+ 'xpack.apm.anomalyDetectionSetup.linkLabel',
+ { defaultMessage: `Anomaly detection` }
+);
diff --git a/x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx b/x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx
index 00ff6f9969725..1f80dbf5f4d95 100644
--- a/x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx
+++ b/x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/index.tsx
@@ -42,7 +42,6 @@ import {
} from '../../../../../common/transaction_types';
interface TransactionChartProps {
- hasMLJob: boolean;
charts: ITransactionChartData;
location: Location;
urlParams: IUrlParams;
@@ -96,18 +95,17 @@ export class TransactionCharts extends Component {
};
public renderMLHeader(hasValidMlLicense: boolean | undefined) {
- const { hasMLJob } = this.props;
- if (!hasValidMlLicense || !hasMLJob) {
+ const { mlJobId } = this.props.charts;
+
+ if (!hasValidMlLicense || !mlJobId) {
return null;
}
- const { serviceName, kuery } = this.props.urlParams;
+ const { serviceName, kuery, transactionType } = this.props.urlParams;
if (!serviceName) {
return null;
}
- const linkedJobId = ''; // TODO [APM ML] link to ML job id for the selected environment
-
const hasKuery = !isEmpty(kuery);
const icon = hasKuery ? (
{
}
)}{' '}
- View Job
+
+ View Job
+
);
diff --git a/x-pack/plugins/apm/public/selectors/chartSelectors.ts b/x-pack/plugins/apm/public/selectors/chartSelectors.ts
index 714d62a703f51..26c2365ed77e1 100644
--- a/x-pack/plugins/apm/public/selectors/chartSelectors.ts
+++ b/x-pack/plugins/apm/public/selectors/chartSelectors.ts
@@ -33,6 +33,7 @@ export interface ITpmBucket {
export interface ITransactionChartData {
tpmSeries: ITpmBucket[];
responseTimeSeries: TimeSeries[];
+ mlJobId: string | undefined;
}
const INITIAL_DATA = {
@@ -62,6 +63,7 @@ export function getTransactionCharts(
return {
tpmSeries,
responseTimeSeries,
+ mlJobId: anomalyTimeseries?.jobId,
};
}
diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
index e723393a24013..c387c5152b1c5 100644
--- a/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
+++ b/x-pack/plugins/apm/server/lib/anomaly_detection/create_anomaly_detection_jobs.ts
@@ -10,12 +10,11 @@ import { snakeCase } from 'lodash';
import { PromiseReturnType } from '../../../../observability/typings/common';
import { Setup } from '../helpers/setup_request';
import {
- SERVICE_ENVIRONMENT,
TRANSACTION_DURATION,
PROCESSOR_EVENT,
} from '../../../common/elasticsearch_fieldnames';
-import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
import { APM_ML_JOB_GROUP, ML_MODULE_ID_APM_TRANSACTION } from './constants';
+import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
export type CreateAnomalyDetectionJobsAPIResponse = PromiseReturnType<
typeof createAnomalyDetectionJobs
@@ -89,9 +88,7 @@ async function createAnomalyDetectionJob({
filter: [
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
{ exists: { field: TRANSACTION_DURATION } },
- environment === ENVIRONMENT_NOT_DEFINED
- ? ENVIRONMENT_NOT_DEFINED_FILTER
- : { term: { [SERVICE_ENVIRONMENT]: environment } },
+ ...getEnvironmentUiFilterES(environment),
],
},
},
@@ -109,13 +106,3 @@ async function createAnomalyDetectionJob({
],
});
}
-
-const ENVIRONMENT_NOT_DEFINED_FILTER = {
- bool: {
- must_not: {
- exists: {
- field: SERVICE_ENVIRONMENT,
- },
- },
- },
-};
diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts
index 8fdebeb597eaf..13b30f159eed1 100644
--- a/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts
+++ b/x-pack/plugins/apm/server/lib/anomaly_detection/get_anomaly_detection_jobs.ts
@@ -6,7 +6,7 @@
import { Logger } from 'kibana/server';
import { Setup } from '../helpers/setup_request';
-import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group';
+import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group';
export async function getAnomalyDetectionJobs(setup: Setup, logger: Logger) {
const { ml } = setup;
diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_by_group.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_with_apm_group.ts
similarity index 100%
rename from x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_by_group.ts
rename to x-pack/plugins/apm/server/lib/anomaly_detection/get_ml_jobs_with_apm_group.ts
diff --git a/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts b/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts
index bf502607fcc1d..999d28309121a 100644
--- a/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts
+++ b/x-pack/plugins/apm/server/lib/anomaly_detection/has_legacy_jobs.ts
@@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { Setup } from '../helpers/setup_request';
-import { getMlJobsWithAPMGroup } from './get_ml_jobs_by_group';
+import { getMlJobsWithAPMGroup } from './get_ml_jobs_with_apm_group';
// Determine whether there are any legacy ml jobs.
// A legacy ML job has a job id that ends with "high_mean_response_time" and created_by=ml-module-apm-transaction
diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts
index 0f0a11a868d6d..800f809727eb6 100644
--- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts
+++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/__test__/get_environment_ui_filter_es.test.ts
@@ -7,24 +7,23 @@
import { getEnvironmentUiFilterES } from '../get_environment_ui_filter_es';
import { ENVIRONMENT_NOT_DEFINED } from '../../../../../common/environment_filter_values';
import { SERVICE_ENVIRONMENT } from '../../../../../common/elasticsearch_fieldnames';
-import { ESFilter } from '../../../../../typings/elasticsearch';
describe('getEnvironmentUiFilterES', () => {
- it('should return undefined, when environment is undefined', () => {
+ it('should return empty array, when environment is undefined', () => {
const uiFilterES = getEnvironmentUiFilterES();
- expect(uiFilterES).toBeUndefined();
+ expect(uiFilterES).toHaveLength(0);
});
it('should create a filter for a service environment', () => {
- const uiFilterES = getEnvironmentUiFilterES('test') as ESFilter;
- expect(uiFilterES).toHaveProperty(['term', SERVICE_ENVIRONMENT], 'test');
+ const uiFilterES = getEnvironmentUiFilterES('test');
+ expect(uiFilterES).toHaveLength(1);
+ expect(uiFilterES[0]).toHaveProperty(['term', SERVICE_ENVIRONMENT], 'test');
});
it('should create a filter for missing service environments', () => {
- const uiFilterES = getEnvironmentUiFilterES(
- ENVIRONMENT_NOT_DEFINED
- ) as ESFilter;
- expect(uiFilterES).toHaveProperty(
+ const uiFilterES = getEnvironmentUiFilterES(ENVIRONMENT_NOT_DEFINED);
+ expect(uiFilterES).toHaveLength(1);
+ expect(uiFilterES[0]).toHaveProperty(
['bool', 'must_not', 'exists', 'field'],
SERVICE_ENVIRONMENT
);
diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts
index 63d222a7fcb6e..87bc8dc968373 100644
--- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts
+++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_environment_ui_filter_es.ts
@@ -8,19 +8,12 @@ import { ESFilter } from '../../../../typings/elasticsearch';
import { ENVIRONMENT_NOT_DEFINED } from '../../../../common/environment_filter_values';
import { SERVICE_ENVIRONMENT } from '../../../../common/elasticsearch_fieldnames';
-export function getEnvironmentUiFilterES(
- environment?: string
-): ESFilter | undefined {
+export function getEnvironmentUiFilterES(environment?: string): ESFilter[] {
if (!environment) {
- return undefined;
+ return [];
}
-
if (environment === ENVIRONMENT_NOT_DEFINED) {
- return {
- bool: { must_not: { exists: { field: SERVICE_ENVIRONMENT } } },
- };
+ return [{ bool: { must_not: { exists: { field: SERVICE_ENVIRONMENT } } } }];
}
- return {
- term: { [SERVICE_ENVIRONMENT]: environment },
- };
+ return [{ term: { [SERVICE_ENVIRONMENT]: environment } }];
}
diff --git a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts
index b34d5535d58cc..c1405b44f2a8a 100644
--- a/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts
+++ b/x-pack/plugins/apm/server/lib/helpers/convert_ui_filters/get_ui_filters_es.ts
@@ -27,22 +27,19 @@ export function getUiFiltersES(uiFilters: UIFilters) {
};
}) as ESFilter[];
- // remove undefined items from list
const esFilters = [
- getKueryUiFilterES(uiFilters.kuery),
- getEnvironmentUiFilterES(uiFilters.environment),
- ]
- .filter((filter) => !!filter)
- .concat(mappedFilters) as ESFilter[];
+ ...getKueryUiFilterES(uiFilters.kuery),
+ ...getEnvironmentUiFilterES(uiFilters.environment),
+ ].concat(mappedFilters) as ESFilter[];
return esFilters;
}
function getKueryUiFilterES(kuery?: string) {
if (!kuery) {
- return;
+ return [];
}
const ast = esKuery.fromKueryExpression(kuery);
- return esKuery.toElasticsearchQuery(ast) as ESFilter;
+ return [esKuery.toElasticsearchQuery(ast) as ESFilter];
}
diff --git a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
index be92bfe5a0099..dd5d19b620c51 100644
--- a/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
+++ b/x-pack/plugins/apm/server/lib/service_map/get_service_map_service_node_info.ts
@@ -9,7 +9,6 @@ import { ESFilter } from '../../../typings/elasticsearch';
import { rangeFilter } from '../../../common/utils/range_filter';
import {
PROCESSOR_EVENT,
- SERVICE_ENVIRONMENT,
SERVICE_NAME,
TRANSACTION_DURATION,
TRANSACTION_TYPE,
@@ -22,7 +21,7 @@ import {
TRANSACTION_REQUEST,
TRANSACTION_PAGE_LOAD,
} from '../../../common/transaction_types';
-import { ENVIRONMENT_NOT_DEFINED } from '../../../common/environment_filter_values';
+import { getEnvironmentUiFilterES } from '../helpers/convert_ui_filters/get_environment_ui_filter_es';
interface Options {
setup: Setup & SetupTimeRange;
@@ -43,30 +42,14 @@ export async function getServiceMapServiceNodeInfo({
}: Options & { serviceName: string; environment?: string }) {
const { start, end } = setup;
- const environmentNotDefinedFilter = {
- bool: { must_not: [{ exists: { field: SERVICE_ENVIRONMENT } }] },
- };
-
const filter: ESFilter[] = [
{ range: rangeFilter(start, end) },
{ term: { [SERVICE_NAME]: serviceName } },
+ ...getEnvironmentUiFilterES(environment),
];
- if (environment) {
- filter.push(
- environment === ENVIRONMENT_NOT_DEFINED
- ? environmentNotDefinedFilter
- : { term: { [SERVICE_ENVIRONMENT]: environment } }
- );
- }
-
const minutes = Math.abs((end - start) / (1000 * 60));
-
- const taskParams = {
- setup,
- minutes,
- filter,
- };
+ const taskParams = { setup, minutes, filter };
const [
errorMetrics,
@@ -97,11 +80,7 @@ async function getErrorMetrics({ setup, minutes, filter }: TaskParameters) {
size: 0,
query: {
bool: {
- filter: filter.concat({
- term: {
- [PROCESSOR_EVENT]: 'error',
- },
- }),
+ filter: filter.concat({ term: { [PROCESSOR_EVENT]: 'error' } }),
},
},
track_total_hits: true,
@@ -134,11 +113,7 @@ async function getTransactionStats({
bool: {
filter: [
...filter,
- {
- term: {
- [PROCESSOR_EVENT]: 'transaction',
- },
- },
+ { term: { [PROCESSOR_EVENT]: 'transaction' } },
{
terms: {
[TRANSACTION_TYPE]: [
@@ -151,13 +126,7 @@ async function getTransactionStats({
},
},
track_total_hits: true,
- aggs: {
- duration: {
- avg: {
- field: TRANSACTION_DURATION,
- },
- },
- },
+ aggs: { duration: { avg: { field: TRANSACTION_DURATION } } },
},
};
const response = await client.search(params);
@@ -181,32 +150,16 @@ async function getCpuMetrics({
query: {
bool: {
filter: filter.concat([
- {
- term: {
- [PROCESSOR_EVENT]: 'metric',
- },
- },
- {
- exists: {
- field: METRIC_SYSTEM_CPU_PERCENT,
- },
- },
+ { term: { [PROCESSOR_EVENT]: 'metric' } },
+ { exists: { field: METRIC_SYSTEM_CPU_PERCENT } },
]),
},
},
- aggs: {
- avgCpuUsage: {
- avg: {
- field: METRIC_SYSTEM_CPU_PERCENT,
- },
- },
- },
+ aggs: { avgCpuUsage: { avg: { field: METRIC_SYSTEM_CPU_PERCENT } } },
},
});
- return {
- avgCpuUsage: response.aggregations?.avgCpuUsage.value ?? null,
- };
+ return { avgCpuUsage: response.aggregations?.avgCpuUsage.value ?? null };
}
async function getMemoryMetrics({
@@ -220,31 +173,13 @@ async function getMemoryMetrics({
query: {
bool: {
filter: filter.concat([
- {
- term: {
- [PROCESSOR_EVENT]: 'metric',
- },
- },
- {
- exists: {
- field: METRIC_SYSTEM_FREE_MEMORY,
- },
- },
- {
- exists: {
- field: METRIC_SYSTEM_TOTAL_MEMORY,
- },
- },
+ { term: { [PROCESSOR_EVENT]: 'metric' } },
+ { exists: { field: METRIC_SYSTEM_FREE_MEMORY } },
+ { exists: { field: METRIC_SYSTEM_TOTAL_MEMORY } },
]),
},
},
- aggs: {
- avgMemoryUsage: {
- avg: {
- script: percentMemoryUsedScript,
- },
- },
- },
+ aggs: { avgMemoryUsage: { avg: { script: percentMemoryUsedScript } } },
},
});
diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
index 6da5d195cf194..6a8aaf8dca8a6 100644
--- a/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
+++ b/x-pack/plugins/apm/server/lib/services/annotations/get_derived_service_annotations.ts
@@ -29,14 +29,9 @@ export async function getDerivedServiceAnnotations({
const filter: ESFilter[] = [
{ term: { [PROCESSOR_EVENT]: 'transaction' } },
{ term: { [SERVICE_NAME]: serviceName } },
+ ...getEnvironmentUiFilterES(environment),
];
- const environmentFilter = getEnvironmentUiFilterES(environment);
-
- if (environmentFilter) {
- filter.push(environmentFilter);
- }
-
const versions =
(
await client.search({
diff --git a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
index 75aeb27ea2122..6e3ae0181ddee 100644
--- a/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
+++ b/x-pack/plugins/apm/server/lib/services/annotations/get_stored_annotations.ts
@@ -29,8 +29,6 @@ export async function getStoredAnnotations({
logger: Logger;
}): Promise {
try {
- const environmentFilter = getEnvironmentUiFilterES(environment);
-
const response: ESSearchResponse = (await apiCaller(
'search',
{
@@ -51,7 +49,7 @@ export async function getStoredAnnotations({
{ term: { 'annotation.type': 'deployment' } },
{ term: { tags: 'apm' } },
{ term: { [SERVICE_NAME]: serviceName } },
- ...(environmentFilter ? [environmentFilter] : []),
+ ...getEnvironmentUiFilterES(environment),
],
},
},
diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts
new file mode 100644
index 0000000000000..3cf9a54e3fe9b
--- /dev/null
+++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/fetcher.ts
@@ -0,0 +1,93 @@
+/*
+ * 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 { Logger } from 'kibana/server';
+import { PromiseReturnType } from '../../../../../../observability/typings/common';
+import { Setup, SetupTimeRange } from '../../../helpers/setup_request';
+
+export type ESResponse = Exclude<
+ PromiseReturnType,
+ undefined
+>;
+
+export async function anomalySeriesFetcher({
+ serviceName,
+ transactionType,
+ intervalString,
+ mlBucketSize,
+ setup,
+ jobId,
+ logger,
+}: {
+ serviceName: string;
+ transactionType: string;
+ intervalString: string;
+ mlBucketSize: number;
+ setup: Setup & SetupTimeRange;
+ jobId: string;
+ logger: Logger;
+}) {
+ const { ml, start, end } = setup;
+ if (!ml) {
+ return;
+ }
+
+ // move the start back with one bucket size, to ensure to get anomaly data in the beginning
+ // this is required because ML has a minimum bucket size (default is 900s) so if our buckets are smaller, we might have several null buckets in the beginning
+ const newStart = start - mlBucketSize * 1000;
+
+ const params = {
+ body: {
+ size: 0,
+ query: {
+ bool: {
+ filter: [
+ { term: { job_id: jobId } },
+ { exists: { field: 'bucket_span' } },
+ { term: { result_type: 'model_plot' } },
+ { term: { partition_field_value: serviceName } },
+ { term: { by_field_value: transactionType } },
+ {
+ range: {
+ timestamp: { gte: newStart, lte: end, format: 'epoch_millis' },
+ },
+ },
+ ],
+ },
+ },
+ aggs: {
+ ml_avg_response_times: {
+ date_histogram: {
+ field: 'timestamp',
+ fixed_interval: intervalString,
+ min_doc_count: 0,
+ extended_bounds: { min: newStart, max: end },
+ },
+ aggs: {
+ anomaly_score: { max: { field: 'anomaly_score' } },
+ lower: { min: { field: 'model_lower' } },
+ upper: { max: { field: 'model_upper' } },
+ },
+ },
+ },
+ },
+ };
+
+ try {
+ const response = await ml.mlSystem.mlAnomalySearch(params);
+ return response;
+ } catch (err) {
+ const isHttpError = 'statusCode' in err;
+ if (isHttpError) {
+ logger.info(
+ `Status code "${err.statusCode}" while retrieving ML anomalies for APM`
+ );
+ return;
+ }
+ logger.error('An error occurred while retrieving ML anomalies for APM');
+ logger.error(err);
+ }
+}
diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts
new file mode 100644
index 0000000000000..2f5e703251c03
--- /dev/null
+++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/get_ml_bucket_size.ts
@@ -0,0 +1,61 @@
+/*
+ * 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 { Logger } from 'kibana/server';
+import { Setup, SetupTimeRange } from '../../../helpers/setup_request';
+
+interface IOptions {
+ setup: Setup & SetupTimeRange;
+ jobId: string;
+ logger: Logger;
+}
+
+interface ESResponse {
+ bucket_span: number;
+}
+
+export async function getMlBucketSize({
+ setup,
+ jobId,
+ logger,
+}: IOptions): Promise {
+ const { ml, start, end } = setup;
+ if (!ml) {
+ return;
+ }
+
+ const params = {
+ body: {
+ _source: 'bucket_span',
+ size: 1,
+ terminateAfter: 1,
+ query: {
+ bool: {
+ filter: [
+ { term: { job_id: jobId } },
+ { exists: { field: 'bucket_span' } },
+ {
+ range: {
+ timestamp: { gte: start, lte: end, format: 'epoch_millis' },
+ },
+ },
+ ],
+ },
+ },
+ },
+ };
+
+ try {
+ const resp = await ml.mlSystem.mlAnomalySearch(params);
+ return resp.hits.hits[0]?._source.bucket_span;
+ } catch (err) {
+ const isHttpError = 'statusCode' in err;
+ if (isHttpError) {
+ return;
+ }
+ logger.error(err);
+ }
+}
diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts
index b2d11f2ffe19a..072099bc9553c 100644
--- a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/index.ts
@@ -3,18 +3,19 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-
+import { Logger } from 'kibana/server';
+import { isNumber } from 'lodash';
+import { getBucketSize } from '../../../helpers/get_bucket_size';
import {
Setup,
SetupTimeRange,
SetupUIFilters,
} from '../../../helpers/setup_request';
-import { Coordinate, RectCoordinate } from '../../../../../typings/timeseries';
-
-interface AnomalyTimeseries {
- anomalyBoundaries: Coordinate[];
- anomalyScore: RectCoordinate[];
-}
+import { anomalySeriesFetcher } from './fetcher';
+import { getMlBucketSize } from './get_ml_bucket_size';
+import { anomalySeriesTransform } from './transform';
+import { getMLJobIds } from '../../../service_map/get_service_anomalies';
+import { UIFilters } from '../../../../../typings/ui_filters';
export async function getAnomalySeries({
serviceName,
@@ -22,13 +23,17 @@ export async function getAnomalySeries({
transactionName,
timeSeriesDates,
setup,
+ logger,
+ uiFilters,
}: {
serviceName: string;
transactionType: string | undefined;
transactionName: string | undefined;
timeSeriesDates: number[];
setup: Setup & SetupTimeRange & SetupUIFilters;
-}): Promise {
+ logger: Logger;
+ uiFilters: UIFilters;
+}) {
// don't fetch anomalies for transaction details page
if (transactionName) {
return;
@@ -39,8 +44,12 @@ export async function getAnomalySeries({
return;
}
- // don't fetch anomalies if uiFilters are applied
- if (setup.uiFiltersES.length > 0) {
+ // don't fetch anomalies if unknown uiFilters are applied
+ const knownFilters = ['environment', 'serviceName'];
+ const uiFilterNames = Object.keys(uiFilters);
+ if (
+ uiFilterNames.some((uiFilterName) => !knownFilters.includes(uiFilterName))
+ ) {
return;
}
@@ -55,6 +64,45 @@ export async function getAnomalySeries({
return;
}
- // TODO [APM ML] return a series of anomaly scores, upper & lower bounds for the given timeSeriesDates
- return;
+ let mlJobIds: string[] = [];
+ try {
+ mlJobIds = await getMLJobIds(setup.ml, uiFilters.environment);
+ } catch (error) {
+ logger.error(error);
+ return;
+ }
+
+ // don't fetch anomalies if there are isn't exaclty 1 ML job match for the given environment
+ if (mlJobIds.length !== 1) {
+ return;
+ }
+ const jobId = mlJobIds[0];
+
+ const mlBucketSize = await getMlBucketSize({ setup, jobId, logger });
+ if (!isNumber(mlBucketSize)) {
+ return;
+ }
+
+ const { start, end } = setup;
+ const { intervalString, bucketSize } = getBucketSize(start, end, 'auto');
+
+ const esResponse = await anomalySeriesFetcher({
+ serviceName,
+ transactionType,
+ intervalString,
+ mlBucketSize,
+ setup,
+ jobId,
+ logger,
+ });
+
+ if (esResponse && mlBucketSize > 0) {
+ return anomalySeriesTransform(
+ esResponse,
+ mlBucketSize,
+ bucketSize,
+ timeSeriesDates,
+ jobId
+ );
+ }
}
diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts
new file mode 100644
index 0000000000000..393a73f7c1ccd
--- /dev/null
+++ b/x-pack/plugins/apm/server/lib/transactions/charts/get_anomaly_data/transform.ts
@@ -0,0 +1,136 @@
+/*
+ * 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 { first, last } from 'lodash';
+import { Coordinate, RectCoordinate } from '../../../../../typings/timeseries';
+import { ESResponse } from './fetcher';
+
+type IBucket = ReturnType;
+function getBucket(
+ bucket: Required<
+ ESResponse
+ >['aggregations']['ml_avg_response_times']['buckets'][0]
+) {
+ return {
+ x: bucket.key,
+ anomalyScore: bucket.anomaly_score.value,
+ lower: bucket.lower.value,
+ upper: bucket.upper.value,
+ };
+}
+
+export type AnomalyTimeSeriesResponse = ReturnType<
+ typeof anomalySeriesTransform
+>;
+export function anomalySeriesTransform(
+ response: ESResponse,
+ mlBucketSize: number,
+ bucketSize: number,
+ timeSeriesDates: number[],
+ jobId: string
+) {
+ const buckets =
+ response.aggregations?.ml_avg_response_times.buckets.map(getBucket) || [];
+
+ const bucketSizeInMillis = Math.max(bucketSize, mlBucketSize) * 1000;
+
+ return {
+ jobId,
+ anomalyScore: getAnomalyScoreDataPoints(
+ buckets,
+ timeSeriesDates,
+ bucketSizeInMillis
+ ),
+ anomalyBoundaries: getAnomalyBoundaryDataPoints(buckets, timeSeriesDates),
+ };
+}
+
+export function getAnomalyScoreDataPoints(
+ buckets: IBucket[],
+ timeSeriesDates: number[],
+ bucketSizeInMillis: number
+): RectCoordinate[] {
+ const ANOMALY_THRESHOLD = 75;
+ const firstDate = first(timeSeriesDates);
+ const lastDate = last(timeSeriesDates);
+
+ if (firstDate === undefined || lastDate === undefined) {
+ return [];
+ }
+
+ return buckets
+ .filter(
+ (bucket) =>
+ bucket.anomalyScore !== null && bucket.anomalyScore > ANOMALY_THRESHOLD
+ )
+ .filter(isInDateRange(firstDate, lastDate))
+ .map((bucket) => {
+ return {
+ x0: bucket.x,
+ x: Math.min(bucket.x + bucketSizeInMillis, lastDate), // don't go beyond last date
+ };
+ });
+}
+
+export function getAnomalyBoundaryDataPoints(
+ buckets: IBucket[],
+ timeSeriesDates: number[]
+): Coordinate[] {
+ return replaceFirstAndLastBucket(buckets, timeSeriesDates)
+ .filter((bucket) => bucket.lower !== null)
+ .map((bucket) => {
+ return {
+ x: bucket.x,
+ y0: bucket.lower,
+ y: bucket.upper,
+ };
+ });
+}
+
+export function replaceFirstAndLastBucket(
+ buckets: IBucket[],
+ timeSeriesDates: number[]
+) {
+ const firstDate = first(timeSeriesDates);
+ const lastDate = last(timeSeriesDates);
+
+ if (firstDate === undefined || lastDate === undefined) {
+ return buckets;
+ }
+
+ const preBucketWithValue = buckets
+ .filter((p) => p.x <= firstDate)
+ .reverse()
+ .find((p) => p.lower !== null);
+
+ const bucketsInRange = buckets.filter(isInDateRange(firstDate, lastDate));
+
+ // replace first bucket if it is null
+ const firstBucket = first(bucketsInRange);
+ if (preBucketWithValue && firstBucket && firstBucket.lower === null) {
+ firstBucket.lower = preBucketWithValue.lower;
+ firstBucket.upper = preBucketWithValue.upper;
+ }
+
+ const lastBucketWithValue = [...buckets]
+ .reverse()
+ .find((p) => p.lower !== null);
+
+ // replace last bucket if it is null
+ const lastBucket = last(bucketsInRange);
+ if (lastBucketWithValue && lastBucket && lastBucket.lower === null) {
+ lastBucket.lower = lastBucketWithValue.lower;
+ lastBucket.upper = lastBucketWithValue.upper;
+ }
+
+ return bucketsInRange;
+}
+
+// anomaly time series contain one or more buckets extra in the beginning
+// these extra buckets should be removed
+function isInDateRange(firstDate: number, lastDate: number) {
+ return (p: IBucket) => p.x >= firstDate && p.x <= lastDate;
+}
diff --git a/x-pack/plugins/apm/server/lib/transactions/charts/index.ts b/x-pack/plugins/apm/server/lib/transactions/charts/index.ts
index 2ec049002d605..e862982145f77 100644
--- a/x-pack/plugins/apm/server/lib/transactions/charts/index.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/charts/index.ts
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { Logger } from 'kibana/server';
import { PromiseReturnType } from '../../../../../observability/typings/common';
import {
Setup,
@@ -13,6 +14,7 @@ import {
import { getAnomalySeries } from './get_anomaly_data';
import { getApmTimeseriesData } from './get_timeseries_data';
import { ApmTimeSeriesResponse } from './get_timeseries_data/transform';
+import { UIFilters } from '../../../../typings/ui_filters';
function getDates(apmTimeseries: ApmTimeSeriesResponse) {
return apmTimeseries.responseTimes.avg.map((p) => p.x);
@@ -26,6 +28,8 @@ export async function getTransactionCharts(options: {
transactionType: string | undefined;
transactionName: string | undefined;
setup: Setup & SetupTimeRange & SetupUIFilters;
+ logger: Logger;
+ uiFilters: UIFilters;
}) {
const apmTimeseries = await getApmTimeseriesData(options);
const anomalyTimeseries = await getAnomalySeries({
diff --git a/x-pack/plugins/apm/server/lib/transactions/queries.test.ts b/x-pack/plugins/apm/server/lib/transactions/queries.test.ts
index 713635cff2fbf..586fa1798b7bc 100644
--- a/x-pack/plugins/apm/server/lib/transactions/queries.test.ts
+++ b/x-pack/plugins/apm/server/lib/transactions/queries.test.ts
@@ -12,6 +12,8 @@ import {
SearchParamsMock,
inspectSearchParams,
} from '../../../public/utils/testHelpers';
+// eslint-disable-next-line @kbn/eslint/no-restricted-paths
+import { loggerMock } from '../../../../../../src/core/server/logging/logger.mock';
describe('transaction queries', () => {
let mock: SearchParamsMock;
@@ -52,6 +54,8 @@ describe('transaction queries', () => {
transactionName: undefined,
transactionType: undefined,
setup,
+ logger: loggerMock.create(),
+ uiFilters: {},
})
);
expect(mock.params).toMatchSnapshot();
@@ -64,6 +68,8 @@ describe('transaction queries', () => {
transactionName: 'bar',
transactionType: undefined,
setup,
+ logger: loggerMock.create(),
+ uiFilters: {},
})
);
expect(mock.params).toMatchSnapshot();
@@ -76,6 +82,8 @@ describe('transaction queries', () => {
transactionName: 'bar',
transactionType: 'baz',
setup,
+ logger: loggerMock.create(),
+ uiFilters: {},
})
);
diff --git a/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts b/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts
index 7009470e1ff17..4d564b773e397 100644
--- a/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts
+++ b/x-pack/plugins/apm/server/routes/settings/anomaly_detection.ts
@@ -18,10 +18,13 @@ export const anomalyDetectionJobsRoute = createRoute(() => ({
path: '/api/apm/settings/anomaly-detection',
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
- const jobs = await getAnomalyDetectionJobs(setup, context.logger);
+ const [jobs, legacyJobs] = await Promise.all([
+ getAnomalyDetectionJobs(setup, context.logger),
+ hasLegacyJobs(setup),
+ ]);
return {
jobs,
- hasLegacyJobs: await hasLegacyJobs(setup),
+ hasLegacyJobs: legacyJobs,
};
},
}));
diff --git a/x-pack/plugins/apm/server/routes/transaction_groups.ts b/x-pack/plugins/apm/server/routes/transaction_groups.ts
index 9ad281159fca5..3d939b04795c6 100644
--- a/x-pack/plugins/apm/server/routes/transaction_groups.ts
+++ b/x-pack/plugins/apm/server/routes/transaction_groups.ts
@@ -14,6 +14,7 @@ import { createRoute } from './create_route';
import { uiFiltersRt, rangeRt } from './default_api_types';
import { getTransactionAvgDurationByBrowser } from '../lib/transactions/avg_duration_by_browser';
import { getTransactionAvgDurationByCountry } from '../lib/transactions/avg_duration_by_country';
+import { UIFilters } from '../../typings/ui_filters';
export const transactionGroupsRoute = createRoute(() => ({
path: '/api/apm/services/{serviceName}/transaction_groups',
@@ -62,14 +63,27 @@ export const transactionGroupsChartsRoute = createRoute(() => ({
},
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
+ const logger = context.logger;
const { serviceName } = context.params.path;
- const { transactionType, transactionName } = context.params.query;
+ const {
+ transactionType,
+ transactionName,
+ uiFilters: uiFiltersJson,
+ } = context.params.query;
+ let uiFilters: UIFilters = {};
+ try {
+ uiFilters = JSON.parse(uiFiltersJson);
+ } catch (error) {
+ logger.error(error);
+ }
return getTransactionCharts({
serviceName,
transactionType,
transactionName,
setup,
+ logger,
+ uiFilters,
});
},
}));
diff --git a/x-pack/plugins/enterprise_search/README.md b/x-pack/plugins/enterprise_search/README.md
index 8c316c848184b..31ee304fe2247 100644
--- a/x-pack/plugins/enterprise_search/README.md
+++ b/x-pack/plugins/enterprise_search/README.md
@@ -2,7 +2,10 @@
## Overview
-This plugin's goal is to provide a Kibana user interface to the Enterprise Search solution's products (App Search and Workplace Search). In its current MVP state, the plugin provides a basic engines overview from App Search with the goal of gathering user feedback and raising product awareness.
+This plugin's goal is to provide a Kibana user interface to the Enterprise Search solution's products (App Search and Workplace Search). In it's current MVP state, the plugin provides the following with the goal of gathering user feedback and raising product awareness:
+
+- **App Search:** A basic engines overview with links into the product.
+- **Workplace Search:** A simple app overview with basic statistics, links to the sources, users (if standard auth), and product settings.
## Development
diff --git a/x-pack/plugins/enterprise_search/common/constants.ts b/x-pack/plugins/enterprise_search/common/constants.ts
index c134131caba75..fc9a47717871b 100644
--- a/x-pack/plugins/enterprise_search/common/constants.ts
+++ b/x-pack/plugins/enterprise_search/common/constants.ts
@@ -4,4 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/
+export const JSON_HEADER = { 'Content-Type': 'application/json' }; // This needs specific casing or Chrome throws a 415 error
+
export const ENGINES_PAGE_SIZE = 10;
diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/index.ts b/x-pack/plugins/enterprise_search/public/applications/__mocks__/index.ts
index 14fde357a980a..6f82946c0ea14 100644
--- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/index.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/index.ts
@@ -7,7 +7,11 @@
export { mockHistory } from './react_router_history.mock';
export { mockKibanaContext } from './kibana_context.mock';
export { mockLicenseContext } from './license_context.mock';
-export { mountWithContext, mountWithKibanaContext } from './mount_with_context.mock';
+export {
+ mountWithContext,
+ mountWithKibanaContext,
+ mountWithAsyncContext,
+} from './mount_with_context.mock';
export { shallowWithIntl } from './shallow_with_i18n.mock';
// Note: shallow_usecontext must be imported directly as a file
diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx
index dfcda544459d4..1e0df1326c177 100644
--- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx
@@ -5,7 +5,8 @@
*/
import React from 'react';
-import { mount } from 'enzyme';
+import { act } from 'react-dom/test-utils';
+import { mount, ReactWrapper } from 'enzyme';
import { I18nProvider } from '@kbn/i18n/react';
import { KibanaContext } from '../';
@@ -47,3 +48,33 @@ export const mountWithKibanaContext = (children: React.ReactNode, context?: obje
);
};
+
+/**
+ * This helper is intended for components that have async effects
+ * (e.g. http fetches) on mount. It mostly adds act/update boilerplate
+ * that's needed for the wrapper to play nice with Enzyme/Jest
+ *
+ * Example usage:
+ *
+ * const wrapper = mountWithAsyncContext( , { http: { get: () => someData } });
+ */
+export const mountWithAsyncContext = async (
+ children: React.ReactNode,
+ context: object
+): Promise => {
+ let wrapper: ReactWrapper | undefined;
+
+ // We get a lot of act() warning/errors in the terminal without this.
+ // TBH, I don't fully understand why since Enzyme's mount is supposed to
+ // have act() baked in - could be because of the wrapping context provider?
+ await act(async () => {
+ wrapper = mountWithContext(children, context);
+ });
+ if (wrapper) {
+ wrapper.update(); // This seems to be required for the DOM to actually update
+
+ return wrapper;
+ } else {
+ throw new Error('Could not mount wrapper');
+ }
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_usecontext.mock.ts b/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_usecontext.mock.ts
index 767a52a75d1fb..2bcdd42c38055 100644
--- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_usecontext.mock.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_usecontext.mock.ts
@@ -19,7 +19,7 @@ jest.mock('react', () => ({
/**
* Example usage within a component test using shallow():
*
- * import '../../../test_utils/mock_shallow_usecontext'; // Must come before React's import, adjust relative path as needed
+ * import '../../../__mocks__/shallow_usecontext'; // Must come before React's import, adjust relative path as needed
*
* import React from 'react';
* import { shallow } from 'enzyme';
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx
index 12bf003564103..25a9fa7430c40 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx
@@ -9,6 +9,7 @@ import '../../../__mocks__/shallow_usecontext.mock';
import React from 'react';
import { shallow } from 'enzyme';
import { EuiEmptyPrompt, EuiButton, EuiLoadingContent } from '@elastic/eui';
+import { ErrorStatePrompt } from '../../../shared/error_state';
jest.mock('../../../shared/telemetry', () => ({
sendTelemetry: jest.fn(),
@@ -22,7 +23,7 @@ describe('ErrorState', () => {
it('renders', () => {
const wrapper = shallow( );
- expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(1);
+ expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1);
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx
index d8eeff2aba1c6..7ac02082ee75c 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx
@@ -4,21 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useContext } from 'react';
-import { EuiPage, EuiPageBody, EuiPageContent, EuiEmptyPrompt, EuiCode } from '@elastic/eui';
-import { FormattedMessage } from '@kbn/i18n/react';
+import React from 'react';
+import { EuiPage, EuiPageBody, EuiPageContent } from '@elastic/eui';
-import { EuiButton } from '../../../shared/react_router_helpers';
+import { ErrorStatePrompt } from '../../../shared/error_state';
import { SetAppSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
import { SendAppSearchTelemetry as SendTelemetry } from '../../../shared/telemetry';
-import { KibanaContext, IKibanaContext } from '../../../index';
import { EngineOverviewHeader } from '../engine_overview_header';
import './empty_states.scss';
export const ErrorState: React.FC = () => {
- const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
-
return (
@@ -26,68 +22,8 @@ export const ErrorState: React.FC = () => {
-
-
-
-
- }
- titleSize="l"
- body={
- <>
-
- {enterpriseSearchUrl},
- }}
- />
-
-
-
- config/kibana.yml,
- }}
- />
-
-
-
-
-
- [enterpriseSearch][plugins],
- }}
- />
-
-
- >
- }
- actions={
-
-
-
- }
- />
+
+
diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx
index 4d2a2ea1df9aa..45ab5dc5b9ab1 100644
--- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx
@@ -8,51 +8,45 @@ import '../../../__mocks__/react_router_history.mock';
import React from 'react';
import { act } from 'react-dom/test-utils';
-import { render, ReactWrapper } from 'enzyme';
+import { shallow, ReactWrapper } from 'enzyme';
-import { I18nProvider } from '@kbn/i18n/react';
-import { KibanaContext } from '../../../';
-import { LicenseContext } from '../../../shared/licensing';
-import { mountWithContext, mockKibanaContext } from '../../../__mocks__';
+import { mountWithAsyncContext, mockKibanaContext } from '../../../__mocks__';
-import { EmptyState, ErrorState } from '../empty_states';
-import { EngineTable, IEngineTablePagination } from './engine_table';
+import { LoadingState, EmptyState, ErrorState } from '../empty_states';
+import { EngineTable } from './engine_table';
import { EngineOverview } from './';
describe('EngineOverview', () => {
+ const mockHttp = mockKibanaContext.http;
+
describe('non-happy-path states', () => {
it('isLoading', () => {
- // We use render() instead of mount() here to not trigger lifecycle methods (i.e., useEffect)
- // TODO: Consider pulling this out to a renderWithContext mock/helper
- const wrapper: Cheerio = render(
-
-
-
-
-
-
-
- );
-
- // render() directly renders HTML which means we have to look for selectors instead of for LoadingState directly
- expect(wrapper.find('.euiLoadingContent')).toHaveLength(2);
+ const wrapper = shallow( );
+
+ expect(wrapper.find(LoadingState)).toHaveLength(1);
});
it('isEmpty', async () => {
- const wrapper = await mountWithApiMock({
- get: () => ({
- results: [],
- meta: { page: { total_results: 0 } },
- }),
+ const wrapper = await mountWithAsyncContext( , {
+ http: {
+ ...mockHttp,
+ get: () => ({
+ results: [],
+ meta: { page: { total_results: 0 } },
+ }),
+ },
});
expect(wrapper.find(EmptyState)).toHaveLength(1);
});
it('hasErrorConnecting', async () => {
- const wrapper = await mountWithApiMock({
- get: () => ({ invalidPayload: true }),
+ const wrapper = await mountWithAsyncContext( , {
+ http: {
+ ...mockHttp,
+ get: () => ({ invalidPayload: true }),
+ },
});
expect(wrapper.find(ErrorState)).toHaveLength(1);
});
@@ -78,17 +72,17 @@ describe('EngineOverview', () => {
},
};
const mockApi = jest.fn(() => mockedApiResponse);
- let wrapper: ReactWrapper;
- beforeAll(async () => {
- wrapper = await mountWithApiMock({ get: mockApi });
+ beforeEach(() => {
+ jest.clearAllMocks();
});
- it('renders', () => {
- expect(wrapper.find(EngineTable)).toHaveLength(1);
- });
+ it('renders and calls the engines API', async () => {
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ });
- it('calls the engines API', () => {
+ expect(wrapper.find(EngineTable)).toHaveLength(1);
expect(mockApi).toHaveBeenNthCalledWith(1, '/api/app_search/engines', {
query: {
type: 'indexed',
@@ -97,19 +91,42 @@ describe('EngineOverview', () => {
});
});
+ describe('when on a platinum license', () => {
+ it('renders a 2nd meta engines table & makes a 2nd meta engines API call', async () => {
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ license: { type: 'platinum', isActive: true },
+ });
+
+ expect(wrapper.find(EngineTable)).toHaveLength(2);
+ expect(mockApi).toHaveBeenNthCalledWith(2, '/api/app_search/engines', {
+ query: {
+ type: 'meta',
+ pageIndex: 1,
+ },
+ });
+ });
+ });
+
describe('pagination', () => {
- const getTablePagination: () => IEngineTablePagination = () =>
- wrapper.find(EngineTable).first().prop('pagination');
+ const getTablePagination = (wrapper: ReactWrapper) =>
+ wrapper.find(EngineTable).prop('pagination');
- it('passes down page data from the API', () => {
- const pagination = getTablePagination();
+ it('passes down page data from the API', async () => {
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ });
+ const pagination = getTablePagination(wrapper);
expect(pagination.totalEngines).toEqual(100);
expect(pagination.pageIndex).toEqual(0);
});
it('re-polls the API on page change', async () => {
- await act(async () => getTablePagination().onPaginate(5));
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ });
+ await act(async () => getTablePagination(wrapper).onPaginate(5));
wrapper.update();
expect(mockApi).toHaveBeenLastCalledWith('/api/app_search/engines', {
@@ -118,54 +135,8 @@ describe('EngineOverview', () => {
pageIndex: 5,
},
});
- expect(getTablePagination().pageIndex).toEqual(4);
- });
- });
-
- describe('when on a platinum license', () => {
- beforeAll(async () => {
- mockApi.mockClear();
- wrapper = await mountWithApiMock({
- license: { type: 'platinum', isActive: true },
- get: mockApi,
- });
- });
-
- it('renders a 2nd meta engines table', () => {
- expect(wrapper.find(EngineTable)).toHaveLength(2);
- });
-
- it('makes a 2nd call to the engines API with type meta', () => {
- expect(mockApi).toHaveBeenNthCalledWith(2, '/api/app_search/engines', {
- query: {
- type: 'meta',
- pageIndex: 1,
- },
- });
+ expect(getTablePagination(wrapper).pageIndex).toEqual(4);
});
});
});
-
- /**
- * Test helpers
- */
-
- const mountWithApiMock = async ({ get, license }: { get(): any; license?: object }) => {
- let wrapper: ReactWrapper | undefined;
- const httpMock = { ...mockKibanaContext.http, get };
-
- // We get a lot of act() warning/errors in the terminal without this.
- // TBH, I don't fully understand why since Enzyme's mount is supposed to
- // have act() baked in - could be because of the wrapping context provider?
- await act(async () => {
- wrapper = mountWithContext( , { http: httpMock, license });
- });
- if (wrapper) {
- wrapper.update(); // This seems to be required for the DOM to actually update
-
- return wrapper;
- } else {
- throw new Error('Could not mount wrapper');
- }
- };
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/index.test.tsx
index 1aead8468ca3b..70e16e61846b4 100644
--- a/x-pack/plugins/enterprise_search/public/applications/index.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/index.test.tsx
@@ -6,14 +6,16 @@
import React from 'react';
+import { AppMountParameters } from 'src/core/public';
import { coreMock } from 'src/core/public/mocks';
import { licensingMock } from '../../../licensing/public/mocks';
import { renderApp } from './';
import { AppSearch } from './app_search';
+import { WorkplaceSearch } from './workplace_search';
describe('renderApp', () => {
- const params = coreMock.createAppMountParamters();
+ let params: AppMountParameters;
const core = coreMock.createStart();
const config = {};
const plugins = {
@@ -22,6 +24,7 @@ describe('renderApp', () => {
beforeEach(() => {
jest.clearAllMocks();
+ params = coreMock.createAppMountParamters();
});
it('mounts and unmounts UI', () => {
@@ -37,4 +40,9 @@ describe('renderApp', () => {
renderApp(AppSearch, core, params, config, plugins);
expect(params.element.querySelector('.setupGuide')).not.toBeNull();
});
+
+ it('renders WorkplaceSearch', () => {
+ renderApp(WorkplaceSearch, core, params, config, plugins);
+ expect(params.element.querySelector('.setupGuide')).not.toBeNull();
+ });
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.test.tsx
new file mode 100644
index 0000000000000..29b773b80158a
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.test.tsx
@@ -0,0 +1,21 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiEmptyPrompt } from '@elastic/eui';
+
+import { ErrorStatePrompt } from './';
+
+describe('ErrorState', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.tsx
new file mode 100644
index 0000000000000..81455cea0b497
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/error_state_prompt.tsx
@@ -0,0 +1,79 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+import { EuiEmptyPrompt, EuiCode } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import { EuiButton } from '../react_router_helpers';
+import { KibanaContext, IKibanaContext } from '../../index';
+
+export const ErrorStatePrompt: React.FC = () => {
+ const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
+
+ return (
+
+
+
+ }
+ titleSize="l"
+ body={
+ <>
+
+ {enterpriseSearchUrl},
+ }}
+ />
+
+
+
+ config/kibana.yml,
+ }}
+ />
+
+
+
+
+
+ [enterpriseSearch][plugins],
+ }}
+ />
+
+
+ >
+ }
+ actions={
+
+
+
+ }
+ />
+ );
+};
diff --git a/x-pack/plugins/apm/typings/anomaly_detection.ts b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/index.ts
similarity index 73%
rename from x-pack/plugins/apm/typings/anomaly_detection.ts
rename to x-pack/plugins/enterprise_search/public/applications/shared/error_state/index.ts
index 30dc92c36dea4..1012fdf4126a2 100644
--- a/x-pack/plugins/apm/typings/anomaly_detection.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/error_state/index.ts
@@ -4,7 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/
-export interface AnomalyDetectionJobByEnv {
- environment: string;
- job_id: string;
-}
+export { ErrorStatePrompt } from './error_state_prompt';
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts
index 7ea73577c4de6..70aa723d62601 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts
@@ -5,7 +5,7 @@
*/
import { generateBreadcrumb } from './generate_breadcrumbs';
-import { appSearchBreadcrumbs, enterpriseSearchBreadcrumbs } from './';
+import { appSearchBreadcrumbs, enterpriseSearchBreadcrumbs, workplaceSearchBreadcrumbs } from './';
import { mockHistory as mockHistoryUntyped } from '../../__mocks__';
const mockHistory = mockHistoryUntyped as any;
@@ -204,3 +204,86 @@ describe('appSearchBreadcrumbs', () => {
});
});
});
+
+describe('workplaceSearchBreadcrumbs', () => {
+ const breadCrumbs = [
+ {
+ text: 'Page 1',
+ path: '/page1',
+ },
+ {
+ text: 'Page 2',
+ path: '/page2',
+ },
+ ];
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mockHistory.createHref.mockImplementation(
+ ({ pathname }: any) => `/enterprise_search/workplace_search${pathname}`
+ );
+ });
+
+ const subject = () => workplaceSearchBreadcrumbs(mockHistory)(breadCrumbs);
+
+ it('Builds a chain of breadcrumbs with Enterprise Search and Workplace Search at the root', () => {
+ expect(subject()).toEqual([
+ {
+ text: 'Enterprise Search',
+ },
+ {
+ href: '/enterprise_search/workplace_search/',
+ onClick: expect.any(Function),
+ text: 'Workplace Search',
+ },
+ {
+ href: '/enterprise_search/workplace_search/page1',
+ onClick: expect.any(Function),
+ text: 'Page 1',
+ },
+ {
+ href: '/enterprise_search/workplace_search/page2',
+ onClick: expect.any(Function),
+ text: 'Page 2',
+ },
+ ]);
+ });
+
+ it('shows just the root if breadcrumbs is empty', () => {
+ expect(workplaceSearchBreadcrumbs(mockHistory)()).toEqual([
+ {
+ text: 'Enterprise Search',
+ },
+ {
+ href: '/enterprise_search/workplace_search/',
+ onClick: expect.any(Function),
+ text: 'Workplace Search',
+ },
+ ]);
+ });
+
+ describe('links', () => {
+ const eventMock = {
+ preventDefault: jest.fn(),
+ } as any;
+
+ it('has Enterprise Search text first', () => {
+ expect(subject()[0].onClick).toBeUndefined();
+ });
+
+ it('has a link to Workplace Search second', () => {
+ (subject()[1] as any).onClick(eventMock);
+ expect(mockHistory.push).toHaveBeenCalledWith('/');
+ });
+
+ it('has a link to page 1 third', () => {
+ (subject()[2] as any).onClick(eventMock);
+ expect(mockHistory.push).toHaveBeenCalledWith('/page1');
+ });
+
+ it('has a link to page 2 last', () => {
+ (subject()[3] as any).onClick(eventMock);
+ expect(mockHistory.push).toHaveBeenCalledWith('/page2');
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts
index 8f72875a32bd4..b57fdfdbb75ca 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts
@@ -52,3 +52,6 @@ export const enterpriseSearchBreadcrumbs = (history: History) => (
export const appSearchBreadcrumbs = (history: History) => (breadcrumbs: TBreadcrumbs = []) =>
enterpriseSearchBreadcrumbs(history)([{ text: 'App Search', path: '/' }, ...breadcrumbs]);
+
+export const workplaceSearchBreadcrumbs = (history: History) => (breadcrumbs: TBreadcrumbs = []) =>
+ enterpriseSearchBreadcrumbs(history)([{ text: 'Workplace Search', path: '/' }, ...breadcrumbs]);
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/index.ts
index cf8bbbc593f2f..c4ef68704b7e0 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/index.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/index.ts
@@ -4,6 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/
-export { enterpriseSearchBreadcrumbs } from './generate_breadcrumbs';
-export { appSearchBreadcrumbs } from './generate_breadcrumbs';
-export { SetAppSearchBreadcrumbs } from './set_breadcrumbs';
+export {
+ enterpriseSearchBreadcrumbs,
+ appSearchBreadcrumbs,
+ workplaceSearchBreadcrumbs,
+} from './generate_breadcrumbs';
+export { SetAppSearchBreadcrumbs, SetWorkplaceSearchBreadcrumbs } from './set_breadcrumbs';
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx
index 530117e197616..e54f1a12b73cb 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx
@@ -8,7 +8,11 @@ import React, { useContext, useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { EuiBreadcrumb } from '@elastic/eui';
import { KibanaContext, IKibanaContext } from '../../index';
-import { appSearchBreadcrumbs, TBreadcrumbs } from './generate_breadcrumbs';
+import {
+ appSearchBreadcrumbs,
+ workplaceSearchBreadcrumbs,
+ TBreadcrumbs,
+} from './generate_breadcrumbs';
/**
* Small on-mount helper for setting Kibana's chrome breadcrumbs on any App Search view
@@ -17,19 +21,17 @@ import { appSearchBreadcrumbs, TBreadcrumbs } from './generate_breadcrumbs';
export type TSetBreadcrumbs = (breadcrumbs: EuiBreadcrumb[]) => void;
-interface IBreadcrumbProps {
+interface IBreadcrumbsProps {
text: string;
isRoot?: never;
}
-interface IRootBreadcrumbProps {
+interface IRootBreadcrumbsProps {
isRoot: true;
text?: never;
}
+type TBreadcrumbsProps = IBreadcrumbsProps | IRootBreadcrumbsProps;
-export const SetAppSearchBreadcrumbs: React.FC = ({
- text,
- isRoot,
-}) => {
+export const SetAppSearchBreadcrumbs: React.FC = ({ text, isRoot }) => {
const history = useHistory();
const { setBreadcrumbs } = useContext(KibanaContext) as IKibanaContext;
@@ -41,3 +43,16 @@ export const SetAppSearchBreadcrumbs: React.FC = ({ text, isRoot }) => {
+ const history = useHistory();
+ const { setBreadcrumbs } = useContext(KibanaContext) as IKibanaContext;
+
+ const crumb = isRoot ? [] : [{ text, path: history.location.pathname }];
+
+ useEffect(() => {
+ setBreadcrumbs(workplaceSearchBreadcrumbs(history)(crumb as TBreadcrumbs | []));
+ }, []);
+
+ return null;
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/index.ts b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/index.ts
index f871f48b17154..eadf7fa805590 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/index.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/index.ts
@@ -6,3 +6,4 @@
export { sendTelemetry } from './send_telemetry';
export { SendAppSearchTelemetry } from './send_telemetry';
+export { SendWorkplaceSearchTelemetry } from './send_telemetry';
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx
index 9825c0d8ab889..3c873dbc25e37 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx
@@ -7,8 +7,10 @@
import React from 'react';
import { httpServiceMock } from 'src/core/public/mocks';
+import { JSON_HEADER as headers } from '../../../../common/constants';
import { mountWithKibanaContext } from '../../__mocks__';
-import { sendTelemetry, SendAppSearchTelemetry } from './';
+
+import { sendTelemetry, SendAppSearchTelemetry, SendWorkplaceSearchTelemetry } from './';
describe('Shared Telemetry Helpers', () => {
const httpMock = httpServiceMock.createSetupContract();
@@ -27,8 +29,8 @@ describe('Shared Telemetry Helpers', () => {
});
expect(httpMock.put).toHaveBeenCalledWith('/api/enterprise_search/telemetry', {
- headers: { 'Content-Type': 'application/json' },
- body: '{"action":"viewed","metric":"setup_guide"}',
+ headers,
+ body: '{"product":"enterprise_search","action":"viewed","metric":"setup_guide"}',
});
});
@@ -47,9 +49,20 @@ describe('Shared Telemetry Helpers', () => {
http: httpMock,
});
- expect(httpMock.put).toHaveBeenCalledWith('/api/app_search/telemetry', {
- headers: { 'Content-Type': 'application/json' },
- body: '{"action":"clicked","metric":"button"}',
+ expect(httpMock.put).toHaveBeenCalledWith('/api/enterprise_search/telemetry', {
+ headers,
+ body: '{"product":"app_search","action":"clicked","metric":"button"}',
+ });
+ });
+
+ it('SendWorkplaceSearchTelemetry component', () => {
+ mountWithKibanaContext( , {
+ http: httpMock,
+ });
+
+ expect(httpMock.put).toHaveBeenCalledWith('/api/enterprise_search/telemetry', {
+ headers,
+ body: '{"product":"workplace_search","action":"viewed","metric":"page"}',
});
});
});
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx
index 300cb18272717..715d61b31512c 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx
@@ -7,6 +7,7 @@
import React, { useContext, useEffect } from 'react';
import { HttpSetup } from 'src/core/public';
+import { JSON_HEADER as headers } from '../../../../common/constants';
import { KibanaContext, IKibanaContext } from '../../index';
interface ISendTelemetryProps {
@@ -25,10 +26,8 @@ interface ISendTelemetry extends ISendTelemetryProps {
export const sendTelemetry = async ({ http, product, action, metric }: ISendTelemetry) => {
try {
- await http.put(`/api/${product}/telemetry`, {
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ action, metric }),
- });
+ const body = JSON.stringify({ product, action, metric });
+ await http.put('/api/enterprise_search/telemetry', { headers, body });
} catch (error) {
throw new Error('Unable to send telemetry');
}
@@ -36,7 +35,7 @@ export const sendTelemetry = async ({ http, product, action, metric }: ISendTele
/**
* React component helpers - useful for on-page-load/views
- * TODO: SendWorkplaceSearchTelemetry and SendEnterpriseSearchTelemetry
+ * TODO: SendEnterpriseSearchTelemetry
*/
export const SendAppSearchTelemetry: React.FC = ({ action, metric }) => {
@@ -48,3 +47,13 @@ export const SendAppSearchTelemetry: React.FC = ({ action,
return null;
};
+
+export const SendWorkplaceSearchTelemetry: React.FC = ({ action, metric }) => {
+ const { http } = useContext(KibanaContext) as IKibanaContext;
+
+ useEffect(() => {
+ sendTelemetry({ http, action, metric, product: 'workplace_search' });
+ }, [action, metric, http]);
+
+ return null;
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/types.ts b/x-pack/plugins/enterprise_search/public/applications/shared/types.ts
new file mode 100644
index 0000000000000..3f28710d92295
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/types.ts
@@ -0,0 +1,14 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export interface IFlashMessagesProps {
+ info?: string[];
+ warning?: string[];
+ error?: string[];
+ success?: string[];
+ isWrapped?: boolean;
+ children?: React.ReactNode;
+}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/getting_started.png b/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/getting_started.png
new file mode 100644
index 0000000000000..b6267b6e2c48e
Binary files /dev/null and b/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/getting_started.png differ
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/logo.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/logo.svg
new file mode 100644
index 0000000000000..e6b987c398268
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/assets/logo.svg
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.test.tsx
new file mode 100644
index 0000000000000..ab5cd7f0de90f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.test.tsx
@@ -0,0 +1,21 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { ErrorStatePrompt } from '../../../shared/error_state';
+import { ErrorState } from './';
+
+describe('ErrorState', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.tsx
new file mode 100644
index 0000000000000..9fa508d599425
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/error_state.tsx
@@ -0,0 +1,34 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { EuiPage, EuiPageBody, EuiPageContent } from '@elastic/eui';
+import { i18n } from '@kbn/i18n';
+
+import { ErrorStatePrompt } from '../../../shared/error_state';
+import { SetWorkplaceSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
+import { SendWorkplaceSearchTelemetry as SendTelemetry } from '../../../shared/telemetry';
+import { ViewContentHeader } from '../shared/view_content_header';
+
+export const ErrorState: React.FC = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/index.ts
new file mode 100644
index 0000000000000..b4d58bab58ff1
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/error_state/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { ErrorState } from './error_state';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/index.ts
new file mode 100644
index 0000000000000..9ee1b444ee817
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { Overview } from './overview';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.test.tsx
new file mode 100644
index 0000000000000..1d7c565935e97
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.test.tsx
@@ -0,0 +1,54 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { EuiEmptyPrompt, EuiButton, EuiButtonEmpty } from '@elastic/eui';
+
+import { OnboardingCard } from './onboarding_card';
+
+jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
+import { sendTelemetry } from '../../../shared/telemetry';
+
+const cardProps = {
+ title: 'My card',
+ icon: 'icon',
+ description: 'this is a card',
+ actionTitle: 'action',
+ testSubj: 'actionButton',
+};
+
+describe('OnboardingCard', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+ expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(1);
+ });
+
+ it('renders an action button', () => {
+ const wrapper = shallow( );
+ const prompt = wrapper.find(EuiEmptyPrompt).dive();
+
+ expect(prompt.find(EuiButton)).toHaveLength(1);
+ expect(prompt.find(EuiButtonEmpty)).toHaveLength(0);
+
+ const button = prompt.find('[data-test-subj="actionButton"]');
+ expect(button.prop('href')).toBe('http://localhost:3002/ws/some_path');
+
+ button.simulate('click');
+ expect(sendTelemetry).toHaveBeenCalled();
+ });
+
+ it('renders an empty button when onboarding is completed', () => {
+ const wrapper = shallow( );
+ const prompt = wrapper.find(EuiEmptyPrompt).dive();
+
+ expect(prompt.find(EuiButton)).toHaveLength(0);
+ expect(prompt.find(EuiButtonEmpty)).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.tsx
new file mode 100644
index 0000000000000..288c0be84fa9a
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_card.tsx
@@ -0,0 +1,92 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+
+import {
+ EuiButton,
+ EuiButtonEmpty,
+ EuiFlexItem,
+ EuiPanel,
+ EuiEmptyPrompt,
+ IconType,
+ EuiButtonProps,
+ EuiButtonEmptyProps,
+ EuiLinkProps,
+} from '@elastic/eui';
+import { useRoutes } from '../shared/use_routes';
+import { sendTelemetry } from '../../../shared/telemetry';
+import { KibanaContext, IKibanaContext } from '../../../index';
+
+interface IOnboardingCardProps {
+ title: React.ReactNode;
+ icon: React.ReactNode;
+ description: React.ReactNode;
+ actionTitle: React.ReactNode;
+ testSubj: string;
+ actionPath?: string;
+ complete?: boolean;
+}
+
+export const OnboardingCard: React.FC = ({
+ title,
+ icon,
+ description,
+ actionTitle,
+ testSubj,
+ actionPath,
+ complete,
+}) => {
+ const { http } = useContext(KibanaContext) as IKibanaContext;
+ const { getWSRoute } = useRoutes();
+
+ const onClick = () =>
+ sendTelemetry({
+ http,
+ product: 'workplace_search',
+ action: 'clicked',
+ metric: 'onboarding_card_button',
+ });
+ const buttonActionProps = actionPath
+ ? {
+ onClick,
+ href: getWSRoute(actionPath),
+ target: '_blank',
+ 'data-test-subj': testSubj,
+ }
+ : {
+ 'data-test-subj': testSubj,
+ };
+
+ const emptyButtonProps = {
+ ...buttonActionProps,
+ } as EuiButtonEmptyProps & EuiLinkProps;
+ const fillButtonProps = {
+ ...buttonActionProps,
+ color: 'secondary',
+ fill: true,
+ } as EuiButtonProps & EuiLinkProps;
+
+ return (
+
+
+ {title}}
+ body={description}
+ actions={
+ complete ? (
+ {actionTitle}
+ ) : (
+ {actionTitle}
+ )
+ }
+ />
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.test.tsx
new file mode 100644
index 0000000000000..6174dc1c795eb
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.test.tsx
@@ -0,0 +1,136 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { ORG_SOURCES_PATH, USERS_PATH } from '../../routes';
+
+jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
+import { sendTelemetry } from '../../../shared/telemetry';
+
+import { OnboardingSteps, OrgNameOnboarding } from './onboarding_steps';
+import { OnboardingCard } from './onboarding_card';
+import { defaultServerData } from './overview';
+
+const account = {
+ id: '1',
+ isAdmin: true,
+ canCreatePersonalSources: true,
+ groups: [],
+ supportEligible: true,
+ isCurated: false,
+};
+
+describe('OnboardingSteps', () => {
+ describe('Shared Sources', () => {
+ it('renders 0 sources state', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(OnboardingCard)).toHaveLength(1);
+ expect(wrapper.find(OnboardingCard).prop('actionPath')).toBe(ORG_SOURCES_PATH);
+ expect(wrapper.find(OnboardingCard).prop('description')).toBe(
+ 'Add shared sources for your organization to start searching.'
+ );
+ });
+
+ it('renders completed sources state', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OnboardingCard).prop('description')).toEqual(
+ 'You have added 2 shared sources. Happy searching.'
+ );
+ });
+
+ it('disables link when the user cannot create sources', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OnboardingCard).prop('actionPath')).toBe(undefined);
+ });
+ });
+
+ describe('Users & Invitations', () => {
+ it('renders 0 users when not on federated auth', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OnboardingCard)).toHaveLength(2);
+ expect(wrapper.find(OnboardingCard).last().prop('actionPath')).toBe(USERS_PATH);
+ expect(wrapper.find(OnboardingCard).last().prop('description')).toEqual(
+ 'Invite your colleagues into this organization to search with you.'
+ );
+ });
+
+ it('renders completed users state', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OnboardingCard).last().prop('description')).toEqual(
+ 'Nice, you’ve invited colleagues to search with you.'
+ );
+ });
+
+ it('disables link when the user cannot create invitations', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OnboardingCard).last().prop('actionPath')).toBe(undefined);
+ });
+ });
+
+ describe('Org Name', () => {
+ it('renders button to change name', () => {
+ const wrapper = shallow( );
+
+ const button = wrapper
+ .find(OrgNameOnboarding)
+ .dive()
+ .find('[data-test-subj="orgNameChangeButton"]');
+
+ button.simulate('click');
+ expect(sendTelemetry).toHaveBeenCalled();
+ });
+
+ it('hides card when name has been changed', () => {
+ const wrapper = shallow(
+
+ );
+
+ expect(wrapper.find(OrgNameOnboarding)).toHaveLength(0);
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.tsx
new file mode 100644
index 0000000000000..1b00347437338
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/onboarding_steps.tsx
@@ -0,0 +1,179 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+import { i18n } from '@kbn/i18n';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import {
+ EuiSpacer,
+ EuiButtonEmpty,
+ EuiTitle,
+ EuiPanel,
+ EuiIcon,
+ EuiFlexGrid,
+ EuiFlexItem,
+ EuiFlexGroup,
+ EuiButtonEmptyProps,
+ EuiLinkProps,
+} from '@elastic/eui';
+import sharedSourcesIcon from '../shared/assets/share_circle.svg';
+import { useRoutes } from '../shared/use_routes';
+import { sendTelemetry } from '../../../shared/telemetry';
+import { KibanaContext, IKibanaContext } from '../../../index';
+import { ORG_SOURCES_PATH, USERS_PATH, ORG_SETTINGS_PATH } from '../../routes';
+
+import { ContentSection } from '../shared/content_section';
+
+import { IAppServerData } from './overview';
+
+import { OnboardingCard } from './onboarding_card';
+
+const SOURCES_TITLE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingSourcesCard.title',
+ { defaultMessage: 'Shared sources' }
+);
+
+const USERS_TITLE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingUsersCard.title',
+ { defaultMessage: 'Users & invitations' }
+);
+
+const ONBOARDING_SOURCES_CARD_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingSourcesCard.description',
+ { defaultMessage: 'Add shared sources for your organization to start searching.' }
+);
+
+const USERS_CARD_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewUsersCard.title',
+ { defaultMessage: 'Nice, you’ve invited colleagues to search with you.' }
+);
+
+const ONBOARDING_USERS_CARD_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingUsersCard.description',
+ { defaultMessage: 'Invite your colleagues into this organization to search with you.' }
+);
+
+export const OnboardingSteps: React.FC = ({
+ hasUsers,
+ hasOrgSources,
+ canCreateContentSources,
+ canCreateInvitations,
+ accountsCount,
+ sourcesCount,
+ fpAccount: { isCurated },
+ organization: { name, defaultOrgName },
+ isFederatedAuth,
+}) => {
+ const accountsPath =
+ !isFederatedAuth && (canCreateInvitations || isCurated) ? USERS_PATH : undefined;
+ const sourcesPath = canCreateContentSources || isCurated ? ORG_SOURCES_PATH : undefined;
+
+ const SOURCES_CARD_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.sourcesOnboardingCard.description',
+ {
+ defaultMessage:
+ 'You have added {sourcesCount, number} shared {sourcesCount, plural, one {source} other {sources}}. Happy searching.',
+ values: { sourcesCount },
+ }
+ );
+
+ return (
+
+
+ 0 ? 'more' : '' },
+ }
+ )}
+ actionPath={sourcesPath}
+ complete={hasOrgSources}
+ />
+ {!isFederatedAuth && (
+ 0 ? 'more' : '' },
+ }
+ )}
+ actionPath={accountsPath}
+ complete={hasUsers}
+ />
+ )}
+
+ {name === defaultOrgName && (
+ <>
+
+
+ >
+ )}
+
+ );
+};
+
+export const OrgNameOnboarding: React.FC = () => {
+ const { http } = useContext(KibanaContext) as IKibanaContext;
+ const { getWSRoute } = useRoutes();
+
+ const onClick = () =>
+ sendTelemetry({
+ http,
+ product: 'workplace_search',
+ action: 'clicked',
+ metric: 'org_name_change_button',
+ });
+
+ const buttonProps = {
+ onClick,
+ target: '_blank',
+ color: 'primary',
+ href: getWSRoute(ORG_SETTINGS_PATH),
+ 'data-test-subj': 'orgNameChangeButton',
+ } as EuiButtonEmptyProps & EuiLinkProps;
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.test.tsx
new file mode 100644
index 0000000000000..112e9a910667a
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.test.tsx
@@ -0,0 +1,31 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiFlexGrid } from '@elastic/eui';
+
+import { OrganizationStats } from './organization_stats';
+import { StatisticCard } from './statistic_card';
+import { defaultServerData } from './overview';
+
+describe('OrganizationStats', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(StatisticCard)).toHaveLength(2);
+ expect(wrapper.find(EuiFlexGrid).prop('columns')).toEqual(2);
+ });
+
+ it('renders additional cards for federated auth', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(StatisticCard)).toHaveLength(4);
+ expect(wrapper.find(EuiFlexGrid).prop('columns')).toEqual(4);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.tsx
new file mode 100644
index 0000000000000..aa9be81f32bae
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/organization_stats.tsx
@@ -0,0 +1,74 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { EuiFlexGrid } from '@elastic/eui';
+
+import { FormattedMessage } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
+
+import { ContentSection } from '../shared/content_section';
+import { ORG_SOURCES_PATH, USERS_PATH } from '../../routes';
+
+import { IAppServerData } from './overview';
+
+import { StatisticCard } from './statistic_card';
+
+export const OrganizationStats: React.FC = ({
+ sourcesCount,
+ pendingInvitationsCount,
+ accountsCount,
+ personalSourcesCount,
+ isFederatedAuth,
+}) => (
+
+ }
+ headerSpacer="m"
+ >
+
+
+ {!isFederatedAuth && (
+ <>
+
+
+ >
+ )}
+
+
+
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx
new file mode 100644
index 0000000000000..e5e5235c52368
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.test.tsx
@@ -0,0 +1,77 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/react_router_history.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { mountWithAsyncContext, mockKibanaContext } from '../../../__mocks__';
+
+import { ErrorState } from '../error_state';
+import { Loading } from '../shared/loading';
+import { ViewContentHeader } from '../shared/view_content_header';
+
+import { OnboardingSteps } from './onboarding_steps';
+import { OrganizationStats } from './organization_stats';
+import { RecentActivity } from './recent_activity';
+import { Overview, defaultServerData } from './overview';
+
+describe('Overview', () => {
+ const mockHttp = mockKibanaContext.http;
+
+ describe('non-happy-path states', () => {
+ it('isLoading', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(Loading)).toHaveLength(1);
+ });
+
+ it('hasErrorConnecting', async () => {
+ const wrapper = await mountWithAsyncContext( , {
+ http: {
+ ...mockHttp,
+ get: () => Promise.reject({ invalidPayload: true }),
+ },
+ });
+
+ expect(wrapper.find(ErrorState)).toHaveLength(1);
+ });
+ });
+
+ describe('happy-path states', () => {
+ it('renders onboarding state', async () => {
+ const mockApi = jest.fn(() => defaultServerData);
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ });
+
+ expect(wrapper.find(ViewContentHeader)).toHaveLength(1);
+ expect(wrapper.find(OnboardingSteps)).toHaveLength(1);
+ expect(wrapper.find(OrganizationStats)).toHaveLength(1);
+ expect(wrapper.find(RecentActivity)).toHaveLength(1);
+ });
+
+ it('renders when onboarding complete', async () => {
+ const obCompleteData = {
+ ...defaultServerData,
+ hasUsers: true,
+ hasOrgSources: true,
+ isOldAccount: true,
+ organization: {
+ name: 'foo',
+ defaultOrgName: 'bar',
+ },
+ };
+ const mockApi = jest.fn(() => obCompleteData);
+ const wrapper = await mountWithAsyncContext( , {
+ http: { ...mockHttp, get: mockApi },
+ });
+
+ expect(wrapper.find(OnboardingSteps)).toHaveLength(0);
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx
new file mode 100644
index 0000000000000..bacd65a2be75f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/overview.tsx
@@ -0,0 +1,151 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext, useEffect, useState } from 'react';
+import { EuiPage, EuiPageBody, EuiSpacer } from '@elastic/eui';
+import { i18n } from '@kbn/i18n';
+
+import { SetWorkplaceSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
+import { SendWorkplaceSearchTelemetry as SendTelemetry } from '../../../shared/telemetry';
+import { KibanaContext, IKibanaContext } from '../../../index';
+
+import { IAccount } from '../../types';
+
+import { ErrorState } from '../error_state';
+
+import { Loading } from '../shared/loading';
+import { ProductButton } from '../shared/product_button';
+import { ViewContentHeader } from '../shared/view_content_header';
+
+import { OnboardingSteps } from './onboarding_steps';
+import { OrganizationStats } from './organization_stats';
+import { RecentActivity, IFeedActivity } from './recent_activity';
+
+export interface IAppServerData {
+ hasUsers: boolean;
+ hasOrgSources: boolean;
+ canCreateContentSources: boolean;
+ canCreateInvitations: boolean;
+ isOldAccount: boolean;
+ sourcesCount: number;
+ pendingInvitationsCount: number;
+ accountsCount: number;
+ personalSourcesCount: number;
+ activityFeed: IFeedActivity[];
+ organization: {
+ name: string;
+ defaultOrgName: string;
+ };
+ isFederatedAuth: boolean;
+ currentUser: {
+ firstName: string;
+ email: string;
+ name: string;
+ color: string;
+ };
+ fpAccount: IAccount;
+}
+
+export const defaultServerData = {
+ accountsCount: 1,
+ activityFeed: [],
+ canCreateContentSources: true,
+ canCreateInvitations: true,
+ currentUser: {
+ firstName: '',
+ email: '',
+ name: '',
+ color: '',
+ },
+ fpAccount: {} as IAccount,
+ hasOrgSources: false,
+ hasUsers: false,
+ isFederatedAuth: true,
+ isOldAccount: false,
+ organization: {
+ name: '',
+ defaultOrgName: '',
+ },
+ pendingInvitationsCount: 0,
+ personalSourcesCount: 0,
+ sourcesCount: 0,
+} as IAppServerData;
+
+const ONBOARDING_HEADER_TITLE = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingHeader.title',
+ { defaultMessage: 'Get started with Workplace Search' }
+);
+
+const HEADER_TITLE = i18n.translate('xpack.enterpriseSearch.workplaceSearch.overviewHeader.title', {
+ defaultMessage: 'Organization overview',
+});
+
+const ONBOARDING_HEADER_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewOnboardingHeader.description',
+ { defaultMessage: 'Complete the following to set up your organization.' }
+);
+
+const HEADER_DESCRIPTION = i18n.translate(
+ 'xpack.enterpriseSearch.workplaceSearch.overviewHeader.description',
+ { defaultMessage: "Your organizations's statistics and activity" }
+);
+
+export const Overview: React.FC = () => {
+ const { http } = useContext(KibanaContext) as IKibanaContext;
+
+ const [isLoading, setIsLoading] = useState(true);
+ const [hasErrorConnecting, setHasErrorConnecting] = useState(false);
+ const [appData, setAppData] = useState(defaultServerData);
+
+ const getAppData = async () => {
+ try {
+ const response = await http.get('/api/workplace_search/overview');
+ setAppData(response);
+ } catch (error) {
+ setHasErrorConnecting(true);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ getAppData();
+ }, []);
+
+ if (hasErrorConnecting) return ;
+ if (isLoading) return ;
+
+ const {
+ hasUsers,
+ hasOrgSources,
+ isOldAccount,
+ organization: { name: orgName, defaultOrgName },
+ } = appData as IAppServerData;
+ const hideOnboarding = hasUsers && hasOrgSources && isOldAccount && orgName !== defaultOrgName;
+
+ const headerTitle = hideOnboarding ? HEADER_TITLE : ONBOARDING_HEADER_TITLE;
+ const headerDescription = hideOnboarding ? HEADER_DESCRIPTION : ONBOARDING_HEADER_DESCRIPTION;
+
+ return (
+
+
+
+
+
+ }
+ />
+ {!hideOnboarding && }
+
+
+
+
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.scss b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.scss
new file mode 100644
index 0000000000000..2d1e474c03faa
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.scss
@@ -0,0 +1,37 @@
+/*
+ * 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.
+ */
+
+.activity {
+ display: flex;
+ justify-content: space-between;
+ padding: $euiSizeM;
+ font-size: $euiFontSizeS;
+
+ &--error {
+ font-weight: $euiFontWeightSemiBold;
+ color: $euiColorDanger;
+ background: rgba($euiColorDanger, 0.1);
+
+ &__label {
+ margin-left: $euiSizeS * 1.75;
+ font-weight: $euiFontWeightRegular;
+ text-decoration: underline;
+ opacity: 0.7;
+ }
+ }
+
+ &__message {
+ flex-grow: 1;
+ }
+
+ &__date {
+ flex-grow: 0;
+ }
+
+ & + & {
+ border-top: $euiBorderThin;
+ }
+}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.test.tsx
new file mode 100644
index 0000000000000..e9bdedb199dad
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.test.tsx
@@ -0,0 +1,61 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { EuiEmptyPrompt, EuiLink } from '@elastic/eui';
+
+import { RecentActivity, RecentActivityItem } from './recent_activity';
+import { defaultServerData } from './overview';
+
+jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
+import { sendTelemetry } from '../../../shared/telemetry';
+
+const org = { name: 'foo', defaultOrgName: 'bar' };
+
+const feed = [
+ {
+ id: 'demo',
+ sourceId: 'd2d2d23d',
+ message: 'was successfully connected',
+ target: 'http://localhost:3002/ws/org/sources',
+ timestamp: '2020-06-24 16:34:16',
+ },
+];
+
+describe('RecentActivity', () => {
+ it('renders with no feed data', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiEmptyPrompt)).toHaveLength(1);
+
+ // Branch coverage - renders without error for custom org name
+ shallow( );
+ });
+
+ it('renders an activity feed with links', () => {
+ const wrapper = shallow( );
+ const activity = wrapper.find(RecentActivityItem).dive();
+
+ expect(activity).toHaveLength(1);
+
+ const link = activity.find('[data-test-subj="viewSourceDetailsLink"]');
+ link.simulate('click');
+ expect(sendTelemetry).toHaveBeenCalled();
+ });
+
+ it('renders activity item error state', () => {
+ const props = { ...feed[0], status: 'error' };
+ const wrapper = shallow( );
+
+ expect(wrapper.find('.activity--error')).toHaveLength(1);
+ expect(wrapper.find('.activity--error__label')).toHaveLength(1);
+ expect(wrapper.find(EuiLink).prop('color')).toEqual('danger');
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.tsx
new file mode 100644
index 0000000000000..8d69582c93684
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/recent_activity.tsx
@@ -0,0 +1,131 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+
+import moment from 'moment';
+
+import { EuiEmptyPrompt, EuiLink, EuiPanel, EuiSpacer, EuiLinkProps } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import { ContentSection } from '../shared/content_section';
+import { useRoutes } from '../shared/use_routes';
+import { sendTelemetry } from '../../../shared/telemetry';
+import { KibanaContext, IKibanaContext } from '../../../index';
+import { getSourcePath } from '../../routes';
+
+import { IAppServerData } from './overview';
+
+import './recent_activity.scss';
+
+export interface IFeedActivity {
+ status?: string;
+ id: string;
+ message: string;
+ timestamp: string;
+ sourceId: string;
+}
+
+export const RecentActivity: React.FC = ({
+ organization: { name, defaultOrgName },
+ activityFeed,
+}) => {
+ return (
+
+ }
+ headerSpacer="m"
+ >
+
+ {activityFeed.length > 0 ? (
+ <>
+ {activityFeed.map((props: IFeedActivity, index) => (
+
+ ))}
+ >
+ ) : (
+ <>
+
+
+ {name === defaultOrgName ? (
+
+ ) : (
+
+ )}
+
+ }
+ />
+
+ >
+ )}
+
+
+ );
+};
+
+export const RecentActivityItem: React.FC = ({
+ id,
+ status,
+ message,
+ timestamp,
+ sourceId,
+}) => {
+ const { http } = useContext(KibanaContext) as IKibanaContext;
+ const { getWSRoute } = useRoutes();
+
+ const onClick = () =>
+ sendTelemetry({
+ http,
+ product: 'workplace_search',
+ action: 'clicked',
+ metric: 'recent_activity_source_details_link',
+ });
+
+ const linkProps = {
+ onClick,
+ target: '_blank',
+ href: getWSRoute(getSourcePath(sourceId)),
+ external: true,
+ color: status === 'error' ? 'danger' : 'primary',
+ 'data-test-subj': 'viewSourceDetailsLink',
+ } as EuiLinkProps;
+
+ return (
+
+
+
+ {id} {message}
+ {status === 'error' && (
+
+ {' '}
+
+
+ )}
+
+
+
{moment.utc(timestamp).fromNow()}
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.test.tsx
new file mode 100644
index 0000000000000..edf266231b39e
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.test.tsx
@@ -0,0 +1,32 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { EuiCard } from '@elastic/eui';
+
+import { StatisticCard } from './statistic_card';
+
+const props = {
+ title: 'foo',
+};
+
+describe('StatisticCard', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiCard)).toHaveLength(1);
+ });
+
+ it('renders clickable card', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiCard).prop('href')).toBe('http://localhost:3002/ws/foo');
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.tsx
new file mode 100644
index 0000000000000..9bc8f4f768073
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/overview/statistic_card.tsx
@@ -0,0 +1,46 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import { EuiCard, EuiFlexItem, EuiTitle, EuiTextColor } from '@elastic/eui';
+
+import { useRoutes } from '../shared/use_routes';
+
+interface IStatisticCardProps {
+ title: string;
+ count?: number;
+ actionPath?: string;
+}
+
+export const StatisticCard: React.FC = ({ title, count = 0, actionPath }) => {
+ const { getWSRoute } = useRoutes();
+
+ const linkProps = actionPath
+ ? {
+ href: getWSRoute(actionPath),
+ target: '_blank',
+ rel: 'noopener',
+ }
+ : {};
+ // TODO: When we port this destination to Kibana, we'll want to create a EuiReactRouterCard component (see shared/react_router_helpers/eui_link.tsx)
+
+ return (
+
+
+ {count}
+
+ }
+ />
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/index.ts
new file mode 100644
index 0000000000000..c367424d375f9
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { SetupGuide } from './setup_guide';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.test.tsx
new file mode 100644
index 0000000000000..b87c35d5a5942
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.test.tsx
@@ -0,0 +1,21 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { shallow } from 'enzyme';
+
+import { SetWorkplaceSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
+import { SetupGuide as SetupGuideLayout } from '../../../shared/setup_guide';
+import { SetupGuide } from './';
+
+describe('SetupGuide', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(SetupGuideLayout)).toHaveLength(1);
+ expect(wrapper.find(SetBreadcrumbs)).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.tsx
new file mode 100644
index 0000000000000..5b5d067d23eb8
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/setup_guide/setup_guide.tsx
@@ -0,0 +1,70 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { EuiSpacer, EuiTitle, EuiText, EuiButton } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
+
+import { SetupGuide as SetupGuideLayout } from '../../../shared/setup_guide';
+
+import { SetWorkplaceSearchBreadcrumbs as SetBreadcrumbs } from '../../../shared/kibana_breadcrumbs';
+import { SendWorkplaceSearchTelemetry as SendTelemetry } from '../../../shared/telemetry';
+import GettingStarted from '../../assets/getting_started.png';
+
+const GETTING_STARTED_LINK_URL =
+ 'https://www.elastic.co/guide/en/workplace-search/current/workplace-search-getting-started.html';
+
+export const SetupGuide: React.FC = () => {
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Get started with Workplace Search
+
+
+
+
+
+
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_circle.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_circle.svg
new file mode 100644
index 0000000000000..f8d2ea1e634f6
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_circle.svg
@@ -0,0 +1,3 @@
+
+
+
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.test.tsx
new file mode 100644
index 0000000000000..f406fb136f13f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.test.tsx
@@ -0,0 +1,50 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiTitle, EuiSpacer } from '@elastic/eui';
+
+import { ContentSection } from './';
+
+const props = {
+ children:
,
+ testSubj: 'contentSection',
+ className: 'test',
+};
+
+describe('ContentSection', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.prop('data-test-subj')).toEqual('contentSection');
+ expect(wrapper.prop('className')).toEqual('test');
+ expect(wrapper.find('.children')).toHaveLength(1);
+ });
+
+ it('displays title and description', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiTitle)).toHaveLength(1);
+ expect(wrapper.find('p').text()).toEqual('bar');
+ });
+
+ it('displays header content', () => {
+ const wrapper = shallow(
+ }
+ />
+ );
+
+ expect(wrapper.find(EuiSpacer).prop('size')).toEqual('s');
+ expect(wrapper.find('.header')).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.tsx
new file mode 100644
index 0000000000000..b2a9eebc72e85
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/content_section.tsx
@@ -0,0 +1,45 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+
+import { EuiSpacer, EuiTitle } from '@elastic/eui';
+
+import { TSpacerSize } from '../../../types';
+
+interface IContentSectionProps {
+ children: React.ReactNode;
+ className?: string;
+ title?: React.ReactNode;
+ description?: React.ReactNode;
+ headerChildren?: React.ReactNode;
+ headerSpacer?: TSpacerSize;
+ testSubj?: string;
+}
+
+export const ContentSection: React.FC = ({
+ children,
+ className = '',
+ title,
+ description,
+ headerChildren,
+ headerSpacer,
+ testSubj,
+}) => (
+
+ {title && (
+ <>
+
+ {title}
+
+ {description &&
{description}
}
+ {headerChildren}
+ {headerSpacer &&
}
+ >
+ )}
+ {children}
+
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/index.ts
new file mode 100644
index 0000000000000..7dcb1b13ad1dc
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/content_section/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { ContentSection } from './content_section';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/index.ts
new file mode 100644
index 0000000000000..745639955dcba
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { Loading } from './loading';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.scss b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.scss
new file mode 100644
index 0000000000000..008a8066f807b
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.scss
@@ -0,0 +1,14 @@
+.loadingSpinnerWrapper {
+ width: 100%;
+ height: 90vh;
+ margin: auto;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+}
+
+.loadingSpinner {
+ width: $euiSizeXXL * 1.25;
+ height: $euiSizeXXL * 1.25;
+}
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.test.tsx
new file mode 100644
index 0000000000000..8d168b436cc3b
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.test.tsx
@@ -0,0 +1,21 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiLoadingSpinner } from '@elastic/eui';
+
+import { Loading } from './';
+
+describe('Loading', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiLoadingSpinner)).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.tsx
new file mode 100644
index 0000000000000..399abedf55e87
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/loading/loading.tsx
@@ -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.
+ */
+
+import React from 'react';
+
+import { EuiLoadingSpinner } from '@elastic/eui';
+
+import './loading.scss';
+
+export const Loading: React.FC = () => (
+
+
+
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/index.ts
new file mode 100644
index 0000000000000..c41e27bacb892
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { ProductButton } from './product_button';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.test.tsx
new file mode 100644
index 0000000000000..429a2c509813d
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.test.tsx
@@ -0,0 +1,38 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiButton } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import { ProductButton } from './';
+
+jest.mock('../../../../shared/telemetry', () => ({
+ sendTelemetry: jest.fn(),
+ SendAppSearchTelemetry: jest.fn(),
+}));
+import { sendTelemetry } from '../../../../shared/telemetry';
+
+describe('ProductButton', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(EuiButton)).toHaveLength(1);
+ expect(wrapper.find(FormattedMessage)).toHaveLength(1);
+ });
+
+ it('sends telemetry on create first engine click', () => {
+ const wrapper = shallow( );
+ const button = wrapper.find(EuiButton);
+
+ button.simulate('click');
+ expect(sendTelemetry).toHaveBeenCalled();
+ (sendTelemetry as jest.Mock).mockClear();
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.tsx
new file mode 100644
index 0000000000000..5b86e14132e0f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/product_button/product_button.tsx
@@ -0,0 +1,41 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+
+import { EuiButton, EuiButtonProps, EuiLinkProps } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+
+import { sendTelemetry } from '../../../../shared/telemetry';
+import { KibanaContext, IKibanaContext } from '../../../../index';
+
+export const ProductButton: React.FC = () => {
+ const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext;
+
+ const buttonProps = {
+ fill: true,
+ iconType: 'popout',
+ 'data-test-subj': 'launchButton',
+ } as EuiButtonProps & EuiLinkProps;
+ buttonProps.href = `${enterpriseSearchUrl}/ws`;
+ buttonProps.target = '_blank';
+ buttonProps.onClick = () =>
+ sendTelemetry({
+ http,
+ product: 'workplace_search',
+ action: 'clicked',
+ metric: 'header_launch_button',
+ });
+
+ return (
+
+
+
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/index.ts
new file mode 100644
index 0000000000000..cb9684408c459
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { useRoutes } from './use_routes';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/use_routes.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/use_routes.tsx
new file mode 100644
index 0000000000000..48b8695f82b43
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/use_routes/use_routes.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 { useContext } from 'react';
+
+import { KibanaContext, IKibanaContext } from '../../../../index';
+
+export const useRoutes = () => {
+ const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
+ const getWSRoute = (path: string): string => `${enterpriseSearchUrl}/ws${path}`;
+ return { getWSRoute };
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/index.ts
new file mode 100644
index 0000000000000..774b3d85c8c85
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/index.ts
@@ -0,0 +1,7 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export { ViewContentHeader } from './view_content_header';
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.test.tsx
new file mode 100644
index 0000000000000..4680f15771caa
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.test.tsx
@@ -0,0 +1,39 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../../../../__mocks__/shallow_usecontext.mock';
+
+import React from 'react';
+import { shallow } from 'enzyme';
+import { EuiFlexGroup } from '@elastic/eui';
+
+import { ViewContentHeader } from './';
+
+const props = {
+ title: 'Header',
+ alignItems: 'flexStart' as any,
+};
+
+describe('ViewContentHeader', () => {
+ it('renders with title and alignItems', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find('h2').text()).toEqual('Header');
+ expect(wrapper.find(EuiFlexGroup).prop('alignItems')).toEqual('flexStart');
+ });
+
+ it('shows description, when present', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find('p').text()).toEqual('Hello World');
+ });
+
+ it('shows action, when present', () => {
+ const wrapper = shallow( } />);
+
+ expect(wrapper.find('.action')).toHaveLength(1);
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.tsx
new file mode 100644
index 0000000000000..0408517fd4ec5
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/view_content_header/view_content_header.tsx
@@ -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 React from 'react';
+
+import { EuiFlexGroup, EuiFlexItem, EuiText, EuiTitle, EuiSpacer } from '@elastic/eui';
+
+import { FlexGroupAlignItems } from '@elastic/eui/src/components/flex/flex_group';
+
+interface IViewContentHeaderProps {
+ title: React.ReactNode;
+ description?: React.ReactNode;
+ action?: React.ReactNode;
+ alignItems?: FlexGroupAlignItems;
+}
+
+export const ViewContentHeader: React.FC = ({
+ title,
+ description,
+ action,
+ alignItems = 'center',
+}) => (
+ <>
+
+
+
+ {title}
+
+ {description && (
+
+ {description}
+
+ )}
+
+ {action && {action} }
+
+
+ >
+);
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx
new file mode 100644
index 0000000000000..743080d965c36
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.test.tsx
@@ -0,0 +1,46 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import '../__mocks__/shallow_usecontext.mock';
+
+import React, { useContext } from 'react';
+import { Redirect } from 'react-router-dom';
+import { shallow } from 'enzyme';
+
+import { SetupGuide } from './components/setup_guide';
+import { Overview } from './components/overview';
+
+import { WorkplaceSearch } from './';
+
+describe('Workplace Search Routes', () => {
+ describe('/', () => {
+ it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => {
+ (useContext as jest.Mock).mockImplementationOnce(() => ({ enterpriseSearchUrl: '' }));
+ const wrapper = shallow( );
+
+ expect(wrapper.find(Redirect)).toHaveLength(1);
+ expect(wrapper.find(Overview)).toHaveLength(0);
+ });
+
+ it('renders Engine Overview when enterpriseSearchUrl is set', () => {
+ (useContext as jest.Mock).mockImplementationOnce(() => ({
+ enterpriseSearchUrl: 'https://foo.bar',
+ }));
+ const wrapper = shallow( );
+
+ expect(wrapper.find(Overview)).toHaveLength(1);
+ expect(wrapper.find(Redirect)).toHaveLength(0);
+ });
+ });
+
+ describe('/setup_guide', () => {
+ it('renders', () => {
+ const wrapper = shallow( );
+
+ expect(wrapper.find(SetupGuide)).toHaveLength(1);
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx
new file mode 100644
index 0000000000000..36b1a56ecba26
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/index.tsx
@@ -0,0 +1,29 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useContext } from 'react';
+import { Route, Redirect } from 'react-router-dom';
+
+import { KibanaContext, IKibanaContext } from '../index';
+
+import { SETUP_GUIDE_PATH } from './routes';
+
+import { SetupGuide } from './components/setup_guide';
+import { Overview } from './components/overview';
+
+export const WorkplaceSearch: React.FC = () => {
+ const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext;
+ return (
+ <>
+
+ {!enterpriseSearchUrl ? : }
+
+
+
+
+ >
+ );
+};
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts
new file mode 100644
index 0000000000000..d9798d1f30cfc
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts
@@ -0,0 +1,12 @@
+/*
+ * 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 const ORG_SOURCES_PATH = '/org/sources';
+export const USERS_PATH = '/org/users';
+export const ORG_SETTINGS_PATH = '/org/settings';
+export const SETUP_GUIDE_PATH = '/setup_guide';
+
+export const getSourcePath = (sourceId: string): string => `${ORG_SOURCES_PATH}/${sourceId}`;
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts
new file mode 100644
index 0000000000000..b448c59c52f3e
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts
@@ -0,0 +1,16 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+export interface IAccount {
+ id: string;
+ isCurated?: boolean;
+ isAdmin: boolean;
+ canCreatePersonalSources: boolean;
+ groups: string[];
+ supportEligible: boolean;
+}
+
+export type TSpacerSize = 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
diff --git a/x-pack/plugins/enterprise_search/public/plugin.ts b/x-pack/plugins/enterprise_search/public/plugin.ts
index fbfcc303de47a..fc95828a3f4a4 100644
--- a/x-pack/plugins/enterprise_search/public/plugin.ts
+++ b/x-pack/plugins/enterprise_search/public/plugin.ts
@@ -22,6 +22,7 @@ import { LicensingPluginSetup } from '../../licensing/public';
import { getPublicUrl } from './applications/shared/enterprise_search_url';
import AppSearchLogo from './applications/app_search/assets/logo.svg';
+import WorkplaceSearchLogo from './applications/workplace_search/assets/logo.svg';
export interface ClientConfigType {
host?: string;
@@ -58,7 +59,21 @@ export class EnterpriseSearchPlugin implements Plugin {
return renderApp(AppSearch, coreStart, params, config, plugins);
},
});
- // TODO: Workplace Search will need to register its own plugin.
+
+ core.application.register({
+ id: 'workplaceSearch',
+ title: 'Workplace Search',
+ appRoute: '/app/enterprise_search/workplace_search',
+ category: DEFAULT_APP_CATEGORIES.enterpriseSearch,
+ mount: async (params: AppMountParameters) => {
+ const [coreStart] = await core.getStartServices();
+
+ const { renderApp } = await import('./applications');
+ const { WorkplaceSearch } = await import('./applications/workplace_search');
+
+ return renderApp(WorkplaceSearch, coreStart, params, config, plugins);
+ },
+ });
plugins.home.featureCatalogue.register({
id: 'appSearch',
@@ -70,7 +85,17 @@ export class EnterpriseSearchPlugin implements Plugin {
category: FeatureCatalogueCategory.DATA,
showOnHomePage: true,
});
- // TODO: Workplace Search will need to register its own feature catalogue section/card.
+
+ plugins.home.featureCatalogue.register({
+ id: 'workplaceSearch',
+ title: 'Workplace Search',
+ icon: WorkplaceSearchLogo,
+ description:
+ 'Search all documents, files, and sources available across your virtual workplace.',
+ path: '/app/enterprise_search/workplace_search',
+ category: FeatureCatalogueCategory.DATA,
+ showOnHomePage: true,
+ });
}
public start(core: CoreStart) {}
diff --git a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts
index e95056b871324..53c6dee61cd1d 100644
--- a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts
+++ b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts
@@ -4,20 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { loggingSystemMock } from 'src/core/server/mocks';
+import { mockLogger } from '../../routes/__mocks__';
-jest.mock('../../../../../../src/core/server', () => ({
- SavedObjectsErrorHelpers: {
- isNotFoundError: jest.fn(),
- },
-}));
-import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
-
-import { registerTelemetryUsageCollector, incrementUICounter } from './telemetry';
+import { registerTelemetryUsageCollector } from './telemetry';
describe('App Search Telemetry Usage Collector', () => {
- const mockLogger = loggingSystemMock.create().get();
-
const makeUsageCollectorStub = jest.fn();
const registerStub = jest.fn();
const usageCollectionMock = {
@@ -103,41 +94,5 @@ describe('App Search Telemetry Usage Collector', () => {
},
});
});
-
- it('should not throw but log a warning if saved objects errors', async () => {
- const errorSavedObjectsMock = { createInternalRepository: () => ({}) } as any;
- registerTelemetryUsageCollector(usageCollectionMock, errorSavedObjectsMock, mockLogger);
-
- // Without log warning (not found)
- (SavedObjectsErrorHelpers.isNotFoundError as jest.Mock).mockImplementationOnce(() => true);
- await makeUsageCollectorStub.mock.calls[0][0].fetch();
-
- expect(mockLogger.warn).not.toHaveBeenCalled();
-
- // With log warning
- (SavedObjectsErrorHelpers.isNotFoundError as jest.Mock).mockImplementationOnce(() => false);
- await makeUsageCollectorStub.mock.calls[0][0].fetch();
-
- expect(mockLogger.warn).toHaveBeenCalledWith(
- 'Failed to retrieve App Search telemetry data: TypeError: savedObjectsRepository.get is not a function'
- );
- });
- });
-
- describe('incrementUICounter', () => {
- it('should increment the saved objects internal repository', async () => {
- const response = await incrementUICounter({
- savedObjects: savedObjectsMock,
- uiAction: 'ui_clicked',
- metric: 'button',
- });
-
- expect(savedObjectsRepoStub.incrementCounter).toHaveBeenCalledWith(
- 'app_search_telemetry',
- 'app_search_telemetry',
- 'ui_clicked.button'
- );
- expect(response).toEqual({ success: true });
- });
});
});
diff --git a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts
index a10f96907ad28..f700088cb67a0 100644
--- a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts
+++ b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts
@@ -5,16 +5,10 @@
*/
import { get } from 'lodash';
-import {
- ISavedObjectsRepository,
- SavedObjectsServiceStart,
- SavedObjectAttributes,
- Logger,
-} from 'src/core/server';
+import { SavedObjectsServiceStart, Logger } from 'src/core/server';
import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
-// This throws `Error: Cannot find module 'src/core/server'` if I import it via alias ¯\_(ツ)_/¯
-import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
+import { getSavedObjectAttributesFromRepo } from '../lib/telemetry';
interface ITelemetry {
ui_viewed: {
@@ -70,10 +64,11 @@ export const registerTelemetryUsageCollector = (
const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart, log: Logger) => {
const savedObjectsRepository = savedObjects.createInternalRepository();
- const savedObjectAttributes = (await getSavedObjectAttributesFromRepo(
+ const savedObjectAttributes = await getSavedObjectAttributesFromRepo(
+ AS_TELEMETRY_NAME,
savedObjectsRepository,
log
- )) as SavedObjectAttributes;
+ );
const defaultTelemetrySavedObject: ITelemetry = {
ui_viewed: {
@@ -114,43 +109,3 @@ const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart, log
},
} as ITelemetry;
};
-
-/**
- * Helper function - fetches saved objects attributes
- */
-
-const getSavedObjectAttributesFromRepo = async (
- savedObjectsRepository: ISavedObjectsRepository,
- log: Logger
-) => {
- try {
- return (await savedObjectsRepository.get(AS_TELEMETRY_NAME, AS_TELEMETRY_NAME)).attributes;
- } catch (e) {
- if (!SavedObjectsErrorHelpers.isNotFoundError(e)) {
- log.warn(`Failed to retrieve App Search telemetry data: ${e}`);
- }
- return null;
- }
-};
-
-/**
- * Set saved objection attributes - used by telemetry route
- */
-
-interface IIncrementUICounter {
- savedObjects: SavedObjectsServiceStart;
- uiAction: string;
- metric: string;
-}
-
-export async function incrementUICounter({ savedObjects, uiAction, metric }: IIncrementUICounter) {
- const internalRepository = savedObjects.createInternalRepository();
-
- await internalRepository.incrementCounter(
- AS_TELEMETRY_NAME,
- AS_TELEMETRY_NAME,
- `${uiAction}.${metric}` // e.g., ui_viewed.setup_guide
- );
-
- return { success: true };
-}
diff --git a/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.test.ts
new file mode 100644
index 0000000000000..3ab3b03dd7725
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.test.ts
@@ -0,0 +1,69 @@
+/*
+ * 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 { mockLogger } from '../../routes/__mocks__';
+
+jest.mock('../../../../../../src/core/server', () => ({
+ SavedObjectsErrorHelpers: {
+ isNotFoundError: jest.fn(),
+ },
+}));
+import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
+
+import { getSavedObjectAttributesFromRepo, incrementUICounter } from './telemetry';
+
+describe('App Search Telemetry Usage Collector', () => {
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe('getSavedObjectAttributesFromRepo', () => {
+ // Note: savedObjectsRepository.get() is best tested as a whole from
+ // individual fetchTelemetryMetrics tests. This mostly just tests error handling
+ it('should not throw but log a warning if saved objects errors', async () => {
+ const errorSavedObjectsMock = {} as any;
+
+ // Without log warning (not found)
+ (SavedObjectsErrorHelpers.isNotFoundError as jest.Mock).mockImplementationOnce(() => true);
+ await getSavedObjectAttributesFromRepo('some_id', errorSavedObjectsMock, mockLogger);
+
+ expect(mockLogger.warn).not.toHaveBeenCalled();
+
+ // With log warning
+ (SavedObjectsErrorHelpers.isNotFoundError as jest.Mock).mockImplementationOnce(() => false);
+ await getSavedObjectAttributesFromRepo('some_id', errorSavedObjectsMock, mockLogger);
+
+ expect(mockLogger.warn).toHaveBeenCalledWith(
+ 'Failed to retrieve some_id telemetry data: TypeError: savedObjectsRepository.get is not a function'
+ );
+ });
+ });
+
+ describe('incrementUICounter', () => {
+ const incrementCounterMock = jest.fn();
+ const savedObjectsMock = {
+ createInternalRepository: jest.fn(() => ({
+ incrementCounter: incrementCounterMock,
+ })),
+ } as any;
+
+ it('should increment the saved objects internal repository', async () => {
+ const response = await incrementUICounter({
+ id: 'app_search_telemetry',
+ savedObjects: savedObjectsMock,
+ uiAction: 'ui_clicked',
+ metric: 'button',
+ });
+
+ expect(incrementCounterMock).toHaveBeenCalledWith(
+ 'app_search_telemetry',
+ 'app_search_telemetry',
+ 'ui_clicked.button'
+ );
+ expect(response).toEqual({ success: true });
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.ts b/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.ts
new file mode 100644
index 0000000000000..f5f4fa368555f
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/collectors/lib/telemetry.ts
@@ -0,0 +1,62 @@
+/*
+ * 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 {
+ ISavedObjectsRepository,
+ SavedObjectsServiceStart,
+ SavedObjectAttributes,
+ Logger,
+} from 'src/core/server';
+
+// This throws `Error: Cannot find module 'src/core/server'` if I import it via alias ¯\_(ツ)_/¯
+import { SavedObjectsErrorHelpers } from '../../../../../../src/core/server';
+
+/**
+ * Fetches saved objects attributes - used by collectors
+ */
+
+export const getSavedObjectAttributesFromRepo = async (
+ id: string, // Telemetry name
+ savedObjectsRepository: ISavedObjectsRepository,
+ log: Logger
+): Promise => {
+ try {
+ return (await savedObjectsRepository.get(id, id)).attributes as SavedObjectAttributes;
+ } catch (e) {
+ if (!SavedObjectsErrorHelpers.isNotFoundError(e)) {
+ log.warn(`Failed to retrieve ${id} telemetry data: ${e}`);
+ }
+ return null;
+ }
+};
+
+/**
+ * Set saved objection attributes - used by telemetry route
+ */
+
+interface IIncrementUICounter {
+ id: string; // Telemetry name
+ savedObjects: SavedObjectsServiceStart;
+ uiAction: string;
+ metric: string;
+}
+
+export async function incrementUICounter({
+ id,
+ savedObjects,
+ uiAction,
+ metric,
+}: IIncrementUICounter) {
+ const internalRepository = savedObjects.createInternalRepository();
+
+ await internalRepository.incrementCounter(
+ id,
+ id,
+ `${uiAction}.${metric}` // e.g., ui_viewed.setup_guide
+ );
+
+ return { success: true };
+}
diff --git a/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.test.ts
new file mode 100644
index 0000000000000..496b2f254f9a6
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.test.ts
@@ -0,0 +1,101 @@
+/*
+ * 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 { mockLogger } from '../../routes/__mocks__';
+
+import { registerTelemetryUsageCollector } from './telemetry';
+
+describe('Workplace Search Telemetry Usage Collector', () => {
+ const makeUsageCollectorStub = jest.fn();
+ const registerStub = jest.fn();
+ const usageCollectionMock = {
+ makeUsageCollector: makeUsageCollectorStub,
+ registerCollector: registerStub,
+ } as any;
+
+ const savedObjectsRepoStub = {
+ get: () => ({
+ attributes: {
+ 'ui_viewed.setup_guide': 10,
+ 'ui_viewed.overview': 20,
+ 'ui_error.cannot_connect': 3,
+ 'ui_clicked.header_launch_button': 30,
+ 'ui_clicked.org_name_change_button': 40,
+ 'ui_clicked.onboarding_card_button': 50,
+ 'ui_clicked.recent_activity_source_details_link': 60,
+ },
+ }),
+ incrementCounter: jest.fn(),
+ };
+ const savedObjectsMock = {
+ createInternalRepository: jest.fn(() => savedObjectsRepoStub),
+ } as any;
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ });
+
+ describe('registerTelemetryUsageCollector', () => {
+ it('should make and register the usage collector', () => {
+ registerTelemetryUsageCollector(usageCollectionMock, savedObjectsMock, mockLogger);
+
+ expect(registerStub).toHaveBeenCalledTimes(1);
+ expect(makeUsageCollectorStub).toHaveBeenCalledTimes(1);
+ expect(makeUsageCollectorStub.mock.calls[0][0].type).toBe('workplace_search');
+ expect(makeUsageCollectorStub.mock.calls[0][0].isReady()).toBe(true);
+ });
+ });
+
+ describe('fetchTelemetryMetrics', () => {
+ it('should return existing saved objects data', async () => {
+ registerTelemetryUsageCollector(usageCollectionMock, savedObjectsMock, mockLogger);
+ const savedObjectsCounts = await makeUsageCollectorStub.mock.calls[0][0].fetch();
+
+ expect(savedObjectsCounts).toEqual({
+ ui_viewed: {
+ setup_guide: 10,
+ overview: 20,
+ },
+ ui_error: {
+ cannot_connect: 3,
+ },
+ ui_clicked: {
+ header_launch_button: 30,
+ org_name_change_button: 40,
+ onboarding_card_button: 50,
+ recent_activity_source_details_link: 60,
+ },
+ });
+ });
+
+ it('should return a default telemetry object if no saved data exists', async () => {
+ const emptySavedObjectsMock = {
+ createInternalRepository: () => ({
+ get: () => ({ attributes: null }),
+ }),
+ } as any;
+
+ registerTelemetryUsageCollector(usageCollectionMock, emptySavedObjectsMock, mockLogger);
+ const savedObjectsCounts = await makeUsageCollectorStub.mock.calls[0][0].fetch();
+
+ expect(savedObjectsCounts).toEqual({
+ ui_viewed: {
+ setup_guide: 0,
+ overview: 0,
+ },
+ ui_error: {
+ cannot_connect: 0,
+ },
+ ui_clicked: {
+ header_launch_button: 0,
+ org_name_change_button: 0,
+ onboarding_card_button: 0,
+ recent_activity_source_details_link: 0,
+ },
+ });
+ });
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.ts
new file mode 100644
index 0000000000000..892de5cfee35e
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/collectors/workplace_search/telemetry.ts
@@ -0,0 +1,115 @@
+/*
+ * 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 { get } from 'lodash';
+import { SavedObjectsServiceStart, Logger } from 'src/core/server';
+import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
+
+import { getSavedObjectAttributesFromRepo } from '../lib/telemetry';
+
+interface ITelemetry {
+ ui_viewed: {
+ setup_guide: number;
+ overview: number;
+ };
+ ui_error: {
+ cannot_connect: number;
+ };
+ ui_clicked: {
+ header_launch_button: number;
+ org_name_change_button: number;
+ onboarding_card_button: number;
+ recent_activity_source_details_link: number;
+ };
+}
+
+export const WS_TELEMETRY_NAME = 'workplace_search_telemetry';
+
+/**
+ * Register the telemetry collector
+ */
+
+export const registerTelemetryUsageCollector = (
+ usageCollection: UsageCollectionSetup,
+ savedObjects: SavedObjectsServiceStart,
+ log: Logger
+) => {
+ const telemetryUsageCollector = usageCollection.makeUsageCollector({
+ type: 'workplace_search',
+ fetch: async () => fetchTelemetryMetrics(savedObjects, log),
+ isReady: () => true,
+ schema: {
+ ui_viewed: {
+ setup_guide: { type: 'long' },
+ overview: { type: 'long' },
+ },
+ ui_error: {
+ cannot_connect: { type: 'long' },
+ },
+ ui_clicked: {
+ header_launch_button: { type: 'long' },
+ org_name_change_button: { type: 'long' },
+ onboarding_card_button: { type: 'long' },
+ recent_activity_source_details_link: { type: 'long' },
+ },
+ },
+ });
+ usageCollection.registerCollector(telemetryUsageCollector);
+};
+
+/**
+ * Fetch the aggregated telemetry metrics from our saved objects
+ */
+
+const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart, log: Logger) => {
+ const savedObjectsRepository = savedObjects.createInternalRepository();
+ const savedObjectAttributes = await getSavedObjectAttributesFromRepo(
+ WS_TELEMETRY_NAME,
+ savedObjectsRepository,
+ log
+ );
+
+ const defaultTelemetrySavedObject: ITelemetry = {
+ ui_viewed: {
+ setup_guide: 0,
+ overview: 0,
+ },
+ ui_error: {
+ cannot_connect: 0,
+ },
+ ui_clicked: {
+ header_launch_button: 0,
+ org_name_change_button: 0,
+ onboarding_card_button: 0,
+ recent_activity_source_details_link: 0,
+ },
+ };
+
+ // If we don't have an existing/saved telemetry object, return the default
+ if (!savedObjectAttributes) {
+ return defaultTelemetrySavedObject;
+ }
+
+ return {
+ ui_viewed: {
+ setup_guide: get(savedObjectAttributes, 'ui_viewed.setup_guide', 0),
+ overview: get(savedObjectAttributes, 'ui_viewed.overview', 0),
+ },
+ ui_error: {
+ cannot_connect: get(savedObjectAttributes, 'ui_error.cannot_connect', 0),
+ },
+ ui_clicked: {
+ header_launch_button: get(savedObjectAttributes, 'ui_clicked.header_launch_button', 0),
+ org_name_change_button: get(savedObjectAttributes, 'ui_clicked.org_name_change_button', 0),
+ onboarding_card_button: get(savedObjectAttributes, 'ui_clicked.onboarding_card_button', 0),
+ recent_activity_source_details_link: get(
+ savedObjectAttributes,
+ 'ui_clicked.recent_activity_source_details_link',
+ 0
+ ),
+ },
+ } as ITelemetry;
+};
diff --git a/x-pack/plugins/enterprise_search/server/plugin.ts b/x-pack/plugins/enterprise_search/server/plugin.ts
index 70be8600862e9..a7bd68f92f78b 100644
--- a/x-pack/plugins/enterprise_search/server/plugin.ts
+++ b/x-pack/plugins/enterprise_search/server/plugin.ts
@@ -22,10 +22,15 @@ import { PluginSetupContract as FeaturesPluginSetup } from '../../features/serve
import { ConfigType } from './';
import { checkAccess } from './lib/check_access';
import { registerPublicUrlRoute } from './routes/enterprise_search/public_url';
-import { registerEnginesRoute } from './routes/app_search/engines';
-import { registerTelemetryRoute } from './routes/app_search/telemetry';
-import { registerTelemetryUsageCollector } from './collectors/app_search/telemetry';
+import { registerTelemetryRoute } from './routes/enterprise_search/telemetry';
+
import { appSearchTelemetryType } from './saved_objects/app_search/telemetry';
+import { registerTelemetryUsageCollector as registerASTelemetryUsageCollector } from './collectors/app_search/telemetry';
+import { registerEnginesRoute } from './routes/app_search/engines';
+
+import { workplaceSearchTelemetryType } from './saved_objects/workplace_search/telemetry';
+import { registerTelemetryUsageCollector as registerWSTelemetryUsageCollector } from './collectors/workplace_search/telemetry';
+import { registerWSOverviewRoute } from './routes/workplace_search/overview';
export interface PluginsSetup {
usageCollection?: UsageCollectionSetup;
@@ -64,8 +69,8 @@ export class EnterpriseSearchPlugin implements Plugin {
order: 0,
icon: 'logoEnterpriseSearch',
navLinkId: 'appSearch', // TODO - remove this once functional tests no longer rely on navLinkId
- app: ['kibana', 'appSearch'], // TODO: 'enterpriseSearch', 'workplaceSearch'
- catalogue: ['appSearch'], // TODO: 'enterpriseSearch', 'workplaceSearch'
+ app: ['kibana', 'appSearch', 'workplaceSearch'], // TODO: 'enterpriseSearch'
+ catalogue: ['appSearch', 'workplaceSearch'], // TODO: 'enterpriseSearch'
privileges: null,
});
@@ -75,15 +80,16 @@ export class EnterpriseSearchPlugin implements Plugin {
capabilities.registerSwitcher(async (request: KibanaRequest) => {
const dependencies = { config, security, request, log: this.logger };
- const { hasAppSearchAccess } = await checkAccess(dependencies);
- // TODO: hasWorkplaceSearchAccess
+ const { hasAppSearchAccess, hasWorkplaceSearchAccess } = await checkAccess(dependencies);
return {
navLinks: {
appSearch: hasAppSearchAccess,
+ workplaceSearch: hasWorkplaceSearchAccess,
},
catalogue: {
appSearch: hasAppSearchAccess,
+ workplaceSearch: hasWorkplaceSearchAccess,
},
};
});
@@ -96,23 +102,24 @@ export class EnterpriseSearchPlugin implements Plugin {
registerPublicUrlRoute(dependencies);
registerEnginesRoute(dependencies);
+ registerWSOverviewRoute(dependencies);
/**
* Bootstrap the routes, saved objects, and collector for telemetry
*/
savedObjects.registerType(appSearchTelemetryType);
+ savedObjects.registerType(workplaceSearchTelemetryType);
let savedObjectsStarted: SavedObjectsServiceStart;
getStartServices().then(([coreStart]) => {
savedObjectsStarted = coreStart.savedObjects;
+
if (usageCollection) {
- registerTelemetryUsageCollector(usageCollection, savedObjectsStarted, this.logger);
+ registerASTelemetryUsageCollector(usageCollection, savedObjectsStarted, this.logger);
+ registerWSTelemetryUsageCollector(usageCollection, savedObjectsStarted, this.logger);
}
});
- registerTelemetryRoute({
- ...dependencies,
- getSavedObjectsService: () => savedObjectsStarted,
- });
+ registerTelemetryRoute({ ...dependencies, getSavedObjectsService: () => savedObjectsStarted });
}
public start() {}
diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.test.ts
similarity index 56%
rename from x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts
rename to x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.test.ts
index e2d5fbcec3705..ebd84d3e0e79a 100644
--- a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts
+++ b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.test.ts
@@ -7,20 +7,21 @@
import { loggingSystemMock, savedObjectsServiceMock } from 'src/core/server/mocks';
import { MockRouter, mockConfig, mockLogger } from '../__mocks__';
-import { registerTelemetryRoute } from './telemetry';
-
-jest.mock('../../collectors/app_search/telemetry', () => ({
+jest.mock('../../collectors/lib/telemetry', () => ({
incrementUICounter: jest.fn(),
}));
-import { incrementUICounter } from '../../collectors/app_search/telemetry';
+import { incrementUICounter } from '../../collectors/lib/telemetry';
+
+import { registerTelemetryRoute } from './telemetry';
/**
* Since these route callbacks are so thin, these serve simply as integration tests
* to ensure they're wired up to the collector functions correctly. Business logic
* is tested more thoroughly in the collectors/telemetry tests.
*/
-describe('App Search Telemetry API', () => {
+describe('Enterprise Search Telemetry API', () => {
let mockRouter: MockRouter;
+ const successResponse = { success: true };
beforeEach(() => {
jest.clearAllMocks();
@@ -34,14 +35,20 @@ describe('App Search Telemetry API', () => {
});
});
- describe('PUT /api/app_search/telemetry', () => {
- it('increments the saved objects counter', async () => {
- const successResponse = { success: true };
+ describe('PUT /api/enterprise_search/telemetry', () => {
+ it('increments the saved objects counter for App Search', async () => {
(incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => successResponse));
- await mockRouter.callRoute({ body: { action: 'viewed', metric: 'setup_guide' } });
+ await mockRouter.callRoute({
+ body: {
+ product: 'app_search',
+ action: 'viewed',
+ metric: 'setup_guide',
+ },
+ });
expect(incrementUICounter).toHaveBeenCalledWith({
+ id: 'app_search_telemetry',
savedObjects: expect.any(Object),
uiAction: 'ui_viewed',
metric: 'setup_guide',
@@ -49,10 +56,36 @@ describe('App Search Telemetry API', () => {
expect(mockRouter.response.ok).toHaveBeenCalledWith({ body: successResponse });
});
+ it('increments the saved objects counter for Workplace Search', async () => {
+ (incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => successResponse));
+
+ await mockRouter.callRoute({
+ body: {
+ product: 'workplace_search',
+ action: 'clicked',
+ metric: 'onboarding_card_button',
+ },
+ });
+
+ expect(incrementUICounter).toHaveBeenCalledWith({
+ id: 'workplace_search_telemetry',
+ savedObjects: expect.any(Object),
+ uiAction: 'ui_clicked',
+ metric: 'onboarding_card_button',
+ });
+ expect(mockRouter.response.ok).toHaveBeenCalledWith({ body: successResponse });
+ });
+
it('throws an error when incrementing fails', async () => {
(incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => Promise.reject('Failed')));
- await mockRouter.callRoute({ body: { action: 'error', metric: 'error' } });
+ await mockRouter.callRoute({
+ body: {
+ product: 'enterprise_search',
+ action: 'error',
+ metric: 'error',
+ },
+ });
expect(incrementUICounter).toHaveBeenCalled();
expect(mockLogger.error).toHaveBeenCalled();
@@ -73,34 +106,50 @@ describe('App Search Telemetry API', () => {
expect(mockRouter.response.internalError).toHaveBeenCalled();
expect(loggingSystemMock.collect(mockLogger).error[0][0]).toEqual(
expect.stringContaining(
- 'App Search UI telemetry error: Error: Could not find Saved Objects service'
+ 'Enterprise Search UI telemetry error: Error: Could not find Saved Objects service'
)
);
});
describe('validates', () => {
it('correctly', () => {
- const request = { body: { action: 'viewed', metric: 'setup_guide' } };
+ const request = {
+ body: { product: 'workplace_search', action: 'viewed', metric: 'setup_guide' },
+ };
mockRouter.shouldValidate(request);
});
+ it('wrong product string', () => {
+ const request = {
+ body: { product: 'workspace_space_search', action: 'viewed', metric: 'setup_guide' },
+ };
+ mockRouter.shouldThrow(request);
+ });
+
it('wrong action string', () => {
- const request = { body: { action: 'invalid', metric: 'setup_guide' } };
+ const request = {
+ body: { product: 'app_search', action: 'invalid', metric: 'setup_guide' },
+ };
mockRouter.shouldThrow(request);
});
it('wrong metric type', () => {
- const request = { body: { action: 'clicked', metric: true } };
+ const request = { body: { product: 'enterprise_search', action: 'clicked', metric: true } };
+ mockRouter.shouldThrow(request);
+ });
+
+ it('product is missing string', () => {
+ const request = { body: { action: 'viewed', metric: 'setup_guide' } };
mockRouter.shouldThrow(request);
});
it('action is missing', () => {
- const request = { body: { metric: 'engines_overview' } };
+ const request = { body: { product: 'app_search', metric: 'engines_overview' } };
mockRouter.shouldThrow(request);
});
it('metric is missing', () => {
- const request = { body: { action: 'error' } };
+ const request = { body: { product: 'app_search', action: 'error' } };
mockRouter.shouldThrow(request);
});
});
diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.ts
similarity index 55%
rename from x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts
rename to x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.ts
index 4cc9b64adc092..7ed1d7b17753c 100644
--- a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts
+++ b/x-pack/plugins/enterprise_search/server/routes/enterprise_search/telemetry.ts
@@ -7,7 +7,15 @@
import { schema } from '@kbn/config-schema';
import { IRouteDependencies } from '../../plugin';
-import { incrementUICounter } from '../../collectors/app_search/telemetry';
+import { incrementUICounter } from '../../collectors/lib/telemetry';
+
+import { AS_TELEMETRY_NAME } from '../../collectors/app_search/telemetry';
+import { WS_TELEMETRY_NAME } from '../../collectors/workplace_search/telemetry';
+const productToTelemetryMap = {
+ app_search: AS_TELEMETRY_NAME,
+ workplace_search: WS_TELEMETRY_NAME,
+ enterprise_search: 'TODO',
+};
export function registerTelemetryRoute({
router,
@@ -16,9 +24,14 @@ export function registerTelemetryRoute({
}: IRouteDependencies) {
router.put(
{
- path: '/api/app_search/telemetry',
+ path: '/api/enterprise_search/telemetry',
validate: {
body: schema.object({
+ product: schema.oneOf([
+ schema.literal('app_search'),
+ schema.literal('workplace_search'),
+ schema.literal('enterprise_search'),
+ ]),
action: schema.oneOf([
schema.literal('viewed'),
schema.literal('clicked'),
@@ -29,21 +42,24 @@ export function registerTelemetryRoute({
},
},
async (ctx, request, response) => {
- const { action, metric } = request.body;
+ const { product, action, metric } = request.body;
try {
if (!getSavedObjectsService) throw new Error('Could not find Saved Objects service');
return response.ok({
body: await incrementUICounter({
+ id: productToTelemetryMap[product],
savedObjects: getSavedObjectsService(),
uiAction: `ui_${action}`,
metric,
}),
});
} catch (e) {
- log.error(`App Search UI telemetry error: ${e instanceof Error ? e.stack : e.toString()}`);
- return response.internalError({ body: 'App Search UI telemetry failed' });
+ log.error(
+ `Enterprise Search UI telemetry error: ${e instanceof Error ? e.stack : e.toString()}`
+ );
+ return response.internalError({ body: 'Enterprise Search UI telemetry failed' });
}
}
);
diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts
new file mode 100644
index 0000000000000..b1b5539795357
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.test.ts
@@ -0,0 +1,127 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { MockRouter, mockConfig, mockLogger } from '../__mocks__';
+
+import { registerWSOverviewRoute } from './overview';
+
+jest.mock('node-fetch');
+const fetch = jest.requireActual('node-fetch');
+const { Response } = fetch;
+const fetchMock = require('node-fetch') as jest.Mocked;
+
+const ORG_ROUTE = 'http://localhost:3002/ws/org';
+
+describe('engine routes', () => {
+ describe('GET /api/workplace_search/overview', () => {
+ const AUTH_HEADER = 'Basic 123';
+ const mockRequest = {
+ headers: {
+ authorization: AUTH_HEADER,
+ },
+ query: {},
+ };
+
+ const mockRouter = new MockRouter({ method: 'get', payload: 'query' });
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ mockRouter.createRouter();
+
+ registerWSOverviewRoute({
+ router: mockRouter.router,
+ log: mockLogger,
+ config: mockConfig,
+ });
+ });
+
+ describe('when the underlying Workplace Search API returns a 200', () => {
+ beforeEach(() => {
+ WorkplaceSearchAPI.shouldBeCalledWith(ORG_ROUTE, {
+ headers: { Authorization: AUTH_HEADER },
+ }).andReturn({ accountsCount: 1 });
+ });
+
+ it('should return 200 with a list of overview from the Workplace Search API', async () => {
+ await mockRouter.callRoute(mockRequest);
+
+ expect(mockRouter.response.ok).toHaveBeenCalledWith({
+ body: { accountsCount: 1 },
+ headers: { 'content-type': 'application/json' },
+ });
+ });
+ });
+
+ describe('when the Workplace Search URL is invalid', () => {
+ beforeEach(() => {
+ WorkplaceSearchAPI.shouldBeCalledWith(ORG_ROUTE, {
+ headers: { Authorization: AUTH_HEADER },
+ }).andReturnError();
+ });
+
+ it('should return 404 with a message', async () => {
+ await mockRouter.callRoute(mockRequest);
+
+ expect(mockRouter.response.notFound).toHaveBeenCalledWith({
+ body: 'cannot-connect',
+ });
+ expect(mockLogger.error).toHaveBeenCalledWith('Cannot connect to Workplace Search: Failed');
+ expect(mockLogger.debug).not.toHaveBeenCalled();
+ });
+ });
+
+ describe('when the Workplace Search API returns invalid data', () => {
+ beforeEach(() => {
+ WorkplaceSearchAPI.shouldBeCalledWith(ORG_ROUTE, {
+ headers: { Authorization: AUTH_HEADER },
+ }).andReturnInvalidData();
+ });
+
+ it('should return 404 with a message', async () => {
+ await mockRouter.callRoute(mockRequest);
+
+ expect(mockRouter.response.notFound).toHaveBeenCalledWith({
+ body: 'cannot-connect',
+ });
+ expect(mockLogger.error).toHaveBeenCalledWith(
+ 'Cannot connect to Workplace Search: Error: Invalid data received from Workplace Search: {"foo":"bar"}'
+ );
+ expect(mockLogger.debug).toHaveBeenCalled();
+ });
+ });
+
+ const WorkplaceSearchAPI = {
+ shouldBeCalledWith(expectedUrl: string, expectedParams: object) {
+ return {
+ andReturn(response: object) {
+ fetchMock.mockImplementation((url: string, params: object) => {
+ expect(url).toEqual(expectedUrl);
+ expect(params).toEqual(expectedParams);
+
+ return Promise.resolve(new Response(JSON.stringify(response)));
+ });
+ },
+ andReturnInvalidData() {
+ fetchMock.mockImplementation((url: string, params: object) => {
+ expect(url).toEqual(expectedUrl);
+ expect(params).toEqual(expectedParams);
+
+ return Promise.resolve(new Response(JSON.stringify({ foo: 'bar' })));
+ });
+ },
+ andReturnError() {
+ fetchMock.mockImplementation((url: string, params: object) => {
+ expect(url).toEqual(expectedUrl);
+ expect(params).toEqual(expectedParams);
+
+ return Promise.reject('Failed');
+ });
+ },
+ };
+ },
+ };
+ });
+});
diff --git a/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts
new file mode 100644
index 0000000000000..d1e2f4f5f180d
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/routes/workplace_search/overview.ts
@@ -0,0 +1,46 @@
+/*
+ * 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 fetch from 'node-fetch';
+
+import { IRouteDependencies } from '../../plugin';
+
+export function registerWSOverviewRoute({ router, config, log }: IRouteDependencies) {
+ router.get(
+ {
+ path: '/api/workplace_search/overview',
+ validate: false,
+ },
+ async (context, request, response) => {
+ try {
+ const entSearchUrl = config.host as string;
+ const url = `${encodeURI(entSearchUrl)}/ws/org`;
+
+ const overviewResponse = await fetch(url, {
+ headers: { Authorization: request.headers.authorization as string },
+ });
+
+ const body = await overviewResponse.json();
+ const hasValidData = typeof body?.accountsCount === 'number';
+
+ if (hasValidData) {
+ return response.ok({
+ body,
+ headers: { 'content-type': 'application/json' },
+ });
+ } else {
+ // Either a completely incorrect Enterprise Search host URL was configured, or Workplace Search is returning bad data
+ throw new Error(`Invalid data received from Workplace Search: ${JSON.stringify(body)}`);
+ }
+ } catch (e) {
+ log.error(`Cannot connect to Workplace Search: ${e.toString()}`);
+ if (e instanceof Error) log.debug(e.stack as string);
+
+ return response.notFound({ body: 'cannot-connect' });
+ }
+ }
+ );
+}
diff --git a/x-pack/plugins/enterprise_search/server/saved_objects/workplace_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/saved_objects/workplace_search/telemetry.ts
new file mode 100644
index 0000000000000..86315a9d617e4
--- /dev/null
+++ b/x-pack/plugins/enterprise_search/server/saved_objects/workplace_search/telemetry.ts
@@ -0,0 +1,19 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+/* istanbul ignore file */
+
+import { SavedObjectsType } from 'src/core/server';
+import { WS_TELEMETRY_NAME } from '../../collectors/workplace_search/telemetry';
+
+export const workplaceSearchTelemetryType: SavedObjectsType = {
+ name: WS_TELEMETRY_NAME,
+ hidden: false,
+ namespaceType: 'agnostic',
+ mappings: {
+ dynamic: false,
+ properties: {},
+ },
+};
diff --git a/x-pack/plugins/index_management/common/lib/component_template_serialization.test.ts b/x-pack/plugins/index_management/common/lib/component_template_serialization.test.ts
index 83682f45918e3..16c45991d1f32 100644
--- a/x-pack/plugins/index_management/common/lib/component_template_serialization.test.ts
+++ b/x-pack/plugins/index_management/common/lib/component_template_serialization.test.ts
@@ -92,6 +92,7 @@ describe('Component template serialization', () => {
},
_kbnMeta: {
usedBy: ['my_index_template'],
+ isManaged: false,
},
});
});
@@ -105,6 +106,7 @@ describe('Component template serialization', () => {
version: 1,
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
_meta: {
serialization: {
diff --git a/x-pack/plugins/index_management/common/lib/component_template_serialization.ts b/x-pack/plugins/index_management/common/lib/component_template_serialization.ts
index 672b8140f79fb..3a1c2c1ca55b2 100644
--- a/x-pack/plugins/index_management/common/lib/component_template_serialization.ts
+++ b/x-pack/plugins/index_management/common/lib/component_template_serialization.ts
@@ -60,24 +60,26 @@ export function deserializeComponentTemplate(
_meta,
_kbnMeta: {
usedBy: indexTemplatesToUsedBy[name] || [],
+ isManaged: Boolean(_meta?.managed === true),
},
};
return deserializedComponentTemplate;
}
-export function deserializeComponenTemplateList(
+export function deserializeComponentTemplateList(
componentTemplateEs: ComponentTemplateFromEs,
indexTemplatesEs: TemplateFromEs[]
) {
const { name, component_template: componentTemplate } = componentTemplateEs;
- const { template } = componentTemplate;
+ const { template, _meta } = componentTemplate;
const indexTemplatesToUsedBy = getIndexTemplatesToUsedBy(indexTemplatesEs);
const componentTemplateListItem: ComponentTemplateListItem = {
name,
usedBy: indexTemplatesToUsedBy[name] || [],
+ isManaged: Boolean(_meta?.managed === true),
hasSettings: hasEntries(template.settings),
hasMappings: hasEntries(template.mappings),
hasAliases: hasEntries(template.aliases),
diff --git a/x-pack/plugins/index_management/common/lib/index.ts b/x-pack/plugins/index_management/common/lib/index.ts
index f39cc063ba731..9e87e87b0eee0 100644
--- a/x-pack/plugins/index_management/common/lib/index.ts
+++ b/x-pack/plugins/index_management/common/lib/index.ts
@@ -19,6 +19,6 @@ export { getTemplateParameter } from './utils';
export {
deserializeComponentTemplate,
- deserializeComponenTemplateList,
+ deserializeComponentTemplateList,
serializeComponentTemplate,
} from './component_template_serialization';
diff --git a/x-pack/plugins/index_management/common/types/component_templates.ts b/x-pack/plugins/index_management/common/types/component_templates.ts
index bc7ebdc2753dd..c8dec40d061bd 100644
--- a/x-pack/plugins/index_management/common/types/component_templates.ts
+++ b/x-pack/plugins/index_management/common/types/component_templates.ts
@@ -22,6 +22,7 @@ export interface ComponentTemplateDeserialized extends ComponentTemplateSerializ
name: string;
_kbnMeta: {
usedBy: string[];
+ isManaged: boolean;
};
}
@@ -36,4 +37,5 @@ export interface ComponentTemplateListItem {
hasMappings: boolean;
hasAliases: boolean;
hasSettings: boolean;
+ isManaged: boolean;
}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx
index 75eb419d56a5c..4462a42758878 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_create.test.tsx
@@ -185,7 +185,7 @@ describe(' ', () => {
},
aliases: ALIASES,
},
- _kbnMeta: { usedBy: [] },
+ _kbnMeta: { usedBy: [], isManaged: false },
};
expect(JSON.parse(JSON.parse(latestRequest.requestBody).body)).toEqual(expected);
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_details.test.ts b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_details.test.ts
index 7c17dde119c42..3d496d68cc66e 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_details.test.ts
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_details.test.ts
@@ -26,13 +26,13 @@ const COMPONENT_TEMPLATE: ComponentTemplateDeserialized = {
},
version: 1,
_meta: { description: 'component template test' },
- _kbnMeta: { usedBy: ['template_1'] },
+ _kbnMeta: { usedBy: ['template_1'], isManaged: false },
};
const COMPONENT_TEMPLATE_ONLY_REQUIRED_FIELDS: ComponentTemplateDeserialized = {
name: 'comp-base',
template: {},
- _kbnMeta: { usedBy: [] },
+ _kbnMeta: { usedBy: [], isManaged: false },
};
describe(' ', () => {
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_edit.test.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_edit.test.tsx
index 115fdf032da8f..114cafe9defde 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_edit.test.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_edit.test.tsx
@@ -52,7 +52,7 @@ describe(' ', () => {
template: {
settings: { number_of_shards: 1 },
},
- _kbnMeta: { usedBy: [] },
+ _kbnMeta: { usedBy: [], isManaged: false },
};
beforeEach(async () => {
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_list.test.ts b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_list.test.ts
index 6f09e51255f3b..bd6ac27375836 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_list.test.ts
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/component_template_list.test.ts
@@ -42,6 +42,7 @@ describe(' ', () => {
hasAliases: true,
hasSettings: true,
usedBy: [],
+ isManaged: false,
};
const componentTemplate2: ComponentTemplateListItem = {
@@ -50,6 +51,7 @@ describe(' ', () => {
hasAliases: true,
hasSettings: true,
usedBy: ['test_index_template_1'],
+ isManaged: false,
};
const componentTemplates = [componentTemplate1, componentTemplate2];
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/setup_environment.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/setup_environment.tsx
index 70634a226c67b..7e460d3855cb0 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/setup_environment.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/__jest__/client_integration/helpers/setup_environment.tsx
@@ -12,6 +12,7 @@ import { HttpSetup } from 'kibana/public';
import {
notificationServiceMock,
docLinksServiceMock,
+ applicationServiceMock,
} from '../../../../../../../../../../src/core/public/mocks';
import { ComponentTemplatesProvider } from '../../../component_templates_context';
@@ -28,6 +29,7 @@ const appDependencies = {
docLinks: docLinksServiceMock.createStartContract(),
toasts: notificationServiceMock.createSetupContract().toasts,
setBreadcrumbs: () => {},
+ getUrlForApp: applicationServiceMock.createStartContract().getUrlForApp,
};
export const setupEnvironment = () => {
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx
index f94c5c38f23dd..60f1fff3cc9de 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/component_template_details.tsx
@@ -6,6 +6,7 @@
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
+
import {
EuiFlyout,
EuiFlyoutHeader,
@@ -17,6 +18,7 @@ import {
EuiButtonEmpty,
EuiSpacer,
EuiCallOut,
+ EuiBadge,
} from '@elastic/eui';
import { SectionLoading, TabSettings, TabAliases, TabMappings } from '../shared_imports';
@@ -29,14 +31,15 @@ import { attemptToDecodeURI } from '../lib';
interface Props {
componentTemplateName: string;
onClose: () => void;
- showFooter?: boolean;
actions?: ManageAction[];
+ showSummaryCallToAction?: boolean;
}
export const ComponentTemplateDetailsFlyout: React.FunctionComponent = ({
componentTemplateName,
onClose,
actions,
+ showSummaryCallToAction,
}) => {
const { api } = useComponentTemplatesContext();
@@ -81,7 +84,12 @@ export const ComponentTemplateDetailsFlyout: React.FunctionComponent = ({
} = componentTemplateDetails;
const tabToComponentMap: Record = {
- summary: ,
+ summary: (
+
+ ),
settings: ,
mappings: ,
aliases: ,
@@ -109,11 +117,27 @@ export const ComponentTemplateDetailsFlyout: React.FunctionComponent = ({
maxWidth={500}
>
-
-
- {decodedComponentTemplateName}
-
-
+
+
+
+
+ {decodedComponentTemplateName}
+
+
+
+
+ {componentTemplateDetails?._kbnMeta.isManaged ? (
+
+ {' '}
+
+
+
+
+ ) : null}
+
{content}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/tab_summary.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/tab_summary.tsx
index 80f28f23c9f91..8d054b97cb4f6 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/tab_summary.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_details/tab_summary.tsx
@@ -6,6 +6,7 @@
import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
+
import {
EuiDescriptionList,
EuiDescriptionListTitle,
@@ -14,15 +15,23 @@ import {
EuiTitle,
EuiCallOut,
EuiSpacer,
+ EuiLink,
} from '@elastic/eui';
import { ComponentTemplateDeserialized } from '../shared_imports';
+import { useComponentTemplatesContext } from '../component_templates_context';
interface Props {
componentTemplateDetails: ComponentTemplateDeserialized;
+ showCallToAction?: boolean;
}
-export const TabSummary: React.FunctionComponent = ({ componentTemplateDetails }) => {
+export const TabSummary: React.FunctionComponent = ({
+ componentTemplateDetails,
+ showCallToAction,
+}) => {
+ const { getUrlForApp } = useComponentTemplatesContext();
+
const { version, _meta, _kbnMeta } = componentTemplateDetails;
const { usedBy } = _kbnMeta;
@@ -43,7 +52,42 @@ export const TabSummary: React.FunctionComponent = ({ componentTemplateDe
iconType="pin"
data-test-subj="notInUseCallout"
size="s"
- />
+ >
+ {showCallToAction && (
+
+
+
+
+ ),
+ editLink: (
+
+
+
+ ),
+ }}
+ />
+
+ )}
+
>
)}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx
index d356eabc7997d..efc8b649ef872 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx
@@ -9,6 +9,7 @@ import { RouteComponentProps } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ScopedHistory } from 'kibana/public';
+import { EuiLink, EuiText, EuiSpacer } from '@elastic/eui';
import { SectionLoading, ComponentTemplateDeserialized } from '../shared_imports';
import { UIM_COMPONENT_TEMPLATE_LIST_LOAD } from '../constants';
@@ -29,7 +30,7 @@ export const ComponentTemplateList: React.FunctionComponent = ({
componentTemplateName,
history,
}) => {
- const { api, trackMetric } = useComponentTemplatesContext();
+ const { api, trackMetric, documentation } = useComponentTemplatesContext();
const { data, isLoading, error, sendRequest } = api.useLoadComponentTemplates();
@@ -65,20 +66,40 @@ export const ComponentTemplateList: React.FunctionComponent = ({
);
} else if (data?.length) {
content = (
-
+ <>
+
+
+ {i18n.translate('xpack.idxMgmt.componentTemplates.list.learnMoreLinkText', {
+ defaultMessage: 'Learn more.',
+ })}
+
+ ),
+ }}
+ />
+
+
+
+
+
+ >
);
} else if (data && data.length === 0) {
content = ;
@@ -111,6 +132,7 @@ export const ComponentTemplateList: React.FunctionComponent = ({
= ({ history }) => {
{i18n.translate('xpack.idxMgmt.home.componentTemplates.emptyPromptDocumentionLink', {
- defaultMessage: 'Learn more',
+ defaultMessage: 'Learn more.',
})}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/table.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/table.tsx
index 089c2f889e726..fc86609f1217d 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/table.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/table.tsx
@@ -13,11 +13,11 @@ import {
EuiTextColor,
EuiIcon,
EuiLink,
+ EuiBadge,
} from '@elastic/eui';
import { ScopedHistory } from 'kibana/public';
-import { reactRouterNavigate } from '../../../../../../../../src/plugins/kibana_react/public';
-import { ComponentTemplateListItem } from '../shared_imports';
+import { ComponentTemplateListItem, reactRouterNavigate } from '../shared_imports';
import { UIM_COMPONENT_TEMPLATE_DETAILS } from '../constants';
import { useComponentTemplatesContext } from '../component_templates_context';
@@ -105,6 +105,13 @@ export const ComponentTable: FunctionComponent = ({
incremental: true,
},
filters: [
+ {
+ type: 'is',
+ field: 'isManaged',
+ name: i18n.translate('xpack.idxMgmt.componentTemplatesList.table.isManagedFilterLabel', {
+ defaultMessage: 'Managed',
+ }),
+ },
{
type: 'field_value_toggle_group',
field: 'usedBy.length',
@@ -144,26 +151,38 @@ export const ComponentTable: FunctionComponent = ({
defaultMessage: 'Name',
}),
sortable: true,
- render: (name: string) => (
- /* eslint-disable-next-line @elastic/eui/href-or-on-click */
- trackMetric('click', UIM_COMPONENT_TEMPLATE_DETAILS)
+ width: '20%',
+ render: (name: string, item: ComponentTemplateListItem) => (
+ <>
+ trackMetric('click', UIM_COMPONENT_TEMPLATE_DETAILS)
+ )}
+ data-test-subj="templateDetailsLink"
+ >
+ {name}
+
+ {item.isManaged && (
+ <>
+
+
+ {i18n.translate('xpack.idxMgmt.componentTemplatesList.table.managedBadgeLabel', {
+ defaultMessage: 'Managed',
+ })}
+
+ >
)}
- data-test-subj="templateDetailsLink"
- >
- {name}
-
+ >
),
},
{
field: 'usedBy',
name: i18n.translate('xpack.idxMgmt.componentTemplatesList.table.isInUseColumnTitle', {
- defaultMessage: 'Index templates',
+ defaultMessage: 'Usage count',
}),
sortable: true,
render: (usedBy: string[]) => {
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx
index 6e35fbad31d4e..134b8b5eda93d 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/component_template_form.tsx
@@ -74,14 +74,11 @@ const wizardSections: { [id: string]: { id: WizardSection; label: string } } = {
export const ComponentTemplateForm = ({
defaultValue = {
name: '',
- template: {
- settings: {},
- mappings: {},
- aliases: {},
- },
+ template: {},
_meta: {},
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
},
isEditing,
@@ -137,23 +134,49 @@ export const ComponentTemplateForm = ({
>
) : null;
- const buildComponentTemplateObject = (initialTemplate: ComponentTemplateDeserialized) => (
- wizardData: WizardContent
- ): ComponentTemplateDeserialized => {
- const componentTemplate = {
- ...initialTemplate,
- name: wizardData.logistics.name,
- version: wizardData.logistics.version,
- _meta: wizardData.logistics._meta,
- template: {
- settings: wizardData.settings,
- mappings: wizardData.mappings,
- aliases: wizardData.aliases,
- },
- };
- return componentTemplate;
+ /**
+ * If no mappings, settings or aliases are defined, it is better to not send an empty
+ * object for those values.
+ * @param componentTemplate The component template object to clean up
+ */
+ const cleanupComponentTemplateObject = (componentTemplate: ComponentTemplateDeserialized) => {
+ const outputTemplate = { ...componentTemplate };
+
+ if (outputTemplate.template.settings === undefined) {
+ delete outputTemplate.template.settings;
+ }
+
+ if (outputTemplate.template.mappings === undefined) {
+ delete outputTemplate.template.mappings;
+ }
+
+ if (outputTemplate.template.aliases === undefined) {
+ delete outputTemplate.template.aliases;
+ }
+
+ return outputTemplate;
};
+ const buildComponentTemplateObject = useCallback(
+ (initialTemplate: ComponentTemplateDeserialized) => (
+ wizardData: WizardContent
+ ): ComponentTemplateDeserialized => {
+ const outputComponentTemplate = {
+ ...initialTemplate,
+ name: wizardData.logistics.name,
+ version: wizardData.logistics.version,
+ _meta: wizardData.logistics._meta,
+ template: {
+ settings: wizardData.settings,
+ mappings: wizardData.mappings,
+ aliases: wizardData.aliases,
+ },
+ };
+ return cleanupComponentTemplateObject(outputComponentTemplate);
+ },
+ []
+ );
+
const onSaveComponentTemplate = useCallback(
async (wizardData: WizardContent) => {
const componentTemplate = buildComponentTemplateObject(defaultValue)(wizardData);
@@ -161,13 +184,13 @@ export const ComponentTemplateForm = ({
// This will strip an empty string if "version" is not set, as well as an empty "_meta" object
onSave(
stripEmptyFields(componentTemplate, {
- types: ['string', 'object'],
+ types: ['string'],
}) as ComponentTemplateDeserialized
);
clearSaveError();
},
- [defaultValue, onSave, clearSaveError]
+ [buildComponentTemplateObject, defaultValue, onSave, clearSaveError]
);
return (
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_logistics.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_logistics.tsx
index 18988fa125a06..c48a23226a371 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_logistics.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_logistics.tsx
@@ -117,7 +117,7 @@ export const StepLogistics: React.FunctionComponent = React.memo(
description={
}
>
@@ -141,7 +141,7 @@ export const StepLogistics: React.FunctionComponent = React.memo(
description={
}
>
@@ -165,7 +165,7 @@ export const StepLogistics: React.FunctionComponent = React.memo(
<>
= React.memo(
{i18n.translate(
'xpack.idxMgmt.componentTemplateForm.stepLogistics.metaDocumentionLink',
{
- defaultMessage: 'Learn more',
+ defaultMessage: 'Learn more.',
}
)}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_review.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_review.tsx
index ce85854dc79ab..67246f2e10c3b 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_review.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_review.tsx
@@ -52,16 +52,12 @@ export const StepReview: React.FunctionComponent = React.memo(({ componen
const serializedComponentTemplate = serializeComponentTemplate(
stripEmptyFields(componentTemplate, {
- types: ['string', 'object'],
+ types: ['string'],
}) as ComponentTemplateDeserialized
);
const {
- template: {
- mappings: serializedMappings,
- settings: serializedSettings,
- aliases: serializedAliases,
- },
+ template: serializedTemplate,
_meta: serializedMeta,
version: serializedVersion,
} = serializedComponentTemplate;
@@ -94,7 +90,7 @@ export const StepReview: React.FunctionComponent = React.memo(({ componen
/>
- {getDescriptionText(serializedSettings)}
+ {getDescriptionText(serializedTemplate?.settings)}
{/* Mappings */}
@@ -105,7 +101,7 @@ export const StepReview: React.FunctionComponent = React.memo(({ componen
/>
- {getDescriptionText(serializedMappings)}
+ {getDescriptionText(serializedTemplate?.mappings)}
{/* Aliases */}
@@ -116,7 +112,7 @@ export const StepReview: React.FunctionComponent = React.memo(({ componen
/>
- {getDescriptionText(serializedAliases)}
+ {getDescriptionText(serializedTemplate?.aliases)}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/component_templates_context.tsx b/x-pack/plugins/index_management/public/application/components/component_templates/component_templates_context.tsx
index ce9e28d0feefe..7be0618481a69 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/component_templates_context.tsx
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/component_templates_context.tsx
@@ -5,7 +5,7 @@
*/
import React, { createContext, useContext } from 'react';
-import { HttpSetup, DocLinksStart, NotificationsSetup } from 'src/core/public';
+import { HttpSetup, DocLinksStart, NotificationsSetup, CoreStart } from 'src/core/public';
import { ManagementAppMountParams } from 'src/plugins/management/public';
import { getApi, getUseRequest, getSendRequest, getDocumentation, getBreadcrumbs } from './lib';
@@ -19,6 +19,7 @@ interface Props {
docLinks: DocLinksStart;
toasts: NotificationsSetup['toasts'];
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
+ getUrlForApp: CoreStart['application']['getUrlForApp'];
}
interface Context {
@@ -29,6 +30,7 @@ interface Context {
breadcrumbs: ReturnType;
trackMetric: (type: 'loaded' | 'click' | 'count', eventName: string) => void;
toasts: NotificationsSetup['toasts'];
+ getUrlForApp: CoreStart['application']['getUrlForApp'];
}
export const ComponentTemplatesProvider = ({
@@ -38,7 +40,15 @@ export const ComponentTemplatesProvider = ({
value: Props;
children: React.ReactNode;
}) => {
- const { httpClient, apiBasePath, trackMetric, docLinks, toasts, setBreadcrumbs } = value;
+ const {
+ httpClient,
+ apiBasePath,
+ trackMetric,
+ docLinks,
+ toasts,
+ setBreadcrumbs,
+ getUrlForApp,
+ } = value;
const useRequest = getUseRequest(httpClient);
const sendRequest = getSendRequest(httpClient);
@@ -49,7 +59,16 @@ export const ComponentTemplatesProvider = ({
return (
{children}
diff --git a/x-pack/plugins/index_management/public/application/components/component_templates/shared_imports.ts b/x-pack/plugins/index_management/public/application/components/component_templates/shared_imports.ts
index 80e222f4f7706..278fadcd90c8b 100644
--- a/x-pack/plugins/index_management/public/application/components/component_templates/shared_imports.ts
+++ b/x-pack/plugins/index_management/public/application/components/component_templates/shared_imports.ts
@@ -62,3 +62,5 @@ export {
} from '../../../../common';
export { serializeComponentTemplate } from '../../../../common/lib';
+
+export { reactRouterNavigate } from '../../../../../../../src/plugins/kibana_react/public';
diff --git a/x-pack/plugins/index_management/public/application/index.tsx b/x-pack/plugins/index_management/public/application/index.tsx
index 7b053a15b26d0..ebc29ac86a17f 100644
--- a/x-pack/plugins/index_management/public/application/index.tsx
+++ b/x-pack/plugins/index_management/public/application/index.tsx
@@ -25,7 +25,7 @@ export const renderApp = (
return () => undefined;
}
- const { i18n, docLinks, notifications } = core;
+ const { i18n, docLinks, notifications, application } = core;
const { Context: I18nContext } = i18n;
const { services, history, setBreadcrumbs } = dependencies;
@@ -36,6 +36,7 @@ export const renderApp = (
docLinks,
toasts: notifications.toasts,
setBreadcrumbs,
+ getUrlForApp: application.getUrlForApp,
};
render(
diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts
index f6f8e7d63d370..16b028887f63c 100644
--- a/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts
+++ b/x-pack/plugins/index_management/server/routes/api/component_templates/get.ts
@@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema';
import {
deserializeComponentTemplate,
- deserializeComponenTemplateList,
+ deserializeComponentTemplateList,
} from '../../../../common/lib';
import { ComponentTemplateFromEs } from '../../../../common';
import { RouteDependencies } from '../../../types';
@@ -36,7 +36,7 @@ export function registerGetAllRoute({ router, license, lib: { isEsError } }: Rou
);
const body = componentTemplates.map((componentTemplate) => {
- const deserializedComponentTemplateListItem = deserializeComponenTemplateList(
+ const deserializedComponentTemplateListItem = deserializeComponentTemplateList(
componentTemplate,
indexTemplates
);
diff --git a/x-pack/plugins/index_management/server/routes/api/component_templates/schema_validation.ts b/x-pack/plugins/index_management/server/routes/api/component_templates/schema_validation.ts
index a1fc258127229..cfcb428f00501 100644
--- a/x-pack/plugins/index_management/server/routes/api/component_templates/schema_validation.ts
+++ b/x-pack/plugins/index_management/server/routes/api/component_templates/schema_validation.ts
@@ -16,5 +16,6 @@ export const componentTemplateSchema = schema.object({
_meta: schema.maybe(schema.object({}, { unknowns: 'allow' })),
_kbnMeta: schema.object({
usedBy: schema.arrayOf(schema.string()),
+ isManaged: schema.boolean(),
}),
});
diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts
index 30b6be435837b..cbd89db97236f 100644
--- a/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts
+++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/index.ts
@@ -8,4 +8,5 @@ export * from './log_entry_categories';
export * from './log_entry_category_datasets';
export * from './log_entry_category_examples';
export * from './log_entry_rate';
-export * from './log_entry_rate_examples';
+export * from './log_entry_examples';
+export * from './log_entry_anomalies';
diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts
new file mode 100644
index 0000000000000..639ac63f9b14d
--- /dev/null
+++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_anomalies.ts
@@ -0,0 +1,137 @@
+/*
+ * 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 * as rt from 'io-ts';
+
+import { timeRangeRT, routeTimingMetadataRT } from '../../shared';
+
+export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH =
+ '/api/infra/log_analysis/results/log_entry_anomalies';
+
+// [Sort field value, tiebreaker value]
+const paginationCursorRT = rt.tuple([
+ rt.union([rt.string, rt.number]),
+ rt.union([rt.string, rt.number]),
+]);
+
+export type PaginationCursor = rt.TypeOf;
+
+export const anomalyTypeRT = rt.keyof({
+ logRate: null,
+ logCategory: null,
+});
+
+export type AnomalyType = rt.TypeOf;
+
+const logEntryAnomalyCommonFieldsRT = rt.type({
+ id: rt.string,
+ anomalyScore: rt.number,
+ dataset: rt.string,
+ typical: rt.number,
+ actual: rt.number,
+ type: anomalyTypeRT,
+ duration: rt.number,
+ startTime: rt.number,
+ jobId: rt.string,
+});
+const logEntrylogRateAnomalyRT = logEntryAnomalyCommonFieldsRT;
+const logEntrylogCategoryAnomalyRT = rt.partial({
+ categoryId: rt.string,
+});
+const logEntryAnomalyRT = rt.intersection([
+ logEntryAnomalyCommonFieldsRT,
+ logEntrylogRateAnomalyRT,
+ logEntrylogCategoryAnomalyRT,
+]);
+
+export type LogEntryAnomaly = rt.TypeOf;
+
+export const getLogEntryAnomaliesSuccessReponsePayloadRT = rt.intersection([
+ rt.type({
+ data: rt.intersection([
+ rt.type({
+ anomalies: rt.array(logEntryAnomalyRT),
+ // Signifies there are more entries backwards or forwards. If this was a request
+ // for a previous page, there are more previous pages, if this was a request for a next page,
+ // there are more next pages.
+ hasMoreEntries: rt.boolean,
+ }),
+ rt.partial({
+ paginationCursors: rt.type({
+ // The cursor to use to fetch the previous page
+ previousPageCursor: paginationCursorRT,
+ // The cursor to use to fetch the next page
+ nextPageCursor: paginationCursorRT,
+ }),
+ }),
+ ]),
+ }),
+ rt.partial({
+ timing: routeTimingMetadataRT,
+ }),
+]);
+
+export type GetLogEntryAnomaliesSuccessResponsePayload = rt.TypeOf<
+ typeof getLogEntryAnomaliesSuccessReponsePayloadRT
+>;
+
+const sortOptionsRT = rt.keyof({
+ anomalyScore: null,
+ dataset: null,
+ startTime: null,
+});
+
+const sortDirectionsRT = rt.keyof({
+ asc: null,
+ desc: null,
+});
+
+const paginationPreviousPageCursorRT = rt.type({
+ searchBefore: paginationCursorRT,
+});
+
+const paginationNextPageCursorRT = rt.type({
+ searchAfter: paginationCursorRT,
+});
+
+const paginationRT = rt.intersection([
+ rt.type({
+ pageSize: rt.number,
+ }),
+ rt.partial({
+ cursor: rt.union([paginationPreviousPageCursorRT, paginationNextPageCursorRT]),
+ }),
+]);
+
+export type Pagination = rt.TypeOf;
+
+const sortRT = rt.type({
+ field: sortOptionsRT,
+ direction: sortDirectionsRT,
+});
+
+export type Sort = rt.TypeOf;
+
+export const getLogEntryAnomaliesRequestPayloadRT = rt.type({
+ data: rt.intersection([
+ rt.type({
+ // the ID of the source configuration
+ sourceId: rt.string,
+ // the time range to fetch the log entry anomalies from
+ timeRange: timeRangeRT,
+ }),
+ rt.partial({
+ // Pagination properties
+ pagination: paginationRT,
+ // Sort properties
+ sort: sortRT,
+ }),
+ ]),
+});
+
+export type GetLogEntryAnomaliesRequestPayload = rt.TypeOf<
+ typeof getLogEntryAnomaliesRequestPayloadRT
+>;
diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts
new file mode 100644
index 0000000000000..1eed29cd37560
--- /dev/null
+++ b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_examples.ts
@@ -0,0 +1,82 @@
+/*
+ * 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 * as rt from 'io-ts';
+
+import {
+ badRequestErrorRT,
+ forbiddenErrorRT,
+ timeRangeRT,
+ routeTimingMetadataRT,
+} from '../../shared';
+
+export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH =
+ '/api/infra/log_analysis/results/log_entry_examples';
+
+/**
+ * request
+ */
+
+export const getLogEntryExamplesRequestPayloadRT = rt.type({
+ data: rt.intersection([
+ rt.type({
+ // the dataset to fetch the log rate examples from
+ dataset: rt.string,
+ // the number of examples to fetch
+ exampleCount: rt.number,
+ // the id of the source configuration
+ sourceId: rt.string,
+ // the time range to fetch the log rate examples from
+ timeRange: timeRangeRT,
+ }),
+ rt.partial({
+ categoryId: rt.string,
+ }),
+ ]),
+});
+
+export type GetLogEntryExamplesRequestPayload = rt.TypeOf<
+ typeof getLogEntryExamplesRequestPayloadRT
+>;
+
+/**
+ * response
+ */
+
+const logEntryExampleRT = rt.type({
+ id: rt.string,
+ dataset: rt.string,
+ message: rt.string,
+ timestamp: rt.number,
+ tiebreaker: rt.number,
+});
+
+export type LogEntryExample = rt.TypeOf;
+
+export const getLogEntryExamplesSuccessReponsePayloadRT = rt.intersection([
+ rt.type({
+ data: rt.type({
+ examples: rt.array(logEntryExampleRT),
+ }),
+ }),
+ rt.partial({
+ timing: routeTimingMetadataRT,
+ }),
+]);
+
+export type GetLogEntryExamplesSuccessReponsePayload = rt.TypeOf<
+ typeof getLogEntryExamplesSuccessReponsePayloadRT
+>;
+
+export const getLogEntryExamplesResponsePayloadRT = rt.union([
+ getLogEntryExamplesSuccessReponsePayloadRT,
+ badRequestErrorRT,
+ forbiddenErrorRT,
+]);
+
+export type GetLogEntryExamplesResponsePayload = rt.TypeOf<
+ typeof getLogEntryExamplesResponsePayloadRT
+>;
diff --git a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate_examples.ts b/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate_examples.ts
deleted file mode 100644
index 700f87ec3beb1..0000000000000
--- a/x-pack/plugins/infra/common/http_api/log_analysis/results/log_entry_rate_examples.ts
+++ /dev/null
@@ -1,77 +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 * as rt from 'io-ts';
-
-import {
- badRequestErrorRT,
- forbiddenErrorRT,
- timeRangeRT,
- routeTimingMetadataRT,
-} from '../../shared';
-
-export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH =
- '/api/infra/log_analysis/results/log_entry_rate_examples';
-
-/**
- * request
- */
-
-export const getLogEntryRateExamplesRequestPayloadRT = rt.type({
- data: rt.type({
- // the dataset to fetch the log rate examples from
- dataset: rt.string,
- // the number of examples to fetch
- exampleCount: rt.number,
- // the id of the source configuration
- sourceId: rt.string,
- // the time range to fetch the log rate examples from
- timeRange: timeRangeRT,
- }),
-});
-
-export type GetLogEntryRateExamplesRequestPayload = rt.TypeOf<
- typeof getLogEntryRateExamplesRequestPayloadRT
->;
-
-/**
- * response
- */
-
-const logEntryRateExampleRT = rt.type({
- id: rt.string,
- dataset: rt.string,
- message: rt.string,
- timestamp: rt.number,
- tiebreaker: rt.number,
-});
-
-export type LogEntryRateExample = rt.TypeOf;
-
-export const getLogEntryRateExamplesSuccessReponsePayloadRT = rt.intersection([
- rt.type({
- data: rt.type({
- examples: rt.array(logEntryRateExampleRT),
- }),
- }),
- rt.partial({
- timing: routeTimingMetadataRT,
- }),
-]);
-
-export type GetLogEntryRateExamplesSuccessReponsePayload = rt.TypeOf<
- typeof getLogEntryRateExamplesSuccessReponsePayloadRT
->;
-
-export const getLogEntryRateExamplesResponsePayloadRT = rt.union([
- getLogEntryRateExamplesSuccessReponsePayloadRT,
- badRequestErrorRT,
- forbiddenErrorRT,
-]);
-
-export type GetLogEntryRateExamplesResponsePayload = rt.TypeOf<
- typeof getLogEntryRateExamplesResponsePayloadRT
->;
diff --git a/x-pack/plugins/infra/common/log_analysis/log_analysis_results.ts b/x-pack/plugins/infra/common/log_analysis/log_analysis_results.ts
index 19c92cb381104..f4497dbba5056 100644
--- a/x-pack/plugins/infra/common/log_analysis/log_analysis_results.ts
+++ b/x-pack/plugins/infra/common/log_analysis/log_analysis_results.ts
@@ -41,6 +41,10 @@ export const formatAnomalyScore = (score: number) => {
return Math.round(score);
};
+export const formatOneDecimalPlace = (number: number) => {
+ return Math.round(number * 10) / 10;
+};
+
export const getFriendlyNameForPartitionId = (partitionId: string) => {
return partitionId !== '' ? partitionId : 'unknown';
};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx
index bf4dbcd87cc41..21c3e3ec70029 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/page_results_content.tsx
@@ -5,30 +5,18 @@
*/
import datemath from '@elastic/datemath';
-import {
- EuiBadge,
- EuiFlexGroup,
- EuiFlexItem,
- EuiPage,
- EuiPanel,
- EuiSuperDatePicker,
- EuiText,
-} from '@elastic/eui';
-import numeral from '@elastic/numeral';
-import { FormattedMessage } from '@kbn/i18n/react';
+import { EuiFlexGroup, EuiFlexItem, EuiPage, EuiPanel, EuiSuperDatePicker } from '@elastic/eui';
import moment from 'moment';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { euiStyled, useTrackPageview } from '../../../../../observability/public';
import { TimeRange } from '../../../../common/http_api/shared/time_range';
import { bucketSpan } from '../../../../common/log_analysis';
-import { LoadingOverlayWrapper } from '../../../components/loading_overlay_wrapper';
import { LogAnalysisJobProblemIndicator } from '../../../components/logging/log_analysis_job_status';
import { useInterval } from '../../../hooks/use_interval';
-import { useKibanaUiSetting } from '../../../utils/use_kibana_ui_setting';
import { AnomaliesResults } from './sections/anomalies';
-import { LogRateResults } from './sections/log_rate';
import { useLogEntryRateModuleContext } from './use_log_entry_rate_module';
import { useLogEntryRateResults } from './use_log_entry_rate_results';
+import { useLogEntryAnomaliesResults } from './use_log_entry_anomalies_results';
import {
StringTimeRange,
useLogAnalysisResultsUrlState,
@@ -36,6 +24,15 @@ import {
const JOB_STATUS_POLLING_INTERVAL = 30000;
+export const SORT_DEFAULTS = {
+ direction: 'desc' as const,
+ field: 'anomalyScore' as const,
+};
+
+export const PAGINATION_DEFAULTS = {
+ pageSize: 25,
+};
+
interface LogEntryRateResultsContentProps {
onOpenSetup: () => void;
}
@@ -46,8 +43,6 @@ export const LogEntryRateResultsContent: React.FunctionComponent {
setQueryTimeRange({
@@ -182,45 +194,18 @@ export const LogEntryRateResultsContent: React.FunctionComponent
-
-
-
- {logEntryRate ? (
-
-
-
-
- {numeral(logEntryRate.totalNumberOfLogEntries).format('0.00a')}
-
-
- ),
- startTime: (
- {moment(queryTimeRange.value.startTime).format(dateFormat)}
- ),
- endTime: {moment(queryTimeRange.value.endTime).format(dateFormat)} ,
- }}
- />
-
-
- ) : null}
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/chart.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/chart.tsx
index 79ab4475ee5a3..ae5c3b5b93b47 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/chart.tsx
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/chart.tsx
@@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-
+import { EuiEmptyPrompt } from '@elastic/eui';
import { RectAnnotationDatum, AnnotationId } from '@elastic/charts';
import {
Axis,
@@ -21,6 +21,7 @@ import numeral from '@elastic/numeral';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import React, { useCallback, useMemo } from 'react';
+import { LoadingOverlayWrapper } from '../../../../../components/loading_overlay_wrapper';
import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
import {
@@ -36,7 +37,16 @@ export const AnomaliesChart: React.FunctionComponent<{
series: Array<{ time: number; value: number }>;
annotations: Record;
renderAnnotationTooltip?: (details?: string) => JSX.Element;
-}> = ({ chartId, series, annotations, setTimeRange, timeRange, renderAnnotationTooltip }) => {
+ isLoading: boolean;
+}> = ({
+ chartId,
+ series,
+ annotations,
+ setTimeRange,
+ timeRange,
+ renderAnnotationTooltip,
+ isLoading,
+}) => {
const [dateFormat] = useKibanaUiSetting('dateFormat', 'Y-MM-DD HH:mm:ss.SSS');
const [isDarkMode] = useKibanaUiSetting('theme:darkMode');
@@ -68,41 +78,56 @@ export const AnomaliesChart: React.FunctionComponent<{
[setTimeRange]
);
- return (
-
-
-
- numeral(value.toPrecision(3)).format('0[.][00]a')} // https://github.com/adamwdraper/Numeral-js/issues/194
- />
-
+ {i18n.translate('xpack.infra.logs.analysis.anomalySectionLogRateChartNoData', {
+ defaultMessage: 'There is no log rate data to display.',
})}
- xScaleType="time"
- yScaleType="linear"
- xAccessor={'time'}
- yAccessors={['value']}
- data={series}
- barSeriesStyle={barSeriesStyle}
- />
- {renderAnnotations(annotations, chartId, renderAnnotationTooltip)}
-
-
-
+
+ }
+ titleSize="m"
+ />
+ ) : (
+
+
+ {series.length ? (
+
+
+ numeral(value.toPrecision(3)).format('0[.][00]a')} // https://github.com/adamwdraper/Numeral-js/issues/194
+ />
+
+ {renderAnnotations(annotations, chartId, renderAnnotationTooltip)}
+
+
+ ) : null}
+
+
);
};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx
index c527b8c49d099..e4b12e199a048 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/expanded_row.tsx
@@ -10,12 +10,12 @@ import { i18n } from '@kbn/i18n';
import React from 'react';
import { useMount } from 'react-use';
import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
-import { AnomalyRecord } from '../../use_log_entry_rate_results';
-import { useLogEntryRateModuleContext } from '../../use_log_entry_rate_module';
-import { useLogEntryRateExamples } from '../../use_log_entry_rate_examples';
+import { LogEntryAnomaly } from '../../../../../../common/http_api';
+import { useLogEntryExamples } from '../../use_log_entry_examples';
import { LogEntryExampleMessages } from '../../../../../components/logging/log_entry_examples/log_entry_examples';
-import { LogEntryRateExampleMessage, LogEntryRateExampleMessageHeaders } from './log_entry_example';
+import { LogEntryExampleMessage, LogEntryExampleMessageHeaders } from './log_entry_example';
import { euiStyled } from '../../../../../../../observability/public';
+import { useLogSourceContext } from '../../../../../containers/logs/log_source';
const EXAMPLE_COUNT = 5;
@@ -24,29 +24,27 @@ const examplesTitle = i18n.translate('xpack.infra.logs.analysis.anomaliesTableEx
});
export const AnomaliesTableExpandedRow: React.FunctionComponent<{
- anomaly: AnomalyRecord;
+ anomaly: LogEntryAnomaly;
timeRange: TimeRange;
- jobId: string;
-}> = ({ anomaly, timeRange, jobId }) => {
- const {
- sourceConfiguration: { sourceId },
- } = useLogEntryRateModuleContext();
+}> = ({ anomaly, timeRange }) => {
+ const { sourceId } = useLogSourceContext();
const {
- getLogEntryRateExamples,
- hasFailedLoadingLogEntryRateExamples,
- isLoadingLogEntryRateExamples,
- logEntryRateExamples,
- } = useLogEntryRateExamples({
- dataset: anomaly.partitionId,
+ getLogEntryExamples,
+ hasFailedLoadingLogEntryExamples,
+ isLoadingLogEntryExamples,
+ logEntryExamples,
+ } = useLogEntryExamples({
+ dataset: anomaly.dataset,
endTime: anomaly.startTime + anomaly.duration,
exampleCount: EXAMPLE_COUNT,
sourceId,
startTime: anomaly.startTime,
+ categoryId: anomaly.categoryId,
});
useMount(() => {
- getLogEntryRateExamples();
+ getLogEntryExamples();
});
return (
@@ -57,17 +55,17 @@ export const AnomaliesTableExpandedRow: React.FunctionComponent<{
{examplesTitle}
0}
+ isLoading={isLoadingLogEntryExamples}
+ hasFailedLoading={hasFailedLoadingLogEntryExamples}
+ hasResults={logEntryExamples.length > 0}
exampleCount={EXAMPLE_COUNT}
- onReload={getLogEntryRateExamples}
+ onReload={getLogEntryExamples}
>
- {logEntryRateExamples.length > 0 ? (
+ {logEntryExamples.length > 0 ? (
<>
-
- {logEntryRateExamples.map((example, exampleIndex) => (
-
+ {logEntryExamples.map((example, exampleIndex) => (
+
))}
>
@@ -87,11 +85,11 @@ export const AnomaliesTableExpandedRow: React.FunctionComponent<{
void;
timeRange: TimeRange;
viewSetupForReconfiguration: () => void;
- jobId: string;
-}> = ({ isLoading, results, setTimeRange, timeRange, viewSetupForReconfiguration, jobId }) => {
- const hasAnomalies = useMemo(() => {
- return results && results.histogramBuckets
- ? results.histogramBuckets.some((bucket) => {
- return bucket.partitions.some((partition) => {
- return partition.anomalies.length > 0;
- });
- })
- : false;
- }, [results]);
-
+ page: Page;
+ fetchNextPage?: FetchNextPage;
+ fetchPreviousPage?: FetchPreviousPage;
+ changeSortOptions: ChangeSortOptions;
+ changePaginationOptions: ChangePaginationOptions;
+ sortOptions: SortOptions;
+ paginationOptions: PaginationOptions;
+}> = ({
+ isLoadingLogRateResults,
+ isLoadingAnomaliesResults,
+ logEntryRateResults,
+ setTimeRange,
+ timeRange,
+ viewSetupForReconfiguration,
+ anomalies,
+ changeSortOptions,
+ sortOptions,
+ changePaginationOptions,
+ paginationOptions,
+ fetchNextPage,
+ fetchPreviousPage,
+ page,
+}) => {
const logEntryRateSeries = useMemo(
- () => (results && results.histogramBuckets ? getLogEntryRateCombinedSeries(results) : []),
- [results]
+ () =>
+ logEntryRateResults && logEntryRateResults.histogramBuckets
+ ? getLogEntryRateCombinedSeries(logEntryRateResults)
+ : [],
+ [logEntryRateResults]
);
const anomalyAnnotations = useMemo(
() =>
- results && results.histogramBuckets
- ? getAnnotationsForAll(results)
+ logEntryRateResults && logEntryRateResults.histogramBuckets
+ ? getAnnotationsForAll(logEntryRateResults)
: {
warning: [],
minor: [],
major: [],
critical: [],
},
- [results]
+ [logEntryRateResults]
);
return (
<>
-
- {title}
+
+ {title}
-
-
-
- }>
- {!results || (results && results.histogramBuckets && !results.histogramBuckets.length) ? (
+ {(!logEntryRateResults ||
+ (logEntryRateResults &&
+ logEntryRateResults.histogramBuckets &&
+ !logEntryRateResults.histogramBuckets.length)) &&
+ (!anomalies || anomalies.length === 0) ? (
+ }
+ >
@@ -94,41 +123,38 @@ export const AnomaliesResults: React.FunctionComponent<{
}
/>
- ) : !hasAnomalies ? (
-
- {i18n.translate('xpack.infra.logs.analysis.anomalySectionNoAnomaliesTitle', {
- defaultMessage: 'No anomalies were detected.',
- })}
-
- }
- titleSize="m"
+
+ ) : (
+ <>
+
+
+
+
+
+
+
- ) : (
- <>
-
-
-
-
-
-
-
- >
- )}
-
+ >
+ )}
>
);
};
@@ -137,13 +163,6 @@ const title = i18n.translate('xpack.infra.logs.analysis.anomaliesSectionTitle',
defaultMessage: 'Anomalies',
});
-const loadingAriaLabel = i18n.translate(
- 'xpack.infra.logs.analysis.anomaliesSectionLoadingAriaLabel',
- { defaultMessage: 'Loading anomalies' }
-);
-
-const LoadingOverlayContent = () => ;
-
interface ParsedAnnotationDetails {
anomalyScoresByPartition: Array<{ partitionName: string; maximumAnomalyScore: number }>;
}
@@ -189,3 +208,10 @@ const renderAnnotationTooltip = (details?: string) => {
const TooltipWrapper = euiStyled('div')`
white-space: nowrap;
`;
+
+const loadingAriaLabel = i18n.translate(
+ 'xpack.infra.logs.analysis.anomaliesSectionLoadingAriaLabel',
+ { defaultMessage: 'Loading anomalies' }
+);
+
+const LoadingOverlayContent = () => ;
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx
index 96f665b3693ca..2965e1fede822 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/log_entry_example.tsx
@@ -28,7 +28,7 @@ import { useLinkProps } from '../../../../../hooks/use_link_props';
import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
import { partitionField } from '../../../../../../common/log_analysis/job_parameters';
import { getEntitySpecificSingleMetricViewerLink } from '../../../../../components/logging/log_analysis_results/analyze_in_ml_button';
-import { LogEntryRateExample } from '../../../../../../common/http_api/log_analysis/results';
+import { LogEntryExample } from '../../../../../../common/http_api/log_analysis/results';
import {
LogColumnConfiguration,
isTimestampLogColumnConfiguration,
@@ -36,6 +36,7 @@ import {
isMessageLogColumnConfiguration,
} from '../../../../../utils/source_configuration';
import { localizedDate } from '../../../../../../common/formatters/datetime';
+import { LogEntryAnomaly } from '../../../../../../common/http_api';
export const exampleMessageScale = 'medium' as const;
export const exampleTimestampFormat = 'time' as const;
@@ -58,19 +59,19 @@ const VIEW_ANOMALY_IN_ML_LABEL = i18n.translate(
}
);
-type Props = LogEntryRateExample & {
+type Props = LogEntryExample & {
timeRange: TimeRange;
- jobId: string;
+ anomaly: LogEntryAnomaly;
};
-export const LogEntryRateExampleMessage: React.FunctionComponent = ({
+export const LogEntryExampleMessage: React.FunctionComponent = ({
id,
dataset,
message,
timestamp,
tiebreaker,
timeRange,
- jobId,
+ anomaly,
}) => {
const [isHovered, setIsHovered] = useState(false);
const [isMenuOpen, setIsMenuOpen] = useState(false);
@@ -107,8 +108,9 @@ export const LogEntryRateExampleMessage: React.FunctionComponent = ({
});
const viewAnomalyInMachineLearningLinkProps = useLinkProps(
- getEntitySpecificSingleMetricViewerLink(jobId, timeRange, {
+ getEntitySpecificSingleMetricViewerLink(anomaly.jobId, timeRange, {
[partitionField]: dataset,
+ ...(anomaly.categoryId ? { mlcategory: anomaly.categoryId } : {}),
})
);
@@ -233,11 +235,11 @@ export const exampleMessageColumnConfigurations: LogColumnConfiguration[] = [
},
];
-export const LogEntryRateExampleMessageHeaders: React.FunctionComponent<{
+export const LogEntryExampleMessageHeaders: React.FunctionComponent<{
dateTime: number;
}> = ({ dateTime }) => {
return (
-
+
<>
{exampleMessageColumnConfigurations.map((columnConfiguration) => {
if (isTimestampLogColumnConfiguration(columnConfiguration)) {
@@ -280,11 +282,11 @@ export const LogEntryRateExampleMessageHeaders: React.FunctionComponent<{
{null}
>
-
+
);
};
-const LogEntryRateExampleMessageHeadersWrapper = euiStyled(LogColumnHeadersWrapper)`
+const LogEntryExampleMessageHeadersWrapper = euiStyled(LogColumnHeadersWrapper)`
border-bottom: none;
box-shadow: none;
padding-right: 0;
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx
index c70a456bfe06a..e0a3b6fb91db0 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/anomalies/table.tsx
@@ -4,45 +4,52 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import { EuiBasicTable, EuiBasicTableColumn } from '@elastic/eui';
+import {
+ EuiBasicTable,
+ EuiBasicTableColumn,
+ EuiIcon,
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiButtonIcon,
+ EuiSpacer,
+} from '@elastic/eui';
import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';
import moment from 'moment';
import { i18n } from '@kbn/i18n';
-import React, { useCallback, useMemo, useState } from 'react';
+import React, { useCallback, useMemo } from 'react';
import { useSet } from 'react-use';
import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
import {
formatAnomalyScore,
getFriendlyNameForPartitionId,
+ formatOneDecimalPlace,
} from '../../../../../../common/log_analysis';
+import { AnomalyType } from '../../../../../../common/http_api/log_analysis';
import { RowExpansionButton } from '../../../../../components/basic_table';
-import { LogEntryRateResults } from '../../use_log_entry_rate_results';
import { AnomaliesTableExpandedRow } from './expanded_row';
import { AnomalySeverityIndicator } from '../../../../../components/logging/log_analysis_results/anomaly_severity_indicator';
import { useKibanaUiSetting } from '../../../../../utils/use_kibana_ui_setting';
+import {
+ Page,
+ FetchNextPage,
+ FetchPreviousPage,
+ ChangeSortOptions,
+ ChangePaginationOptions,
+ SortOptions,
+ PaginationOptions,
+ LogEntryAnomalies,
+} from '../../use_log_entry_anomalies_results';
+import { LoadingOverlayWrapper } from '../../../../../components/loading_overlay_wrapper';
interface TableItem {
id: string;
dataset: string;
datasetName: string;
anomalyScore: number;
- anomalyMessage: string;
startTime: number;
-}
-
-interface SortingOptions {
- sort: {
- field: keyof TableItem;
- direction: 'asc' | 'desc';
- };
-}
-
-interface PaginationOptions {
- pageIndex: number;
- pageSize: number;
- totalItemCount: number;
- pageSizeOptions: number[];
- hidePerPageOptions: boolean;
+ typical: number;
+ actual: number;
+ type: AnomalyType;
}
const anomalyScoreColumnName = i18n.translate(
@@ -73,125 +80,78 @@ const datasetColumnName = i18n.translate(
}
);
-const moreThanExpectedAnomalyMessage = i18n.translate(
- 'xpack.infra.logs.analysis.anomaliesTableMoreThanExpectedAnomalyMessage',
- {
- defaultMessage: 'More log messages in this dataset than expected',
- }
-);
-
-const fewerThanExpectedAnomalyMessage = i18n.translate(
- 'xpack.infra.logs.analysis.anomaliesTableFewerThanExpectedAnomalyMessage',
- {
- defaultMessage: 'Fewer log messages in this dataset than expected',
- }
-);
-
-const getAnomalyMessage = (actualRate: number, typicalRate: number): string => {
- return actualRate < typicalRate
- ? fewerThanExpectedAnomalyMessage
- : moreThanExpectedAnomalyMessage;
-};
-
export const AnomaliesTable: React.FunctionComponent<{
- results: LogEntryRateResults;
+ results: LogEntryAnomalies;
setTimeRange: (timeRange: TimeRange) => void;
timeRange: TimeRange;
- jobId: string;
-}> = ({ results, timeRange, setTimeRange, jobId }) => {
+ changeSortOptions: ChangeSortOptions;
+ changePaginationOptions: ChangePaginationOptions;
+ sortOptions: SortOptions;
+ paginationOptions: PaginationOptions;
+ page: Page;
+ fetchNextPage?: FetchNextPage;
+ fetchPreviousPage?: FetchPreviousPage;
+ isLoading: boolean;
+}> = ({
+ results,
+ timeRange,
+ setTimeRange,
+ changeSortOptions,
+ sortOptions,
+ changePaginationOptions,
+ paginationOptions,
+ fetchNextPage,
+ fetchPreviousPage,
+ page,
+ isLoading,
+}) => {
const [dateFormat] = useKibanaUiSetting('dateFormat', 'Y-MM-DD HH:mm:ss');
+ const tableSortOptions = useMemo(() => {
+ return {
+ sort: sortOptions,
+ };
+ }, [sortOptions]);
+
const tableItems: TableItem[] = useMemo(() => {
- return results.anomalies.map((anomaly) => {
+ return results.map((anomaly) => {
return {
id: anomaly.id,
- dataset: anomaly.partitionId,
- datasetName: getFriendlyNameForPartitionId(anomaly.partitionId),
+ dataset: anomaly.dataset,
+ datasetName: getFriendlyNameForPartitionId(anomaly.dataset),
anomalyScore: formatAnomalyScore(anomaly.anomalyScore),
- anomalyMessage: getAnomalyMessage(anomaly.actualLogEntryRate, anomaly.typicalLogEntryRate),
startTime: anomaly.startTime,
+ type: anomaly.type,
+ typical: anomaly.typical,
+ actual: anomaly.actual,
};
});
}, [results]);
const [expandedIds, { add: expandId, remove: collapseId }] = useSet(new Set());
- const expandedDatasetRowContents = useMemo(
+ const expandedIdsRowContents = useMemo(
() =>
- [...expandedIds].reduce>((aggregatedDatasetRows, id) => {
- const anomaly = results.anomalies.find((_anomaly) => _anomaly.id === id);
+ [...expandedIds].reduce>((aggregatedRows, id) => {
+ const anomaly = results.find((_anomaly) => _anomaly.id === id);
return {
- ...aggregatedDatasetRows,
+ ...aggregatedRows,
[id]: anomaly ? (
-
+
) : null,
};
}, {}),
- [expandedIds, results, timeRange, jobId]
+ [expandedIds, results, timeRange]
);
- const [sorting, setSorting] = useState({
- sort: {
- field: 'anomalyScore',
- direction: 'desc',
- },
- });
-
- const [_pagination, setPagination] = useState({
- pageIndex: 0,
- pageSize: 20,
- totalItemCount: results.anomalies.length,
- pageSizeOptions: [10, 20, 50],
- hidePerPageOptions: false,
- });
-
- const paginationOptions = useMemo(() => {
- return {
- ..._pagination,
- totalItemCount: results.anomalies.length,
- };
- }, [_pagination, results]);
-
const handleTableChange = useCallback(
- ({ page = {}, sort = {} }) => {
- const { index, size } = page;
- setPagination((currentPagination) => {
- return {
- ...currentPagination,
- pageIndex: index,
- pageSize: size,
- };
- });
- const { field, direction } = sort;
- setSorting({
- sort: {
- field,
- direction,
- },
- });
+ ({ sort = {} }) => {
+ changeSortOptions(sort);
},
- [setSorting, setPagination]
+ [changeSortOptions]
);
- const sortedTableItems = useMemo(() => {
- let sortedItems: TableItem[] = [];
- if (sorting.sort.field === 'datasetName') {
- sortedItems = tableItems.sort((a, b) => (a.datasetName > b.datasetName ? 1 : -1));
- } else if (sorting.sort.field === 'anomalyScore') {
- sortedItems = tableItems.sort((a, b) => a.anomalyScore - b.anomalyScore);
- } else if (sorting.sort.field === 'startTime') {
- sortedItems = tableItems.sort((a, b) => a.startTime - b.startTime);
- }
-
- return sorting.sort.direction === 'asc' ? sortedItems : sortedItems.reverse();
- }, [tableItems, sorting]);
-
- const pageOfItems: TableItem[] = useMemo(() => {
- const { pageIndex, pageSize } = paginationOptions;
- return sortedTableItems.slice(pageIndex * pageSize, pageIndex * pageSize + pageSize);
- }, [paginationOptions, sortedTableItems]);
-
const columns: Array> = useMemo(
() => [
{
@@ -204,10 +164,11 @@ export const AnomaliesTable: React.FunctionComponent<{
render: (anomalyScore: number) => ,
},
{
- field: 'anomalyMessage',
name: anomalyMessageColumnName,
- sortable: false,
truncateText: true,
+ render: (item: TableItem) => (
+
+ ),
},
{
field: 'startTime',
@@ -240,18 +201,116 @@ export const AnomaliesTable: React.FunctionComponent<{
],
[collapseId, expandId, expandedIds, dateFormat]
);
+ return (
+ <>
+
+
+
+
+
+ >
+ );
+};
+
+const AnomalyMessage = ({
+ actual,
+ typical,
+ type,
+}: {
+ actual: number;
+ typical: number;
+ type: AnomalyType;
+}) => {
+ const moreThanExpectedAnomalyMessage = i18n.translate(
+ 'xpack.infra.logs.analysis.anomaliesTableMoreThanExpectedAnomalyMessage',
+ {
+ defaultMessage:
+ 'more log messages in this {type, select, logRate {dataset} logCategory {category}} than expected',
+ values: { type },
+ }
+ );
+
+ const fewerThanExpectedAnomalyMessage = i18n.translate(
+ 'xpack.infra.logs.analysis.anomaliesTableFewerThanExpectedAnomalyMessage',
+ {
+ defaultMessage:
+ 'fewer log messages in this {type, select, logRate {dataset} logCategory {category}} than expected',
+ values: { type },
+ }
+ );
+
+ const isMore = actual > typical;
+ const message = isMore ? moreThanExpectedAnomalyMessage : fewerThanExpectedAnomalyMessage;
+ const ratio = isMore ? actual / typical : typical / actual;
+ const icon = isMore ? 'sortUp' : 'sortDown';
+ // Edge case scenarios where actual and typical might sit at 0.
+ const useRatio = ratio !== Infinity;
+ const ratioMessage = useRatio ? `${formatOneDecimalPlace(ratio)}x` : '';
return (
-
+
+ {`${ratioMessage} ${message}`}
+
+ );
+};
+
+const previousPageLabel = i18n.translate(
+ 'xpack.infra.logs.analysis.anomaliesTablePreviousPageLabel',
+ {
+ defaultMessage: 'Previous page',
+ }
+);
+
+const nextPageLabel = i18n.translate('xpack.infra.logs.analysis.anomaliesTableNextPageLabel', {
+ defaultMessage: 'Next page',
+});
+
+const PaginationControls = ({
+ fetchPreviousPage,
+ fetchNextPage,
+ page,
+ isLoading,
+}: {
+ fetchPreviousPage?: () => void;
+ fetchNextPage?: () => void;
+ page: number;
+ isLoading: boolean;
+}) => {
+ return (
+
+
+
+
+
+ {page}
+
+
+
+
+
);
};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/bar_chart.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/bar_chart.tsx
deleted file mode 100644
index 498a9f88176f8..0000000000000
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/bar_chart.tsx
+++ /dev/null
@@ -1,100 +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 {
- Axis,
- BarSeries,
- Chart,
- niceTimeFormatter,
- Settings,
- TooltipValue,
- BrushEndListener,
- LIGHT_THEME,
- DARK_THEME,
-} from '@elastic/charts';
-import { i18n } from '@kbn/i18n';
-import numeral from '@elastic/numeral';
-import moment from 'moment';
-import React, { useCallback, useMemo } from 'react';
-
-import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
-import { useKibanaUiSetting } from '../../../../../utils/use_kibana_ui_setting';
-
-export const LogEntryRateBarChart: React.FunctionComponent<{
- setTimeRange: (timeRange: TimeRange) => void;
- timeRange: TimeRange;
- series: Array<{ group: string; time: number; value: number }>;
-}> = ({ series, setTimeRange, timeRange }) => {
- const [dateFormat] = useKibanaUiSetting('dateFormat');
- const [isDarkMode] = useKibanaUiSetting('theme:darkMode');
-
- const chartDateFormatter = useMemo(
- () => niceTimeFormatter([timeRange.startTime, timeRange.endTime]),
- [timeRange]
- );
-
- const tooltipProps = useMemo(
- () => ({
- headerFormatter: (tooltipData: TooltipValue) =>
- moment(tooltipData.value).format(dateFormat || 'Y-MM-DD HH:mm:ss.SSS'),
- }),
- [dateFormat]
- );
-
- const handleBrushEnd = useCallback(
- ({ x }) => {
- if (!x) {
- return;
- }
- const [startTime, endTime] = x;
- setTimeRange({
- endTime,
- startTime,
- });
- },
- [setTimeRange]
- );
-
- return (
-
-
-
- numeral(value.toPrecision(3)).format('0[.][00]a')} // https://github.com/adamwdraper/Numeral-js/issues/194
- />
-
-
-
-
- );
-};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/index.tsx b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/index.tsx
deleted file mode 100644
index 3da025d90119f..0000000000000
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/sections/log_rate/index.tsx
+++ /dev/null
@@ -1,98 +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 { EuiEmptyPrompt, EuiLoadingSpinner, EuiSpacer, EuiText, EuiTitle } from '@elastic/eui';
-import { i18n } from '@kbn/i18n';
-import React, { useMemo } from 'react';
-
-import { TimeRange } from '../../../../../../common/http_api/shared/time_range';
-import { BetaBadge } from '../../../../../components/beta_badge';
-import { LoadingOverlayWrapper } from '../../../../../components/loading_overlay_wrapper';
-import { LogEntryRateResults as Results } from '../../use_log_entry_rate_results';
-import { getLogEntryRatePartitionedSeries } from '../helpers/data_formatters';
-import { LogEntryRateBarChart } from './bar_chart';
-
-export const LogRateResults = ({
- isLoading,
- results,
- setTimeRange,
- timeRange,
-}: {
- isLoading: boolean;
- results: Results | null;
- setTimeRange: (timeRange: TimeRange) => void;
- timeRange: TimeRange;
-}) => {
- const logEntryRateSeries = useMemo(
- () => (results && results.histogramBuckets ? getLogEntryRatePartitionedSeries(results) : []),
- [results]
- );
-
- return (
- <>
-
-
- {title}
-
-
- }>
- {!results || (results && results.histogramBuckets && !results.histogramBuckets.length) ? (
- <>
-
-
- {i18n.translate('xpack.infra.logs.analysis.logRateSectionNoDataTitle', {
- defaultMessage: 'There is no data to display.',
- })}
-
- }
- titleSize="m"
- body={
-
- {i18n.translate('xpack.infra.logs.analysis.logRateSectionNoDataBody', {
- defaultMessage: 'You may want to adjust your time range.',
- })}
-
- }
- />
- >
- ) : (
- <>
-
-
-
- {i18n.translate('xpack.infra.logs.analysis.logRateSectionBucketSpanLabel', {
- defaultMessage: 'Bucket span: ',
- })}
-
- {i18n.translate('xpack.infra.logs.analysis.logRateSectionBucketSpanValue', {
- defaultMessage: '15 minutes',
- })}
-
-
-
- >
- )}
-
- >
- );
-};
-
-const title = i18n.translate('xpack.infra.logs.analysis.logRateSectionTitle', {
- defaultMessage: 'Log entries',
-});
-
-const loadingAriaLabel = i18n.translate(
- 'xpack.infra.logs.analysis.logRateSectionLoadingAriaLabel',
- { defaultMessage: 'Loading log rate results' }
-);
-
-const LoadingOverlayContent = () => ;
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts
new file mode 100644
index 0000000000000..d4a0eaae43ac0
--- /dev/null
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_anomalies.ts
@@ -0,0 +1,41 @@
+/*
+ * 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 { npStart } from '../../../../legacy_singletons';
+import {
+ getLogEntryAnomaliesRequestPayloadRT,
+ getLogEntryAnomaliesSuccessReponsePayloadRT,
+ LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH,
+} from '../../../../../common/http_api/log_analysis';
+import { decodeOrThrow } from '../../../../../common/runtime_types';
+import { Sort, Pagination } from '../../../../../common/http_api/log_analysis';
+
+export const callGetLogEntryAnomaliesAPI = async (
+ sourceId: string,
+ startTime: number,
+ endTime: number,
+ sort: Sort,
+ pagination: Pagination
+) => {
+ const response = await npStart.http.fetch(LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH, {
+ method: 'POST',
+ body: JSON.stringify(
+ getLogEntryAnomaliesRequestPayloadRT.encode({
+ data: {
+ sourceId,
+ timeRange: {
+ startTime,
+ endTime,
+ },
+ sort,
+ pagination,
+ },
+ })
+ ),
+ });
+
+ return decodeOrThrow(getLogEntryAnomaliesSuccessReponsePayloadRT)(response);
+};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_rate_examples.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts
similarity index 77%
rename from x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_rate_examples.ts
rename to x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts
index d3b30da72af96..a125b53f9e635 100644
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_rate_examples.ts
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/service_calls/get_log_entry_examples.ts
@@ -10,23 +10,24 @@ import { identity } from 'fp-ts/lib/function';
import { npStart } from '../../../../legacy_singletons';
import {
- getLogEntryRateExamplesRequestPayloadRT,
- getLogEntryRateExamplesSuccessReponsePayloadRT,
+ getLogEntryExamplesRequestPayloadRT,
+ getLogEntryExamplesSuccessReponsePayloadRT,
LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH,
} from '../../../../../common/http_api/log_analysis';
import { createPlainError, throwErrors } from '../../../../../common/runtime_types';
-export const callGetLogEntryRateExamplesAPI = async (
+export const callGetLogEntryExamplesAPI = async (
sourceId: string,
startTime: number,
endTime: number,
dataset: string,
- exampleCount: number
+ exampleCount: number,
+ categoryId?: string
) => {
const response = await npStart.http.fetch(LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH, {
method: 'POST',
body: JSON.stringify(
- getLogEntryRateExamplesRequestPayloadRT.encode({
+ getLogEntryExamplesRequestPayloadRT.encode({
data: {
dataset,
exampleCount,
@@ -35,13 +36,14 @@ export const callGetLogEntryRateExamplesAPI = async (
startTime,
endTime,
},
+ categoryId,
},
})
),
});
return pipe(
- getLogEntryRateExamplesSuccessReponsePayloadRT.decode(response),
+ getLogEntryExamplesSuccessReponsePayloadRT.decode(response),
fold(throwErrors(createPlainError), identity)
);
};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts
new file mode 100644
index 0000000000000..cadb4c420c133
--- /dev/null
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_anomalies_results.ts
@@ -0,0 +1,262 @@
+/*
+ * 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 { useMemo, useState, useCallback, useEffect, useReducer } from 'react';
+
+import { LogEntryAnomaly } from '../../../../common/http_api';
+import { useTrackedPromise } from '../../../utils/use_tracked_promise';
+import { callGetLogEntryAnomaliesAPI } from './service_calls/get_log_entry_anomalies';
+import { Sort, Pagination, PaginationCursor } from '../../../../common/http_api/log_analysis';
+
+export type SortOptions = Sort;
+export type PaginationOptions = Pick;
+export type Page = number;
+export type FetchNextPage = () => void;
+export type FetchPreviousPage = () => void;
+export type ChangeSortOptions = (sortOptions: Sort) => void;
+export type ChangePaginationOptions = (paginationOptions: PaginationOptions) => void;
+export type LogEntryAnomalies = LogEntryAnomaly[];
+interface PaginationCursors {
+ previousPageCursor: PaginationCursor;
+ nextPageCursor: PaginationCursor;
+}
+
+interface ReducerState {
+ page: number;
+ lastReceivedCursors: PaginationCursors | undefined;
+ paginationCursor: Pagination['cursor'] | undefined;
+ hasNextPage: boolean;
+ paginationOptions: PaginationOptions;
+ sortOptions: Sort;
+ timeRange: {
+ start: number;
+ end: number;
+ };
+}
+
+type ReducerStateDefaults = Pick<
+ ReducerState,
+ 'page' | 'lastReceivedCursors' | 'paginationCursor' | 'hasNextPage'
+>;
+
+type ReducerAction =
+ | { type: 'changePaginationOptions'; payload: { paginationOptions: PaginationOptions } }
+ | { type: 'changeSortOptions'; payload: { sortOptions: Sort } }
+ | { type: 'fetchNextPage' }
+ | { type: 'fetchPreviousPage' }
+ | { type: 'changeHasNextPage'; payload: { hasNextPage: boolean } }
+ | { type: 'changeLastReceivedCursors'; payload: { lastReceivedCursors: PaginationCursors } }
+ | { type: 'changeTimeRange'; payload: { timeRange: { start: number; end: number } } };
+
+const stateReducer = (state: ReducerState, action: ReducerAction): ReducerState => {
+ const resetPagination = {
+ page: 1,
+ paginationCursor: undefined,
+ };
+ switch (action.type) {
+ case 'changePaginationOptions':
+ return {
+ ...state,
+ ...resetPagination,
+ ...action.payload,
+ };
+ case 'changeSortOptions':
+ return {
+ ...state,
+ ...resetPagination,
+ ...action.payload,
+ };
+ case 'changeHasNextPage':
+ return {
+ ...state,
+ ...action.payload,
+ };
+ case 'changeLastReceivedCursors':
+ return {
+ ...state,
+ ...action.payload,
+ };
+ case 'fetchNextPage':
+ return state.lastReceivedCursors
+ ? {
+ ...state,
+ page: state.page + 1,
+ paginationCursor: { searchAfter: state.lastReceivedCursors.nextPageCursor },
+ }
+ : state;
+ case 'fetchPreviousPage':
+ return state.lastReceivedCursors
+ ? {
+ ...state,
+ page: state.page - 1,
+ paginationCursor: { searchBefore: state.lastReceivedCursors.previousPageCursor },
+ }
+ : state;
+ case 'changeTimeRange':
+ return {
+ ...state,
+ ...resetPagination,
+ ...action.payload,
+ };
+ default:
+ return state;
+ }
+};
+
+const STATE_DEFAULTS: ReducerStateDefaults = {
+ // NOTE: This piece of state is purely for the client side, it could be extracted out of the hook.
+ page: 1,
+ // Cursor from the last request
+ lastReceivedCursors: undefined,
+ // Cursor to use for the next request. For the first request, and therefore not paging, this will be undefined.
+ paginationCursor: undefined,
+ hasNextPage: false,
+};
+
+export const useLogEntryAnomaliesResults = ({
+ endTime,
+ startTime,
+ sourceId,
+ defaultSortOptions,
+ defaultPaginationOptions,
+}: {
+ endTime: number;
+ startTime: number;
+ sourceId: string;
+ defaultSortOptions: Sort;
+ defaultPaginationOptions: Pick;
+}) => {
+ const initStateReducer = (stateDefaults: ReducerStateDefaults): ReducerState => {
+ return {
+ ...stateDefaults,
+ paginationOptions: defaultPaginationOptions,
+ sortOptions: defaultSortOptions,
+ timeRange: {
+ start: startTime,
+ end: endTime,
+ },
+ };
+ };
+
+ const [reducerState, dispatch] = useReducer(stateReducer, STATE_DEFAULTS, initStateReducer);
+
+ const [logEntryAnomalies, setLogEntryAnomalies] = useState([]);
+
+ const [getLogEntryAnomaliesRequest, getLogEntryAnomalies] = useTrackedPromise(
+ {
+ cancelPreviousOn: 'creation',
+ createPromise: async () => {
+ const {
+ timeRange: { start: queryStartTime, end: queryEndTime },
+ sortOptions,
+ paginationOptions,
+ paginationCursor,
+ } = reducerState;
+ return await callGetLogEntryAnomaliesAPI(
+ sourceId,
+ queryStartTime,
+ queryEndTime,
+ sortOptions,
+ {
+ ...paginationOptions,
+ cursor: paginationCursor,
+ }
+ );
+ },
+ onResolve: ({ data: { anomalies, paginationCursors: requestCursors, hasMoreEntries } }) => {
+ const { paginationCursor } = reducerState;
+ if (requestCursors) {
+ dispatch({
+ type: 'changeLastReceivedCursors',
+ payload: { lastReceivedCursors: requestCursors },
+ });
+ }
+ // Check if we have more "next" entries. "Page" covers the "previous" scenario,
+ // since we need to know the page we're on anyway.
+ if (!paginationCursor || (paginationCursor && 'searchAfter' in paginationCursor)) {
+ dispatch({ type: 'changeHasNextPage', payload: { hasNextPage: hasMoreEntries } });
+ } else if (paginationCursor && 'searchBefore' in paginationCursor) {
+ // We've requested a previous page, therefore there is a next page.
+ dispatch({ type: 'changeHasNextPage', payload: { hasNextPage: true } });
+ }
+ setLogEntryAnomalies(anomalies);
+ },
+ },
+ [
+ sourceId,
+ dispatch,
+ reducerState.timeRange,
+ reducerState.sortOptions,
+ reducerState.paginationOptions,
+ reducerState.paginationCursor,
+ ]
+ );
+
+ const changeSortOptions = useCallback(
+ (nextSortOptions: Sort) => {
+ dispatch({ type: 'changeSortOptions', payload: { sortOptions: nextSortOptions } });
+ },
+ [dispatch]
+ );
+
+ const changePaginationOptions = useCallback(
+ (nextPaginationOptions: PaginationOptions) => {
+ dispatch({
+ type: 'changePaginationOptions',
+ payload: { paginationOptions: nextPaginationOptions },
+ });
+ },
+ [dispatch]
+ );
+
+ // Time range has changed
+ useEffect(() => {
+ dispatch({
+ type: 'changeTimeRange',
+ payload: { timeRange: { start: startTime, end: endTime } },
+ });
+ }, [startTime, endTime]);
+
+ useEffect(() => {
+ getLogEntryAnomalies();
+ }, [getLogEntryAnomalies]);
+
+ const handleFetchNextPage = useCallback(() => {
+ if (reducerState.lastReceivedCursors) {
+ dispatch({ type: 'fetchNextPage' });
+ }
+ }, [dispatch, reducerState]);
+
+ const handleFetchPreviousPage = useCallback(() => {
+ if (reducerState.lastReceivedCursors) {
+ dispatch({ type: 'fetchPreviousPage' });
+ }
+ }, [dispatch, reducerState]);
+
+ const isLoadingLogEntryAnomalies = useMemo(
+ () => getLogEntryAnomaliesRequest.state === 'pending',
+ [getLogEntryAnomaliesRequest.state]
+ );
+
+ const hasFailedLoadingLogEntryAnomalies = useMemo(
+ () => getLogEntryAnomaliesRequest.state === 'rejected',
+ [getLogEntryAnomaliesRequest.state]
+ );
+
+ return {
+ logEntryAnomalies,
+ getLogEntryAnomalies,
+ isLoadingLogEntryAnomalies,
+ hasFailedLoadingLogEntryAnomalies,
+ changeSortOptions,
+ sortOptions: reducerState.sortOptions,
+ changePaginationOptions,
+ paginationOptions: reducerState.paginationOptions,
+ fetchPreviousPage: reducerState.page > 1 ? handleFetchPreviousPage : undefined,
+ fetchNextPage: reducerState.hasNextPage ? handleFetchNextPage : undefined,
+ page: reducerState.page,
+ };
+};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_examples.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_examples.ts
new file mode 100644
index 0000000000000..fae5bd200a415
--- /dev/null
+++ b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_examples.ts
@@ -0,0 +1,65 @@
+/*
+ * 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 { useMemo, useState } from 'react';
+
+import { LogEntryExample } from '../../../../common/http_api';
+import { useTrackedPromise } from '../../../utils/use_tracked_promise';
+import { callGetLogEntryExamplesAPI } from './service_calls/get_log_entry_examples';
+
+export const useLogEntryExamples = ({
+ dataset,
+ endTime,
+ exampleCount,
+ sourceId,
+ startTime,
+ categoryId,
+}: {
+ dataset: string;
+ endTime: number;
+ exampleCount: number;
+ sourceId: string;
+ startTime: number;
+ categoryId?: string;
+}) => {
+ const [logEntryExamples, setLogEntryExamples] = useState([]);
+
+ const [getLogEntryExamplesRequest, getLogEntryExamples] = useTrackedPromise(
+ {
+ cancelPreviousOn: 'creation',
+ createPromise: async () => {
+ return await callGetLogEntryExamplesAPI(
+ sourceId,
+ startTime,
+ endTime,
+ dataset,
+ exampleCount,
+ categoryId
+ );
+ },
+ onResolve: ({ data: { examples } }) => {
+ setLogEntryExamples(examples);
+ },
+ },
+ [dataset, endTime, exampleCount, sourceId, startTime]
+ );
+
+ const isLoadingLogEntryExamples = useMemo(() => getLogEntryExamplesRequest.state === 'pending', [
+ getLogEntryExamplesRequest.state,
+ ]);
+
+ const hasFailedLoadingLogEntryExamples = useMemo(
+ () => getLogEntryExamplesRequest.state === 'rejected',
+ [getLogEntryExamplesRequest.state]
+ );
+
+ return {
+ getLogEntryExamples,
+ hasFailedLoadingLogEntryExamples,
+ isLoadingLogEntryExamples,
+ logEntryExamples,
+ };
+};
diff --git a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_rate_examples.ts b/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_rate_examples.ts
deleted file mode 100644
index 12bcdb2a4b4d6..0000000000000
--- a/x-pack/plugins/infra/public/pages/logs/log_entry_rate/use_log_entry_rate_examples.ts
+++ /dev/null
@@ -1,63 +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 { useMemo, useState } from 'react';
-
-import { LogEntryRateExample } from '../../../../common/http_api';
-import { useTrackedPromise } from '../../../utils/use_tracked_promise';
-import { callGetLogEntryRateExamplesAPI } from './service_calls/get_log_entry_rate_examples';
-
-export const useLogEntryRateExamples = ({
- dataset,
- endTime,
- exampleCount,
- sourceId,
- startTime,
-}: {
- dataset: string;
- endTime: number;
- exampleCount: number;
- sourceId: string;
- startTime: number;
-}) => {
- const [logEntryRateExamples, setLogEntryRateExamples] = useState([]);
-
- const [getLogEntryRateExamplesRequest, getLogEntryRateExamples] = useTrackedPromise(
- {
- cancelPreviousOn: 'creation',
- createPromise: async () => {
- return await callGetLogEntryRateExamplesAPI(
- sourceId,
- startTime,
- endTime,
- dataset,
- exampleCount
- );
- },
- onResolve: ({ data: { examples } }) => {
- setLogEntryRateExamples(examples);
- },
- },
- [dataset, endTime, exampleCount, sourceId, startTime]
- );
-
- const isLoadingLogEntryRateExamples = useMemo(
- () => getLogEntryRateExamplesRequest.state === 'pending',
- [getLogEntryRateExamplesRequest.state]
- );
-
- const hasFailedLoadingLogEntryRateExamples = useMemo(
- () => getLogEntryRateExamplesRequest.state === 'rejected',
- [getLogEntryRateExamplesRequest.state]
- );
-
- return {
- getLogEntryRateExamples,
- hasFailedLoadingLogEntryRateExamples,
- isLoadingLogEntryRateExamples,
- logEntryRateExamples,
- };
-};
diff --git a/x-pack/plugins/infra/server/infra_server.ts b/x-pack/plugins/infra/server/infra_server.ts
index 8af37a36ef745..6596e07ebaca5 100644
--- a/x-pack/plugins/infra/server/infra_server.ts
+++ b/x-pack/plugins/infra/server/infra_server.ts
@@ -15,9 +15,10 @@ import {
initGetLogEntryCategoryDatasetsRoute,
initGetLogEntryCategoryExamplesRoute,
initGetLogEntryRateRoute,
- initGetLogEntryRateExamplesRoute,
+ initGetLogEntryExamplesRoute,
initValidateLogAnalysisDatasetsRoute,
initValidateLogAnalysisIndicesRoute,
+ initGetLogEntryAnomaliesRoute,
} from './routes/log_analysis';
import { initMetricExplorerRoute } from './routes/metrics_explorer';
import { initMetadataRoute } from './routes/metadata';
@@ -51,13 +52,14 @@ export const initInfraServer = (libs: InfraBackendLibs) => {
initGetLogEntryCategoryDatasetsRoute(libs);
initGetLogEntryCategoryExamplesRoute(libs);
initGetLogEntryRateRoute(libs);
+ initGetLogEntryAnomaliesRoute(libs);
initSnapshotRoute(libs);
initNodeDetailsRoute(libs);
initSourceRoute(libs);
initValidateLogAnalysisDatasetsRoute(libs);
initValidateLogAnalysisIndicesRoute(libs);
initLogEntriesRoute(libs);
- initGetLogEntryRateExamplesRoute(libs);
+ initGetLogEntryExamplesRoute(libs);
initLogEntriesHighlightsRoute(libs);
initLogEntriesSummaryRoute(libs);
initLogEntriesSummaryHighlightsRoute(libs);
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/common.ts b/x-pack/plugins/infra/server/lib/log_analysis/common.ts
new file mode 100644
index 0000000000000..0c0b0a0f19982
--- /dev/null
+++ b/x-pack/plugins/infra/server/lib/log_analysis/common.ts
@@ -0,0 +1,29 @@
+/*
+ * 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 type { MlAnomalyDetectors } from '../../types';
+import { startTracingSpan } from '../../../common/performance_tracing';
+import { NoLogAnalysisMlJobError } from './errors';
+
+export async function fetchMlJob(mlAnomalyDetectors: MlAnomalyDetectors, jobId: string) {
+ const finalizeMlGetJobSpan = startTracingSpan('Fetch ml job from ES');
+ const {
+ jobs: [mlJob],
+ } = await mlAnomalyDetectors.jobs(jobId);
+
+ const mlGetJobSpan = finalizeMlGetJobSpan();
+
+ if (mlJob == null) {
+ throw new NoLogAnalysisMlJobError(`Failed to find ml job ${jobId}.`);
+ }
+
+ return {
+ mlJob,
+ timing: {
+ spans: [mlGetJobSpan],
+ },
+ };
+}
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/errors.ts b/x-pack/plugins/infra/server/lib/log_analysis/errors.ts
index e07126416f4ce..09fee8844fbc5 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/errors.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/errors.ts
@@ -33,3 +33,10 @@ export class UnknownCategoryError extends Error {
Object.setPrototypeOf(this, new.target.prototype);
}
}
+
+export class InsufficientAnomalyMlJobsConfigured extends Error {
+ constructor(message?: string) {
+ super(message);
+ Object.setPrototypeOf(this, new.target.prototype);
+ }
+}
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/index.ts b/x-pack/plugins/infra/server/lib/log_analysis/index.ts
index 44c2bafce4194..c9a176be0a28f 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/index.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/index.ts
@@ -7,3 +7,4 @@
export * from './errors';
export * from './log_entry_categories_analysis';
export * from './log_entry_rate_analysis';
+export * from './log_entry_anomalies';
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts
new file mode 100644
index 0000000000000..12ae516564d66
--- /dev/null
+++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_anomalies.ts
@@ -0,0 +1,398 @@
+/*
+ * 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 { RequestHandlerContext } from 'src/core/server';
+import { InfraRequestHandlerContext } from '../../types';
+import { TracingSpan, startTracingSpan } from '../../../common/performance_tracing';
+import { fetchMlJob } from './common';
+import {
+ getJobId,
+ logEntryCategoriesJobTypes,
+ logEntryRateJobTypes,
+ jobCustomSettingsRT,
+} from '../../../common/log_analysis';
+import { Sort, Pagination } from '../../../common/http_api/log_analysis';
+import type { MlSystem } from '../../types';
+import { createLogEntryAnomaliesQuery, logEntryAnomaliesResponseRT } from './queries';
+import {
+ InsufficientAnomalyMlJobsConfigured,
+ InsufficientLogAnalysisMlJobConfigurationError,
+ UnknownCategoryError,
+} from './errors';
+import { decodeOrThrow } from '../../../common/runtime_types';
+import {
+ createLogEntryExamplesQuery,
+ logEntryExamplesResponseRT,
+} from './queries/log_entry_examples';
+import { InfraSource } from '../sources';
+import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
+import { fetchLogEntryCategories } from './log_entry_categories_analysis';
+
+interface MappedAnomalyHit {
+ id: string;
+ anomalyScore: number;
+ dataset: string;
+ typical: number;
+ actual: number;
+ jobId: string;
+ startTime: number;
+ duration: number;
+ categoryId?: string;
+}
+
+export async function getLogEntryAnomalies(
+ context: RequestHandlerContext & { infra: Required },
+ sourceId: string,
+ startTime: number,
+ endTime: number,
+ sort: Sort,
+ pagination: Pagination
+) {
+ const finalizeLogEntryAnomaliesSpan = startTracingSpan('get log entry anomalies');
+
+ const logRateJobId = getJobId(context.infra.spaceId, sourceId, logEntryRateJobTypes[0]);
+ const logCategoriesJobId = getJobId(
+ context.infra.spaceId,
+ sourceId,
+ logEntryCategoriesJobTypes[0]
+ );
+
+ const jobIds: string[] = [];
+ let jobSpans: TracingSpan[] = [];
+
+ try {
+ const {
+ timing: { spans },
+ } = await fetchMlJob(context.infra.mlAnomalyDetectors, logRateJobId);
+ jobIds.push(logRateJobId);
+ jobSpans = [...jobSpans, ...spans];
+ } catch (e) {
+ // Job wasn't found
+ }
+
+ try {
+ const {
+ timing: { spans },
+ } = await fetchMlJob(context.infra.mlAnomalyDetectors, logCategoriesJobId);
+ jobIds.push(logCategoriesJobId);
+ jobSpans = [...jobSpans, ...spans];
+ } catch (e) {
+ // Job wasn't found
+ }
+
+ if (jobIds.length === 0) {
+ throw new InsufficientAnomalyMlJobsConfigured(
+ 'Log rate or categorisation ML jobs need to be configured to search anomalies'
+ );
+ }
+
+ const {
+ anomalies,
+ paginationCursors,
+ hasMoreEntries,
+ timing: { spans: fetchLogEntryAnomaliesSpans },
+ } = await fetchLogEntryAnomalies(
+ context.infra.mlSystem,
+ jobIds,
+ startTime,
+ endTime,
+ sort,
+ pagination
+ );
+
+ const data = anomalies.map((anomaly) => {
+ const { jobId } = anomaly;
+
+ if (jobId === logRateJobId) {
+ return parseLogRateAnomalyResult(anomaly, logRateJobId);
+ } else {
+ return parseCategoryAnomalyResult(anomaly, logCategoriesJobId);
+ }
+ });
+
+ const logEntryAnomaliesSpan = finalizeLogEntryAnomaliesSpan();
+
+ return {
+ data,
+ paginationCursors,
+ hasMoreEntries,
+ timing: {
+ spans: [logEntryAnomaliesSpan, ...jobSpans, ...fetchLogEntryAnomaliesSpans],
+ },
+ };
+}
+
+const parseLogRateAnomalyResult = (anomaly: MappedAnomalyHit, jobId: string) => {
+ const {
+ id,
+ anomalyScore,
+ dataset,
+ typical,
+ actual,
+ duration,
+ startTime: anomalyStartTime,
+ } = anomaly;
+
+ return {
+ id,
+ anomalyScore,
+ dataset,
+ typical,
+ actual,
+ duration,
+ startTime: anomalyStartTime,
+ type: 'logRate' as const,
+ jobId,
+ };
+};
+
+const parseCategoryAnomalyResult = (anomaly: MappedAnomalyHit, jobId: string) => {
+ const {
+ id,
+ anomalyScore,
+ dataset,
+ typical,
+ actual,
+ duration,
+ startTime: anomalyStartTime,
+ categoryId,
+ } = anomaly;
+
+ return {
+ id,
+ anomalyScore,
+ dataset,
+ typical,
+ actual,
+ duration,
+ startTime: anomalyStartTime,
+ categoryId,
+ type: 'logCategory' as const,
+ jobId,
+ };
+};
+
+async function fetchLogEntryAnomalies(
+ mlSystem: MlSystem,
+ jobIds: string[],
+ startTime: number,
+ endTime: number,
+ sort: Sort,
+ pagination: Pagination
+) {
+ // We'll request 1 extra entry on top of our pageSize to determine if there are
+ // more entries to be fetched. This avoids scenarios where the client side can't
+ // determine if entries.length === pageSize actually means there are more entries / next page
+ // or not.
+ const expandedPagination = { ...pagination, pageSize: pagination.pageSize + 1 };
+
+ const finalizeFetchLogEntryAnomaliesSpan = startTracingSpan('fetch log entry anomalies');
+
+ const results = decodeOrThrow(logEntryAnomaliesResponseRT)(
+ await mlSystem.mlAnomalySearch(
+ createLogEntryAnomaliesQuery(jobIds, startTime, endTime, sort, expandedPagination)
+ )
+ );
+
+ const {
+ hits: { hits },
+ } = results;
+ const hasMoreEntries = hits.length > pagination.pageSize;
+
+ // An extra entry was found and hasMoreEntries has been determined, the extra entry can be removed.
+ if (hasMoreEntries) {
+ hits.pop();
+ }
+
+ // To "search_before" the sort order will have been reversed for ES.
+ // The results are now reversed back, to match the requested sort.
+ if (pagination.cursor && 'searchBefore' in pagination.cursor) {
+ hits.reverse();
+ }
+
+ const paginationCursors =
+ hits.length > 0
+ ? {
+ previousPageCursor: hits[0].sort,
+ nextPageCursor: hits[hits.length - 1].sort,
+ }
+ : undefined;
+
+ const anomalies = hits.map((result) => {
+ const {
+ job_id,
+ record_score: anomalyScore,
+ typical,
+ actual,
+ partition_field_value: dataset,
+ bucket_span: duration,
+ timestamp: anomalyStartTime,
+ by_field_value: categoryId,
+ } = result._source;
+
+ return {
+ id: result._id,
+ anomalyScore,
+ dataset,
+ typical: typical[0],
+ actual: actual[0],
+ jobId: job_id,
+ startTime: anomalyStartTime,
+ duration: duration * 1000,
+ categoryId,
+ };
+ });
+
+ const fetchLogEntryAnomaliesSpan = finalizeFetchLogEntryAnomaliesSpan();
+
+ return {
+ anomalies,
+ paginationCursors,
+ hasMoreEntries,
+ timing: {
+ spans: [fetchLogEntryAnomaliesSpan],
+ },
+ };
+}
+
+export async function getLogEntryExamples(
+ context: RequestHandlerContext & { infra: Required },
+ sourceId: string,
+ startTime: number,
+ endTime: number,
+ dataset: string,
+ exampleCount: number,
+ sourceConfiguration: InfraSource,
+ callWithRequest: KibanaFramework['callWithRequest'],
+ categoryId?: string
+) {
+ const finalizeLogEntryExamplesSpan = startTracingSpan('get log entry rate example log entries');
+
+ const jobId = getJobId(
+ context.infra.spaceId,
+ sourceId,
+ categoryId != null ? logEntryCategoriesJobTypes[0] : logEntryRateJobTypes[0]
+ );
+
+ const {
+ mlJob,
+ timing: { spans: fetchMlJobSpans },
+ } = await fetchMlJob(context.infra.mlAnomalyDetectors, jobId);
+
+ const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings);
+ const indices = customSettings?.logs_source_config?.indexPattern;
+ const timestampField = customSettings?.logs_source_config?.timestampField;
+ const tiebreakerField = sourceConfiguration.configuration.fields.tiebreaker;
+
+ if (indices == null || timestampField == null) {
+ throw new InsufficientLogAnalysisMlJobConfigurationError(
+ `Failed to find index configuration for ml job ${jobId}`
+ );
+ }
+
+ const {
+ examples,
+ timing: { spans: fetchLogEntryExamplesSpans },
+ } = await fetchLogEntryExamples(
+ context,
+ sourceId,
+ indices,
+ timestampField,
+ tiebreakerField,
+ startTime,
+ endTime,
+ dataset,
+ exampleCount,
+ callWithRequest,
+ categoryId
+ );
+
+ const logEntryExamplesSpan = finalizeLogEntryExamplesSpan();
+
+ return {
+ data: examples,
+ timing: {
+ spans: [logEntryExamplesSpan, ...fetchMlJobSpans, ...fetchLogEntryExamplesSpans],
+ },
+ };
+}
+
+export async function fetchLogEntryExamples(
+ context: RequestHandlerContext & { infra: Required },
+ sourceId: string,
+ indices: string,
+ timestampField: string,
+ tiebreakerField: string,
+ startTime: number,
+ endTime: number,
+ dataset: string,
+ exampleCount: number,
+ callWithRequest: KibanaFramework['callWithRequest'],
+ categoryId?: string
+) {
+ const finalizeEsSearchSpan = startTracingSpan('Fetch log rate examples from ES');
+
+ let categoryQuery: string | undefined;
+
+ // Examples should be further scoped to a specific ML category
+ if (categoryId) {
+ const parsedCategoryId = parseInt(categoryId, 10);
+
+ const logEntryCategoriesCountJobId = getJobId(
+ context.infra.spaceId,
+ sourceId,
+ logEntryCategoriesJobTypes[0]
+ );
+
+ const { logEntryCategoriesById } = await fetchLogEntryCategories(
+ context,
+ logEntryCategoriesCountJobId,
+ [parsedCategoryId]
+ );
+
+ const category = logEntryCategoriesById[parsedCategoryId];
+
+ if (category == null) {
+ throw new UnknownCategoryError(parsedCategoryId);
+ }
+
+ categoryQuery = category._source.terms;
+ }
+
+ const {
+ hits: { hits },
+ } = decodeOrThrow(logEntryExamplesResponseRT)(
+ await callWithRequest(
+ context,
+ 'search',
+ createLogEntryExamplesQuery(
+ indices,
+ timestampField,
+ tiebreakerField,
+ startTime,
+ endTime,
+ dataset,
+ exampleCount,
+ categoryQuery
+ )
+ )
+ );
+
+ const esSearchSpan = finalizeEsSearchSpan();
+
+ return {
+ examples: hits.map((hit) => ({
+ id: hit._id,
+ dataset: hit._source.event?.dataset ?? '',
+ message: hit._source.message ?? '',
+ timestamp: hit.sort[0],
+ tiebreaker: hit.sort[1],
+ })),
+ timing: {
+ spans: [esSearchSpan],
+ },
+ };
+}
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts
index 4f244d724405e..6d00ba56e0e66 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_categories_analysis.ts
@@ -17,7 +17,6 @@ import { decodeOrThrow } from '../../../common/runtime_types';
import type { MlAnomalyDetectors, MlSystem } from '../../types';
import {
InsufficientLogAnalysisMlJobConfigurationError,
- NoLogAnalysisMlJobError,
NoLogAnalysisResultsIndexError,
UnknownCategoryError,
} from './errors';
@@ -45,6 +44,7 @@ import {
topLogEntryCategoriesResponseRT,
} from './queries/top_log_entry_categories';
import { InfraSource } from '../sources';
+import { fetchMlJob } from './common';
const COMPOSITE_AGGREGATION_BATCH_SIZE = 1000;
@@ -213,7 +213,7 @@ export async function getLogEntryCategoryExamples(
const {
mlJob,
timing: { spans: fetchMlJobSpans },
- } = await fetchMlJob(context, logEntryCategoriesCountJobId);
+ } = await fetchMlJob(context.infra.mlAnomalyDetectors, logEntryCategoriesCountJobId);
const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings);
const indices = customSettings?.logs_source_config?.indexPattern;
@@ -330,7 +330,7 @@ async function fetchTopLogEntryCategories(
};
}
-async function fetchLogEntryCategories(
+export async function fetchLogEntryCategories(
context: { infra: { mlSystem: MlSystem } },
logEntryCategoriesCountJobId: string,
categoryIds: number[]
@@ -452,30 +452,6 @@ async function fetchTopLogEntryCategoryHistograms(
};
}
-async function fetchMlJob(
- context: { infra: { mlAnomalyDetectors: MlAnomalyDetectors } },
- logEntryCategoriesCountJobId: string
-) {
- const finalizeMlGetJobSpan = startTracingSpan('Fetch ml job from ES');
-
- const {
- jobs: [mlJob],
- } = await context.infra.mlAnomalyDetectors.jobs(logEntryCategoriesCountJobId);
-
- const mlGetJobSpan = finalizeMlGetJobSpan();
-
- if (mlJob == null) {
- throw new NoLogAnalysisMlJobError(`Failed to find ml job ${logEntryCategoriesCountJobId}.`);
- }
-
- return {
- mlJob,
- timing: {
- spans: [mlGetJobSpan],
- },
- };
-}
-
async function fetchLogEntryCategoryExamples(
requestContext: { core: { elasticsearch: { legacy: { client: ILegacyScopedClusterClient } } } },
indices: string,
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts
index 290cf03b67365..0323980dcd013 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/log_entry_rate_analysis.ts
@@ -7,7 +7,6 @@
import { pipe } from 'fp-ts/lib/pipeable';
import { map, fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
-import { RequestHandlerContext } from 'src/core/server';
import { throwErrors, createPlainError } from '../../../common/runtime_types';
import {
logRateModelPlotResponseRT,
@@ -15,22 +14,9 @@ import {
LogRateModelPlotBucket,
CompositeTimestampPartitionKey,
} from './queries';
-import { startTracingSpan } from '../../../common/performance_tracing';
-import { decodeOrThrow } from '../../../common/runtime_types';
-import { getJobId, jobCustomSettingsRT } from '../../../common/log_analysis';
-import {
- createLogEntryRateExamplesQuery,
- logEntryRateExamplesResponseRT,
-} from './queries/log_entry_rate_examples';
-import {
- InsufficientLogAnalysisMlJobConfigurationError,
- NoLogAnalysisMlJobError,
- NoLogAnalysisResultsIndexError,
-} from './errors';
-import { InfraSource } from '../sources';
+import { getJobId } from '../../../common/log_analysis';
+import { NoLogAnalysisResultsIndexError } from './errors';
import type { MlSystem } from '../../types';
-import { InfraRequestHandlerContext } from '../../types';
-import { KibanaFramework } from '../adapters/framework/kibana_framework_adapter';
const COMPOSITE_AGGREGATION_BATCH_SIZE = 1000;
@@ -143,130 +129,3 @@ export async function getLogEntryRateBuckets(
}
}, []);
}
-
-export async function getLogEntryRateExamples(
- context: RequestHandlerContext & { infra: Required },
- sourceId: string,
- startTime: number,
- endTime: number,
- dataset: string,
- exampleCount: number,
- sourceConfiguration: InfraSource,
- callWithRequest: KibanaFramework['callWithRequest']
-) {
- const finalizeLogEntryRateExamplesSpan = startTracingSpan(
- 'get log entry rate example log entries'
- );
-
- const jobId = getJobId(context.infra.spaceId, sourceId, 'log-entry-rate');
-
- const {
- mlJob,
- timing: { spans: fetchMlJobSpans },
- } = await fetchMlJob(context, jobId);
-
- const customSettings = decodeOrThrow(jobCustomSettingsRT)(mlJob.custom_settings);
- const indices = customSettings?.logs_source_config?.indexPattern;
- const timestampField = customSettings?.logs_source_config?.timestampField;
- const tiebreakerField = sourceConfiguration.configuration.fields.tiebreaker;
-
- if (indices == null || timestampField == null) {
- throw new InsufficientLogAnalysisMlJobConfigurationError(
- `Failed to find index configuration for ml job ${jobId}`
- );
- }
-
- const {
- examples,
- timing: { spans: fetchLogEntryRateExamplesSpans },
- } = await fetchLogEntryRateExamples(
- context,
- indices,
- timestampField,
- tiebreakerField,
- startTime,
- endTime,
- dataset,
- exampleCount,
- callWithRequest
- );
-
- const logEntryRateExamplesSpan = finalizeLogEntryRateExamplesSpan();
-
- return {
- data: examples,
- timing: {
- spans: [logEntryRateExamplesSpan, ...fetchMlJobSpans, ...fetchLogEntryRateExamplesSpans],
- },
- };
-}
-
-export async function fetchLogEntryRateExamples(
- context: RequestHandlerContext & { infra: Required },
- indices: string,
- timestampField: string,
- tiebreakerField: string,
- startTime: number,
- endTime: number,
- dataset: string,
- exampleCount: number,
- callWithRequest: KibanaFramework['callWithRequest']
-) {
- const finalizeEsSearchSpan = startTracingSpan('Fetch log rate examples from ES');
-
- const {
- hits: { hits },
- } = decodeOrThrow(logEntryRateExamplesResponseRT)(
- await callWithRequest(
- context,
- 'search',
- createLogEntryRateExamplesQuery(
- indices,
- timestampField,
- tiebreakerField,
- startTime,
- endTime,
- dataset,
- exampleCount
- )
- )
- );
-
- const esSearchSpan = finalizeEsSearchSpan();
-
- return {
- examples: hits.map((hit) => ({
- id: hit._id,
- dataset,
- message: hit._source.message ?? '',
- timestamp: hit.sort[0],
- tiebreaker: hit.sort[1],
- })),
- timing: {
- spans: [esSearchSpan],
- },
- };
-}
-
-async function fetchMlJob(
- context: RequestHandlerContext & { infra: Required },
- logEntryRateJobId: string
-) {
- const finalizeMlGetJobSpan = startTracingSpan('Fetch ml job from ES');
- const {
- jobs: [mlJob],
- } = await context.infra.mlAnomalyDetectors.jobs(logEntryRateJobId);
-
- const mlGetJobSpan = finalizeMlGetJobSpan();
-
- if (mlJob == null) {
- throw new NoLogAnalysisMlJobError(`Failed to find ml job ${logEntryRateJobId}.`);
- }
-
- return {
- mlJob,
- timing: {
- spans: [mlGetJobSpan],
- },
- };
-}
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/common.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/common.ts
index eacf29b303db0..87394028095de 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/queries/common.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/common.ts
@@ -21,6 +21,14 @@ export const createJobIdFilters = (jobId: string) => [
},
];
+export const createJobIdsFilters = (jobIds: string[]) => [
+ {
+ terms: {
+ job_id: jobIds,
+ },
+ },
+];
+
export const createTimeRangeFilters = (startTime: number, endTime: number) => [
{
range: {
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts
index 8c470acbf02fb..792c5bf98b538 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/index.ts
@@ -6,3 +6,4 @@
export * from './log_entry_rate';
export * from './top_log_entry_categories';
+export * from './log_entry_anomalies';
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_anomalies.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_anomalies.ts
new file mode 100644
index 0000000000000..fc72776ea5cac
--- /dev/null
+++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_anomalies.ts
@@ -0,0 +1,128 @@
+/*
+ * 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 * as rt from 'io-ts';
+import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearch_runtime_types';
+import {
+ createJobIdsFilters,
+ createTimeRangeFilters,
+ createResultTypeFilters,
+ defaultRequestParameters,
+} from './common';
+import { Sort, Pagination } from '../../../../common/http_api/log_analysis';
+
+// TODO: Reassess validity of this against ML docs
+const TIEBREAKER_FIELD = '_doc';
+
+const sortToMlFieldMap = {
+ dataset: 'partition_field_value',
+ anomalyScore: 'record_score',
+ startTime: 'timestamp',
+};
+
+export const createLogEntryAnomaliesQuery = (
+ jobIds: string[],
+ startTime: number,
+ endTime: number,
+ sort: Sort,
+ pagination: Pagination
+) => {
+ const { field } = sort;
+ const { pageSize } = pagination;
+
+ const filters = [
+ ...createJobIdsFilters(jobIds),
+ ...createTimeRangeFilters(startTime, endTime),
+ ...createResultTypeFilters(['record']),
+ ];
+
+ const sourceFields = [
+ 'job_id',
+ 'record_score',
+ 'typical',
+ 'actual',
+ 'partition_field_value',
+ 'timestamp',
+ 'bucket_span',
+ 'by_field_value',
+ ];
+
+ const { querySortDirection, queryCursor } = parsePaginationCursor(sort, pagination);
+
+ const sortOptions = [
+ { [sortToMlFieldMap[field]]: querySortDirection },
+ { [TIEBREAKER_FIELD]: querySortDirection }, // Tiebreaker
+ ];
+
+ const resultsQuery = {
+ ...defaultRequestParameters,
+ body: {
+ query: {
+ bool: {
+ filter: filters,
+ },
+ },
+ search_after: queryCursor,
+ sort: sortOptions,
+ size: pageSize,
+ _source: sourceFields,
+ },
+ };
+
+ return resultsQuery;
+};
+
+export const logEntryAnomalyHitRT = rt.type({
+ _id: rt.string,
+ _source: rt.intersection([
+ rt.type({
+ job_id: rt.string,
+ record_score: rt.number,
+ typical: rt.array(rt.number),
+ actual: rt.array(rt.number),
+ partition_field_value: rt.string,
+ bucket_span: rt.number,
+ timestamp: rt.number,
+ }),
+ rt.partial({
+ by_field_value: rt.string,
+ }),
+ ]),
+ sort: rt.tuple([rt.union([rt.string, rt.number]), rt.union([rt.string, rt.number])]),
+});
+
+export type LogEntryAnomalyHit = rt.TypeOf;
+
+export const logEntryAnomaliesResponseRT = rt.intersection([
+ commonSearchSuccessResponseFieldsRT,
+ rt.type({
+ hits: rt.type({
+ hits: rt.array(logEntryAnomalyHitRT),
+ }),
+ }),
+]);
+
+export type LogEntryAnomaliesResponseRT = rt.TypeOf;
+
+const parsePaginationCursor = (sort: Sort, pagination: Pagination) => {
+ const { cursor } = pagination;
+ const { direction } = sort;
+
+ if (!cursor) {
+ return { querySortDirection: direction, queryCursor: undefined };
+ }
+
+ // We will always use ES's search_after to paginate, to mimic "search_before" behaviour we
+ // need to reverse the user's chosen search direction for the ES query.
+ if ('searchBefore' in cursor) {
+ return {
+ querySortDirection: direction === 'desc' ? 'asc' : 'desc',
+ queryCursor: cursor.searchBefore,
+ };
+ } else {
+ return { querySortDirection: direction, queryCursor: cursor.searchAfter };
+ }
+};
diff --git a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_rate_examples.ts b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts
similarity index 59%
rename from x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_rate_examples.ts
rename to x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts
index ef06641caf797..74a664e78dcd6 100644
--- a/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_rate_examples.ts
+++ b/x-pack/plugins/infra/server/lib/log_analysis/queries/log_entry_examples.ts
@@ -10,14 +10,15 @@ import { commonSearchSuccessResponseFieldsRT } from '../../../utils/elasticsearc
import { defaultRequestParameters } from './common';
import { partitionField } from '../../../../common/log_analysis';
-export const createLogEntryRateExamplesQuery = (
+export const createLogEntryExamplesQuery = (
indices: string,
timestampField: string,
tiebreakerField: string,
startTime: number,
endTime: number,
dataset: string,
- exampleCount: number
+ exampleCount: number,
+ categoryQuery?: string
) => ({
...defaultRequestParameters,
body: {
@@ -32,11 +33,27 @@ export const createLogEntryRateExamplesQuery = (
},
},
},
- {
- term: {
- [partitionField]: dataset,
- },
- },
+ ...(!!dataset
+ ? [
+ {
+ term: {
+ [partitionField]: dataset,
+ },
+ },
+ ]
+ : []),
+ ...(categoryQuery
+ ? [
+ {
+ match: {
+ message: {
+ query: categoryQuery,
+ operator: 'AND',
+ },
+ },
+ },
+ ]
+ : []),
],
},
},
@@ -47,7 +64,7 @@ export const createLogEntryRateExamplesQuery = (
size: exampleCount,
});
-export const logEntryRateExampleHitRT = rt.type({
+export const logEntryExampleHitRT = rt.type({
_id: rt.string,
_source: rt.partial({
event: rt.partial({
@@ -58,15 +75,15 @@ export const logEntryRateExampleHitRT = rt.type({
sort: rt.tuple([rt.number, rt.number]),
});
-export type LogEntryRateExampleHit = rt.TypeOf;
+export type LogEntryExampleHit = rt.TypeOf;
-export const logEntryRateExamplesResponseRT = rt.intersection([
+export const logEntryExamplesResponseRT = rt.intersection([
commonSearchSuccessResponseFieldsRT,
rt.type({
hits: rt.type({
- hits: rt.array(logEntryRateExampleHitRT),
+ hits: rt.array(logEntryExampleHitRT),
}),
}),
]);
-export type LogEntryRateExamplesResponse = rt.TypeOf;
+export type LogEntryExamplesResponse = rt.TypeOf;
diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts
index 30b6be435837b..cbd89db97236f 100644
--- a/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts
+++ b/x-pack/plugins/infra/server/routes/log_analysis/results/index.ts
@@ -8,4 +8,5 @@ export * from './log_entry_categories';
export * from './log_entry_category_datasets';
export * from './log_entry_category_examples';
export * from './log_entry_rate';
-export * from './log_entry_rate_examples';
+export * from './log_entry_examples';
+export * from './log_entry_anomalies';
diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts
new file mode 100644
index 0000000000000..f4911658ea496
--- /dev/null
+++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_anomalies.ts
@@ -0,0 +1,112 @@
+/*
+ * 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 Boom from 'boom';
+import { InfraBackendLibs } from '../../../lib/infra_types';
+import {
+ LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH,
+ getLogEntryAnomaliesSuccessReponsePayloadRT,
+ getLogEntryAnomaliesRequestPayloadRT,
+ GetLogEntryAnomaliesRequestPayload,
+ Sort,
+ Pagination,
+} from '../../../../common/http_api/log_analysis';
+import { createValidationFunction } from '../../../../common/runtime_types';
+import { assertHasInfraMlPlugins } from '../../../utils/request_context';
+import { getLogEntryAnomalies } from '../../../lib/log_analysis';
+
+export const initGetLogEntryAnomaliesRoute = ({ framework }: InfraBackendLibs) => {
+ framework.registerRoute(
+ {
+ method: 'post',
+ path: LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH,
+ validate: {
+ body: createValidationFunction(getLogEntryAnomaliesRequestPayloadRT),
+ },
+ },
+ framework.router.handleLegacyErrors(async (requestContext, request, response) => {
+ const {
+ data: {
+ sourceId,
+ timeRange: { startTime, endTime },
+ sort: sortParam,
+ pagination: paginationParam,
+ },
+ } = request.body;
+
+ const { sort, pagination } = getSortAndPagination(sortParam, paginationParam);
+
+ try {
+ assertHasInfraMlPlugins(requestContext);
+
+ const {
+ data: logEntryAnomalies,
+ paginationCursors,
+ hasMoreEntries,
+ timing,
+ } = await getLogEntryAnomalies(
+ requestContext,
+ sourceId,
+ startTime,
+ endTime,
+ sort,
+ pagination
+ );
+
+ return response.ok({
+ body: getLogEntryAnomaliesSuccessReponsePayloadRT.encode({
+ data: {
+ anomalies: logEntryAnomalies,
+ hasMoreEntries,
+ paginationCursors,
+ },
+ timing,
+ }),
+ });
+ } catch (error) {
+ if (Boom.isBoom(error)) {
+ throw error;
+ }
+
+ return response.customError({
+ statusCode: error.statusCode ?? 500,
+ body: {
+ message: error.message ?? 'An unexpected error occurred',
+ },
+ });
+ }
+ })
+ );
+};
+
+const getSortAndPagination = (
+ sort: Partial = {},
+ pagination: Partial = {}
+): {
+ sort: Sort;
+ pagination: Pagination;
+} => {
+ const sortDefaults = {
+ field: 'anomalyScore' as const,
+ direction: 'desc' as const,
+ };
+
+ const sortWithDefaults = {
+ ...sortDefaults,
+ ...sort,
+ };
+
+ const paginationDefaults = {
+ pageSize: 50,
+ };
+
+ const paginationWithDefaults = {
+ ...paginationDefaults,
+ ...pagination,
+ };
+
+ return { sort: sortWithDefaults, pagination: paginationWithDefaults };
+};
diff --git a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_rate_examples.ts b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts
similarity index 75%
rename from x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_rate_examples.ts
rename to x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts
index b8ebcc66911dc..be4caee769506 100644
--- a/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_rate_examples.ts
+++ b/x-pack/plugins/infra/server/routes/log_analysis/results/log_entry_examples.ts
@@ -7,21 +7,21 @@
import Boom from 'boom';
import { createValidationFunction } from '../../../../common/runtime_types';
import { InfraBackendLibs } from '../../../lib/infra_types';
-import { NoLogAnalysisResultsIndexError, getLogEntryRateExamples } from '../../../lib/log_analysis';
+import { NoLogAnalysisResultsIndexError, getLogEntryExamples } from '../../../lib/log_analysis';
import { assertHasInfraMlPlugins } from '../../../utils/request_context';
import {
- getLogEntryRateExamplesRequestPayloadRT,
- getLogEntryRateExamplesSuccessReponsePayloadRT,
+ getLogEntryExamplesRequestPayloadRT,
+ getLogEntryExamplesSuccessReponsePayloadRT,
LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH,
} from '../../../../common/http_api/log_analysis';
-export const initGetLogEntryRateExamplesRoute = ({ framework, sources }: InfraBackendLibs) => {
+export const initGetLogEntryExamplesRoute = ({ framework, sources }: InfraBackendLibs) => {
framework.registerRoute(
{
method: 'post',
path: LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH,
validate: {
- body: createValidationFunction(getLogEntryRateExamplesRequestPayloadRT),
+ body: createValidationFunction(getLogEntryExamplesRequestPayloadRT),
},
},
framework.router.handleLegacyErrors(async (requestContext, request, response) => {
@@ -31,6 +31,7 @@ export const initGetLogEntryRateExamplesRoute = ({ framework, sources }: InfraBa
exampleCount,
sourceId,
timeRange: { startTime, endTime },
+ categoryId,
},
} = request.body;
@@ -42,7 +43,7 @@ export const initGetLogEntryRateExamplesRoute = ({ framework, sources }: InfraBa
try {
assertHasInfraMlPlugins(requestContext);
- const { data: logEntryRateExamples, timing } = await getLogEntryRateExamples(
+ const { data: logEntryExamples, timing } = await getLogEntryExamples(
requestContext,
sourceId,
startTime,
@@ -50,13 +51,14 @@ export const initGetLogEntryRateExamplesRoute = ({ framework, sources }: InfraBa
dataset,
exampleCount,
sourceConfiguration,
- framework.callWithRequest
+ framework.callWithRequest,
+ categoryId
);
return response.ok({
- body: getLogEntryRateExamplesSuccessReponsePayloadRT.encode({
+ body: getLogEntryExamplesSuccessReponsePayloadRT.encode({
data: {
- examples: logEntryRateExamples,
+ examples: logEntryExamples,
},
timing,
}),
diff --git a/x-pack/plugins/ingest_manager/common/mocks.ts b/x-pack/plugins/ingest_manager/common/mocks.ts
index 131917af44595..e85364f2bb672 100644
--- a/x-pack/plugins/ingest_manager/common/mocks.ts
+++ b/x-pack/plugins/ingest_manager/common/mocks.ts
@@ -6,7 +6,7 @@
import { NewPackageConfig, PackageConfig } from './types/models/package_config';
-export const createNewPackageConfigMock = () => {
+export const createNewPackageConfigMock = (): NewPackageConfig => {
return {
name: 'endpoint-1',
description: '',
@@ -20,10 +20,10 @@ export const createNewPackageConfigMock = () => {
version: '0.9.0',
},
inputs: [],
- } as NewPackageConfig;
+ };
};
-export const createPackageConfigMock = () => {
+export const createPackageConfigMock = (): PackageConfig => {
const newPackageConfig = createNewPackageConfigMock();
return {
...newPackageConfig,
@@ -37,7 +37,10 @@ export const createPackageConfigMock = () => {
inputs: [
{
config: {},
+ enabled: true,
+ type: 'endpoint',
+ streams: [],
},
],
- } as PackageConfig;
+ };
};
diff --git a/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts b/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts
index c2043a40369e2..1fb6fead454ef 100644
--- a/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts
+++ b/x-pack/plugins/ingest_manager/common/services/config_to_yaml.ts
@@ -11,8 +11,8 @@ const CONFIG_KEYS_ORDER = [
'name',
'revision',
'type',
- 'settings',
'outputs',
+ 'agent',
'inputs',
'enabled',
'use_output',
diff --git a/x-pack/plugins/ingest_manager/common/types/models/agent_config.ts b/x-pack/plugins/ingest_manager/common/types/models/agent_config.ts
index a6040742e45fc..00ba51fc1843a 100644
--- a/x-pack/plugins/ingest_manager/common/types/models/agent_config.ts
+++ b/x-pack/plugins/ingest_manager/common/types/models/agent_config.ts
@@ -62,7 +62,7 @@ export interface FullAgentConfig {
};
inputs: FullAgentConfigInput[];
revision?: number;
- settings?: {
+ agent?: {
monitoring: {
use_output?: string;
enabled: boolean;
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts
index 56b78c6faa93a..0bb09c2731032 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/agent_config.ts
@@ -48,6 +48,17 @@ export const useGetOneAgentConfigFull = (agentConfigId: string) => {
});
};
+export const sendGetOneAgentConfigFull = (
+ agentConfigId: string,
+ query: { standalone?: boolean } = {}
+) => {
+ return sendRequest({
+ path: agentConfigRouteService.getInfoFullPath(agentConfigId),
+ method: 'get',
+ query,
+ });
+};
+
export const sendGetOneAgentConfig = (agentConfigId: string) => {
return sendRequest({
path: agentConfigRouteService.getInfoPath(agentConfigId),
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts
index 10d9e03e986e1..5a334e2739027 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/hooks/use_request/enrollment_api_keys.ts
@@ -44,6 +44,18 @@ export function sendDeleteOneEnrollmentAPIKey(keyId: string, options?: RequestOp
});
}
+export function sendGetEnrollmentAPIKeys(
+ query: GetEnrollmentAPIKeysRequest['query'],
+ options?: RequestOptions
+) {
+ return sendRequest({
+ method: 'get',
+ path: enrollmentAPIKeyRouteService.getListPath(),
+ query,
+ ...options,
+ });
+}
+
export function useGetEnrollmentAPIKeys(
query: GetEnrollmentAPIKeysRequest['query'],
options?: RequestOptions
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx
index e0f40f1b15375..7ccb59f0e741e 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/layout.tsx
@@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React from 'react';
+import React, { memo, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiFlexGroup,
@@ -27,130 +27,148 @@ export const CreatePackageConfigPageLayout: React.FunctionComponent<{
agentConfig?: AgentConfig;
packageInfo?: PackageInfo;
'data-test-subj'?: string;
-}> = ({
- from,
- cancelUrl,
- onCancel,
- agentConfig,
- packageInfo,
- children,
- 'data-test-subj': dataTestSubj,
-}) => {
- const leftColumn = (
-
-
- {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
-
-
-
-
-
+}> = memo(
+ ({
+ from,
+ cancelUrl,
+ onCancel,
+ agentConfig,
+ packageInfo,
+ children,
+ 'data-test-subj': dataTestSubj,
+ }) => {
+ const pageTitle = useMemo(() => {
+ if ((from === 'package' || from === 'edit') && packageInfo) {
+ return (
+
+
+
+
+
+
+
+ {from === 'edit' ? (
+
+ ) : (
+
+ )}
+
+
+
+
+ );
+ }
+
+ return from === 'edit' ? (
- {from === 'edit' ? (
-
- ) : (
-
- )}
+
-
-
-
-
- {from === 'edit' ? (
+ ) : (
+
+
- ) : from === 'config' ? (
+
+
+ );
+ }, [from, packageInfo]);
+
+ const pageDescription = useMemo(() => {
+ return from === 'edit' ? (
+
+ ) : from === 'config' ? (
+
+ ) : (
+
+ );
+ }, [from]);
+
+ const leftColumn = (
+
+
+ {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
+
- ) : (
+
+
+ {pageTitle}
+
+
+
+ {pageDescription}
+
+
+
+ );
+
+ const rightColumn =
+ agentConfig && (from === 'config' || from === 'edit') ? (
+
+
- )}
-
-
-
- );
- const rightColumn = (
-
-
-
- {agentConfig && (from === 'config' || from === 'edit') ? (
-
-
-
-
-
- {agentConfig?.name || '-'}
-
-
- ) : null}
- {packageInfo && from === 'package' ? (
-
-
-
-
-
-
-
-
-
-
- {packageInfo?.title || packageInfo?.name || '-'}
-
-
-
-
- ) : null}
-
-
- );
+
+ {agentConfig?.name || '-'}
+
+ ) : undefined;
- const maxWidth = 770;
- return (
-
- {children}
-
- );
-};
+ const maxWidth = 770;
+ return (
+
+ {children}
+
+ );
+ }
+);
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx
index 85c0f2134d8dc..98f04dbd92659 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_config.tsx
@@ -3,17 +3,15 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState, Fragment } from 'react';
+import React, { useState, Fragment, memo, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
+ EuiFlexGrid,
EuiFlexGroup,
EuiFlexItem,
EuiText,
- EuiTextColor,
EuiSpacer,
EuiButtonEmpty,
- EuiTitle,
- EuiIconTip,
} from '@elastic/eui';
import { PackageConfigInput, RegistryVarsEntry } from '../../../../types';
import {
@@ -29,150 +27,157 @@ export const PackageConfigInputConfig: React.FunctionComponent<{
updatePackageConfigInput: (updatedInput: Partial) => void;
inputVarsValidationResults: PackageConfigConfigValidationResults;
forceShowErrors?: boolean;
-}> = ({
- packageInputVars,
- packageConfigInput,
- updatePackageConfigInput,
- inputVarsValidationResults,
- forceShowErrors,
-}) => {
- // Showing advanced options toggle state
- const [isShowingAdvanced, setIsShowingAdvanced] = useState(false);
+}> = memo(
+ ({
+ packageInputVars,
+ packageConfigInput,
+ updatePackageConfigInput,
+ inputVarsValidationResults,
+ forceShowErrors,
+ }) => {
+ // Showing advanced options toggle state
+ const [isShowingAdvanced, setIsShowingAdvanced] = useState(false);
- // Errors state
- const hasErrors = forceShowErrors && validationHasErrors(inputVarsValidationResults);
+ // Errors state
+ const hasErrors = forceShowErrors && validationHasErrors(inputVarsValidationResults);
- const requiredVars: RegistryVarsEntry[] = [];
- const advancedVars: RegistryVarsEntry[] = [];
+ const requiredVars: RegistryVarsEntry[] = [];
+ const advancedVars: RegistryVarsEntry[] = [];
- if (packageInputVars) {
- packageInputVars.forEach((varDef) => {
- if (isAdvancedVar(varDef)) {
- advancedVars.push(varDef);
- } else {
- requiredVars.push(varDef);
- }
- });
- }
+ if (packageInputVars) {
+ packageInputVars.forEach((varDef) => {
+ if (isAdvancedVar(varDef)) {
+ advancedVars.push(varDef);
+ } else {
+ requiredVars.push(varDef);
+ }
+ });
+ }
+
+ const advancedVarsWithErrorsCount: number = useMemo(
+ () =>
+ advancedVars.filter(
+ ({ name: varName }) => inputVarsValidationResults.vars?.[varName]?.length
+ ).length,
+ [advancedVars, inputVarsValidationResults.vars]
+ );
- return (
-
-
-
-
-
-
-
+ return (
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
- {hasErrors ? (
-
-
- }
- position="right"
- type="alert"
- iconProps={{ color: 'danger' }}
- />
-
- ) : null}
-
-
-
-
-
-
-
-
-
-
- {requiredVars.map((varDef) => {
- const { name: varName, type: varType } = varDef;
- const value = packageConfigInput.vars![varName].value;
- return (
-
- {
- updatePackageConfigInput({
- vars: {
- ...packageConfigInput.vars,
- [varName]: {
- type: varType,
- value: newValue,
+
+
+
+ {requiredVars.map((varDef) => {
+ const { name: varName, type: varType } = varDef;
+ const value = packageConfigInput.vars![varName].value;
+ return (
+
+ {
+ updatePackageConfigInput({
+ vars: {
+ ...packageConfigInput.vars,
+ [varName]: {
+ type: varType,
+ value: newValue,
+ },
},
- },
- });
- }}
- errors={inputVarsValidationResults.vars![varName]}
- forceShowErrors={forceShowErrors}
- />
-
- );
- })}
- {advancedVars.length ? (
-
-
- {/* Wrapper div to prevent button from going full width */}
-
- setIsShowingAdvanced(!isShowingAdvanced)}
- flush="left"
- >
-
-
-
-
- {isShowingAdvanced
- ? advancedVars.map((varDef) => {
- const { name: varName, type: varType } = varDef;
- const value = packageConfigInput.vars![varName].value;
- return (
-
- {
- updatePackageConfigInput({
- vars: {
- ...packageConfigInput.vars,
- [varName]: {
- type: varType,
- value: newValue,
- },
- },
- });
- }}
- errors={inputVarsValidationResults.vars![varName]}
- forceShowErrors={forceShowErrors}
+ });
+ }}
+ errors={inputVarsValidationResults.vars![varName]}
+ forceShowErrors={forceShowErrors}
+ />
+
+ );
+ })}
+ {advancedVars.length ? (
+
+
+ {/* Wrapper div to prevent button from going full width */}
+
+
+ setIsShowingAdvanced(!isShowingAdvanced)}
+ flush="left"
+ >
+
+
+
+ {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? (
+
+
+
+
- );
- })
- : null}
-
- ) : null}
-
-
-
- );
-};
+ ) : null}
+
+
+ {isShowingAdvanced
+ ? advancedVars.map((varDef) => {
+ const { name: varName, type: varType } = varDef;
+ const value = packageConfigInput.vars![varName].value;
+ return (
+
+ {
+ updatePackageConfigInput({
+ vars: {
+ ...packageConfigInput.vars,
+ [varName]: {
+ type: varType,
+ value: newValue,
+ },
+ },
+ });
+ }}
+ errors={inputVarsValidationResults.vars![varName]}
+ forceShowErrors={forceShowErrors}
+ />
+
+ );
+ })
+ : null}
+
+ ) : null}
+
+
+
+ );
+ }
+);
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx
index f9c9dcd469b25..af26afdbf74d7 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_panel.tsx
@@ -3,21 +3,18 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState, Fragment } from 'react';
+import React, { useState, Fragment, memo } from 'react';
import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import {
- EuiPanel,
EuiFlexGroup,
EuiFlexItem,
EuiSwitch,
EuiText,
- EuiTextColor,
EuiButtonIcon,
EuiHorizontalRule,
EuiSpacer,
- EuiIconTip,
} from '@elastic/eui';
import {
PackageConfigInput,
@@ -25,16 +22,44 @@ import {
RegistryInput,
RegistryStream,
} from '../../../../types';
-import { PackageConfigInputValidationResults, validationHasErrors } from '../services';
+import {
+ PackageConfigInputValidationResults,
+ hasInvalidButRequiredVar,
+ countValidationErrors,
+} from '../services';
import { PackageConfigInputConfig } from './package_config_input_config';
import { PackageConfigInputStreamConfig } from './package_config_input_stream';
-const FlushHorizontalRule = styled(EuiHorizontalRule)`
- margin-left: -${(props) => props.theme.eui.paddingSizes.m};
- margin-right: -${(props) => props.theme.eui.paddingSizes.m};
- width: auto;
+const ShortenedHorizontalRule = styled(EuiHorizontalRule)`
+ &&& {
+ width: ${(11 / 12) * 100}%;
+ margin-left: auto;
+ }
`;
+const shouldShowStreamsByDefault = (
+ packageInput: RegistryInput,
+ packageInputStreams: Array,
+ packageConfigInput: PackageConfigInput
+): boolean => {
+ return (
+ packageConfigInput.enabled &&
+ (hasInvalidButRequiredVar(packageInput.vars, packageConfigInput.vars) ||
+ Boolean(
+ packageInputStreams.find(
+ (stream) =>
+ stream.enabled &&
+ hasInvalidButRequiredVar(
+ stream.vars,
+ packageConfigInput.streams.find(
+ (pkgStream) => stream.dataset.name === pkgStream.dataset.name
+ )?.vars
+ )
+ )
+ ))
+ );
+};
+
export const PackageConfigInputPanel: React.FunctionComponent<{
packageInput: RegistryInput;
packageInputStreams: Array;
@@ -42,148 +67,136 @@ export const PackageConfigInputPanel: React.FunctionComponent<{
updatePackageConfigInput: (updatedInput: Partial) => void;
inputValidationResults: PackageConfigInputValidationResults;
forceShowErrors?: boolean;
-}> = ({
- packageInput,
- packageInputStreams,
- packageConfigInput,
- updatePackageConfigInput,
- inputValidationResults,
- forceShowErrors,
-}) => {
- // Showing streams toggle state
- const [isShowingStreams, setIsShowingStreams] = useState(false);
+}> = memo(
+ ({
+ packageInput,
+ packageInputStreams,
+ packageConfigInput,
+ updatePackageConfigInput,
+ inputValidationResults,
+ forceShowErrors,
+ }) => {
+ // Showing streams toggle state
+ const [isShowingStreams, setIsShowingStreams] = useState(
+ shouldShowStreamsByDefault(packageInput, packageInputStreams, packageConfigInput)
+ );
- // Errors state
- const hasErrors = forceShowErrors && validationHasErrors(inputValidationResults);
+ // Errors state
+ const errorCount = countValidationErrors(inputValidationResults);
+ const hasErrors = forceShowErrors && errorCount;
- return (
-
- {/* Header / input-level toggle */}
-
-
-
-
-
-
-
- {packageInput.title || packageInput.type}
-
-
-
-
- {hasErrors ? (
+ const inputStreams = packageInputStreams
+ .map((packageInputStream) => {
+ return {
+ packageInputStream,
+ packageConfigInputStream: packageConfigInput.streams.find(
+ (stream) => stream.dataset.name === packageInputStream.dataset.name
+ ),
+ };
+ })
+ .filter((stream) => Boolean(stream.packageConfigInputStream));
+
+ return (
+ <>
+ {/* Header / input-level toggle */}
+
+
+
-
- }
- position="right"
- type="alert"
- iconProps={{ color: 'danger' }}
- />
+
+ {packageInput.title || packageInput.type}
+
- ) : null}
-
- }
- checked={packageConfigInput.enabled}
- onChange={(e) => {
- const enabled = e.target.checked;
- updatePackageConfigInput({
- enabled,
- streams: packageConfigInput.streams.map((stream) => ({
- ...stream,
+
+ }
+ checked={packageConfigInput.enabled}
+ onChange={(e) => {
+ const enabled = e.target.checked;
+ updatePackageConfigInput({
enabled,
- })),
- });
- }}
- />
-
-
-
-
-
-
-
- {packageConfigInput.streams.filter((stream) => stream.enabled).length}
-
-
- ),
- total: packageInputStreams.length,
- }}
- />
-
-
-
- setIsShowingStreams(!isShowingStreams)}
- color="text"
- aria-label={
- isShowingStreams
- ? i18n.translate(
- 'xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel',
- {
- defaultMessage: 'Hide {type} streams',
- values: {
- type: packageInput.type,
- },
- }
- )
- : i18n.translate(
- 'xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel',
- {
- defaultMessage: 'Show {type} streams',
- values: {
- type: packageInput.type,
- },
- }
- )
+ streams: packageConfigInput.streams.map((stream) => ({
+ ...stream,
+ enabled,
+ })),
+ });
+ if (!enabled && isShowingStreams) {
+ setIsShowingStreams(false);
}
- />
-
-
-
-
+ }}
+ />
+
+
+
+ {hasErrors ? (
+
+
+
+
+
+ ) : null}
+
+ setIsShowingStreams(!isShowingStreams)}
+ color={hasErrors ? 'danger' : 'text'}
+ aria-label={
+ isShowingStreams
+ ? i18n.translate(
+ 'xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel',
+ {
+ defaultMessage: 'Hide {type} inputs',
+ values: {
+ type: packageInput.type,
+ },
+ }
+ )
+ : i18n.translate(
+ 'xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel',
+ {
+ defaultMessage: 'Show {type} inputs',
+ values: {
+ type: packageInput.type,
+ },
+ }
+ )
+ }
+ />
+
+
+
+
- {/* Header rule break */}
- {isShowingStreams ? : null}
+ {/* Header rule break */}
+ {isShowingStreams ? : null}
- {/* Input level configuration */}
- {isShowingStreams && packageInput.vars && packageInput.vars.length ? (
-
-
-
-
- ) : null}
+ {/* Input level configuration */}
+ {isShowingStreams && packageInput.vars && packageInput.vars.length ? (
+
+
+
+
+ ) : null}
- {/* Per-stream configuration */}
- {isShowingStreams ? (
-
- {packageInputStreams.map((packageInputStream) => {
- const packageConfigInputStream = packageConfigInput.streams.find(
- (stream) => stream.dataset.name === packageInputStream.dataset.name
- );
- return packageConfigInputStream ? (
-
+ {/* Per-stream configuration */}
+ {isShowingStreams ? (
+
+ {inputStreams.map(({ packageInputStream, packageConfigInputStream }, index) => (
+
) => {
@@ -213,17 +226,21 @@ export const PackageConfigInputPanel: React.FunctionComponent<{
updatePackageConfigInput(updatedInput);
}}
inputStreamValidationResults={
- inputValidationResults.streams![packageConfigInputStream.id]
+ inputValidationResults.streams![packageConfigInputStream!.id]
}
forceShowErrors={forceShowErrors}
/>
-
-
+ {index !== inputStreams.length - 1 ? (
+ <>
+
+
+ >
+ ) : null}
- ) : null;
- })}
-
- ) : null}
-
- );
-};
+ ))}
+
+ ) : null}
+ >
+ );
+ }
+);
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx
index 52a4748fe14c7..11a9df276485b 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_stream.tsx
@@ -3,18 +3,17 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState, Fragment } from 'react';
+import React, { useState, Fragment, memo, useMemo } from 'react';
import ReactMarkdown from 'react-markdown';
import { FormattedMessage } from '@kbn/i18n/react';
import {
+ EuiFlexGrid,
EuiFlexGroup,
EuiFlexItem,
EuiSwitch,
EuiText,
EuiSpacer,
EuiButtonEmpty,
- EuiTextColor,
- EuiIconTip,
} from '@elastic/eui';
import { PackageConfigInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types';
import {
@@ -30,153 +29,157 @@ export const PackageConfigInputStreamConfig: React.FunctionComponent<{
updatePackageConfigInputStream: (updatedStream: Partial) => void;
inputStreamValidationResults: PackageConfigConfigValidationResults;
forceShowErrors?: boolean;
-}> = ({
- packageInputStream,
- packageConfigInputStream,
- updatePackageConfigInputStream,
- inputStreamValidationResults,
- forceShowErrors,
-}) => {
- // Showing advanced options toggle state
- const [isShowingAdvanced, setIsShowingAdvanced] = useState(false);
+}> = memo(
+ ({
+ packageInputStream,
+ packageConfigInputStream,
+ updatePackageConfigInputStream,
+ inputStreamValidationResults,
+ forceShowErrors,
+ }) => {
+ // Showing advanced options toggle state
+ const [isShowingAdvanced, setIsShowingAdvanced] = useState();
- // Errors state
- const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults);
+ // Errors state
+ const hasErrors = forceShowErrors && validationHasErrors(inputStreamValidationResults);
- const requiredVars: RegistryVarsEntry[] = [];
- const advancedVars: RegistryVarsEntry[] = [];
+ const requiredVars: RegistryVarsEntry[] = [];
+ const advancedVars: RegistryVarsEntry[] = [];
- if (packageInputStream.vars && packageInputStream.vars.length) {
- packageInputStream.vars.forEach((varDef) => {
- if (isAdvancedVar(varDef)) {
- advancedVars.push(varDef);
- } else {
- requiredVars.push(varDef);
- }
- });
- }
+ if (packageInputStream.vars && packageInputStream.vars.length) {
+ packageInputStream.vars.forEach((varDef) => {
+ if (isAdvancedVar(varDef)) {
+ advancedVars.push(varDef);
+ } else {
+ requiredVars.push(varDef);
+ }
+ });
+ }
- return (
-
-
-
-
-
- {packageInputStream.title}
-
-
- {hasErrors ? (
-
-
- }
- position="right"
- type="alert"
- iconProps={{ color: 'danger' }}
- />
-
+ const advancedVarsWithErrorsCount: number = useMemo(
+ () =>
+ advancedVars.filter(
+ ({ name: varName }) => inputStreamValidationResults.vars?.[varName]?.length
+ ).length,
+ [advancedVars, inputStreamValidationResults.vars]
+ );
+
+ return (
+
+
+
+
+
+ {
+ const enabled = e.target.checked;
+ updatePackageConfigInputStream({
+ enabled,
+ });
+ }}
+ />
+ {packageInputStream.description ? (
+
+
+
+
+
+
) : null}
-
- }
- checked={packageConfigInputStream.enabled}
- onChange={(e) => {
- const enabled = e.target.checked;
- updatePackageConfigInputStream({
- enabled,
- });
- }}
- />
- {packageInputStream.description ? (
-
-
-
-
-
-
- ) : null}
-
-
-
- {requiredVars.map((varDef) => {
- const { name: varName, type: varType } = varDef;
- const value = packageConfigInputStream.vars![varName].value;
- return (
-
- {
- updatePackageConfigInputStream({
- vars: {
- ...packageConfigInputStream.vars,
- [varName]: {
- type: varType,
- value: newValue,
+
+
+
+
+
+ {requiredVars.map((varDef) => {
+ const { name: varName, type: varType } = varDef;
+ const value = packageConfigInputStream.vars![varName].value;
+ return (
+
+ {
+ updatePackageConfigInputStream({
+ vars: {
+ ...packageConfigInputStream.vars,
+ [varName]: {
+ type: varType,
+ value: newValue,
+ },
},
- },
- });
- }}
- errors={inputStreamValidationResults.vars![varName]}
- forceShowErrors={forceShowErrors}
- />
-
- );
- })}
- {advancedVars.length ? (
-
-
- {/* Wrapper div to prevent button from going full width */}
-
- setIsShowingAdvanced(!isShowingAdvanced)}
- flush="left"
- >
-
-
-
-
- {isShowingAdvanced
- ? advancedVars.map((varDef) => {
- const { name: varName, type: varType } = varDef;
- const value = packageConfigInputStream.vars![varName].value;
- return (
-
- {
- updatePackageConfigInputStream({
- vars: {
- ...packageConfigInputStream.vars,
- [varName]: {
- type: varType,
- value: newValue,
- },
- },
- });
- }}
- errors={inputStreamValidationResults.vars![varName]}
- forceShowErrors={forceShowErrors}
+ });
+ }}
+ errors={inputStreamValidationResults.vars![varName]}
+ forceShowErrors={forceShowErrors}
+ />
+
+ );
+ })}
+ {advancedVars.length ? (
+
+
+
+
+ setIsShowingAdvanced(!isShowingAdvanced)}
+ flush="left"
+ >
+
+
+
+ {!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? (
+
+
+
+
- );
- })
- : null}
-
- ) : null}
-
-
-
- );
-};
+ ) : null}
+
+
+ {isShowingAdvanced
+ ? advancedVars.map((varDef) => {
+ const { name: varName, type: varType } = varDef;
+ const value = packageConfigInputStream.vars![varName].value;
+ return (
+
+ {
+ updatePackageConfigInputStream({
+ vars: {
+ ...packageConfigInputStream.vars,
+ [varName]: {
+ type: varType,
+ value: newValue,
+ },
+ },
+ });
+ }}
+ errors={inputStreamValidationResults.vars![varName]}
+ forceShowErrors={forceShowErrors}
+ />
+
+ );
+ })
+ : null}
+
+ ) : null}
+
+
+
+ );
+ }
+);
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx
index 8868e00ecc1f1..eb681096a080e 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/components/package_config_input_var_field.tsx
@@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState } from 'react';
+import React, { useState, memo, useMemo } from 'react';
import ReactMarkdown from 'react-markdown';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFormRow, EuiFieldText, EuiComboBox, EuiText, EuiCodeEditor } from '@elastic/eui';
@@ -18,13 +18,13 @@ export const PackageConfigInputVarField: React.FunctionComponent<{
onChange: (newValue: any) => void;
errors?: string[] | null;
forceShowErrors?: boolean;
-}> = ({ varDef, value, onChange, errors: varErrors, forceShowErrors }) => {
+}> = memo(({ varDef, value, onChange, errors: varErrors, forceShowErrors }) => {
const [isDirty, setIsDirty] = useState(false);
const { multi, required, type, title, name, description } = varDef;
const isInvalid = (isDirty || forceShowErrors) && !!varErrors;
const errors = isInvalid ? varErrors : null;
- const renderField = () => {
+ const field = useMemo(() => {
if (multi) {
return (
setIsDirty(true)}
/>
);
- };
+ }, [isInvalid, multi, onChange, type, value]);
return (
}
>
- {renderField()}
+ {field}
);
-};
+});
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx
index b446e6bf97e7b..74cbcdca512db 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/index.tsx
@@ -5,6 +5,7 @@
*/
import React, { useState, useEffect, useMemo, useCallback, ReactEventHandler } from 'react';
import { useRouteMatch, useHistory } from 'react-router-dom';
+import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import {
@@ -31,6 +32,7 @@ import {
useConfig,
sendGetAgentStatus,
} from '../../../hooks';
+import { Loading } from '../../../components';
import { ConfirmDeployConfigModal } from '../components';
import { CreatePackageConfigPageLayout } from './components';
import { CreatePackageConfigFrom, PackageConfigFormState } from './types';
@@ -45,6 +47,12 @@ import { StepConfigurePackage } from './step_configure_package';
import { StepDefinePackageConfig } from './step_define_package_config';
import { useIntraAppState } from '../../../hooks/use_intra_app_state';
+const StepsWithLessPadding = styled(EuiSteps)`
+ .euiStep__content {
+ padding-bottom: ${(props) => props.theme.eui.paddingSizes.m};
+ }
+`;
+
export const CreatePackageConfigPage: React.FunctionComponent = () => {
const {
notifications,
@@ -75,6 +83,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
// Agent config and package info states
const [agentConfig, setAgentConfig] = useState();
const [packageInfo, setPackageInfo] = useState();
+ const [isLoadingSecondStep, setIsLoadingSecondStep] = useState(false);
const agentConfigId = agentConfig?.id;
// Retrieve agent count
@@ -151,40 +160,47 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
const hasErrors = validationResults ? validationHasErrors(validationResults) : false;
+ // Update package config validation
+ const updatePackageConfigValidation = useCallback(
+ (newPackageConfig?: NewPackageConfig) => {
+ if (packageInfo) {
+ const newValidationResult = validatePackageConfig(
+ newPackageConfig || packageConfig,
+ packageInfo
+ );
+ setValidationResults(newValidationResult);
+ // eslint-disable-next-line no-console
+ console.debug('Package config validation results', newValidationResult);
+
+ return newValidationResult;
+ }
+ },
+ [packageConfig, packageInfo]
+ );
+
// Update package config method
- const updatePackageConfig = (updatedFields: Partial) => {
- const newPackageConfig = {
- ...packageConfig,
- ...updatedFields,
- };
- setPackageConfig(newPackageConfig);
-
- // eslint-disable-next-line no-console
- console.debug('Package config updated', newPackageConfig);
- const newValidationResults = updatePackageConfigValidation(newPackageConfig);
- const hasPackage = newPackageConfig.package;
- const hasValidationErrors = newValidationResults
- ? validationHasErrors(newValidationResults)
- : false;
- const hasAgentConfig = newPackageConfig.config_id && newPackageConfig.config_id !== '';
- if (hasPackage && hasAgentConfig && !hasValidationErrors) {
- setFormState('VALID');
- }
- };
+ const updatePackageConfig = useCallback(
+ (updatedFields: Partial) => {
+ const newPackageConfig = {
+ ...packageConfig,
+ ...updatedFields,
+ };
+ setPackageConfig(newPackageConfig);
- const updatePackageConfigValidation = (newPackageConfig?: NewPackageConfig) => {
- if (packageInfo) {
- const newValidationResult = validatePackageConfig(
- newPackageConfig || packageConfig,
- packageInfo
- );
- setValidationResults(newValidationResult);
// eslint-disable-next-line no-console
- console.debug('Package config validation results', newValidationResult);
-
- return newValidationResult;
- }
- };
+ console.debug('Package config updated', newPackageConfig);
+ const newValidationResults = updatePackageConfigValidation(newPackageConfig);
+ const hasPackage = newPackageConfig.package;
+ const hasValidationErrors = newValidationResults
+ ? validationHasErrors(newValidationResults)
+ : false;
+ const hasAgentConfig = newPackageConfig.config_id && newPackageConfig.config_id !== '';
+ if (hasPackage && hasAgentConfig && !hasValidationErrors) {
+ setFormState('VALID');
+ }
+ },
+ [packageConfig, updatePackageConfigValidation]
+ );
// Cancel path
const cancelUrl = useMemo(() => {
@@ -276,6 +292,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
updatePackageInfo={updatePackageInfo}
agentConfig={agentConfig}
updateAgentConfig={updateAgentConfig}
+ setIsLoadingSecondStep={setIsLoadingSecondStep}
/>
),
[pkgkey, updatePackageInfo, agentConfig, updateAgentConfig]
@@ -288,11 +305,47 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
updateAgentConfig={updateAgentConfig}
packageInfo={packageInfo}
updatePackageInfo={updatePackageInfo}
+ setIsLoadingSecondStep={setIsLoadingSecondStep}
/>
),
[configId, updateAgentConfig, packageInfo, updatePackageInfo]
);
+ const stepConfigurePackage = useMemo(
+ () =>
+ isLoadingSecondStep ? (
+
+ ) : agentConfig && packageInfo ? (
+ <>
+
+
+ >
+ ) : (
+
+ ),
+ [
+ agentConfig,
+ formState,
+ isLoadingSecondStep,
+ packageConfig,
+ packageInfo,
+ updatePackageConfig,
+ validationResults,
+ ]
+ );
+
const steps: EuiStepProps[] = [
from === 'package'
? {
@@ -310,44 +363,16 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
}),
children: stepSelectPackage,
},
- {
- title: i18n.translate(
- 'xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle',
- {
- defaultMessage: 'Configure integration',
- }
- ),
- status: !packageInfo || !agentConfig ? 'disabled' : undefined,
- children:
- agentConfig && packageInfo ? (
-
- ) : null,
- },
{
title: i18n.translate(
'xpack.ingestManager.createPackageConfig.stepConfigurePackageConfigTitle',
{
- defaultMessage: 'Select the data you want to collect',
+ defaultMessage: 'Configure integration',
}
),
- status: !packageInfo || !agentConfig ? 'disabled' : undefined,
+ status: !packageInfo || !agentConfig || isLoadingSecondStep ? 'disabled' : undefined,
'data-test-subj': 'dataCollectionSetupStep',
- children:
- agentConfig && packageInfo ? (
-
- ) : null,
+ children: stepConfigurePackage,
},
];
@@ -371,7 +396,7 @@ export const CreatePackageConfigPage: React.FunctionComponent = () => {
: agentConfig && (
)}
-
+
{/* TODO #64541 - Remove classes */}
{
: undefined
}
>
-
+
- {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
-
+ {!isLoadingSecondStep && agentConfig && packageInfo && formState === 'INVALID' ? (
-
+ ) : null}
-
-
-
+
+
+ {/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
+
+
+
+
+
+
+
+
+
+
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts
new file mode 100644
index 0000000000000..679ae4b1456d6
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts
@@ -0,0 +1,94 @@
+/*
+ * 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 { hasInvalidButRequiredVar } from './has_invalid_but_required_var';
+
+describe('Ingest Manager - hasInvalidButRequiredVar', () => {
+ it('returns true for invalid & required vars', () => {
+ expect(
+ hasInvalidButRequiredVar(
+ [
+ {
+ name: 'mock_var',
+ type: 'text',
+ required: true,
+ },
+ ],
+ {}
+ )
+ ).toBe(true);
+
+ expect(
+ hasInvalidButRequiredVar(
+ [
+ {
+ name: 'mock_var',
+ type: 'text',
+ required: true,
+ },
+ ],
+ {
+ mock_var: {
+ value: undefined,
+ },
+ }
+ )
+ ).toBe(true);
+ });
+
+ it('returns false for valid & required vars', () => {
+ expect(
+ hasInvalidButRequiredVar(
+ [
+ {
+ name: 'mock_var',
+ type: 'text',
+ required: true,
+ },
+ ],
+ {
+ mock_var: {
+ value: 'foo',
+ },
+ }
+ )
+ ).toBe(false);
+ });
+
+ it('returns false for optional vars', () => {
+ expect(
+ hasInvalidButRequiredVar(
+ [
+ {
+ name: 'mock_var',
+ type: 'text',
+ },
+ ],
+ {
+ mock_var: {
+ value: 'foo',
+ },
+ }
+ )
+ ).toBe(false);
+
+ expect(
+ hasInvalidButRequiredVar(
+ [
+ {
+ name: 'mock_var',
+ type: 'text',
+ required: false,
+ },
+ ],
+ {
+ mock_var: {
+ value: undefined,
+ },
+ }
+ )
+ ).toBe(false);
+ });
+});
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts
new file mode 100644
index 0000000000000..f632d40a05621
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts
@@ -0,0 +1,26 @@
+/*
+ * 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 { PackageConfigConfigRecord, RegistryVarsEntry } from '../../../../types';
+import { validatePackageConfigConfig } from './';
+
+export const hasInvalidButRequiredVar = (
+ registryVars?: RegistryVarsEntry[],
+ packageConfigVars?: PackageConfigConfigRecord
+): boolean => {
+ return (
+ (registryVars && !packageConfigVars) ||
+ Boolean(
+ registryVars &&
+ registryVars.find(
+ (registryVar) =>
+ registryVar.required &&
+ (!packageConfigVars ||
+ !packageConfigVars[registryVar.name] ||
+ validatePackageConfigConfig(packageConfigVars[registryVar.name], registryVar)?.length)
+ )
+ )
+ );
+};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts
index 6cfb1c74bd661..0d33a4e113f03 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/index.ts
@@ -4,10 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/
export { isAdvancedVar } from './is_advanced_var';
+export { hasInvalidButRequiredVar } from './has_invalid_but_required_var';
export {
PackageConfigValidationResults,
PackageConfigConfigValidationResults,
PackageConfigInputValidationResults,
validatePackageConfig,
+ validatePackageConfigConfig,
validationHasErrors,
+ countValidationErrors,
} from './validate_package_config';
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts
index 398f1d675c5df..a2f4a6675ac80 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/is_advanced_var.ts
@@ -6,7 +6,7 @@
import { RegistryVarsEntry } from '../../../../types';
export const isAdvancedVar = (varDef: RegistryVarsEntry): boolean => {
- if (varDef.show_user || (varDef.required && !varDef.default)) {
+ if (varDef.show_user || (varDef.required && varDef.default === undefined)) {
return false;
}
return true;
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts
index cd301747c3f53..bd9d216ca969a 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/services/validate_package_config.ts
@@ -171,7 +171,7 @@ export const validatePackageConfig = (
return validationResults;
};
-const validatePackageConfigConfig = (
+export const validatePackageConfigConfig = (
configEntry: PackageConfigConfigRecordEntry,
varDef: RegistryVarsEntry
): string[] | null => {
@@ -237,13 +237,22 @@ const validatePackageConfigConfig = (
return errors.length ? errors : null;
};
-export const validationHasErrors = (
+export const countValidationErrors = (
validationResults:
| PackageConfigValidationResults
| PackageConfigInputValidationResults
| PackageConfigConfigValidationResults
-) => {
+): number => {
const flattenedValidation = getFlattenedObject(validationResults);
+ const errors = Object.values(flattenedValidation).filter((value) => Boolean(value)) || [];
+ return errors.length;
+};
- return !!Object.entries(flattenedValidation).find(([, value]) => !!value);
+export const validationHasErrors = (
+ validationResults:
+ | PackageConfigValidationResults
+ | PackageConfigInputValidationResults
+ | PackageConfigConfigValidationResults
+): boolean => {
+ return countValidationErrors(validationResults) > 0;
};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx
index eecd204a5e307..380a03e15695b 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_configure_package.tsx
@@ -4,12 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
-import { FormattedMessage } from '@kbn/i18n/react';
-import { EuiPanel, EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiCallOut } from '@elastic/eui';
-import { i18n } from '@kbn/i18n';
+import { EuiHorizontalRule, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { PackageInfo, RegistryStream, NewPackageConfig, PackageConfigInput } from '../../../types';
import { Loading } from '../../../components';
-import { PackageConfigValidationResults, validationHasErrors } from './services';
+import { PackageConfigValidationResults } from './services';
import { PackageConfigInputPanel, CustomPackageConfig } from './components';
import { CreatePackageConfigFrom } from './types';
@@ -52,8 +50,6 @@ export const StepConfigurePackage: React.FunctionComponent<{
validationResults,
submitAttempted,
}) => {
- const hasErrors = validationResults ? validationHasErrors(validationResults) : false;
-
// Configure inputs (and their streams)
// Assume packages only export one config template for now
const renderConfigureInputs = () =>
@@ -61,76 +57,50 @@ export const StepConfigurePackage: React.FunctionComponent<{
packageInfo.config_templates[0] &&
packageInfo.config_templates[0].inputs &&
packageInfo.config_templates[0].inputs.length ? (
-
- {packageInfo.config_templates[0].inputs.map((packageInput) => {
- const packageConfigInput = packageConfig.inputs.find(
- (input) => input.type === packageInput.type
- );
- const packageInputStreams = findStreamsForInputType(packageInput.type, packageInfo);
- return packageConfigInput ? (
-
- ) => {
- const indexOfUpdatedInput = packageConfig.inputs.findIndex(
- (input) => input.type === packageInput.type
- );
- const newInputs = [...packageConfig.inputs];
- newInputs[indexOfUpdatedInput] = {
- ...newInputs[indexOfUpdatedInput],
- ...updatedInput,
- };
- updatePackageConfig({
- inputs: newInputs,
- });
- }}
- inputValidationResults={validationResults!.inputs![packageConfigInput.type]}
- forceShowErrors={submitAttempted}
- />
-
- ) : null;
- })}
-
+ <>
+
+
+ {packageInfo.config_templates[0].inputs.map((packageInput) => {
+ const packageConfigInput = packageConfig.inputs.find(
+ (input) => input.type === packageInput.type
+ );
+ const packageInputStreams = findStreamsForInputType(packageInput.type, packageInfo);
+ return packageConfigInput ? (
+
+ ) => {
+ const indexOfUpdatedInput = packageConfig.inputs.findIndex(
+ (input) => input.type === packageInput.type
+ );
+ const newInputs = [...packageConfig.inputs];
+ newInputs[indexOfUpdatedInput] = {
+ ...newInputs[indexOfUpdatedInput],
+ ...updatedInput,
+ };
+ updatePackageConfig({
+ inputs: newInputs,
+ });
+ }}
+ inputValidationResults={validationResults!.inputs![packageConfigInput.type]}
+ forceShowErrors={submitAttempted}
+ />
+
+
+ ) : null;
+ })}
+
+ >
) : (
-
-
-
+
);
- return validationResults ? (
-
- {renderConfigureInputs()}
- {hasErrors && submitAttempted ? (
-
-
-
-
-
-
-
-
-
- ) : null}
-
- ) : (
-
- );
+ return validationResults ? renderConfigureInputs() : ;
};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx
index b2ffe62104eb1..a04d023ebcc48 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_define_package_config.tsx
@@ -3,17 +3,18 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useEffect, useState, Fragment } from 'react';
+import React, { useEffect, useState } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import {
- EuiFlexGrid,
- EuiFlexItem,
EuiFormRow,
EuiFieldText,
EuiButtonEmpty,
EuiSpacer,
EuiText,
EuiComboBox,
+ EuiDescribedFormGroup,
+ EuiFlexGroup,
+ EuiFlexItem,
} from '@elastic/eui';
import { AgentConfig, PackageInfo, PackageConfig, NewPackageConfig } from '../../../types';
import { packageToPackageConfigInputs } from '../../../services';
@@ -28,7 +29,7 @@ export const StepDefinePackageConfig: React.FunctionComponent<{
validationResults: PackageConfigValidationResults;
}> = ({ agentConfig, packageInfo, packageConfig, updatePackageConfig, validationResults }) => {
// Form show/hide states
- const [isShowingAdvancedDefine, setIsShowingAdvancedDefine] = useState(false);
+ const [isShowingAdvanced, setIsShowingAdvanced] = useState(false);
// Update package config's package and config info
useEffect(() => {
@@ -74,111 +75,140 @@ export const StepDefinePackageConfig: React.FunctionComponent<{
]);
return validationResults ? (
- <>
-
-
-
+
+
+
+ }
+ description={
+
+ }
+ >
+ <>
+ {/* Name */}
+
+ }
+ >
+
+ updatePackageConfig({
+ name: e.target.value,
+ })
}
- >
-
- updatePackageConfig({
- name: e.target.value,
- })
- }
- data-test-subj="packageConfigNameInput"
+ data-test-subj="packageConfigNameInput"
+ />
+
+
+ {/* Description */}
+
-
-
-
-
+
+ }
+ isInvalid={!!validationResults.description}
+ error={validationResults.description}
+ >
+
+ updatePackageConfig({
+ description: e.target.value,
+ })
}
- labelAppend={
-
+ />
+
+
+
+ {/* Advanced options toggle */}
+
+
+ setIsShowingAdvanced(!isShowingAdvanced)}
+ flush="left"
+ >
+
+
+
+ {!isShowingAdvanced && !!validationResults.namespace ? (
+
+
- }
- isInvalid={!!validationResults.description}
- error={validationResults.description}
- >
-
- updatePackageConfig({
- description: e.target.value,
- })
+
+ ) : null}
+
+
+ {/* Advanced options content */}
+ {/* Todo: Populate list of existing namespaces */}
+ {isShowingAdvanced ? (
+ <>
+
+
}
- />
-
-
-
-
- setIsShowingAdvancedDefine(!isShowingAdvancedDefine)}
- >
-
-
- {/* Todo: Populate list of existing namespaces */}
- {isShowingAdvancedDefine || !!validationResults.namespace ? (
-
-
-
-
-
+ >
+
- {
- updatePackageConfig({
- namespace: newNamespace,
- });
- }}
- onChange={(newNamespaces: Array<{ label: string }>) => {
- updatePackageConfig({
- namespace: newNamespaces.length ? newNamespaces[0].label : '',
- });
- }}
- />
-
-
-
-
- ) : null}
- >
+ onCreateOption={(newNamespace: string) => {
+ updatePackageConfig({
+ namespace: newNamespace,
+ });
+ }}
+ onChange={(newNamespaces: Array<{ label: string }>) => {
+ updatePackageConfig({
+ namespace: newNamespaces.length ? newNamespaces[0].label : '',
+ });
+ }}
+ />
+
+ >
+ ) : null}
+ >
+
) : (
);
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx
index f6391cf1fa456..91c80b7eee4c8 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_config.tsx
@@ -6,29 +6,50 @@
import React, { useEffect, useState, Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
-import { EuiFlexGroup, EuiFlexItem, EuiSelectable, EuiSpacer, EuiTextColor } from '@elastic/eui';
+import {
+ EuiFlexGroup,
+ EuiFlexItem,
+ EuiSelectable,
+ EuiSpacer,
+ EuiTextColor,
+ EuiPortal,
+ EuiButtonEmpty,
+} from '@elastic/eui';
import { Error } from '../../../components';
import { AgentConfig, PackageInfo, GetAgentConfigsResponseItem } from '../../../types';
import { isPackageLimited, doesAgentConfigAlreadyIncludePackage } from '../../../services';
-import { useGetPackageInfoByKey, useGetAgentConfigs, sendGetOneAgentConfig } from '../../../hooks';
+import {
+ useGetPackageInfoByKey,
+ useGetAgentConfigs,
+ sendGetOneAgentConfig,
+ useCapabilities,
+} from '../../../hooks';
+import { CreateAgentConfigFlyout } from '../list_page/components';
export const StepSelectConfig: React.FunctionComponent<{
pkgkey: string;
updatePackageInfo: (packageInfo: PackageInfo | undefined) => void;
agentConfig: AgentConfig | undefined;
updateAgentConfig: (config: AgentConfig | undefined) => void;
-}> = ({ pkgkey, updatePackageInfo, agentConfig, updateAgentConfig }) => {
+ setIsLoadingSecondStep: (isLoading: boolean) => void;
+}> = ({ pkgkey, updatePackageInfo, agentConfig, updateAgentConfig, setIsLoadingSecondStep }) => {
// Selected config state
const [selectedConfigId, setSelectedConfigId] = useState(
agentConfig ? agentConfig.id : undefined
);
const [selectedConfigError, setSelectedConfigError] = useState();
+ // Create new config flyout state
+ const hasWriteCapabilites = useCapabilities().write;
+ const [isCreateAgentConfigFlyoutOpen, setIsCreateAgentConfigFlyoutOpen] = useState(
+ false
+ );
+
// Fetch package info
const {
data: packageInfoData,
error: packageInfoError,
- isLoading: packageInfoLoading,
+ isLoading: isPackageInfoLoading,
} = useGetPackageInfoByKey(pkgkey);
const isLimitedPackage = (packageInfoData && isPackageLimited(packageInfoData.response)) || false;
@@ -37,6 +58,7 @@ export const StepSelectConfig: React.FunctionComponent<{
data: agentConfigsData,
error: agentConfigsError,
isLoading: isAgentConfigsLoading,
+ sendRequest: refreshAgentConfigs,
} = useGetAgentConfigs({
page: 1,
perPage: 1000,
@@ -64,6 +86,7 @@ export const StepSelectConfig: React.FunctionComponent<{
useEffect(() => {
const fetchAgentConfigInfo = async () => {
if (selectedConfigId) {
+ setIsLoadingSecondStep(true);
const { data, error } = await sendGetOneAgentConfig(selectedConfigId);
if (error) {
setSelectedConfigError(error);
@@ -76,11 +99,12 @@ export const StepSelectConfig: React.FunctionComponent<{
setSelectedConfigError(undefined);
updateAgentConfig(undefined);
}
+ setIsLoadingSecondStep(false);
};
if (!agentConfig || selectedConfigId !== agentConfig.id) {
fetchAgentConfigInfo();
}
- }, [selectedConfigId, agentConfig, updateAgentConfig]);
+ }, [selectedConfigId, agentConfig, updateAgentConfig, setIsLoadingSecondStep]);
// Display package error if there is one
if (packageInfoError) {
@@ -113,92 +137,126 @@ export const StepSelectConfig: React.FunctionComponent<{
}
return (
-
-
- {
- const alreadyHasLimitedPackage =
- (isLimitedPackage &&
- packageInfoData &&
- doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) ||
- false;
- return {
- label: agentConf.name,
- key: agentConf.id,
- checked: selectedConfigId === agentConf.id ? 'on' : undefined,
- disabled: alreadyHasLimitedPackage,
- 'data-test-subj': 'agentConfigItem',
- };
- })}
- renderOption={(option) => (
-
- {option.label}
-
-
- {agentConfigsById[option.key!].description}
-
-
-
-
-
-
-
-
- )}
- listProps={{
- bordered: true,
- }}
- searchProps={{
- placeholder: i18n.translate(
- 'xpack.ingestManager.createPackageConfig.StepSelectConfig.filterAgentConfigsInputPlaceholder',
- {
- defaultMessage: 'Search for agent configurations',
+ <>
+ {isCreateAgentConfigFlyoutOpen ? (
+
+ {
+ setIsCreateAgentConfigFlyoutOpen(false);
+ if (newAgentConfig) {
+ refreshAgentConfigs();
+ setSelectedConfigId(newAgentConfig.id);
+ }
+ }}
+ ownFocus={true}
+ />
+
+ ) : null}
+
+
+ {
+ const alreadyHasLimitedPackage =
+ (isLimitedPackage &&
+ packageInfoData &&
+ doesAgentConfigAlreadyIncludePackage(agentConf, packageInfoData.response.name)) ||
+ false;
+ return {
+ label: agentConf.name,
+ key: agentConf.id,
+ checked: selectedConfigId === agentConf.id ? 'on' : undefined,
+ disabled: alreadyHasLimitedPackage,
+ 'data-test-subj': 'agentConfigItem',
+ };
+ })}
+ renderOption={(option) => (
+
+ {option.label}
+
+
+ {agentConfigsById[option.key!].description}
+
+
+
+
+
+
+
+
+ )}
+ listProps={{
+ bordered: true,
+ }}
+ searchProps={{
+ placeholder: i18n.translate(
+ 'xpack.ingestManager.createPackageConfig.StepSelectConfig.filterAgentConfigsInputPlaceholder',
+ {
+ defaultMessage: 'Search for agent configurations',
+ }
+ ),
+ }}
+ height={180}
+ onChange={(options) => {
+ const selectedOption = options.find((option) => option.checked === 'on');
+ if (selectedOption) {
+ if (selectedOption.key !== selectedConfigId) {
+ setSelectedConfigId(selectedOption.key);
+ }
+ } else {
+ setSelectedConfigId(undefined);
+ }
+ }}
+ >
+ {(list, search) => (
+
+ {search}
+
+ {list}
+
+ )}
+
+
+ {/* Display selected agent config error if there is one */}
+ {selectedConfigError ? (
+
+
}
- ),
- }}
- height={240}
- onChange={(options) => {
- const selectedOption = options.find((option) => option.checked === 'on');
- if (selectedOption) {
- setSelectedConfigId(selectedOption.key);
- } else {
- setSelectedConfigId(undefined);
- }
- }}
- >
- {(list, search) => (
-
- {search}
-
- {list}
-
- )}
-
-
- {/* Display selected agent config error if there is one */}
- {selectedConfigError ? (
+ error={selectedConfigError}
+ />
+
+ ) : null}
-
+ setIsCreateAgentConfigFlyoutOpen(true)}
+ flush="left"
+ size="s"
+ >
- }
- error={selectedConfigError}
- />
+
+
- ) : null}
-
+
+ >
);
};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx
index 204b862bd4dc4..048ae101fcd6f 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_package_config_page/step_select_package.tsx
@@ -22,7 +22,14 @@ export const StepSelectPackage: React.FunctionComponent<{
updateAgentConfig: (config: AgentConfig | undefined) => void;
packageInfo?: PackageInfo;
updatePackageInfo: (packageInfo: PackageInfo | undefined) => void;
-}> = ({ agentConfigId, updateAgentConfig, packageInfo, updatePackageInfo }) => {
+ setIsLoadingSecondStep: (isLoading: boolean) => void;
+}> = ({
+ agentConfigId,
+ updateAgentConfig,
+ packageInfo,
+ updatePackageInfo,
+ setIsLoadingSecondStep,
+}) => {
// Selected package state
const [selectedPkgKey, setSelectedPkgKey] = useState(
packageInfo ? `${packageInfo.name}-${packageInfo.version}` : undefined
@@ -30,7 +37,11 @@ export const StepSelectPackage: React.FunctionComponent<{
const [selectedPkgError, setSelectedPkgError] = useState();
// Fetch agent config info
- const { data: agentConfigData, error: agentConfigError } = useGetOneAgentConfig(agentConfigId);
+ const {
+ data: agentConfigData,
+ error: agentConfigError,
+ isLoading: isAgentConfigsLoading,
+ } = useGetOneAgentConfig(agentConfigId);
// Fetch packages info
// Filter out limited packages already part of selected agent config
@@ -66,6 +77,7 @@ export const StepSelectPackage: React.FunctionComponent<{
useEffect(() => {
const fetchPackageInfo = async () => {
if (selectedPkgKey) {
+ setIsLoadingSecondStep(true);
const { data, error } = await sendGetPackageInfoByKey(selectedPkgKey);
if (error) {
setSelectedPkgError(error);
@@ -74,6 +86,7 @@ export const StepSelectPackage: React.FunctionComponent<{
setSelectedPkgError(undefined);
updatePackageInfo(data.response);
}
+ setIsLoadingSecondStep(false);
} else {
setSelectedPkgError(undefined);
updatePackageInfo(undefined);
@@ -82,7 +95,7 @@ export const StepSelectPackage: React.FunctionComponent<{
if (!packageInfo || selectedPkgKey !== `${packageInfo.name}-${packageInfo.version}`) {
fetchPackageInfo();
}
- }, [selectedPkgKey, packageInfo, updatePackageInfo]);
+ }, [selectedPkgKey, packageInfo, updatePackageInfo, setIsLoadingSecondStep]);
// Display agent config error if there is one
if (agentConfigError) {
@@ -121,7 +134,7 @@ export const StepSelectPackage: React.FunctionComponent<{
searchable
allowExclusions={false}
singleSelection={true}
- isLoading={isPackagesLoading || isLimitedPackagesLoading}
+ isLoading={isPackagesLoading || isLimitedPackagesLoading || isAgentConfigsLoading}
options={packages.map(({ title, name, version, icons }) => {
const pkgkey = `${name}-${version}`;
return {
@@ -154,7 +167,9 @@ export const StepSelectPackage: React.FunctionComponent<{
onChange={(options) => {
const selectedOption = options.find((option) => option.checked === 'on');
if (selectedOption) {
- setSelectedPkgKey(selectedOption.key);
+ if (selectedOption.key !== selectedPkgKey) {
+ setSelectedPkgKey(selectedOption.key);
+ }
} else {
setSelectedPkgKey(undefined);
}
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx
index 52fd95d663671..f4411a6057a15 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/edit_package_config_page/index.tsx
@@ -3,14 +3,13 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useCallback, useMemo } from 'react';
import { useRouteMatch, useHistory } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiButtonEmpty,
EuiButton,
- EuiSteps,
EuiBottomBar,
EuiFlexGroup,
EuiFlexItem,
@@ -160,38 +159,45 @@ export const EditPackageConfigPage: React.FunctionComponent = () => {
const [validationResults, setValidationResults] = useState();
const hasErrors = validationResults ? validationHasErrors(validationResults) : false;
- // Update package config method
- const updatePackageConfig = (updatedFields: Partial) => {
- const newPackageConfig = {
- ...packageConfig,
- ...updatedFields,
- };
- setPackageConfig(newPackageConfig);
+ // Update package config validation
+ const updatePackageConfigValidation = useCallback(
+ (newPackageConfig?: UpdatePackageConfig) => {
+ if (packageInfo) {
+ const newValidationResult = validatePackageConfig(
+ newPackageConfig || packageConfig,
+ packageInfo
+ );
+ setValidationResults(newValidationResult);
+ // eslint-disable-next-line no-console
+ console.debug('Package config validation results', newValidationResult);
- // eslint-disable-next-line no-console
- console.debug('Package config updated', newPackageConfig);
- const newValidationResults = updatePackageConfigValidation(newPackageConfig);
- const hasValidationErrors = newValidationResults
- ? validationHasErrors(newValidationResults)
- : false;
- if (!hasValidationErrors) {
- setFormState('VALID');
- }
- };
+ return newValidationResult;
+ }
+ },
+ [packageConfig, packageInfo]
+ );
- const updatePackageConfigValidation = (newPackageConfig?: UpdatePackageConfig) => {
- if (packageInfo) {
- const newValidationResult = validatePackageConfig(
- newPackageConfig || packageConfig,
- packageInfo
- );
- setValidationResults(newValidationResult);
- // eslint-disable-next-line no-console
- console.debug('Package config validation results', newValidationResult);
+ // Update package config method
+ const updatePackageConfig = useCallback(
+ (updatedFields: Partial) => {
+ const newPackageConfig = {
+ ...packageConfig,
+ ...updatedFields,
+ };
+ setPackageConfig(newPackageConfig);
- return newValidationResult;
- }
- };
+ // eslint-disable-next-line no-console
+ console.debug('Package config updated', newPackageConfig);
+ const newValidationResults = updatePackageConfigValidation(newPackageConfig);
+ const hasValidationErrors = newValidationResults
+ ? validationHasErrors(newValidationResults)
+ : false;
+ if (!hasValidationErrors) {
+ setFormState('VALID');
+ }
+ },
+ [packageConfig, updatePackageConfigValidation]
+ );
// Cancel url
const cancelUrl = getHref('configuration_details', { configId });
@@ -271,6 +277,40 @@ export const EditPackageConfigPage: React.FunctionComponent = () => {
packageInfo,
};
+ const configurePackage = useMemo(
+ () =>
+ agentConfig && packageInfo ? (
+ <>
+
+
+
+ >
+ ) : null,
+ [
+ agentConfig,
+ formState,
+ packageConfig,
+ packageConfigId,
+ packageInfo,
+ updatePackageConfig,
+ validationResults,
+ ]
+ );
+
return (
{isLoadingData ? (
@@ -301,46 +341,7 @@ export const EditPackageConfigPage: React.FunctionComponent = () => {
onCancel={() => setFormState('VALID')}
/>
)}
-
- ),
- },
- {
- title: i18n.translate(
- 'xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle',
- {
- defaultMessage: 'Select the data you want to collect',
- }
- ),
- children: (
-
- ),
- },
- ]}
- />
+ {configurePackage}
{/* TODO #64541 - Remove classes */}
{
: undefined
}
>
-
+
-
+ {agentConfig && packageInfo && formState === 'INVALID' ? (
-
+ ) : null}
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx
index d1abd88adba86..37fce340da6ea 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/list_page/components/create_config.tsx
@@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useState } from 'react';
+import styled from 'styled-components';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import {
@@ -17,16 +18,24 @@ import {
EuiButtonEmpty,
EuiButton,
EuiText,
+ EuiFlyoutProps,
} from '@elastic/eui';
-import { NewAgentConfig } from '../../../../types';
+import { NewAgentConfig, AgentConfig } from '../../../../types';
import { useCapabilities, useCore, sendCreateAgentConfig } from '../../../../hooks';
import { AgentConfigForm, agentConfigFormValidation } from '../../components';
-interface Props {
- onClose: () => void;
+const FlyoutWithHigherZIndex = styled(EuiFlyout)`
+ z-index: ${(props) => props.theme.eui.euiZLevel5};
+`;
+
+interface Props extends EuiFlyoutProps {
+ onClose: (createdAgentConfig?: AgentConfig) => void;
}
-export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClose }) => {
+export const CreateAgentConfigFlyout: React.FunctionComponent = ({
+ onClose,
+ ...restOfProps
+}) => {
const { notifications } = useCore();
const hasWriteCapabilites = useCapabilities().write;
const [agentConfig, setAgentConfig] = useState({
@@ -86,7 +95,7 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos
-
+ onClose()} flush="left">
= ({ onClos
}
)
);
- onClose();
+ onClose(data.item);
} else {
notifications.toasts.addDanger(
error
@@ -147,10 +156,10 @@ export const CreateAgentConfigFlyout: React.FunctionComponent = ({ onClos
);
return (
-
+
{header}
{body}
{footer}
-
+
);
};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_details_page/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_details_page/index.tsx
index 15086879ce80b..ae9b1e1f6f433 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_details_page/index.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/agent_details_page/index.tsx
@@ -86,7 +86,7 @@ export const AgentDetailsPage: React.FunctionComponent = () => {
>
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx
index 8cd337586d1bc..09b00240dc127 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/config_selection.tsx
@@ -4,46 +4,98 @@
* you may not use this file except in compliance with the Elastic License.
*/
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSelect, EuiSpacer, EuiText, EuiButtonEmpty } from '@elastic/eui';
-import { AgentConfig } from '../../../../types';
-import { useGetEnrollmentAPIKeys } from '../../../../hooks';
+import { AgentConfig, GetEnrollmentAPIKeysResponse } from '../../../../types';
+import { sendGetEnrollmentAPIKeys, useCore } from '../../../../hooks';
import { AgentConfigPackageBadges } from '../agent_config_package_badges';
-interface Props {
- agentConfigs: AgentConfig[];
- onKeyChange: (key: string) => void;
-}
+type Props = {
+ agentConfigs?: AgentConfig[];
+ onConfigChange?: (key: string) => void;
+} & (
+ | {
+ withKeySelection: true;
+ onKeyChange?: (key: string) => void;
+ }
+ | {
+ withKeySelection: false;
+ }
+);
-export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKeyChange }) => {
- const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false);
- const enrollmentAPIKeysRequest = useGetEnrollmentAPIKeys({
- page: 1,
- perPage: 1000,
- });
+export const EnrollmentStepAgentConfig: React.FC = (props) => {
+ const { notifications } = useCore();
+ const { withKeySelection, agentConfigs, onConfigChange } = props;
+ const onKeyChange = props.withKeySelection && props.onKeyChange;
+ const [isAuthenticationSettingsOpen, setIsAuthenticationSettingsOpen] = useState(false);
+ const [enrollmentAPIKeys, setEnrollmentAPIKeys] = useState(
+ []
+ );
const [selectedState, setSelectedState] = useState<{
agentConfigId?: string;
enrollmentAPIKeyId?: string;
- }>({
- agentConfigId: agentConfigs.length ? agentConfigs[0].id : undefined,
- });
- const filteredEnrollmentAPIKeys = React.useMemo(() => {
- if (!selectedState.agentConfigId || !enrollmentAPIKeysRequest.data) {
- return [];
+ }>({});
+
+ useEffect(() => {
+ if (agentConfigs && agentConfigs.length && !selectedState.agentConfigId) {
+ setSelectedState({
+ ...selectedState,
+ agentConfigId: agentConfigs[0].id,
+ });
+ }
+ }, [agentConfigs, selectedState]);
+
+ useEffect(() => {
+ if (onConfigChange && selectedState.agentConfigId) {
+ onConfigChange(selectedState.agentConfigId);
+ }
+ }, [selectedState.agentConfigId, onConfigChange]);
+
+ useEffect(() => {
+ if (!withKeySelection) {
+ return;
+ }
+ if (!selectedState.agentConfigId) {
+ setEnrollmentAPIKeys([]);
+ return;
}
- return enrollmentAPIKeysRequest.data.list.filter(
- (key) => key.config_id === selectedState.agentConfigId
- );
- }, [enrollmentAPIKeysRequest.data, selectedState.agentConfigId]);
+ async function fetchEnrollmentAPIKeys() {
+ try {
+ const res = await sendGetEnrollmentAPIKeys({
+ page: 1,
+ perPage: 10000,
+ });
+ if (res.error) {
+ throw res.error;
+ }
+
+ if (!res.data) {
+ throw new Error('No data while fetching enrollment API keys');
+ }
+
+ setEnrollmentAPIKeys(
+ res.data.list.filter((key) => key.config_id === selectedState.agentConfigId)
+ );
+ } catch (error) {
+ notifications.toasts.addError(error, {
+ title: 'Error',
+ });
+ }
+ }
+ fetchEnrollmentAPIKeys();
+ }, [withKeySelection, selectedState.agentConfigId, notifications.toasts]);
// Select first API key when config change
React.useEffect(() => {
- if (!selectedState.enrollmentAPIKeyId && filteredEnrollmentAPIKeys.length > 0) {
- const enrollmentAPIKeyId = filteredEnrollmentAPIKeys[0].id;
+ if (!withKeySelection || !onKeyChange) {
+ return;
+ }
+ if (!selectedState.enrollmentAPIKeyId && enrollmentAPIKeys.length > 0) {
+ const enrollmentAPIKeyId = enrollmentAPIKeys[0].id;
setSelectedState({
agentConfigId: selectedState.agentConfigId,
enrollmentAPIKeyId,
@@ -51,7 +103,7 @@ export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKey
onKeyChange(enrollmentAPIKeyId);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [filteredEnrollmentAPIKeys, selectedState.enrollmentAPIKeyId, selectedState.agentConfigId]);
+ }, [enrollmentAPIKeys, selectedState.enrollmentAPIKeyId, selectedState.agentConfigId]);
return (
<>
@@ -65,7 +117,8 @@ export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKey
/>
}
- options={agentConfigs.map((config) => ({
+ isLoading={!agentConfigs}
+ options={(agentConfigs || []).map((config) => ({
value: config.id,
text: config.name,
}))}
@@ -85,43 +138,47 @@ export const EnrollmentStepAgentConfig: React.FC = ({ agentConfigs, onKey
{selectedState.agentConfigId && (
)}
-
- setIsAuthenticationSettingsOpen(!isAuthenticationSettingsOpen)}
- >
-
-
- {isAuthenticationSettingsOpen && (
+ {withKeySelection && onKeyChange && (
<>
- ({
- value: key.id,
- text: key.name,
- }))}
- value={selectedState.enrollmentAPIKeyId || undefined}
- prepend={
-
-
-
- }
- onChange={(e) => {
- setSelectedState({
- ...selectedState,
- enrollmentAPIKeyId: e.target.value,
- });
- onKeyChange(e.target.value);
- }}
- />
+ setIsAuthenticationSettingsOpen(!isAuthenticationSettingsOpen)}
+ >
+
+
+ {isAuthenticationSettingsOpen && (
+ <>
+
+ ({
+ value: key.id,
+ text: key.name,
+ }))}
+ value={selectedState.enrollmentAPIKeyId || undefined}
+ prepend={
+
+
+
+ }
+ onChange={(e) => {
+ setSelectedState({
+ ...selectedState,
+ enrollmentAPIKeyId: e.target.value,
+ });
+ onKeyChange(e.target.value);
+ }}
+ />
+ >
+ )}
>
)}
>
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx
index 43173124d6bae..2c66001cc8c08 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/index.tsx
@@ -14,126 +14,57 @@ import {
EuiButtonEmpty,
EuiButton,
EuiFlyoutFooter,
- EuiSteps,
- EuiText,
- EuiLink,
+ EuiTab,
+ EuiTabs,
} from '@elastic/eui';
-import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';
-import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { AgentConfig } from '../../../../types';
-import { EnrollmentStepAgentConfig } from './config_selection';
-import {
- useGetOneEnrollmentAPIKey,
- useCore,
- useGetSettings,
- useLink,
- useFleetStatus,
-} from '../../../../hooks';
-import { ManualInstructions } from '../../../../components/enrollment_instructions';
+import { ManagedInstructions } from './managed_instructions';
+import { StandaloneInstructions } from './standalone_instructions';
interface Props {
onClose: () => void;
- agentConfigs: AgentConfig[];
+ agentConfigs?: AgentConfig[];
}
export const AgentEnrollmentFlyout: React.FunctionComponent = ({
onClose,
- agentConfigs = [],
+ agentConfigs,
}) => {
- const { getHref } = useLink();
- const core = useCore();
- const fleetStatus = useFleetStatus();
-
- const [selectedAPIKeyId, setSelectedAPIKeyId] = useState();
-
- const settings = useGetSettings();
- const apiKey = useGetOneEnrollmentAPIKey(selectedAPIKeyId);
-
- const kibanaUrl =
- settings.data?.item?.kibana_url ?? `${window.location.origin}${core.http.basePath.get()}`;
- const kibanaCASha256 = settings.data?.item?.kibana_ca_sha256;
-
- const steps: EuiContainedStepProps[] = [
- {
- title: i18n.translate('xpack.ingestManager.agentEnrollment.stepDownloadAgentTitle', {
- defaultMessage: 'Download the Elastic Agent',
- }),
- children: (
-
-
-
-
- ),
- }}
- />
-
- ),
- },
- {
- title: i18n.translate('xpack.ingestManager.agentEnrollment.stepChooseAgentConfigTitle', {
- defaultMessage: 'Choose an agent configuration',
- }),
- children: (
-
- ),
- },
- {
- title: i18n.translate('xpack.ingestManager.agentEnrollment.stepRunAgentTitle', {
- defaultMessage: 'Enroll and run the Elastic Agent',
- }),
- children: apiKey.data && (
-
- ),
- },
- ];
+ const [mode, setMode] = useState<'managed' | 'standalone'>('managed');
return (
-
+
+
+ setMode('managed')}>
+
+
+ setMode('standalone')}>
+
+
+
+
- {fleetStatus.isReady ? (
- <>
-
- >
+ {mode === 'managed' ? (
+
) : (
- <>
-
-
-
- ),
- }}
- />
- >
+
)}
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx
new file mode 100644
index 0000000000000..eefb7f1bb7b5f
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/managed_instructions.tsx
@@ -0,0 +1,91 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useState } from 'react';
+import { EuiSteps, EuiLink, EuiText, EuiSpacer } from '@elastic/eui';
+import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';
+import { i18n } from '@kbn/i18n';
+import { FormattedMessage } from '@kbn/i18n/react';
+import { AgentConfig } from '../../../../types';
+import {
+ useGetOneEnrollmentAPIKey,
+ useCore,
+ useGetSettings,
+ useLink,
+ useFleetStatus,
+} from '../../../../hooks';
+import { ManualInstructions } from '../../../../components/enrollment_instructions';
+import { DownloadStep, AgentConfigSelectionStep } from './steps';
+
+interface Props {
+ agentConfigs?: AgentConfig[];
+}
+
+export const ManagedInstructions: React.FunctionComponent = ({ agentConfigs }) => {
+ const { getHref } = useLink();
+ const core = useCore();
+ const fleetStatus = useFleetStatus();
+
+ const [selectedAPIKeyId, setSelectedAPIKeyId] = useState();
+
+ const settings = useGetSettings();
+ const apiKey = useGetOneEnrollmentAPIKey(selectedAPIKeyId);
+
+ const kibanaUrl =
+ settings.data?.item?.kibana_url ?? `${window.location.origin}${core.http.basePath.get()}`;
+ const kibanaCASha256 = settings.data?.item?.kibana_ca_sha256;
+
+ const steps: EuiContainedStepProps[] = [
+ DownloadStep(),
+ AgentConfigSelectionStep({ agentConfigs, setSelectedAPIKeyId }),
+ {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepEnrollAndRunAgentTitle', {
+ defaultMessage: 'Enroll and start the Elastic Agent',
+ }),
+ children: apiKey.data && (
+
+ ),
+ },
+ ];
+
+ return (
+ <>
+
+
+
+
+ {fleetStatus.isReady ? (
+ <>
+
+ >
+ ) : (
+ <>
+
+
+
+ ),
+ }}
+ />
+ >
+ )}
+ >
+ );
+};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx
new file mode 100644
index 0000000000000..d5f79563f33c4
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/standalone_instructions.tsx
@@ -0,0 +1,181 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { useState, useEffect, useMemo } from 'react';
+import {
+ EuiSteps,
+ EuiText,
+ EuiSpacer,
+ EuiButton,
+ EuiCode,
+ EuiFlexItem,
+ EuiFlexGroup,
+ EuiCodeBlock,
+ EuiCopy,
+} from '@elastic/eui';
+import { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';
+import { i18n } from '@kbn/i18n';
+import { FormattedMessage } from '@kbn/i18n/react';
+import { AgentConfig } from '../../../../types';
+import { useCore, sendGetOneAgentConfigFull } from '../../../../hooks';
+import { DownloadStep, AgentConfigSelectionStep } from './steps';
+import { configToYaml, agentConfigRouteService } from '../../../../services';
+
+interface Props {
+ agentConfigs?: AgentConfig[];
+}
+
+const RUN_INSTRUCTIONS = './elastic-agent run';
+
+export const StandaloneInstructions: React.FunctionComponent = ({ agentConfigs }) => {
+ const core = useCore();
+ const { notifications } = core;
+
+ const [selectedConfigId, setSelectedConfigId] = useState();
+ const [fullAgentConfig, setFullAgentConfig] = useState();
+
+ const downloadLink = selectedConfigId
+ ? core.http.basePath.prepend(
+ `${agentConfigRouteService.getInfoFullDownloadPath(selectedConfigId)}?standalone=true`
+ )
+ : undefined;
+
+ useEffect(() => {
+ async function fetchFullConfig() {
+ try {
+ if (!selectedConfigId) {
+ return;
+ }
+ const res = await sendGetOneAgentConfigFull(selectedConfigId, { standalone: true });
+ if (res.error) {
+ throw res.error;
+ }
+
+ if (!res.data) {
+ throw new Error('No data while fetching full agent config');
+ }
+
+ setFullAgentConfig(res.data.item);
+ } catch (error) {
+ notifications.toasts.addError(error, {
+ title: 'Error',
+ });
+ }
+ }
+ fetchFullConfig();
+ }, [selectedConfigId, notifications.toasts]);
+
+ const yaml = useMemo(() => configToYaml(fullAgentConfig), [fullAgentConfig]);
+ const steps: EuiContainedStepProps[] = [
+ DownloadStep(),
+ AgentConfigSelectionStep({ agentConfigs, setSelectedConfigId }),
+ {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepConfigureAgentTitle', {
+ defaultMessage: 'Configure the agent',
+ }),
+ children: (
+ <>
+
+ elastic-agent.yml,
+ ESUsernameVariable: ES_USERNAME ,
+ ESPasswordVariable: ES_PASSWORD ,
+ outputSection: outputs ,
+ }}
+ />
+
+
+
+
+ {(copy) => (
+
+
+
+ )}
+
+
+
+
+
+
+
+
+
+
+ {yaml}
+
+
+ >
+ ),
+ },
+ {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepRunAgentTitle', {
+ defaultMessage: 'Start the agent',
+ }),
+ children: (
+ <>
+
+
+
+ {RUN_INSTRUCTIONS}
+
+
+ {(copy) => (
+
+
+
+ )}
+
+
+ >
+ ),
+ },
+ {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepCheckForDataTitle', {
+ defaultMessage: 'Check for data',
+ }),
+ status: 'incomplete',
+ children: (
+ <>
+
+
+
+ >
+ ),
+ },
+ ];
+
+ return (
+ <>
+
+
+
+
+
+ >
+ );
+};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx
new file mode 100644
index 0000000000000..d01e207169920
--- /dev/null
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/fleet/components/agent_enrollment_flyout/steps.tsx
@@ -0,0 +1,66 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { EuiText, EuiButton, EuiSpacer } from '@elastic/eui';
+import { FormattedMessage } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
+import { EnrollmentStepAgentConfig } from './config_selection';
+import { AgentConfig } from '../../../../types';
+
+export const DownloadStep = () => {
+ return {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepDownloadAgentTitle', {
+ defaultMessage: 'Download the Elastic Agent',
+ }),
+ children: (
+ <>
+
+
+
+
+
+
+
+ >
+ ),
+ };
+};
+
+export const AgentConfigSelectionStep = ({
+ agentConfigs,
+ setSelectedAPIKeyId,
+ setSelectedConfigId,
+}: {
+ agentConfigs?: AgentConfig[];
+ setSelectedAPIKeyId?: (key: string) => void;
+ setSelectedConfigId?: (configId: string) => void;
+}) => {
+ return {
+ title: i18n.translate('xpack.ingestManager.agentEnrollment.stepChooseAgentConfigTitle', {
+ defaultMessage: 'Choose an agent configuration',
+ }),
+ children: (
+
+ ),
+ };
+};
diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts
index 170a9cedc08d9..dc27da18bc008 100644
--- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts
+++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/types/index.ts
@@ -18,6 +18,7 @@ export {
UpdatePackageConfig,
PackageConfigInput,
PackageConfigInputStream,
+ PackageConfigConfigRecord,
PackageConfigConfigRecordEntry,
Output,
DataStream,
diff --git a/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts b/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts
index 110f6b9950829..718aca89ea4fd 100644
--- a/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts
+++ b/x-pack/plugins/ingest_manager/server/routes/agent_config/handlers.ts
@@ -232,15 +232,17 @@ export const deleteAgentConfigsHandler: RequestHandler<
}
};
-export const getFullAgentConfig: RequestHandler> = async (context, request, response) => {
+export const getFullAgentConfig: RequestHandler<
+ TypeOf,
+ TypeOf
+> = async (context, request, response) => {
const soClient = context.core.savedObjects.client;
try {
const fullAgentConfig = await agentConfigService.getFullConfig(
soClient,
- request.params.agentConfigId
+ request.params.agentConfigId,
+ { standalone: request.query.standalone === true }
);
if (fullAgentConfig) {
const body: GetFullAgentConfigResponse = {
@@ -264,21 +266,24 @@ export const getFullAgentConfig: RequestHandler> = async (context, request, response) => {
+export const downloadFullAgentConfig: RequestHandler<
+ TypeOf,
+ TypeOf
+> = async (context, request, response) => {
const soClient = context.core.savedObjects.client;
const {
params: { agentConfigId },
} = request;
try {
- const fullAgentConfig = await agentConfigService.getFullConfig(soClient, agentConfigId);
+ const fullAgentConfig = await agentConfigService.getFullConfig(soClient, agentConfigId, {
+ standalone: request.query.standalone === true,
+ });
if (fullAgentConfig) {
const body = configToYaml(fullAgentConfig);
const headers: ResponseHeaders = {
'content-type': 'text/x-yaml',
- 'content-disposition': `attachment; filename="elastic-agent-config-${fullAgentConfig.id}.yml"`,
+ 'content-disposition': `attachment; filename="elastic-agent.yml"`,
};
return response.ok({
body,
diff --git a/x-pack/plugins/ingest_manager/server/saved_objects/index.ts b/x-pack/plugins/ingest_manager/server/saved_objects/index.ts
index 6c360fdeda460..4c58ac57a54a2 100644
--- a/x-pack/plugins/ingest_manager/server/saved_objects/index.ts
+++ b/x-pack/plugins/ingest_manager/server/saved_objects/index.ts
@@ -67,7 +67,7 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
last_checkin_status: { type: 'keyword' },
config_revision: { type: 'integer' },
default_api_key_id: { type: 'keyword' },
- default_api_key: { type: 'binary', index: false },
+ default_api_key: { type: 'binary' },
updated_at: { type: 'date' },
current_error_events: { type: 'text', index: false },
packages: { type: 'keyword' },
@@ -85,7 +85,7 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
properties: {
agent_id: { type: 'keyword' },
type: { type: 'keyword' },
- data: { type: 'binary', index: false },
+ data: { type: 'binary' },
sent_at: { type: 'date' },
created_at: { type: 'date' },
},
@@ -146,7 +146,7 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
properties: {
name: { type: 'keyword' },
type: { type: 'keyword' },
- api_key: { type: 'binary', index: false },
+ api_key: { type: 'binary' },
api_key_id: { type: 'keyword' },
config_id: { type: 'keyword' },
created_at: { type: 'date' },
@@ -170,8 +170,8 @@ const savedObjectTypes: { [key: string]: SavedObjectsType } = {
is_default: { type: 'boolean' },
hosts: { type: 'keyword' },
ca_sha256: { type: 'keyword', index: false },
- fleet_enroll_username: { type: 'binary', index: false },
- fleet_enroll_password: { type: 'binary', index: false },
+ fleet_enroll_username: { type: 'binary' },
+ fleet_enroll_password: { type: 'binary' },
config: { type: 'flattened' },
},
},
diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.test.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.test.ts
index c46e648ad088a..225251b061e58 100644
--- a/x-pack/plugins/ingest_manager/server/services/agent_config.test.ts
+++ b/x-pack/plugins/ingest_manager/server/services/agent_config.test.ts
@@ -61,7 +61,7 @@ describe('agent config', () => {
},
inputs: [],
revision: 1,
- settings: {
+ agent: {
monitoring: {
enabled: false,
logs: false,
@@ -90,7 +90,7 @@ describe('agent config', () => {
},
inputs: [],
revision: 1,
- settings: {
+ agent: {
monitoring: {
use_output: 'default',
enabled: true,
@@ -120,7 +120,7 @@ describe('agent config', () => {
},
inputs: [],
revision: 1,
- settings: {
+ agent: {
monitoring: {
use_output: 'default',
enabled: true,
diff --git a/x-pack/plugins/ingest_manager/server/services/agent_config.ts b/x-pack/plugins/ingest_manager/server/services/agent_config.ts
index fe247d5b91db0..c068b594318c1 100644
--- a/x-pack/plugins/ingest_manager/server/services/agent_config.ts
+++ b/x-pack/plugins/ingest_manager/server/services/agent_config.ts
@@ -365,7 +365,8 @@ class AgentConfigService {
public async getFullConfig(
soClient: SavedObjectsClientContract,
- id: string
+ id: string,
+ options?: { standalone: boolean }
): Promise {
let config;
@@ -400,6 +401,13 @@ class AgentConfigService {
api_key,
...outputConfig,
};
+
+ if (options?.standalone) {
+ delete outputs[name].api_key;
+ outputs[name].username = 'ES_USERNAME';
+ outputs[name].password = 'ES_PASSWORD';
+ }
+
return outputs;
},
{} as FullAgentConfig['outputs']
@@ -409,7 +417,7 @@ class AgentConfigService {
revision: config.revision,
...(config.monitoring_enabled && config.monitoring_enabled.length > 0
? {
- settings: {
+ agent: {
monitoring: {
use_output: defaultOutput.name,
enabled: true,
@@ -419,7 +427,7 @@ class AgentConfigService {
},
}
: {
- settings: {
+ agent: {
monitoring: { enabled: false, logs: false, metrics: false },
},
}),
diff --git a/x-pack/plugins/ingest_manager/server/services/package_config.test.ts b/x-pack/plugins/ingest_manager/server/services/package_config.test.ts
index f8dd1c65e3e72..e86e2608e252d 100644
--- a/x-pack/plugins/ingest_manager/server/services/package_config.test.ts
+++ b/x-pack/plugins/ingest_manager/server/services/package_config.test.ts
@@ -4,8 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
+import { savedObjectsClientMock } from 'src/core/server/mocks';
+import { createPackageConfigMock } from '../../common/mocks';
import { packageConfigService } from './package_config';
-import { PackageInfo } from '../types';
+import { PackageInfo, PackageConfigSOAttributes } from '../types';
+import { SavedObjectsUpdateResponse } from 'src/core/server';
async function mockedGetAssetsData(_a: any, _b: any, dataset: string) {
if (dataset === 'dataset1') {
@@ -161,4 +164,32 @@ describe('Package config service', () => {
]);
});
});
+
+ describe('update', () => {
+ it('should fail to update on version conflict', async () => {
+ const savedObjectsClient = savedObjectsClientMock.create();
+ savedObjectsClient.get.mockResolvedValue({
+ id: 'test',
+ type: 'abcd',
+ references: [],
+ version: 'test',
+ attributes: createPackageConfigMock(),
+ });
+ savedObjectsClient.update.mockImplementation(
+ async (
+ type: string,
+ id: string
+ ): Promise> => {
+ throw savedObjectsClient.errors.createConflictError('abc', '123');
+ }
+ );
+ await expect(
+ packageConfigService.update(
+ savedObjectsClient,
+ 'the-package-config-id',
+ createPackageConfigMock()
+ )
+ ).rejects.toThrow('Saved object [abc/123] conflict');
+ });
+ });
});
diff --git a/x-pack/plugins/ingest_manager/server/services/package_config.ts b/x-pack/plugins/ingest_manager/server/services/package_config.ts
index 9433a81e74b07..e8ca09a83c2b6 100644
--- a/x-pack/plugins/ingest_manager/server/services/package_config.ts
+++ b/x-pack/plugins/ingest_manager/server/services/package_config.ts
@@ -44,6 +44,20 @@ class PackageConfigService {
packageConfig: NewPackageConfig,
options?: { id?: string; user?: AuthenticatedUser }
): Promise {
+ // Check that its agent config does not have a package config with the same name
+ const parentAgentConfig = await agentConfigService.get(soClient, packageConfig.config_id);
+ if (!parentAgentConfig) {
+ throw new Error('Agent config not found');
+ } else {
+ if (
+ (parentAgentConfig.package_configs as PackageConfig[]).find(
+ (siblingPackageConfig) => siblingPackageConfig.name === packageConfig.name
+ )
+ ) {
+ throw new Error('There is already a package with the same name on this agent config');
+ }
+ }
+
// Make sure the associated package is installed
if (packageConfig.package?.name) {
const [, pkgInfo] = await Promise.all([
@@ -225,6 +239,21 @@ class PackageConfigService {
throw new Error('Package config not found');
}
+ // Check that its agent config does not have a package config with the same name
+ const parentAgentConfig = await agentConfigService.get(soClient, packageConfig.config_id);
+ if (!parentAgentConfig) {
+ throw new Error('Agent config not found');
+ } else {
+ if (
+ (parentAgentConfig.package_configs as PackageConfig[]).find(
+ (siblingPackageConfig) =>
+ siblingPackageConfig.id !== id && siblingPackageConfig.name === packageConfig.name
+ )
+ ) {
+ throw new Error('There is already a package with the same name on this agent config');
+ }
+ }
+
await soClient.update(
SAVED_OBJECT_TYPE,
id,
diff --git a/x-pack/plugins/ingest_manager/server/services/setup.ts b/x-pack/plugins/ingest_manager/server/services/setup.ts
index e27a5456a5a7d..627abc158143d 100644
--- a/x-pack/plugins/ingest_manager/server/services/setup.ts
+++ b/x-pack/plugins/ingest_manager/server/services/setup.ts
@@ -180,11 +180,18 @@ export async function setupFleet(
fleet_enroll_password: password,
});
- // Generate default enrollment key
- await generateEnrollmentAPIKey(soClient, {
- name: 'Default',
- configId: await agentConfigService.getDefaultAgentConfigId(soClient),
+ const { items: agentConfigs } = await agentConfigService.list(soClient, {
+ perPage: 10000,
});
+
+ await Promise.all(
+ agentConfigs.map((agentConfig) => {
+ return generateEnrollmentAPIKey(soClient, {
+ name: `Default`,
+ configId: agentConfig.id,
+ });
+ })
+ );
}
function generateRandomPassword() {
diff --git a/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts b/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts
index d076a803f4b53..594bd141459c1 100644
--- a/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts
+++ b/x-pack/plugins/ingest_manager/server/types/rest_spec/agent_config.ts
@@ -51,5 +51,6 @@ export const GetFullAgentConfigRequestSchema = {
}),
query: schema.object({
download: schema.maybe(schema.boolean()),
+ standalone: schema.maybe(schema.boolean()),
}),
};
diff --git a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts
index c7bfe94742bd6..1bd8c5401eb1d 100644
--- a/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts
+++ b/x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts
@@ -5,7 +5,7 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */
-import { RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
+import { RENDER_AS, SORT_ORDER, SCALING_TYPES, SOURCE_TYPES } from '../constants';
import { MapExtent, MapQuery } from './map_descriptor';
import { Filter, TimeRange } from '../../../../../src/plugins/data/common';
@@ -26,10 +26,12 @@ type ESSearchSourceSyncMeta = {
scalingType: SCALING_TYPES;
topHitsSplitField: string;
topHitsSize: number;
+ sourceType: SOURCE_TYPES.ES_SEARCH;
};
type ESGeoGridSourceSyncMeta = {
requestType: RENDER_AS;
+ sourceType: SOURCE_TYPES.ES_GEO_GRID;
};
export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncMeta | null;
@@ -51,7 +53,6 @@ export type VectorStyleRequestMeta = MapFilters & {
export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
- sourceType?: string;
// top hits meta
areEntitiesTrimmed?: boolean;
diff --git a/x-pack/plugins/maps/common/descriptor_types/sources.ts b/x-pack/plugins/maps/common/descriptor_types/sources.ts
index e32b5f44c8272..7eda37bf53351 100644
--- a/x-pack/plugins/maps/common/descriptor_types/sources.ts
+++ b/x-pack/plugins/maps/common/descriptor_types/sources.ts
@@ -77,8 +77,8 @@ export type ESPewPewSourceDescriptor = AbstractESAggSourceDescriptor & {
};
export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & {
- indexPatternTitle: string;
- term: string; // term field name
+ indexPatternTitle?: string;
+ term?: string; // term field name
whereQuery?: Query;
};
@@ -138,7 +138,7 @@ export type GeojsonFileSourceDescriptor = {
};
export type JoinDescriptor = {
- leftField: string;
+ leftField?: string;
right: ESTermSourceDescriptor;
};
diff --git a/x-pack/plugins/maps/kibana.json b/x-pack/plugins/maps/kibana.json
index e422efb31cb0d..fbf45aee02125 100644
--- a/x-pack/plugins/maps/kibana.json
+++ b/x-pack/plugins/maps/kibana.json
@@ -21,7 +21,6 @@
"server": true,
"extraPublicDirs": ["common/constants"],
"requiredBundles": [
- "charts",
"kibanaReact",
"kibanaUtils",
"savedObjects"
diff --git a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts
index 551e20fc5ceb5..26a0ffc1b1a37 100644
--- a/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts
+++ b/x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts
@@ -126,7 +126,7 @@ function getClusterStyleDescriptor(
),
}
: undefined;
- // @ts-ignore
+ // @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.DYNAMIC,
options: {
@@ -136,7 +136,7 @@ function getClusterStyleDescriptor(
};
} else {
// copy static styles to cluster style
- // @ts-ignore
+ // @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.STATIC,
options: { ...styleProperty.getOptions() },
@@ -192,8 +192,8 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
const requestMeta = sourceDataRequest.getMeta();
if (
requestMeta &&
- requestMeta.sourceType &&
- requestMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
+ requestMeta.sourceMeta &&
+ requestMeta.sourceMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
) {
isClustered = true;
}
@@ -220,8 +220,12 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
: displayName;
}
- isJoinable() {
- return false;
+ showJoinEditor() {
+ return true;
+ }
+
+ getJoinsDisabledReason() {
+ return this._documentSource.getJoinsDisabledReason();
}
getJoins() {
diff --git a/x-pack/plugins/maps/public/classes/layers/layer.tsx b/x-pack/plugins/maps/public/classes/layers/layer.tsx
index d6f6ee8fa609b..d8def155a9185 100644
--- a/x-pack/plugins/maps/public/classes/layers/layer.tsx
+++ b/x-pack/plugins/maps/public/classes/layers/layer.tsx
@@ -78,6 +78,8 @@ export interface ILayer {
isPreviewLayer: () => boolean;
areLabelsOnTop: () => boolean;
supportsLabelsOnTop: () => boolean;
+ showJoinEditor(): boolean;
+ getJoinsDisabledReason(): string | null;
}
export type Footnote = {
icon: ReactElement;
@@ -141,13 +143,12 @@ export class AbstractLayer implements ILayer {
}
static getBoundDataForSource(mbMap: unknown, sourceId: string): FeatureCollection {
- // @ts-ignore
+ // @ts-expect-error
const mbStyle = mbMap.getStyle();
return mbStyle.sources[sourceId].data;
}
async cloneDescriptor(): Promise {
- // @ts-ignore
const clonedDescriptor = copyPersistentState(this._descriptor);
// layer id is uuid used to track styles/layers in mapbox
clonedDescriptor.id = uuid();
@@ -155,14 +156,10 @@ export class AbstractLayer implements ILayer {
clonedDescriptor.label = `Clone of ${displayName}`;
clonedDescriptor.sourceDescriptor = this.getSource().cloneDescriptor();
- // todo: remove this
- // This should not be in AbstractLayer. It relies on knowledge of VectorLayerDescriptor
- // @ts-ignore
if (clonedDescriptor.joins) {
- // @ts-ignore
+ // @ts-expect-error
clonedDescriptor.joins.forEach((joinDescriptor) => {
// right.id is uuid used to track requests in inspector
- // @ts-ignore
joinDescriptor.right.id = uuid();
});
}
@@ -173,8 +170,12 @@ export class AbstractLayer implements ILayer {
return `${this.getId()}${MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER}${layerNameSuffix}`;
}
- isJoinable(): boolean {
- return this.getSource().isJoinable();
+ showJoinEditor(): boolean {
+ return this.getSource().showJoinEditor();
+ }
+
+ getJoinsDisabledReason() {
+ return this.getSource().getJoinsDisabledReason();
}
isPreviewLayer(): boolean {
@@ -394,7 +395,6 @@ export class AbstractLayer implements ILayer {
const requestTokens = this._dataRequests.map((dataRequest) => dataRequest.getRequestToken());
// Compact removes all the undefineds
- // @ts-ignore
return _.compact(requestTokens);
}
@@ -478,7 +478,7 @@ export class AbstractLayer implements ILayer {
}
syncVisibilityWithMb(mbMap: unknown, mbLayerId: string) {
- // @ts-ignore
+ // @ts-expect-error
mbMap.setLayoutProperty(mbLayerId, 'visibility', this.isVisible() ? 'visible' : 'none');
}
diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/clusters_layer_wizard.tsx b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/clusters_layer_wizard.tsx
index 715c16b22dc51..ee97fdd0a2bf6 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/clusters_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/clusters_layer_wizard.tsx
@@ -28,7 +28,7 @@ import {
VECTOR_STYLES,
STYLE_TYPE,
} from '../../../../common/constants';
-import { COLOR_GRADIENTS } from '../../styles/color_utils';
+import { NUMERICAL_COLOR_PALETTES } from '../../styles/color_palettes';
export const clustersLayerWizardConfig: LayerWizard = {
categories: [LAYER_WIZARD_CATEGORY.ELASTICSEARCH],
@@ -57,7 +57,7 @@ export const clustersLayerWizardConfig: LayerWizard = {
name: COUNT_PROP_NAME,
origin: FIELD_ORIGIN.SOURCE,
},
- color: COLOR_GRADIENTS[0].value,
+ color: NUMERICAL_COLOR_PALETTES[0].value,
type: COLOR_MAP_TYPE.ORDINAL,
},
},
diff --git a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js
index 9431fb55dc88b..1be74140fe1bf 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js
+++ b/x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js
@@ -63,6 +63,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
getSyncMeta() {
return {
requestType: this._descriptor.requestType,
+ sourceType: SOURCE_TYPES.ES_GEO_GRID,
};
}
@@ -103,7 +104,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
return true;
}
- isJoinable() {
+ showJoinEditor() {
return false;
}
@@ -307,7 +308,6 @@ export class ESGeoGridSource extends AbstractESAggSource {
},
meta: {
areResultsTrimmed: false,
- sourceType: SOURCE_TYPES.ES_GEO_GRID,
},
};
}
diff --git a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js
index a4cff7c89a011..98db7bcdcc8a3 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js
+++ b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js
@@ -51,7 +51,7 @@ export class ESPewPewSource extends AbstractESAggSource {
return true;
}
- isJoinable() {
+ showJoinEditor() {
return false;
}
diff --git a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/point_2_point_layer_wizard.tsx b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/point_2_point_layer_wizard.tsx
index ae7414b827c8d..fee84d0208978 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/point_2_point_layer_wizard.tsx
+++ b/x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/point_2_point_layer_wizard.tsx
@@ -18,7 +18,7 @@ import {
VECTOR_STYLES,
STYLE_TYPE,
} from '../../../../common/constants';
-import { COLOR_GRADIENTS } from '../../styles/color_utils';
+import { NUMERICAL_COLOR_PALETTES } from '../../styles/color_palettes';
// @ts-ignore
import { CreateSourceEditor } from './create_source_editor';
import { LayerWizard, RenderWizardArguments } from '../../layers/layer_wizard_registry';
@@ -50,7 +50,7 @@ export const point2PointLayerWizardConfig: LayerWizard = {
name: COUNT_PROP_NAME,
origin: FIELD_ORIGIN.SOURCE,
},
- color: COLOR_GRADIENTS[0].value,
+ color: NUMERICAL_COLOR_PALETTES[0].value,
},
},
[VECTOR_STYLES.LINE_WIDTH]: {
diff --git a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js
index c8f14f1dc6a4b..330fa6e8318ed 100644
--- a/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js
+++ b/x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js
@@ -385,7 +385,7 @@ export class ESSearchSource extends AbstractESSource {
return {
data: featureCollection,
- meta: { ...meta, sourceType: SOURCE_TYPES.ES_SEARCH },
+ meta,
};
}
@@ -540,6 +540,7 @@ export class ESSearchSource extends AbstractESSource {
scalingType: this._descriptor.scalingType,
topHitsSplitField: this._descriptor.topHitsSplitField,
topHitsSize: this._descriptor.topHitsSize,
+ sourceType: SOURCE_TYPES.ES_SEARCH,
};
}
@@ -551,6 +552,14 @@ export class ESSearchSource extends AbstractESSource {
path: geoField.name,
};
}
+
+ getJoinsDisabledReason() {
+ return this._descriptor.scalingType === SCALING_TYPES.CLUSTERS
+ ? i18n.translate('xpack.maps.source.esSearch.joinsDisabledReason', {
+ defaultMessage: 'Joins are not supported when scaling by clusters',
+ })
+ : null;
+ }
}
registerSource({
diff --git a/x-pack/plugins/maps/public/classes/sources/source.ts b/x-pack/plugins/maps/public/classes/sources/source.ts
index c68e22ada8b0c..696c07376575b 100644
--- a/x-pack/plugins/maps/public/classes/sources/source.ts
+++ b/x-pack/plugins/maps/public/classes/sources/source.ts
@@ -54,7 +54,8 @@ export interface ISource {
isESSource(): boolean;
renderSourceSettingsEditor({ onChange }: SourceEditorArgs): ReactElement | null;
supportsFitToBounds(): Promise;
- isJoinable(): boolean;
+ showJoinEditor(): boolean;
+ getJoinsDisabledReason(): string | null;
cloneDescriptor(): SourceDescriptor;
getFieldNames(): string[];
getApplyGlobalQuery(): boolean;
@@ -80,7 +81,6 @@ export class AbstractSource implements ISource {
destroy(): void {}
cloneDescriptor(): SourceDescriptor {
- // @ts-ignore
return copyPersistentState(this._descriptor);
}
@@ -148,10 +148,14 @@ export class AbstractSource implements ISource {
return 0;
}
- isJoinable(): boolean {
+ showJoinEditor(): boolean {
return false;
}
+ getJoinsDisabledReason() {
+ return null;
+ }
+
isESSource(): boolean {
return false;
}
diff --git a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.js b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.js
index ecb13bb875721..98ed89a6ff0ad 100644
--- a/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.js
+++ b/x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.js
@@ -122,7 +122,7 @@ export class AbstractVectorSource extends AbstractSource {
return false;
}
- isJoinable() {
+ showJoinEditor() {
return true;
}
diff --git a/x-pack/plugins/maps/public/classes/styles/_index.scss b/x-pack/plugins/maps/public/classes/styles/_index.scss
index 3ee713ffc1a02..bd1467bed9d4e 100644
--- a/x-pack/plugins/maps/public/classes/styles/_index.scss
+++ b/x-pack/plugins/maps/public/classes/styles/_index.scss
@@ -1,4 +1,4 @@
-@import 'components/color_gradient';
+@import 'heatmap/components/legend/color_gradient';
@import 'vector/components/style_prop_editor';
@import 'vector/components/color/color_stops';
@import 'vector/components/symbol/icon_select';
diff --git a/x-pack/plugins/maps/public/classes/styles/color_palettes.test.ts b/x-pack/plugins/maps/public/classes/styles/color_palettes.test.ts
new file mode 100644
index 0000000000000..b964ecf6d6b63
--- /dev/null
+++ b/x-pack/plugins/maps/public/classes/styles/color_palettes.test.ts
@@ -0,0 +1,58 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+import {
+ getColorRampCenterColor,
+ getOrdinalMbColorRampStops,
+ getColorPalette,
+} from './color_palettes';
+
+describe('getColorPalette', () => {
+ it('Should create RGB color ramp', () => {
+ expect(getColorPalette('Blues')).toEqual([
+ '#ecf1f7',
+ '#d9e3ef',
+ '#c5d5e7',
+ '#b2c7df',
+ '#9eb9d8',
+ '#8bacd0',
+ '#769fc8',
+ '#6092c0',
+ ]);
+ });
+});
+
+describe('getColorRampCenterColor', () => {
+ it('Should get center color from color ramp', () => {
+ expect(getColorRampCenterColor('Blues')).toBe('#9eb9d8');
+ });
+});
+
+describe('getOrdinalMbColorRampStops', () => {
+ it('Should create color stops for custom range', () => {
+ expect(getOrdinalMbColorRampStops('Blues', 0, 1000)).toEqual([
+ 0,
+ '#ecf1f7',
+ 125,
+ '#d9e3ef',
+ 250,
+ '#c5d5e7',
+ 375,
+ '#b2c7df',
+ 500,
+ '#9eb9d8',
+ 625,
+ '#8bacd0',
+ 750,
+ '#769fc8',
+ 875,
+ '#6092c0',
+ ]);
+ });
+
+ it('Should snap to end of color stops for identical range', () => {
+ expect(getOrdinalMbColorRampStops('Blues', 23, 23)).toEqual([23, '#6092c0']);
+ });
+});
diff --git a/x-pack/plugins/maps/public/classes/styles/color_palettes.ts b/x-pack/plugins/maps/public/classes/styles/color_palettes.ts
new file mode 100644
index 0000000000000..e7574b4e7b3e4
--- /dev/null
+++ b/x-pack/plugins/maps/public/classes/styles/color_palettes.ts
@@ -0,0 +1,172 @@
+/*
+ * 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 tinycolor from 'tinycolor2';
+import {
+ // @ts-ignore
+ euiPaletteForStatus,
+ // @ts-ignore
+ euiPaletteForTemperature,
+ // @ts-ignore
+ euiPaletteCool,
+ // @ts-ignore
+ euiPaletteWarm,
+ // @ts-ignore
+ euiPaletteNegative,
+ // @ts-ignore
+ euiPalettePositive,
+ // @ts-ignore
+ euiPaletteGray,
+ // @ts-ignore
+ euiPaletteColorBlind,
+} from '@elastic/eui/lib/services';
+import { EuiColorPalettePickerPaletteProps } from '@elastic/eui';
+
+export const DEFAULT_HEATMAP_COLOR_RAMP_NAME = 'theclassic';
+
+export const DEFAULT_FILL_COLORS: string[] = euiPaletteColorBlind();
+export const DEFAULT_LINE_COLORS: string[] = [
+ ...DEFAULT_FILL_COLORS.map((color: string) => tinycolor(color).darken().toHexString()),
+ // Explicitly add black & white as border color options
+ '#000',
+ '#FFF',
+];
+
+const COLOR_PALETTES: EuiColorPalettePickerPaletteProps[] = [
+ {
+ value: 'Blues',
+ palette: euiPaletteCool(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Greens',
+ palette: euiPalettePositive(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Greys',
+ palette: euiPaletteGray(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Reds',
+ palette: euiPaletteNegative(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Yellow to Red',
+ palette: euiPaletteWarm(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Green to Red',
+ palette: euiPaletteForStatus(8),
+ type: 'gradient',
+ },
+ {
+ value: 'Blue to Red',
+ palette: euiPaletteForTemperature(8),
+ type: 'gradient',
+ },
+ {
+ value: DEFAULT_HEATMAP_COLOR_RAMP_NAME,
+ palette: [
+ 'rgb(65, 105, 225)', // royalblue
+ 'rgb(0, 256, 256)', // cyan
+ 'rgb(0, 256, 0)', // lime
+ 'rgb(256, 256, 0)', // yellow
+ 'rgb(256, 0, 0)', // red
+ ],
+ type: 'gradient',
+ },
+ {
+ value: 'palette_0',
+ palette: euiPaletteColorBlind(),
+ type: 'fixed',
+ },
+ {
+ value: 'palette_20',
+ palette: euiPaletteColorBlind({ rotations: 2 }),
+ type: 'fixed',
+ },
+ {
+ value: 'palette_30',
+ palette: euiPaletteColorBlind({ rotations: 3 }),
+ type: 'fixed',
+ },
+];
+
+export const NUMERICAL_COLOR_PALETTES = COLOR_PALETTES.filter(
+ (palette: EuiColorPalettePickerPaletteProps) => {
+ return palette.type === 'gradient';
+ }
+);
+
+export const CATEGORICAL_COLOR_PALETTES = COLOR_PALETTES.filter(
+ (palette: EuiColorPalettePickerPaletteProps) => {
+ return palette.type === 'fixed';
+ }
+);
+
+export function getColorPalette(colorPaletteId: string): string[] {
+ const colorPalette = COLOR_PALETTES.find(({ value }: EuiColorPalettePickerPaletteProps) => {
+ return value === colorPaletteId;
+ });
+ return colorPalette ? (colorPalette.palette as string[]) : [];
+}
+
+export function getColorRampCenterColor(colorPaletteId: string): string | null {
+ if (!colorPaletteId) {
+ return null;
+ }
+ const palette = getColorPalette(colorPaletteId);
+ return palette.length === 0 ? null : palette[Math.floor(palette.length / 2)];
+}
+
+// Returns an array of color stops
+// [ stop_input_1: number, stop_output_1: color, stop_input_n: number, stop_output_n: color ]
+export function getOrdinalMbColorRampStops(
+ colorPaletteId: string,
+ min: number,
+ max: number
+): Array | null {
+ if (!colorPaletteId) {
+ return null;
+ }
+
+ if (min > max) {
+ return null;
+ }
+
+ const palette = getColorPalette(colorPaletteId);
+ if (palette.length === 0) {
+ return null;
+ }
+
+ if (max === min) {
+ // just return single stop value
+ return [max, palette[palette.length - 1]];
+ }
+
+ const delta = max - min;
+ return palette.reduce(
+ (accu: Array, stopColor: string, idx: number, srcArr: string[]) => {
+ const stopNumber = min + (delta * idx) / srcArr.length;
+ return [...accu, stopNumber, stopColor];
+ },
+ []
+ );
+}
+
+export function getLinearGradient(colorStrings: string[]): string {
+ const intervals = colorStrings.length;
+ let linearGradient = `linear-gradient(to right, ${colorStrings[0]} 0%,`;
+ for (let i = 1; i < intervals - 1; i++) {
+ linearGradient = `${linearGradient} ${colorStrings[i]} \
+ ${Math.floor((100 * i) / (intervals - 1))}%,`;
+ }
+ return `${linearGradient} ${colorStrings[colorStrings.length - 1]} 100%)`;
+}
diff --git a/x-pack/plugins/maps/public/classes/styles/color_utils.test.ts b/x-pack/plugins/maps/public/classes/styles/color_utils.test.ts
deleted file mode 100644
index ed7cafd53a6fc..0000000000000
--- a/x-pack/plugins/maps/public/classes/styles/color_utils.test.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-import {
- COLOR_GRADIENTS,
- getColorRampCenterColor,
- getOrdinalMbColorRampStops,
- getHexColorRangeStrings,
- getLinearGradient,
- getRGBColorRangeStrings,
-} from './color_utils';
-
-jest.mock('ui/new_platform');
-
-describe('COLOR_GRADIENTS', () => {
- it('Should contain EuiSuperSelect options list of color ramps', () => {
- expect(COLOR_GRADIENTS.length).toBe(6);
- const colorGradientOption = COLOR_GRADIENTS[0];
- expect(colorGradientOption.value).toBe('Blues');
- });
-});
-
-describe('getRGBColorRangeStrings', () => {
- it('Should create RGB color ramp', () => {
- expect(getRGBColorRangeStrings('Blues', 8)).toEqual([
- 'rgb(247,250,255)',
- 'rgb(221,234,247)',
- 'rgb(197,218,238)',
- 'rgb(157,201,224)',
- 'rgb(106,173,213)',
- 'rgb(65,145,197)',
- 'rgb(32,112,180)',
- 'rgb(7,47,107)',
- ]);
- });
-});
-
-describe('getHexColorRangeStrings', () => {
- it('Should create HEX color ramp', () => {
- expect(getHexColorRangeStrings('Blues')).toEqual([
- '#f7faff',
- '#ddeaf7',
- '#c5daee',
- '#9dc9e0',
- '#6aadd5',
- '#4191c5',
- '#2070b4',
- '#072f6b',
- ]);
- });
-});
-
-describe('getColorRampCenterColor', () => {
- it('Should get center color from color ramp', () => {
- expect(getColorRampCenterColor('Blues')).toBe('rgb(106,173,213)');
- });
-});
-
-describe('getColorRampStops', () => {
- it('Should create color stops for custom range', () => {
- expect(getOrdinalMbColorRampStops('Blues', 0, 1000, 8)).toEqual([
- 0,
- '#f7faff',
- 125,
- '#ddeaf7',
- 250,
- '#c5daee',
- 375,
- '#9dc9e0',
- 500,
- '#6aadd5',
- 625,
- '#4191c5',
- 750,
- '#2070b4',
- 875,
- '#072f6b',
- ]);
- });
-
- it('Should snap to end of color stops for identical range', () => {
- expect(getOrdinalMbColorRampStops('Blues', 23, 23, 8)).toEqual([23, '#072f6b']);
- });
-});
-
-describe('getLinearGradient', () => {
- it('Should create linear gradient from color ramp', () => {
- const colorRamp = [
- 'rgb(247,250,255)',
- 'rgb(221,234,247)',
- 'rgb(197,218,238)',
- 'rgb(157,201,224)',
- 'rgb(106,173,213)',
- 'rgb(65,145,197)',
- 'rgb(32,112,180)',
- 'rgb(7,47,107)',
- ];
- expect(getLinearGradient(colorRamp)).toBe(
- 'linear-gradient(to right, rgb(247,250,255) 0%, rgb(221,234,247) 14%, rgb(197,218,238) 28%, rgb(157,201,224) 42%, rgb(106,173,213) 57%, rgb(65,145,197) 71%, rgb(32,112,180) 85%, rgb(7,47,107) 100%)'
- );
- });
-});
diff --git a/x-pack/plugins/maps/public/classes/styles/color_utils.tsx b/x-pack/plugins/maps/public/classes/styles/color_utils.tsx
deleted file mode 100644
index 0192a9d7ca68f..0000000000000
--- a/x-pack/plugins/maps/public/classes/styles/color_utils.tsx
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-import React from 'react';
-import tinycolor from 'tinycolor2';
-import chroma from 'chroma-js';
-// @ts-ignore
-import { euiPaletteColorBlind } from '@elastic/eui/lib/services';
-import { ColorGradient } from './components/color_gradient';
-import { RawColorSchema, vislibColorMaps } from '../../../../../../src/plugins/charts/public';
-
-export const GRADIENT_INTERVALS = 8;
-
-export const DEFAULT_FILL_COLORS: string[] = euiPaletteColorBlind();
-export const DEFAULT_LINE_COLORS: string[] = [
- ...DEFAULT_FILL_COLORS.map((color: string) => tinycolor(color).darken().toHexString()),
- // Explicitly add black & white as border color options
- '#000',
- '#FFF',
-];
-
-function getRGBColors(colorRamp: Array<[number, number[]]>, numLegendColors: number = 4): string[] {
- const colors = [];
- colors[0] = getRGBColor(colorRamp, 0);
- for (let i = 1; i < numLegendColors - 1; i++) {
- colors[i] = getRGBColor(colorRamp, Math.floor((colorRamp.length * i) / numLegendColors));
- }
- colors[numLegendColors - 1] = getRGBColor(colorRamp, colorRamp.length - 1);
- return colors;
-}
-
-function getRGBColor(colorRamp: Array<[number, number[]]>, i: number): string {
- const rgbArray = colorRamp[i][1];
- const red = Math.floor(rgbArray[0] * 255);
- const green = Math.floor(rgbArray[1] * 255);
- const blue = Math.floor(rgbArray[2] * 255);
- return `rgb(${red},${green},${blue})`;
-}
-
-function getColorSchema(colorRampName: string): RawColorSchema {
- const colorSchema = vislibColorMaps[colorRampName];
- if (!colorSchema) {
- throw new Error(
- `${colorRampName} not found. Expected one of following values: ${Object.keys(
- vislibColorMaps
- )}`
- );
- }
- return colorSchema;
-}
-
-export function getRGBColorRangeStrings(
- colorRampName: string,
- numberColors: number = GRADIENT_INTERVALS
-): string[] {
- const colorSchema = getColorSchema(colorRampName);
- return getRGBColors(colorSchema.value, numberColors);
-}
-
-export function getHexColorRangeStrings(
- colorRampName: string,
- numberColors: number = GRADIENT_INTERVALS
-): string[] {
- return getRGBColorRangeStrings(colorRampName, numberColors).map((rgbColor) =>
- chroma(rgbColor).hex()
- );
-}
-
-export function getColorRampCenterColor(colorRampName: string): string | null {
- if (!colorRampName) {
- return null;
- }
- const colorSchema = getColorSchema(colorRampName);
- const centerIndex = Math.floor(colorSchema.value.length / 2);
- return getRGBColor(colorSchema.value, centerIndex);
-}
-
-// Returns an array of color stops
-// [ stop_input_1: number, stop_output_1: color, stop_input_n: number, stop_output_n: color ]
-export function getOrdinalMbColorRampStops(
- colorRampName: string,
- min: number,
- max: number,
- numberColors: number
-): Array | null {
- if (!colorRampName) {
- return null;
- }
-
- if (min > max) {
- return null;
- }
-
- const hexColors = getHexColorRangeStrings(colorRampName, numberColors);
- if (max === min) {
- // just return single stop value
- return [max, hexColors[hexColors.length - 1]];
- }
-
- const delta = max - min;
- return hexColors.reduce(
- (accu: Array, stopColor: string, idx: number, srcArr: string[]) => {
- const stopNumber = min + (delta * idx) / srcArr.length;
- return [...accu, stopNumber, stopColor];
- },
- []
- );
-}
-
-export const COLOR_GRADIENTS = Object.keys(vislibColorMaps).map((colorRampName) => ({
- value: colorRampName,
- inputDisplay: ,
-}));
-
-export const COLOR_RAMP_NAMES = Object.keys(vislibColorMaps);
-
-export function getLinearGradient(colorStrings: string[]): string {
- const intervals = colorStrings.length;
- let linearGradient = `linear-gradient(to right, ${colorStrings[0]} 0%,`;
- for (let i = 1; i < intervals - 1; i++) {
- linearGradient = `${linearGradient} ${colorStrings[i]} \
- ${Math.floor((100 * i) / (intervals - 1))}%,`;
- }
- return `${linearGradient} ${colorStrings[colorStrings.length - 1]} 100%)`;
-}
-
-export interface ColorPalette {
- id: string;
- colors: string[];
-}
-
-const COLOR_PALETTES_CONFIGS: ColorPalette[] = [
- {
- id: 'palette_0',
- colors: euiPaletteColorBlind(),
- },
- {
- id: 'palette_20',
- colors: euiPaletteColorBlind({ rotations: 2 }),
- },
- {
- id: 'palette_30',
- colors: euiPaletteColorBlind({ rotations: 3 }),
- },
-];
-
-export function getColorPalette(paletteId: string): string[] | null {
- const palette = COLOR_PALETTES_CONFIGS.find(({ id }: ColorPalette) => id === paletteId);
- return palette ? palette.colors : null;
-}
-
-export const COLOR_PALETTES = COLOR_PALETTES_CONFIGS.map((palette) => {
- const paletteDisplay = palette.colors.map((color) => {
- const style: React.CSSProperties = {
- backgroundColor: color,
- width: `${100 / palette.colors.length}%`,
- position: 'relative',
- height: '100%',
- display: 'inline-block',
- };
- return (
-
-
-
- );
- });
- return {
- value: palette.id,
- inputDisplay: {paletteDisplay}
,
- };
-});
diff --git a/x-pack/plugins/maps/public/classes/styles/components/color_gradient.tsx b/x-pack/plugins/maps/public/classes/styles/components/color_gradient.tsx
deleted file mode 100644
index b29146062e46d..0000000000000
--- a/x-pack/plugins/maps/public/classes/styles/components/color_gradient.tsx
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-import React from 'react';
-import {
- COLOR_RAMP_NAMES,
- GRADIENT_INTERVALS,
- getRGBColorRangeStrings,
- getLinearGradient,
-} from '../color_utils';
-
-interface Props {
- colorRamp?: string[];
- colorRampName?: string;
-}
-
-export const ColorGradient = ({ colorRamp, colorRampName }: Props) => {
- if (!colorRamp && (!colorRampName || !COLOR_RAMP_NAMES.includes(colorRampName))) {
- return null;
- }
-
- const rgbColorStrings = colorRampName
- ? getRGBColorRangeStrings(colorRampName, GRADIENT_INTERVALS)
- : colorRamp!;
- const background = getLinearGradient(rgbColorStrings);
- return
;
-};
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.tsx.snap b/x-pack/plugins/maps/public/classes/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.tsx.snap
index 9d07b9c641e0f..7c42b78fdc552 100644
--- a/x-pack/plugins/maps/public/classes/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.tsx.snap
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/components/__snapshots__/heatmap_style_editor.test.tsx.snap
@@ -10,66 +10,120 @@ exports[`HeatmapStyleEditor is rendered 1`] = `
label="Color range"
labelType="label"
>
- ,
- "text": "theclassic",
- "value": "theclassic",
- },
- Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#ecf1f7",
+ "#d9e3ef",
+ "#c5d5e7",
+ "#b2c7df",
+ "#9eb9d8",
+ "#8bacd0",
+ "#769fc8",
+ "#6092c0",
+ ],
+ "type": "gradient",
"value": "Blues",
},
Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#e6f1ee",
+ "#cce4de",
+ "#b3d6cd",
+ "#9ac8bd",
+ "#80bbae",
+ "#65ad9e",
+ "#47a08f",
+ "#209280",
+ ],
+ "type": "gradient",
"value": "Greens",
},
Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#e0e4eb",
+ "#c2c9d5",
+ "#a6afbf",
+ "#8c95a5",
+ "#757c8b",
+ "#5e6471",
+ "#494d58",
+ "#343741",
+ ],
+ "type": "gradient",
"value": "Greys",
},
Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#fdeae5",
+ "#f9d5cc",
+ "#f4c0b4",
+ "#eeab9c",
+ "#e79685",
+ "#df816e",
+ "#d66c58",
+ "#cc5642",
+ ],
+ "type": "gradient",
"value": "Reds",
},
Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#f9eac5",
+ "#f6d9af",
+ "#f3c89a",
+ "#efb785",
+ "#eba672",
+ "#e89361",
+ "#e58053",
+ "#e7664c",
+ ],
+ "type": "gradient",
"value": "Yellow to Red",
},
Object {
- "inputDisplay": ,
+ "palette": Array [
+ "#209280",
+ "#3aa38d",
+ "#54b399",
+ "#95b978",
+ "#df9352",
+ "#e7664c",
+ "#da5e47",
+ "#cc5642",
+ ],
+ "type": "gradient",
"value": "Green to Red",
},
+ Object {
+ "palette": Array [
+ "#6092c0",
+ "#84a9cd",
+ "#a8bfda",
+ "#cad7e8",
+ "#f0d3b0",
+ "#ecb385",
+ "#ea8d69",
+ "#e7664c",
+ ],
+ "type": "gradient",
+ "value": "Blue to Red",
+ },
+ Object {
+ "palette": Array [
+ "rgb(65, 105, 225)",
+ "rgb(0, 256, 256)",
+ "rgb(0, 256, 0)",
+ "rgb(256, 256, 0)",
+ "rgb(256, 0, 0)",
+ ],
+ "type": "gradient",
+ "value": "theclassic",
+ },
]
}
valueOfSelected="Blues"
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_constants.ts b/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_constants.ts
index 583c78e56581b..b043c2791b146 100644
--- a/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_constants.ts
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_constants.ts
@@ -6,17 +6,6 @@
import { i18n } from '@kbn/i18n';
-// Color stops from default Mapbox heatmap-color
-export const DEFAULT_RGB_HEATMAP_COLOR_RAMP = [
- 'rgb(65, 105, 225)', // royalblue
- 'rgb(0, 256, 256)', // cyan
- 'rgb(0, 256, 0)', // lime
- 'rgb(256, 256, 0)', // yellow
- 'rgb(256, 0, 0)', // red
-];
-
-export const DEFAULT_HEATMAP_COLOR_RAMP_NAME = 'theclassic';
-
export const HEATMAP_COLOR_RAMP_LABEL = i18n.translate('xpack.maps.heatmap.colorRampLabel', {
defaultMessage: 'Color range',
});
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_style_editor.tsx b/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_style_editor.tsx
index d15fdbd79de75..48713f1ddfd4b 100644
--- a/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_style_editor.tsx
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/components/heatmap_style_editor.tsx
@@ -6,14 +6,9 @@
import React from 'react';
-import { EuiFormRow, EuiSuperSelect } from '@elastic/eui';
-import { COLOR_GRADIENTS } from '../../color_utils';
-import { ColorGradient } from '../../components/color_gradient';
-import {
- DEFAULT_RGB_HEATMAP_COLOR_RAMP,
- DEFAULT_HEATMAP_COLOR_RAMP_NAME,
- HEATMAP_COLOR_RAMP_LABEL,
-} from './heatmap_constants';
+import { EuiFormRow, EuiColorPalettePicker } from '@elastic/eui';
+import { NUMERICAL_COLOR_PALETTES } from '../../color_palettes';
+import { HEATMAP_COLOR_RAMP_LABEL } from './heatmap_constants';
interface Props {
colorRampName: string;
@@ -21,28 +16,18 @@ interface Props {
}
export function HeatmapStyleEditor({ colorRampName, onHeatmapColorChange }: Props) {
- const onColorRampChange = (selectedColorRampName: string) => {
+ const onColorRampChange = (selectedPaletteId: string) => {
onHeatmapColorChange({
- colorRampName: selectedColorRampName,
+ colorRampName: selectedPaletteId,
});
};
- const colorRampOptions = [
- {
- value: DEFAULT_HEATMAP_COLOR_RAMP_NAME,
- text: DEFAULT_HEATMAP_COLOR_RAMP_NAME,
- inputDisplay: ,
- },
- ...COLOR_GRADIENTS,
- ];
-
return (
-
diff --git a/x-pack/plugins/maps/public/classes/styles/components/_color_gradient.scss b/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/_color_gradient.scss
similarity index 100%
rename from x-pack/plugins/maps/public/classes/styles/components/_color_gradient.scss
rename to x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/_color_gradient.scss
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/color_gradient.tsx b/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/color_gradient.tsx
new file mode 100644
index 0000000000000..b4a241f625683
--- /dev/null
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/color_gradient.tsx
@@ -0,0 +1,19 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { getColorPalette, getLinearGradient } from '../../../color_palettes';
+
+interface Props {
+ colorPaletteId: string;
+}
+
+export const ColorGradient = ({ colorPaletteId }: Props) => {
+ const palette = getColorPalette(colorPaletteId);
+ return palette.length ? (
+
+ ) : null;
+};
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/heatmap_legend.js b/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/heatmap_legend.js
index 1d8dfe9c7bdbf..5c3600a149afe 100644
--- a/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/heatmap_legend.js
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/components/legend/heatmap_legend.js
@@ -7,13 +7,9 @@
import React from 'react';
import { i18n } from '@kbn/i18n';
-import { ColorGradient } from '../../../components/color_gradient';
+import { ColorGradient } from './color_gradient';
import { RangedStyleLegendRow } from '../../../components/ranged_style_legend_row';
-import {
- DEFAULT_RGB_HEATMAP_COLOR_RAMP,
- DEFAULT_HEATMAP_COLOR_RAMP_NAME,
- HEATMAP_COLOR_RAMP_LABEL,
-} from '../heatmap_constants';
+import { HEATMAP_COLOR_RAMP_LABEL } from '../heatmap_constants';
export class HeatmapLegend extends React.Component {
constructor() {
@@ -41,17 +37,9 @@ export class HeatmapLegend extends React.Component {
}
render() {
- const colorRampName = this.props.colorRampName;
- const header =
- colorRampName === DEFAULT_HEATMAP_COLOR_RAMP_NAME ? (
-
- ) : (
-
- );
-
return (
}
minLabel={i18n.translate('xpack.maps.heatmapLegend.coldLabel', {
defaultMessage: 'cold',
})}
diff --git a/x-pack/plugins/maps/public/classes/styles/heatmap/heatmap_style.js b/x-pack/plugins/maps/public/classes/styles/heatmap/heatmap_style.js
index 5f920d0ba52d3..55bbbc9319dfb 100644
--- a/x-pack/plugins/maps/public/classes/styles/heatmap/heatmap_style.js
+++ b/x-pack/plugins/maps/public/classes/styles/heatmap/heatmap_style.js
@@ -8,15 +8,15 @@ import React from 'react';
import { AbstractStyle } from '../style';
import { HeatmapStyleEditor } from './components/heatmap_style_editor';
import { HeatmapLegend } from './components/legend/heatmap_legend';
-import { DEFAULT_HEATMAP_COLOR_RAMP_NAME } from './components/heatmap_constants';
+import { DEFAULT_HEATMAP_COLOR_RAMP_NAME, getOrdinalMbColorRampStops } from '../color_palettes';
import { LAYER_STYLE_TYPE, GRID_RESOLUTION } from '../../../../common/constants';
-import { getOrdinalMbColorRampStops, GRADIENT_INTERVALS } from '../color_utils';
+
import { i18n } from '@kbn/i18n';
import { EuiIcon } from '@elastic/eui';
//The heatmap range chosen hear runs from 0 to 1. It is arbitrary.
//Weighting is on the raw count/sum values.
-const MIN_RANGE = 0;
+const MIN_RANGE = 0.1; // 0 to 0.1 is displayed as transparent color stop
const MAX_RANGE = 1;
export class HeatmapStyle extends AbstractStyle {
@@ -83,40 +83,19 @@ export class HeatmapStyle extends AbstractStyle {
property: propertyName,
});
- const { colorRampName } = this._descriptor;
- if (colorRampName && colorRampName !== DEFAULT_HEATMAP_COLOR_RAMP_NAME) {
- const colorStops = getOrdinalMbColorRampStops(
- colorRampName,
- MIN_RANGE,
- MAX_RANGE,
- GRADIENT_INTERVALS
- );
- // TODO handle null
- mbMap.setPaintProperty(layerId, 'heatmap-color', [
- 'interpolate',
- ['linear'],
- ['heatmap-density'],
- 0,
- 'rgba(0, 0, 255, 0)',
- ...colorStops.slice(2), // remove first stop from colorStops to avoid conflict with transparent stop at zero
- ]);
- } else {
+ const colorStops = getOrdinalMbColorRampStops(
+ this._descriptor.colorRampName,
+ MIN_RANGE,
+ MAX_RANGE
+ );
+ if (colorStops) {
mbMap.setPaintProperty(layerId, 'heatmap-color', [
'interpolate',
['linear'],
['heatmap-density'],
0,
'rgba(0, 0, 255, 0)',
- 0.1,
- 'royalblue',
- 0.3,
- 'cyan',
- 0.5,
- 'lime',
- 0.7,
- 'yellow',
- 1,
- 'red',
+ ...colorStops,
]);
}
}
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/color/color_map_select.js b/x-pack/plugins/maps/public/classes/styles/vector/components/color/color_map_select.js
index fe2f302504a15..a7d849265d815 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/components/color/color_map_select.js
+++ b/x-pack/plugins/maps/public/classes/styles/vector/components/color/color_map_select.js
@@ -6,10 +6,17 @@
import React, { Component, Fragment } from 'react';
-import { EuiSpacer, EuiSelect, EuiSuperSelect, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
+import {
+ EuiSpacer,
+ EuiSelect,
+ EuiColorPalettePicker,
+ EuiFlexGroup,
+ EuiFlexItem,
+} from '@elastic/eui';
import { ColorStopsOrdinal } from './color_stops_ordinal';
import { COLOR_MAP_TYPE } from '../../../../../../common/constants';
import { ColorStopsCategorical } from './color_stops_categorical';
+import { CATEGORICAL_COLOR_PALETTES, NUMERICAL_COLOR_PALETTES } from '../../../color_palettes';
import { i18n } from '@kbn/i18n';
const CUSTOM_COLOR_MAP = 'CUSTOM_COLOR_MAP';
@@ -65,10 +72,10 @@ export class ColorMapSelect extends Component {
);
}
- _onColorMapSelect = (selectedValue) => {
- const useCustomColorMap = selectedValue === CUSTOM_COLOR_MAP;
+ _onColorPaletteSelect = (selectedPaletteId) => {
+ const useCustomColorMap = selectedPaletteId === CUSTOM_COLOR_MAP;
this.props.onChange({
- color: useCustomColorMap ? null : selectedValue,
+ color: useCustomColorMap ? null : selectedPaletteId,
useCustomColorMap,
type: this.props.colorMapType,
});
@@ -126,26 +133,28 @@ export class ColorMapSelect extends Component {
return null;
}
- const colorMapOptionsWithCustom = [
+ const palettes =
+ this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL
+ ? NUMERICAL_COLOR_PALETTES
+ : CATEGORICAL_COLOR_PALETTES;
+
+ const palettesWithCustom = [
{
value: CUSTOM_COLOR_MAP,
- inputDisplay: this.props.customOptionLabel,
+ title:
+ this.props.colorMapType === COLOR_MAP_TYPE.ORDINAL
+ ? i18n.translate('xpack.maps.style.customColorRampLabel', {
+ defaultMessage: 'Custom color ramp',
+ })
+ : i18n.translate('xpack.maps.style.customColorPaletteLabel', {
+ defaultMessage: 'Custom color palette',
+ }),
+ type: 'text',
'data-test-subj': `colorMapSelectOption_${CUSTOM_COLOR_MAP}`,
},
- ...this.props.colorMapOptions,
+ ...palettes,
];
- let valueOfSelected;
- if (this.props.useCustomColorMap) {
- valueOfSelected = CUSTOM_COLOR_MAP;
- } else {
- valueOfSelected = this.props.colorMapOptions.find(
- (option) => option.value === this.props.color
- )
- ? this.props.color
- : '';
- }
-
const toggle = this.props.showColorMapTypeToggle ? (
{this._renderColorMapToggle()}
) : null;
@@ -155,12 +164,13 @@ export class ColorMapSelect extends Component {
{toggle}
-
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/color/dynamic_color_form.js b/x-pack/plugins/maps/public/classes/styles/vector/components/color/dynamic_color_form.js
index 90070343a1b48..1034e8f5d6525 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/components/color/dynamic_color_form.js
+++ b/x-pack/plugins/maps/public/classes/styles/vector/components/color/dynamic_color_form.js
@@ -10,8 +10,6 @@ import { FieldSelect } from '../field_select';
import { ColorMapSelect } from './color_map_select';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common/constants';
-import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils';
-import { i18n } from '@kbn/i18n';
export function DynamicColorForm({
fields,
@@ -91,14 +89,10 @@ export function DynamicColorForm({
return (
{
fieldMetaOptions,
} as ColorDynamicOptions,
} as ColorDynamicStylePropertyDescriptor;
- expect(extractColorFromStyleProperty(colorStyleProperty, defaultColor)).toBe(
- 'rgb(106,173,213)'
- );
+ expect(extractColorFromStyleProperty(colorStyleProperty, defaultColor)).toBe('#9eb9d8');
});
});
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/legend/extract_color_from_style_property.ts b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/extract_color_from_style_property.ts
index dadb3f201fa33..4a3f45a929fd1 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/components/legend/extract_color_from_style_property.ts
+++ b/x-pack/plugins/maps/public/classes/styles/vector/components/legend/extract_color_from_style_property.ts
@@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
-// @ts-ignore
-import { getColorRampCenterColor, getColorPalette } from '../../../color_utils';
+import { getColorRampCenterColor, getColorPalette } from '../../../color_palettes';
import { COLOR_MAP_TYPE, STYLE_TYPE } from '../../../../../../common/constants';
import {
ColorDynamicOptions,
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.js b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.js
index 6528648eff552..53a3fc95adbeb 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.js
+++ b/x-pack/plugins/maps/public/classes/styles/vector/components/vector_style_editor.js
@@ -15,7 +15,7 @@ import { VectorStyleLabelEditor } from './label/vector_style_label_editor';
import { VectorStyleLabelBorderSizeEditor } from './label/vector_style_label_border_size_editor';
import { OrientationEditor } from './orientation/orientation_editor';
import { getDefaultDynamicProperties, getDefaultStaticProperties } from '../vector_style_defaults';
-import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_utils';
+import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS } from '../../color_palettes';
import { i18n } from '@kbn/i18n';
import { EuiSpacer, EuiButtonGroup, EuiFormRow, EuiSwitch } from '@elastic/eui';
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/__snapshots__/dynamic_color_property.test.js.snap b/x-pack/plugins/maps/public/classes/styles/vector/properties/__snapshots__/dynamic_color_property.test.js.snap
index 29eb52897a50e..402eab355406b 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/properties/__snapshots__/dynamic_color_property.test.js.snap
+++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/__snapshots__/dynamic_color_property.test.js.snap
@@ -175,7 +175,7 @@ exports[`ordinal Should render only single band of last color when delta is 0 1`
key="0"
>
{
- const rawStopValue = rangeFieldMeta.min + rangeFieldMeta.delta * (index / GRADIENT_INTERVALS);
+ const rawStopValue = rangeFieldMeta.min + rangeFieldMeta.delta * (index / colors.length);
return {
color,
stop: dynamicRound(rawStopValue),
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.test.js b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.test.js
index 1879b260da2e2..7992ee5b3aeaf 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.test.js
+++ b/x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.test.js
@@ -323,21 +323,21 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
-1,
'rgba(0,0,0,0)',
0,
- '#f7faff',
+ '#ecf1f7',
12.5,
- '#ddeaf7',
+ '#d9e3ef',
25,
- '#c5daee',
+ '#c5d5e7',
37.5,
- '#9dc9e0',
+ '#b2c7df',
50,
- '#6aadd5',
+ '#9eb9d8',
62.5,
- '#4191c5',
+ '#8bacd0',
75,
- '#2070b4',
+ '#769fc8',
87.5,
- '#072f6b',
+ '#6092c0',
]);
});
});
diff --git a/x-pack/plugins/maps/public/classes/styles/vector/vector_style_defaults.ts b/x-pack/plugins/maps/public/classes/styles/vector/vector_style_defaults.ts
index a6878a0d760c7..a3ae80e0a5935 100644
--- a/x-pack/plugins/maps/public/classes/styles/vector/vector_style_defaults.ts
+++ b/x-pack/plugins/maps/public/classes/styles/vector/vector_style_defaults.ts
@@ -12,11 +12,11 @@ import {
STYLE_TYPE,
} from '../../../../common/constants';
import {
- COLOR_GRADIENTS,
- COLOR_PALETTES,
DEFAULT_FILL_COLORS,
DEFAULT_LINE_COLORS,
-} from '../color_utils';
+ NUMERICAL_COLOR_PALETTES,
+ CATEGORICAL_COLOR_PALETTES,
+} from '../color_palettes';
import { VectorStylePropertiesDescriptor } from '../../../../common/descriptor_types';
// @ts-ignore
import { getUiSettings } from '../../../kibana_services';
@@ -28,8 +28,8 @@ export const DEFAULT_MAX_SIZE = 32;
export const DEFAULT_SIGMA = 3;
export const DEFAULT_LABEL_SIZE = 14;
export const DEFAULT_ICON_SIZE = 6;
-export const DEFAULT_COLOR_RAMP = COLOR_GRADIENTS[0].value;
-export const DEFAULT_COLOR_PALETTE = COLOR_PALETTES[0].value;
+export const DEFAULT_COLOR_RAMP = NUMERICAL_COLOR_PALETTES[0].value;
+export const DEFAULT_COLOR_PALETTE = CATEGORICAL_COLOR_PALETTES[0].value;
export const LINE_STYLES = [VECTOR_STYLES.LINE_COLOR, VECTOR_STYLES.LINE_WIDTH];
export const POLYGON_STYLES = [
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/__snapshots__/view.test.js.snap b/x-pack/plugins/maps/public/connected_components/layer_panel/__snapshots__/view.test.js.snap
index 1c48ed2290dce..2cf5287ae6594 100644
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/__snapshots__/view.test.js.snap
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/__snapshots__/view.test.js.snap
@@ -96,8 +96,8 @@ exports[`LayerPanel is rendered 1`] = `
"getId": [Function],
"getImmutableSourceProperties": [Function],
"getLayerTypeIconName": [Function],
- "isJoinable": [Function],
"renderSourceSettingsEditor": [Function],
+ "showJoinEditor": [Function],
"supportsElasticsearchFilters": [Function],
}
}
@@ -107,6 +107,17 @@ exports[`LayerPanel is rendered 1`] = `
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/index.js b/x-pack/plugins/maps/public/connected_components/layer_panel/index.js
index 1c8dcdb43d434..17fd41d120194 100644
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/index.js
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/index.js
@@ -12,7 +12,7 @@ import { updateSourceProp } from '../../actions';
function mapStateToProps(state = {}) {
const selectedLayer = getSelectedLayer(state);
return {
- key: selectedLayer ? `${selectedLayer.getId()}${selectedLayer.isJoinable()}` : '',
+ key: selectedLayer ? `${selectedLayer.getId()}${selectedLayer.showJoinEditor()}` : '',
selectedLayer,
};
}
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/__snapshots__/join_editor.test.tsx.snap b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/__snapshots__/join_editor.test.tsx.snap
new file mode 100644
index 0000000000000..00d7f44d6273f
--- /dev/null
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/__snapshots__/join_editor.test.tsx.snap
@@ -0,0 +1,100 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Should render callout when joins are disabled 1`] = `
+
+
+
+
+
+
+
+
+
+ Simulated disabled reason
+
+
+`;
+
+exports[`Should render join editor 1`] = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+`;
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.js b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.js
deleted file mode 100644
index cf55c16bbe0be..0000000000000
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.js
+++ /dev/null
@@ -1,31 +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 { connect } from 'react-redux';
-import { JoinEditor } from './view';
-import {
- getSelectedLayer,
- getSelectedLayerJoinDescriptors,
-} from '../../../selectors/map_selectors';
-import { setJoinsForLayer } from '../../../actions';
-
-function mapDispatchToProps(dispatch) {
- return {
- onChange: (layer, joins) => {
- dispatch(setJoinsForLayer(layer, joins));
- },
- };
-}
-
-function mapStateToProps(state = {}) {
- return {
- joins: getSelectedLayerJoinDescriptors(state),
- layer: getSelectedLayer(state),
- };
-}
-
-const connectedJoinEditor = connect(mapStateToProps, mapDispatchToProps)(JoinEditor);
-export { connectedJoinEditor as JoinEditor };
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.tsx b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.tsx
new file mode 100644
index 0000000000000..0348b38351971
--- /dev/null
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/index.tsx
@@ -0,0 +1,31 @@
+/*
+ * 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 { AnyAction, Dispatch } from 'redux';
+import { connect } from 'react-redux';
+import { JoinEditor } from './join_editor';
+import { getSelectedLayerJoinDescriptors } from '../../../selectors/map_selectors';
+import { setJoinsForLayer } from '../../../actions';
+import { MapStoreState } from '../../../reducers/store';
+import { ILayer } from '../../../classes/layers/layer';
+import { JoinDescriptor } from '../../../../common/descriptor_types';
+
+function mapStateToProps(state: MapStoreState) {
+ return {
+ joins: getSelectedLayerJoinDescriptors(state),
+ };
+}
+
+function mapDispatchToProps(dispatch: Dispatch) {
+ return {
+ onChange: (layer: ILayer, joins: JoinDescriptor[]) => {
+ dispatch(setJoinsForLayer(layer, joins));
+ },
+ };
+}
+
+const connectedJoinEditor = connect(mapStateToProps, mapDispatchToProps)(JoinEditor);
+export { connectedJoinEditor as JoinEditor };
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.test.tsx b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.test.tsx
new file mode 100644
index 0000000000000..12da1c4bb9388
--- /dev/null
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.test.tsx
@@ -0,0 +1,63 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { ILayer } from '../../../classes/layers/layer';
+import { JoinEditor } from './join_editor';
+import { shallow } from 'enzyme';
+import { JoinDescriptor } from '../../../../common/descriptor_types';
+
+class MockLayer {
+ private readonly _disableReason: string | null;
+
+ constructor(disableReason: string | null) {
+ this._disableReason = disableReason;
+ }
+
+ getJoinsDisabledReason() {
+ return this._disableReason;
+ }
+}
+
+const defaultProps = {
+ joins: [
+ {
+ leftField: 'iso2',
+ right: {
+ id: '673ff994-fc75-4c67-909b-69fcb0e1060e',
+ indexPatternTitle: 'kibana_sample_data_logs',
+ term: 'geo.src',
+ indexPatternId: 'abcde',
+ metrics: [
+ {
+ type: 'count',
+ label: 'web logs count',
+ },
+ ],
+ },
+ } as JoinDescriptor,
+ ],
+ layerDisplayName: 'myLeftJoinField',
+ leftJoinFields: [],
+ onChange: () => {},
+};
+
+test('Should render join editor', () => {
+ const component = shallow(
+
+ );
+ expect(component).toMatchSnapshot();
+});
+
+test('Should render callout when joins are disabled', () => {
+ const component = shallow(
+
+ );
+ expect(component).toMatchSnapshot();
+});
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx
new file mode 100644
index 0000000000000..c589604e85112
--- /dev/null
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/join_editor.tsx
@@ -0,0 +1,124 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React, { Fragment } from 'react';
+import uuid from 'uuid/v4';
+
+import {
+ EuiButtonEmpty,
+ EuiTitle,
+ EuiSpacer,
+ EuiToolTip,
+ EuiTextAlign,
+ EuiCallOut,
+} from '@elastic/eui';
+
+import { FormattedMessage } from '@kbn/i18n/react';
+import { i18n } from '@kbn/i18n';
+// @ts-expect-error
+import { Join } from './resources/join';
+import { ILayer } from '../../../classes/layers/layer';
+import { JoinDescriptor } from '../../../../common/descriptor_types';
+import { IField } from '../../../classes/fields/field';
+
+interface Props {
+ joins: JoinDescriptor[];
+ layer: ILayer;
+ layerDisplayName: string;
+ leftJoinFields: IField[];
+ onChange: (layer: ILayer, joins: JoinDescriptor[]) => void;
+}
+
+export function JoinEditor({ joins, layer, onChange, leftJoinFields, layerDisplayName }: Props) {
+ const renderJoins = () => {
+ return joins.map((joinDescriptor: JoinDescriptor, index: number) => {
+ const handleOnChange = (updatedDescriptor: JoinDescriptor) => {
+ onChange(layer, [...joins.slice(0, index), updatedDescriptor, ...joins.slice(index + 1)]);
+ };
+
+ const handleOnRemove = () => {
+ onChange(layer, [...joins.slice(0, index), ...joins.slice(index + 1)]);
+ };
+
+ return (
+
+
+
+
+ );
+ });
+ };
+
+ const addJoin = () => {
+ onChange(layer, [
+ ...joins,
+ {
+ right: {
+ id: uuid(),
+ applyGlobalQuery: true,
+ },
+ } as JoinDescriptor,
+ ]);
+ };
+
+ const renderContent = () => {
+ const disabledReason = layer.getJoinsDisabledReason();
+ return disabledReason ? (
+ {disabledReason}
+ ) : (
+
+ {renderJoins()}
+
+
+
+
+
+
+
+
+
+ );
+ };
+
+ return (
+
+
+
+
+
+
+
+
+
+ {renderContent()}
+
+ );
+}
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/view.js b/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/view.js
deleted file mode 100644
index 900f5c9ff53ea..0000000000000
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/join_editor/view.js
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the Elastic License;
- * you may not use this file except in compliance with the Elastic License.
- */
-
-import React, { Fragment } from 'react';
-import uuid from 'uuid/v4';
-
-import {
- EuiFlexGroup,
- EuiFlexItem,
- EuiButtonIcon,
- EuiTitle,
- EuiSpacer,
- EuiToolTip,
-} from '@elastic/eui';
-
-import { Join } from './resources/join';
-import { FormattedMessage } from '@kbn/i18n/react';
-import { i18n } from '@kbn/i18n';
-
-export function JoinEditor({ joins, layer, onChange, leftJoinFields, layerDisplayName }) {
- const renderJoins = () => {
- return joins.map((joinDescriptor, index) => {
- const handleOnChange = (updatedDescriptor) => {
- onChange(layer, [...joins.slice(0, index), updatedDescriptor, ...joins.slice(index + 1)]);
- };
-
- const handleOnRemove = () => {
- onChange(layer, [...joins.slice(0, index), ...joins.slice(index + 1)]);
- };
-
- return (
-
-
-
-
- );
- });
- };
-
- const addJoin = () => {
- onChange(layer, [
- ...joins,
- {
- right: {
- id: uuid(),
- applyGlobalQuery: true,
- },
- },
- ]);
- };
-
- if (!layer.isJoinable()) {
- return null;
- }
-
- return (
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {renderJoins()}
-
- );
-}
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/view.js b/x-pack/plugins/maps/public/connected_components/layer_panel/view.js
index 71d76ff53d8a9..2e20a4492f08b 100644
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/view.js
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/view.js
@@ -75,7 +75,7 @@ export class LayerPanel extends React.Component {
};
async _loadLeftJoinFields() {
- if (!this.props.selectedLayer || !this.props.selectedLayer.isJoinable()) {
+ if (!this.props.selectedLayer || !this.props.selectedLayer.showJoinEditor()) {
return;
}
@@ -120,7 +120,7 @@ export class LayerPanel extends React.Component {
}
_renderJoinSection() {
- if (!this.props.selectedLayer.isJoinable()) {
+ if (!this.props.selectedLayer.showJoinEditor()) {
return null;
}
@@ -128,6 +128,7 @@ export class LayerPanel extends React.Component {
diff --git a/x-pack/plugins/maps/public/connected_components/layer_panel/view.test.js b/x-pack/plugins/maps/public/connected_components/layer_panel/view.test.js
index 99893c1bc5bee..33ca80b00c451 100644
--- a/x-pack/plugins/maps/public/connected_components/layer_panel/view.test.js
+++ b/x-pack/plugins/maps/public/connected_components/layer_panel/view.test.js
@@ -55,7 +55,7 @@ const mockLayer = {
getImmutableSourceProperties: () => {
return [{ label: 'source prop1', value: 'you get one chance to set me' }];
},
- isJoinable: () => {
+ showJoinEditor: () => {
return true;
},
supportsElasticsearchFilters: () => {
diff --git a/x-pack/plugins/maps/public/meta.test.js b/x-pack/plugins/maps/public/meta.test.js
index 5c04a57c00058..3486bf003aee0 100644
--- a/x-pack/plugins/maps/public/meta.test.js
+++ b/x-pack/plugins/maps/public/meta.test.js
@@ -36,6 +36,11 @@ describe('getGlyphUrl', () => {
beforeAll(() => {
require('./kibana_services').getIsEmsEnabled = () => true;
require('./kibana_services').getEmsFontLibraryUrl = () => EMS_FONTS_URL_MOCK;
+ require('./kibana_services').getHttp = () => ({
+ basePath: {
+ prepend: (url) => url, // No need to actually prepend a dev basepath for test
+ },
+ });
});
describe('EMS proxy enabled', () => {
diff --git a/x-pack/plugins/maps/public/meta.ts b/x-pack/plugins/maps/public/meta.ts
index 54c5eac7fe1b0..34c5f004fd7f3 100644
--- a/x-pack/plugins/maps/public/meta.ts
+++ b/x-pack/plugins/maps/public/meta.ts
@@ -30,8 +30,6 @@ import {
getKibanaVersion,
} from './kibana_services';
-const GIS_API_RELATIVE = `../${GIS_API_PATH}`;
-
export function getKibanaRegionList(): unknown[] {
return getRegionmapLayers();
}
@@ -69,10 +67,14 @@ export function getEMSClient(): EMSClient {
const proxyElasticMapsServiceInMaps = getProxyElasticMapsServiceInMaps();
const proxyPath = '';
const tileApiUrl = proxyElasticMapsServiceInMaps
- ? relativeToAbsolute(`${GIS_API_RELATIVE}/${EMS_TILES_CATALOGUE_PATH}`)
+ ? relativeToAbsolute(
+ getHttp().basePath.prepend(`/${GIS_API_PATH}/${EMS_TILES_CATALOGUE_PATH}`)
+ )
: getEmsTileApiUrl();
const fileApiUrl = proxyElasticMapsServiceInMaps
- ? relativeToAbsolute(`${GIS_API_RELATIVE}/${EMS_FILES_CATALOGUE_PATH}`)
+ ? relativeToAbsolute(
+ getHttp().basePath.prepend(`/${GIS_API_PATH}/${EMS_FILES_CATALOGUE_PATH}`)
+ )
: getEmsFileApiUrl();
emsClient = new EMSClient({
@@ -101,8 +103,11 @@ export function getGlyphUrl(): string {
return getHttp().basePath.prepend(`/${FONTS_API_PATH}/{fontstack}/{range}`);
}
return getProxyElasticMapsServiceInMaps()
- ? relativeToAbsolute(`../${GIS_API_PATH}/${EMS_TILES_CATALOGUE_PATH}/${EMS_GLYPHS_PATH}`) +
- `/{fontstack}/{range}`
+ ? relativeToAbsolute(
+ getHttp().basePath.prepend(
+ `/${GIS_API_PATH}/${EMS_TILES_CATALOGUE_PATH}/${EMS_GLYPHS_PATH}`
+ )
+ ) + `/{fontstack}/{range}`
: getEmsFontLibraryUrl();
}
diff --git a/x-pack/plugins/maps/server/plugin.ts b/x-pack/plugins/maps/server/plugin.ts
index dbcce50ac2b9a..7d091099c1aaa 100644
--- a/x-pack/plugins/maps/server/plugin.ts
+++ b/x-pack/plugins/maps/server/plugin.ts
@@ -26,12 +26,14 @@ import { initRoutes } from './routes';
import { ILicense } from '../../licensing/common/types';
import { LicensingPluginSetup } from '../../licensing/server';
import { HomeServerPluginSetup } from '../../../../src/plugins/home/server';
+import { MapsLegacyPluginSetup } from '../../../../src/plugins/maps_legacy/server';
interface SetupDeps {
features: FeaturesPluginSetupContract;
usageCollection: UsageCollectionSetup;
home: HomeServerPluginSetup;
licensing: LicensingPluginSetup;
+ mapsLegacy: MapsLegacyPluginSetup;
}
export class MapsPlugin implements Plugin {
@@ -129,9 +131,10 @@ export class MapsPlugin implements Plugin {
// @ts-ignore
async setup(core: CoreSetup, plugins: SetupDeps) {
- const { usageCollection, home, licensing, features } = plugins;
+ const { usageCollection, home, licensing, features, mapsLegacy } = plugins;
// @ts-ignore
const config$ = this._initializerContext.config.create();
+ const mapsLegacyConfig = await mapsLegacy.config$.pipe(take(1)).toPromise();
const currentConfig = await config$.pipe(take(1)).toPromise();
// @ts-ignore
@@ -150,7 +153,7 @@ export class MapsPlugin implements Plugin {
initRoutes(
core.http.createRouter(),
license.uid,
- currentConfig,
+ mapsLegacyConfig,
this.kibanaVersion,
this._logger
);
diff --git a/x-pack/plugins/maps/server/routes.js b/x-pack/plugins/maps/server/routes.js
index ad66712eb3ad6..1876c0de19c56 100644
--- a/x-pack/plugins/maps/server/routes.js
+++ b/x-pack/plugins/maps/server/routes.js
@@ -73,9 +73,10 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
validate: {
query: schema.object({
id: schema.maybe(schema.string()),
- x: schema.maybe(schema.number()),
- y: schema.maybe(schema.number()),
- z: schema.maybe(schema.number()),
+ elastic_tile_service_tos: schema.maybe(schema.string()),
+ my_app_name: schema.maybe(schema.string()),
+ my_app_version: schema.maybe(schema.string()),
+ license: schema.maybe(schema.string()),
}),
},
},
@@ -111,9 +112,9 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_TILES_RASTER_TILE_PATH}`,
validate: false,
},
- async (context, request, { ok, badRequest }) => {
+ async (context, request, response) => {
if (!checkEMSProxyEnabled()) {
- return badRequest('map.proxyElasticMapsServiceInMaps disabled');
+ return response.badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
if (
@@ -138,7 +139,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
.replace('{y}', request.query.y)
.replace('{z}', request.query.z);
- return await proxyResource({ url, contentType: 'image/png' }, { ok, badRequest });
+ return await proxyResource({ url, contentType: 'image/png' }, response);
}
);
@@ -203,7 +204,9 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
});
//rewrite
return ok({
- body: layers,
+ body: {
+ layers,
+ },
});
}
);
@@ -293,7 +296,11 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_TILES_VECTOR_STYLE_PATH}`,
validate: {
query: schema.object({
- id: schema.maybe(schema.string()),
+ id: schema.string(),
+ elastic_tile_service_tos: schema.maybe(schema.string()),
+ my_app_name: schema.maybe(schema.string()),
+ my_app_version: schema.maybe(schema.string()),
+ license: schema.maybe(schema.string()),
}),
},
},
@@ -302,11 +309,6 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
return badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
- if (!request.query.id) {
- logger.warn('Must supply id parameter to retrieve EMS vector style');
- return null;
- }
-
const tmsServices = await emsClient.getTMSServices();
const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id);
if (!tmsService) {
@@ -342,8 +344,12 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_TILES_VECTOR_SOURCE_PATH}`,
validate: {
query: schema.object({
- id: schema.maybe(schema.string()),
+ id: schema.string(),
sourceId: schema.maybe(schema.string()),
+ elastic_tile_service_tos: schema.maybe(schema.string()),
+ my_app_name: schema.maybe(schema.string()),
+ my_app_version: schema.maybe(schema.string()),
+ license: schema.maybe(schema.string()),
}),
},
},
@@ -352,11 +358,6 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
return badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
- if (!request.query.id || !request.query.sourceId) {
- logger.warn('Must supply id and sourceId parameter to retrieve EMS vector source');
- return null;
- }
-
const tmsServices = await emsClient.getTMSServices();
const tmsService = tmsServices.find((layer) => layer.getId() === request.query.id);
if (!tmsService) {
@@ -381,28 +382,21 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_TILES_VECTOR_TILE_PATH}`,
validate: {
query: schema.object({
- id: schema.maybe(schema.string()),
- sourceId: schema.maybe(schema.string()),
- x: schema.maybe(schema.number()),
- y: schema.maybe(schema.number()),
- z: schema.maybe(schema.number()),
+ id: schema.string(),
+ sourceId: schema.string(),
+ x: schema.number(),
+ y: schema.number(),
+ z: schema.number(),
+ elastic_tile_service_tos: schema.maybe(schema.string()),
+ my_app_name: schema.maybe(schema.string()),
+ my_app_version: schema.maybe(schema.string()),
+ license: schema.maybe(schema.string()),
}),
},
},
- async (context, request, { ok, badRequest }) => {
+ async (context, request, response) => {
if (!checkEMSProxyEnabled()) {
- return badRequest('map.proxyElasticMapsServiceInMaps disabled');
- }
-
- if (
- !request.query.id ||
- !request.query.sourceId ||
- typeof parseInt(request.query.x, 10) !== 'number' ||
- typeof parseInt(request.query.y, 10) !== 'number' ||
- typeof parseInt(request.query.z, 10) !== 'number'
- ) {
- logger.warn('Must supply id/sourceId/x/y/z parameters to retrieve EMS vector tile');
- return null;
+ return response.badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
const tmsServices = await emsClient.getTMSServices();
@@ -417,24 +411,29 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
.replace('{y}', request.query.y)
.replace('{z}', request.query.z);
- return await proxyResource({ url }, { ok, badRequest });
+ return await proxyResource({ url }, response);
}
);
router.get(
{
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_GLYPHS_PATH}/{fontstack}/{range}`,
- validate: false,
+ validate: {
+ params: schema.object({
+ fontstack: schema.string(),
+ range: schema.string(),
+ }),
+ },
},
- async (context, request, { ok, badRequest }) => {
+ async (context, request, response) => {
if (!checkEMSProxyEnabled()) {
- return badRequest('map.proxyElasticMapsServiceInMaps disabled');
+ return response.badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
const url = mapConfig.emsFontLibraryUrl
.replace('{fontstack}', request.params.fontstack)
.replace('{range}', request.params.range);
- return await proxyResource({ url }, { ok, badRequest });
+ return await proxyResource({ url }, response);
}
);
@@ -442,19 +441,22 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
{
path: `${ROOT}/${EMS_TILES_API_PATH}/${EMS_SPRITES_PATH}/{id}/sprite{scaling?}.{extension}`,
validate: {
+ query: schema.object({
+ elastic_tile_service_tos: schema.maybe(schema.string()),
+ my_app_name: schema.maybe(schema.string()),
+ my_app_version: schema.maybe(schema.string()),
+ license: schema.maybe(schema.string()),
+ }),
params: schema.object({
id: schema.string(),
+ scaling: schema.maybe(schema.string()),
+ extension: schema.string(),
}),
},
},
- async (context, request, { ok, badRequest }) => {
+ async (context, request, response) => {
if (!checkEMSProxyEnabled()) {
- return badRequest('map.proxyElasticMapsServiceInMaps disabled');
- }
-
- if (!request.params.id) {
- logger.warn('Must supply id parameter to retrieve EMS vector source sprite');
- return null;
+ return response.badRequest('map.proxyElasticMapsServiceInMaps disabled');
}
const tmsServices = await emsClient.getTMSServices();
@@ -479,7 +481,7 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
url: proxyPathUrl,
contentType: request.params.extension === 'png' ? 'image/png' : '',
},
- { ok, badRequest }
+ response
);
}
);
@@ -570,25 +572,23 @@ export function initRoutes(router, licenseUid, mapConfig, kbnVersion, logger) {
return proxyEMSInMaps;
}
- async function proxyResource({ url, contentType }, { ok, badRequest }) {
+ async function proxyResource({ url, contentType }, response) {
try {
const resource = await fetch(url);
const arrayBuffer = await resource.arrayBuffer();
- const bufferedResponse = Buffer.from(arrayBuffer);
- const headers = {
- 'Content-Disposition': 'inline',
- };
- if (contentType) {
- headers['Content-type'] = contentType;
- }
-
- return ok({
- body: bufferedResponse,
- headers,
+ const buffer = Buffer.from(arrayBuffer);
+
+ return response.ok({
+ body: buffer,
+ headers: {
+ 'content-disposition': 'inline',
+ 'content-length': buffer.length,
+ ...(contentType ? { 'Content-type': contentType } : {}),
+ },
});
} catch (e) {
logger.warn(`Cannot connect to EMS for resource, error: ${e.message}`);
- return badRequest(`Cannot connect to EMS`);
+ return response.badRequest(`Cannot connect to EMS`);
}
}
}
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/logo.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/logo.json
new file mode 100644
index 0000000000000..ca61db7992083
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/logo.json
@@ -0,0 +1,3 @@
+{
+ "icon": "logoSecurity"
+}
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/manifest.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/manifest.json
new file mode 100644
index 0000000000000..b7afe8d2b158a
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/manifest.json
@@ -0,0 +1,64 @@
+{
+ "id": "siem_cloudtrail",
+ "title": "SIEM Cloudtrail",
+ "description": "Detect suspicious activity recorded in your cloudtrail logs.",
+ "type": "Filebeat data",
+ "logoFile": "logo.json",
+ "defaultIndexPattern": "filebeat-*",
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}}
+ ]
+ }
+ },
+ "jobs": [
+ {
+ "id": "rare_method_for_a_city",
+ "file": "rare_method_for_a_city.json"
+ },
+ {
+ "id": "rare_method_for_a_country",
+ "file": "rare_method_for_a_country.json"
+ },
+ {
+ "id": "rare_method_for_a_username",
+ "file": "rare_method_for_a_username.json"
+ },
+ {
+ "id": "high_distinct_count_error_message",
+ "file": "high_distinct_count_error_message.json"
+ },
+ {
+ "id": "rare_error_code",
+ "file": "rare_error_code.json"
+ }
+ ],
+ "datafeeds": [
+ {
+ "id": "datafeed-rare_method_for_a_city",
+ "file": "datafeed_rare_method_for_a_city.json",
+ "job_id": "rare_method_for_a_city"
+ },
+ {
+ "id": "datafeed-rare_method_for_a_country",
+ "file": "datafeed_rare_method_for_a_country.json",
+ "job_id": "rare_method_for_a_country"
+ },
+ {
+ "id": "datafeed-rare_method_for_a_username",
+ "file": "datafeed_rare_method_for_a_username.json",
+ "job_id": "rare_method_for_a_username"
+ },
+ {
+ "id": "datafeed-high_distinct_count_error_message",
+ "file": "datafeed_high_distinct_count_error_message.json",
+ "job_id": "high_distinct_count_error_message"
+ },
+ {
+ "id": "datafeed-rare_error_code",
+ "file": "datafeed_rare_error_code.json",
+ "job_id": "rare_error_code"
+ }
+ ]
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_high_distinct_count_error_message.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_high_distinct_count_error_message.json
new file mode 100644
index 0000000000000..269aac2ea72a1
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_high_distinct_count_error_message.json
@@ -0,0 +1,16 @@
+{
+ "job_id": "JOB_ID",
+ "indices": [
+ "INDEX_PATTERN_NAME"
+ ],
+ "max_empty_searches": 10,
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}},
+ {"term": {"event.module": "aws"}},
+ {"exists": {"field": "aws.cloudtrail.error_message"}}
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_error_code.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_error_code.json
new file mode 100644
index 0000000000000..4b463a4d10991
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_error_code.json
@@ -0,0 +1,16 @@
+{
+ "job_id": "JOB_ID",
+ "indices": [
+ "INDEX_PATTERN_NAME"
+ ],
+ "max_empty_searches": 10,
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}},
+ {"term": {"event.module": "aws"}},
+ {"exists": {"field": "aws.cloudtrail.error_code"}}
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_city.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_city.json
new file mode 100644
index 0000000000000..e436273a848e7
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_city.json
@@ -0,0 +1,16 @@
+{
+ "job_id": "JOB_ID",
+ "indices": [
+ "INDEX_PATTERN_NAME"
+ ],
+ "max_empty_searches": 10,
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}},
+ {"term": {"event.module": "aws"}},
+ {"exists": {"field": "source.geo.city_name"}}
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_country.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_country.json
new file mode 100644
index 0000000000000..f0e80174b8791
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_country.json
@@ -0,0 +1,16 @@
+{
+ "job_id": "JOB_ID",
+ "indices": [
+ "INDEX_PATTERN_NAME"
+ ],
+ "max_empty_searches": 10,
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}},
+ {"term": {"event.module": "aws"}},
+ {"exists": {"field": "source.geo.country_iso_code"}}
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_username.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_username.json
new file mode 100644
index 0000000000000..2fd3622ff81ce
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/datafeed_rare_method_for_a_username.json
@@ -0,0 +1,16 @@
+{
+ "job_id": "JOB_ID",
+ "indices": [
+ "INDEX_PATTERN_NAME"
+ ],
+ "max_empty_searches": 10,
+ "query": {
+ "bool": {
+ "filter": [
+ {"term": {"event.dataset": "aws.cloudtrail"}},
+ {"term": {"event.module": "aws"}},
+ {"exists": {"field": "user.name"}}
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/high_distinct_count_error_message.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/high_distinct_count_error_message.json
new file mode 100644
index 0000000000000..fdabf66ac91b3
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/high_distinct_count_error_message.json
@@ -0,0 +1,33 @@
+{
+ "job_type": "anomaly_detector",
+ "description": "Looks for a spike in the rate of an error message which may simply indicate an impending service failure but these can also be byproducts of attempted or successful persistence, privilege escalation, defense evasion, discovery, lateral movement, or collection activity by a threat actor.",
+ "groups": [
+ "siem",
+ "cloudtrail"
+ ],
+ "analysis_config": {
+ "bucket_span": "15m",
+ "detectors": [
+ {
+ "detector_description": "high_distinct_count(\"aws.cloudtrail.error_message\")",
+ "function": "high_distinct_count",
+ "field_name": "aws.cloudtrail.error_message"
+ }
+ ],
+ "influencers": [
+ "aws.cloudtrail.user_identity.arn",
+ "source.ip",
+ "source.geo.city_name"
+ ]
+ },
+ "allow_lazy_open": true,
+ "analysis_limits": {
+ "model_memory_limit": "16mb"
+ },
+ "data_description": {
+ "time_field": "@timestamp"
+ },
+ "custom_settings": {
+ "created_by": "ml-module-siem-cloudtrail"
+ }
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_error_code.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_error_code.json
new file mode 100644
index 0000000000000..0f8fa814ac60a
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_error_code.json
@@ -0,0 +1,33 @@
+{
+ "job_type": "anomaly_detector",
+ "description": "Looks for unsual errors. Rare and unusual errors may simply indicate an impending service failure but they can also be byproducts of attempted or successful persistence, privilege escalation, defense evasion, discovery, lateral movement, or collection activity by a threat actor.",
+ "groups": [
+ "siem",
+ "cloudtrail"
+ ],
+ "analysis_config": {
+ "bucket_span": "60m",
+ "detectors": [
+ {
+ "detector_description": "rare by \"aws.cloudtrail.error_code\"",
+ "function": "rare",
+ "by_field_name": "aws.cloudtrail.error_code"
+ }
+ ],
+ "influencers": [
+ "aws.cloudtrail.user_identity.arn",
+ "source.ip",
+ "source.geo.city_name"
+ ]
+ },
+ "allow_lazy_open": true,
+ "analysis_limits": {
+ "model_memory_limit": "16mb"
+ },
+ "data_description": {
+ "time_field": "@timestamp"
+ },
+ "custom_settings": {
+ "created_by": "ml-module-siem-cloudtrail"
+ }
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_city.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_city.json
new file mode 100644
index 0000000000000..eff4d4cdbb889
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_city.json
@@ -0,0 +1,34 @@
+{
+ "job_type": "anomaly_detector",
+ "description": "Looks for AWS API calls that, while not inherently suspicious or abnormal, are sourcing from a geolocation (city) that is unusual. This can be the result of compromised credentials or keys.",
+ "groups": [
+ "siem",
+ "cloudtrail"
+ ],
+ "analysis_config": {
+ "bucket_span": "60m",
+ "detectors": [
+ {
+ "detector_description": "rare by \"event.action\" partition by \"source.geo.city_name\"",
+ "function": "rare",
+ "by_field_name": "event.action",
+ "partition_field_name": "source.geo.city_name"
+ }
+ ],
+ "influencers": [
+ "aws.cloudtrail.user_identity.arn",
+ "source.ip",
+ "source.geo.city_name"
+ ]
+ },
+ "allow_lazy_open": true,
+ "analysis_limits": {
+ "model_memory_limit": "64mb"
+ },
+ "data_description": {
+ "time_field": "@timestamp"
+ },
+ "custom_settings": {
+ "created_by": "ml-module-siem-cloudtrail"
+ }
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_country.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_country.json
new file mode 100644
index 0000000000000..810822c30a5dd
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_country.json
@@ -0,0 +1,34 @@
+{
+ "job_type": "anomaly_detector",
+ "description": "Looks for AWS API calls that, while not inherently suspicious or abnormal, are sourcing from a geolocation (country) that is unusual. This can be the result of compromised credentials or keys.",
+ "groups": [
+ "siem",
+ "cloudtrail"
+ ],
+ "analysis_config": {
+ "bucket_span": "60m",
+ "detectors": [
+ {
+ "detector_description": "rare by \"event.action\" partition by \"source.geo.country_iso_code\"",
+ "function": "rare",
+ "by_field_name": "event.action",
+ "partition_field_name": "source.geo.country_iso_code"
+ }
+ ],
+ "influencers": [
+ "aws.cloudtrail.user_identity.arn",
+ "source.ip",
+ "source.geo.country_iso_code"
+ ]
+ },
+ "allow_lazy_open": true,
+ "analysis_limits": {
+ "model_memory_limit": "64mb"
+ },
+ "data_description": {
+ "time_field": "@timestamp"
+ },
+ "custom_settings": {
+ "created_by": "ml-module-siem-cloudtrail"
+ }
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_username.json b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_username.json
new file mode 100644
index 0000000000000..2edf52e8351ed
--- /dev/null
+++ b/x-pack/plugins/ml/server/models/data_recognizer/modules/siem_cloudtrail/ml/rare_method_for_a_username.json
@@ -0,0 +1,34 @@
+{
+ "job_type": "anomaly_detector",
+ "description": "Looks for AWS API calls that, while not inherently suspicious or abnormal, are sourcing from a user context that does not normally call the method. This can be the result of compromised credentials or keys as someone uses a valid account to persist, move laterally, or exfil data.",
+ "groups": [
+ "siem",
+ "cloudtrail"
+ ],
+ "analysis_config": {
+ "bucket_span": "60m",
+ "detectors": [
+ {
+ "detector_description": "rare by \"event.action\" partition by \"user.name\"",
+ "function": "rare",
+ "by_field_name": "event.action",
+ "partition_field_name": "user.name"
+ }
+ ],
+ "influencers": [
+ "user.name",
+ "source.ip",
+ "source.geo.city_name"
+ ]
+ },
+ "allow_lazy_open": true,
+ "analysis_limits": {
+ "model_memory_limit": "128mb"
+ },
+ "data_description": {
+ "time_field": "@timestamp"
+ },
+ "custom_settings": {
+ "created_by": "ml-module-siem-cloudtrail"
+ }
+ }
\ No newline at end of file
diff --git a/x-pack/plugins/security_solution/common/endpoint/models/event.ts b/x-pack/plugins/security_solution/common/endpoint/models/event.ts
index 86cccff957211..9b4550f52ff22 100644
--- a/x-pack/plugins/security_solution/common/endpoint/models/event.ts
+++ b/x-pack/plugins/security_solution/common/endpoint/models/event.ts
@@ -82,7 +82,6 @@ export function getAncestryAsArray(event: ResolverEvent | undefined): string[] {
* @param event The event to get the category for
*/
export function primaryEventCategory(event: ResolverEvent): string | undefined {
- // Returning "Process" as a catch-all here because it seems pretty general
if (isLegacyEvent(event)) {
const legacyFullType = event.endgame.event_type_full;
if (legacyFullType) {
@@ -96,6 +95,20 @@ export function primaryEventCategory(event: ResolverEvent): string | undefined {
}
}
+/**
+ * @param event The event to get the full ECS category for
+ */
+export function allEventCategories(event: ResolverEvent): string | string[] | undefined {
+ if (isLegacyEvent(event)) {
+ const legacyFullType = event.endgame.event_type_full;
+ if (legacyFullType) {
+ return legacyFullType;
+ }
+ } else {
+ return event.event.category;
+ }
+}
+
/**
* ECS event type will be things like 'creation', 'deletion', 'access', etc.
* see: https://www.elastic.co/guide/en/ecs/current/ecs-event.html
diff --git a/x-pack/plugins/security_solution/common/endpoint/schema/resolver.ts b/x-pack/plugins/security_solution/common/endpoint/schema/resolver.ts
index 42cbc2327fc28..c67ad3665d004 100644
--- a/x-pack/plugins/security_solution/common/endpoint/schema/resolver.ts
+++ b/x-pack/plugins/security_solution/common/endpoint/schema/resolver.ts
@@ -12,10 +12,10 @@ import { schema } from '@kbn/config-schema';
export const validateTree = {
params: schema.object({ id: schema.string() }),
query: schema.object({
- children: schema.number({ defaultValue: 10, min: 0, max: 100 }),
- ancestors: schema.number({ defaultValue: 3, min: 0, max: 5 }),
- events: schema.number({ defaultValue: 100, min: 0, max: 1000 }),
- alerts: schema.number({ defaultValue: 100, min: 0, max: 1000 }),
+ children: schema.number({ defaultValue: 200, min: 0, max: 10000 }),
+ ancestors: schema.number({ defaultValue: 200, min: 0, max: 10000 }),
+ events: schema.number({ defaultValue: 1000, min: 0, max: 10000 }),
+ alerts: schema.number({ defaultValue: 1000, min: 0, max: 10000 }),
afterEvent: schema.maybe(schema.string()),
afterAlert: schema.maybe(schema.string()),
afterChild: schema.maybe(schema.string()),
@@ -29,7 +29,7 @@ export const validateTree = {
export const validateEvents = {
params: schema.object({ id: schema.string() }),
query: schema.object({
- events: schema.number({ defaultValue: 100, min: 1, max: 1000 }),
+ events: schema.number({ defaultValue: 1000, min: 1, max: 10000 }),
afterEvent: schema.maybe(schema.string()),
legacyEndpointID: schema.maybe(schema.string()),
}),
@@ -41,7 +41,7 @@ export const validateEvents = {
export const validateAlerts = {
params: schema.object({ id: schema.string() }),
query: schema.object({
- alerts: schema.number({ defaultValue: 100, min: 1, max: 1000 }),
+ alerts: schema.number({ defaultValue: 1000, min: 1, max: 10000 }),
afterAlert: schema.maybe(schema.string()),
legacyEndpointID: schema.maybe(schema.string()),
}),
@@ -53,7 +53,7 @@ export const validateAlerts = {
export const validateAncestry = {
params: schema.object({ id: schema.string() }),
query: schema.object({
- ancestors: schema.number({ defaultValue: 0, min: 0, max: 10 }),
+ ancestors: schema.number({ defaultValue: 200, min: 0, max: 10000 }),
legacyEndpointID: schema.maybe(schema.string()),
}),
};
@@ -64,7 +64,7 @@ export const validateAncestry = {
export const validateChildren = {
params: schema.object({ id: schema.string() }),
query: schema.object({
- children: schema.number({ defaultValue: 10, min: 1, max: 100 }),
+ children: schema.number({ defaultValue: 200, min: 1, max: 10000 }),
afterChild: schema.maybe(schema.string()),
legacyEndpointID: schema.maybe(schema.string()),
}),
diff --git a/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts b/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts
index 12e6f3db9b61e..759eec69bc022 100644
--- a/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts
+++ b/x-pack/plugins/security_solution/cypress/integration/timeline_toggle_column.spec.ts
@@ -24,7 +24,8 @@ import {
import { HOSTS_URL } from '../urls/navigation';
-describe('toggle column in timeline', () => {
+// Flaky: https://github.com/elastic/kibana/issues/71361
+describe.skip('toggle column in timeline', () => {
before(() => {
loginAndWaitForPage(HOSTS_URL);
});
diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/policy_response_friendly_names.ts b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/policy_response_friendly_names.ts
index 28e91331b428d..020e8c9e38ad5 100644
--- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/policy_response_friendly_names.ts
+++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/details/policy_response_friendly_names.ts
@@ -6,7 +6,209 @@
import { i18n } from '@kbn/i18n';
-const responseMap = new Map();
+const policyResponses: Array<[string, string]> = [
+ [
+ 'configure_dns_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_dns_events',
+ { defaultMessage: 'Configure DNS Events' }
+ ),
+ ],
+ [
+ 'configure_elasticsearch_connection',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_elasticsearch_connection',
+ { defaultMessage: 'Configure Elastic Search Connection' }
+ ),
+ ],
+ [
+ 'configure_file_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_file_events',
+ { defaultMessage: 'Configure File Events' }
+ ),
+ ],
+ [
+ 'configure_imageload_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_imageload_events',
+ { defaultMessage: 'Configure Image Load Events' }
+ ),
+ ],
+ [
+ 'configure_kernel',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_kernel', {
+ defaultMessage: 'Configure Kernel',
+ }),
+ ],
+ [
+ 'configure_logging',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_logging', {
+ defaultMessage: 'Configure Logging',
+ }),
+ ],
+ [
+ 'configure_malware',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_malware', {
+ defaultMessage: 'Configure Malware',
+ }),
+ ],
+ [
+ 'configure_network_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_network_events',
+ { defaultMessage: 'Configure Network Events' }
+ ),
+ ],
+ [
+ 'configure_process_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_process_events',
+ { defaultMessage: 'Configure Process Events' }
+ ),
+ ],
+ [
+ 'configure_registry_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_registry_events',
+ { defaultMessage: 'Configure Registry Events' }
+ ),
+ ],
+ [
+ 'configure_security_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configure_security_events',
+ { defaultMessage: 'Configure Security Events' }
+ ),
+ ],
+ [
+ 'connect_kernel',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.connect_kernel', {
+ defaultMessage: 'Connect Kernel',
+ }),
+ ],
+ [
+ 'detect_async_image_load_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_async_image_load_events',
+ { defaultMessage: 'Detect Async Image Load Events' }
+ ),
+ ],
+ [
+ 'detect_file_open_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_file_open_events',
+ { defaultMessage: 'Detect File Open Events' }
+ ),
+ ],
+ [
+ 'detect_file_write_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_file_write_events',
+ { defaultMessage: 'Detect File Write Events' }
+ ),
+ ],
+ [
+ 'detect_network_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_network_events',
+ { defaultMessage: 'Detect Network Events' }
+ ),
+ ],
+ [
+ 'detect_process_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_process_events',
+ { defaultMessage: 'Detect Process Events' }
+ ),
+ ],
+ [
+ 'detect_registry_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_registry_events',
+ { defaultMessage: 'Detect Registry Events' }
+ ),
+ ],
+ [
+ 'detect_sync_image_load_events',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detect_sync_image_load_events',
+ { defaultMessage: 'Detect Sync Image Load Events' }
+ ),
+ ],
+ [
+ 'download_global_artifacts',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.download_global_artifacts',
+ { defaultMessage: 'Download Global Artifacts' }
+ ),
+ ],
+ [
+ 'download_user_artifacts',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.download_user_artifacts',
+ { defaultMessage: 'Download User Artifacts' }
+ ),
+ ],
+ [
+ 'load_config',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.load_config', {
+ defaultMessage: 'Load Config',
+ }),
+ ],
+ [
+ 'load_malware_model',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.load_malware_model',
+ { defaultMessage: 'Load Malware Model' }
+ ),
+ ],
+ [
+ 'read_elasticsearch_config',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.read_elasticsearch_config',
+ { defaultMessage: 'Read ElasticSearch Config' }
+ ),
+ ],
+ [
+ 'read_events_config',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.read_events_config',
+ { defaultMessage: 'Read Events Config' }
+ ),
+ ],
+ [
+ 'read_kernel_config',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.read_kernel_config',
+ { defaultMessage: 'Read Kernel Config' }
+ ),
+ ],
+ [
+ 'read_logging_config',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.read_logging_config',
+ { defaultMessage: 'Read Logging Config' }
+ ),
+ ],
+ [
+ 'read_malware_config',
+ i18n.translate(
+ 'xpack.securitySolution.endpoint.hostDetails.policyResponse.read_malware_config',
+ { defaultMessage: 'Read Malware Config' }
+ ),
+ ],
+ [
+ 'workflow',
+ i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.workflow', {
+ defaultMessage: 'Workflow',
+ }),
+ ],
+];
+
+const responseMap = new Map(policyResponses);
+
+// Additional values used in the Policy Response UI
responseMap.set(
'success',
i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.success', {
@@ -49,144 +251,6 @@ responseMap.set(
defaultMessage: 'Events',
})
);
-responseMap.set(
- 'configure_elasticsearch_connection',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.configureElasticSearchConnection',
- {
- defaultMessage: 'Configure Elastic Search Connection',
- }
- )
-);
-responseMap.set(
- 'configure_logging',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configureLogging', {
- defaultMessage: 'Configure Logging',
- })
-);
-responseMap.set(
- 'configure_kernel',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configureKernel', {
- defaultMessage: 'Configure Kernel',
- })
-);
-responseMap.set(
- 'configure_malware',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.configureMalware', {
- defaultMessage: 'Configure Malware',
- })
-);
-responseMap.set(
- 'connect_kernel',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.connectKernel', {
- defaultMessage: 'Connect Kernel',
- })
-);
-responseMap.set(
- 'detect_file_open_events',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detectFileOpenEvents',
- {
- defaultMessage: 'Detect File Open Events',
- }
- )
-);
-responseMap.set(
- 'detect_file_write_events',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detectFileWriteEvents',
- {
- defaultMessage: 'Detect File Write Events',
- }
- )
-);
-responseMap.set(
- 'detect_image_load_events',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.detectImageLoadEvents',
- {
- defaultMessage: 'Detect Image Load Events',
- }
- )
-);
-responseMap.set(
- 'detect_process_events',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.detectProcessEvents', {
- defaultMessage: 'Detect Process Events',
- })
-);
-responseMap.set(
- 'download_global_artifacts',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.downloadGlobalArtifacts',
- {
- defaultMessage: 'Download Global Artifacts',
- }
- )
-);
-responseMap.set(
- 'load_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.loadConfig', {
- defaultMessage: 'Load Config',
- })
-);
-responseMap.set(
- 'load_malware_model',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.loadMalwareModel', {
- defaultMessage: 'Load Malware Model',
- })
-);
-responseMap.set(
- 'read_elasticsearch_config',
- i18n.translate(
- 'xpack.securitySolution.endpoint.hostDetails.policyResponse.readElasticSearchConfig',
- {
- defaultMessage: 'Read ElasticSearch Config',
- }
- )
-);
-responseMap.set(
- 'read_events_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.readEventsConfig', {
- defaultMessage: 'Read Events Config',
- })
-);
-responseMap.set(
- 'read_kernel_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.readKernelConfig', {
- defaultMessage: 'Read Kernel Config',
- })
-);
-responseMap.set(
- 'read_logging_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.readLoggingConfig', {
- defaultMessage: 'Read Logging Config',
- })
-);
-responseMap.set(
- 'read_malware_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.readMalwareConfig', {
- defaultMessage: 'Read Malware Config',
- })
-);
-responseMap.set(
- 'workflow',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.workflow', {
- defaultMessage: 'Workflow',
- })
-);
-responseMap.set(
- 'download_model',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.downloadModel', {
- defaultMessage: 'Download Model',
- })
-);
-responseMap.set(
- 'ingest_events_config',
- i18n.translate('xpack.securitySolution.endpoint.hostDetails.policyResponse.injestEventsConfig', {
- defaultMessage: 'Injest Events Config',
- })
-);
/**
* Maps a server provided value to corresponding i18n'd string.
@@ -195,5 +259,13 @@ export function formatResponse(responseString: string) {
if (responseMap.has(responseString)) {
return responseMap.get(responseString);
}
- return responseString;
+
+ // Its possible for the UI to receive an Action name that it does not yet have a translation,
+ // thus we generate a label for it here by making it more user fiendly
+ responseMap.set(
+ responseString,
+ responseString.replace(/_/g, ' ').replace(/\b(\w)/g, (m) => m.toUpperCase())
+ );
+
+ return responseMap.get(responseString);
}
diff --git a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx
index 996b987ea2be3..a61088e2edd29 100644
--- a/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx
+++ b/x-pack/plugins/security_solution/public/management/pages/endpoint_hosts/view/index.test.tsx
@@ -13,8 +13,9 @@ import { mockPolicyResultList } from '../../policy/store/policy_list/mock_policy
import { AppContextTestRender, createAppRootMockRenderer } from '../../../../common/mock/endpoint';
import {
HostInfo,
- HostStatus,
HostPolicyResponseActionStatus,
+ HostPolicyResponseAppliedAction,
+ HostStatus,
} from '../../../../../common/endpoint/types';
import { EndpointDocGenerator } from '../../../../../common/endpoint/generate_data';
import { AppAction } from '../../../../common/store/actions';
@@ -251,6 +252,16 @@ describe('when on the hosts page', () => {
) {
malwareResponseConfigurations.concerned_actions.push(downloadModelAction.name);
}
+
+ // Add an unknown Action Name - to ensure we handle the format of it on the UI
+ const unknownAction: HostPolicyResponseAppliedAction = {
+ status: HostPolicyResponseActionStatus.success,
+ message: 'test message',
+ name: 'a_new_unknown_action',
+ };
+ policyResponse.Endpoint.policy.applied.actions.push(unknownAction);
+ malwareResponseConfigurations.concerned_actions.push(unknownAction.name);
+
reactTestingLibrary.act(() => {
store.dispatch({
type: 'serverReturnedHostPolicyResponse',
@@ -564,6 +575,10 @@ describe('when on the hosts page', () => {
'?page_index=0&page_size=10&selected_host=1'
);
});
+
+ it('should format unknown policy action names', async () => {
+ expect(renderResult.getByText('A New Unknown Action')).not.toBeNull();
+ });
});
});
});
diff --git a/x-pack/plugins/security_solution/public/resolver/models/resolver_tree.ts b/x-pack/plugins/security_solution/public/resolver/models/resolver_tree.ts
index cf32988a856b2..446e371832d38 100644
--- a/x-pack/plugins/security_solution/public/resolver/models/resolver_tree.ts
+++ b/x-pack/plugins/security_solution/public/resolver/models/resolver_tree.ts
@@ -9,6 +9,7 @@ import {
ResolverEvent,
ResolverNodeStats,
ResolverLifecycleNode,
+ ResolverChildNode,
} from '../../../common/endpoint/types';
import { uniquePidForProcess } from './process_event';
@@ -60,11 +61,13 @@ export function relatedEventsStats(tree: ResolverTree): Map {
let store: Store;
+ let dispatchTree: (tree: ResolverTree) => void;
beforeEach(() => {
store = createStore(dataReducer, undefined);
+ dispatchTree = (tree) => {
+ const action: DataAction = {
+ type: 'serverReturnedResolverData',
+ payload: {
+ result: tree,
+ databaseDocumentID: '',
+ },
+ };
+ store.dispatch(action);
+ };
});
describe('when data was received and the ancestry and children edges had cursors', () => {
beforeEach(() => {
- const generator = new EndpointDocGenerator('seed');
+ // Generate a 'tree' using the Resolver generator code. This structure isn't the same as what the API returns.
+ const baseTree = generateBaseTree();
const tree = mockResolverTree({
- events: generator.generateTree({ ancestors: 1, generations: 2, children: 2 }).allEvents,
+ events: baseTree.allEvents,
cursors: {
- childrenNextChild: 'aValidChildursor',
+ childrenNextChild: 'aValidChildCursor',
ancestryNextAncestor: 'aValidAncestorCursor',
},
- });
- if (tree) {
- const action: DataAction = {
- type: 'serverReturnedResolverData',
- payload: {
- result: tree,
- databaseDocumentID: '',
- },
- };
- store.dispatch(action);
- }
+ })!;
+ dispatchTree(tree);
});
it('should indicate there are additional ancestor', () => {
expect(selectors.hasMoreAncestors(store.getState())).toBe(true);
@@ -49,4 +53,251 @@ describe('Resolver Data Middleware', () => {
expect(selectors.hasMoreChildren(store.getState())).toBe(true);
});
});
+
+ describe('when data was received with stats mocked for the first child node', () => {
+ let firstChildNodeInTree: TreeNode;
+ let eventStatsForFirstChildNode: { total: number; byCategory: Record };
+ let categoryToOverCount: string;
+ let tree: ResolverTree;
+
+ /**
+ * Compiling stats to use for checking limit warnings and counts of missing events
+ * e.g. Limit warnings should show when number of related events actually displayed
+ * is lower than the estimated count from stats.
+ */
+
+ beforeEach(() => {
+ ({
+ tree,
+ firstChildNodeInTree,
+ eventStatsForFirstChildNode,
+ categoryToOverCount,
+ } = mockedTree());
+ if (tree) {
+ dispatchTree(tree);
+ }
+ });
+
+ describe('and when related events were returned with totals equalling what stat counts indicate they should be', () => {
+ beforeEach(() => {
+ // Return related events for the first child node
+ const relatedAction: DataAction = {
+ type: 'serverReturnedRelatedEventData',
+ payload: {
+ entityID: firstChildNodeInTree.id,
+ events: firstChildNodeInTree.relatedEvents,
+ nextEvent: null,
+ },
+ };
+ store.dispatch(relatedAction);
+ });
+ it('should have the correct related events', () => {
+ const selectedEventsByEntityId = selectors.relatedEventsByEntityId(store.getState());
+ const selectedEventsForFirstChildNode = selectedEventsByEntityId.get(
+ firstChildNodeInTree.id
+ )!.events;
+
+ expect(selectedEventsForFirstChildNode).toBe(firstChildNodeInTree.relatedEvents);
+ });
+ it('should indicate the correct related event count for each category', () => {
+ const selectedRelatedInfo = selectors.relatedEventInfoByEntityId(store.getState());
+ const displayCountsForCategory = selectedRelatedInfo(firstChildNodeInTree.id)
+ ?.numberActuallyDisplayedForCategory!;
+
+ const eventCategoriesForNode: string[] = Object.keys(
+ eventStatsForFirstChildNode.byCategory
+ );
+
+ for (const eventCategory of eventCategoriesForNode) {
+ expect(`${eventCategory}:${displayCountsForCategory(eventCategory)}`).toBe(
+ `${eventCategory}:${eventStatsForFirstChildNode.byCategory[eventCategory]}`
+ );
+ }
+ });
+ /**
+ * The general approach reflected here is to _avoid_ showing a limit warning - even if we hit
+ * the overall related event limit - as long as the number in our category matches what the stats
+ * say we have. E.g. If the stats say you have 20 dns events, and we receive 20 dns events, we
+ * don't need to display a limit warning for that, even if we hit some overall event limit of e.g. 100
+ * while we were fetching the 20.
+ */
+ it('should not indicate the limit has been exceeded because the number of related events received for the category is greater or equal to the stats count', () => {
+ const selectedRelatedInfo = selectors.relatedEventInfoByEntityId(store.getState());
+ const shouldShowLimit = selectedRelatedInfo(firstChildNodeInTree.id)
+ ?.shouldShowLimitForCategory!;
+ for (const typeCounted of Object.keys(eventStatsForFirstChildNode.byCategory)) {
+ expect(shouldShowLimit(typeCounted)).toBe(false);
+ }
+ });
+ it('should not indicate that there are any related events missing because the number of related events received for the category is greater or equal to the stats count', () => {
+ const selectedRelatedInfo = selectors.relatedEventInfoByEntityId(store.getState());
+ const notDisplayed = selectedRelatedInfo(firstChildNodeInTree.id)
+ ?.numberNotDisplayedForCategory!;
+ for (const typeCounted of Object.keys(eventStatsForFirstChildNode.byCategory)) {
+ expect(notDisplayed(typeCounted)).toBe(0);
+ }
+ });
+ });
+ describe('when data was received and stats show more related events than the API can provide', () => {
+ beforeEach(() => {
+ // Add 1 to the stats for an event category so that the selectors think we are missing data.
+ // This mutates `tree`, and then we re-dispatch it
+ eventStatsForFirstChildNode.byCategory[categoryToOverCount] =
+ eventStatsForFirstChildNode.byCategory[categoryToOverCount] + 1;
+
+ if (tree) {
+ dispatchTree(tree);
+ const relatedAction: DataAction = {
+ type: 'serverReturnedRelatedEventData',
+ payload: {
+ entityID: firstChildNodeInTree.id,
+ events: firstChildNodeInTree.relatedEvents,
+ nextEvent: 'aValidNextEventCursor',
+ },
+ };
+ store.dispatch(relatedAction);
+ }
+ });
+ it('should have the correct related events', () => {
+ const selectedEventsByEntityId = selectors.relatedEventsByEntityId(store.getState());
+ const selectedEventsForFirstChildNode = selectedEventsByEntityId.get(
+ firstChildNodeInTree.id
+ )!.events;
+
+ expect(selectedEventsForFirstChildNode).toBe(firstChildNodeInTree.relatedEvents);
+ });
+ it('should indicate the limit has been exceeded because the number of related events received for the category is less than what the stats count said it would be', () => {
+ const selectedRelatedInfo = selectors.relatedEventInfoByEntityId(store.getState());
+ const shouldShowLimit = selectedRelatedInfo(firstChildNodeInTree.id)
+ ?.shouldShowLimitForCategory!;
+ expect(shouldShowLimit(categoryToOverCount)).toBe(true);
+ });
+ it('should indicate that there are related events missing because the number of related events received for the category is less than what the stats count said it would be', () => {
+ const selectedRelatedInfo = selectors.relatedEventInfoByEntityId(store.getState());
+ const notDisplayed = selectedRelatedInfo(firstChildNodeInTree.id)
+ ?.numberNotDisplayedForCategory!;
+ expect(notDisplayed(categoryToOverCount)).toBe(1);
+ });
+ });
+ });
});
+
+function mockedTree() {
+ // Generate a 'tree' using the Resolver generator code. This structure isn't the same as what the API returns.
+ const baseTree = generateBaseTree();
+
+ const { children } = baseTree;
+ const firstChildNodeInTree = [...children.values()][0];
+
+ // The `generateBaseTree` mock doesn't calculate stats (the actual data has them.)
+ // So calculate some stats for just the node that we'll test.
+ const statsResults = compileStatsForChild(firstChildNodeInTree);
+
+ const tree = mockResolverTree({
+ events: baseTree.allEvents,
+ /**
+ * Calculate children from the ResolverTree response using the children of the `Tree` we generated using the Resolver data generator code.
+ * Compile (and attach) stats to the first child node.
+ *
+ * The purpose of `children` here is to set the `actual`
+ * value that the stats values will be compared with
+ * to derive things like the number of missing events and if
+ * related event limits should be shown.
+ */
+ children: [...baseTree.children.values()].map((node: TreeNode) => {
+ // Treat each `TreeNode` as a `ResolverChildNode`.
+ // These types are almost close enough to be used interchangably (for the purposes of this test.)
+ const childNode: Partial = node;
+
+ // `TreeNode` has `id` which is the same as `entityID`.
+ // The `ResolverChildNode` calls the entityID as `entityID`.
+ // Set `entityID` on `childNode` since the code in test relies on it.
+ childNode.entityID = (childNode as TreeNode).id;
+
+ // This should only be true for the first child.
+ if (node.id === firstChildNodeInTree.id) {
+ // attach stats
+ childNode.stats = {
+ events: statsResults.eventStats,
+ totalAlerts: 0,
+ };
+ }
+ return childNode;
+ }) as ResolverChildNode[] /**
+ Cast to ResolverChildNode[] array is needed because incoming
+ TreeNodes from the generator cannot be assigned cleanly to the
+ tree model's expected ResolverChildNode type.
+ */,
+ });
+
+ return {
+ tree: tree!,
+ firstChildNodeInTree,
+ eventStatsForFirstChildNode: statsResults.eventStats,
+ categoryToOverCount: statsResults.firstCategory,
+ };
+}
+
+function generateBaseTree() {
+ const generator = new EndpointDocGenerator('seed');
+ return generator.generateTree({
+ ancestors: 1,
+ generations: 2,
+ children: 3,
+ percentWithRelated: 100,
+ alwaysGenMaxChildrenPerNode: true,
+ });
+}
+
+function compileStatsForChild(
+ node: TreeNode
+): {
+ eventStats: {
+ /** The total number of related events. */
+ total: number;
+ /** A record with the categories of events as keys, and the count of events per category as values. */
+ byCategory: Record;
+ };
+ /** The category of the first event. */
+ firstCategory: string;
+} {
+ const totalRelatedEvents = node.relatedEvents.length;
+ // For the purposes of testing, we pick one category to fake an extra event for
+ // so we can test if the event limit selectors do the right thing.
+
+ let firstCategory: string | undefined;
+
+ const compiledStats = node.relatedEvents.reduce(
+ (counts: Record, relatedEvent) => {
+ // `relatedEvent.event.category` is `string | string[]`.
+ // Wrap it in an array and flatten that array to get a `string[] | [string]`
+ // which we can loop over.
+ const categories: string[] = [relatedEvent.event.category].flat();
+
+ for (const category of categories) {
+ // Set the first category as 'categoryToOverCount'
+ if (firstCategory === undefined) {
+ firstCategory = category;
+ }
+
+ // Increment the count of events with this category
+ counts[category] = counts[category] ? counts[category] + 1 : 1;
+ }
+ return counts;
+ },
+ {}
+ );
+ if (firstCategory === undefined) {
+ throw new Error('there were no related events for the node.');
+ }
+ return {
+ /**
+ * Object to use for the first child nodes stats `events` object?
+ */
+ eventStats: {
+ total: totalRelatedEvents,
+ byCategory: compiledStats,
+ },
+ firstCategory,
+ };
+}
diff --git a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts
index 9c47c765457e3..990b911e5dbd0 100644
--- a/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts
+++ b/x-pack/plugins/security_solution/public/resolver/store/data/selectors.ts
@@ -5,7 +5,7 @@
*/
import rbush from 'rbush';
-import { createSelector } from 'reselect';
+import { createSelector, defaultMemoize } from 'reselect';
import {
DataState,
AdjacentProcessMap,
@@ -32,6 +32,7 @@ import {
} from '../../../../common/endpoint/types';
import * as resolverTreeModel from '../../models/resolver_tree';
import { isometricTaxiLayout } from '../../models/indexed_process_tree/isometric_taxi_layout';
+import { allEventCategories } from '../../../../common/endpoint/models/event';
/**
* If there is currently a request.
@@ -167,6 +168,116 @@ export function hasMoreAncestors(state: DataState): boolean {
return tree ? resolverTreeModel.hasMoreAncestors(tree) : false;
}
+interface RelatedInfoFunctions {
+ shouldShowLimitForCategory: (category: string) => boolean;
+ numberNotDisplayedForCategory: (category: string) => number;
+ numberActuallyDisplayedForCategory: (category: string) => number;
+}
+/**
+ * A map of `entity_id`s to functions that provide information about
+ * related events by ECS `.category` Primarily to avoid having business logic
+ * in UI components.
+ */
+export const relatedEventInfoByEntityId: (
+ state: DataState
+) => (entityID: string) => RelatedInfoFunctions | null = createSelector(
+ relatedEventsByEntityId,
+ relatedEventsStats,
+ function selectLineageLimitInfo(
+ /* eslint-disable no-shadow */
+ relatedEventsByEntityId,
+ relatedEventsStats
+ /* eslint-enable no-shadow */
+ ) {
+ if (!relatedEventsStats) {
+ // If there are no related event stats, there are no related event info objects
+ return (entityId: string) => null;
+ }
+ return (entityId) => {
+ const stats = relatedEventsStats.get(entityId);
+ if (!stats) {
+ return null;
+ }
+ const eventsResponseForThisEntry = relatedEventsByEntityId.get(entityId);
+ const hasMoreEvents =
+ eventsResponseForThisEntry && eventsResponseForThisEntry.nextEvent !== null;
+ /**
+ * Get the "aggregate" total for the event category (i.e. _all_ events that would qualify as being "in category")
+ * For a set like `[DNS,File][File,DNS][Registry]` The first and second events would contribute to the aggregate total for DNS being 2.
+ * This is currently aligned with how the backed provides this information.
+ *
+ * @param eventCategory {string} The ECS category like 'file','dns',etc.
+ */
+ const aggregateTotalForCategory = (eventCategory: string): number => {
+ return stats.events.byCategory[eventCategory] || 0;
+ };
+
+ /**
+ * Get all the related events in the category provided.
+ *
+ * @param eventCategory {string} The ECS category like 'file','dns',etc.
+ */
+ const unmemoizedMatchingEventsForCategory = (eventCategory: string): ResolverEvent[] => {
+ if (!eventsResponseForThisEntry) {
+ return [];
+ }
+ return eventsResponseForThisEntry.events.filter((resolverEvent) => {
+ for (const category of [allEventCategories(resolverEvent)].flat()) {
+ if (category === eventCategory) {
+ return true;
+ }
+ }
+ return false;
+ });
+ };
+
+ const matchingEventsForCategory = defaultMemoize(unmemoizedMatchingEventsForCategory);
+
+ /**
+ * The number of events that occurred before the API limit was reached.
+ * The number of events that came back form the API that have `eventCategory` in their list of categories.
+ *
+ * @param eventCategory {string} The ECS category like 'file','dns',etc.
+ */
+ const numberActuallyDisplayedForCategory = (eventCategory: string): number => {
+ return matchingEventsForCategory(eventCategory)?.length || 0;
+ };
+
+ /**
+ * The total number counted by the backend - the number displayed
+ *
+ * @param eventCategory {string} The ECS category like 'file','dns',etc.
+ */
+ const numberNotDisplayedForCategory = (eventCategory: string): number => {
+ return (
+ aggregateTotalForCategory(eventCategory) -
+ numberActuallyDisplayedForCategory(eventCategory)
+ );
+ };
+
+ /**
+ * `true` when the `nextEvent` cursor appeared in the results and we are short on the number needed to
+ * fullfill the aggregate count.
+ *
+ * @param eventCategory {string} The ECS category like 'file','dns',etc.
+ */
+ const shouldShowLimitForCategory = (eventCategory: string): boolean => {
+ if (hasMoreEvents && numberNotDisplayedForCategory(eventCategory) > 0) {
+ return true;
+ }
+ return false;
+ };
+
+ const entryValue = {
+ shouldShowLimitForCategory,
+ numberNotDisplayedForCategory,
+ numberActuallyDisplayedForCategory,
+ };
+ return entryValue;
+ };
+ }
+);
+
/**
* If we need to fetch, this is the ID to fetch.
*/
@@ -285,6 +396,7 @@ export const visibleProcessNodePositionsAndEdgeLineSegments = createSelector(
};
}
);
+
/**
* If there is a pending request that's for a entity ID that doesn't matche the `entityID`, then we should cancel it.
*/
diff --git a/x-pack/plugins/security_solution/public/resolver/store/selectors.ts b/x-pack/plugins/security_solution/public/resolver/store/selectors.ts
index 2bc254d118d33..6e512cfe13f62 100644
--- a/x-pack/plugins/security_solution/public/resolver/store/selectors.ts
+++ b/x-pack/plugins/security_solution/public/resolver/store/selectors.ts
@@ -103,6 +103,16 @@ export const relatedEventsReady = composeSelectors(
dataSelectors.relatedEventsReady
);
+/**
+ * Business logic lookup functions by ECS category by entity id.
+ * Example usage:
+ * const numberOfFileEvents = infoByEntityId.get(`someEntityId`)?.getAggregateTotalForCategory(`file`);
+ */
+export const relatedEventInfoByEntityId = composeSelectors(
+ dataStateSelector,
+ dataSelectors.relatedEventInfoByEntityId
+);
+
/**
* Returns the id of the "current" tree node (fake-focused)
*/
@@ -158,6 +168,16 @@ export const isLoading = composeSelectors(dataStateSelector, dataSelectors.isLoa
*/
export const hasError = composeSelectors(dataStateSelector, dataSelectors.hasError);
+/**
+ * True if the children cursor is not null
+ */
+export const hasMoreChildren = composeSelectors(dataStateSelector, dataSelectors.hasMoreChildren);
+
+/**
+ * True if the ancestor cursor is not null
+ */
+export const hasMoreAncestors = composeSelectors(dataStateSelector, dataSelectors.hasMoreAncestors);
+
/**
* An array containing all the processes currently in the Resolver than can be graphed
*/
diff --git a/x-pack/plugins/security_solution/public/resolver/view/limit_warnings.tsx b/x-pack/plugins/security_solution/public/resolver/view/limit_warnings.tsx
new file mode 100644
index 0000000000000..e3bad8ee2e574
--- /dev/null
+++ b/x-pack/plugins/security_solution/public/resolver/view/limit_warnings.tsx
@@ -0,0 +1,126 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import React from 'react';
+import { EuiCallOut } from '@elastic/eui';
+import { FormattedMessage } from 'react-intl';
+
+const lineageLimitMessage = (
+ <>
+
+ >
+);
+
+const LineageTitleMessage = React.memo(function LineageTitleMessage({
+ numberOfEntries,
+}: {
+ numberOfEntries: number;
+}) {
+ return (
+ <>
+
+ >
+ );
+});
+
+const RelatedEventsLimitMessage = React.memo(function RelatedEventsLimitMessage({
+ category,
+ numberOfEventsMissing,
+}: {
+ numberOfEventsMissing: number;
+ category: string;
+}) {
+ return (
+ <>
+
+ >
+ );
+});
+
+const RelatedLimitTitleMessage = React.memo(function RelatedLimitTitleMessage({
+ category,
+ numberOfEventsDisplayed,
+}: {
+ numberOfEventsDisplayed: number;
+ category: string;
+}) {
+ return (
+ <>
+
+ >
+ );
+});
+
+/**
+ * Limit warning for hitting the /events API limit
+ */
+export const RelatedEventLimitWarning = React.memo(function RelatedEventLimitWarning({
+ className,
+ eventType,
+ numberActuallyDisplayed,
+ numberMissing,
+}: {
+ className?: string;
+ eventType: string;
+ numberActuallyDisplayed: number;
+ numberMissing: number;
+}) {
+ /**
+ * Based on API limits, all related events may not be displayed.
+ */
+ return (
+
+ }
+ >
+
+
+
+
+ );
+});
+
+/**
+ * Limit warning for hitting a limit of nodes in the tree
+ */
+export const LimitWarning = React.memo(function LimitWarning({
+ className,
+ numberDisplayed,
+}: {
+ className?: string;
+ numberDisplayed: number;
+}) {
+ return (
+ }
+ >
+ {lineageLimitMessage}
+
+ );
+});
diff --git a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_list.tsx b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_list.tsx
index 9152649c07abf..0ed677885775f 100644
--- a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_list.tsx
+++ b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_process_list.tsx
@@ -13,6 +13,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useSelector } from 'react-redux';
+import styled from 'styled-components';
import * as event from '../../../../common/endpoint/models/event';
import * as selectors from '../../store/selectors';
import { CrumbInfo, formatter, StyledBreadcrumbs } from './panel_content_utilities';
@@ -20,6 +21,27 @@ import { useResolverDispatch } from '../use_resolver_dispatch';
import { SideEffectContext } from '../side_effect_context';
import { CubeForProcess } from './process_cube_icon';
import { ResolverEvent } from '../../../../common/endpoint/types';
+import { LimitWarning } from '../limit_warnings';
+
+const StyledLimitWarning = styled(LimitWarning)`
+ flex-flow: row wrap;
+ display: block;
+ align-items: baseline;
+ margin-top: 1em;
+
+ & .euiCallOutHeader {
+ display: inline;
+ margin-right: 0.25em;
+ }
+
+ & .euiText {
+ display: inline;
+ }
+
+ & .euiText p {
+ display: inline;
+ }
+`;
/**
* The "default" view for the panel: A list of all the processes currently in the graph.
@@ -145,6 +167,7 @@ export const ProcessListWithCounts = memo(function ProcessListWithCounts({
}),
[processNodePositions]
);
+ const numberOfProcesses = processTableView.length;
const crumbs = useMemo(() => {
return [
@@ -160,9 +183,13 @@ export const ProcessListWithCounts = memo(function ProcessListWithCounts({
];
}, []);
+ const children = useSelector(selectors.hasMoreChildren);
+ const ancestors = useSelector(selectors.hasMoreAncestors);
+ const showWarning = children === true || ancestors === true;
return (
<>
+ {showWarning && }
items={processTableView} columns={columns} sorting />
>
diff --git a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_list.tsx b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_list.tsx
index 1c17cf7e6ce34..591432e1f9f9f 100644
--- a/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_list.tsx
+++ b/x-pack/plugins/security_solution/public/resolver/view/panels/panel_content_related_list.tsx
@@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n';
import { EuiTitle, EuiSpacer, EuiText, EuiButtonEmpty, EuiHorizontalRule } from '@elastic/eui';
import { useSelector } from 'react-redux';
import { FormattedMessage } from 'react-intl';
+import styled from 'styled-components';
import {
CrumbInfo,
formatDate,
@@ -20,6 +21,7 @@ import * as event from '../../../../common/endpoint/models/event';
import { ResolverEvent, ResolverNodeStats } from '../../../../common/endpoint/types';
import * as selectors from '../../store/selectors';
import { useResolverDispatch } from '../use_resolver_dispatch';
+import { RelatedEventLimitWarning } from '../limit_warnings';
/**
* This view presents a list of related events of a given type for a given process.
@@ -40,16 +42,53 @@ interface MatchingEventEntry {
setQueryParams: () => void;
}
+const StyledRelatedLimitWarning = styled(RelatedEventLimitWarning)`
+ flex-flow: row wrap;
+ display: block;
+ align-items: baseline;
+ margin-top: 1em;
+
+ & .euiCallOutHeader {
+ display: inline;
+ margin-right: 0.25em;
+ }
+
+ & .euiText {
+ display: inline;
+ }
+
+ & .euiText p {
+ display: inline;
+ }
+`;
+
const DisplayList = memo(function DisplayList({
crumbs,
matchingEventEntries,
+ eventType,
+ processEntityId,
}: {
crumbs: Array<{ text: string | JSX.Element; onClick: () => void }>;
matchingEventEntries: MatchingEventEntry[];
+ eventType: string;
+ processEntityId: string;
}) {
+ const relatedLookupsByCategory = useSelector(selectors.relatedEventInfoByEntityId);
+ const lookupsForThisNode = relatedLookupsByCategory(processEntityId);
+ const shouldShowLimitWarning = lookupsForThisNode?.shouldShowLimitForCategory(eventType);
+ const numberDisplayed = lookupsForThisNode?.numberActuallyDisplayedForCategory(eventType);
+ const numberMissing = lookupsForThisNode?.numberNotDisplayedForCategory(eventType);
+
return (
<>
+ {shouldShowLimitWarning && typeof numberDisplayed !== 'undefined' && numberMissing ? (
+
+ ) : null}
<>
{matchingEventEntries.map((eventView, index) => {
@@ -250,6 +289,13 @@ export const ProcessEventListNarrowedByType = memo(function ProcessEventListNarr
);
}
- return ;
+ return (
+
+ );
});
ProcessEventListNarrowedByType.displayName = 'ProcessEventListNarrowedByType';
diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/common.ts b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/common.ts
index 71d14eb1226d5..77a5e85b14199 100644
--- a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/common.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/common.ts
@@ -7,13 +7,13 @@ import { Logger } from 'src/core/server';
export const ArtifactConstants = {
GLOBAL_ALLOWLIST_NAME: 'endpoint-exceptionlist',
- SAVED_OBJECT_TYPE: 'endpoint:user-artifact:v2',
+ SAVED_OBJECT_TYPE: 'endpoint:user-artifact',
SUPPORTED_OPERATING_SYSTEMS: ['linux', 'macos', 'windows'],
SCHEMA_VERSION: 'v1',
};
export const ManifestConstants = {
- SAVED_OBJECT_TYPE: 'endpoint:user-artifact-manifest:v2',
+ SAVED_OBJECT_TYPE: 'endpoint:user-artifact-manifest',
SCHEMA_VERSION: 'v1',
INITIAL_VERSION: 'WzAsMF0=',
};
diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/saved_object_mappings.ts b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/saved_object_mappings.ts
index 89e974a3d5fd3..0fb433df95de3 100644
--- a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/saved_object_mappings.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/saved_object_mappings.ts
@@ -45,7 +45,6 @@ export const exceptionsArtifactSavedObjectMappings: SavedObjectsType['mappings']
},
body: {
type: 'binary',
- index: false,
},
},
};
@@ -66,14 +65,14 @@ export const manifestSavedObjectMappings: SavedObjectsType['mappings'] = {
export const exceptionsArtifactType: SavedObjectsType = {
name: exceptionsArtifactSavedObjectType,
- hidden: false, // TODO: should these be hidden?
+ hidden: false,
namespaceType: 'agnostic',
mappings: exceptionsArtifactSavedObjectMappings,
};
export const manifestType: SavedObjectsType = {
name: manifestSavedObjectType,
- hidden: false, // TODO: should these be hidden?
+ hidden: false,
namespaceType: 'agnostic',
mappings: manifestSavedObjectMappings,
};
diff --git a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.mock.ts b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.mock.ts
index 3bdc5dfbcbd45..3e4fee8871b8a 100644
--- a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.mock.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.mock.ts
@@ -64,7 +64,7 @@ export const getManifestManagerMock = (opts?: {
}
packageConfigService.list = jest.fn().mockResolvedValue({
total: 1,
- items: [createPackageConfigMock()],
+ items: [{ version: 'abcd', ...createPackageConfigMock() }],
});
let savedObjectsClient = savedObjectsClientMock.create();
diff --git a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.test.ts b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.test.ts
index d092e7060f8aa..80d325ece765c 100644
--- a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.test.ts
+++ b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_manager/manifest_manager.test.ts
@@ -77,8 +77,36 @@ describe('manifest_manager', () => {
const packageConfigService = createPackageConfigServiceMock();
const manifestManager = getManifestManagerMock({ packageConfigService });
const snapshot = await manifestManager.getSnapshot();
- const dispatched = await manifestManager.dispatch(snapshot!.manifest);
- expect(dispatched).toEqual([]);
+ const dispatchErrors = await manifestManager.dispatch(snapshot!.manifest);
+ expect(dispatchErrors).toEqual([]);
+ const entries = snapshot!.manifest.getEntries();
+ const artifact = Object.values(entries)[0].getArtifact();
+ expect(
+ packageConfigService.update.mock.calls[0][2].inputs[0].config!.artifact_manifest.value
+ ).toEqual({
+ manifest_version: ManifestConstants.INITIAL_VERSION,
+ schema_version: 'v1',
+ artifacts: {
+ [artifact.identifier]: {
+ compression_algorithm: 'none',
+ encryption_algorithm: 'none',
+ decoded_sha256: artifact.decodedSha256,
+ encoded_sha256: artifact.encodedSha256,
+ decoded_size: artifact.decodedSize,
+ encoded_size: artifact.encodedSize,
+ relative_url: `/api/endpoint/artifacts/download/${artifact.identifier}/${artifact.decodedSha256}`,
+ },
+ },
+ });
+ });
+
+ test('ManifestManager fails to dispatch on conflict', async () => {
+ const packageConfigService = createPackageConfigServiceMock();
+ const manifestManager = getManifestManagerMock({ packageConfigService });
+ const snapshot = await manifestManager.getSnapshot();
+ packageConfigService.update.mockRejectedValue({ status: 409 });
+ const dispatchErrors = await manifestManager.dispatch(snapshot!.manifest);
+ expect(dispatchErrors).toEqual([{ status: 409 }]);
const entries = snapshot!.manifest.getEntries();
const artifact = Object.values(entries)[0].getArtifact();
expect(
diff --git a/x-pack/plugins/security_solution/server/plugin.ts b/x-pack/plugins/security_solution/server/plugin.ts
index 3ba978ebb0ee7..7819160a31564 100644
--- a/x-pack/plugins/security_solution/server/plugin.ts
+++ b/x-pack/plugins/security_solution/server/plugin.ts
@@ -16,6 +16,7 @@ import {
PluginInitializerContext,
SavedObjectsClient,
} from '../../../../src/core/server';
+import { UsageCollectionSetup } from '../../../../src/plugins/usage_collection/server';
import { PluginSetupContract as AlertingSetup } from '../../alerts/server';
import { SecurityPluginSetup as SecuritySetup } from '../../security/server';
import { PluginSetupContract as FeaturesSetup } from '../../features/server';
@@ -46,17 +47,19 @@ import { ArtifactClient, ManifestManager } from './endpoint/services';
import { EndpointAppContextService } from './endpoint/endpoint_app_context_services';
import { EndpointAppContext } from './endpoint/types';
import { registerDownloadExceptionListRoute } from './endpoint/routes/artifacts';
+import { initUsageCollectors } from './usage';
export interface SetupPlugins {
alerts: AlertingSetup;
encryptedSavedObjects?: EncryptedSavedObjectsSetup;
features: FeaturesSetup;
licensing: LicensingPluginSetup;
+ lists?: ListPluginSetup;
+ ml?: MlSetup;
security?: SecuritySetup;
spaces?: SpacesSetup;
taskManager?: TaskManagerSetupContract;
- ml?: MlSetup;
- lists?: ListPluginSetup;
+ usageCollection?: UsageCollectionSetup;
}
export interface StartPlugins {
@@ -106,9 +109,15 @@ export class Plugin implements IPlugin void;
+export interface UsageData {
+ detections: DetectionsUsage;
+}
+
+export const registerCollector: RegisterCollector = ({ kibanaIndex, ml, usageCollection }) => {
+ if (!usageCollection) {
+ return;
+ }
+
+ const collector = usageCollection.makeUsageCollector({
+ type: 'security_solution',
+ schema: {
+ detections: {
+ detection_rules: {
+ custom: {
+ enabled: { type: 'long' },
+ disabled: { type: 'long' },
+ },
+ elastic: {
+ enabled: { type: 'long' },
+ disabled: { type: 'long' },
+ },
+ },
+ ml_jobs: {
+ custom: {
+ enabled: { type: 'long' },
+ disabled: { type: 'long' },
+ },
+ elastic: {
+ enabled: { type: 'long' },
+ disabled: { type: 'long' },
+ },
+ },
+ },
+ },
+ isReady: () => kibanaIndex.length > 0,
+ fetch: async (callCluster: LegacyAPICaller): Promise => ({
+ detections: await fetchDetectionsUsage(kibanaIndex, callCluster, ml),
+ }),
+ });
+
+ usageCollection.registerCollector(collector);
+};
diff --git a/x-pack/plugins/security_solution/server/usage/detections.mocks.ts b/x-pack/plugins/security_solution/server/usage/detections.mocks.ts
new file mode 100644
index 0000000000000..c80dc6936ec7b
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/detections.mocks.ts
@@ -0,0 +1,162 @@
+/*
+ * 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 { INTERNAL_IMMUTABLE_KEY } from '../../common/constants';
+
+export const getMockJobSummaryResponse = () => [
+ {
+ id: 'linux_anomalous_network_activity_ecs',
+ description:
+ 'SIEM Auditbeat: Looks for unusual processes using the network which could indicate command-and-control, lateral movement, persistence, or data exfiltration activity (beta)',
+ groups: ['auditbeat', 'process', 'siem'],
+ processed_record_count: 141889,
+ memory_status: 'ok',
+ jobState: 'opened',
+ hasDatafeed: true,
+ datafeedId: 'datafeed-linux_anomalous_network_activity_ecs',
+ datafeedIndices: ['auditbeat-*'],
+ datafeedState: 'started',
+ latestTimestampMs: 1594085401911,
+ earliestTimestampMs: 1593054845656,
+ latestResultsTimestampMs: 1594085401911,
+ isSingleMetricViewerJob: true,
+ nodeName: 'node',
+ },
+ {
+ id: 'linux_anomalous_network_port_activity_ecs',
+ description:
+ 'SIEM Auditbeat: Looks for unusual destination port activity that could indicate command-and-control, persistence mechanism, or data exfiltration activity (beta)',
+ groups: ['auditbeat', 'process', 'siem'],
+ processed_record_count: 0,
+ memory_status: 'ok',
+ jobState: 'closed',
+ hasDatafeed: true,
+ datafeedId: 'datafeed-linux_anomalous_network_port_activity_ecs',
+ datafeedIndices: ['auditbeat-*'],
+ datafeedState: 'stopped',
+ isSingleMetricViewerJob: true,
+ },
+ {
+ id: 'other_job',
+ description: 'a job that is custom',
+ groups: ['auditbeat', 'process'],
+ processed_record_count: 0,
+ memory_status: 'ok',
+ jobState: 'closed',
+ hasDatafeed: true,
+ datafeedId: 'datafeed-other',
+ datafeedIndices: ['auditbeat-*'],
+ datafeedState: 'stopped',
+ isSingleMetricViewerJob: true,
+ },
+ {
+ id: 'another_job',
+ description: 'another job that is custom',
+ groups: ['auditbeat', 'process'],
+ processed_record_count: 0,
+ memory_status: 'ok',
+ jobState: 'opened',
+ hasDatafeed: true,
+ datafeedId: 'datafeed-another',
+ datafeedIndices: ['auditbeat-*'],
+ datafeedState: 'started',
+ isSingleMetricViewerJob: true,
+ },
+];
+
+export const getMockListModulesResponse = () => [
+ {
+ id: 'siem_auditbeat',
+ title: 'SIEM Auditbeat',
+ description:
+ 'Detect suspicious network activity and unusual processes in Auditbeat data (beta).',
+ type: 'Auditbeat data',
+ logoFile: 'logo.json',
+ defaultIndexPattern: 'auditbeat-*',
+ query: {
+ bool: {
+ filter: [
+ {
+ term: {
+ 'agent.type': 'auditbeat',
+ },
+ },
+ ],
+ },
+ },
+ jobs: [
+ {
+ id: 'linux_anomalous_network_activity_ecs',
+ config: {
+ job_type: 'anomaly_detector',
+ description:
+ 'SIEM Auditbeat: Looks for unusual processes using the network which could indicate command-and-control, lateral movement, persistence, or data exfiltration activity (beta)',
+ groups: ['siem', 'auditbeat', 'process'],
+ analysis_config: {
+ bucket_span: '15m',
+ detectors: [
+ {
+ detector_description: 'rare by "process.name"',
+ function: 'rare',
+ by_field_name: 'process.name',
+ },
+ ],
+ influencers: ['host.name', 'process.name', 'user.name', 'destination.ip'],
+ },
+ allow_lazy_open: true,
+ analysis_limits: {
+ model_memory_limit: '64mb',
+ },
+ data_description: {
+ time_field: '@timestamp',
+ },
+ },
+ },
+ {
+ id: 'linux_anomalous_network_port_activity_ecs',
+ config: {
+ job_type: 'anomaly_detector',
+ description:
+ 'SIEM Auditbeat: Looks for unusual destination port activity that could indicate command-and-control, persistence mechanism, or data exfiltration activity (beta)',
+ groups: ['siem', 'auditbeat', 'network'],
+ analysis_config: {
+ bucket_span: '15m',
+ detectors: [
+ {
+ detector_description: 'rare by "destination.port"',
+ function: 'rare',
+ by_field_name: 'destination.port',
+ },
+ ],
+ influencers: ['host.name', 'process.name', 'user.name', 'destination.ip'],
+ },
+ allow_lazy_open: true,
+ analysis_limits: {
+ model_memory_limit: '32mb',
+ },
+ data_description: {
+ time_field: '@timestamp',
+ },
+ },
+ },
+ ],
+ datafeeds: [],
+ kibana: {},
+ },
+];
+
+export const getMockRulesResponse = () => ({
+ hits: {
+ hits: [
+ { _source: { alert: { enabled: true, tags: [`${INTERNAL_IMMUTABLE_KEY}:true`] } } },
+ { _source: { alert: { enabled: true, tags: [`${INTERNAL_IMMUTABLE_KEY}:false`] } } },
+ { _source: { alert: { enabled: false, tags: [`${INTERNAL_IMMUTABLE_KEY}:true`] } } },
+ { _source: { alert: { enabled: true, tags: [`${INTERNAL_IMMUTABLE_KEY}:true`] } } },
+ { _source: { alert: { enabled: false, tags: [`${INTERNAL_IMMUTABLE_KEY}:false`] } } },
+ { _source: { alert: { enabled: false, tags: [`${INTERNAL_IMMUTABLE_KEY}:true`] } } },
+ { _source: { alert: { enabled: false, tags: [`${INTERNAL_IMMUTABLE_KEY}:true`] } } },
+ ],
+ },
+});
diff --git a/x-pack/plugins/security_solution/server/usage/detections.test.ts b/x-pack/plugins/security_solution/server/usage/detections.test.ts
new file mode 100644
index 0000000000000..7fd2d3eb9ff27
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/detections.test.ts
@@ -0,0 +1,107 @@
+/*
+ * 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 { LegacyAPICaller } from '../../../../../src/core/server';
+import { elasticsearchServiceMock } from '../../../../../src/core/server/mocks';
+import { jobServiceProvider } from '../../../ml/server/models/job_service';
+import { DataRecognizer } from '../../../ml/server/models/data_recognizer';
+import { mlServicesMock } from '../lib/machine_learning/mocks';
+import {
+ getMockJobSummaryResponse,
+ getMockListModulesResponse,
+ getMockRulesResponse,
+} from './detections.mocks';
+import { fetchDetectionsUsage } from './detections';
+
+jest.mock('../../../ml/server/models/job_service');
+jest.mock('../../../ml/server/models/data_recognizer');
+
+describe('Detections Usage', () => {
+ describe('fetchDetectionsUsage()', () => {
+ let callClusterMock: jest.Mocked;
+ let mlMock: ReturnType;
+
+ beforeEach(() => {
+ callClusterMock = elasticsearchServiceMock.createLegacyClusterClient().callAsInternalUser;
+ mlMock = mlServicesMock.create();
+ });
+
+ it('returns zeroed counts if both calls are empty', async () => {
+ const result = await fetchDetectionsUsage('', callClusterMock, mlMock);
+
+ expect(result).toEqual({
+ detection_rules: {
+ custom: {
+ enabled: 0,
+ disabled: 0,
+ },
+ elastic: {
+ enabled: 0,
+ disabled: 0,
+ },
+ },
+ ml_jobs: {
+ custom: {
+ enabled: 0,
+ disabled: 0,
+ },
+ elastic: {
+ enabled: 0,
+ disabled: 0,
+ },
+ },
+ });
+ });
+
+ it('tallies rules data given rules results', async () => {
+ (callClusterMock as jest.Mock).mockResolvedValue(getMockRulesResponse());
+ const result = await fetchDetectionsUsage('', callClusterMock, mlMock);
+
+ expect(result).toEqual(
+ expect.objectContaining({
+ detection_rules: {
+ custom: {
+ enabled: 1,
+ disabled: 1,
+ },
+ elastic: {
+ enabled: 2,
+ disabled: 3,
+ },
+ },
+ })
+ );
+ });
+
+ it('tallies jobs data given jobs results', async () => {
+ const mockJobSummary = jest.fn().mockResolvedValue(getMockJobSummaryResponse());
+ const mockListModules = jest.fn().mockResolvedValue(getMockListModulesResponse());
+ (jobServiceProvider as jest.Mock).mockImplementation(() => ({
+ jobsSummary: mockJobSummary,
+ }));
+ (DataRecognizer as jest.Mock).mockImplementation(() => ({
+ listModules: mockListModules,
+ }));
+
+ const result = await fetchDetectionsUsage('', callClusterMock, mlMock);
+
+ expect(result).toEqual(
+ expect.objectContaining({
+ ml_jobs: {
+ custom: {
+ enabled: 1,
+ disabled: 1,
+ },
+ elastic: {
+ enabled: 1,
+ disabled: 1,
+ },
+ },
+ })
+ );
+ });
+ });
+});
diff --git a/x-pack/plugins/security_solution/server/usage/detections.ts b/x-pack/plugins/security_solution/server/usage/detections.ts
new file mode 100644
index 0000000000000..1475a8ae34625
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/detections.ts
@@ -0,0 +1,39 @@
+/*
+ * 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 { LegacyAPICaller } from '../../../../../src/core/server';
+import { getMlJobsUsage, getRulesUsage } from './detections_helpers';
+import { MlPluginSetup } from '../../../ml/server';
+
+interface FeatureUsage {
+ enabled: number;
+ disabled: number;
+}
+
+export interface DetectionRulesUsage {
+ custom: FeatureUsage;
+ elastic: FeatureUsage;
+}
+
+export interface MlJobsUsage {
+ custom: FeatureUsage;
+ elastic: FeatureUsage;
+}
+
+export interface DetectionsUsage {
+ detection_rules: DetectionRulesUsage;
+ ml_jobs: MlJobsUsage;
+}
+
+export const fetchDetectionsUsage = async (
+ kibanaIndex: string,
+ callCluster: LegacyAPICaller,
+ ml: MlPluginSetup | undefined
+): Promise => {
+ const rulesUsage = await getRulesUsage(kibanaIndex, callCluster);
+ const mlJobsUsage = await getMlJobsUsage(ml);
+ return { detection_rules: rulesUsage, ml_jobs: mlJobsUsage };
+};
diff --git a/x-pack/plugins/security_solution/server/usage/detections_helpers.ts b/x-pack/plugins/security_solution/server/usage/detections_helpers.ts
new file mode 100644
index 0000000000000..18a90b12991b2
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/detections_helpers.ts
@@ -0,0 +1,188 @@
+/*
+ * 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 { SearchParams } from 'elasticsearch';
+
+import { LegacyAPICaller, SavedObjectsClient } from '../../../../../src/core/server';
+// eslint-disable-next-line @kbn/eslint/no-restricted-paths
+import { jobServiceProvider } from '../../../ml/server/models/job_service';
+// eslint-disable-next-line @kbn/eslint/no-restricted-paths
+import { DataRecognizer } from '../../../ml/server/models/data_recognizer';
+import { MlPluginSetup } from '../../../ml/server';
+import { SIGNALS_ID, INTERNAL_IMMUTABLE_KEY } from '../../common/constants';
+import { DetectionRulesUsage, MlJobsUsage } from './detections';
+import { isJobStarted } from '../../common/machine_learning/helpers';
+
+interface DetectionsMetric {
+ isElastic: boolean;
+ isEnabled: boolean;
+}
+
+const isElasticRule = (tags: string[]) => tags.includes(`${INTERNAL_IMMUTABLE_KEY}:true`);
+
+const initialRulesUsage: DetectionRulesUsage = {
+ custom: {
+ enabled: 0,
+ disabled: 0,
+ },
+ elastic: {
+ enabled: 0,
+ disabled: 0,
+ },
+};
+
+const initialMlJobsUsage: MlJobsUsage = {
+ custom: {
+ enabled: 0,
+ disabled: 0,
+ },
+ elastic: {
+ enabled: 0,
+ disabled: 0,
+ },
+};
+
+const updateRulesUsage = (
+ ruleMetric: DetectionsMetric,
+ usage: DetectionRulesUsage
+): DetectionRulesUsage => {
+ const { isEnabled, isElastic } = ruleMetric;
+ if (isEnabled && isElastic) {
+ return {
+ ...usage,
+ elastic: {
+ ...usage.elastic,
+ enabled: usage.elastic.enabled + 1,
+ },
+ };
+ } else if (!isEnabled && isElastic) {
+ return {
+ ...usage,
+ elastic: {
+ ...usage.elastic,
+ disabled: usage.elastic.disabled + 1,
+ },
+ };
+ } else if (isEnabled && !isElastic) {
+ return {
+ ...usage,
+ custom: {
+ ...usage.custom,
+ enabled: usage.custom.enabled + 1,
+ },
+ };
+ } else if (!isEnabled && !isElastic) {
+ return {
+ ...usage,
+ custom: {
+ ...usage.custom,
+ disabled: usage.custom.disabled + 1,
+ },
+ };
+ } else {
+ return usage;
+ }
+};
+
+const updateMlJobsUsage = (jobMetric: DetectionsMetric, usage: MlJobsUsage): MlJobsUsage => {
+ const { isEnabled, isElastic } = jobMetric;
+ if (isEnabled && isElastic) {
+ return {
+ ...usage,
+ elastic: {
+ ...usage.elastic,
+ enabled: usage.elastic.enabled + 1,
+ },
+ };
+ } else if (!isEnabled && isElastic) {
+ return {
+ ...usage,
+ elastic: {
+ ...usage.elastic,
+ disabled: usage.elastic.disabled + 1,
+ },
+ };
+ } else if (isEnabled && !isElastic) {
+ return {
+ ...usage,
+ custom: {
+ ...usage.custom,
+ enabled: usage.custom.enabled + 1,
+ },
+ };
+ } else if (!isEnabled && !isElastic) {
+ return {
+ ...usage,
+ custom: {
+ ...usage.custom,
+ disabled: usage.custom.disabled + 1,
+ },
+ };
+ } else {
+ return usage;
+ }
+};
+
+export const getRulesUsage = async (
+ index: string,
+ callCluster: LegacyAPICaller
+): Promise => {
+ let rulesUsage: DetectionRulesUsage = initialRulesUsage;
+ const ruleSearchOptions: SearchParams = {
+ body: { query: { bool: { filter: { term: { 'alert.alertTypeId': SIGNALS_ID } } } } },
+ filterPath: ['hits.hits._source.alert.enabled', 'hits.hits._source.alert.tags'],
+ ignoreUnavailable: true,
+ index,
+ size: 10000, // elasticsearch index.max_result_window default value
+ };
+
+ try {
+ const ruleResults = await callCluster<{ alert: { enabled: boolean; tags: string[] } }>(
+ 'search',
+ ruleSearchOptions
+ );
+
+ if (ruleResults.hits?.hits?.length > 0) {
+ rulesUsage = ruleResults.hits.hits.reduce((usage, hit) => {
+ const isElastic = isElasticRule(hit._source.alert.tags);
+ const isEnabled = hit._source.alert.enabled;
+
+ return updateRulesUsage({ isElastic, isEnabled }, usage);
+ }, initialRulesUsage);
+ }
+ } catch (e) {
+ // ignore failure, usage will be zeroed
+ }
+
+ return rulesUsage;
+};
+
+export const getMlJobsUsage = async (ml: MlPluginSetup | undefined): Promise => {
+ let jobsUsage: MlJobsUsage = initialMlJobsUsage;
+
+ if (ml) {
+ try {
+ const mlCaller = ml.mlClient.callAsInternalUser;
+ const modules = await new DataRecognizer(
+ mlCaller,
+ ({} as unknown) as SavedObjectsClient
+ ).listModules();
+ const moduleJobs = modules.flatMap((module) => module.jobs);
+ const jobs = await jobServiceProvider(mlCaller).jobsSummary(['siem']);
+
+ jobsUsage = jobs.reduce((usage, job) => {
+ const isElastic = moduleJobs.some((moduleJob) => moduleJob.id === job.id);
+ const isEnabled = isJobStarted(job.jobState, job.datafeedState);
+
+ return updateMlJobsUsage({ isElastic, isEnabled }, usage);
+ }, initialMlJobsUsage);
+ } catch (e) {
+ // ignore failure, usage will be zeroed
+ }
+ }
+
+ return jobsUsage;
+};
diff --git a/x-pack/plugins/security_solution/server/usage/index.ts b/x-pack/plugins/security_solution/server/usage/index.ts
new file mode 100644
index 0000000000000..4d8749a83be80
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/index.ts
@@ -0,0 +1,14 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import { CollectorDependencies } from './types';
+import { registerCollector } from './collector';
+
+export type InitUsageCollectors = (deps: CollectorDependencies) => void;
+
+export const initUsageCollectors: InitUsageCollectors = (dependencies) => {
+ registerCollector(dependencies);
+};
diff --git a/x-pack/plugins/security_solution/server/usage/types.ts b/x-pack/plugins/security_solution/server/usage/types.ts
new file mode 100644
index 0000000000000..955a4eaf4be5a
--- /dev/null
+++ b/x-pack/plugins/security_solution/server/usage/types.ts
@@ -0,0 +1,12 @@
+/*
+ * 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 { SetupPlugins } from '../plugin';
+
+export type CollectorDependencies = { kibanaIndex: string } & Pick<
+ SetupPlugins,
+ 'ml' | 'usageCollection'
+>;
diff --git a/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx b/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx
index 309dad366bef8..17cce6efafb6f 100644
--- a/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx
+++ b/x-pack/plugins/snapshot_restore/public/application/components/repository_form/type_settings/readonly_settings.tsx
@@ -46,7 +46,7 @@ export const ReadonlySettings: React.FunctionComponent = ({
case 'ftp':
return (
repositories.url.allowed_urls,
diff --git a/x-pack/plugins/spaces/server/lib/request_interceptors/on_request_interceptor.ts b/x-pack/plugins/spaces/server/lib/request_interceptors/on_request_interceptor.ts
index 18e9da25576eb..4b3a5d662f12d 100644
--- a/x-pack/plugins/spaces/server/lib/request_interceptors/on_request_interceptor.ts
+++ b/x-pack/plugins/spaces/server/lib/request_interceptors/on_request_interceptor.ts
@@ -5,7 +5,7 @@
*/
import {
KibanaRequest,
- OnPreAuthToolkit,
+ OnPreRoutingToolkit,
LifecycleResponseFactory,
CoreSetup,
} from 'src/core/server';
@@ -18,10 +18,10 @@ export interface OnRequestInterceptorDeps {
http: CoreSetup['http'];
}
export function initSpacesOnRequestInterceptor({ http }: OnRequestInterceptorDeps) {
- http.registerOnPreAuth(async function spacesOnPreAuthHandler(
+ http.registerOnPreRouting(async function spacesOnPreRoutingHandler(
request: KibanaRequest,
response: LifecycleResponseFactory,
- toolkit: OnPreAuthToolkit
+ toolkit: OnPreRoutingToolkit
) {
const serverBasePath = http.basePath.serverBasePath;
const path = request.url.pathname;
diff --git a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json
index fbef75b9aa9cc..c5d528cbcce23 100644
--- a/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json
+++ b/x-pack/plugins/telemetry_collection_xpack/schema/xpack_plugins.json
@@ -41,6 +41,43 @@
}
}
},
+ "workplace_search": {
+ "properties": {
+ "ui_viewed": {
+ "properties": {
+ "setup_guide": {
+ "type": "long"
+ },
+ "overview": {
+ "type": "long"
+ }
+ }
+ },
+ "ui_error": {
+ "properties": {
+ "cannot_connect": {
+ "type": "long"
+ }
+ }
+ },
+ "ui_clicked": {
+ "properties": {
+ "header_launch_button": {
+ "type": "long"
+ },
+ "org_name_change_button": {
+ "type": "long"
+ },
+ "onboarding_card_button": {
+ "type": "long"
+ },
+ "recent_activity_source_details_link": {
+ "type": "long"
+ }
+ }
+ }
+ }
+ },
"fileUploadTelemetry": {
"properties": {
"filesUploadedTotalCount": {
@@ -127,6 +164,62 @@
}
}
},
+ "security_solution": {
+ "properties": {
+ "detections": {
+ "properties": {
+ "detection_rules": {
+ "properties": {
+ "custom": {
+ "properties": {
+ "enabled": {
+ "type": "long"
+ },
+ "disabled": {
+ "type": "long"
+ }
+ }
+ },
+ "elastic": {
+ "properties": {
+ "enabled": {
+ "type": "long"
+ },
+ "disabled": {
+ "type": "long"
+ }
+ }
+ }
+ }
+ },
+ "ml_jobs": {
+ "properties": {
+ "custom": {
+ "properties": {
+ "enabled": {
+ "type": "long"
+ },
+ "disabled": {
+ "type": "long"
+ }
+ }
+ },
+ "elastic": {
+ "properties": {
+ "enabled": {
+ "type": "long"
+ },
+ "disabled": {
+ "type": "long"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"spaces": {
"properties": {
"usesFeatureControls": {
diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json
index 92285d8bf72f8..c1f36372ec94e 100644
--- a/x-pack/plugins/translations/translations/ja-JP.json
+++ b/x-pack/plugins/translations/translations/ja-JP.json
@@ -641,7 +641,6 @@
"data.filter.filterEditor.cancelButtonLabel": "キャンセル",
"data.filter.filterEditor.createCustomLabelInputLabel": "カスタムラベル",
"data.filter.filterEditor.createCustomLabelSwitchLabel": "カスタムラベルを作成しますか?",
- "data.filter.filterEditor.dateFormatHelpLinkLabel": "対応データフォーマット",
"data.filter.filterEditor.doesNotExistOperatorOptionLabel": "存在しません",
"data.filter.filterEditor.editFilterPopupTitle": "フィルターを編集",
"data.filter.filterEditor.editFilterValuesButtonLabel": "フィルター値を編集",
@@ -7472,7 +7471,6 @@
"xpack.infra.logs.analysis.anomaliesSectionLineSeriesName": "15 分ごとのログエントリー (平均)",
"xpack.infra.logs.analysis.anomaliesSectionLoadingAriaLabel": "異常を読み込み中",
"xpack.infra.logs.analysis.anomaliesSectionTitle": "異常",
- "xpack.infra.logs.analysis.anomalySectionNoAnomaliesTitle": "異常が検出されませんでした。",
"xpack.infra.logs.analysis.anomalySectionNoDataBody": "時間範囲を調整する必要があるかもしれません。",
"xpack.infra.logs.analysis.anomalySectionNoDataTitle": "表示するデータがありません。",
"xpack.infra.logs.analysis.jobConfigurationOutdatedCalloutMessage": "異なるソース構成を使用して ML ジョブが作成されました。現在の構成を適用するにはジョブを再作成してください。これにより以前検出された異常が削除されます。",
@@ -7481,14 +7479,6 @@
"xpack.infra.logs.analysis.jobDefinitionOutdatedCalloutTitle": "古い ML ジョブ定義",
"xpack.infra.logs.analysis.jobStoppedCalloutMessage": "ML ジョブが手動またはリソース不足により停止しました。新しいログエントリーはジョブが再起動するまで処理されません。",
"xpack.infra.logs.analysis.jobStoppedCalloutTitle": "ML ジョブが停止しました",
- "xpack.infra.logs.analysis.logRateResultsToolbarText": "{startTime} から {endTime} までの {numberOfLogs} 件のログエントリーを分析しました",
- "xpack.infra.logs.analysis.logRateSectionBucketSpanLabel": "バケットスパン: ",
- "xpack.infra.logs.analysis.logRateSectionBucketSpanValue": "15 分",
- "xpack.infra.logs.analysis.logRateSectionLineSeriesName": "15 分ごとのログエントリー (平均)",
- "xpack.infra.logs.analysis.logRateSectionLoadingAriaLabel": "ログレートの結果を読み込み中",
- "xpack.infra.logs.analysis.logRateSectionNoDataBody": "時間範囲を調整する必要があるかもしれません。",
- "xpack.infra.logs.analysis.logRateSectionNoDataTitle": "表示するデータがありません。",
- "xpack.infra.logs.analysis.logRateSectionTitle": "ログレート",
"xpack.infra.logs.analysis.missingMlResultsPrivilegesBody": "本機能は機械学習ジョブを利用し、そのステータスと結果にアクセスするためには、少なくとも{machineLearningUserRole}ロールが必要です。",
"xpack.infra.logs.analysis.missingMlResultsPrivilegesTitle": "追加の機械学習の権限が必要です",
"xpack.infra.logs.analysis.missingMlSetupPrivilegesBody": "本機能は機械学習ジョブを利用し、設定には{machineLearningAdminRole}ロールが必要です。",
@@ -8042,7 +8032,6 @@
"xpack.ingestManager.agentDetails.viewAgentListTitle": "すべてのエージェント構成を表示",
"xpack.ingestManager.agentEnrollment.cancelButtonLabel": "キャンセル",
"xpack.ingestManager.agentEnrollment.continueButtonLabel": "続行",
- "xpack.ingestManager.agentEnrollment.downloadDescription": "ホストのコンピューターでElasticエージェントをダウンロードします。エージェントバイナリをダウンロードできます。検証署名はElasticの{downloadLink}にあります。",
"xpack.ingestManager.agentEnrollment.downloadLink": "ダウンロードページ",
"xpack.ingestManager.agentEnrollment.fleetNotInitializedText": "エージェントを登録する前に、フリートを設定する必要があります。{link}",
"xpack.ingestManager.agentEnrollment.flyoutTitle": "新しいエージェントを登録",
@@ -8173,7 +8162,6 @@
"xpack.ingestManager.createPackageConfig.agentConfigurationNameLabel": "構成",
"xpack.ingestManager.createPackageConfig.cancelButton": "キャンセル",
"xpack.ingestManager.createPackageConfig.cancelLinkText": "キャンセル",
- "xpack.ingestManager.createPackageConfig.packageNameLabel": "統合",
"xpack.ingestManager.createPackageConfig.pageDescriptionfromConfig": "次の手順に従い、統合をこのエージェント構成に追加します。",
"xpack.ingestManager.createPackageConfig.pageDescriptionfromPackage": "次の手順に従い、この統合をエージェント構成に追加します。",
"xpack.ingestManager.createPackageConfig.pageTitle": "データソースを追加",
@@ -8184,19 +8172,12 @@
"xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNameInputLabel": "データソース名",
"xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNamespaceInputLabel": "名前空間",
"xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel": "{type} ストリームを隠す",
- "xpack.ingestManager.createPackageConfig.stepConfigure.inputConfigErrorsTooltip": "構成エラーを修正してください",
- "xpack.ingestManager.createPackageConfig.stepConfigure.inputLevelErrorsTooltip": "構成エラーを修正してください",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsDescription": "次の設定はすべてのストリームに適用されます。",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsTitle": "設定",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputVarFieldOptionalLabel": "オプション",
"xpack.ingestManager.createPackageConfig.stepConfigure.noConfigOptionsMessage": "構成するものがありません",
"xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel": "{type} ストリームを表示",
- "xpack.ingestManager.createPackageConfig.stepConfigure.streamLevelErrorsTooltip": "構成エラーを修正してください",
- "xpack.ingestManager.createPackageConfig.stepConfigure.streamsEnabledCountText": "{count} / {total, plural, one {# ストリーム} other {# ストリーム}}が有効です",
"xpack.ingestManager.createPackageConfig.stepConfigure.toggleAdvancedOptionsButtonText": "高度なオプション",
- "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorText": "続行する前に、上記のエラーを修正してください",
- "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorTitle": "データソース構成にエラーがあります",
- "xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle": "データソースを定義",
"xpack.ingestManager.createPackageConfig.stepSelectAgentConfigTitle": "エージェント構成を選択する",
"xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText": "{count, plural, one {# エージェント} other {# エージェント}}",
"xpack.ingestManager.createPackageConfig.StepSelectConfig.errorLoadingAgentConfigsTitle": "エージェント構成の読み込みエラー",
@@ -8268,8 +8249,6 @@
"xpack.ingestManager.editPackageConfig.pageDescription": "次の手順に従い、このデータソースを編集します。",
"xpack.ingestManager.editPackageConfig.pageTitle": "データソースを編集",
"xpack.ingestManager.editPackageConfig.saveButton": "データソースを保存",
- "xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle": "収集するデータを選択",
- "xpack.ingestManager.editPackageConfig.stepDefinePackageConfigTitle": "データソースを定義",
"xpack.ingestManager.editPackageConfig.updatedNotificationMessage": "フリートは'{agentConfigName}'構成で使用されているすべてのエージェントに更新をデプロイします。",
"xpack.ingestManager.editPackageConfig.updatedNotificationTitle": "正常に'{packageConfigName}'を更新しました",
"xpack.ingestManager.enrollemntAPIKeyList.emptyMessage": "登録トークンが見つかりません。",
@@ -15258,7 +15237,6 @@
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlLabel": "パス (必須)",
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlSchemeLabel": "スキーム",
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlTitle": "URL",
- "xpack.snapshotRestore.repositoryForm.typeReadonly.urlWhitelistDescription": "この URL は {settingKey} 設定で登録する必要があります。",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathDescription": "レポジトリデータへのバケットパスです。",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathLabel": "ベースパス",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathTitle": "ベースパス",
diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json
index 457f65e89083d..7e36d5676585c 100644
--- a/x-pack/plugins/translations/translations/zh-CN.json
+++ b/x-pack/plugins/translations/translations/zh-CN.json
@@ -641,7 +641,6 @@
"data.filter.filterEditor.cancelButtonLabel": "取消",
"data.filter.filterEditor.createCustomLabelInputLabel": "定制标签",
"data.filter.filterEditor.createCustomLabelSwitchLabel": "创建定制标签?",
- "data.filter.filterEditor.dateFormatHelpLinkLabel": "已接受日期格式",
"data.filter.filterEditor.doesNotExistOperatorOptionLabel": "不存在",
"data.filter.filterEditor.editFilterPopupTitle": "编辑筛选",
"data.filter.filterEditor.editFilterValuesButtonLabel": "编辑筛选值",
@@ -7477,7 +7476,6 @@
"xpack.infra.logs.analysis.anomaliesSectionLineSeriesName": "每 15 分钟日志条目数(平均值)",
"xpack.infra.logs.analysis.anomaliesSectionLoadingAriaLabel": "正在加载异常",
"xpack.infra.logs.analysis.anomaliesSectionTitle": "异常",
- "xpack.infra.logs.analysis.anomalySectionNoAnomaliesTitle": "未检测到任何异常。",
"xpack.infra.logs.analysis.anomalySectionNoDataBody": "您可能想调整时间范围。",
"xpack.infra.logs.analysis.anomalySectionNoDataTitle": "没有可显示的数据。",
"xpack.infra.logs.analysis.jobConfigurationOutdatedCalloutMessage": "创建 ML 作业时所使用的源配置不同。重新创建作业以应用当前配置。这将移除以前检测到的异常。",
@@ -7486,14 +7484,6 @@
"xpack.infra.logs.analysis.jobDefinitionOutdatedCalloutTitle": "ML 作业定义已过期",
"xpack.infra.logs.analysis.jobStoppedCalloutMessage": "ML 作业已手动停止或由于缺乏资源而停止。作业重新启动后,才会处理新的日志条目。",
"xpack.infra.logs.analysis.jobStoppedCalloutTitle": "ML 作业已停止",
- "xpack.infra.logs.analysis.logRateResultsToolbarText": "从 {startTime} 到 {endTime} 已分析 {numberOfLogs} 个日志条目",
- "xpack.infra.logs.analysis.logRateSectionBucketSpanLabel": "存储桶跨度: ",
- "xpack.infra.logs.analysis.logRateSectionBucketSpanValue": "15 分钟",
- "xpack.infra.logs.analysis.logRateSectionLineSeriesName": "每 15 分钟日志条目数(平均值)",
- "xpack.infra.logs.analysis.logRateSectionLoadingAriaLabel": "正在加载日志速率结果",
- "xpack.infra.logs.analysis.logRateSectionNoDataBody": "您可能想调整时间范围。",
- "xpack.infra.logs.analysis.logRateSectionNoDataTitle": "没有可显示的数据。",
- "xpack.infra.logs.analysis.logRateSectionTitle": "日志速率",
"xpack.infra.logs.analysis.missingMlResultsPrivilegesBody": "此功能使用 Machine Learning 作业,要访问这些作业的状态和结果,至少需要 {machineLearningUserRole} 角色。",
"xpack.infra.logs.analysis.missingMlResultsPrivilegesTitle": "需要额外的 Machine Learning 权限",
"xpack.infra.logs.analysis.missingMlSetupPrivilegesBody": "此功能使用 Machine Learning 作业,这需要 {machineLearningAdminRole} 角色才能设置。",
@@ -8047,7 +8037,6 @@
"xpack.ingestManager.agentDetails.viewAgentListTitle": "查看所有代理配置",
"xpack.ingestManager.agentEnrollment.cancelButtonLabel": "取消",
"xpack.ingestManager.agentEnrollment.continueButtonLabel": "继续",
- "xpack.ingestManager.agentEnrollment.downloadDescription": "在主机计算机上下载 Elastic 代理。可以从 Elastic 的{downloadLink}下载代理二进制文件及其验证签名。",
"xpack.ingestManager.agentEnrollment.downloadLink": "下载页面",
"xpack.ingestManager.agentEnrollment.fleetNotInitializedText": "注册代理前需要设置 Fleet。{link}",
"xpack.ingestManager.agentEnrollment.flyoutTitle": "注册新代理",
@@ -8178,7 +8167,6 @@
"xpack.ingestManager.createPackageConfig.agentConfigurationNameLabel": "配置",
"xpack.ingestManager.createPackageConfig.cancelButton": "取消",
"xpack.ingestManager.createPackageConfig.cancelLinkText": "取消",
- "xpack.ingestManager.createPackageConfig.packageNameLabel": "集成",
"xpack.ingestManager.createPackageConfig.pageDescriptionfromConfig": "按照下面的说明将集成添加此代理配置。",
"xpack.ingestManager.createPackageConfig.pageDescriptionfromPackage": "按照下面的说明将此集成添加代理配置。",
"xpack.ingestManager.createPackageConfig.pageTitle": "添加数据源",
@@ -8189,19 +8177,12 @@
"xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNameInputLabel": "数据源名称",
"xpack.ingestManager.createPackageConfig.stepConfigure.packageConfigNamespaceInputLabel": "命名空间",
"xpack.ingestManager.createPackageConfig.stepConfigure.hideStreamsAriaLabel": "隐藏 {type} 流",
- "xpack.ingestManager.createPackageConfig.stepConfigure.inputConfigErrorsTooltip": "解决配置错误",
- "xpack.ingestManager.createPackageConfig.stepConfigure.inputLevelErrorsTooltip": "解决配置错误",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsDescription": "以下设置适用于所有流。",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputSettingsTitle": "设置",
"xpack.ingestManager.createPackageConfig.stepConfigure.inputVarFieldOptionalLabel": "可选",
"xpack.ingestManager.createPackageConfig.stepConfigure.noConfigOptionsMessage": "没有可配置的内容",
"xpack.ingestManager.createPackageConfig.stepConfigure.showStreamsAriaLabel": "显示 {type} 流",
- "xpack.ingestManager.createPackageConfig.stepConfigure.streamLevelErrorsTooltip": "解决配置错误",
- "xpack.ingestManager.createPackageConfig.stepConfigure.streamsEnabledCountText": "{count} / {total, plural, one {# 个流} other {# 个流}}已启用",
"xpack.ingestManager.createPackageConfig.stepConfigure.toggleAdvancedOptionsButtonText": "高级选项",
- "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorText": "在继续之前请解决上述错误",
- "xpack.ingestManager.createPackageConfig.stepConfigure.validationErrorTitle": "您的数据源配置有错误",
- "xpack.ingestManager.createPackageConfig.stepDefinePackageConfigTitle": "定义您的数据源",
"xpack.ingestManager.createPackageConfig.stepSelectAgentConfigTitle": "选择代理配置",
"xpack.ingestManager.createPackageConfig.StepSelectConfig.agentConfigAgentsCountText": "{count, plural, one {# 个代理} other {# 个代理}}",
"xpack.ingestManager.createPackageConfig.StepSelectConfig.errorLoadingAgentConfigsTitle": "加载代理配置时出错",
@@ -8273,8 +8254,6 @@
"xpack.ingestManager.editPackageConfig.pageDescription": "按照下面的说明编辑此数据源。",
"xpack.ingestManager.editPackageConfig.pageTitle": "编辑数据源",
"xpack.ingestManager.editPackageConfig.saveButton": "保存数据源",
- "xpack.ingestManager.editPackageConfig.stepConfigurePackageConfigTitle": "选择要收集的数据",
- "xpack.ingestManager.editPackageConfig.stepDefinePackageConfigTitle": "定义您的数据源",
"xpack.ingestManager.editPackageConfig.updatedNotificationMessage": "Fleet 会将更新部署到所有使用配置“{agentConfigName}”的代理",
"xpack.ingestManager.editPackageConfig.updatedNotificationTitle": "已成功更新“{packageConfigName}”",
"xpack.ingestManager.enrollemntAPIKeyList.emptyMessage": "未找到任何注册令牌。",
@@ -15264,7 +15243,6 @@
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlLabel": "路径(必填)",
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlSchemeLabel": "方案",
"xpack.snapshotRestore.repositoryForm.typeReadonly.urlTitle": "URL",
- "xpack.snapshotRestore.repositoryForm.typeReadonly.urlWhitelistDescription": "必须在 {settingKey} 设置中注册此 URL。",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathDescription": "存储库数据的存储桶路径。",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathLabel": "基路径",
"xpack.snapshotRestore.repositoryForm.typeS3.basePathTitle": "基路径",
diff --git a/x-pack/test/api_integration/apis/endpoint/artifacts/index.ts b/x-pack/test/api_integration/apis/endpoint/artifacts/index.ts
index ca59d396839ae..ba68b9b7ba6ee 100644
--- a/x-pack/test/api_integration/apis/endpoint/artifacts/index.ts
+++ b/x-pack/test/api_integration/apis/endpoint/artifacts/index.ts
@@ -5,6 +5,7 @@
*/
import expect from '@kbn/expect';
+import { createHash } from 'crypto';
import { inflateSync } from 'zlib';
import { FtrProviderContext } from '../../../ftr_provider_context';
@@ -69,7 +70,18 @@ export default function (providerContext: FtrProviderContext) {
.expect(404);
});
- it('should download an artifact with correct hash', async () => {
+ it('should fail on invalid api key with 401', async () => {
+ await supertestWithoutAuth
+ .get(
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/1825fb19fcc6dc391cae0bc4a2e96dd7f728a0c3ae9e1469251ada67f9e1b975'
+ )
+ .set('kbn-xsrf', 'xxx')
+ .set('authorization', `ApiKey iNvAlId`)
+ .send()
+ .expect(401);
+ });
+
+ it('should download an artifact with list items', async () => {
await supertestWithoutAuth
.get(
'/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
@@ -79,7 +91,18 @@ export default function (providerContext: FtrProviderContext) {
.send()
.expect(200)
.expect((response) => {
- const artifactJson = JSON.parse(inflateSync(response.body).toString());
+ expect(response.body.byteLength).to.equal(160);
+ const encodedHash = createHash('sha256').update(response.body).digest('hex');
+ expect(encodedHash).to.equal(
+ '5caaeabcb7864d47157fc7c28d5a7398b4f6bbaaa565d789c02ee809253b7613'
+ );
+ const decodedBody = inflateSync(response.body);
+ const decodedHash = createHash('sha256').update(decodedBody).digest('hex');
+ expect(decodedHash).to.equal(
+ 'd2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ );
+ expect(decodedBody.byteLength).to.equal(358);
+ const artifactJson = JSON.parse(decodedBody.toString());
expect(artifactJson).to.eql({
entries: [
{
@@ -116,10 +139,10 @@ export default function (providerContext: FtrProviderContext) {
});
});
- it('should download an artifact with correct hash from cache', async () => {
+ it('should download an artifact with unicode characters', async () => {
await supertestWithoutAuth
.get(
- '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-windows-v1/8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e'
)
.set('kbn-xsrf', 'xxx')
.set('authorization', `ApiKey ${agentAccessAPIKey}`)
@@ -131,14 +154,25 @@ export default function (providerContext: FtrProviderContext) {
.then(async () => {
await supertestWithoutAuth
.get(
- '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-windows-v1/8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e'
)
.set('kbn-xsrf', 'xxx')
.set('authorization', `ApiKey ${agentAccessAPIKey}`)
.send()
.expect(200)
.expect((response) => {
- const artifactJson = JSON.parse(inflateSync(response.body).toString());
+ const encodedHash = createHash('sha256').update(response.body).digest('hex');
+ expect(encodedHash).to.equal(
+ '73015ee5131dabd1b48aa4776d3e766d836f8dd8c9fa8999c9b931f60027f07f'
+ );
+ expect(response.body.byteLength).to.equal(191);
+ const decodedBody = inflateSync(response.body);
+ const decodedHash = createHash('sha256').update(decodedBody).digest('hex');
+ expect(decodedHash).to.equal(
+ '8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e'
+ );
+ expect(decodedBody.byteLength).to.equal(704);
+ const artifactJson = JSON.parse(decodedBody.toString());
expect(artifactJson).to.eql({
entries: [
{
@@ -150,6 +184,35 @@ export default function (providerContext: FtrProviderContext) {
type: 'exact_cased',
value: 'Elastic, N.V.',
},
+ {
+ entries: [
+ {
+ field: 'signer',
+ operator: 'included',
+ type: 'exact_cased',
+ value: '😈',
+ },
+ {
+ field: 'trusted',
+ operator: 'included',
+ type: 'exact_cased',
+ value: 'true',
+ },
+ ],
+ field: 'file.signature',
+ type: 'nested',
+ },
+ ],
+ },
+ {
+ type: 'simple',
+ entries: [
+ {
+ field: 'actingProcess.file.signer',
+ operator: 'included',
+ type: 'exact_cased',
+ value: 'Another signer',
+ },
{
entries: [
{
@@ -176,15 +239,112 @@ export default function (providerContext: FtrProviderContext) {
});
});
- it('should fail on invalid api key', async () => {
+ it('should download an artifact with empty exception list', async () => {
await supertestWithoutAuth
.get(
- '/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/1825fb19fcc6dc391cae0bc4a2e96dd7f728a0c3ae9e1469251ada67f9e1b975'
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658'
)
.set('kbn-xsrf', 'xxx')
- .set('authorization', `ApiKey iNvAlId`)
+ .set('authorization', `ApiKey ${agentAccessAPIKey}`)
.send()
- .expect(401);
+ .expect(200)
+ .expect((response) => {
+ JSON.parse(inflateSync(response.body).toString());
+ })
+ .then(async () => {
+ await supertestWithoutAuth
+ .get(
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-macos-v1/d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658'
+ )
+ .set('kbn-xsrf', 'xxx')
+ .set('authorization', `ApiKey ${agentAccessAPIKey}`)
+ .send()
+ .expect(200)
+ .expect((response) => {
+ const encodedHash = createHash('sha256').update(response.body).digest('hex');
+ expect(encodedHash).to.equal(
+ 'f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda'
+ );
+ expect(response.body.byteLength).to.equal(22);
+ const decodedBody = inflateSync(response.body);
+ const decodedHash = createHash('sha256').update(decodedBody).digest('hex');
+ expect(decodedHash).to.equal(
+ 'd801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658'
+ );
+ expect(decodedBody.byteLength).to.equal(14);
+ const artifactJson = JSON.parse(decodedBody.toString());
+ expect(artifactJson.entries.length).to.equal(0);
+ });
+ });
+ });
+
+ it('should download an artifact from cache', async () => {
+ await supertestWithoutAuth
+ .get(
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ )
+ .set('kbn-xsrf', 'xxx')
+ .set('authorization', `ApiKey ${agentAccessAPIKey}`)
+ .send()
+ .expect(200)
+ .expect((response) => {
+ JSON.parse(inflateSync(response.body).toString());
+ })
+ .then(async () => {
+ await supertestWithoutAuth
+ .get(
+ '/api/endpoint/artifacts/download/endpoint-exceptionlist-linux-v1/d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ )
+ .set('kbn-xsrf', 'xxx')
+ .set('authorization', `ApiKey ${agentAccessAPIKey}`)
+ .send()
+ .expect(200)
+ .expect((response) => {
+ const encodedHash = createHash('sha256').update(response.body).digest('hex');
+ expect(encodedHash).to.equal(
+ '5caaeabcb7864d47157fc7c28d5a7398b4f6bbaaa565d789c02ee809253b7613'
+ );
+ const decodedBody = inflateSync(response.body);
+ const decodedHash = createHash('sha256').update(decodedBody).digest('hex');
+ expect(decodedHash).to.equal(
+ 'd2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f'
+ );
+ const artifactJson = JSON.parse(decodedBody.toString());
+ expect(artifactJson).to.eql({
+ entries: [
+ {
+ type: 'simple',
+ entries: [
+ {
+ field: 'actingProcess.file.signer',
+ operator: 'included',
+ type: 'exact_cased',
+ value: 'Elastic, N.V.',
+ },
+ {
+ entries: [
+ {
+ field: 'signer',
+ operator: 'included',
+ type: 'exact_cased',
+ value: 'Evil',
+ },
+ {
+ field: 'trusted',
+ operator: 'included',
+ type: 'exact_cased',
+ value: 'true',
+ },
+ ],
+ field: 'file.signature',
+ type: 'nested',
+ },
+ ],
+ },
+ ],
+ });
+ });
+ });
});
});
}
diff --git a/x-pack/test/api_integration/apis/endpoint/resolver.ts b/x-pack/test/api_integration/apis/endpoint/resolver.ts
index ace32111005f4..c8217f2b6872a 100644
--- a/x-pack/test/api_integration/apis/endpoint/resolver.ts
+++ b/x-pack/test/api_integration/apis/endpoint/resolver.ts
@@ -366,7 +366,7 @@ export default function resolverAPIIntegrationTests({ getService }: FtrProviderC
it('should error on invalid pagination values', async () => {
await supertest.get(`/api/endpoint/resolver/${entityID}/events?events=0`).expect(400);
- await supertest.get(`/api/endpoint/resolver/${entityID}/events?events=2000`).expect(400);
+ await supertest.get(`/api/endpoint/resolver/${entityID}/events?events=20000`).expect(400);
await supertest.get(`/api/endpoint/resolver/${entityID}/events?events=-1`).expect(400);
});
});
@@ -444,14 +444,18 @@ export default function resolverAPIIntegrationTests({ getService }: FtrProviderC
it('should have a populated next parameter', async () => {
const { body }: { body: ResolverAncestry } = await supertest
- .get(`/api/endpoint/resolver/${entityID}/ancestry?legacyEndpointID=${endpointID}`)
+ .get(
+ `/api/endpoint/resolver/${entityID}/ancestry?legacyEndpointID=${endpointID}&ancestors=0`
+ )
.expect(200);
expect(body.nextAncestor).to.eql('94041');
});
it('should handle an ancestors param request', async () => {
let { body }: { body: ResolverAncestry } = await supertest
- .get(`/api/endpoint/resolver/${entityID}/ancestry?legacyEndpointID=${endpointID}`)
+ .get(
+ `/api/endpoint/resolver/${entityID}/ancestry?legacyEndpointID=${endpointID}&ancestors=0`
+ )
.expect(200);
const next = body.nextAncestor;
@@ -579,7 +583,7 @@ export default function resolverAPIIntegrationTests({ getService }: FtrProviderC
it('errors on invalid pagination values', async () => {
await supertest.get(`/api/endpoint/resolver/${entityID}/children?children=0`).expect(400);
await supertest
- .get(`/api/endpoint/resolver/${entityID}/children?children=2000`)
+ .get(`/api/endpoint/resolver/${entityID}/children?children=20000`)
.expect(400);
await supertest
.get(`/api/endpoint/resolver/${entityID}/children?children=-1`)
diff --git a/x-pack/test/api_integration/apis/management/index_management/component_templates.ts b/x-pack/test/api_integration/apis/management/index_management/component_templates.ts
index 1a00eaba35aa1..30ec95f208c80 100644
--- a/x-pack/test/api_integration/apis/management/index_management/component_templates.ts
+++ b/x-pack/test/api_integration/apis/management/index_management/component_templates.ts
@@ -78,6 +78,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(testComponentTemplate).to.eql({
name: COMPONENT_NAME,
usedBy: [],
+ isManaged: false,
hasSettings: true,
hasMappings: true,
hasAliases: false,
@@ -96,6 +97,7 @@ export default function ({ getService }: FtrProviderContext) {
...COMPONENT,
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
});
});
@@ -148,6 +150,7 @@ export default function ({ getService }: FtrProviderContext) {
},
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
})
.expect(200);
@@ -167,6 +170,7 @@ export default function ({ getService }: FtrProviderContext) {
template: {},
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
})
.expect(200);
@@ -185,6 +189,7 @@ export default function ({ getService }: FtrProviderContext) {
template: {},
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
})
.expect(409);
@@ -246,6 +251,7 @@ export default function ({ getService }: FtrProviderContext) {
version: 1,
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
})
.expect(200);
@@ -267,6 +273,7 @@ export default function ({ getService }: FtrProviderContext) {
version: 1,
_kbnMeta: {
usedBy: [],
+ isManaged: false,
},
})
.expect(404);
diff --git a/x-pack/test/api_integration/apis/ml/modules/get_module.ts b/x-pack/test/api_integration/apis/ml/modules/get_module.ts
index 5ca496a7a7fe9..cfb3c17ac7f21 100644
--- a/x-pack/test/api_integration/apis/ml/modules/get_module.ts
+++ b/x-pack/test/api_integration/apis/ml/modules/get_module.ts
@@ -25,6 +25,7 @@ const moduleIds = [
'sample_data_weblogs',
'siem_auditbeat',
'siem_auditbeat_auth',
+ 'siem_cloudtrail',
'siem_packetbeat',
'siem_winlogbeat',
'siem_winlogbeat_auth',
diff --git a/x-pack/test/functional/apps/maps/mapbox_styles.js b/x-pack/test/functional/apps/maps/mapbox_styles.js
index 63bfc331d8886..744eb4ac74bf6 100644
--- a/x-pack/test/functional/apps/maps/mapbox_styles.js
+++ b/x-pack/test/functional/apps/maps/mapbox_styles.js
@@ -52,21 +52,21 @@ export const MAPBOX_STYLES = {
2,
'rgba(0,0,0,0)',
3,
- '#f7faff',
+ '#ecf1f7',
4.125,
- '#ddeaf7',
+ '#d9e3ef',
5.25,
- '#c5daee',
+ '#c5d5e7',
6.375,
- '#9dc9e0',
+ '#b2c7df',
7.5,
- '#6aadd5',
+ '#9eb9d8',
8.625,
- '#4191c5',
+ '#8bacd0',
9.75,
- '#2070b4',
+ '#769fc8',
10.875,
- '#072f6b',
+ '#6092c0',
],
'circle-opacity': 0.75,
'circle-stroke-color': '#41937c',
@@ -122,21 +122,21 @@ export const MAPBOX_STYLES = {
2,
'rgba(0,0,0,0)',
3,
- '#f7faff',
+ '#ecf1f7',
4.125,
- '#ddeaf7',
+ '#d9e3ef',
5.25,
- '#c5daee',
+ '#c5d5e7',
6.375,
- '#9dc9e0',
+ '#b2c7df',
7.5,
- '#6aadd5',
+ '#9eb9d8',
8.625,
- '#4191c5',
+ '#8bacd0',
9.75,
- '#2070b4',
+ '#769fc8',
10.875,
- '#072f6b',
+ '#6092c0',
],
'fill-opacity': 0.75,
},
diff --git a/x-pack/test/functional/es_archives/endpoint/artifacts/api_feature/data.json b/x-pack/test/functional/es_archives/endpoint/artifacts/api_feature/data.json
index bd1010240f86c..47390f0428742 100644
--- a/x-pack/test/functional/es_archives/endpoint/artifacts/api_feature/data.json
+++ b/x-pack/test/functional/es_archives/endpoint/artifacts/api_feature/data.json
@@ -1,12 +1,12 @@
{
"type": "doc",
"value": {
- "id": "endpoint:user-artifact:v2:endpoint-exceptionlist-linux-v1-d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f",
+ "id": "endpoint:user-artifact:endpoint-exceptionlist-linux-v1-d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f",
"index": ".kibana",
"source": {
"references": [
],
- "endpoint:user-artifact:v2": {
+ "endpoint:user-artifact": {
"body": "eJylkM8KwjAMxl9Fci59gN29iicvMqR02QjUbiSpKGPvbiw6ETwpuX1/fh9kBszKhALNcQa9TQgNCJ2nhOA+vJ4wdWaGqJSHPY8RRXxPCb3QkJEtP07IQUe2GOWYSoedqU8qXq16ikGqeAmpPNRtCqIU3WbnDx4WN38d/WvhQqmCXzDlIlojP9CsjLC0bqWtHwhaGN/1jHVkae3u+6N6Sg==",
"created": 1593016187465,
"compressionAlgorithm": "zlib",
@@ -17,7 +17,7 @@
"decodedSha256": "d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f",
"decodedSize": 358
},
- "type": "endpoint:user-artifact:v2",
+ "type": "endpoint:user-artifact",
"updated_at": "2020-06-24T16:29:47.584Z"
}
}
@@ -26,20 +26,70 @@
{
"type": "doc",
"value": {
- "id": "endpoint:user-artifact-manifest:v2:endpoint-manifest-v1",
+ "id": "endpoint:user-artifact:endpoint-exceptionlist-macos-v1-d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658",
"index": ".kibana",
"source": {
"references": [
],
- "endpoint:user-artifact-manifest:v2": {
+ "endpoint:user-artifact": {
+ "body": "eJyrVkrNKynKTC1WsoqOrQUAJxkFKQ==",
+ "created": 1594402653532,
+ "compressionAlgorithm": "zlib",
+ "encryptionAlgorithm": "none",
+ "identifier": "endpoint-exceptionlist-macos-v1",
+ "encodedSha256": "f8e6afa1d5662f5b37f83337af774b5785b5b7f1daee08b7b00c2d6813874cda",
+ "encodedSize": 14,
+ "decodedSha256": "d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658",
+ "decodedSize": 22
+ },
+ "type": "endpoint:user-artifact",
+ "updated_at": "2020-07-10T17:38:47.584Z"
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "id": "endpoint:user-artifact:endpoint-exceptionlist-windows-v1-8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e",
+ "index": ".kibana",
+ "source": {
+ "references": [
+ ],
+ "endpoint:user-artifact": {
+ "body": "eJzFkL0KwjAUhV+lZA55gG4OXcXJRYqE9LZeiElJbotSsvsIbr6ij2AaakVwUqTr+fkOnIGBIYfgWb4bGJ1bYDnzeGw1MP7m1Qi6iqZUhKbZOKvAe1GjBuGxMeBi3rbgJFkXY2iU7iqoojpR4RSreyV9Enupu1EttPSEimdrsRUs8OHj6C8L99v1ksBPGLnOU4p8QYtlYKHkM21+QFLn4FU3kEZCOU4vcOzKWDqAyybGP54tetSLPluGB+Nu8h4=",
+ "created": 1594402653532,
+ "compressionAlgorithm": "zlib",
+ "encryptionAlgorithm": "none",
+ "identifier": "endpoint-exceptionlist-windows-v1",
+ "encodedSha256": "73015ee5131dabd1b48aa4776d3e766d836f8dd8c9fa8999c9b931f60027f07f",
+ "encodedSize": 191,
+ "decodedSha256": "8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e",
+ "decodedSize": 704
+ },
+ "type": "endpoint:user-artifact",
+ "updated_at": "2020-07-10T17:38:47.584Z"
+ }
+ }
+}
+
+{
+ "type": "doc",
+ "value": {
+ "id": "endpoint:user-artifact-manifest:endpoint-manifest-v1",
+ "index": ".kibana",
+ "source": {
+ "references": [
+ ],
+ "endpoint:user-artifact-manifest": {
"created": 1593183699663,
"ids": [
"endpoint-exceptionlist-linux-v1-d2a9c760005b08d43394e59a8701ae75c80881934ccf15a006944452b80f7f9f",
"endpoint-exceptionlist-macos-v1-d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658",
- "endpoint-exceptionlist-windows-v1-d801aa1fb7ddcc330a5e3173372ea6af4a3d08ec58074478e85aa5603e926658"
+ "endpoint-exceptionlist-windows-v1-8d2bcc37e82fad5d06e2c9e4bd96793ea8905ace1d528a57d0d0579ecc8c647e"
]
},
- "type": "endpoint:user-artifact-manifest:v2",
+ "type": "endpoint:user-artifact-manifest",
"updated_at": "2020-06-26T15:01:39.704Z"
}
}
diff --git a/x-pack/test/functional_embedded/tests/iframe_embedded.ts b/x-pack/test/functional_embedded/tests/iframe_embedded.ts
index 9b5c9894a9407..f05d70b6cb3e8 100644
--- a/x-pack/test/functional_embedded/tests/iframe_embedded.ts
+++ b/x-pack/test/functional_embedded/tests/iframe_embedded.ts
@@ -14,7 +14,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const config = getService('config');
const testSubjects = getService('testSubjects');
- describe('in iframe', () => {
+ // Flaky: https://github.com/elastic/kibana/issues/70928
+ describe.skip('in iframe', () => {
it('should open Kibana for logged-in user', async () => {
const isChromeHiddenBefore = await PageObjects.common.isChromeHidden();
expect(isChromeHiddenBefore).to.be(true);
diff --git a/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/app_search/setup_guide.ts b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/app_search/setup_guide.ts
index 1d478c6baf29c..76a47cc4a7e10 100644
--- a/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/app_search/setup_guide.ts
+++ b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/app_search/setup_guide.ts
@@ -24,7 +24,7 @@ export default function enterpriseSearchSetupGuideTests({
});
describe('when no enterpriseSearch.host is configured', () => {
- it('navigating to the enterprise_search plugin will redirect a user to the setup guide', async () => {
+ it('navigating to the plugin will redirect a user to the setup guide', async () => {
await PageObjects.appSearch.navigateToPage();
await retry.try(async function () {
const currentUrl = await browser.getCurrentUrl();
diff --git a/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/index.ts b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/index.ts
index 31a92e752fcf4..ebfdca780c127 100644
--- a/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/index.ts
+++ b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/index.ts
@@ -11,5 +11,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
this.tags('ciGroup10');
loadTestFile(require.resolve('./app_search/setup_guide'));
+ loadTestFile(require.resolve('./workplace_search/setup_guide'));
});
}
diff --git a/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/workplace_search/setup_guide.ts b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/workplace_search/setup_guide.ts
new file mode 100644
index 0000000000000..20145306b21c8
--- /dev/null
+++ b/x-pack/test/functional_enterprise_search/apps/enterprise_search/without_host_configured/workplace_search/setup_guide.ts
@@ -0,0 +1,36 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import expect from '@kbn/expect';
+import { FtrProviderContext } from '../../../../ftr_provider_context';
+
+export default function enterpriseSearchSetupGuideTests({
+ getService,
+ getPageObjects,
+}: FtrProviderContext) {
+ const esArchiver = getService('esArchiver');
+ const browser = getService('browser');
+ const retry = getService('retry');
+
+ const PageObjects = getPageObjects(['workplaceSearch']);
+
+ describe('Setup Guide', function () {
+ before(async () => await esArchiver.load('empty_kibana'));
+ after(async () => {
+ await esArchiver.unload('empty_kibana');
+ });
+
+ describe('when no enterpriseSearch.host is configured', () => {
+ it('navigating to the plugin will redirect a user to the setup guide', async () => {
+ await PageObjects.workplaceSearch.navigateToPage();
+ await retry.try(async function () {
+ const currentUrl = await browser.getCurrentUrl();
+ expect(currentUrl).to.contain('/workplace_search/setup_guide');
+ });
+ });
+ });
+ });
+}
diff --git a/x-pack/test/functional_enterprise_search/page_objects/index.ts b/x-pack/test/functional_enterprise_search/page_objects/index.ts
index 009fb26482419..87de26b6feda0 100644
--- a/x-pack/test/functional_enterprise_search/page_objects/index.ts
+++ b/x-pack/test/functional_enterprise_search/page_objects/index.ts
@@ -6,8 +6,10 @@
import { pageObjects as basePageObjects } from '../../functional/page_objects';
import { AppSearchPageProvider } from './app_search';
+import { WorkplaceSearchPageProvider } from './workplace_search';
export const pageObjects = {
...basePageObjects,
appSearch: AppSearchPageProvider,
+ workplaceSearch: WorkplaceSearchPageProvider,
};
diff --git a/x-pack/test/functional_enterprise_search/page_objects/workplace_search.ts b/x-pack/test/functional_enterprise_search/page_objects/workplace_search.ts
new file mode 100644
index 0000000000000..f97ad2af58111
--- /dev/null
+++ b/x-pack/test/functional_enterprise_search/page_objects/workplace_search.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.
+ */
+
+import { FtrProviderContext } from '../ftr_provider_context';
+
+export function WorkplaceSearchPageProvider({ getPageObjects }: FtrProviderContext) {
+ const PageObjects = getPageObjects(['common']);
+
+ return {
+ async navigateToPage(): Promise {
+ return await PageObjects.common.navigateToApp('enterprise_search/workplace_search');
+ },
+ };
+}
diff --git a/x-pack/test/ingest_manager_api_integration/apis/index.js b/x-pack/test/ingest_manager_api_integration/apis/index.js
index 30c49140c6e2a..81848917f9b05 100644
--- a/x-pack/test/ingest_manager_api_integration/apis/index.js
+++ b/x-pack/test/ingest_manager_api_integration/apis/index.js
@@ -17,5 +17,6 @@ export default function ({ loadTestFile }) {
// Package configs
loadTestFile(require.resolve('./package_config/create'));
+ loadTestFile(require.resolve('./package_config/update'));
});
}
diff --git a/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts b/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts
index c7748ab255f43..cae4ff79bdef6 100644
--- a/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts
+++ b/x-pack/test/ingest_manager_api_integration/apis/package_config/create.ts
@@ -126,5 +126,48 @@ export default function ({ getService }: FtrProviderContext) {
warnAndSkipTest(this, log);
}
});
+
+ it('should return a 500 if there is another package config with the same name', async function () {
+ if (server.enabled) {
+ await supertest
+ .post(`/api/ingest_manager/package_configs`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'same-name-test-1',
+ description: '',
+ namespace: 'default',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ })
+ .expect(200);
+ await supertest
+ .post(`/api/ingest_manager/package_configs`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'same-name-test-1',
+ description: '',
+ namespace: 'default',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ })
+ .expect(500);
+ } else {
+ warnAndSkipTest(this, log);
+ }
+ });
});
}
diff --git a/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts b/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts
new file mode 100644
index 0000000000000..0251fef5f767c
--- /dev/null
+++ b/x-pack/test/ingest_manager_api_integration/apis/package_config/update.ts
@@ -0,0 +1,127 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License;
+ * you may not use this file except in compliance with the Elastic License.
+ */
+
+import expect from '@kbn/expect';
+import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
+import { warnAndSkipTest } from '../../helpers';
+
+export default function ({ getService }: FtrProviderContext) {
+ const log = getService('log');
+ const supertest = getService('supertest');
+ const dockerServers = getService('dockerServers');
+
+ const server = dockerServers.get('registry');
+ // use function () {} and not () => {} here
+ // because `this` has to point to the Mocha context
+ // see https://mochajs.org/#arrow-functions
+
+ describe('Package Config - update', async function () {
+ let agentConfigId: string;
+ let packageConfigId: string;
+ let packageConfigId2: string;
+
+ before(async function () {
+ const { body: agentConfigResponse } = await supertest
+ .post(`/api/ingest_manager/agent_configs`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'Test config',
+ namespace: 'default',
+ });
+ agentConfigId = agentConfigResponse.item.id;
+
+ const { body: packageConfigResponse } = await supertest
+ .post(`/api/ingest_manager/package_configs`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'filetest-1',
+ description: '',
+ namespace: 'default',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ });
+ packageConfigId = packageConfigResponse.item.id;
+
+ const { body: packageConfigResponse2 } = await supertest
+ .post(`/api/ingest_manager/package_configs`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'filetest-2',
+ description: '',
+ namespace: 'default',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ });
+ packageConfigId2 = packageConfigResponse2.item.id;
+ });
+
+ it('should work with valid values', async function () {
+ if (server.enabled) {
+ const { body: apiResponse } = await supertest
+ .put(`/api/ingest_manager/package_configs/${packageConfigId}`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'filetest-1',
+ description: '',
+ namespace: 'updated_namespace',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ })
+ .expect(200);
+
+ expect(apiResponse.success).to.be(true);
+ } else {
+ warnAndSkipTest(this, log);
+ }
+ });
+
+ it('should return a 500 if there is another package config with the same name', async function () {
+ if (server.enabled) {
+ await supertest
+ .put(`/api/ingest_manager/package_configs/${packageConfigId2}`)
+ .set('kbn-xsrf', 'xxxx')
+ .send({
+ name: 'filetest-1',
+ description: '',
+ namespace: 'updated_namespace',
+ config_id: agentConfigId,
+ enabled: true,
+ output_id: '',
+ inputs: [],
+ package: {
+ name: 'filetest',
+ title: 'For File Tests',
+ version: '0.1.0',
+ },
+ })
+ .expect(500);
+ } else {
+ warnAndSkipTest(this, log);
+ }
+ });
+ });
+}
diff --git a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts
index 7207bb3fc37b3..9a0a819f68b62 100644
--- a/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts
+++ b/x-pack/test/security_solution_endpoint/apps/endpoint/policy_details.ts
@@ -195,7 +195,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
},
},
revision: 3,
- settings: {
+ agent: {
monitoring: {
enabled: false,
logs: false,
diff --git a/x-pack/test/ui_capabilities/security_and_spaces/tests/catalogue.ts b/x-pack/test/ui_capabilities/security_and_spaces/tests/catalogue.ts
index 0e0d46c6ce2cd..0d5c553a786fa 100644
--- a/x-pack/test/ui_capabilities/security_and_spaces/tests/catalogue.ts
+++ b/x-pack/test/ui_capabilities/security_and_spaces/tests/catalogue.ts
@@ -50,9 +50,10 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('catalogue');
// everything except ml and monitoring and enterprise search is enabled
+ const exceptions = ['ml', 'monitoring', 'appSearch', 'workplaceSearch'];
const expected = mapValues(
uiCapabilities.value!.catalogue,
- (enabled, catalogueId) => !['ml', 'monitoring', 'appSearch'].includes(catalogueId)
+ (enabled, catalogueId) => !exceptions.includes(catalogueId)
);
expect(uiCapabilities.value!.catalogue).to.eql(expected);
break;
diff --git a/x-pack/test/ui_capabilities/security_and_spaces/tests/nav_links.ts b/x-pack/test/ui_capabilities/security_and_spaces/tests/nav_links.ts
index 08a7d789153e7..0133a2fafb129 100644
--- a/x-pack/test/ui_capabilities/security_and_spaces/tests/nav_links.ts
+++ b/x-pack/test/ui_capabilities/security_and_spaces/tests/nav_links.ts
@@ -51,7 +51,13 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('navLinks');
expect(uiCapabilities.value!.navLinks).to.eql(
- navLinksBuilder.except('ml', 'monitoring', 'enterpriseSearch', 'appSearch')
+ navLinksBuilder.except(
+ 'ml',
+ 'monitoring',
+ 'enterpriseSearch',
+ 'appSearch',
+ 'workplaceSearch'
+ )
);
break;
case 'superuser at nothing_space':
diff --git a/x-pack/test/ui_capabilities/security_only/tests/catalogue.ts b/x-pack/test/ui_capabilities/security_only/tests/catalogue.ts
index 99f91407dc1d2..9ed1c890bf57f 100644
--- a/x-pack/test/ui_capabilities/security_only/tests/catalogue.ts
+++ b/x-pack/test/ui_capabilities/security_only/tests/catalogue.ts
@@ -48,9 +48,10 @@ export default function catalogueTests({ getService }: FtrProviderContext) {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('catalogue');
// everything except ml and monitoring and enterprise search is enabled
+ const exceptions = ['ml', 'monitoring', 'appSearch', 'workplaceSearch'];
const expected = mapValues(
uiCapabilities.value!.catalogue,
- (enabled, catalogueId) => !['ml', 'monitoring', 'appSearch'].includes(catalogueId)
+ (enabled, catalogueId) => !exceptions.includes(catalogueId)
);
expect(uiCapabilities.value!.catalogue).to.eql(expected);
break;
diff --git a/x-pack/test/ui_capabilities/security_only/tests/nav_links.ts b/x-pack/test/ui_capabilities/security_only/tests/nav_links.ts
index d3bd2e1afd357..18838e536cf96 100644
--- a/x-pack/test/ui_capabilities/security_only/tests/nav_links.ts
+++ b/x-pack/test/ui_capabilities/security_only/tests/nav_links.ts
@@ -49,7 +49,7 @@ export default function navLinksTests({ getService }: FtrProviderContext) {
expect(uiCapabilities.success).to.be(true);
expect(uiCapabilities.value).to.have.property('navLinks');
expect(uiCapabilities.value!.navLinks).to.eql(
- navLinksBuilder.except('ml', 'monitoring', 'appSearch')
+ navLinksBuilder.except('ml', 'monitoring', 'appSearch', 'workplaceSearch')
);
break;
case 'foo_all':
diff --git a/yarn.lock b/yarn.lock
index 290713d32d333..bd6c2031d0ec8 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -20916,16 +20916,21 @@ lodash.uniq@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
-lodash@4.17.11, lodash@4.17.15, lodash@>4.17.4, lodash@^4, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.10.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.15.19, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.16, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.10, lodash@~4.17.15, lodash@~4.17.5:
- version "4.17.19"
- resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
- integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
+lodash@4.17.11, lodash@4.17.15, lodash@>4.17.4, lodash@^4, lodash@^4.0.0, lodash@^4.0.1, lodash@^4.10.0, lodash@^4.11.1, lodash@^4.14.0, lodash@^4.15.0, lodash@^4.17.0, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.2, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.6.1, lodash@~4.17.10, lodash@~4.17.15, lodash@~4.17.5:
+ version "4.17.15"
+ resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
+ integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
lodash@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y=
+lodash@^4.17.16:
+ version "4.17.19"
+ resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
+ integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==
+
"lodash@npm:@elastic/lodash@3.10.1-kibana4":
version "3.10.1-kibana4"
resolved "https://registry.yarnpkg.com/@elastic/lodash/-/lodash-3.10.1-kibana4.tgz#d491228fd659b4a1b0dfa08ba9c67a4979b9746d"