Skip to content

Commit

Permalink
Add plugin API for customizing the logging configuration (elastic#68704
Browse files Browse the repository at this point in the history
…) (elastic#69749)

# Conflicts:
#	x-pack/plugins/security/server/authentication/authenticator.test.ts
  • Loading branch information
joshdover committed Jun 24, 2020
1 parent b20d0ef commit 7211305
Show file tree
Hide file tree
Showing 149 changed files with 1,963 additions and 692 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- 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; [AppenderConfigType](./kibana-plugin-core-server.appenderconfigtype.md)

## AppenderConfigType type


<b>Signature:</b>

```typescript
export declare type AppenderConfigType = TypeOf<typeof appendersSchema>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- 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; [CoreSetup](./kibana-plugin-core-server.coresetup.md) &gt; [logging](./kibana-plugin-core-server.coresetup.logging.md)

## CoreSetup.logging property

[LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md)

<b>Signature:</b>

```typescript
logging: LoggingServiceSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| [elasticsearch](./kibana-plugin-core-server.coresetup.elasticsearch.md) | <code>ElasticsearchServiceSetup</code> | [ElasticsearchServiceSetup](./kibana-plugin-core-server.elasticsearchservicesetup.md) |
| [getStartServices](./kibana-plugin-core-server.coresetup.getstartservices.md) | <code>StartServicesAccessor&lt;TPluginsStart, TStart&gt;</code> | [StartServicesAccessor](./kibana-plugin-core-server.startservicesaccessor.md) |
| [http](./kibana-plugin-core-server.coresetup.http.md) | <code>HttpServiceSetup &amp; {</code><br/><code> resources: HttpResources;</code><br/><code> }</code> | [HttpServiceSetup](./kibana-plugin-core-server.httpservicesetup.md) |
| [logging](./kibana-plugin-core-server.coresetup.logging.md) | <code>LoggingServiceSetup</code> | [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) |
| [metrics](./kibana-plugin-core-server.coresetup.metrics.md) | <code>MetricsServiceSetup</code> | [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) |
| [savedObjects](./kibana-plugin-core-server.coresetup.savedobjects.md) | <code>SavedObjectsServiceSetup</code> | [SavedObjectsServiceSetup](./kibana-plugin-core-server.savedobjectsservicesetup.md) |
| [status](./kibana-plugin-core-server.coresetup.status.md) | <code>StatusServiceSetup</code> | [StatusServiceSetup](./kibana-plugin-core-server.statusservicesetup.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- 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; [LoggerConfigType](./kibana-plugin-core-server.loggerconfigtype.md)

## LoggerConfigType type


<b>Signature:</b>

```typescript
export declare type LoggerConfigType = TypeOf<typeof loggerSchema>;
```
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; [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) &gt; [appenders](./kibana-plugin-core-server.loggercontextconfiginput.appenders.md)

## LoggerContextConfigInput.appenders property

<b>Signature:</b>

```typescript
appenders?: Record<string, AppenderConfigType> | Map<string, AppenderConfigType>;
```
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; [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) &gt; [loggers](./kibana-plugin-core-server.loggercontextconfiginput.loggers.md)

## LoggerContextConfigInput.loggers property

<b>Signature:</b>

```typescript
loggers?: LoggerConfigType[];
```
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; [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md)

## LoggerContextConfigInput interface


<b>Signature:</b>

```typescript
export interface LoggerContextConfigInput
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [appenders](./kibana-plugin-core-server.loggercontextconfiginput.appenders.md) | <code>Record&lt;string, AppenderConfigType&gt; &#124; Map&lt;string, AppenderConfigType&gt;</code> | |
| [loggers](./kibana-plugin-core-server.loggercontextconfiginput.loggers.md) | <code>LoggerConfigType[]</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!-- 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; [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) &gt; [configure](./kibana-plugin-core-server.loggingservicesetup.configure.md)

## LoggingServiceSetup.configure() method

Customizes the logging config for the plugin's context.

<b>Signature:</b>

```typescript
configure(config$: Observable<LoggerContextConfigInput>): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| config$ | <code>Observable&lt;LoggerContextConfigInput&gt;</code> | |

<b>Returns:</b>

`void`

## Remarks

Assumes that that the `context` property of the individual `logger` items emitted by `config$` are relative to the plugin's logging context (defaults to `plugins.<plugin_id>`<!-- -->).

## Example

Customize the configuration for the plugins.data.search context.

```ts
core.logging.configure(
of({
appenders: new Map(),
loggers: [{ context: 'search', appenders: ['default'] }]
})
)

```

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; [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md)

## LoggingServiceSetup interface

Provides APIs to plugins for customizing the plugin's logger.

<b>Signature:</b>

```typescript
export interface LoggingServiceSetup
```

## Methods

| Method | Description |
| --- | --- |
| [configure(config$)](./kibana-plugin-core-server.loggingservicesetup.configure.md) | Customizes the logging config for the plugin's context. |

4 changes: 4 additions & 0 deletions docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [LegacyServiceSetupDeps](./kibana-plugin-core-server.legacyservicesetupdeps.md) | |
| [LegacyServiceStartDeps](./kibana-plugin-core-server.legacyservicestartdeps.md) | |
| [Logger](./kibana-plugin-core-server.logger.md) | Logger exposes all the necessary methods to log any type of information and this is the interface used by the logging consumers including plugins. |
| [LoggerContextConfigInput](./kibana-plugin-core-server.loggercontextconfiginput.md) | |
| [LoggerFactory](./kibana-plugin-core-server.loggerfactory.md) | The single purpose of <code>LoggerFactory</code> interface is to define a way to retrieve a context-based logger instance. |
| [LoggingServiceSetup](./kibana-plugin-core-server.loggingservicesetup.md) | Provides APIs to plugins for customizing the plugin's logger. |
| [LogMeta](./kibana-plugin-core-server.logmeta.md) | Contextual metadata |
| [MetricsServiceSetup](./kibana-plugin-core-server.metricsservicesetup.md) | APIs to retrieves metrics gathered and exposed by the core platform. |
| [NodesVersionCompatibility](./kibana-plugin-core-server.nodesversioncompatibility.md) | |
Expand Down Expand Up @@ -209,6 +211,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->

| Type Alias | Description |
| --- | --- |
| [AppenderConfigType](./kibana-plugin-core-server.appenderconfigtype.md) | |
| [AuthenticationHandler](./kibana-plugin-core-server.authenticationhandler.md) | See [AuthToolkit](./kibana-plugin-core-server.authtoolkit.md)<!-- -->. |
| [AuthHeaders](./kibana-plugin-core-server.authheaders.md) | Auth Headers map |
| [AuthResult](./kibana-plugin-core-server.authresult.md) | |
Expand Down Expand Up @@ -242,6 +245,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [KibanaResponseFactory](./kibana-plugin-core-server.kibanaresponsefactory.md) | Creates an object containing request response payload, HTTP headers, error details, and other data transmitted to the client. |
| [KnownHeaders](./kibana-plugin-core-server.knownheaders.md) | Set of well-known HTTP headers. |
| [LifecycleResponseFactory](./kibana-plugin-core-server.lifecycleresponsefactory.md) | Creates an object containing redirection or error response with error details, HTTP headers, and other data transmitted to the client. |
| [LoggerConfigType](./kibana-plugin-core-server.loggerconfigtype.md) | |
| [MIGRATION\_ASSISTANCE\_INDEX\_ACTION](./kibana-plugin-core-server.migration_assistance_index_action.md) | |
| [MIGRATION\_DEPRECATION\_LEVEL](./kibana-plugin-core-server.migration_deprecation_level.md) | |
| [MutatingOperationRefreshSetting](./kibana-plugin-core-server.mutatingoperationrefreshsetting.md) | Elasticsearch Refresh setting for mutating operation |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import supertest from 'supertest';
import { HttpService, InternalHttpServiceSetup } from '../../http';
import { contextServiceMock } from '../../context/context_service.mock';
import { loggingServiceMock } from '../../logging/logging_service.mock';
import { loggingSystemMock } from '../../logging/logging_system.mock';
import { Env } from '../../config';
import { getEnvOptions } from '../../config/__mocks__/env';
import { CapabilitiesService, CapabilitiesSetup } from '..';
Expand All @@ -44,7 +44,7 @@ describe('CapabilitiesService', () => {
service = new CapabilitiesService({
coreId,
env,
logger: loggingServiceMock.create(),
logger: loggingSystemMock.create(),
configService: {} as any,
});
serviceSetup = await service.setup({ http: httpSetup });
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/config/config_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import { rawConfigServiceMock } from './raw_config_service.mock';
import { schema } from '@kbn/config-schema';

import { ConfigService, Env } from '.';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { loggingSystemMock } from '../logging/logging_system.mock';
import { getEnvOptions } from './__mocks__/env';

const emptyArgv = getEnvOptions();
const defaultEnv = new Env('/kibana', emptyArgv);
const logger = loggingServiceMock.create();
const logger = loggingSystemMock.create();

const getRawConfigProvider = (rawConfig: Record<string, any>) =>
rawConfigServiceMock.create({ rawConfig });
Expand Down Expand Up @@ -443,9 +443,9 @@ test('logs deprecation warning during validation', async () => {
return config;
});

loggingServiceMock.clear(logger);
loggingSystemMock.clear(logger);
await configService.validate();
expect(loggingServiceMock.collect(logger).warn).toMatchInlineSnapshot(`
expect(loggingSystemMock.collect(logger).warn).toMatchInlineSnapshot(`
Array [
Array [
"some deprecation message",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { loggingServiceMock } from '../../logging/logging_service.mock';
export const mockLoggingService = loggingServiceMock.create();
mockLoggingService.asLoggerFactory.mockImplementation(() => mockLoggingService);
jest.doMock('../../logging/logging_service', () => ({
LoggingService: jest.fn(() => mockLoggingService),
import { loggingSystemMock } from '../../logging/logging_system.mock';
export const mockLoggingSystem = loggingSystemMock.create();
mockLoggingSystem.asLoggerFactory.mockImplementation(() => mockLoggingSystem);
jest.doMock('../../logging/logging_system', () => ({
LoggingSystem: jest.fn(() => mockLoggingSystem),
}));
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { mockLoggingService } from './config_deprecation.test.mocks';
import { loggingServiceMock } from '../../logging/logging_service.mock';
import { mockLoggingSystem } from './config_deprecation.test.mocks';
import { loggingSystemMock } from '../../logging/logging_system.mock';
import * as kbnTestServer from '../../../../test_utils/kbn_server';

describe('configuration deprecations', () => {
Expand All @@ -35,7 +35,7 @@ describe('configuration deprecations', () => {

await root.setup();

const logs = loggingServiceMock.collect(mockLoggingService);
const logs = loggingSystemMock.collect(mockLoggingSystem);
const warnings = logs.warn.flatMap((i) => i);
expect(warnings).not.toContain(
'"optimize.lazy" is deprecated and has been replaced by "optimize.watch"'
Expand All @@ -55,7 +55,7 @@ describe('configuration deprecations', () => {

await root.setup();

const logs = loggingServiceMock.collect(mockLoggingService);
const logs = loggingSystemMock.collect(mockLoggingSystem);
const warnings = logs.warn.flatMap((i) => i);
expect(warnings).toContain(
'"optimize.lazy" is deprecated and has been replaced by "optimize.watch"'
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/core_context.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
import { CoreContext } from './core_context';
import { getEnvOptions } from './config/__mocks__/env';
import { Env, IConfigService } from './config';
import { loggingServiceMock } from './logging/logging_service.mock';
import { loggingSystemMock } from './logging/logging_system.mock';
import { configServiceMock } from './config/config_service.mock';
import { ILoggingService } from './logging';
import { ILoggingSystem } from './logging';

function create({
env = Env.createDefault(getEnvOptions()),
logger = loggingServiceMock.create(),
logger = loggingSystemMock.create(),
configService = configServiceMock.create(),
}: {
env?: Env;
logger?: jest.Mocked<ILoggingService>;
logger?: jest.Mocked<ILoggingSystem>;
configService?: jest.Mocked<IConfigService>;
} = {}): DeeplyMockedKeys<CoreContext> {
return { coreId: Symbol(), env, logger, configService };
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/cluster_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import {
import { errors } from 'elasticsearch';
import { get } from 'lodash';
import { Logger } from '../logging';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { loggingSystemMock } from '../logging/logging_system.mock';
import { httpServerMock } from '../http/http_server.mocks';
import { ClusterClient } from './cluster_client';

const logger = loggingServiceMock.create();
const logger = loggingSystemMock.create();
afterEach(() => jest.clearAllMocks());

test('#constructor creates client with parsed config', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import { duration } from 'moment';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { loggingSystemMock } from '../logging/logging_system.mock';
import {
ElasticsearchClientConfig,
parseElasticsearchClientConfig,
} from './elasticsearch_client_config';
const logger = loggingServiceMock.create();
const logger = loggingSystemMock.create();
afterEach(() => jest.clearAllMocks());

test('parses minimally specified config', () => {
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('#log', () => {

expect(typeof esLogger.close).toBe('function');

expect(loggingServiceMock.collect(logger)).toMatchInlineSnapshot(`
expect(loggingSystemMock.collect(logger)).toMatchInlineSnapshot(`
Object {
"debug": Array [],
"error": Array [
Expand Down Expand Up @@ -406,7 +406,7 @@ Object {

expect(typeof esLogger.close).toBe('function');

expect(loggingServiceMock.collect(logger)).toMatchInlineSnapshot(`
expect(loggingSystemMock.collect(logger)).toMatchInlineSnapshot(`
Object {
"debug": Array [
Array [
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/elasticsearch/elasticsearch_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Env } from '../config';
import { getEnvOptions } from '../config/__mocks__/env';
import { CoreContext } from '../core_context';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { loggingSystemMock } from '../logging/logging_system.mock';
import { httpServiceMock } from '../http/http_service.mock';
import { ElasticsearchConfig } from './elasticsearch_config';
import { ElasticsearchService } from './elasticsearch_service';
Expand Down Expand Up @@ -55,7 +55,7 @@ configService.atPath.mockReturnValue(

let env: Env;
let coreContext: CoreContext;
const logger = loggingServiceMock.create();
const logger = loggingSystemMock.create();
beforeEach(() => {
env = Env.createDefault(getEnvOptions());

Expand Down
8 changes: 4 additions & 4 deletions src/core/server/elasticsearch/retry_call_cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import * as legacyElasticsearch from 'elasticsearch';

import { retryCallCluster, migrationsRetryCallCluster } from './retry_call_cluster';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { loggingSystemMock } from '../logging/logging_system.mock';

describe('retryCallCluster', () => {
it('retries ES API calls that rejects with NoConnections', () => {
Expand Down Expand Up @@ -69,10 +69,10 @@ describe('migrationsRetryCallCluster', () => {
'Gone',
];

const mockLogger = loggingServiceMock.create();
const mockLogger = loggingSystemMock.create();

beforeEach(() => {
loggingServiceMock.clear(mockLogger);
loggingSystemMock.clear(mockLogger);
});

errors.forEach((errorName) => {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('migrationsRetryCallCluster', () => {
callEsApi.mockResolvedValueOnce('done');
const retried = migrationsRetryCallCluster(callEsApi, mockLogger.get('mock log'), 1);
await retried('endpoint');
expect(loggingServiceMock.collect(mockLogger).warn).toMatchInlineSnapshot(`
expect(loggingSystemMock.collect(mockLogger).warn).toMatchInlineSnapshot(`
Array [
Array [
"Unable to connect to Elasticsearch. Error: No Living connections",
Expand Down
Loading

0 comments on commit 7211305

Please sign in to comment.