-
Notifications
You must be signed in to change notification settings - Fork 816
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
Add ability to get docker IP address from Rancher labels for Rancher 1.3 #3265
Conversation
Nice one @zippolyte This way users will be able to graph their metrics based on rancher resources. |
@@ -171,6 +171,14 @@ def _get_host_address(self, state, c_id, tpl_var): | |||
if pod_ip: | |||
return pod_ip | |||
|
|||
# try to get the rancher IP address | |||
log.debug("No IP address was found in container %s (%s) " |
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.
Could you add if Platform.is_rancher()
before this new code? Otherwise this rancher-specific log line will show up in non Rancher environments.
You'll need to create an is_rancher
function in platform.py
first. One way you could detect rancher is by looking for their agent container(s) (read more about that here).
@@ -290,6 +301,12 @@ def get_tags(self, state, c_id): | |||
if swarm_svc: | |||
tags.append('swarm_service:%s' % swarm_svc) | |||
|
|||
if Platform.is_rancher(): | |||
c_inspect = state.inspect_container(c_id) | |||
service_name = c_inspect.get('Config', {}).get('Labels', {}).get('io.rancher.container.name') |
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.
maybe make io.rancher.container.name
a constant? It could live here or in dockerutil.
log.debug("No IP address was found in container %s (%s) " | ||
"trying with the Rancher label" % (c_id[:12], c_img)) | ||
|
||
ip_addr = c_inspect.get('Config', {}).get('Labels', {}).get('io.rancher.container.ip') |
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.
maybe make io.rancher.container.ip
a constant?
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.
Nice! LGTM
cool, i like it better too :) |
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.
LGTM
edit by hkaj: linked with DataDog/integrations-core#282