Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Deterministic output for doc types (#76890) #76922

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<b>Signature:</b>

```typescript
export declare type AppenderConfigType = TypeOf<typeof appendersSchema>;
export declare type AppenderConfigType = ConsoleAppenderConfig | FileAppenderConfig | LegacyAppenderConfig;
```
13 changes: 3 additions & 10 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
* @packageDocumentation
*/

import { Type } from '@kbn/config-schema';
import {
ElasticsearchServiceSetup,
ILegacyScopedClusterClient,
configSchema as elasticsearchConfigSchema,
ElasticsearchServiceStart,
IScopedClusterClient,
} from './elasticsearch';

import { HttpServiceSetup, HttpServiceStart } from './http';
import { HttpResources } from './http_resources';

Expand All @@ -63,12 +63,7 @@ import { CapabilitiesSetup, CapabilitiesStart } from './capabilities';
import { MetricsServiceStart } from './metrics';
import { StatusServiceSetup } from './status';
import { Auditor, AuditTrailSetup, AuditTrailStart } from './audit_trail';
import {
LoggingServiceSetup,
appendersSchema,
loggerContextConfigSchema,
loggerSchema,
} from './logging';
import { AppenderConfigType, appendersSchema, LoggingServiceSetup } from './logging';

export { AuditableEvent, Auditor, AuditorFactory, AuditTrailSetup } from './audit_trail';
export { bootstrap } from './bootstrap';
Expand Down Expand Up @@ -497,8 +492,6 @@ export const config = {
schema: elasticsearchConfigSchema,
},
logging: {
appenders: appendersSchema,
loggers: loggerSchema,
loggerContext: loggerContextConfigSchema,
appenders: appendersSchema as Type<AppenderConfigType>,
},
};
5 changes: 5 additions & 0 deletions src/core/server/legacy/logging/appenders/legacy_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import { LogRecord } from '../../../logging/log_record';
import { LegacyLoggingServer } from '../legacy_logging_server';
import { LegacyVars } from '../../types';

export interface LegacyAppenderConfig {
kind: 'legacy-appender';
legacyLoggingConfig?: any;
}

/**
* Simple appender that just forwards `LogRecord` to the legacy KbnServer log.
* @internal
Expand Down
13 changes: 8 additions & 5 deletions src/core/server/logging/appenders/appenders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';

import { assertNever } from '../../../utils';
import { LegacyAppender } from '../../legacy/logging/appenders/legacy_appender';
import {
LegacyAppender,
LegacyAppenderConfig,
} from '../../legacy/logging/appenders/legacy_appender';
import { Layouts } from '../layouts/layouts';
import { LogRecord } from '../log_record';
import { ConsoleAppender } from './console/console_appender';
import { FileAppender } from './file/file_appender';
import { ConsoleAppender, ConsoleAppenderConfig } from './console/console_appender';
import { FileAppender, FileAppenderConfig } from './file/file_appender';

/**
* Config schema for validting the shape of the `appenders` key in in {@link LoggerContextConfigType} or
Expand All @@ -39,7 +42,7 @@ export const appendersSchema = schema.oneOf([
]);

/** @public */
export type AppenderConfigType = TypeOf<typeof appendersSchema>;
export type AppenderConfigType = ConsoleAppenderConfig | FileAppenderConfig | LegacyAppenderConfig;

/**
* Entity that can append `LogRecord` instances to file, stdout, memory or whatever
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@

import { schema } from '@kbn/config-schema';

import { Layout, Layouts } from '../../layouts/layouts';
import { Layout, Layouts, LayoutConfigType } from '../../layouts/layouts';
import { LogRecord } from '../../log_record';
import { DisposableAppender } from '../appenders';

const { literal, object } = schema;

export interface ConsoleAppenderConfig {
kind: 'console';
layout: LayoutConfigType;
}

/**
*
* Appender that formats all the `LogRecord` instances it receives and logs them via built-in `console`.
* @internal
*/
Expand Down
8 changes: 7 additions & 1 deletion src/core/server/logging/appenders/file/file_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@
import { schema } from '@kbn/config-schema';
import { createWriteStream, WriteStream } from 'fs';

import { Layout, Layouts } from '../../layouts/layouts';
import { Layout, Layouts, LayoutConfigType } from '../../layouts/layouts';
import { LogRecord } from '../../log_record';
import { DisposableAppender } from '../appenders';

