Skip to content

Commit 3fcc1eb

Browse files
committed
Add extra config capabilities via a map
1 parent 1b39759 commit 3fcc1eb

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
3131
# Add Docker check
3232
COPY conf.d/docker_daemon.yaml /etc/dd-agent/conf.d/docker_daemon.yaml
3333

34+
COPY alpine/config_helper.py /config_helper.py
3435
COPY entrypoint.sh /entrypoint.sh
3536

3637
# Extra conf.d and checks.d

alpine/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ COPY conf.d/docker_daemon.yaml "$DD_HOME/agent/conf.d/docker_daemon.yaml"
1414

1515
# Add install and config files
1616
ADD https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh /tmp/setup_agent.sh
17+
COPY config_helper.py /config_helper.py
1718
COPY entrypoint.sh /entrypoint.sh
1819

1920
# Expose supervisor and DogStatsD port

alpine/config_helper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/opt/datadog-agent/embedded/bin/python
2+
'''
3+
This script is a helper to build additionnal config file options
4+
'''
5+
from argparse import ArgumentParser
6+
from os import getenv
7+
from json import loads
8+
9+
def add_extra_datadog_conf(conf_string, conf_file):
10+
'''
11+
This function takes a json-formatted string as parameter and adds its
12+
content at the end of the datadog.conf file given as parameter.
13+
14+
The json string defining the additionnal config HAS to be formatted as
15+
follows:
16+
'{"key1": "value1", "key2": "value2"}'
17+
or: '{"histogram_percentiles": "0.75, 0.95, 0.99"}'
18+
'''
19+
try:
20+
conf_data = loads(conf_string)
21+
with open(conf_file, 'a') as f:
22+
for data in conf_data:
23+
f.write('{}: {}\n'.format(data, conf_data[data]))
24+
except:
25+
pass
26+
27+
if __name__ == '__main__':
28+
parser = ArgumentParser()
29+
parser.add_argument('-c', '--config-file',
30+
default='/etc/dd-agent/datadog.conf',
31+
help='Full path of the config file to write the config to')
32+
parser.add_argument('-j', '--json-env',
33+
default='DD_EXTRA_CONF',
34+
help='Name of the environment variable to retrieve the json string from')
35+
args = parser.parse_args()
36+
37+
dd_extra_conf = getenv(args.json_env, '{}')
38+
add_extra_datadog_conf(dd_extra_conf, args.config_file)

alpine/entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ if [[ $SD_BACKEND_PASSWORD ]]; then
115115
sed -i -e 's@^# sd_backend_password:.*$@sd_backend_password: '${SD_BACKEND_PASSWORD}'@' /opt/datadog-agent/agent/datadog.conf
116116
fi
117117

118+
if [[ -n "$DD_EXTRA_CONF" ]]; then
119+
PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python /config_helper.py -c /opt/datadog-agent/agent/datadog.conf
120+
fi
121+
118122
##### Integrations config #####
119123

120124
if [[ -n "${KUBERNETES}" || -n "${MESOS_MASTER}" || -n "${MESOS_SLAVE}" ]]; then

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ if [[ $SD_BACKEND_PASSWORD ]]; then
129129
sed -i -e 's@^# sd_backend_password:.*$@sd_backend_password: '${SD_BACKEND_PASSWORD}'@' /etc/dd-agent/datadog.conf
130130
fi
131131

132+
if [[ -n "$DD_EXTRA_CONF" ]]; then
133+
PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python /config_helper.py
134+
fi
135+
132136
##### Integrations config #####
133137

134138
if [[ $KUBERNETES || $MESOS_MASTER || $MESOS_SLAVE ]]; then

0 commit comments

Comments
 (0)