Skip to content

Commit b59d12b

Browse files
authored
Merge pull request #99 from trento-project/prometheus-ssl-termination
Prometheus ssl termination
2 parents 449cfb4 + 2bb8da0 commit b59d12b

File tree

10 files changed

+96
-8
lines changed

10 files changed

+96
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ jobs:
111111
hosts:
112112
server:
113113
ansible_host: ${{ env.TEST_HOST_IP }}
114+
prometheus_hosts:
115+
hosts:
116+
server:
117+
ansible_host: ${{ env.TEST_HOST_IP }}
114118
agents:
115119
hosts:
116120
agent:
@@ -160,6 +164,10 @@ jobs:
160164
hosts:
161165
server:
162166
ansible_host: ${{ env.TEST_HOST_IP }}
167+
prometheus_hosts:
168+
hosts:
169+
server:
170+
ansible_host: ${{ env.TEST_HOST_IP }}
163171
options: |
164172
--extra-vars "web_postgres_password='trento' \
165173
wanda_postgres_password='wanda' \

README.adoc

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ The nginx configuration acts as a reverse proxy for all the components.
5656
`server.yml` playbook installs Trento server components (Web and
5757
Wanda) along with the supporting third-party application dependencies.
5858

59-
This playbook supports auto-discovery of the hosts for RabbitMQ and
60-
Postgres in Web and Wanda. This feature is enabled when
61-
`provision_postgres` and `provision_rabbitmq` flags are true. When
62-
auto-discovery is active, `*_host` variables in `app` role are
63-
ignored. If you want to use external services for these dependencies,
59+
This playbook supports auto-discovery of the hosts for RabbitMQ, Postgres and Prometheus
60+
in Web and Wanda. This feature is enabled when `provision_postgres`,
61+
`provision_rabbitmq` and `provision_prometheus` flags are true. When
62+
auto-discovery is active, `*_host` variables (in `trento` role
63+
and any other role using them) are ignored.
64+
If you want to use external services for these dependencies,
6465
turn off the respective flag and specify the `*_host` variable in your
6566
inventory.
6667

@@ -401,6 +402,24 @@ per-role basis if appropriate.
401402

402403
| trento_rabbitmq_vhost | The rabbitmq vhost used for the current
403404
deployment | "trento"
405+
406+
| trento_prometheus_host | The host where Prometheus is
407+
located. Used as input for calculating
408+
`trento_prometheus_effective_host` variable that is the default for
409+
`*_prometheus_host` variables in some dependent roles. This variable
410+
is ignored when `trento_prometheus_host_group` is non-empty string. |
411+
localhost
412+
413+
| trento_prometheus_port | The port where Prometheus is exposed. | 9090
414+
415+
| trento_prometheus_host_group | Name of the host group where Prometheus
416+
is located. If this value is not empty string, activates
417+
auto-discovery of the Prometheus host by searching it in the specified
418+
group. Used as input for calculating
419+
`trento_prometheus_effective_host` variable that is the default for
420+
`*_prometheus_host` variables in some dependent roles. When
421+
auto-discovery is active, the value of `trento_prometheus_host` is
422+
ignored. | ""
404423
|===
405424

406425
*Web role*
@@ -707,7 +726,7 @@ More detailed info about usage and defaults available link:https://github.com/tr
707726
The target address of the node exporter to scrape metrics from, in case `agent_prometheus_mode` is set to "pull". |
708727
Defaults to the lowest discovered IP address with a default port number (9100).
709728

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
729+
| agent_prometheus_remote_write_url | The remote write URL of the Prometheus server, in case `agent_prometheus_mode` is set to "push". | "https://<value of `trento_server_name`>/prometheus/api/v1/write"
711730

712731
| agent_prometheus_scrape_interval | Scrape interval for Prometheus to scrape the node exporter, in case `agent_prometheus_mode` is set to "push". | "15s"
713732

@@ -836,6 +855,14 @@ More detailed info about usage and defaults available link:https://github.com/tr
836855

837856
| rproxy_ssl_key_as_base64 | Whether SSL key is provided as base64
838857
string | false
858+
859+
| rproxy_provision_prometheus | Whether to provision Prometheus
860+
proxy configuration in the reverse proxy | false
861+
862+
| rproxy_prometheus_host | The host where Prometheus is located. | <value of `trento_prometheus_effective_host`>
863+
864+
| rproxy_prometheus_port | The port where Prometheus is exposed. | <value of `trento_prometheus_port`>
865+
839866
|===
840867

841868
== Clean up

roles/agent/vars/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ agent_prometheus_mode_push: "{{ agent_resolved_prometheus_mode == 'push' }}"
77
agent_resolved_prometheus_node_exporter_target: "{{ agent_prometheus_mode_pull | ternary(agent_prometheus_node_exporter_target, '') }}"
88
agent_resolved_prometheus_scrape_interval: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_scrape_interval, '') }}"
99

10-
__agent_discovered_prometheus_remote_write_url: "{{ agent_prometheus_remote_write_url | default('http://{}:{}{}'.format(trento_server_name, 9090, '/api/v1/write'), true) }}"
10+
__agent_discovered_prometheus_remote_write_url: "{{ agent_prometheus_remote_write_url | default('https://{}{}'.format(trento_server_name, '/prometheus/api/v1/write'), true) }}"
1111
agent_resolved_prometheus_remote_write_url: "{{ agent_prometheus_mode_push | ternary(__agent_discovered_prometheus_remote_write_url, '') }}"
1212

1313
agent_resolved_prometheus_auth: "{{ agent_prometheus_mode_push | ternary(agent_prometheus_auth, '') }}"

