-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: conn mgr access to moving averages record object #897
fix: conn mgr access to moving averages record object #897
Conversation
30dda0e
to
b993194
Compare
003b93b
to
0cd432c
Compare
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.
Fine as a quick fix but some suggestions are inline
@@ -27,7 +27,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [windows-latest, ubuntu-latest, macos-latest] | |||
node: [12, 14] | |||
node: [14] |
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.
node: [14] | |
node: [14, 15] |
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.
15 is blocked by #857
@@ -82,7 +82,7 @@ class Stats extends EventEmitter { | |||
/** | |||
* Returns a clone of the internal movingAverages | |||
* | |||
* @returns {MovingAverage} | |||
* @returns {Object} | |||
*/ | |||
get movingAverages () { | |||
return Object.assign({}, this._movingAverages) |
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.
This is just a shallow clone, it doesn't prevent deep values being modified by the caller - if we care about that we should manually create a copy. If we don't we should just return this._movingAverages
.
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.
I think we do not want to allow changes. I will create an issue for this
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.
@@ -82,7 +82,7 @@ class Stats extends EventEmitter { | |||
/** | |||
* Returns a clone of the internal movingAverages | |||
* | |||
* @returns {MovingAverage} | |||
* @returns {Object} |
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.
* @returns {Object} |
Maybe just let the compiler infer the return type? (see comment about shallow cloning below)
This PR fixes the connection manager access to the
movingAverages
getter. After the module update with types, this broke libp2p's build.It returns an Object as we can see on:
This object contains a key for the metric and another object as value to create multiple intervals for computing the move average:
movingAverages[key][interval].movingAverage()
=> This is the actual MovingAverage instance.Metrics is not a public API and is not properly typed for now, the work is being tracked on #830 . We should probably change this from an Object to a Map and properly type these moving averages record, but just fixing the bug here.
Per #896 (comment)