Skip to content

Commit

Permalink
Surfacing deprecations with rich context from ES warning header (#120044
Browse files Browse the repository at this point in the history
) (#120800)

* First stab at surfacing deprecations from warning header

* Log deprecations with error level but disable logger context by default

* Don't filter out error logs from ProcRunner

* Another try at not having messages ignored on CI

* Log deprecation logs with warn not info

* Tests

* Let write() do it's writing

* Commit pre-built @kbn/pm package

* Second try to commit pre-built @kbn/pm package

* Enable deprecation logger for jest_integration even though logs aren't interleaved

* Apply suggestions from code review

Co-authored-by: Luke Elmers <[email protected]>

* deprecations logger: warn for kibana and debug for users

* Refactor split query and deprecation logger out of configure_client

* Unit test for tooling_log_text_writer

* Fix TS

* Use event.meta.request.params.headers to include Client constructor headers

* Fix tests

* Ignore deprecation warnings not from Elasticsearch

* Log on info level

* Log in JSON so that entire deprecation message is on one line

* commit built kbn-pm package

Co-authored-by: Luke Elmers <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Rudolf Meijering <[email protected]>
Co-authored-by: Luke Elmers <[email protected]>
  • Loading branch information
3 people authored Dec 8, 2021
1 parent 24b8608 commit 5b04d2b
Show file tree
Hide file tree
Showing 10 changed files with 867 additions and 493 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,55 @@ it('formats %s patterns and indents multi-line messages correctly', () => {
const output = write.mock.calls.reduce((acc, chunk) => `${acc}${chunk}`, '');
expect(output).toMatchSnapshot();
});

it('does not write messages from sources in ignoreSources', () => {
const write = jest.fn();
const writer = new ToolingLogTextWriter({
ignoreSources: ['myIgnoredSource'],
level: 'debug',
writeTo: {
write,
},
});

writer.write({
source: 'myIgnoredSource',
type: 'success',
indent: 10,
args: [
'%s\n%O\n\n%d',
'foo bar',
{ foo: { bar: { 1: [1, 2, 3] } }, bar: { bar: { 1: [1, 2, 3] } } },
Infinity,
],
});

const output = write.mock.calls.reduce((acc, chunk) => `${acc}${chunk}`, '');
expect(output).toEqual('');
});

it('never ignores write messages from the kibana elasticsearch.deprecation logger context', () => {
const write = jest.fn();
const writer = new ToolingLogTextWriter({
ignoreSources: ['myIgnoredSource'],
level: 'debug',
writeTo: {
write,
},
});

writer.write({
source: 'myIgnoredSource',
type: 'write',
indent: 10,
args: [
'%s\n%O\n\n%d',
'[elasticsearch.deprecation]',
{ foo: { bar: { 1: [1, 2, 3] } }, bar: { bar: { 1: [1, 2, 3] } } },
Infinity,
],
});

const output = write.mock.calls.reduce((acc, chunk) => `${acc}${chunk}`, '');
expect(output).toMatchSnapshot();
});
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ export class ToolingLogTextWriter implements Writer {
}

if (this.ignoreSources && msg.source && this.ignoreSources.includes(msg.source)) {
return false;
if (msg.type === 'write') {
const txt = format(msg.args[0], ...msg.args.slice(1));
// Ensure that Elasticsearch deprecation log messages from Kibana aren't ignored
if (!/elasticsearch\.deprecation/.test(txt)) {
return false;
}
} else {
return false;
}
}

const prefix = has(MSG_PREFIXES, msg.type) ? MSG_PREFIXES[msg.type] : '';
Expand Down
10 changes: 9 additions & 1 deletion packages/kbn-pm/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6639,7 +6639,15 @@ class ToolingLogTextWriter {
}

if (this.ignoreSources && msg.source && this.ignoreSources.includes(msg.source)) {
return false;
if (msg.type === 'write') {
const txt = (0, _util.format)(msg.args[0], ...msg.args.slice(1)); // Ensure that Elasticsearch deprecation log messages from Kibana aren't ignored

if (!/elasticsearch\.deprecation/.test(txt)) {
return false;
}
} else {
return false;
}
}

const prefix = has(MSG_PREFIXES, msg.type) ? MSG_PREFIXES[msg.type] : '';
Expand Down
Loading

0 comments on commit 5b04d2b

Please sign in to comment.