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

KSM add node tag for pods + override hostname #1000

Merged
merged 5 commits into from
Jan 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ env:
- TRAVIS_FLAVOR=kong FLAVOR_VERSION=0.9.0
- TRAVIS_FLAVOR=kube_dns FLAVOR_VERSION=0.1.0
- TRAVIS_FLAVOR=kubernetes
- TRAVIS_FLAVOR=kubernetes_state
- TRAVIS_FLAVOR=kyototycoon FLAVOR_VERSION=0.9.56
- TRAVIS_FLAVOR=lighttpd
- TRAVIS_FLAVOR=mcache FLAVOR_VERSION=1.4.22
Expand Down
1 change: 1 addition & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ test:
- rake ci:run[kafka]
- rake ci:run[docker_daemon]
- rake ci:run[kubernetes]
- rake ci:run[kubernetes_state]
- rake ci:run[cassandra_nodetool]
- rake ci:run[squid]
- bundle exec rake requirements
Expand Down
7 changes: 7 additions & 0 deletions kubernetes_state/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG - kubernetes_state

2.1.0 / Unreleased
==================
### Changes

* [IMPROVEMENT] Add the node label wherever the pod label is present [#1000][]
* [IMPROVEMENT] Override hostname with the node label if present [#1000][]

2.0.0 / 2018-01-10
==================
### Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

KubernetesState = kubernetes_state.KubernetesState

__version__ = "2.0.0"
__version__ = "2.1.0"

__all__ = ['kubernetes_state']
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ def __init__(self, name, init_config, agentConfig, instances=None):
'kube_job_status_start_time',
]

self.label_joins = {
'kube_pod_info': {
'label_to_match': 'pod',
'labels_to_get': ['node']
}
}

self.label_to_hostname = 'node'

def check(self, instance):
endpoint = instance.get('kube_state_url')
if endpoint is None:
Expand Down
2 changes: 1 addition & 1 deletion kubernetes_state/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"linux",
"mac_os"
],
"version": "2.0.0",
"version": "2.1.0",
"use_omnibus_reqs": true,
"public_title": "Datadog-Kubernetes State Integration",
"categories":["orchestration", "containers"],
Expand Down
30 changes: 26 additions & 4 deletions kubernetes_state/test/test_kubernetes_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
import mock
import os

# 3p
from nose.plugins.attrib import attr

# project
from tests.checks.common import AgentCheckTest

NAMESPACE = 'kubernetes_state'


class MockResponse:
"""
MockResponse is used to simulate the object requests.Response commonly returned by requests.get
Expand All @@ -29,6 +31,7 @@ def close(self):
pass


@attr(requires='kubernetes_state')
class TestKubernetesState(AgentCheckTest):
CHECK_NAME = 'kubernetes_state'

Expand Down Expand Up @@ -90,6 +93,16 @@ class TestKubernetesState(AgentCheckTest):
NAMESPACE + '.statefulset.replicas_updated',
]

TAGS = {
NAMESPACE + '.pod.ready': ['node:minikube'],
NAMESPACE + '.pod.scheduled': ['node:minikube']
}

HOSTNAMES = {
NAMESPACE + '.pod.ready': 'minikube',
NAMESPACE + '.pod.scheduled': 'minikube'
}

ZERO_METRICS = [
NAMESPACE + '.deployment.replicas_unavailable',
NAMESPACE + '.deployment.paused',
Expand Down Expand Up @@ -118,7 +131,8 @@ def test__update_kube_state_metrics(self, mock_poll):
}]
}

self.run_check(config)
# run check twice to have pod/node mapping
self.run_check_twice(config)

self.assertServiceCheck(NAMESPACE + '.node.ready', self.check.OK)
self.assertServiceCheck(NAMESPACE + '.node.out_of_disk', self.check.OK)
Expand All @@ -137,7 +151,14 @@ def test__update_kube_state_metrics(self, mock_poll):
tags=['namespace:default', 'pod:hello-1509998460-tzh8k']) # Unknown

for metric in self.METRICS:
self.assertMetric(metric)
self.assertMetric(
metric,
hostname=self.HOSTNAMES.get(metric, None)
)
tags = self.TAGS.get(metric, None)
if tags:
for tag in tags:
self.assertMetricTag(metric, tag)
if metric not in self.ZERO_METRICS:
self.assertMetricNotAllZeros(metric)

Expand All @@ -156,7 +177,8 @@ def test__update_kube_state_metrics_v040(self, mock_poll):
}]
}

self.run_check(config)
# run check twice to have pod/node mapping
self.run_check_twice(config)

self.assertServiceCheck(NAMESPACE + '.node.ready', self.check.OK)
self.assertServiceCheck(NAMESPACE + '.node.out_of_disk', self.check.OK)
Expand Down