-
Notifications
You must be signed in to change notification settings - Fork 420
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
Fix runtime workers not flushing to Dogstatsd #939
Changes from all commits
39e134c
1dea33a
11f0d6b
b2c74b9
144d10d
d8da5fe
b45c938
4c9949c
86a5ea3
37b3c9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,8 @@ class RuntimeWorker(_worker.PeriodicWorkerThread): | |
|
||
FLUSH_INTERVAL = 10 | ||
|
||
def __init__(self, statsd_client, flush_interval=FLUSH_INTERVAL): | ||
def __init__(self, statsd_client, flush_interval=None): | ||
flush_interval = self.FLUSH_INTERVAL if flush_interval is None else flush_interval | ||
super(RuntimeWorker, self).__init__(interval=flush_interval, | ||
name=self.__class__.__name__) | ||
self._statsd_client = statsd_client | ||
|
@@ -78,7 +79,7 @@ def flush(self): | |
for key, value in self._runtime_metrics: | ||
self._write_metric(key, value) | ||
|
||
on_periodic = flush | ||
run_periodic = flush | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤦♂ I guess the tests passed because we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or |
||
on_shutdown = flush | ||
|
||
def reset(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,8 @@ def __init__(self): | |
self._runtime_id = generate_runtime_id() | ||
self._runtime_worker = None | ||
self._dogstatsd_client = None | ||
self._dogstatsd_host = self.DEFAULT_HOSTNAME | ||
self._dogstatsd_port = self.DEFAULT_DOGSTATSD_PORT | ||
|
||
def get_call_context(self, *args, **kwargs): | ||
""" | ||
|
@@ -154,12 +156,11 @@ def configure(self, enabled=None, hostname=None, port=None, dogstatsd_host=None, | |
self._wrap_executor = wrap_executor | ||
|
||
if collect_metrics and self._runtime_worker is None: | ||
self._dogstatsd_host = dogstatsd_host or self._dogstatsd_host | ||
self._dogstatsd_port = dogstatsd_port or self._dogstatsd_port | ||
# start dogstatsd client if not already running | ||
if not self._dogstatsd_client: | ||
self._start_dogstatsd_client( | ||
dogstatsd_host or self.DEFAULT_HOSTNAME, | ||
dogstatsd_port or self.DEFAULT_DOGSTATSD_PORT, | ||
) | ||
self._start_dogstatsd_client() | ||
|
||
self._start_runtime_worker() | ||
|
||
|
@@ -271,18 +272,18 @@ def start_span(self, name, child_of=None, service=None, resource=None, span_type | |
# add it to the current context | ||
context.add_span(span) | ||
|
||
# check for new process if runtime metrics worker has already been started | ||
if self._runtime_worker: | ||
self._check_new_process() | ||
|
||
# update set of services handled by tracer | ||
if service: | ||
if service and service not in self._services: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed by looking at logs that we were updating |
||
self._services.add(service) | ||
|
||
# The constant tags for the dogstatsd client needs to updated with any new | ||
# service(s) that may have been added. | ||
self._update_dogstatsd_constant_tags() | ||
|
||
# check for new process if runtime metrics worker has already been started | ||
if self._runtime_worker: | ||
self._check_new_process() | ||
|
||
return span | ||
|
||
def _update_dogstatsd_constant_tags(self): | ||
|
@@ -299,12 +300,15 @@ def _update_dogstatsd_constant_tags(self): | |
log.debug('Updating constant tags {}'.format(tags)) | ||
self._dogstatsd_client.constant_tags = tags | ||
|
||
def _start_dogstatsd_client(self, host, port): | ||
def _start_dogstatsd_client(self): | ||
# start dogstatsd as client with constant tags | ||
log.debug('Starting DogStatsd on {}:{}'.format(host, port)) | ||
log.debug('Connecting to DogStatsd on {}:{}'.format( | ||
self._dogstatsd_host, | ||
self._dogstatsd_port | ||
)) | ||
self._dogstatsd_client = DogStatsd( | ||
host=host, | ||
port=port, | ||
host=self._dogstatsd_host, | ||
port=self._dogstatsd_port, | ||
) | ||
|
||
def _start_runtime_worker(self): | ||
|
@@ -330,6 +334,10 @@ def _check_new_process(self): | |
|
||
self._start_runtime_worker() | ||
|
||
# force an immediate update constant tags since we have reset services | ||
# and generated a new runtime id | ||
self._update_dogstatsd_constant_tags() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will run for every single trace being finished, is that what we want? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the major change for this PR right? Everything else looks like some organization work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be run whenever a new child process is forked. And, right, the other changes could be removed to keep this PR focused. |
||
|
||
def trace(self, name, service=None, resource=None, span_type=None): | ||
""" | ||
Return a span that will trace an operation called `name`. The context that created | ||
|
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.
why?
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.
We did this because we had trouble finding a way to override the flush interval in a test case.
This isn't ideal and should likely be refactored into something else.
Maybe:
This is what we are doing that required us to make this change:
dd-trace-py/tests/internal/runtime/test_runtime_metrics.py
Lines 53 to 62 in 144d10d
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.
Fair enough.
Yeah
configure
should allow to customize that ultimately.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.
yeah, I think the main think we wanted to test was end-to-end letting the tracer configure the runtime worker, did the right thing