enhancement(pushgateway): allows using multiple web listen addresses

Signed-off-by: Christian Krause <christian.krause@idiv.de>
This commit is contained in:
Christian Krause 2023-09-04 11:53:16 +02:00
parent 54d857d41b
commit 01b437147d
No known key found for this signature in database
GPG key ID: 3CD613B9A8567F58
4 changed files with 36 additions and 9 deletions

View file

@ -4,7 +4,9 @@ provisioner:
group_vars:
all:
pushgateway_binary_local_dir: "/tmp/pushgateway-linux-amd64"
pushgateway_web_listen_address: "127.0.0.1:8080"
pushgateway_web_listen_address:
- '127.0.0.1:8080'
- '127.0.1.1:8080'
pushgateway_tls_server_config:
cert_file: /etc/pushgateway/tls.cert
key_file: /etc/pushgateway/tls.key

View file

@ -3,6 +3,7 @@ __metaclass__ = type
import os
import testinfra.utils.ansible_runner
import pytest
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@ -37,10 +38,9 @@ def test_protecthome_property(host):
assert p.get("ProtectHome") == "yes"
def test_socket(host):
sockets = [
"tcp://127.0.0.1:8080"
]
for socket in sockets:
s = host.socket(socket)
assert s.is_listening
@pytest.mark.parametrize("sockets", [
"tcp://127.0.0.1:8080",
"tcp://127.0.1.1:8080",
])
def test_socket(host, sockets):
assert host.socket(sockets).is_listening

View file

@ -20,10 +20,26 @@
ansible.builtin.package_facts:
when: "not 'packages' in ansible_facts"
- name: Assert that used version supports listen address type
ansible.builtin.assert:
that:
- >-
pushgateway_web_listen_address is string
or
(
pushgateway_version is version('1.5.0', '>=') and
pushgateway_web_listen_address | type_debug == "list"
)
- name: Naive assertion of proper listen address
ansible.builtin.assert:
that:
- "':' in pushgateway_web_listen_address"
- >-
[pushgateway_web_listen_address] |
flatten |
reject('match', '.+:\\d+$') |
list |
length == 0
- name: Assert that TLS config is correct
when: pushgateway_tls_server_config | length > 0

View file

@ -16,7 +16,16 @@ ExecStart={{ pushgateway_binary_install_dir }}/pushgateway \
'--web.config=/etc/pushgateway/web_config.yml' \
{% endif %}
{% endif %}
{% if pushgateway_version is version('1.5.0', '>=') and
pushgateway_web_listen_address is iterable and
pushgateway_web_listen_address is not mapping and
pushgateway_web_listen_address is not string %}
{% for address in pushgateway_web_listen_address %}
'--web.listen-address={{ address }}' \
{% endfor %}
{% else %}
'--web.listen-address={{ pushgateway_web_listen_address }}' \
{% endif %}
'--web.telemetry-path={{ pushgateway_web_telemetry_path }}'
SyslogIdentifier=pushgateway