Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyc-splunk committed Dec 13, 2023
1 parent 6475dda commit cc83fa1
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- 'deployments/ansible/galaxy.yml'
branches:
- main
- ansible-node-zc
pull_request:
paths:
- '.github/workflows/ansible.yml'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@
splunk_otel_auto_instrumentation_enable_metrics: true
splunk_otel_auto_instrumentation_otlp_endpoint: http://0.0.0.0:4317
tasks:
- name: "Install nodejs"
block:
- name: "install tar with apt"
ansible.builtin.apt:
name: tar
update_cache: yes
when: ansible_os_family == "Debian"
- name: "install tar with yum"
ansible.builtin.yum:
name: tar
update_cache: yes
when: ansible_os_family == "RedHat"
- name: "install tar with zypper"
community.general.zypper:
name: tar
update_cache: yes
when: ansible_os_family == "Suse"
- name: "download and extract"
unarchive:
src: https://nodejs.org/download/release/v16.20.2/node-v16.20.2-linux-x64.tar.gz
dest: /usr/local
remote_src: yes
- name: "create npm symlink"
file:
src: /usr/local/node-v16.20.2-linux-x64/bin/npm
dest: /usr/local/bin/npm
state: link
mode: '755'
- name: "Include signalfx.splunk_otel_collector.collector role"
include_role:
name: "collector"
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
set_fact:
auto_instrumentation_version: "{{ ansible_facts.packages['splunk-otel-auto-instrumentation'][0].version }}"

- name: splunk-otel-js installed
community.general.npm:
name: /usr/lib/splunk-instrumentation/splunk-otel-js.tgz
path: /usr/lib/splunk-instrumentation/splunk-otel-js
state: present
check_mode: yes
register: splunk_otel_js_installed
failed_when: splunk_otel_js_installed is changed

- name: Check for systemd drop-in file
ansible.builtin.stat:
path: /usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf
Expand Down Expand Up @@ -53,58 +62,85 @@
register: config
failed_when: config is changed

- name: Assert instrumentation config contains NODE_OPTIONS
ansible.builtin.lineinfile:
line: NODE_OPTIONS=-r /usr/lib/splunk-instrumentation/splunk-otel-js/node_modules/@splunk/otel/instrument
dest: /etc/splunk/zeroconfig/node.conf
state: present
check_mode: yes
register: config
failed_when: config is changed

- name: Assert instrumentation config contains OTEL_RESOURCE_ATTRIBUTES
ansible.builtin.lineinfile:
line: "OTEL_RESOURCE_ATTRIBUTES=\
splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }},\
deployment.environment=test"
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf

- name: Assert instrumentation config contains OTEL_SERVICE_NAME
ansible.builtin.lineinfile:
line: OTEL_SERVICE_NAME=test
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf

- name: Assert instrumentation config contains SPLUNK_PROFILER_ENABLED
ansible.builtin.lineinfile:
line: SPLUNK_PROFILER_ENABLED=true
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf

- name: Assert instrumentation config contains SPLUNK_PROFILER_MEMORY_ENABLED
ansible.builtin.lineinfile:
line: SPLUNK_PROFILER_MEMORY_ENABLED=true
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf

- name: Assert instrumentation config contains SPLUNK_METRICS_ENABLED
ansible.builtin.lineinfile:
line: SPLUNK_METRICS_ENABLED=true
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf

- name: Assert instrumentation config contains OTEL_EXPORTER_OTLP_ENDPOINT
ansible.builtin.lineinfile:
line: OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4317
dest: /etc/splunk/zeroconfig/java.conf
dest: "/etc/splunk/zeroconfig/{{ item }}"
state: present
check_mode: yes
register: config
failed_when: config is changed
loop:
- java.conf
- node.conf
2 changes: 2 additions & 0 deletions deployments/ansible/roles/collector/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ splunk_otel_auto_instrumentation_enable_profiler: false
splunk_otel_auto_instrumentation_enable_profiler_memory: false
splunk_otel_auto_instrumentation_enable_metrics: false
splunk_otel_auto_instrumentation_otlp_endpoint: http://127.0.0.1:4317
splunk_otel_auto_instrumentation_sdks: ["java", "node"]
splunk_otel_auto_instrumentation_npm_path: "npm"

