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

[auto-discovery][jmx] send terminator after configs + fix execption handling #3426

Merged
merged 2 commits into from
Jul 11, 2017
Merged
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
22 changes: 14 additions & 8 deletions agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
JMX_GRACE_SECS = 2
SERVICE_DISCOVERY_PREFIX = 'SD-'
SD_CONFIG_SEP = "#### SERVICE-DISCOVERY ####\n"
SD_CONFIG_TERM = "#### SERVICE-DISCOVERY TERM ####\n"

DEFAULT_SUPERVISOR_SOCKET = '/opt/datadog-agent/run/datadog-supervisor.sock'
DEFAULT_COLLECTOR_PROFILE_INTERVAL = 20
Expand Down Expand Up @@ -440,18 +441,23 @@ def _submit_jmx_service_discovery(self, jmx_sd_configs):
log.debug("Unable to automatically start jmxfetch on Windows via supervisor.")

buffer = ""
for name, yaml in jmx_sd_configs.iteritems():
try:
names = []
try:
for name, yaml in jmx_sd_configs.iteritems():
buffer += SD_CONFIG_SEP
buffer += "# {}\n".format(name)
buffer += yaml
except Exception as e:
log.exception("unable to submit YAML via RPC: %s", e)
else:
log.info("JMX SD Config via named pip %s successfully.", name)
names.append(name)

if buffer:
os.write(self.sd_pipe, buffer)
if buffer:
# will block if len(buffer) > OS pipe buffer.
# JMX will unblock when it reads on the other end.
os.write(self.sd_pipe, buffer)
os.write(self.sd_pipe, SD_CONFIG_TERM)
except Exception as e:
log.exception("unable to submit YAML via pipe: %s", e)
else:
log.info("JMX SD Configs submitted via named pipe successfully: %s", names)

def _should_restart(self):
if time.time() - self.agent_start > self.restart_interval:
Expand Down