-
Notifications
You must be signed in to change notification settings - Fork 11
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
base: master
Are you sure you want to change the base?
Conversation
.gitignore
Outdated
@@ -0,0 +1 @@ | |||
.vscode |
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.
Nope.
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) { |
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.
Please pass now
here as well. Getting the current time isn't always free.
meter.go
Outdated
String() string | ||
Mark(count uint64) | ||
Snapshot() Snapshot | ||
Reset() |
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'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).
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.
Can't drop Snapshot()
because it's used in MeterRegistry.walkIdle()
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 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?
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.
@Stebalien Gentle reminder, can you, please, check my last commit and say if it's fine with you?
As it was proposed in issue#23 I have modified the code to allow user to customize the metrics calculation.
Major changes:
meter
struct calledMeterInterface
meter
toMeterInterface
sweeper.update()
toMeterInterface.Update()
. Nowsweeper.update()
only callsMeterInterface.Update()
in a loopMinor changes:
approxEq
of with==
, so for consistency I have changed all comparisons toapproxEq