export interface FileAppenderConfig {
kind: 'file';
layout: LayoutConfigType;
path: string;
}

/**
* Appender that formats all the `LogRecord` instances it receives and writes them to the specified file.
* @internal
Expand Down
6 changes: 4 additions & 2 deletions src/core/server/logging/layouts/json_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import moment from 'moment-timezone';
import { merge } from 'lodash';
import { schema, TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';

import { LogRecord } from '../log_record';
import { Layout } from './layouts';
Expand All @@ -31,7 +31,9 @@ const jsonLayoutSchema = object({
});

/** @internal */
export type JsonLayoutConfigType = TypeOf<typeof jsonLayoutSchema>;
export interface JsonLayoutConfigType {
kind: 'json';
}

/**
* Layout that just converts `LogRecord` into JSON string.
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { PatternLayout, PatternLayoutConfigType } from './pattern_layout';

const { oneOf } = schema;

type LayoutConfigType = PatternLayoutConfigType | JsonLayoutConfigType;
export type LayoutConfigType = PatternLayoutConfigType | JsonLayoutConfigType;

/**
* Entity that can format `LogRecord` instance into a string.
Expand Down
8 changes: 6 additions & 2 deletions src/core/server/logging/layouts/pattern_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';

import { LogRecord } from '../log_record';
import { Layout } from './layouts';
Expand Down Expand Up @@ -58,7 +58,11 @@ const conversions: Conversion[] = [
];

/** @internal */
export type PatternLayoutConfigType = TypeOf<typeof patternLayoutSchema>;
export interface PatternLayoutConfigType {
kind: 'pattern';
highlight?: boolean;
pattern?: string;
}

