Skip to content

Commit 86e3fe0

Browse files
committed
Work in progress
1 parent 795c013 commit 86e3fe0

File tree

7 files changed

+75
-33
lines changed

7 files changed

+75
-33
lines changed

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
2121
# 4. Remove dd-agent user from init.d configuration
2222
# 5. Fix permission on /etc/init.d/datadog-agent
2323
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
24-
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
25-
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
2624
&& sed -i "/user=dd-agent/d" /etc/dd-agent/supervisor.conf \
2725
&& sed -i 's/AGENTUSER="dd-agent"/AGENTUSER="root"/g' /etc/init.d/datadog-agent \
2826
&& rm /etc/dd-agent/conf.d/network.yaml.default \

alpine/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ RUN apk add -qU --no-cache -t .build-deps gcc musl-dev pgcluster-dev linux-heade
3535
# 3. Remove dd-agent user from supervisor configuration
3636
# 4. Remove setup script
3737
RUN cp "$DD_HOME/agent/datadog.conf.example" "$DD_HOME/agent/datadog.conf" \
38-
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" "$DD_HOME/agent/datadog.conf" \
39-
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" "$DD_HOME/agent/datadog.conf" \
4038
&& sed -i "/user=dd-agent/d" "$DD_HOME/agent/supervisor.conf" \
4139
&& rm "$DD_HOME/agent/conf.d/network.yaml.default" \
4240
|| rm /tmp/setup_agent.sh

config_builder.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/opt/datadog-agent/embedded/bin/python
2+
'''
3+
This script is used to generate the configuration of the datadog agent, its
4+
integrations and other moving parts.
5+
'''
6+
7+
from os import getenv, environ
8+
import logging
9+
10+
# Structure of the defaut activated elements in the different files
11+
# This is the 1st layer of parameters. It will be overwritten by the
12+
# environment variables
13+
DEFAULT_PARAMS = {
14+
'datadog.conf': {
15+
'non_local_traffic': 'yes',
16+
'log_to_syslog': 'no'
17+
}
18+
}
19+
20+
class ConfBuilder(object):
21+
'''
22+
This class manages the configuration files
23+
'''
24+
def init(self):
25+
# excludes from the generic variables parsing the ones that have a
26+
# certain logic warpped around them
27+
self.exclude_from_generic = ['DD_API_KEY', 'DD_API_KEY_FILE', 'DD_HOME',
28+
'DD_START_AGENT', 'DD_LOGS_STDOUT']
29+
30+
def build_datadog_conf(self):
31+
'''
32+
Builds the datadog.conf based on the environment variables
33+
'''
34+
self.set_api_key()
35+
self.set_generics()
36+
37+
def set_api_key(self):
38+
'''
39+
Gets the API key from the environment or the key file
40+
and sets it in the configuration
41+
'''
42+
api_key = getenv('DD_API_KEY', getenv('API_KEY', ''))
43+
keyfile = getenv('DD_API_KEY_FILE', '')
44+
if keyfile != '':
45+
try:
46+
with open(keyfile, 'r') as kfile:
47+
api_key = kfile.read()
48+
except Exception:
49+
logging.warning('Unable to read the content of they key file specified in DD_API_KEY_FILE')
50+
if len(api_key) > 0:
51+
logging.error('You must set API_KEY environment variable or include a DD_API_KEY_FILE to run the Datadog Agent container')
52+
exit(1)
53+
self.set_property('api_key', api_key)
54+
55+
def set_generics(self):
56+
'''
57+
Looks for environment variables starting by 'DD_' and consider that the
58+
rest of the variable name is the name of the property to set
59+
'''
60+
for dd_var in environ:
61+
if dd_var.starts_with('DD_') and dd_var.upper() not in self.exclude_from_generic:
62+
if len(dd_var) > 0:
63+
self.set_property(dd_var[3:].lower(), environ[dd_var])
64+
65+
def set_property(self, property_name, property_value):
66+
'''
67+
Sets the given property to the given value in the configuration
68+
'''
69+
print('{}: {}'.format(property_name, property_value))
70+
71+
if __name__ == '__main__':
72+
cfg = ConfBuilder()
73+
cfg.build_datadog_conf()

dogstatsd/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
2020
# 2. Turn syslog off
2121
# 3. Use custom supervisor.conf
2222
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
23-
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
24-
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
2523
&& mv /supervisor.conf /etc/dd-agent/supervisor.conf
2624

2725
# Expose supervisor, DogStatsD and trace-agent port

dogstatsd/alpine/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ RUN apk add -qU --no-cache -t .build-deps curl gcc musl-dev pgcluster-dev linux-
3131
# 3. Use custom supervisor.conf
3232
# 4. Clean up the install script
3333
RUN mv $DD_HOME/agent/datadog.conf.example $DD_HOME/agent/datadog.conf \
34-
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" $DD_HOME/agent/datadog.conf \
35-
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" $DD_HOME/agent/datadog.conf \
3634
&& mv /supervisor.conf $DD_HOME/agent/supervisor.conf \
3735
&& rm /tmp/setup_agent.sh
3836

entrypoint.sh

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@
44

55
##### Core config #####
66

7-
if [[ $DD_API_KEY ]]; then
8-
export API_KEY=${DD_API_KEY}
9-
fi
10-
11-
if [[ $DD_API_KEY_FILE ]]; then
12-
export API_KEY=$(cat $DD_API_KEY_FILE)
13-
fi
14-
15-
if [[ $API_KEY ]]; then
16-
sed -i -e "s/^.*api_key:.*$/api_key: ${API_KEY}/" /etc/dd-agent/datadog.conf
17-
else
18-
echo "You must set API_KEY environment variable or include a DD_API_KEY_FILE to run the Datadog Agent container"
19-
exit 1
20-
fi
21-
22-
if [[ $DD_HOSTNAME ]]; then
23-
sed -i -r -e "s/^# ?hostname.*$/hostname: ${DD_HOSTNAME}/" /etc/dd-agent/datadog.conf
24-
fi
25-
267
if [[ $DD_TAGS ]]; then
278
export TAGS=${DD_TAGS}
289
fi

jmx/Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ RUN echo "deb http://apt.datadoghq.com/ stable main" > /etc/apt/sources.list.d/d
1515
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1616

1717
# Configure the Agent
18-
# 1. Listen to statsd from other containers
19-
# 2. Turn syslog off
20-
# 3. Enable Service Discovery with JMXFetch
18+
# 1. Enable Service Discovery with JMXFetch
2119
# 4. Remove dd-agent user from supervisor configuration
2220
# 5. Remove dd-agent user from init.d configuration
2321
# 6. Fix permission on /etc/init.d/datadog-agent
22+
ENV DD_SD_JMX_ENABLE=yes
2423
RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
25-
&& sed -i -e"s/^.*non_local_traffic:.*$/non_local_traffic: yes/" /etc/dd-agent/datadog.conf \
26-
&& sed -i -e"s/^.*log_to_syslog:.*$/log_to_syslog: no/" /etc/dd-agent/datadog.conf \
27-
&& sed -i -e"s/^.*sd_jmx_enable:.*$/sd_jmx_enable: yes/" /etc/dd-agent/datadog.conf \
2824
&& sed -i "/user=dd-agent/d" /etc/dd-agent/supervisor.conf \
2925
&& sed -i 's/AGENTUSER="dd-agent"/AGENTUSER="root"/g' /etc/init.d/datadog-agent \
3026
&& rm /etc/dd-agent/conf.d/network.yaml.default \

0 commit comments

Comments
 (0)