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.
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.
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.
Curious, what's the difference with def __init__(self, func, interval=DEFAULT_INTERVAL, **kwargs)?
There was a problem hiding this comment.
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.
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.
| pass | ||
|
|
||
|
|
||
| class PeriodicTask(threading.Thread): |
There was a problem hiding this comment.
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.
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.
This PR changes
StackdriverStatsExporterto 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_metricsand 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 exposingStatsas a singleton viastats.stats.Fixes #583 by exporting less frequently than the stackdriver minimum sampling period.
Fixes #470 by replacing
ViewDatawith metrics objects that are created on the fly.Addresses #454, which we can close after making the same changes to the prometheus exporter.