-
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
[Config] Update config logic to look for checks in 3rd-party directory #2273
Conversation
conf_exists = False | ||
try: | ||
thrird_party_path = get_3rd_party_path(osname) | ||
places.append(lambda name: os.path.join(thrird_party_path, name, 'check.py')) |
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.
typo third
For better coverage, how about a test for the case where the check class inherits from a subclass of |
if 'pythonpath' in check_config: | ||
pythonpath = check_config['pythonpath'] | ||
if not isinstance(pythonpath, list): | ||
pythonpath = [pythonpath] |
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.
Does it make sense to do some stricter checks here? For example [os.path.exists(path) for path in pythonpath]
? You probably know better whether that case should fail the initialization, print a warning, or do nothing at all
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.
I'd rather keep it safe leave the current logic untouched if you don't mind
4d1b088
to
4539088
Compare
import config as Config | ||
Config.get_checksd_path = self.patched_get_checksd_path | ||
Config.get_confd_path = self.patched_get_confd_path | ||
Config.get_3rd_party_path = self.patched_get_3rd_party_path |
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.
This pattern seems weird. Is it possible to use a MockConfig
object with the dummy methods, and then decorate at the class-level:
@patch.object(config, 'Config', MockConfig)
class TestConfigLoadCheckDirectory(unittest.TestCase):
Nice cleanup, long overdue! Left a few comments |
4539088
to
db66e08
Compare
@talwai thanks for the review, took your comments into account |
looks great 👍 |
Added a test on the deprecated nagios logic, and fix the logic for this case |
@tmichelet is this intended for 5.7? |
no @irabinovitch we'll release it as part of 5.8 |
# Look for the per-check config, which *must* exist | ||
if not check_config.get('instances'): | ||
log.error("Config %s is missing 'instances'" % config_path) | ||
return False, None, {} |
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.
Isn't this check already taken care of by the check_yaml
function?
There's one thing that's not handled anymore if I read through the code correctly: the For instance we use default confs for all the checks that are enabled by default ( Tests that should pass: def testConfigDefault(self, *args):
copyfile('%s/valid_conf.yaml' % FIXTURE_PATH,
'%s/test_check.yaml.default' % TEMP_ETC_CONF_DIR)
copyfile('%s/valid_check_1.py' % FIXTURE_PATH,
'%s/test_check.py' % TEMP_ETC_CHECKS_DIR)
checks = load_check_directory({"additional_checksd": TEMP_ETC_CHECKS_DIR}, "foo")
self.assertEquals(1, len(checks['initialized_checks']))
def testConfigCustomOverDefault(self, *args):
copyfile('%s/valid_conf.yaml' % FIXTURE_PATH,
'%s/test_check.yaml' % TEMP_ETC_CONF_DIR)
copyfile('%s/valid_conf_2.yaml' % FIXTURE_PATH, # a 2nd valid conf file, slightly different so that we can test which one has been picked up (with 2 instances for instance)
'%s/test_check.yaml.default' % TEMP_ETC_CONF_DIR)
copyfile('%s/valid_check_1.py' % FIXTURE_PATH,
'%s/test_check.py' % TEMP_ETC_CHECKS_DIR)
checks = load_check_directory({"additional_checksd": TEMP_ETC_CHECKS_DIR}, "foo")
self.assertEquals(1, len(checks['initialized_checks']))
self.assertEquals(1, checks['initialized_checks'][0].instance_count()) # check that we picked the right conf Apart from that it's a very welcome refactoring! 👍 |
Oh and FYI flake8 is complaining about |
@olivielpeau rebased on master, and added last two commits, could you have a second look please? |
|
||
|
||
TMP_DIR = tempfile.gettempdir() | ||
TEMP_3RD_PARTY_CHECKS_DIR = '%s/dd-agent-tests/3rd-party' % TMP_DIR |
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.
os.path.join(TMP_DIR, 'dd-agent-tests', '3rd-party')
would be slightly better here
(same thing for the 3 lines below)
One last nitpick, other than that feel free to squash and merge! |
@olivielpeau updated and squashed, can be merged I think |
- add tests on the config logic - refactor the logic - add some logic to add for checks in 3rd-party folder -- We are starting to install checks in the 3rd-party folder. Let the agent use these checks. Priority should be: - /etc/dd-agent/checks.d/ - /opt/datadog-agent/3rd-party/ - /opt/datadog-agent/agent/checks.d/
Needs a rebase |
Closing in favor of #2467 |
Logic tested on staging