/**
* Layout that formats `LogRecord` using the `pattern` string with optional
Expand Down
4 changes: 3 additions & 1 deletion src/core/server/logging/logging_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export const config = {
}),
};

export type LoggingConfigType = TypeOf<typeof config.schema>;
export type LoggingConfigType = Omit<TypeOf<typeof config.schema>, 'appenders'> & {
appenders: Map<string, AppenderConfigType>;
};

/**
* Config schema for validating the inputs to the {@link LoggingServiceStart.configure} API.
Expand Down
123 changes: 31 additions & 92 deletions src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ import { UpdateDocumentByQueryParams } from 'elasticsearch';
import { UpdateDocumentParams } from 'elasticsearch';
import { Url } from 'url';

// Warning: (ae-forgotten-export) The symbol "appendersSchema" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ConsoleAppenderConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "FileAppenderConfig" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "LegacyAppenderConfig" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type AppenderConfigType = TypeOf<typeof appendersSchema>;
export type AppenderConfigType = ConsoleAppenderConfig | FileAppenderConfig | LegacyAppenderConfig;

// @public
export function assertNever(x: never): never;
Expand Down Expand Up @@ -325,108 +327,45 @@ export type CapabilitiesSwitcher = (request: KibanaRequest, uiCapabilities: Capa
export const config: {
elasticsearch: {
schema: import("@kbn/config-schema").ObjectType<{
sniffOnStart: import("@kbn/config-schema").Type<boolean>;
sniffInterval: import("@kbn/config-schema").Type<false | import("moment").Duration>;
sniffOnConnectionFault: import("@kbn/config-schema").Type<boolean>;
hosts: import("@kbn/config-schema").Type<string | string[]>;
preserveHost: import("@kbn/config-schema").Type<boolean>;
username: import("@kbn/config-schema").Type<string | undefined>;
password: import("@kbn/config-schema").Type<string | undefined>;
requestHeadersWhitelist: import("@kbn/config-schema").Type<string | string[]>;
customHeaders: import("@kbn/config-schema").Type<Record<string, string>>;
shardTimeout: import("@kbn/config-schema").Type<import("moment").Duration>;
requestTimeout: import("@kbn/config-schema").Type<import("moment").Duration>;
pingTimeout: import("@kbn/config-schema").Type<import("moment").Duration>;
startupTimeout: import("@kbn/config-schema").Type<import("moment").Duration>;
logQueries: import("@kbn/config-schema").Type<boolean>;
sniffOnStart: Type<boolean>;
sniffInterval: Type<false | import("moment").Duration>;
sniffOnConnectionFault: Type<boolean>;
hosts: Type<string | string[]>;
preserveHost: Type<boolean>;
username: Type<string | undefined>;
password: Type<string | undefined>;
requestHeadersWhitelist: Type<string | string[]>;
customHeaders: Type<Record<string, string>>;
shardTimeout: Type<import("moment").Duration>;
requestTimeout: Type<import("moment").Duration>;
pingTimeout: Type<import("moment").Duration>;
startupTimeout: Type<import("moment").Duration>;
logQueries: Type<boolean>;
ssl: import("@kbn/config-schema").ObjectType<{
verificationMode: import("@kbn/config-schema").Type<"none" | "certificate" | "full">;
certificateAuthorities: import("@kbn/config-schema").Type<string | string[] | undefined>;
certificate: import("@kbn/config-schema").Type<string | undefined>;
key: import("@kbn/config-schema").Type<string | undefined>;
keyPassphrase: import("@kbn/config-schema").Type<string | undefined>;
verificationMode: Type<"none" | "certificate" | "full">;
certificateAuthorities: Type<string | string[] | undefined>;
certificate: Type<string | undefined>;
key: Type<string | undefined>;
keyPassphrase: Type<string | undefined>;
keystore: import("@kbn/config-schema").ObjectType<{
path: import("@kbn/config-schema").Type<string | undefined>;
password: import("@kbn/config-schema").Type<string | undefined>;
path: Type<string | undefined>;
password: Type<string | undefined>;
}>;
truststore: import("@kbn/config-schema").ObjectType<{
path: import("@kbn/config-schema").Type<string | undefined>;
password: import("@kbn/config-schema").Type<string | undefined>;
path: Type<string | undefined>;
password: Type<string | undefined>;
}>;
alwaysPresentCertificate: import("@kbn/config-schema").Type<boolean>;
alwaysPresentCertificate: Type<boolean>;
}>;
apiVersion: import("@kbn/config-schema").Type<string>;
apiVersion: Type<string>;
healthCheck: import("@kbn/config-schema").ObjectType<{
delay: import("@kbn/config-schema").Type<import("moment").Duration>;
delay: Type<import("moment").Duration>;
}>;
ignoreVersionMismatch: import("@kbn/config-schema/target/types/types").ConditionalType<false, boolean, boolean>;
}>;
};
logging: {
appenders: import("@kbn/config-schema").Type<Readonly<{} & {
layout: Readonly<{} & {
kind: "json";
}> | Readonly<{
pattern?: string | undefined;
highlight?: boolean | undefined;
} & {
kind: "pattern";
}>;
kind: "console";
}> | Readonly<{} & {
path: string;
layout: Readonly<{} & {
kind: "json";
}> | Readonly<{
pattern?: string | undefined;
highlight?: boolean | undefined;
} & {
kind: "pattern";
}>;
kind: "file";
}> | Readonly<{
legacyLoggingConfig?: any;
} & {
kind: "legacy-appender";
}>>;
loggers: import("@kbn/config-schema").ObjectType<{
appenders: import("@kbn/config-schema").Type<string[]>;
context: import("@kbn/config-schema").Type<string>;
level: import("@kbn/config-schema").Type<import("./logging/log_level").LogLevelId>;
}>;
loggerContext: import("@kbn/config-schema").ObjectType<{
appenders: import("@kbn/config-schema").Type<Map<string, Readonly<{} & {
layout: Readonly<{} & {
kind: "json";
}> | Readonly<{
pattern?: string | undefined;
highlight?: boolean | undefined;
} & {
kind: "pattern";
}>;
kind: "console";
}> | Readonly<{} & {
path: string;
layout: Readonly<{} & {
kind: "json";
}> | Readonly<{
pattern?: string | undefined;
highlight?: boolean | undefined;
} & {
kind: "pattern";
}>;
kind: "file";
}> | Readonly<{
legacyLoggingConfig?: any;
} & {
kind: "legacy-appender";
}>>>;
loggers: import("@kbn/config-schema").Type<Readonly<{} & {
context: string;
appenders: string[];
level: import("./logging/log_level").LogLevelId;
}>[]>;
}>;
appenders: Type<AppenderConfigType>;
};
};

Expand Down
1 change: 1 addition & 0 deletions tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"incremental": false,
"declaration": true,
"outDir": "./target/types",
"stripInternal": false,
Expand Down