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

Enable customization of metrics calculation #26

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

ArtemVasilevMIPT
Copy link

As it was proposed in issue#23 I have modified the code to allow user to customize the metrics calculation.
Major changes:

  • Added new interface for meter struct called MeterInterface
  • Replaced all entries of meter to MeterInterface
  • Moved metrics calculation from sweeper.update() to MeterInterface.Update(). Now sweeper.update() only calls MeterInterface.Update() in a loop

Minor changes:

  • I have noticed that in tests float are compared either with approxEq of with ==, so for consistency I have changed all comparisons to approxEq

.gitignore Outdated
@@ -0,0 +1 @@
.vscode
Copy link
Contributor

Choose a reason for hiding this comment

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

Nope.

@Stebalien
Copy link
Member

This is a very large change and isn't obviously correct (it touches a lot of complex parallel code). I'll try to get to it eventually, it'll likely take a while.

meter.go Outdated
@@ -69,3 +94,85 @@ func (m *Meter) Reset() {
func (m *Meter) String() string {
return m.Snapshot().String()
}

func (m *Meter) Update(tdiff time.Duration) {
Copy link
Member

Choose a reason for hiding this comment

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

Please pass now here as well. Getting the current time isn't always free.

meter.go Outdated
Comment on lines 28 to 31
String() string
Mark(count uint64)
Snapshot() Snapshot
Reset()
Copy link
Member

Choose a reason for hiding this comment

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

I'd drop all of these from this interface and focus on what the sweeper requires. Different meter implementations will need different interfaces (e.g., different data in their snapshots).

Copy link
Author

Choose a reason for hiding this comment

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

Can't drop Snapshot() because it's used in MeterRegistry.walkIdle()

Copy link
Author

Choose a reason for hiding this comment

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

I ran some tests and discovered that my changes made the library incompatible with the current version of libp2p. Turns out that BandwidthCounter from libp2p uses method MeterRegistry.ForEach(). In my version this method accepts func(string, MeterInterface) but originally it accepts func(string, *Meter). I plan to explicitly specify the right version of MeterRegistry.ForEach() for compatibility with libp2p. Do you have better suggestions?

Copy link
Author

Choose a reason for hiding this comment

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

@Stebalien Gentle reminder, can you, please, check my last commit and say if it's fine with you?

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.

3 participants