-
Notifications
You must be signed in to change notification settings - Fork 231
Add support for configuring APM injection #481
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4286480
wip: add support for installing APM injection
rarguelloF 27e9741
switch pky-redhat to using yum, not apt
jonbodner 81bcfa6
additional fixes for redhat support
jonbodner 6ee68c9
implement apm host docker injection and address review comments
rarguelloF a8c7233
fix lint
rarguelloF 1c45849
add task for container-only install
jonbodner 989494b
changes to support new --no-agent-config-change flag and to fix conta…
jonbodner a61bda0
update names of vars to match agent install script
jonbodner 9ca6674
fix docker check
jonbodner b82343d
fix the default value for datadog_apm_instrumentation_rc so it always…
jonbodner af84e5a
address review comments
rarguelloF 7363e24
update README with new APM inject variables
rarguelloF d9ef38c
Update defaults/main.yml
rarguelloF 2756f1b
Merge branch 'main' into rarguelloF/apm-injection
rarguelloF 83e92ee
fix stat docker folder task
rarguelloF b4a3943
Merge branch 'main' into rarguelloF/apm-injection
d410291
Update code to pass stricter ansible-lint
7d2d6be
Fix typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
bkabrda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
| --- | ||
bkabrda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - 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 hidden or 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 hidden or 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 hidden or 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 %} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.