Skip to content

[server/logging] intercept ECONNRESET messages and downgrade them#8785

Merged
spalger merged 6 commits intoelastic:masterfrom
spalger:implement/server-log-interceptor
Oct 20, 2016
Merged

[server/logging] intercept ECONNRESET messages and downgrade them#8785
spalger merged 6 commits intoelastic:masterfrom
spalger:implement/server-log-interceptor

Conversation

@spalger
Copy link
Copy Markdown
Contributor

@spalger spalger commented Oct 20, 2016

Fixes #8623

Implements a LogInterceptor that sees every log message before it is filtered by the squeeze stream. This allows us to transform log messages we might not have control over, like the log messages that come from hapi itself, before they are processed by the standard log message pipeline.

}

const unmatchedEventTags = event.tags.slice(0);
const unmatchedExpectedTags = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tags seem to have a perceived order. Is there a reason for not requiring the order to match as well?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we require the order to match, I think we could potentially use _.isEqual

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I suppose I could sort and then use _.isEqual, sounds good to me!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am thinking we don't even need to sort. The expected tags would need to match the order of the events tags. Trying to not do more than we need to.

Copy link
Copy Markdown
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

LGTM

One minor question/suggestion

if (i > -1) {
unmatchedEventTags.splice(i, 1);
} else {
unmatchedExpectedTags.push(t);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we just return false here?

}
});

return unmatchedEventTags.concat(unmatchedExpectedTags).length === 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We could check if the length of unmatchedEventTags is 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I suppose we could, since the lengths of both arrays is the same.

import { get, isEqual, sortBy } from 'lodash';

