Skip to content

Allow creating async instruments with either a callback function or generator #5

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 4 commits into from
Sep 24, 2021

Conversation

aabmass
Copy link

@aabmass aabmass commented Sep 21, 2021

See the docstring I added to Meter.create_observable_counter() for usage. This gives examples of collecting CPU time from /proc/stat

@aabmass aabmass force-pushed the callbacks_and_generators branch 4 times, most recently from 3998b9c to 657a071 Compare September 21, 2021 03:21
@ocelotl
Copy link
Owner

ocelotl commented Sep 23, 2021

Overall looks good, just please add test cases to ensure that the functionality is equivalent when a generator is used as a callback or when a function is ✌️

@aabmass aabmass force-pushed the callbacks_and_generators branch 2 times, most recently from 82d2f11 to f14aa76 Compare September 23, 2021 17:32
with self.assertLogs(level=ERROR):
list(observable_counter.callback())

def test_observable_counter_callback(self):
Copy link
Author

Choose a reason for hiding this comment

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

@ocelotl this test case shows the callback form working

return self.value == o.value and self.attributes == o.attributes


class TestCpuTimeIntegration(TestCase):
Copy link
Author

Choose a reason for hiding this comment

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

This test is basically the example code I put in the docstring above. Also shows the function callback form working

@ocelotl
Copy link
Owner

ocelotl commented Sep 24, 2021

@aabmass, please resolve conflicts so that we can merge this in the metrics API PR ✌️

@aabmass aabmass force-pushed the callbacks_and_generators branch from 0bc01e7 to 9ac4650 Compare September 24, 2021 14:17
@ocelotl ocelotl merged commit 97b7d6d into ocelotl:issue_1835 Sep 24, 2021
@aabmass aabmass deleted the callbacks_and_generators branch September 24, 2021 19:33
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.

2 participants