-
Notifications
You must be signed in to change notification settings - Fork 845
Deadlock on gcCollector #371
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c02a6fa
Fix deadlock in gc collector
Krukov 455b035
Skip gccolect test for python < 3
Krukov b72da86
Fix python 2.6 skipIf
Krukov 39a6362
Use bounds without INF and doubled threshold
Krukov 7589f93
Use gc.stats for gcCollector metrics
Krukov 9b12b4c
Allow multiprocess
7bf2cdf
Use the counter as gc metrics and rename metrics names
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,62 @@ | ||
| from __future__ import unicode_literals | ||
|
|
||
| import unittest | ||
| import gc | ||
| import sys | ||
|
|
||
| if sys.version_info < (2, 7): | ||
| # We need the skip decorators from unittest2 on Python 2.6. | ||
| import unittest2 as unittest | ||
| else: | ||
| import unittest | ||
|
|
||
| from prometheus_client import CollectorRegistry, GCCollector | ||
|
|
||
|
|
||
| @unittest.skipIf(sys.version_info < (3, 4), "Test requires Python 3.4 +") | ||
| class TestGCCollector(unittest.TestCase): | ||
| def setUp(self): | ||
| gc.disable() | ||
| gc.collect() | ||
| self.registry = CollectorRegistry() | ||
| self.gc = _MockGC() | ||
|
|
||
| def test_working(self): | ||
| collector = GCCollector(registry=self.registry, gc=self.gc) | ||
| self.gc.start_gc({'generation': 0}) | ||
| self.gc.stop_gc({'generation': 0, 'collected': 10, 'uncollectable': 2}) | ||
|
|
||
| self.assertEqual(1, | ||
| self.registry.get_sample_value( | ||
| 'python_gc_duration_seconds_count', | ||
| labels={"generation": "0"})) | ||
|
|
||
| self.assertEqual(1, | ||
| self.registry.get_sample_value( | ||
| 'python_gc_collected_objects_count', | ||
| labels={"generation": "0"})) | ||
|
|
||
| self.assertEqual(1, | ||
| self.registry.get_sample_value( | ||
| 'python_gc_uncollectable_objects_count', | ||
| labels={"generation": "0"})) | ||
|
|
||
| self.assertEqual(10, | ||
| self.registry.get_sample_value( | ||
| 'python_gc_collected_objects_sum', | ||
| labels={"generation": "0"})) | ||
|
|
||
| self.assertEqual(2, | ||
| GCCollector(registry=self.registry) | ||
| self.registry.collect() | ||
| before = self.registry.get_sample_value('python_gc_objects_collected_total', | ||
| labels={"generation": "0"}) | ||
|
|
||
| # add targets for gc | ||
| a = [] | ||
| a.append(a) | ||
| del a | ||
| b = [] | ||
| b.append(b) | ||
| del b | ||
|
|
||
| gc.collect(0) | ||
| self.registry.collect() | ||
|
|
||
| after = self.registry.get_sample_value('python_gc_objects_collected_total', | ||
| labels={"generation": "0"}) | ||
| self.assertEqual(2, after - before) | ||
| self.assertEqual(0, | ||
| self.registry.get_sample_value( | ||
| 'python_gc_uncollectable_objects_sum', | ||
| 'python_gc_objects_uncollectable_total', | ||
| labels={"generation": "0"})) | ||
|
|
||
| def test_empty(self): | ||
|
|
||
| class _MockGC(object): | ||
| def __init__(self): | ||
| self.callbacks = [] | ||
| GCCollector(registry=self.registry) | ||
| self.registry.collect() | ||
| before = self.registry.get_sample_value('python_gc_objects_collected_total', | ||
| labels={"generation": "0"}) | ||
| gc.collect(0) | ||
| self.registry.collect() | ||
|
|
||
| def start_gc(self, info): | ||
| for cb in self.callbacks: | ||
| cb('start', info) | ||
| after = self.registry.get_sample_value('python_gc_objects_collected_total', | ||
| labels={"generation": "0"}) | ||
| self.assertEqual(0, after - before) | ||
|
|
||
| def stop_gc(self, info): | ||
| for cb in self.callbacks: | ||
| cb('stop', info) | ||
| def tearDown(self): | ||
| gc.enable() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Counters should end in _total
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.
CounterMetricFamilywill add it autocratically. You can see it in tests https://github.com/prometheus/client_python/pull/371/files#diff-b8616fecc6de945cdf630d3ad09aebb8R26There 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.
Ah yes, I'd forgotten I'd already added that.