Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/elastic/kibana into alert…
Browse files Browse the repository at this point in the history
…ing/telemetry-for-predefined-rule-ids
  • Loading branch information
ymao1 committed Aug 16, 2021
2 parents 38c2c4b + 024eeed commit 507e4ef
Show file tree
Hide file tree
Showing 117 changed files with 1,787 additions and 475 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [DeprecationsClient](./kibana-plugin-core-server.deprecationsclient.md) &gt; [getAllDeprecations](./kibana-plugin-core-server.deprecationsclient.getalldeprecations.md)

## DeprecationsClient.getAllDeprecations property

<b>Signature:</b>

```typescript
getAllDeprecations: () => Promise<DomainDeprecationDetails[]>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [DeprecationsClient](./kibana-plugin-core-server.deprecationsclient.md)

## DeprecationsClient interface

Server-side client that provides access to fetch all Kibana deprecations

<b>Signature:</b>

```typescript
export interface DeprecationsClient
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [getAllDeprecations](./kibana-plugin-core-server.deprecationsclient.getalldeprecations.md) | <code>() =&gt; Promise&lt;DomainDeprecationDetails[]&gt;</code> | |

1 change: 1 addition & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [DeprecationAPIClientParams](./kibana-plugin-core-server.deprecationapiclientparams.md) | |
| [DeprecationAPIResponse](./kibana-plugin-core-server.deprecationapiresponse.md) | |
| [DeprecationInfo](./kibana-plugin-core-server.deprecationinfo.md) | |
| [DeprecationsClient](./kibana-plugin-core-server.deprecationsclient.md) | Server-side client that provides access to fetch all Kibana deprecations |
| [DeprecationsDetails](./kibana-plugin-core-server.deprecationsdetails.md) | |
| [DeprecationSettings](./kibana-plugin-core-server.deprecationsettings.md) | UiSettings deprecation field options. |
| [DeprecationsServiceSetup](./kibana-plugin-core-server.deprecationsservicesetup.md) | The deprecations service provides a way for the Kibana platform to communicate deprecated features and configs with its users. These deprecations are only communicated if the deployment is using these features. Allowing for a user tailored experience for upgrading the stack version.<!-- -->The Deprecation service is consumed by the upgrade assistant to assist with the upgrade experience.<!-- -->If a deprecated feature can be resolved without manual user intervention. Using correctiveActions.api allows the Upgrade Assistant to use this api to correct the deprecation upon a user trigger. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ core: {
uiSettings: {
client: IUiSettingsClient;
};
deprecations: {
client: DeprecationsClient;
};
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface RequestHandlerContext

| Property | Type | Description |
| --- | --- | --- |
| [core](./kibana-plugin-core-server.requesthandlercontext.core.md) | <code>{</code><br/><code> savedObjects: {</code><br/><code> client: SavedObjectsClientContract;</code><br/><code> typeRegistry: ISavedObjectTypeRegistry;</code><br/><code> getClient: (options?: SavedObjectsClientProviderOptions) =&gt; SavedObjectsClientContract;</code><br/><code> getExporter: (client: SavedObjectsClientContract) =&gt; ISavedObjectsExporter;</code><br/><code> getImporter: (client: SavedObjectsClientContract) =&gt; ISavedObjectsImporter;</code><br/><code> };</code><br/><code> elasticsearch: {</code><br/><code> client: IScopedClusterClient;</code><br/><code> legacy: {</code><br/><code> client: ILegacyScopedClusterClient;</code><br/><code> };</code><br/><code> };</code><br/><code> uiSettings: {</code><br/><code> client: IUiSettingsClient;</code><br/><code> };</code><br/><code> }</code> | |
| [core](./kibana-plugin-core-server.requesthandlercontext.core.md) | <code>{</code><br/><code> savedObjects: {</code><br/><code> client: SavedObjectsClientContract;</code><br/><code> typeRegistry: ISavedObjectTypeRegistry;</code><br/><code> getClient: (options?: SavedObjectsClientProviderOptions) =&gt; SavedObjectsClientContract;</code><br/><code> getExporter: (client: SavedObjectsClientContract) =&gt; ISavedObjectsExporter;</code><br/><code> getImporter: (client: SavedObjectsClientContract) =&gt; ISavedObjectsImporter;</code><br/><code> };</code><br/><code> elasticsearch: {</code><br/><code> client: IScopedClusterClient;</code><br/><code> legacy: {</code><br/><code> client: ILegacyScopedClusterClient;</code><br/><code> };</code><br/><code> };</code><br/><code> uiSettings: {</code><br/><code> client: IUiSettingsClient;</code><br/><code> };</code><br/><code> deprecations: {</code><br/><code> client: DeprecationsClient;</code><br/><code> };</code><br/><code> }</code> | |

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.14",
"@elastic/ems-client": "7.14.0",
"@elastic/eui": "36.1.0",
"@elastic/eui": "37.1.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "^9.0.1-kibana3",
"@elastic/maki": "6.3.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-docs-utils/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@kbn/babel-preset/node_preset"]
}
22 changes: 16 additions & 6 deletions packages/kbn-docs-utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config", "ts_project")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library", "pkg_npm")
load("//src/dev/bazel:index.bzl", "jsts_transpiler")

