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

[dns_check] change to network check #2924

Merged
merged 3 commits into from
Nov 17, 2016
Merged

Conversation

sjenriquez
Copy link
Contributor

What does this PR do?

Changes the DNS check to a network type check that allows instances to run in separate threads.

Motivation

Per customer request.

Additional Notes

Will affect this open PR: #2799

Copy link
Contributor

@remh remh left a comment

Choose a reason for hiding this comment

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

That's a great first pass.

What happens if someone doesn't pass a name to its configuration ?

def __init__(self, name, init_config, agentConfig, instances=None):
AgentCheck.__init__(self, name, init_config, agentConfig, instances)
self.default_timeout = init_config.get('default_timeout', self.DEFAULT_TIMEOUT)
def __init__(self, name, init_config, agentConfig, instances):
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove the constructor entirely if you are just calling the parent constructor

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 did this to set the default_timeout when configured in init_config. network.py only passes instance to _check(), not init_config.
https://github.com/DataDog/dd-agent/blob/master/checks/network_checks.py#L138

Is there a better way to set default_timeout when configured in the yaml file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point

# Fetches the conf
try:
hostname = instance.get('hostname')
except Exception:
Copy link
Contributor

Choose a reason for hiding this comment

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

instance.get('hostname')

cannot return an exception.
Better to do something like

def _load_conf(self, instance):
    hostname = instance.get('hostname')
    if not hostname:
        raise BadConfException('A valid "hostname" must be specified')
    ...

hostname, timeout, nameserver, record_type, resolver = self._load_conf(instance)

# Perform the DNS query, and report its duration as a gauge
start_time = end_time = 0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to declare them, as you are declaring them a few lines later

if end_time - start_time > 0:
self.gauge('dns.response_time', end_time - start_time, tags=tags)
self.service_check(self.SERVICE_CHECK_NAME, AgentCheck.OK, tags=self._get_tags(instance))
self.gauge('dns.response_time', end_time - start_time, tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

better to keep the keyword argument tags=tags


def _get_tags(self, instance):
instance_name = instance.get('name')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think people upgrading from a previous version won't have a name so we should default to the hostname

def report_as_service_check(self, sc_name, status, instance, msg=None):
tags = self._get_tags(instance)

# FIXME: 5.3, Setting skip_event True here to hide deprecated option in yaml.
Copy link
Contributor

Choose a reason for hiding this comment

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

Outdated comment

@sjenriquez
Copy link
Contributor Author

When a name isn't passed this Exception in network.py is raised:
https://github.com/DataDog/dd-agent/blob/master/checks/network_checks.py#L79-L80

@olivielpeau olivielpeau modified the milestones: 5.10.0, Triage Oct 21, 2016
@olivielpeau
Copy link
Member

Moving this PR to Triage since it's not a blocker for 5.10 but feel free to merge it whenever it's ready, I'll update the milestone accordingly

@remh remh modified the milestones: 5.10.0, Triage Oct 26, 2016
@remh
Copy link
Contributor

remh commented Oct 26, 2016

@sjenriquez Then this will break compatibility for current users of the DNS check, if they upgrade their agent, the check will break. Can you fix that please ?

@olivielpeau olivielpeau modified the milestones: 5.11.0, 5.10.0 Oct 27, 2016
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.

4 participants