-
Notifications
You must be signed in to change notification settings - Fork 801
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
[#674, #675] Mitigate performance regression by filtering restricted registry collections #680
Changes from 3 commits
009d885
9268e8d
9398980
0e9367d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,10 +135,23 @@ def __init__(self, names, registry): | |
self._registry = registry | ||
|
||
def collect(self): | ||
for metric in self._registry.collect(): | ||
m = metric._restricted_metric(self._name_set) | ||
if m: | ||
yield m | ||
names = copy.copy(self._name_set) | ||
collectors = set() | ||
yield_target_info = False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd have this as the thing to yield, rather than a bool for cleanliness. Also avoids a race. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
with self._registry._lock: | ||
if 'target_info' in names and self._registry._target_info: | ||
yield_target_info = True | ||
names.remove('target_info') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this, the registry should be preventing this from happening in the first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I understood it right - but done. |
||
for name in names: | ||
if name in self._registry._names_to_collectors: | ||
collectors.add(self._registry._names_to_collectors[name]) | ||
if yield_target_info: | ||
yield self._registry._target_info_metric() | ||
for collector in collectors: | ||
for metric in collector.collect(): | ||
m = metric._restricted_metric(self._name_set) | ||
if m: | ||
yield m | ||
|
||
|
||
REGISTRY = CollectorRegistry(auto_describe=True) |
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.
Why is this copy here? This set shouldn't be changing after the object is instantiated.
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.
Trying to do it in the same way collections used to be filtered with target_info. There used to be a set variable that was modified if target_info was found - in order not to change the class field in the same way, we copy it to
names
.