Skip to content

Commit

Permalink
[Rename] Refactored src/core/server/logging,metrics,plugins,rendering…
Browse files Browse the repository at this point in the history
…,root (#90)

* [Rename] addressed PR comments

Signed-off-by: Mihir Soni <mihirsoni.123@gmail.com>
  • Loading branch information
mihirsoni committed Mar 20, 2021
1 parent ef9d8a5 commit 59c9657
Show file tree
Hide file tree
Showing 69 changed files with 269 additions and 269 deletions.
22 changes: 11 additions & 11 deletions src/core/server/logging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
- [Logging config migration](#logging-config-migration)
- [Log record format changes](#log-record-format-changes)

The way logging works in Kibana is inspired by `log4j 2` logging framework used by [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#logging).
The main idea is to have consistent logging behaviour (configuration, log format etc.) across the entire Elastic Stack
The way logging works in OpenSearch Dashboards is inspired by `log4j 2` logging framework used by [OpenSearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/settings.html#logging).
The main idea is to have consistent logging behaviour (configuration, log format etc.) across the entire OpenSearch Stack
where possible.

## Loggers, Appenders and Layouts

Kibana logging system has three main components: _loggers_, _appenders_ and _layouts_. These components allow us to log
OpenSearch Dashboards logging system has three main components: _loggers_, _appenders_ and _layouts_. These components allow us to log
messages according to message type and level, and to control how these messages are formatted and where the final logs
will be displayed or stored.

Expand Down Expand Up @@ -86,7 +86,7 @@ Example of `%logger` output:
```bash
server
server.http
server.http.Kibana
server.http.OpenSearchDashboards
```

#### message
Expand Down Expand Up @@ -130,7 +130,7 @@ text and any other metadata that may be associated with the log message itself.
## Configuration

As any configuration in the platform, logging configuration is validated against the predefined schema and if there are
any issues with it, Kibana will fail to start with the detailed error message.
any issues with it, OpenSearch Dashboards will fail to start with the detailed error message.

Once the code acquired a logger instance it should not care about any runtime changes in the configuration that may
happen: all changes will be applied to existing logger instances under the hood.
Expand All @@ -147,7 +147,7 @@ logging:
highlight: true
file:
kind: file
path: /var/log/kibana.log
path: /var/log/opensearch_dashboards.log
layout:
kind: pattern
custom:
Expand All @@ -157,7 +157,7 @@ logging:
pattern: "[%date][%level] %message"
json-file-appender:
kind: file
path: /var/log/kibana-json.log
path: /var/log/opensearch-dashboards-json.log

root:
appenders: [console, file]
Expand Down Expand Up @@ -212,7 +212,7 @@ Usage is very straightforward, one should just get a logger for a specific conte
different log level.

```typescript
const logger = kibana.logger.get('server');
const logger = opensearchDashboards.logger.get('server');
logger.trace('Message with `trace` log level.');
logger.debug('Message with `debug` log level.');
Expand All @@ -221,7 +221,7 @@ logger.warn('Message with `warn` log level.');
logger.error('Message with `error` log level.');
logger.fatal('Message with `fatal` log level.');

const loggerWithNestedContext = kibana.logger.get('server', 'http');
const loggerWithNestedContext = opensearchDashboards.logger.get('server', 'http');
loggerWithNestedContext.trace('Message with `trace` log level.');
loggerWithNestedContext.debug('Message with `debug` log level.');
```
Expand Down Expand Up @@ -254,7 +254,7 @@ root appenders, make sure that it contains `default` appender to provide backwar
`root` context anymore and not forwarded to the legacy logging service.

#### logging.dest
By default logs in *stdout*. With new Kibana logging you can use pre-existing `console` appender or
By default logs in *stdout*. With new OpenSearch Dashboards logging you can use pre-existing `console` appender or
define a custom one.
```yaml
logging:
Expand All @@ -269,7 +269,7 @@ logging:
appenders:
file:
kind: file
path: /var/log/kibana.log
path: /var/log/opensearch_dashboards.log
layout:
kind: pattern
loggers:
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/appenders/appenders.test.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export const mockCreateLayout = jest.fn();
jest.mock('../layouts/layouts', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { schema } = require('@kbn/config-schema');
const { schema } = require('@osd/config-schema');
return {
Layouts: {
configSchema: schema.object({ kind: schema.literal('mock') }),
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/logging/appenders/appenders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { assertNever } from '@kbn/std';
import { DisposableAppender } from '@kbn/logging';
import { schema } from '@osd/config-schema';
import { assertNever } from '@osd/std';
import { DisposableAppender } from '@osd/logging';

import {
LegacyAppender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogLevel, LogRecord } from '@kbn/logging';
import { LogLevel, LogRecord } from '@osd/logging';
import { BufferAppender } from './buffer_appender';

test('`flush()` does not return any record buffered at the beginning.', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogRecord, DisposableAppender } from '@kbn/logging';
import { LogRecord, DisposableAppender } from '@osd/logging';

/**
* Simple appender that just buffers `LogRecord` instances it receives. It is a *reserved* appender
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

jest.mock('../../layouts/layouts', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { schema } = require('@kbn/config-schema');
const { schema } = require('@osd/config-schema');
return {
Layouts: {
configSchema: schema.object({
Expand All @@ -29,7 +29,7 @@ jest.mock('../../layouts/layouts', () => {
};
});

import { LogRecord, LogLevel } from '@kbn/logging';
import { LogRecord, LogLevel } from '@osd/logging';
import { ConsoleAppender } from './console_appender';

test('`configSchema` creates correct schema.', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/logging/appenders/console/console_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { Layout, LogRecord, DisposableAppender } from '@kbn/logging';
import { schema } from '@osd/config-schema';
import { Layout, LogRecord, DisposableAppender } from '@osd/logging';
import { Layouts, LayoutConfigType } from '../../layouts/layouts';

const { literal, object } = schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

jest.mock('../../layouts/layouts', () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { schema } = require('@kbn/config-schema');
const { schema } = require('@osd/config-schema');
return {
Layouts: {
configSchema: schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { mockCreateWriteStream } from './file_appender.test.mocks';

import { LogRecord, LogLevel } from '@kbn/logging';
import { LogRecord, LogLevel } from '@osd/logging';
import { FileAppender } from './file_appender';

const tickMs = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/logging/appenders/file/file_appender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { LogRecord, Layout, DisposableAppender } from '@kbn/logging';
import { schema } from '@osd/config-schema';
import { LogRecord, Layout, DisposableAppender } from '@osd/logging';
import { createWriteStream, WriteStream } from 'fs';

import { Layouts, LayoutConfigType } from '../../layouts/layouts';
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export {
Logger,
LogLevelId,
LogLevel,
} from '@kbn/logging';
} from '@osd/logging';
export {
config,
LoggingConfigType,
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/logging/integration_tests/logging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

import * as kbnTestServer from '../../../test_helpers/kbn_server';
import * as osdTestServer from '../../../test_helpers/osd_server';
import { InternalCoreSetup } from '../../internal_types';
import { LoggerContextConfigInput } from '../logging_config';
import { Subject } from 'rxjs';

function createRoot() {
return kbnTestServer.createRoot({
return osdTestServer.createRoot({
logging: {
silent: true, // set "true" in kbnTestServer
silent: true, // set "true" in osdTestServer
appenders: {
'test-console': {
kind: 'console',
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('logging service', () => {
enable ? loggingConfig$.next(CUSTOM_LOGGING_CONFIG) : loggingConfig$.next({});
beforeAll(async () => {
mockConsoleLog = jest.spyOn(global.console, 'log');
root = kbnTestServer.createRoot();
root = osdTestServer.createRoot();

setup = await root.setup();
setup.logging.configure(['plugins', 'myplugin'], loggingConfig$);
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import moment from 'moment-timezone';
import { last } from 'lodash';
import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';

import { Conversion } from './type';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import chalk from 'chalk';
import { LogRecord, LogLevel } from '@kbn/logging';
import { LogRecord, LogLevel } from '@osd/logging';

import { Conversion } from './type';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import chalk from 'chalk';
import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';

import { Conversion } from './type';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';
import { Conversion } from './type';

export const MessageConversion: Conversion = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';
import { Conversion } from './type';

export const MetaConversion: Conversion = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/pid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';
import { Conversion } from './type';

export const PidConversion: Conversion = {
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/layouts/conversions/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogRecord } from '@kbn/logging';
import { LogRecord } from '@osd/logging';

export interface Conversion {
pattern: RegExp;
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/logging/layouts/json_layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogLevel, LogRecord } from '@kbn/logging';
import { LogLevel, LogRecord } from '@osd/logging';
import { JsonLayout } from './json_layout';

const timestamp = new Date(Date.UTC(2012, 1, 1, 14, 30, 22, 11));
Expand Down Expand Up @@ -207,7 +207,7 @@ test('format() meta can merge override logs', () => {
pid: 3,
meta: {
log: {
kbn_custom_field: 'hello',
osd_custom_field: 'hello',
},
},
})
Expand All @@ -218,7 +218,7 @@ test('format() meta can merge override logs', () => {
log: {
level: 'ERROR',
logger: 'bar',
kbn_custom_field: 'hello',
osd_custom_field: 'hello',
},
process: {
pid: 3,
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/logging/layouts/json_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import moment from 'moment-timezone';
import { merge } from 'lodash';
import { schema } from '@kbn/config-schema';
import { LogRecord, Layout } from '@kbn/logging';
import { schema } from '@osd/config-schema';
import { LogRecord, Layout } from '@osd/logging';

const { literal, object } = schema;

Expand Down
6 changes: 3 additions & 3 deletions src/core/server/logging/layouts/layouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { Layout } from '@kbn/logging';
import { assertNever } from '@kbn/std';
import { schema } from '@osd/config-schema';
import { Layout } from '@osd/logging';
import { assertNever } from '@osd/std';

import { JsonLayout, JsonLayoutConfigType } from './json_layout';
import { PatternLayout, PatternLayoutConfigType } from './pattern_layout';
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/logging/layouts/pattern_layout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogLevel, LogRecord } from '@kbn/logging';
import { LogLevel, LogRecord } from '@osd/logging';
import { stripAnsiSnapshotSerializer } from '../../../test_helpers/strip_ansi_snapshot_serializer';
import { PatternLayout, patternSchema } from './pattern_layout';

Expand Down Expand Up @@ -310,8 +310,8 @@ describe('schema', () => {

it('fails on %date with predefined date format and invalid timezone', () => {
expect(() =>
patternSchema.validate('%date{ISO8601_TZ}{Europe/Kibana}')
).toThrowErrorMatchingInlineSnapshot(`"Unknown timezone: Europe/Kibana"`);
patternSchema.validate('%date{ISO8601_TZ}{Europe/OpenSearchDashboards}')
).toThrowErrorMatchingInlineSnapshot(`"Unknown timezone: Europe/OpenSearchDashboards"`);
});

it('validates several %date in pattern', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/logging/layouts/pattern_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { schema } from '@kbn/config-schema';
import { LogRecord, Layout } from '@kbn/logging';
import { schema } from '@osd/config-schema';
import { LogRecord, Layout } from '@osd/logging';

import {
Conversion,
Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/logger.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { loggerMock, MockedLogger } from '@kbn/logging/target/mocks';
export { loggerMock, MockedLogger } from '@osd/logging/target/mocks';
2 changes: 1 addition & 1 deletion src/core/server/logging/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { LogLevel, Appender } from '@kbn/logging';
import { LogLevel, Appender } from '@osd/logging';
import { LoggingConfig } from './logging_config';
import { BaseLogger } from './logger';

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/logging/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Appender, LogLevel, LogRecord, LoggerFactory, LogMeta, Logger } from '@kbn/logging';
import { Appender, LogLevel, LogRecord, LoggerFactory, LogMeta, Logger } from '@osd/logging';

function isError(x: any): x is Error {
return x instanceof Error;
Expand Down
Loading

0 comments on commit 59c9657

Please sign in to comment.