roles/prometheus/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
prometheus_port: 9090
2+
prometheus_port: "{{ trento_prometheus_port }}"
33
prometheus_web_url: "{{ web_host | default('http://{}'.format(trento_server_name)) }}" # `web_host` is for backwards-compatibility
44
prometheus_web_listen_port: "{{ web_listen_port | default(trento_web_listen_port) }}" # `web_listen_port` for backwards-compatibility
55
prometheus_enable_remote_write_receiver: true

roles/rproxy/defaults/main/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ rproxy_ssl_cert: "{{ nginx_ssl_cert }}"
1414
rproxy_ssl_cert_as_base64: "{{ nginx_ssl_cert_as_base64 }}"
1515
rproxy_ssl_key: "{{ nginx_ssl_key }}"
1616
rproxy_ssl_key_as_base64: "{{ nginx_ssl_key_as_base64 }}"
17+
rproxy_provision_prometheus: false
18+
rproxy_prometheus_host: "{{ trento_prometheus_effective_host }}"
19+
rproxy_prometheus_port: "{{ trento_prometheus_port }}"

roles/rproxy/templates/trento.conf.j2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ upstream {{ wanda_upstream }} {
1111
server 127.0.0.1:{{ wanda_port }} max_fails=5 fail_timeout=60s;
1212
}
1313

14+
{% if rproxy_provision_prometheus -%}
15+
upstream prometheus {
16+
server {{ rproxy_prometheus_host }}:{{ rproxy_prometheus_port }} max_fails=5 fail_timeout=60s;
17+
}
18+
{% endif %}
19+
1420
server {
1521
# Redirect HTTP to HTTPS
1622
listen {{ http_listen_port }};
@@ -30,6 +36,23 @@ server {
3036
ssl_prefer_server_ciphers on;
3137
ssl_session_cache shared:SSL:10m;
3238

39+
{% if rproxy_provision_prometheus %}
40+
# Prometheus rule
41+
location /prometheus/ {
42+
allow all;
43+
44+
# Proxy Headers
45+
proxy_http_version 1.1;
46+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
47+
proxy_set_header Host $http_host;
48+
proxy_set_header X-Cluster-Client-Ip $remote_addr;
49+
50+
# Add final slash to replace the prometheus_location value by the value in proxy_pass
51+
# https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
52+
proxy_pass http://prometheus/;
53+
}
54+
{% endif %}
55+
3356
# Wanda rule
3457
location {{ wanda_location }}/ {
3558
allow all;

roles/trento/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ trento_rabbitmq_host_group: ""
3535
trento_rabbitmq_username: trento
3636
trento_rabbitmq_password: "{{ undef(hint='Password for RabbitMQ trento user is mandatory') }}"
3737
trento_rabbitmq_vhost: trento
38+
trento_prometheus_host_group: ""
39+
trento_prometheus_host: localhost
40+
trento_prometheus_port: 9090

roles/trento/tasks/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,13 @@
1818
Inventory ansible host is {{ __trento_rabbitmq_ansible_host | default('undefined') }}.
1919
User value is {{ trento_rabbitmq_host }}
2020
verbosity: 1
21+
22+
- name: Show host discovery results for Prometheus
23+
ansible.builtin.debug:
24+
msg: |
25+
Effective Prometheus host is {{ trento_prometheus_effective_host }}.
26+
Discovery host is {{ __trento_prometheus_discovery_host | default('undefined') }}.
27+
Inventory host is {{ __trento_prometheus_inventory_host | default('undefined') }}.
28+
Inventory ansible host is {{ __trento_prometheus_ansible_host | default('undefined') }}.
29+
User value is {{ trento_prometheus_host }}
30+
verbosity: 1

roles/trento/vars/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ __trento_rabbitmq_discovery_host: "{{ (inventory_hostname in groups[trento_rabbi
3636
trento_rabbitmq_effective_host: "{{ trento_rabbitmq_host_group is truthy
3737
| ternary(__trento_rabbitmq_discovery_host,
3838
trento_rabbitmq_host) }}"
39+
40+
# Prometheus auto-discovery
41+
__trento_prometheus_inventory_host: "{{ groups[trento_prometheus_host_group][0] }}"
42+
__trento_prometheus_ansible_host: "{{ hostvars[__trento_prometheus_inventory_host].ansible_host }}"
43+
__trento_prometheus_discovery_host: "{{ (inventory_hostname in groups[trento_prometheus_host_group])
44+
| ternary('127.0.0.1',
45+
__trento_prometheus_ansible_host | default(__trento_prometheus_inventory_host)) }}"
46+
trento_prometheus_effective_host: "{{ trento_prometheus_host_group is truthy
47+
| ternary(__trento_prometheus_discovery_host,
48+
trento_prometheus_host) }}"

server.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
# Explicitly call the trento role with the passed parameters to
4545
# please the linter.
4646
- role: trento
47+
run_once: true
4748
vars:
4849
trento_postgres_host_group: "{{ 'postgres_hosts' if (provision_postgres | bool) else '' }}"
4950
trento_rabbitmq_host_group: "{{ 'rabbitmq_hosts' if (provision_rabbitmq | bool) else '' }}"
51+
trento_prometheus_host_group: "{{ 'prometheus_hosts' if (provision_prometheus | bool) else '' }}"
5052

5153
- role: web
5254
become: true
@@ -57,6 +59,8 @@
5759
- role: rproxy
5860
become: true
5961
when: provision_proxy | bool
62+
vars:
63+
rproxy_provision_prometheus: "{{ provision_prometheus | bool }}"
6064

6165
- role: firewall
6266
become: true

0 commit comments

Comments
 (0)