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

create kbn-legacy-logging package #77678

Merged
merged 25 commits into from
Nov 22, 2020

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Sep 16, 2020

Summary

Related to #76003 and #56205

Create the @kbn/legacy-logging package and move legacy logging implementation to it.

Checklist

@pgayvallet pgayvallet marked this pull request as ready for review September 17, 2020 14:19
@pgayvallet pgayvallet requested review from a team as code owners September 17, 2020 14:19
@pgayvallet pgayvallet added Feature:Legacy Removal Issues related to removing legacy Kibana release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.10.0 labels Sep 17, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

App Arch updates LGTM

loggers: HANDLED_IN_KIBANA_PLATFORM,
root: HANDLED_IN_KIBANA_PLATFORM,

silent: Joi.boolean().default(false),
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: is it possible to migrate this to config-schema to remove another dependency on joi?

Copy link
Contributor Author

@pgayvallet pgayvallet Sep 23, 2020

Choose a reason for hiding this comment

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

I thought it was not possible, TIL: we actually got siblingRef in config-schema.

However the joi schema is still used by the legacy config: https://github.com/elastic/kibana/pull/77678/files#diff-30708bfadd0e62135e289c55c5d900be. Not sure we can convert it back to joi to register it to the legacy config if we migrate it. We could use the protected internalSchema property though I guess, but not sure this is a proper solution

/**
* Internal "schema" backed by Joi.
* @type {Schema}
*/
protected readonly internalSchema: AnySchema;

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can see: legacy platform doesn't read config values, but pass them to @kbn/legacy-logging so it might be okay to move config validation to those @kbn/legacy-logging methods that accept config as a function parameter. The main downside of this approach is that the logging config will be validated at a different time than the other config parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's keep it that way until #81483 is resolved imho.

packages/kbn-legacy-logging/src/log_format.ts Outdated Show resolved Hide resolved

import KbnLoggerJsonFormat from './log_format_json';
import { attachMetaData } from './metadata';
import { createListStream, createPromiseFromStreams } from './test_utils';
Copy link
Contributor

Choose a reason for hiding this comment

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

another place to fix when we move stream utils to @kbn/std package

packages/kbn-legacy-logging/tsconfig.json Outdated Show resolved Hide resolved
src/legacy/server/kbn_server.js Outdated Show resolved Hide resolved
{
"name": "@kbn/legacy-logging",
"version": "1.0.0",
"private": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a Readme that this package is a temporary workaround until we migrate logging to the KP?

Copy link
Contributor Author

@pgayvallet pgayvallet Sep 23, 2020

Choose a reason for hiding this comment

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

I was more planning to keep it there until we totally get rid of the legacy logging system in 8.0 tbh. It will be way easier to delete it with all the code being centralized in this package. Was that what you meant?

edit: oh, I guess you mean the server event logging part. But there is the same issue. We have to keep support of the legacy logging format, meaning that the module won't go away before 8.0.


setupLogging(this, Config.withDefaultSchema(config));
setupLogging((this as unknown) as Server, loggingConfig, 2147483647);
Copy link
Contributor

Choose a reason for hiding this comment

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

So we expect LegacyLoggingServer won't be called when the package is imported from CLI scripts? How does the final dependency tree look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only import of this package in core (soon in kbn/config instead) is from the legacy appender

constructor(legacyLoggingConfig: Readonly<LegacyVars>) {
this.loggingServer = new LegacyLoggingServer(legacyLoggingConfig);
}

The idea was to change the file to use a dynamic require in the constructor to only load the module when needed. The cli / packages that will use the config service would default to KP logging (probably just defaulting to console appender), that way, the legacy logging (and hapi stuff) is not imported.

Note that the main goal to not load the legacy logging system / hapi when importing the config service was for the apm script instrumentation, which is no longer concerned by the problem, as it will have its own loader to ensure we are not importing any module we want to instrument at all (#77855)

@LeeDr LeeDr added v7.10.1 and removed v7.10.0 labels Nov 12, 2020
data: string | Record<string, any>;
}

export type AnyEvent =
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

return downgradeIfErrorType('HPE_INVALID_METHOD', event);
}

