Skip to content

Commit

Permalink
Log deprecations originating from Kibana on debug level (#123660) (#1…
Browse files Browse the repository at this point in the history
…23711)

* Log deprecations originating from Kibana on debug level

* Surface debug level deprecation logs on CI

* Review feedback

(cherry picked from commit c64c766)
  • Loading branch information
rudolf authored Jan 25, 2022
1 parent b37a52b commit c93d9f6
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,13 +532,12 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.emit('response', new errors.ResponseError(response), response);

// One debug log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug.length).toEqual(1);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
/Query:\n.*400\n.*GET \/_path\?hello\=dolly \[illegal_argument_exception\]: request \[\/_path\] contains unrecognized parameter: \[name\]/
);
});
Expand All @@ -564,7 +563,6 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.emit('response', null, response);

expect(loggingSystemMock.collect(logger).info).toEqual([]);
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
Expand Down Expand Up @@ -598,13 +596,12 @@ describe('instrumentQueryAndDeprecationLogger', () => {
});
client.emit('response', null, response);

// One debug log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug.length).toEqual(1);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
// Test debug[1] since theree is one log entry from 'elasticsearch.query' context
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
'Elasticsearch deprecation: 299 Elasticsearch-8.1.0 "GET /_path is deprecated"'
);
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).info[0][0]).toMatch(
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch('Origin:kibana');
expect(loggingSystemMock.collect(logger).debug[1][0]).toMatch(
/Query:\n.*200\n.*GET \/_path\?hello\=dolly/
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,9 @@ export const instrumentEsQueryAndDeprecationLogger = ({
? 'kibana'
: 'user';

const deprecationMsg = `Elasticsearch deprecation: ${event.warnings}\nOrigin:${requestOrigin}\nQuery:\n${queryMsg}`;
if (requestOrigin === 'kibana') {
deprecationLogger.info(deprecationMsg);
} else {
deprecationLogger.debug(deprecationMsg);
}
deprecationLogger.debug(
`Elasticsearch deprecation: ${event.warnings}\nOrigin:${requestOrigin}\nQuery:\n${queryMsg}`
);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function createRoot(options: { maxBatchSizeBytes?: number }) {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function createRoot(options: { maxBatchSizeBytes?: number }) {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function createRoot() {
loggers: [
{
name: 'root',
level: 'info',
appenders: ['file'],
},
],
Expand Down
19 changes: 19 additions & 0 deletions src/core/test_helpers/kbn_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ export function createRootWithCorePlugins(settings = {}, cliArgs: Partial<CliArg
username: kibanaServerTestUser.username,
password: kibanaServerTestUser.password,
},
// Log ES deprecations to surface these in CI
logging: {
loggers: [
{
name: 'root',
level: 'error',
appenders: ['console'],
},
{
name: 'elasticsearch.deprecation',
level: 'all',
appenders: ['deprecation'],
},
],
appenders: {
deprecation: { type: 'console', layout: { type: 'json' } },
console: { type: 'console', layout: { type: 'pattern' } },
},
},
// createRootWithSettings sets default value to "true", so undefined should be threatened as "true".
...(cliArgs.oss === false
? {
Expand Down

0 comments on commit c93d9f6

Please sign in to comment.