PKG_BASE_NAME = "kbn-docs-utils"
PKG_REQUIRE_NAME = "@kbn/docs-utils"
Expand All @@ -26,7 +27,7 @@ NPM_MODULE_EXTRA_FILES = [
"package.json",
]

SRC_DEPS = [
RUNTIME_DEPS = [
"//packages/kbn-config",
"//packages/kbn-dev-utils",
"//packages/kbn-utils",
Expand All @@ -35,12 +36,20 @@ SRC_DEPS = [
]

TYPES_DEPS = [
"//packages/kbn-config",
"//packages/kbn-dev-utils",
"//packages/kbn-utils",
"@npm//ts-morph",
"@npm//@types/dedent",
"@npm//@types/jest",
"@npm//@types/node",
]

DEPS = SRC_DEPS + TYPES_DEPS
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)

ts_config(
name = "tsconfig",
Expand All @@ -52,13 +61,14 @@ ts_config(
)

ts_project(
name = "tsc",
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = DEPS,
deps = TYPES_DEPS,
declaration = True,
declaration_map = True,
out_dir = "target",
emit_declaration_only = True,
out_dir = "target_types",
source_map = True,
root_dir = "src",
tsconfig = ":tsconfig",
Expand All @@ -67,7 +77,7 @@ ts_project(
js_library(
name = PKG_BASE_NAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = DEPS + [":tsc"],
deps = RUNTIME_DEPS + [":target_node", ":tsc_types"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-docs-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"private": "true",
"main": "target/index.js",
"types": "target/index.d.ts",
"main": "target_node/index.js",
"types": "target_types/index.d.ts",
"kibana": {
"devOnly": true
}
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-docs-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"outDir": "./target/types",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"sourceMap": true,
"sourceRoot": "../../../../packages/kbn-docs-utils/src",
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-rule-data-utils/src/alerts_as_data_rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const AlertConsumers = {
INFRASTRUCTURE: 'infrastructure',
OBSERVABILITY: 'observability',
SIEM: 'siem',
SYNTHETICS: 'synthetics',
UPTIME: 'uptime',
} as const;
export type AlertConsumers = typeof AlertConsumers[keyof typeof AlertConsumers];
export type STATUS_VALUES = 'open' | 'acknowledged' | 'closed' | 'in-progress'; // TODO: remove 'in-progress' after migration to 'acknowledged'
Expand All @@ -35,7 +35,7 @@ export const mapConsumerToIndexName: Record<AlertConsumers, string | string[]> =
infrastructure: '.alerts-observability.metrics',
observability: '.alerts-observability',
siem: ['.alerts-security.alerts', '.siem-signals'],
synthetics: '.alerts-observability-synthetics',
uptime: '.alerts-observability.uptime',
};
export type ValidFeatureId = keyof typeof mapConsumerToIndexName;

Expand Down
10 changes: 10 additions & 0 deletions scripts/saved_objs_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

require('../src/setup_node_env');
require('../test/common/services/saved_object_info').runSavedObjInfoSvc();
2 changes: 2 additions & 0 deletions src/core/public/i18n/__snapshots__/i18n_service.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/core/public/i18n/i18n_eui_mapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,16 @@ export const getEuiContextMapping = (): EuiTokensObject => {
description: 'Descending size label',
}
),
'euiDatePopoverButton.invalidTitle': ({ title }: EuiValues) =>
i18n.translate('core.euiDatePopoverButton.invalidTitle', {
defaultMessage: 'Invalid date: {title}',
values: { title },
}),
'euiDatePopoverButton.outdatedTitle': ({ title }: EuiValues) =>
i18n.translate('core.euiDatePopoverButton.outdatedTitle', {
defaultMessage: 'Update needed: {title}',
values: { title },
}),
'euiFieldPassword.showPassword': i18n.translate('core.euiFieldPassword.showPassword', {
defaultMessage:
'Show password as plain text. Note: this will visually expose your password on the screen.',
Expand Down
37 changes: 37 additions & 0 deletions src/core/server/core_route_handler_context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,40 @@ describe('#uiSettings', () => {
});
});
});

describe('#deprecations', () => {
describe('#client', () => {
test('returns the results of coreStart.deprecations.asScopedToClient', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const context = new CoreRouteHandlerContext(coreStart, request);

const client = context.deprecations.client;
expect(client).toBe(coreStart.deprecations.asScopedToClient.mock.results[0].value);
});

test('lazily created', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const context = new CoreRouteHandlerContext(coreStart, request);

expect(coreStart.deprecations.asScopedToClient).not.toHaveBeenCalled();
const client = context.deprecations.client;
expect(coreStart.deprecations.asScopedToClient).toHaveBeenCalled();
expect(client).toBeDefined();
});

test('only creates one instance', () => {
const request = httpServerMock.createKibanaRequest();
const coreStart = coreMock.createInternalStart();
const context = new CoreRouteHandlerContext(coreStart, request);

const client1 = context.deprecations.client;
const client2 = context.deprecations.client;
expect(coreStart.deprecations.asScopedToClient.mock.calls.length).toBe(1);
const mockResult = coreStart.deprecations.asScopedToClient.mock.results[0].value;
expect(client1).toBe(mockResult);
expect(client2).toBe(mockResult);
});
});
});
26 changes: 26 additions & 0 deletions src/core/server/core_route_handler_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
LegacyScopedClusterClient,
} from './elasticsearch';
import { InternalUiSettingsServiceStart, IUiSettingsClient } from './ui_settings';
import { DeprecationsClient, InternalDeprecationsServiceStart } from './deprecations';

