Skip to content

Commit

Permalink
Log deprecations with error level but disable logger context by default
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Dec 1, 2021
1 parent fef4ad5 commit 270ed4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const addLogging = ({ client, type, logger }: { client: Client; type: string; lo

queryLogger.debug(queryMessage, meta);

if (event.headers.warning ?? false) {
if (event.headers!.warning ?? false) {
// Plugins can explicitly mark requests as originating from a user by
// removing the `'x-elastic-product-origin': 'kibana'` header that's
// added by default. User requests will be shown to users in the
Expand All @@ -153,23 +153,27 @@ const addLogging = ({ client, type, logger }: { client: Client; type: string; lo
// Kibana requests will be hidden from the upgrade assistant UI and are
// only logged to help developers maintain their plugins
const requestOrigin =
(event.meta.request.params.headers != null &&
(event.meta.request.params.headers['x-elastic-product-origin'] as unknown as string)) ??
(event.meta.request.options.headers != null &&
(event.meta.request.options.headers[
'x-elastic-product-origin'
] as unknown as string)) ??
'user';

const stackTrace = new Error().stack?.split('\n').slice(5).join('\n');

// Construct a JSON logMeta payload to make it easier for CI tools to consume
const logMeta = {
deprecation: {
message: event.headers.warning ?? 'placeholder',
message: event.headers!.warning ?? 'placeholder',
requestOrigin,
query: queryMessage,
stack: stackTrace,
},
};
deprecationLogger.debug(
`ES DEPRECATION: ${event.headers.warning}\nOrigin:${requestOrigin}\nStack trace:\n${stackTrace}\nQuery:\n${queryMessage}`,
deprecationLogger.error(
`ES DEPRECATION: ${
event.headers!.warning
}\nOrigin:${requestOrigin}\nStack trace:\n${stackTrace}\nQuery:\n${queryMessage}`,
logMeta as unknown as LogMeta
);
}
Expand Down
8 changes: 7 additions & 1 deletion src/core/server/logging/logging_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ export const config = {
defaultValue: new Map<string, AppenderConfigType>(),
}),
loggers: schema.arrayOf(loggerSchema, {
defaultValue: [],
defaultValue: [
{
name: 'elasticsearch.deprecation',
level: 'off',
appenders: [],
},
],
}),
root: schema.object(
{
Expand Down
2 changes: 2 additions & 0 deletions test/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default function () {
`--plugin-path=${path.join(__dirname, 'fixtures', 'plugins', 'newsfeed')}`,
`--newsfeed.service.urlRoot=${servers.kibana.protocol}://${servers.kibana.hostname}:${servers.kibana.port}`,
`--newsfeed.service.pathTemplate=/api/_newsfeed-FTS-external-service-simulators/kibana/v{VERSION}.json`,
'--logging.loggers[0].name=elasticsearch.deprecation',
'--logging.loggers[0].level=all',
],
},
services,
Expand Down

0 comments on commit 270ed4e

Please sign in to comment.