-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Introduce LegacyAppender
that forwards log records to the legacy platform.
#14354
Merged
azasypkin
merged 5 commits into
elastic:new-platform
from
azasypkin:issue-13412-legacy-logging-format
Oct 9, 2017
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2dd3f40
Introduce `LegacyJsonLayout` and `LegacyPatternLayout`.
azasypkin 0666d03
Introduce `LegacyAppender` instead of custom legacy layouts.
azasypkin 6342f69
Add unit tests for `LegacyAppender`.
azasypkin 575be11
Convert `LegacyKbnServer` interface to class. Group all new `kbnServe…
azasypkin b9aa1ab
Change `it` to `test`.
azasypkin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,25 @@ | ||
import { LegacyConfig } from './LegacyPlatformConfig'; | ||
import { LegacyPlatformProxifier } from './LegacyPlatformProxifier'; | ||
|
||
/** | ||
* Represents legacy kbnServer instance, provided by the legacy platform. | ||
* Represents a wrapper around legacy `kbnServer` instance that exposes only | ||
* a subset of `kbnServer` APIs used by the new platform. | ||
* @internal | ||
*/ | ||
export interface LegacyKbnServer { | ||
readonly config: LegacyConfig; | ||
readonly server: { log: (...args: any[]) => void }; | ||
export class LegacyKbnServer { | ||
constructor(private readonly rawKbnServer: any) {} | ||
|
||
/** | ||
* Custom HTTP Listener provided by the new platform and that will be used | ||
* within legacy platform by HapiJS server. | ||
* Custom HTTP Listener used by HapiJS server in the legacy platform. | ||
*/ | ||
newPlatformProxyListener: LegacyPlatformProxifier; | ||
get newPlatformProxyListener() { | ||
return this.rawKbnServer.newPlatform.proxyListener; | ||
} | ||
|
||
/** | ||
* Propagates legacy config updates to the new platform. | ||
* Forwards log request to the legacy platform. | ||
* @param tags A string or array of strings used to briefly identify the event. | ||
* @param [data] Optional string or object to log with the event. | ||
* @param [timestamp] Timestamp value associated with the log record. | ||
*/ | ||
updateNewPlatformConfig: (legacyConfig: LegacyConfig) => void; | ||
log(tags: string | string[], data?: string | Error, timestamp?: Date) { | ||
this.rawKbnServer.server.log(tags, data, timestamp); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { LegacyKbnServer } from '..'; | ||
|
||
it('correctly returns `newPlatformProxyListener`.', () => { | ||
const rawKbnServer = { | ||
newPlatform: { | ||
proxyListener: {} | ||
} | ||
}; | ||
|
||
const legacyKbnServer = new LegacyKbnServer(rawKbnServer); | ||
expect(legacyKbnServer.newPlatformProxyListener).toBe( | ||
rawKbnServer.newPlatform.proxyListener | ||
); | ||
}); | ||
|
||
it('correctly forwards log record.', () => { | ||
const rawKbnServer = { | ||
server: { log: jest.fn() } | ||
}; | ||
|
||
const legacyKbnServer = new LegacyKbnServer(rawKbnServer); | ||
|
||
const timestamp = new Date(Date.UTC(2012, 1, 1, 11, 22, 33, 44)); | ||
legacyKbnServer.log(['one', 'two'], 'message', timestamp); | ||
legacyKbnServer.log('three', new Error('log error'), timestamp); | ||
|
||
expect(rawKbnServer.server.log.mock.calls).toMatchSnapshot(); | ||
}); |
19 changes: 19 additions & 0 deletions
19
platform/legacy/__tests__/__snapshots__/LegacyKbnServer.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`correctly forwards log record. 1`] = ` | ||
Array [ | ||
Array [ | ||
Array [ | ||
"one", | ||
"two", | ||
], | ||
"message", | ||
2012-02-01T11:22:33.044Z, | ||
], | ||
Array [ | ||
"three", | ||
[Error: log error], | ||
2012-02-01T11:22:33.044Z, | ||
], | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ export class LegacyAppender implements DisposableAppender { | |
* @param record `LogRecord` instance to forward to. | ||
*/ | ||
append(record: LogRecord) { | ||
this.kbnServer.server.log( | ||
this.kbnServer.log( | ||
[record.level.id.toLowerCase(), ...record.context.split('.')], | ||
record.error || record.message, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: it seems in the legacy platform we can't provide both message and error :/ |
||
record.timestamp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick:
it
->test
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm not sure here, as I don't know if we are consistent either way, so feel free to skip)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha-ha, right, it should definitely be
test
- I believe we are pretty consistent on this in the new platform code (I see only 3 more tests that useit
and that was me who did that :), so I'll change them totest
too).