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

Introduce LegacyAppender that forwards log records to the legacy platform. #14354

Merged

Conversation

azasypkin
Copy link
Member

LegacyAppender just forwards all log records it receives to the kbnServer.server.log so that legacy platform can decide how to format that records and where it should be written to.

From the new-platform perspective LegacyAppender is set as default appender used by the root logger.

Fixes #13412.

@azasypkin
Copy link
Member Author

Hey @kjbekkelund,

Here is implementation of the 2nd option I mentioned in the #13412. You can also take a look at the first commit that is what I meant by option 1 :)

append(record: LogRecord) {
this.kbnServer.server.log(
[record.level.id.toLowerCase(), ...record.context.split('.')],
record.error || record.message,
Copy link
Member Author

Choose a reason for hiding this comment

The 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 :/

@@ -24,6 +25,8 @@ export class MutableLoggerFactory implements LoggerFactory {
private readonly bufferAppender = new BufferAppender();
private readonly loggers: Map<string, LoggerAdapter> = new Map();

constructor(private readonly env: Env) {}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env is now everywhere :)

@azasypkin azasypkin force-pushed the issue-13412-legacy-logging-format branch from 7c73347 to 6342f69 Compare October 6, 2017 15:42
@kimjoar
Copy link
Contributor

kimjoar commented Oct 9, 2017

We now export interface LegacyKbnServer, but I wonder if we should make that a class, and construct it with the kbnServer as input. The goal would be to never pass the raw kbnServer around, so we could just have it be any within the LegacyKbnServer class. However, the LegacyKbnServer class would expose the specific apis we want to open up in the new platform, e.g. for logging etc. Does that make sense? You've touched way more than me on this code, so their might be nuances I'm not seeing.

@kimjoar
Copy link
Contributor

kimjoar commented Oct 9, 2017

(I know this isn't too far away from what we're doing, as we're specifying the interface, I'm just trying to make it even stricter — just not sure if it makes sense 🙈)

Copy link
Contributor

@kimjoar kimjoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it works as expected. LGTM.

Just that one question re legacyKbnServer. If you want to we could also do that in a follow-up PR, so I'm good with merging this as-is.

appender.append(record);
}

expect(legacyLogStub.mock.calls).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great use of snapshots imo 🎉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it works pretty well for cases when arguments are predictable, borrowed the approach from your logger mock's _collect method :)

@azasypkin
Copy link
Member Author

We now export interface LegacyKbnServer, but I wonder if we should make that a class, and construct it with the kbnServer as input. The goal would be to never pass the raw kbnServer around, so we could just have it be any within the LegacyKbnServer class. However, the LegacyKbnServer class would expose the specific apis we want to open up in the new platform, e.g. for logging etc. Does that make sense? You've touched way more than me on this code, so their might be nuances I'm not seeing.

Do you mean something like this?

export class LegacyKbnServer {
  constructor(private readonly rawKbnServer: any) {
  }

  get newPlatformProxyListener() {
    return this.rawKbnServer.newPlatformProxyListener;
  }

  log(...args: any[]) {
    this.rawKbnServer.server.log(...args);
  }
}
---------------
export const injectIntoKbnServer = (rawKbnServer: any) => {
  const legacyConfig$ = new BehaviorSubject(rawKbnServer.config);
  const config$ = legacyConfig$.map(
    legacyConfig => new LegacyConfigToRawConfigAdapter(legacyConfig)
  );

  rawKbnServer.updateNewPlatformConfig = (legacyConfig: LegacyConfig) => {
    legacyConfig$.next(legacyConfig);
  };

  //const LegacyPlatformProxifier =
  rawKbnServer.newPlatformProxyListener = new LegacyPlatformProxifier(
    new Root(config$, Env.createDefault({ kbnServer: new LegacyKbnServer(rawKbnServer) }))
  );
};

@kimjoar
Copy link
Contributor

kimjoar commented Oct 9, 2017

Yep

…r` methods under `newPlatform` "namespace".
@azasypkin
Copy link
Member Author

@kjbekkelund Thanks for review. Would you mind taking a look at the 4th commit with LegacyKbnServer class?

Copy link
Contributor

@kimjoar kimjoar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. LGTM.

@@ -0,0 +1,28 @@
import { LegacyKbnServer } from '..';

it('correctly returns `newPlatformProxyListener`.', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: it -> test?

Copy link
Contributor

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)

Copy link
Member Author

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 use it and that was me who did that :), so I'll change them to test too).

@azasypkin azasypkin merged commit 01d0f31 into elastic:new-platform Oct 9, 2017
@azasypkin azasypkin deleted the issue-13412-legacy-logging-format branch October 9, 2017 14:25
@kimjoar kimjoar added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants