-
Notifications
You must be signed in to change notification settings - Fork 822
Discussion, improve CounterDataPoint.inc() critical path #1471
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
base: main
Are you sure you want to change the base?
Conversation
…ter.DataPointIgnoringExemplars, which can be used. Also makes Counter.DataPoint visible and reduces foodprint by making it static.
@fstab
|
yes, I agree |
I think that's a great idea 😄 |
there's also the concept that you should be able to get the best possible performance with this library 😄 |
@zeitlinger What about deprecating |
yes, sounds like the right way forward 😄 |
// says withoutExemplars they should stay disabled. | ||
boolean notTurnedOffWithinCode = | ||
builder == null || builder.exemplarsEnabled == null || builder.exemplarsEnabled; | ||
if (exemplarsEnabled && notTurnedOffWithinCode) { |
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.
if (exemplarsEnabled && notTurnedOffWithinCode) { | |
if (exemplarsEnabled && !Objects.equals(builder.exemplarsEnabled, false)) { |
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.
builder can't be null (adding NullAway is on my list...)
I think its better to address the Regarding the counter optimization, I think this code looks rather ugly and hurts a lot:
Better idea:
While
Would also return a |
sounds good 😄 |
@fstab, @dhoard, @tomwilkie, @zeitlinger
Thanks for the cool library. Its a pleasure to work with!
I was using it for a new project and started with placing own
LongAdder
in the code and expose via thecollect()
method. This way, I would I could manipulate it directly in the class implementing the service resulting in maximum performance. The code started to be come repetitive and add some point I realised that I am starting to implement something likeCounterDataPoint
again. To avoid this, I started digging into the code to see what the overhead would be.With a code like
counter.labelValues().inc(1)
there is a bit of indirection until we hitLongAdder
. However, there is already a faster path as the documentation inCounterDataPoint
describes:Looking deeper into the code there is a tiny bit more indirection, which could be avoided.
This patch is returning a specialised class in case the exemplars support is not enabled. The intended usage is:
The unit test run successfully, however I realise that its breaking with the concept that the configuration can override what is configured in the code. I am not sure whether this would be tolerable for that special case. If an SRE enables exemplars for further diagnosis, the application would crash completely. Not good. However, probably
The patch is still worth discussion and worth applying without propagating to use
Counter.DataPointIgnoringExemplars
class directly. This class can be private to avoid wrong usage. Which brings me to the class visibility ofCounter.DataPoint
.My IDE marks code with:
The problem is that it's used as type parameter in the main
Counter
class and therefor becomes visible. My recommendation would be to make this public, deprecate the interfaceCounterDataPoint
and mandate to useCounter.DataPoint
instead. That is painful and probably will not happen fast, however, it is a mismatch, sinceCounter
is a class that is not open for extension and the only one that will ever provide aCounterDataPoint
.The patch also removes two unnecessary boolean fields. If that makes sense, I can also extract that as a housekeeping PR.
Thoughts?