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

[Config] Update config logic to look for checks in 3rd-party directory #2273

Closed
wants to merge 1 commit into from

Conversation

tmichelet
Copy link
Contributor

  • Add tests on config's logic
  • Refactor logic
  • Update logic to look for checks in 3rd-party directory

Logic tested on staging

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'))
Copy link
Contributor

Choose a reason for hiding this comment

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

typo third

@talwai
Copy link
Contributor

talwai commented Feb 19, 2016

For better coverage, how about a test for the case where the check class inherits from a subclass of AgentCheck? E.g. class SnmpCheck(NetworkCheck)

if 'pythonpath' in check_config:
pythonpath = check_config['pythonpath']
if not isinstance(pythonpath, list):
pythonpath = [pythonpath]
Copy link
Contributor

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

Copy link
Contributor Author

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

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

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):

@talwai
Copy link
Contributor

talwai commented Feb 19, 2016

Nice cleanup, long overdue! Left a few comments

@tmichelet
Copy link
Contributor Author

@talwai thanks for the review, took your comments into account

@talwai
Copy link
Contributor

talwai commented Feb 22, 2016

looks great 👍

@tmichelet
Copy link
Contributor Author

Added a test on the deprecated nagios logic, and fix the logic for this case

@irabinovitch
Copy link
Contributor

@tmichelet is this intended for 5.7?

@tmichelet
Copy link
Contributor Author

no @irabinovitch we'll release it as part of 5.8

@olivielpeau olivielpeau added this to the 5.8.0 milestone Feb 29, 2016
# 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, {}
Copy link
Member

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?

@olivielpeau olivielpeau self-assigned this Mar 16, 2016
@olivielpeau
Copy link
Member

There's one thing that's not handled anymore if I read through the code correctly: the .yaml.default files should also be taken into account (but should be ignored when a .yaml file is present for the same check).

For instance we use default confs for all the checks that are enabled by default (ntp, disk, network and agent_stats if I remember correctly).

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! 👍

@olivielpeau
Copy link
Member

Oh and FYI flake8 is complaining about tests/core/fixtures/checks/invalid_check_2.py:1:1: F401 'nothing' imported but unused, a # noqa should fix it

tmichelet added a commit that referenced this pull request Mar 24, 2016
tmichelet added a commit that referenced this pull request Mar 24, 2016
@tmichelet
Copy link
Contributor Author

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

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)

@olivielpeau
Copy link
Member

One last nitpick, other than that feel free to squash and merge!

tmichelet added a commit that referenced this pull request Apr 12, 2016
@tmichelet
Copy link
Contributor Author

@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/
@remh
Copy link

remh commented Apr 21, 2016

Needs a rebase

@olivielpeau
Copy link
Member

Closing in favor of #2467

@olivielpeau olivielpeau closed this May 4, 2016
@olivielpeau olivielpeau deleted the tristan/sdk branch June 1, 2016 14:40
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.

5 participants