class CoreElasticsearchRouteHandlerContext {
#client?: IScopedClusterClient;
Expand Down Expand Up @@ -103,10 +104,30 @@ class CoreUiSettingsRouteHandlerContext {
}
}

class CoreDeprecationsRouteHandlerContext {
#client?: DeprecationsClient;
constructor(
private readonly deprecationsStart: InternalDeprecationsServiceStart,
private readonly elasticsearchRouterHandlerContext: CoreElasticsearchRouteHandlerContext,
private readonly savedObjectsRouterHandlerContext: CoreSavedObjectsRouteHandlerContext
) {}

public get client() {
if (this.#client == null) {
this.#client = this.deprecationsStart.asScopedToClient(
this.elasticsearchRouterHandlerContext.client,
this.savedObjectsRouterHandlerContext.client
);
}
return this.#client;
}
}

export class CoreRouteHandlerContext {
readonly elasticsearch: CoreElasticsearchRouteHandlerContext;
readonly savedObjects: CoreSavedObjectsRouteHandlerContext;
readonly uiSettings: CoreUiSettingsRouteHandlerContext;
readonly deprecations: CoreDeprecationsRouteHandlerContext;

constructor(
private readonly coreStart: InternalCoreStart,
Expand All @@ -124,5 +145,10 @@ export class CoreRouteHandlerContext {
this.coreStart.uiSettings,
this.savedObjects
);
this.deprecations = new CoreDeprecationsRouteHandlerContext(
this.coreStart.deprecations,
this.elasticsearch,
this.savedObjects
);
}
}
22 changes: 22 additions & 0 deletions src/core/server/deprecations/deprecations_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
DeprecationsService,
InternalDeprecationsServiceSetup,
DeprecationsServiceSetup,
InternalDeprecationsServiceStart,
DeprecationsClient,
} from './deprecations_service';
type DeprecationsServiceContract = PublicMethodsOf<DeprecationsService>;