function doTagsMatch(event, tags) {
return isEqual(sortBy(get(event, 'tags')), sortBy(tags));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Repeating here since my comment is hidden after the last update:

Is there a reason why we need to support not matching the order?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't control the code that sends the tags, and I don't see why we wouldn't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It just doesn't seem necessary to add the additional overhead while limiting control. Should the tag order change in Hapi we can always update them. In the future if we want to be less greedy with the matching we can then sort.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright

@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Oct 20, 2016

LGTM

@@ -0,0 +1,55 @@
import expect from 'expect.js';
import { shuffle } from 'lodash';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shuffle is no longer being used.

Copy link
Copy Markdown
Member

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

LGTM!

* @param {object} - log event
*/
downgradeIfEconnreset(event) {
const isClientError = doTagsMatch(event, ['error', 'client', 'connection']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hapi is using the following order ['connection', 'client', 'error'] per https://github.com/hapijs/hapi/blob/master/lib/connection.js#L96

Copy link
Copy Markdown
Contributor Author

@spalger spalger Oct 20, 2016

Choose a reason for hiding this comment

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

ugh, I looked at the order in the log output, which is sorted by color I think :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch! I have seen it so much today it's just a blur.

@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Oct 20, 2016

LGTM - Ship It!!

@spalger spalger merged commit 7c482af into elastic:master Oct 20, 2016
elastic-jasper added a commit that referenced this pull request Oct 20, 2016
---------

**Commit 1:**
[server/logging] intercept ECONNRESET messages and downgrade them

* Original sha: 38bcad9
* Authored by spalger <email@spalger.com> on 2016-10-20T19:24:16Z

**Commit 2:**
[server/logging] remove doTagsMatch() helper

* Original sha: a8eea58
* Authored by spalger <email@spalger.com> on 2016-10-20T20:19:33Z

**Commit 3:**
[server/logging] add tests for log interceptor

* Original sha: 866abcc
* Authored by spalger <email@spalger.com> on 2016-10-20T20:35:35Z

**Commit 4:**
[server/logging] only match tags that are in the right order

* Original sha: 1973ed8
* Authored by spalger <email@spalger.com> on 2016-10-20T20:50:26Z

**Commit 5:**
[server/logging] remove unused dependency

* Original sha: dbe5f6f
* Authored by spalger <email@spalger.com> on 2016-10-20T20:58:59Z

**Commit 6:**
[server/logging] fix the order we expect tags to be in

* Original sha: 76e09e6
* Authored by spalger <email@spalger.com> on 2016-10-20T21:04:58Z
elastic-jasper added a commit that referenced this pull request Oct 20, 2016
---------

**Commit 1:**
[server/logging] intercept ECONNRESET messages and downgrade them

* Original sha: 38bcad9
* Authored by spalger <email@spalger.com> on 2016-10-20T19:24:16Z

**Commit 2:**
[server/logging] remove doTagsMatch() helper

* Original sha: a8eea58
* Authored by spalger <email@spalger.com> on 2016-10-20T20:19:33Z

**Commit 3:**
[server/logging] add tests for log interceptor

* Original sha: 866abcc
* Authored by spalger <email@spalger.com> on 2016-10-20T20:35:35Z

**Commit 4:**
[server/logging] only match tags that are in the right order

* Original sha: 1973ed8
* Authored by spalger <email@spalger.com> on 2016-10-20T20:50:26Z

**Commit 5:**
[server/logging] remove unused dependency

* Original sha: dbe5f6f
* Authored by spalger <email@spalger.com> on 2016-10-20T20:58:59Z

**Commit 6:**
[server/logging] fix the order we expect tags to be in

* Original sha: 76e09e6
* Authored by spalger <email@spalger.com> on 2016-10-20T21:04:58Z
epixa added a commit that referenced this pull request Oct 20, 2016
[backport] PR #8785 to 5.0 - [server/logging] intercept ECONNRESET messages and downgrade them
epixa added a commit that referenced this pull request Oct 20, 2016
[backport] PR #8785 to 5.x - [server/logging] intercept ECONNRESET messages and downgrade them
@epixa epixa added v5.1.1 and removed v5.1.0 labels Dec 8, 2016
epixa added a commit that referenced this pull request Dec 22, 2016
With the latest node/hapi upgrades, ECONNRESET errors are being logged
whereas they weren't before.
@epixa epixa added the v4.6.4 label Dec 22, 2016
@epixa
Copy link
Copy Markdown
Contributor

epixa commented Dec 22, 2016

4.6 9f5cf2c

airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
---------

**Commit 1:**
[server/logging] intercept ECONNRESET messages and downgrade them

* Original sha: 77dc71aa714369e40f3660c655b9e08b00010699 [formerly 38bcad9]
* Authored by spalger <email@spalger.com> on 2016-10-20T19:24:16Z

**Commit 2:**
[server/logging] remove doTagsMatch() helper

* Original sha: 0bde8381146b8c4d391360cb4d5feda9b1e3d3cd [formerly a8eea58]
* Authored by spalger <email@spalger.com> on 2016-10-20T20:19:33Z

**Commit 3:**
[server/logging] add tests for log interceptor

* Original sha: 6c529b0f47582bc863f025f5fe83b07f59af6fd8 [formerly 866abcc]
* Authored by spalger <email@spalger.com> on 2016-10-20T20:35:35Z

**Commit 4:**
[server/logging] only match tags that are in the right order

* Original sha: 04b7da8b4cb502e25fc65714c3e8fa9cba5725ca [formerly 1973ed8]
* Authored by spalger <email@spalger.com> on 2016-10-20T20:50:26Z

**Commit 5:**
[server/logging] remove unused dependency

* Original sha: 7990a50ec74343b3b1a3200873132377dfbda20e [formerly dbe5f6f]
* Authored by spalger <email@spalger.com> on 2016-10-20T20:58:59Z

**Commit 6:**
[server/logging] fix the order we expect tags to be in

* Original sha: f21a523883ef26c8ca7d461c54da8d66fb0076c5 [formerly 76e09e6]
* Authored by spalger <email@spalger.com> on 2016-10-20T21:04:58Z


Former-commit-id: 6326821
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
[backport] PR elastic#8785 to 5.x - [server/logging] intercept ECONNRESET messages and downgrade them

Former-commit-id: a5080ee
@spalger spalger deleted the implement/server-log-interceptor branch October 18, 2019 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants