Skip to content

Commit

Permalink
Merge pull request #2038 from DataDog/remh/k8s_fixes
Browse files Browse the repository at this point in the history
[kubernets] Kubelet check failing shouldn't stop metrics collection
  • Loading branch information
Remi Hakim committed Nov 3, 2015
2 parents 05d893b + d038ae5 commit 3baeb7d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
15 changes: 9 additions & 6 deletions checks.d/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def _perform_kubelet_checks(self, url):

except Exception, e:
self.log.warning('kubelet check failed: %s' % str(e))
self.service_check(service_check_base, AgentCheck.CRITICAL, 'Kubelet check failed: %s' % str(e))
raise
self.service_check(service_check_base, AgentCheck.CRITICAL,
message='Kubelet check failed: %s' % str(e))

def _perform_master_checks(self, url):
try:
Expand All @@ -104,12 +104,15 @@ def _perform_master_checks(self, url):
nodename = nodeinfo['name']
service_check_name = "{0}.master.{1}.check".format(NAMESPACE, nodename)
cond = nodeinfo['status'][-1]['type']
minion_name = nodeinfo['metadata']['name']
tags = ["minion_name:{0}".format(minion_name)]
if cond != 'Ready':
self.service_check(service_check_name, AgentCheck.CRITICAL, cond)
self.service_check(service_check_name, AgentCheck.CRITICAL,
tags=tags, message=cond)
else:
self.service_check(service_check_name, AgentCheck.OK)
self.service_check(service_check_name, AgentCheck.OK, tags=tags)
except Exception, e:
self.service_check(service_check_name, AgentCheck.CRITICAL, cond)
self.service_check(service_check_name, AgentCheck.CRITICAL, message=str(e))
self.log.warning('master checks url=%s exception=%s' % (url, str(e)))
raise

Expand Down Expand Up @@ -138,7 +141,7 @@ def check(self, instance):
if instance.get('enable_master_checks', False):
master_port = instance.get('master_port', DEFAULT_MASTER_PORT)
master_host = instance.get('master_host', 'localhost')
master_url = '%s://%s:%d/nodes' % (method, host, master_port)
master_url = '%s://%s:%d/api/v1/nodes' % (method, host, master_port)
self._perform_master_checks(master_url)

# kubelet health checks
Expand Down
2 changes: 1 addition & 1 deletion checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def service_check(self, check_name, status, tags=None, timestamp=None,
:param hostname: (optional) str, host that generated the service
check. Defaults to the host_name of the agent
:param check_run_id: (optional) int, id used for logging and tracing
purposes. Don't need to be unique. If not
purposes. Doesn't need to be unique. If not
specified, one will be generated.
"""
if hostname is None:
Expand Down
4 changes: 0 additions & 4 deletions conf.d/kubernetes.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ instances:
#
use_histogram: True
#
# Getting the master checks
# master_host: localhost
# master_port: 8080
#
# Kubelet checks
# enable_kubelet_checks: true
# kubelet_port: 10255
Expand Down
3 changes: 1 addition & 2 deletions tests/checks/mock/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def test_fail(self):
}

# Can't use run_check_twice due to specific metrics
with self.assertRaises(Exception):
self.run_check(config, mocks=mocks, force_reload=True)
self.run_check(config, mocks=mocks, force_reload=True)
self.assertServiceCheck("kubernetes.kubelet.check", status=AgentCheck.CRITICAL)
self.coverage_report()

Expand Down

0 comments on commit 3baeb7d

Please sign in to comment.