Expand All @@ -22,6 +24,16 @@ const createSetupContractMock = () => {
return setupContract;
};

const createStartContractMock = () => {
const mocked: jest.Mocked<InternalDeprecationsServiceStart> = {
asScopedToClient: jest.fn(),
};

mocked.asScopedToClient.mockReturnValue(createClientMock());

return mocked;
};

const createInternalSetupContractMock = () => {
const internalSetupContract: jest.Mocked<InternalDeprecationsServiceSetup> = {
getRegistry: jest.fn(),
Expand All @@ -42,8 +54,18 @@ const createDeprecationsServiceMock = () => {
return mocked;
};

const createClientMock = () => {
const mocked: jest.Mocked<DeprecationsClient> = {
getAllDeprecations: jest.fn(),
};
mocked.getAllDeprecations.mockResolvedValue([]);
return mocked;
};

export const deprecationsServiceMock = {
create: createDeprecationsServiceMock,
createInternalSetupContract: createInternalSetupContractMock,
createSetupContract: createSetupContractMock,
createInternalStartContract: createStartContractMock,
createClient: createClientMock,
};
28 changes: 23 additions & 5 deletions src/core/server/deprecations/deprecations_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
import { DeprecationsService } from './deprecations_service';
import { httpServiceMock } from '../http/http_service.mock';
import { mockRouter } from '../http/router/router.mock';
import { savedObjectsClientMock, elasticsearchServiceMock } from '../mocks';
import { mockCoreContext } from '../core_context.mock';
import { mockDeprecationsFactory } from './deprecations_factory.mock';
import { mockDeprecationsRegistry } from './deprecations_registry.mock';

describe('DeprecationsService', () => {
const coreContext = mockCoreContext.create();
const http = httpServiceMock.createInternalSetupContract();
const router = mockRouter.create();
http.createRouter.mockReturnValue(router);
const deprecationsCoreSetupDeps = { http };

beforeEach(() => jest.clearAllMocks());

describe('#setup', () => {
const http = httpServiceMock.createInternalSetupContract();
const router = mockRouter.create();
http.createRouter.mockReturnValue(router);
const deprecationsCoreSetupDeps = { http };

it('registers routes', () => {
const deprecationsService = new DeprecationsService(coreContext);
deprecationsService.setup(deprecationsCoreSetupDeps);
Expand All @@ -43,6 +44,23 @@ describe('DeprecationsService', () => {
});
});

describe('#start', () => {
describe('#asScopedToClient', () => {
it('returns client with #getAllDeprecations method', async () => {
const esClient = elasticsearchServiceMock.createScopedClusterClient();
const savedObjectsClient = savedObjectsClientMock.create();
const deprecationsService = new DeprecationsService(coreContext);

deprecationsService.setup(deprecationsCoreSetupDeps);

const start = deprecationsService.start();
const deprecationsClient = start.asScopedToClient(esClient, savedObjectsClient);

expect(deprecationsClient.getAllDeprecations).toBeDefined();
});
});
});

describe('#registerConfigDeprecationsInfo', () => {
const deprecationsFactory = mockDeprecationsFactory.create();
const deprecationsRegistry = mockDeprecationsRegistry.create();
Expand Down
Loading

0 comments on commit 507e4ef

Please sign in to comment.