-
Notifications
You must be signed in to change notification settings - Fork 250
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
Stackdriver poll-based metrics #593
Conversation
contrib/opencensus-ext-stackdriver/opencensus/ext/stackdriver/stats_exporter/__init__.py
Outdated
Show resolved
Hide resolved
@@ -402,21 +363,34 @@ def get_user_agent_slug(): | |||
return "opencensus-python/{}".format(__version__) |
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.
Curious (although it is not added by this PR) - which version do we want here (opencensus or ext package or both)?
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.
The other clients report the core library version, but I think there's a good argument for replacing this with just the ext version.
|
||
def __init__(self, func, interval=None, **kwargs): | ||
super(PeriodicTask, self).__init__(**kwargs) | ||
if interval is None: |
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.
Curious, what's the difference with def __init__(self, func, interval=DEFAULT_INTERVAL, **kwargs)
?
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.
Just that it makes it easy to make the same argument optional in the calling func.
interval
comes all the way from stackdriver.stats_exporter.new_stats_exporter
, if we used DEFAULT_INTERVAL
here we'd have to either have to use it as the default value in the callers (which means importing it in other modules) or make two separate calls, e.g.
def caller_in_another_module(interval=None):
...
if interval is None:
task = PeriodicTask()
else:
task = PeriodicTask(interval=interval)
Using None
everywhere is convenient, but there are a few big drawbacks: it's less readable since you can't tell the defaults by looking at the signature, you can't change the default value to something other than None
without changing all the callers too, and it doesn't work for arguments that can actually have None
as their value.
I'm on the fence here, if you have an opinion on this I'm happy to change it.
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.
I don't have strong opinion here. Just observed that using None is a common pattern: https://docs.python-guide.org/writing/gotchas/. Feel free to make your call.
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.
LGTM.
pass | ||
|
||
|
||
class PeriodicTask(threading.Thread): |
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.
This could be useful for other exporters (e.g. trace exporters), please consider putting it in opencensus.common
.
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.
For trace exporters we want a queue that periodically exports batches of spans. It's possible that we'd reuse this, but I think we ought to move it when we do instead of now.
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.
Make sense.
This PR changes
StackdriverStatsExporter
to use metrics data models internally, and switches from a push-based export model (export on each call torecord
) to a poll-based one (periodically callstats.get_metrics
and export the results). It also allows the stackdriver exporter to export gauge metrics. It includes the changes from #560 and #577.This PR includes multiple breaking behavior and API changes, including starting (and now returning) a background thread from
stats_exporter.new_stats_exporter
, and exposingStats
as a singleton viastats.stats
.Fixes #583 by exporting less frequently than the stackdriver minimum sampling period.
Fixes #470 by replacing
ViewData
with metrics objects that are created on the fly.Addresses #454, which we can close after making the same changes to the prometheus exporter.