-
Notifications
You must be signed in to change notification settings - Fork 813
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
Allow autoconf templates in docker labels #3451
Conversation
bebc153
to
14192c1
Compare
6b73eee
to
d3481f9
Compare
The
The strict pattern according to the docker page would be Additionally the reverse-dns style recommendation implies it should be |
770b2dc
to
6c19ba4
Compare
Good catch, I'm renaming the labels to be valid. Here is an example label section for a basic jmx check:
The test docker image is rebuilding as I post this, could you give it another try? |
This appears to work. My docker-compose.yml was: version: "2"
services:
tomcat:
image: tomcat:8-alpine
ports:
- "8080:8080"
- "8099:8099"
environment:
- JVM_HEAP=-Xmx512m -Xms512m
- CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
labels:
com.datadoghq.sd.check_names: "[\"jmx\"]"
com.datadoghq.sd.init_configs: "[{}]"
com.datadoghq.sd.instances: "[{\"host\": \"%%host%%\", \"port\": \"%%port_1%%\", \"tags\" : { \"env\" : \"jm\", \"app\" : \"appnamehere\" }}]"
datadog:
image: datadog/dev-dd-agent:jmx-xvello_template_in_labels
depends_on:
- tomcat
environment:
- API_KEY
- SD_JMX_ENABLE=yes
- SD_BACKEND=docker
- DD_HOSTNAME=jmtest
- LOG_LEVEL=DEBUG
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc:/host/proc:ro
- /sys/fs/cgroup:/host/sys/fs/cgroup:ro I had to add escaping else compose complained about the YAML format. Using this image and configuration I saw the JMX metrics appear in DataDog under app:appnamehere and env:jm. A couple of things I noticed: |
Hi @jhmartin, Thanks for your feedback. Happy to know this is working for you! As for escaping, if you surround your JSON with single quotes, you don't need to escape double quotes, please have a look at the example I posted Indeed, JMX is kind of a special child for now as it runs in a separate java process, and does not appear in |
if docker_labels: | ||
kube_config = self._get_docker_config(identifier, docker_labels) | ||
if kube_config is not None: | ||
to_check.update(kube_config[0]) |
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.
kube_config --> docker_config same for the 2 lines above
docker_labels = kwargs.get(DOCKER_LABELS) | ||
source = "" | ||
|
||
kube_config = None |
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.
same here, you can call it config
or whatever but it's not k8s specific anymore
left nitpick comments and will give it a spin before we merge but it looks 👍 |
6c19ba4
to
343e8d8
Compare
e589e5b
to
3f99823
Compare
Hi @jhmartin, I'm just merging that PR, so 5.17 will have support for templates as labels. Regard |
@xvello Saw that, no problem. |
@xvello
It currently works, but relying on underscore in a label name may cause an issue in the future. Better to change it to -, or accept both. |
What does this PR do?
Mirroring the kubernetes annotation autodiscovery source, lookup autoconf template in container labels. These templates are expected in the JSON format.
If k8s annotation are present, they take precedence. Else, if valid json is found in the following labels:
Warning: the label names changed from the original PR, to reflect the s/ServiceDiscovery/AutoDiscovery/ transition
a template is rendered from them, bypassing the auto_conf files lookup.
If a K/V store backend is configured, this feature is disabled, like k8s annotations.
Testing Guidelines
test_get_check_tpls_labels
test method. We could go further with integration testing.datadog/dev-dd-agent:jmx-xvello_template_in_labels
image