-
Notifications
You must be signed in to change notification settings - Fork 815
Refactoring and metric wrapper unification #313
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
Conversation
Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
…n core) Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
…s to allow for that) Signed-off-by: Aarni Koskela <akx@iki.fi>
Also gets rid of the LabelWrapper class; all top-level metric classes can now act in both labeled and unlabeled modes Fixes prometheus#210 Signed-off-by: Aarni Koskela <akx@iki.fi>
Signed-off-by: Aarni Koskela <akx@iki.fi>
I'm in the middle of adding various openmetrics-related stuff, so I'll look at this properly once that's all released. One question from a quick peek is why you need two classes to replace label wrapper. |
With this class structure, one can do g = Gauge(..., ['label1', 'label2'])
g.labels('v1', 'v2').set(123) but g = Gauge(..., ['label1', 'label2'])
g.labels('v1', 'v2').labels('v3', 'v4').set(123) is impossible, since If we want to allow |
Hmm, I'm seeing deadlocks in multiproc mode in the GC collector (which is actually understandable, since GC callbacks could get triggered at any point) with this PR. @brian-brazil, do you think changing Haven't yet tested whether |
I suspect it does have the same problem. @tcolgate |
Nope, just reproed it with 0.4.0. Opening a ticket. |
Closing as superseded by #344. |
This PR does a couple things. (If you want, I can split these into separate PRs.)
🔧 Firstly, it refactors the 1200+-line
core.py
into separate modules for each functionality. This does not affect imports for client code; all the sameprometheus_client
-provided non-underscored names are re-exported from that file. Some previously underscored names were brought into the light.✨ Secondly (and this is what prompted me to really do this work), it fixes #210 by removing the factory function magic decorator
MetricWrapper
; as it was before, say, an invocationGauge(...)
could either return aGauge
object, as you'd expect, or a_LabelWrapper
if you'd passed in a list of label names. This tripped up code completion (and tbqh, me :) ) and static analysis.Instead, the six metric wrappers (Counter, Enum, Gauge, Histogram, Info, Summary) are now plain old classes (though with a slightly arcane diamond-shaped inheritance hierarchy that lets them be used both with and without
.labels()
).👓 Thirdly, there was a mostly mechanical
autopep8
pass to placatetox flake8
errors. (That check isn't run by CI, it seems?)No test code was changed for this (aside from the removal of the
__wrapped__
attribute as there is nothing to wrap anymore), so I would say this is backwards API compatible (with the exception of client code that might have done checks likeisinstance(x, _LabelWrapper)
).I'm glad to answer any questions and/or modify things as needed! :)