-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for configuring APM injection (#481)
Co-authored-by: Jon Bodner <[email protected]> Co-authored-by: Heston Hoffman <[email protected]> Co-authored-by: Slavek Kabrda <[email protected]>
- Loading branch information
1 parent
a8ddc45
commit 16e6af9
Showing
11 changed files
with
231 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
- name: Fail if the Datadog Agent version is not compatible with APM host injection | ||
fail: | ||
msg: APM Host Injection is not supported for this datadog-agent version. | ||
when: agent_datadog_agent_major_version | int < 7 | ||
|
||
- name: Fail if APM Host injection is not supported on this host | ||
fail: | ||
msg: APM Host Injection is not supported in this platform. | ||
when: ansible_facts.os_family not in ["Debian", "RedHat", "Rocky", "AlmaLinux"] | ||
|
||
- name: Fail if APM Host injection type does not contain a supported value | ||
fail: | ||
msg: The provided value for datadog_apm_instrumentation_enabled is not valid. Valid values are "all", "host" and "docker" | ||
when: datadog_apm_instrumentation_enabled not in ["all", "host", "docker"] | ||
|
||
- name: Check if docker daemon config dir exists | ||
stat: | ||
path: /etc/docker | ||
register: agent_docker_daemon_config_dir | ||
|
||
- name: Fail if APM Host container injection requirements aren't met (Docker installed) | ||
fail: | ||
msg: > | ||
/etc/docker does not exist. Please ensure docker is installed or disable the | ||
datadog_apm_instrumentation_enabled="docker" flag. | ||
when: >- | ||
datadog_apm_instrumentation_enabled in ["all", "docker"] | ||
and ( | ||
agent_docker_daemon_config_dir.stat.isdir is not defined | ||
or not agent_docker_daemon_config_dir.stat.isdir | ||
) | ||
- name: Fail if datadog_manage_config is not enabled | ||
fail: | ||
msg: "APM Host Injection requires datadog_manage_config: true" | ||
when: not datadog_manage_config | ||
|
||
- name: Set internal values for APM host injection datadog_config | ||
set_fact: | ||
agent_dd_apm_host_inject_config: | ||
apm_config: | ||
receiver_socket: /opt/datadog/apm/inject/run/apm.socket | ||
use_dogstatsd: true | ||
dogstatsd_socket: /opt/datadog/apm/inject/run/dsd.socket | ||
|
||
- name: Fail if provided config is not compatible with APM host injection | ||
fail: | ||
msg: | | ||
The provided config is not compatible with APM host injection. The expected config parameters to be included are: | ||
"{{ agent_dd_apm_host_inject_config | to_nice_yaml }}" | ||
when: item.condition | ||
loop: | ||
- condition: >- | ||
{{ | ||
'use_dogstatsd' in agent_datadog_config | ||
and agent_datadog_config['use_dogstatsd'] != agent_dd_apm_host_inject_config['use_dogstatsd'] | ||
}} | ||
- condition: >- | ||
{{ | ||
'dogstatsd_socket' in agent_datadog_config | ||
and agent_datadog_config['dogstatsd_socket'] != agent_dd_apm_host_inject_config['dogstatsd_socket'] | ||
}} | ||
- condition: >- | ||
{{ | ||
'apm_config' in agent_datadog_config | ||
and 'receiver_socket' in agent_datadog_config['apm_config'] | ||
and agent_datadog_config['apm_config']['receiver_socket'] != agent_dd_apm_host_inject_config['apm_config']['receiver_socket'] | ||
}} | ||
- name: Update datadog_config including config values needed for APM host injection | ||
set_fact: | ||
agent_datadog_config: "{{ agent_datadog_config | combine(agent_dd_apm_host_inject_config, list_merge='keep') }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
- name: Include APM host injection Debian install tasks | ||
include_tasks: pkg-debian/install-apm-inject-latest.yml | ||
when: not ansible_check_mode and ansible_facts.os_family == "Debian" | ||
|
||
- name: Include APM host injection RedHat install tasks | ||
include_tasks: pkg-redhat/install-apm-inject-latest.yml | ||
when: not ansible_check_mode and ansible_facts.os_family in ["RedHat", "Rocky", "AlmaLinux"] | ||
|
||
- name: Check if dd-host-install needs to run | ||
command: dd-host-install --no-config-change --no-agent-restart --dry-run | ||
register: agent_dd_host_install_cmd | ||
changed_when: false | ||
failed_when: agent_dd_host_install_cmd.rc >= 2 | ||
|
||
- name: Run APM host injection setup script | ||
command: dd-host-install --no-config-change --no-agent-restart | ||
notify: restart datadog-agent | ||
when: not ansible_check_mode and agent_dd_host_install_cmd.rc == 1 and datadog_apm_instrumentation_enabled in ["all", "host"] | ||
changed_when: true | ||
|
||
- name: Check if dd-container-install needs to run | ||
command: dd-container-install --dry-run | ||
register: agent_dd_container_install_cmd | ||
changed_when: false | ||
failed_when: agent_dd_container_install_cmd.rc >= 2 | ||
|
||
- name: Create Docker APM injection config file | ||
template: | ||
src: apm-inject-docker-config.yaml.j2 | ||
dest: /etc/datadog-agent/inject/docker_config.yaml | ||
mode: "0640" | ||
owner: root | ||
group: "{{ datadog_group }}" | ||
when: datadog_apm_instrumentation_docker_config | ||
|
||
- name: Run APM host-docker injection (Docker) setup script | ||
# this command will change /etc/docker/daemon.json and reload docker if changes are made. | ||
command: dd-container-install | ||
when: not ansible_check_mode and agent_dd_container_install_cmd.rc == 1 and datadog_apm_instrumentation_enabled in ["all", "docker"] | ||
changed_when: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
- name: Set APM injection install packages | ||
set_fact: | ||
agent_dd_apm_install_pkgs: "{{ (agent_dd_apm_install_pkgs | default([], true)) + ['datadog-apm-library-' + item] }}" | ||
with_items: "{{ datadog_apm_instrumentation_languages }}" | ||
|
||
- name: Install APM inject libraries | ||
apt: | ||
name: "{{ ['datadog-apm-inject'] + (agent_dd_apm_install_pkgs | default([], true)) }}" | ||
state: latest # noqa package-latest | ||
update_cache: true | ||
cache_valid_time: "{{ datadog_apt_cache_valid_time }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
- name: Set APM injection install packages | ||
set_fact: | ||
agent_dd_apm_install_pkgs: "{{ (agent_dd_apm_install_pkgs | default([], true)) + ['datadog-apm-library-' + item] }}" | ||
with_items: "{{ datadog_apm_instrumentation_languages }}" | ||
|
||
- name: Install APM inject libraries (dnf) | ||
dnf: | ||
name: "{{ ['datadog-apm-inject'] + (agent_dd_apm_install_pkgs | default([], true)) }}" | ||
update_cache: true | ||
state: latest # noqa package-latest | ||
when: not ansible_check_mode and ansible_pkg_mgr == "dnf" | ||
|
||
- name: Install APM inject libraries (yum) | ||
yum: | ||
name: "{{ ['datadog-apm-inject'] + (agent_dd_apm_install_pkgs | default([], true)) }}" | ||
update_cache: true | ||
state: latest # noqa package-latest | ||
when: not ansible_check_mode and ansible_pkg_mgr == "yum" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# {{ ansible_managed }} | ||
|
||
{{ datadog_apm_instrumentation_docker_config | to_nice_yaml }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# {{ ansible_managed }} | ||
|
||
{% if datadog_site is defined | ||
and datadog_config["site"] is not defined -%} | ||
and agent_datadog_config["site"] is not defined -%} | ||
site: {{ datadog_site }} | ||
{% endif %} | ||
|
||
{% if datadog_config["dd_url"] is not defined | ||
{% if agent_datadog_config["dd_url"] is not defined | ||
and datadog_url is defined -%} | ||
dd_url: {{ datadog_url }} | ||
{% endif %} | ||
|
||
{% if datadog_config["api_key"] is not defined -%} | ||
{% if agent_datadog_config["api_key"] is not defined -%} | ||
api_key: {{ datadog_api_key | default('youshouldsetthis') }} | ||
{% endif %} | ||
|
||
{% if datadog_config | default({}, true) | length > 0 -%} | ||
{{ datadog_config | to_nice_yaml }} | ||
{% if agent_datadog_config | default({}, true) | length > 0 -%} | ||
{{ agent_datadog_config | to_nice_yaml }} | ||
{% endif %} |