-
Notifications
You must be signed in to change notification settings - Fork 814
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
[service_discovery][jmx] trying to pick-up JMX changes with SD. #3010
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
951b291
[service_discovery][jmx] trying to pick-up JMX changes with SD.
truthbk 316cf62
[service_discovery][jmx] enable auto-conf for JMX checks.
truthbk 9cc3762
[service_discovery][jmx] some cleanup.
truthbk 779f58d
[service_discovery][jmx] refactor config. Default pipe location to /o…
truthbk 51808fa
[service_discovery][jmx] adding JMX YAML generation test.
truthbk aec4d71
[service_discovery][jmx] empty result set if configs not retrievable.
truthbk 809494b
[service_discovery][tests][skip ci] unneccessary noqa.
truthbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,6 @@ embedded/* | |
dump.rdb | ||
tests/core/fixtures/flare/dd* | ||
.python-version | ||
.ropeproject | ||
.bundle | ||
tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
from urlparse import urlparse | ||
|
||
# project | ||
from util import check_yaml | ||
from util import check_yaml, config_to_yaml | ||
from utils.platform import Platform, get_os | ||
from utils.proxy import get_proxy | ||
from utils.service_discovery.config import extract_agent_config | ||
|
@@ -42,6 +42,9 @@ | |
DEFAULT_CHECK_FREQUENCY = 15 # seconds | ||
LOGGING_MAX_BYTES = 10 * 1024 * 1024 | ||
SDK_INTEGRATIONS_DIR = 'integrations' | ||
SD_PIPE_NAME = "dd-service_discovery" | ||
SD_PIPE_UNIX_PATH = '/opt/datadog-agent/run' | ||
SD_PIPE_WIN_PATH = "\\\\.\\pipe\\{pipename}" | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
@@ -72,6 +75,8 @@ | |
"app.datad0g.com", | ||
] | ||
|
||
JMX_SD_CONF_TEMPLATE = '.jmx.{}.yaml' | ||
|
||
|
||
class PathNotFound(Exception): | ||
pass | ||
|
@@ -376,7 +381,6 @@ def get_config(parse_args=True, cfg_path=None, options=None): | |
if options is not None and options.profile: | ||
agentConfig['developer_mode'] = True | ||
|
||
# | ||
# Core config | ||
#ap | ||
if not config.has_option('Main', 'api_key'): | ||
|
@@ -743,6 +747,16 @@ def get_sdk_integrations_path(osname=None): | |
return path | ||
raise PathNotFound(path) | ||
|
||
def get_jmx_pipe_path(): | ||
if Platform.is_windows(): | ||
pipe_path = SD_PIPE_WIN_PATH | ||
else: | ||
pipe_path = SD_PIPE_UNIX_PATH | ||
if not os.path.isdir(pipe_path): | ||
pipe_path = '/tmp' | ||
|
||
return pipe_path | ||
|
||
|
||
def get_auto_confd_path(osname=None): | ||
"""Used for service discovery which only works for Unix""" | ||
|
@@ -873,6 +887,7 @@ def _service_disco_configs(agentConfig): | |
service_disco_configs = sd_backend.get_configs() | ||
except Exception: | ||
log.exception("Loading service discovery configurations failed.") | ||
return {} | ||
else: | ||
service_disco_configs = {} | ||
|
||
|
@@ -997,6 +1012,7 @@ def load_check_directory(agentConfig, hostname): | |
initialize. Only checks that have a configuration | ||
file in conf.d will be returned. ''' | ||
from checks import AGENT_METRICS_CHECK_NAME | ||
from jmxfetch import JMX_CHECKS | ||
|
||
initialized_checks = {} | ||
init_failed_checks = {} | ||
|
@@ -1035,7 +1051,9 @@ def load_check_directory(agentConfig, hostname): | |
|
||
for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems(): | ||
# ignore this config from service disco if the check has been loaded through a file config | ||
if check_name in initialized_checks or check_name in init_failed_checks: | ||
if check_name in initialized_checks or \ | ||
check_name in init_failed_checks or \ | ||
check_name in JMX_CHECKS: | ||
continue | ||
|
||
sd_init_config, sd_instances = service_disco_check_config[1] | ||
|
@@ -1065,12 +1083,14 @@ def load_check_directory(agentConfig, hostname): | |
|
||
def load_check(agentConfig, hostname, checkname): | ||
"""Same logic as load_check_directory except it loads one specific check""" | ||
from jmxfetch import JMX_CHECKS | ||
|
||
agentConfig['checksd_hostname'] = hostname | ||
osname = get_os() | ||
checks_places = get_checks_places(osname, agentConfig) | ||
for config_path in _file_configs_paths(osname, agentConfig): | ||
check_name = _conf_path_to_check_name(config_path) | ||
if check_name == checkname: | ||
if check_name == checkname and check_name not in JMX_CHECKS: | ||
conf_is_valid, check_config, invalid_check = _load_file_config(config_path, check_name, agentConfig) | ||
|
||
if invalid_check and not conf_is_valid: | ||
|
@@ -1092,6 +1112,35 @@ def load_check(agentConfig, hostname, checkname): | |
|
||
return None | ||
|
||
def generate_jmx_configs(agentConfig, hostname, checknames=None): | ||
"""Similar logic to load_check_directory for JMX checks""" | ||
from jmxfetch import JMX_CHECKS | ||
|
||
if not checknames: | ||
checknames = JMX_CHECKS | ||
agentConfig['checksd_hostname'] = hostname | ||
|
||
# the check was not found, try with service discovery | ||
generated = {} | ||
for check_name, service_disco_check_config in _service_disco_configs(agentConfig).iteritems(): | ||
if check_name in checknames and check_name in JMX_CHECKS: | ||
log.debug('Generating JMX config for: %s' % check_name) | ||
|
||
sd_init_config, sd_instances = service_disco_check_config | ||
|
||
check_config = {'init_config': sd_init_config, | ||
'instances': sd_instances} | ||
|
||
try: | ||
yaml = config_to_yaml(check_config) | ||
# generated["{}_{}".format(check_name, idx)] = yaml | ||
generated["{}_{}".format(check_name, 0)] = yaml | ||
log.debug("YAML generated: %s", yaml) | ||
except Exception: | ||
log.exception("Unable to generate YAML config for %s", check_name) | ||
|
||
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. except:
log.exception("Unable to generate YAML config for %s", check_name) 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. good catch! |
||
return generated | ||
|
||
# | ||
# logging | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what's the
_0
for?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.
So this was actually a product of an original misunderstanding on my part. But then I saw some utility for it (although I have to take another look at this code) - for example simultaneous containers for the same service, but with different tags or whatever, that could have different configurations. On the JMX side we'd use the check name as the key in the map, so this would allow us to support that in the future, that's why we have the commented line on the top. We can discuss and possibly remove.