Skip to content

Commit 449cfb4

Browse files
Configure Alloy (#97)
* Add Prometheus configuration params * Add task to generate alloy config * Add agent cleanup tasks * Make ansible lint happy * Improve template conditionals to not render empty lines * Improve variable docs
1 parent 13a1d56 commit 449cfb4

File tree

8 files changed

+167
-12
lines changed

8 files changed

+167
-12
lines changed

README.adoc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,46 @@ per-role basis if appropriate.
687687
base64 string | false
688688
|===
689689

690+
The following variables drive the monitoring tooling on an agent host.
691+
692+
More detailed info about usage and defaults available link:https://github.com/trento-project/agent/blob/main/packaging/config/agent.yaml[here].
693+
694+
[width="100%",cols="10%,47%,43%",options="header",]
695+
|===
696+
|Name | Description | Default
697+
698+
| agent_prometheus_mode |
699+
Whether to use Prometheus in "pull" mode with prometheus node exporters or in "push" mode with grafana alloy. |
700+
If unspecified it resolves to "pull" for SLES \<= 15.7 and "pull" for SLES 16 and above.
701+
702+
| agent_prometheus_exporter_name |
703+
Exporter name used in host discovery. |
704+
"node_exporter" in case of prometheus "pull" mode, "grafana_alloy" in case of "push" mode.
705+
706+
| agent_prometheus_node_exporter_target |
707+
The target address of the node exporter to scrape metrics from, in case `agent_prometheus_mode` is set to "pull". |
708+
Defaults to the lowest discovered IP address with a default port number (9100).
709+
710+
| agent_prometheus_remote_write_url | The remote write URL of the Prometheus server, in case `agent_prometheus_mode` is set to "push". | currently undefined. Needs to be improved for autodiscovery
711+
712+
| agent_prometheus_scrape_interval | Scrape interval for Prometheus to scrape the node exporter, in case `agent_prometheus_mode` is set to "push". | "15s"
713+
714+
| agent_prometheus_auth | Authentication method when pushing metrics to Prometheus, in case `agent_prometheus_mode` is set to "push". One of: "none", "basic", "bearer", "mtls" | "bearer"
715+
716+
| agent_prometheus_auth_bearer_token | Bearer token used when `agent_prometheus_auth` is set to "bearer". Required if `agent_prometheus_auth` is set to "bearer" | ""
717+
718+
| agent_prometheus_auth_username | Username used when `agent_prometheus_auth` is set to "basic". Required if `agent_prometheus_auth` is set to "basic". | ""
719+
720+
| agent_prometheus_auth_password | Password used when `agent_prometheus_auth` is set to "basic". Required if `agent_prometheus_auth` is set to "basic". | ""
721+
722+
| agent_prometheus_tls_ca_cert | CA certificate used to verify the TLS certificate of the Prometheus server, in case `agent_prometheus_mode` is set to "push" and the Prometheus server uses TLS. This is required when the Prometheus server TLS certificate is signed by a non-public CA. | ""
723+
724+
| agent_prometheus_tls_client_cert | Client certificate used for mTLS authentication when `agent_prometheus_auth` is set to "mtls". Required if `agent_prometheus_auth` is set to "mtls". | ""
725+
726+
| agent_prometheus_tls_client_key | Client key used for mTLS authentication when `agent_prometheus_auth` is set to "mtls". Required if `agent_prometheus_auth` is set to "mtls". | ""
727+
728+
|===
729+
690730
*Postgres role*
691731

692732
[width="100%",cols="16%,57%,27%",options="header",]

cleanup-agents.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# code: language=ansible
2+
---
3+
- name: Clean up trento components
4+
hosts: agents
5+
become: true
6+
tasks:
7+
- name: Clean up Trento Agents
8+
ansible.builtin.import_role:
9+
name: agent
10+
tasks_from: cleanup

roles/agent/defaults/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,21 @@ agent_rabbitmq_vhost: "{{ rabbitmq_vhost | default(trento_rabbitmq_vhost) }}" #
99
agent_install_monitoring_dep: true
1010
agent_server_ca_cert: "{{ undef() }}"
1111
agent_server_ca_cert_as_base64: false
12+
# See https://github.com/trento-project/agent/blob/main/packaging/config/agent.yaml for more details about the following variables
13+
agent_prometheus_mode: ""
14+
agent_prometheus_exporter_name: ""
15+
# pull mode specific variables
16+
agent_prometheus_node_exporter_target: ""
17+
# push mode specific variables
18+
agent_prometheus_scrape_interval: ""
19+
agent_prometheus_remote_write_url: ""
20+
agent_prometheus_auth: ""
21+
# when auth is bearer - default
22+
agent_prometheus_auth_bearer_token: ""
23+
# when auth is basic
24+
agent_prometheus_auth_username: ""
25+
agent_prometheus_auth_password: ""
26+
# TLS/mTLS related variables
27+
agent_prometheus_tls_ca_cert: ""
28+
agent_prometheus_tls_client_cert: ""
29+
agent_prometheus_tls_client_key: ""

roles/agent/handlers/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
name: trento-agent
66
state: restarted
77

8-
- name: Start Prometheus node_exporter service
8+
- name: Restart Prometheus node_exporter service
99
ansible.builtin.service:
1010
name: prometheus-node_exporter
1111
state: restarted
1212
enabled: true
13-
when: agent_host_pre_16
1413

15-
- name: Start Alloy service
14+
- name: Restart Alloy service
1615
ansible.builtin.service:
1716
name: alloy
1817
state: restarted
1918
enabled: true
20-
when: agent_host_post_16

roles/agent/tasks/cleanup.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# code: language=ansible
2+
---
3+
- name: Stop and disable trento-agent service
4+
ansible.builtin.service:
5+
name: trento-agent
6+
state: stopped
7+
enabled: false
8+
9+
- name: Remove trento alloy configuration
10+
ansible.builtin.file:
11+
path: "/etc/alloy/trento.alloy"
12+
state: absent
13+
when: agent_prometheus_mode_push
14+
notify:
15+
- Restart Alloy service

roles/agent/tasks/main.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,37 @@
4343
community.general.zypper:
4444
name: golang-github-prometheus-node_exporter
4545
state: latest
46-
when: agent_install_monitoring_dep and agent_host_pre_16
46+
when: agent_install_monitoring_dep and agent_prometheus_mode_pull
4747
notify:
48-
- Start Prometheus node_exporter service
48+
- Restart Prometheus node_exporter service
4949

50-
- name: Install 'alloy' on SLES 16 and later
51-
community.general.zypper:
52-
name: alloy
53-
state: latest
54-
when: agent_install_monitoring_dep and agent_host_post_16
50+
- name: Install and configure alloy on SLES 16 and later
51+
when: agent_install_monitoring_dep and agent_prometheus_mode_push
5552
notify:
56-
- Start Alloy service
53+
- Restart Alloy service
54+
block:
55+
- name: Install 'alloy'
56+
community.general.zypper:
57+
name: alloy
58+
state: latest
59+
60+
- name: Get alloy configuration output from the agent
61+
ansible.builtin.command: trento-agent generate alloy
62+
register: __agent_alloy_config_result
63+
changed_when: false
64+
65+
- name: Generate trento alloy configuration
66+
ansible.builtin.blockinfile:
67+
path: "/etc/alloy/trento.alloy"
68+
block: "{{ __agent_alloy_config_result.stdout }}"
69+
marker: "// {mark} TRENTO CONFIGURATION - ANSIBLE MANAGED"
70+
mode: "0644"
71+
create: true
72+
backup: true
73+
74+
- name: Append trento alloy configuration
75+
ansible.builtin.replace:
76+
path: "/etc/sysconfig/alloy"
77+
regexp: '^CONFIG_FILE=".*"$'
78+
replace: 'CONFIG_FILE="/etc/alloy/"'
79+
backup: true

roles/agent/templates/agent.conf.j2

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,38 @@
33
server-url: {{ agent_trento_server_url }}
44
api-key: {{ agent_web_api_key }}
55
facts-service-url: {{ agent_amqp_protocol }}://{{ agent_rabbitmq_username }}:{{ agent_rabbitmq_password }}@{{ agent_rabbitmq_host }}/{{ agent_rabbitmq_vhost | urlencode | replace('/', '%2F') }}
6+
7+
prometheus-mode: {{ agent_resolved_prometheus_mode }}
8+
{% if agent_prometheus_exporter_name is truthy -%}
9+
prometheus-exporter-name: {{ agent_prometheus_exporter_name }}
10+
{% endif -%}
11+
{% if agent_resolved_prometheus_node_exporter_target is truthy -%}
12+
prometheus-node-exporter-target: {{ agent_resolved_prometheus_node_exporter_target }}
13+
{% endif -%}
14+
{% if agent_resolved_prometheus_scrape_interval is truthy -%}
15+
prometheus-scrape-interval: {{ agent_resolved_prometheus_scrape_interval }}
16+
{% endif -%}
17+
{% if agent_resolved_prometheus_remote_write_url is truthy -%}
18+
prometheus-url: {{ agent_resolved_prometheus_remote_write_url }}
19+
{% endif -%}
20+
{% if agent_resolved_prometheus_auth is truthy -%}
21+
prometheus-auth: {{ agent_resolved_prometheus_auth }}
22+
{% endif -%}
23+
{% if agent_resolved_prometheus_auth_bearer_token is truthy -%}
24+
prometheus-auth-bearer-token: {{ agent_resolved_prometheus_auth_bearer_token }}
25+
{% endif -%}
26+
{% if agent_resolved_prometheus_auth_username is truthy -%}
27+
prometheus-auth-username: {{ agent_resolved_prometheus_auth_username }}
28+
{% endif -%}
29+
{% if agent_resolved_prometheus_auth_password is truthy -%}
30+
prometheus-auth-password: {{ agent_resolved_prometheus_auth_password }}
31+
{% endif -%}
32+
{% if agent_resolved_prometheus_tls_ca_cert is truthy -%}
33+
prometheus-tls-ca-cert: {{ agent_resolved_prometheus_tls_ca_cert }}
34+
{% endif -%}
35+
{% if agent_resolved_prometheus_tls_client_cert is truthy -%}
36+
prometheus-tls-client-cert: {{ agent_resolved_prometheus_tls_client_cert }}
37+
{% endif -%}
38+
{% if agent_resolved_prometheus_tls_client_key is truthy -%}
39+
prometheus-tls-client-key: {{ agent_resolved_prometheus_tls_client_key }}
40+
{% endif -%}

roles/agent/vars/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
---
22
agent_host_pre_16: "{{ ansible_distribution_version is version('15.7', '<=') | bool }}"
33
agent_host_post_16: "{{ ansible_distribution_version is version('16.0', '>=') | bool }}"
4+
agent_resolved_prometheus_mode: "{{ agent_prometheus_mode | default(agent_host_pre_16 | ternary('pull', 'push'), true) }}"
5+
agent_prometheus_mode_pull: "{{ agent_resolved_prometheus_mode == 'pull' }}"
6+
agent_prometheus_mode_push: "{{ agent_resolved_prometheus_mode == 'push' }}"
7+
agent_resolved_prometheus_node_exporter_target: "{{ agent_prometheus_mode_pull | ternary(agent_prometheus_node_exporter_target, '') }}"
8+
agent_resolved_prometheus_scrape_interval: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_scrape_interval, '') }}"
9+
10+
__agent_discovered_prometheus_remote_write_url: "{{ agent_prometheus_remote_write_url | default('http://{}:{}{}'.format(trento_server_name, 9090, '/api/v1/write'), true) }}"
11+
agent_resolved_prometheus_remote_write_url: "{{ agent_prometheus_mode_push | ternary(__agent_discovered_prometheus_remote_write_url, '') }}"
12+
13+
agent_resolved_prometheus_auth: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_auth, '') }}"
14+
agent_resolved_prometheus_auth_bearer_token: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_auth_bearer_token, '') }}"
15+
agent_resolved_prometheus_auth_username: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_auth_username, '') }}"
16+
agent_resolved_prometheus_auth_password: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_auth_password, '') }}"
17+
agent_resolved_prometheus_tls_ca_cert: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_tls_ca_cert, '') }}"
18+
agent_resolved_prometheus_tls_client_cert: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_tls_client_cert, '') }}"
19+
agent_resolved_prometheus_tls_client_key: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_tls_client_key, '') }}"

0 commit comments

Comments
 (0)