Skip to content

Commit

Permalink
Add extra config capabilities via a map
Browse files Browse the repository at this point in the history
  • Loading branch information
aerostitch committed Aug 1, 2017
1 parent 1b39759 commit 3fcc1eb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RUN mv /etc/dd-agent/datadog.conf.example /etc/dd-agent/datadog.conf \
# Add Docker check
COPY conf.d/docker_daemon.yaml /etc/dd-agent/conf.d/docker_daemon.yaml

COPY alpine/config_helper.py /config_helper.py
COPY entrypoint.sh /entrypoint.sh

# Extra conf.d and checks.d
Expand Down
1 change: 1 addition & 0 deletions alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY conf.d/docker_daemon.yaml "$DD_HOME/agent/conf.d/docker_daemon.yaml"

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

# Expose supervisor and DogStatsD port
Expand Down
38 changes: 38 additions & 0 deletions alpine/config_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/opt/datadog-agent/embedded/bin/python
'''
This script is a helper to build additionnal config file options
'''
from argparse import ArgumentParser
from os import getenv
from json import loads

def add_extra_datadog_conf(conf_string, conf_file):
'''
This function takes a json-formatted string as parameter and adds its
content at the end of the datadog.conf file given as parameter.
The json string defining the additionnal config HAS to be formatted as
follows:
'{"key1": "value1", "key2": "value2"}'
or: '{"histogram_percentiles": "0.75, 0.95, 0.99"}'
'''
try:
conf_data = loads(conf_string)
with open(conf_file, 'a') as f:
for data in conf_data:
f.write('{}: {}\n'.format(data, conf_data[data]))
except:
pass

if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('-c', '--config-file',
default='/etc/dd-agent/datadog.conf',
help='Full path of the config file to write the config to')
parser.add_argument('-j', '--json-env',
default='DD_EXTRA_CONF',
help='Name of the environment variable to retrieve the json string from')
args = parser.parse_args()

dd_extra_conf = getenv(args.json_env, '{}')
add_extra_datadog_conf(dd_extra_conf, args.config_file)
4 changes: 4 additions & 0 deletions alpine/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ if [[ $SD_BACKEND_PASSWORD ]]; then
sed -i -e 's@^# sd_backend_password:.*$@sd_backend_password: '${SD_BACKEND_PASSWORD}'@' /opt/datadog-agent/agent/datadog.conf
fi

if [[ -n "$DD_EXTRA_CONF" ]]; then
PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python /config_helper.py -c /opt/datadog-agent/agent/datadog.conf
fi

##### Integrations config #####

if [[ -n "${KUBERNETES}" || -n "${MESOS_MASTER}" || -n "${MESOS_SLAVE}" ]]; then
Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ if [[ $SD_BACKEND_PASSWORD ]]; then
sed -i -e 's@^# sd_backend_password:.*$@sd_backend_password: '${SD_BACKEND_PASSWORD}'@' /etc/dd-agent/datadog.conf
fi

if [[ -n "$DD_EXTRA_CONF" ]]; then
PYTHONPATH=/opt/datadog-agent/agent /opt/datadog-agent/embedded/bin/python /config_helper.py
fi

##### Integrations config #####

if [[ $KUBERNETES || $MESOS_MASTER || $MESOS_SLAVE ]]; then
Expand Down

0 comments on commit 3fcc1eb

Please sign in to comment.