This repository was archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Add fail after configuration #155
Open
ubnt-michals
wants to merge
2
commits into
rapid7:master
Choose a base branch
from
ubnt-michals:fail_after_configuration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,8 @@ import text from './text'; | |
| import build from './serialize'; | ||
| import { | ||
| BadOptionsError, | ||
| LogentriesError | ||
| LogentriesError, | ||
| ReconnectFailedError, | ||
| } from './error'; | ||
| import RingBuffer from './ringbuffer'; | ||
| import BunyanStream from './bunyanstream'; | ||
|
|
@@ -140,6 +141,8 @@ class Logger extends Writable { | |
| this.inactivityTimeout = opts.inactivityTimeout || defaults.inactivityTimeout; | ||
| this.disableTimeout = opts.disableTimeout; | ||
| this.token = opts.token; | ||
| this.reconnectFailed = false; | ||
| this.reconnectFailAfter = opts.reconnectFailAfter || defaults.reconnectFailAfter; | ||
| this.reconnectInitialDelay = opts.reconnectInitialDelay || defaults.reconnectInitialDelay; | ||
| this.reconnectMaxDelay = opts.reconnectMaxDelay || defaults.reconnectMaxDelay; | ||
| this.reconnectBackoffStrategy = | ||
|
|
@@ -187,6 +190,7 @@ class Logger extends Writable { | |
| this.on(bufferDrainEvent, () => { | ||
| this.debugLogger.log('RingBuffer drained.'); | ||
| this.drained = true; | ||
| this.reconnectFailed = false; | ||
| }); | ||
|
|
||
| this.on(timeoutEvent, () => { | ||
|
|
@@ -211,6 +215,21 @@ class Logger extends Writable { | |
| */ | ||
| _write(ch, enc, cb) { | ||
| this.drained = false; | ||
|
|
||
| if (this.reconnectFailed) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are we trying to accomplish with this check? |
||
| this.ringBuffer.read(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are losing an event here, aren't we? |
||
|
|
||
| if (this.ringBuffer.isEmpty()) { | ||
| this.emit(bufferDrainEvent); | ||
| // this event is DEPRECATED - will be removed in next major release. | ||
| // new users should use 'buffer drain' event instead. | ||
| this.emit('connection drain'); | ||
| } | ||
|
|
||
| cb(); | ||
| return; | ||
| } | ||
|
|
||
| this.connection.then(conn => { | ||
| const record = this.ringBuffer.read(); | ||
| if (record) { | ||
|
|
@@ -233,8 +252,15 @@ class Logger extends Writable { | |
| } | ||
| cb(); | ||
| }).catch(err => { | ||
| this.emit(errorEvent, err); | ||
| this.debugLogger.log(`Error: ${err}`); | ||
| if (err instanceof ReconnectFailedError) { | ||
| this.ringBuffer.read(); // this connection failed, shift the buffer | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are losing an event here. read() will return the ext event in the buffer by shifting it. |
||
| this.reconnectFailed = true; | ||
| this.debugLogger.log('Error: Reconnect failed'); | ||
| } else { | ||
| this.emit(errorEvent, err); | ||
| this.debugLogger.log(`Error: ${err}`); | ||
| } | ||
|
|
||
| cb(); | ||
| }); | ||
| } | ||
|
|
@@ -413,12 +439,12 @@ class Logger extends Writable { | |
| initialDelay: this.reconnectInitialDelay, | ||
| maxDelay: this.reconnectMaxDelay, | ||
| strategy: this.reconnectBackoffStrategy, | ||
| failAfter: Infinity, | ||
| failAfter: this.reconnectFailAfter, | ||
| randomisationFactor: 0, | ||
| immediate: false | ||
| }); | ||
|
|
||
| this.connection = new Promise((resolve) => { | ||
| this.connection = new Promise((resolve, reject) => { | ||
| const connOpts = { | ||
| host: this.host, | ||
| port: this.port | ||
|
|
@@ -442,6 +468,10 @@ class Logger extends Writable { | |
| } | ||
| }); | ||
|
|
||
| this.reconnection.once('fail', () => { | ||
| reject(new ReconnectFailedError()); | ||
| }); | ||
|
|
||
| this.reconnection.once('disconnect', () => { | ||
| this.debugLogger.log('Socket was disconnected'); | ||
| this.connection = null; | ||
|
|
@@ -579,6 +609,14 @@ class Logger extends Writable { | |
| this._json = val; | ||
| } | ||
|
|
||
| get reconnectFailed() { | ||
| return this._reconnectFailed; | ||
| } | ||
|
|
||
| set reconnectFailed(val) { | ||
| this._reconnectFailed = val; | ||
| } | ||
|
|
||
| get reconnectMaxDelay() { | ||
| return this._reconnectMaxDelay; | ||
| } | ||
|
|
@@ -595,6 +633,14 @@ class Logger extends Writable { | |
| this._reconnectInitialDelay = val; | ||
| } | ||
|
|
||
| get reconnectFailAfter() { | ||
| return this._reconnectFailAfter; | ||
| } | ||
|
|
||
| set reconnectFailAfter(val) { | ||
| this._reconnectFailAfter = val; | ||
| } | ||
|
|
||
| get reconnectBackoffStrategy() { | ||
| return this._reconnectBackoffStrategy; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,11 @@ class RingBuffer extends EventEmitter { | |
| return this.records.shift(); | ||
| } | ||
|
|
||
| empty() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see the place we use this function. |
||
| this.bufferWasFull = false; | ||
| this.records = []; | ||
| } | ||
|
|
||
| isEmpty() { | ||
| return this.records.length === 0; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this change for along with the new entry on gobblefile.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is related to:
src/error.jshere:
ReconnectFailedError extends LogentriesErrorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no better way doing this? without introducing a new dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have
babel-preset-es2015which includesbabel-plugin-transform-es2015-classes.This last one supports partially and it recommends to use
babel-plugin-transform-builtin-extendwhich also have limitations.I am not sure.