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

chore(tracer): limit memory usage for extra services reports #7060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ddtrace/settings/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Config(object):
available and can be updated by users.
"""

_extra_services_queue = multiprocessing.Queue() # type: multiprocessing.Queue
_extra_services_queue = multiprocessing.Queue(512) # type: multiprocessing.Queue

class _HTTPServerConfig(object):
_error_statuses = "500-599" # type: str
Expand Down Expand Up @@ -422,12 +422,12 @@ def __getattr__(self, name):
return self._config[name]

def _add_extra_service(self, service_name: str) -> None:
from queue import Empty
from queue import Full

if service_name != self.service:
if self._remote_config_enabled and service_name != self.service:
try:
self._extra_services_queue.put_nowait(service_name)
except Empty: # nosec
except Full: # nosec
pass
except BaseException:
log.debug("unexpected failure with _add_extra_service", exc_info=True)
Expand Down
19 changes: 14 additions & 5 deletions tests/contrib/flask/test_flask_appsec.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,8 @@ def test_route():
)

def test_multiple_service_name(self):
import time

import flask

import ddtrace
Expand All @@ -936,8 +938,15 @@ def new_service(service_name):
ddtrace.Pin.override(flask.Flask, service=service_name, tracer=ddtrace.tracer)
return "Ok %s" % service_name, 200

self._aux_appsec_prepare_tracer()
resp = self.client.get("/new_service/awesome_test")
assert resp.status_code == 200
assert get_response_body(resp) == "Ok awesome_test"
assert "awesome_test" in ddtrace.config._get_extra_services()
with override_global_config(dict(_remote_config_enabled=True)):
self._aux_appsec_prepare_tracer()
assert ddtrace.config._remote_config_enabled
resp = self.client.get("/new_service/awesome_test")
assert resp.status_code == 200
assert get_response_body(resp) == "Ok awesome_test"
for _ in range(10):
time.sleep(1)
if "awesome_test" in ddtrace.config._get_extra_services():
break
else:
raise AssertionError("extra service not found")
Loading