Skip to content
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

Merged
merged 3 commits into from
Mar 9, 2021

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Mar 9, 2021

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)


@vasco-santos vasco-santos force-pushed the fix/conn-mgr-access-to-moving-averages-object branch from 30dda0e to b993194 Compare March 9, 2021 11:50
@vasco-santos vasco-santos force-pushed the fix/conn-mgr-access-to-moving-averages-object branch from 003b93b to 0cd432c Compare March 9, 2021 14:11
Copy link
Member

@achingbrain achingbrain left a 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]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
node: [14]
node: [14, 15]

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

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}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @returns {Object}

Maybe just let the compiler infer the return type? (see comment about shallow cloning below)

@vasco-santos vasco-santos merged commit 5f702f3 into master Mar 9, 2021
@vasco-santos vasco-santos deleted the fix/conn-mgr-access-to-moving-averages-object branch March 9, 2021 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants