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

[#674, #675] Mitigate performance regression by filtering restricted registry collections #680

Merged
merged 4 commits into from
Jul 6, 2021

Conversation

pavel-lexyr
Copy link
Contributor

#675 introduces a significant performance regression in restricted registry collecting. This attempts to reduce the regression by re-introducing filter code removed in the previous version.

@pavel-lexyr
Copy link
Contributor Author

py2.7 passes locally. What do the logs say on the CI?

@csmarchbanks
Copy link
Member

csmarchbanks commented Jul 1, 2021

==================================== ERRORS ====================================
_____________________ ERROR collecting tests/test_core.py ______________________
ImportError while importing test module '/home/circleci/project/tests/test_core.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_core.py:5: in <module>
    from unittest.mock import MagicMock
E   ImportError: No module named mock

You can use a skipIf and import the mock only for the test such as done in https://github.com/prometheus/client_python/blob/master/tests/openmetrics/test_parser.py#L492.

Signed-off-by: Pavel <pavel@lexyr.com>
@pavel-lexyr
Copy link
Contributor Author

Aha. That worked - thank you!

Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

This approach looks good to me, and I appreciate the test you added. I will give some time for @brian-brazil to review as well.

m = metric._restricted_metric(self._name_set)
if m:
yield m
names = copy.copy(self._name_set)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

collectors = set()
with self._registry._lock:
if 'target_info' in names and self._registry._target_info:
yield self._registry._target_info_metric()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is safe to yield under the lock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Good catch!

Signed-off-by: Pavel <pavel@lexyr.com>
with self._registry._lock:
if 'target_info' in names and self._registry._target_info:
yield_target_info = True
names.remove('target_info')
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I understood it right - but done.

yield m
names = copy.copy(self._name_set)
collectors = set()
yield_target_info = False
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: Pavel <pavel@lexyr.com>
@brian-brazil
Copy link
Contributor

👍

@pavel-lexyr pavel-lexyr requested a review from csmarchbanks July 5, 2021 15:40
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

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

Thanks for the additional review and fixes!

@csmarchbanks csmarchbanks merged commit c49e55a into prometheus:master Jul 6, 2021
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