downgradeIfHTTPWhenHTTPS(event) {
downgradeIfHTTPWhenHTTPS(event: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

any --> unknown ?

Copy link
Contributor Author

@pgayvallet pgayvallet Nov 20, 2020

Choose a reason for hiding this comment

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

even better. any -> AnyEvent a60d262

* @param {Array<any>} items - the list of items to provide
* @return {Readable}
*/
export function createListStream<T = any>(items: T | T[] = []) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we haven't move them to @kbn/std yet 😞 let's do in a follow-up

Copy link
Contributor

Choose a reason for hiding this comment

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

opened #84033

"declarationMap": true,
"types": ["jest", "node"]
},
"include": ["./src/**/*.ts"]
Copy link
Contributor

Choose a reason for hiding this comment

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

optional: src/**/*

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
enterpriseSearch 731.7KB 731.8KB +57.0B

Distributable file count

id before after diff
default 42975 43023 +48
oss 22502 22550 +48

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
upgradeAssistant 60.4KB 60.5KB +57.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit e176def into elastic:master Nov 22, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Nov 22, 2020
* create kbn-legacy-logging package and start to move things

* fix rotator tests

* fix logging system test mocks

* move logging format to the package

* move logging setup to package

* adapt legacy logging server

* remove usage of legacy config in the legacy logging server

* move legacy logging server to package

* remove `??` syntax from package

* update generated doc

* fix a few things due to month old merge

* remove typings from project

* move reconfigureLogging to package

* add basic README file

* update generated doc

* remove old typings

* add typing for legacy logging events

* remove `??` from packages

* fix / improve event types usages

* remove suffix from tsconfig
# Conflicts:
#	src/legacy/server/config/schema.js
pgayvallet added a commit that referenced this pull request Nov 23, 2020
* create kbn-legacy-logging package (#77678)

* create kbn-legacy-logging package and start to move things

* fix rotator tests

* fix logging system test mocks

* move logging format to the package

* move logging setup to package

* adapt legacy logging server

* remove usage of legacy config in the legacy logging server

* move legacy logging server to package

* remove `??` syntax from package

* update generated doc

* fix a few things due to month old merge

* remove typings from project

* move reconfigureLogging to package

* add basic README file

* update generated doc

* remove old typings

* add typing for legacy logging events

* remove `??` from packages

* fix / improve event types usages

* remove suffix from tsconfig
# Conflicts:
#	src/legacy/server/config/schema.js

* fix for 7.x branch
gmmorris added a commit to rudolf/kibana that referenced this pull request Nov 23, 2020
* master: (67 commits)
  [Observability] Load hasData call asynchronously (elastic#80644)
  Implement AnonymousAuthenticationProvider. (elastic#79985)
  Deprecate `visualization:colorMapping` advanced setting (elastic#83372)
  [TSVB] [Rollup] Table tab not working with rollup indexes (elastic#83635)
  Revert "[Search] Search batching using bfetch (elastic#83418)" (elastic#84037)
  skip flaky suite (elastic#83772)
  skip flaky suite (elastic#69849)
  create kbn-legacy-logging package (elastic#77678)
  [Search] Search batching using bfetch (elastic#83418)
  [Security Solution] Refactor Timeline flyout to take a full page (elastic#82033)
  Drop use of console-stamp (elastic#83922)
  skip flaky suite (elastic#84011 , elastic#84012)
  Fixed usage of `isReady` for usage collection of alerts and actions (elastic#83760)
  [maps] support URL drilldowns (elastic#83732)
  Revert "Added default dedupKey value as an {{alertInstanceId}} to provide grouping functionality for PagerDuty incidents. (elastic#83226)"
  [code coverage] Update jest config to collect more data (elastic#83804)
  Added default dedupKey value as an {{alertInstanceId}} to provide grouping functionality for PagerDuty incidents. (elastic#83226)
  [Security Solution] Give notice when endpoint policy is out of date (elastic#83469)
  [Security Solution] Sync url state on any changes to query string (elastic#83314)
  [CI] Initial TeamCity implementation (elastic#81043)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Legacy Removal Issues related to removing legacy Kibana release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants