Skip to content
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

Merged
merged 10 commits into from Jun 3, 2019

Conversation

majorgreys
Copy link
Collaborator

@majorgreys majorgreys commented May 15, 2019

  • Fixes shutdown of runtime workers and add test
  • Avoid unnecessary setting services

@majorgreys majorgreys requested a review from a team as a code owner May 15, 2019 15:41
ddtrace/tracer.py Outdated Show resolved Hide resolved
@@ -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()
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

# update set of services handled by tracer
if service:
if service and service not in self._services:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Noticed by looking at logs that we were updating self._services and constant tags with each span, which is definitely overkill. So added this membership test before adding a service.

@majorgreys majorgreys force-pushed the majorgreys/runtime-tag-fix branch 2 times, most recently from e898373 to 36161f3 Compare May 16, 2019 17:59
Copy link
Contributor

@jd jd left a comment

Choose a reason for hiding this comment

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

I really wish you wrote a commit message / PR description because I've no idea what this fixes (except the periodic call) :)

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Member

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:

class Tracer:
    def configure(self, ... _runtime_flush_interval=10):
        pass

This is what we are doing that required us to make this change:

default_flush_interval = RuntimeWorker.FLUSH_INTERVAL
try:
# lower flush interval
RuntimeWorker.FLUSH_INTERVAL = 1/4
# configure tracer for runtime metrics
self.tracer.configure(collect_metrics=True)
finally:
# reset flush interval
RuntimeWorker.FLUSH_INTERVAL = default_flush_interval

Copy link
Contributor

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.

Copy link
Member

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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

🤦‍♂

I guess the tests passed because we call flush manually?

Copy link
Member

Choose a reason for hiding this comment

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

yeah, we call flush on stop()

Copy link
Member

Choose a reason for hiding this comment

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

or join or w/e

@majorgreys majorgreys added this to the 0.26.0 milestone Jun 3, 2019
@majorgreys majorgreys changed the title Fix runtime tags in Dogstatsd Fix runtime workers not flushing to Dogstatsd Jun 3, 2019
@majorgreys majorgreys merged commit d0a6f51 into master Jun 3, 2019
@majorgreys majorgreys deleted the majorgreys/runtime-tag-fix branch June 3, 2019 16:26
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.

None yet

3 participants