# Custom environment variables for the collector service
splunk_otel_collector_additional_env_vars: {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,43 @@
set_fact:
auto_instrumentation_version: "{{ ansible_facts.packages['splunk-otel-auto-instrumentation'][0].version }}"

- name: Set up /etc/ld.so.preload for Splunk OpenTelemetry Auto Instrumentation
ansible.builtin.template:
src: ld_so_preload.j2
dest: /etc/ld.so.preload
owner: root
group: root
mode: '644'
- name: Set auto instrumentation facts
set_fact:
with_new_instrumentation: >
{{ auto_instrumentation_version is version('0.87.0', '>=') }}
with_systemd: >
{{ splunk_otel_auto_instrumentation_systemd | bool }}
with_java: >
{{ "java" in (splunk_otel_auto_instrumentation_sdks | default([])) }}
with_nodejs: >
{{ "nodejs" in (splunk_otel_auto_instrumentation_sdks | default([])) and
auto_instrumentation_version is version('0.87.0', '>=') }}
- name: Check for npm
shell: "command -v {{ splunk_otel_auto_instrumentation_npm_path | default('npm') }}"
check_mode: yes
register: npm_check
ignore_errors: true
when: with_nodejs

- name: Install splunk-otel-js
block:
- name: Create /usr/lib/splunk-instrumentation/splunk-otel-js
ansible.builtin.file:
path: /usr/lib/splunk-instrumentation/splunk-otel-js
state: directory
- name: npm install
community.general.npm:
name: /usr/lib/splunk-instrumentation/splunk-otel-js.tgz
path: /usr/lib/splunk-instrumentation/splunk-otel-js
executable: "{{ npm_check.stdout.strip() }}"
when: with_nodejs and (npm_check.rc == 0)

- name: Delete the Splunk OpenTelemetry Auto Instrumentation systemd config
ansible.builtin.file:
path: /usr/lib/systemd/system.conf.d/00-splunk-otel-auto-instrumentation.conf
state: absent
when: not (splunk_otel_auto_instrumentation_systemd | bool)
when: not with_systemd
notify: "Reload systemd daemon"

- name: Set up the Splunk OpenTelemetry Auto Instrumentation config file
Expand All @@ -42,9 +66,7 @@
owner: root
group: root
mode: '644'
when: >
auto_instrumentation_version is version('0.87.0', '<') and
not (splunk_otel_auto_instrumentation_systemd | bool)
when: with_java and not with_new_instrumentation and not with_systemd

- name: Set up the Splunk OpenTelemetry Auto Instrumentation for Java config file
ansible.builtin.template:
Expand All @@ -53,15 +75,22 @@
owner: root
group: root
mode: '644'
when: >
auto_instrumentation_version is version('0.87.0', '>=') and
not (splunk_otel_auto_instrumentation_systemd | bool)
when: with_java and with_new_instrumentation and not with_systemd

- name: Set up the Splunk OpenTelemetry Auto Instrumentation for Node.js config file
ansible.builtin.template:
src: node.conf.j2
dest: /etc/splunk/zeroconfig/node.conf
owner: root
group: root
mode: '644'
when: with_nodejs and (npm_check.rc == 0) and not with_systemd

- name: Ensure the system.conf.d directory exists
ansible.builtin.file:
path: /usr/lib/systemd/system.conf.d
state: directory
when: splunk_otel_auto_instrumentation_systemd | bool
when: with_systemd

- name: Set up systemd for Splunk OpenTelemetry Auto Instrumentation
ansible.builtin.template:
Expand All @@ -70,5 +99,13 @@
owner: root
group: root
mode: '644'
when: splunk_otel_auto_instrumentation_systemd | bool
when: with_systemd and (with_java or (with_nodejs and npm_check.rc == 0))
notify: "Reload systemd daemon"

- name: Set up /etc/ld.so.preload for Splunk OpenTelemetry Auto Instrumentation
ansible.builtin.template:
src: ld_so_preload.j2
dest: /etc/ld.so.preload
owner: root
group: root
mode: '644'
13 changes: 13 additions & 0 deletions deployments/ansible/roles/collector/templates/node.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
NODE_OPTIONS=-r /usr/lib/splunk-instrumentation/splunk-otel-js/node_modules/@splunk/otel/instrument
{% if splunk_otel_auto_instrumentation_resource_attributes is defined and splunk_otel_auto_instrumentation_resource_attributes %}
OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }},{{ splunk_otel_auto_instrumentation_resource_attributes }}
{% else %}
OTEL_RESOURCE_ATTRIBUTES=splunk.zc.method=splunk-otel-auto-instrumentation-{{ auto_instrumentation_version }}
{% endif %}
{% if splunk_otel_auto_instrumentation_service_name is defined and splunk_otel_auto_instrumentation_service_name %}
OTEL_SERVICE_NAME={{ splunk_otel_auto_instrumentation_service_name }}
{% endif %}
SPLUNK_PROFILER_ENABLED={{ splunk_otel_auto_instrumentation_enable_profiler | string | lower }}
SPLUNK_PROFILER_MEMORY_ENABLED={{ splunk_otel_auto_instrumentation_enable_profiler_memory | string | lower }}
SPLUNK_METRICS_ENABLED={{ splunk_otel_auto_instrumentation_enable_metrics | string | lower }}
OTEL_EXPORTER_OTLP_ENDPOINT={{ splunk_otel_auto_instrumentation_otlp_endpoint }}

0 comments on commit cc83fa1

Please sign in to comment.