From 352969e2d11d80b74485664737a5c0c49b87b14d Mon Sep 17 00:00:00 2001 From: Andy McCrae Date: Mon, 13 Feb 2017 15:02:05 +0000 Subject: [PATCH] Move away from include statsd.j2 The statsd.j2 include approach is great, but it is hitting an ansible bug with Jinja2==2.9.5 which hasn't been fixed with Ansible and doens't seem to be fixed anytime soon. Here is an example bug: https://github.com/ansible/ansible/issues/20494 This patch also refactors the statsd.j2 import parts, a lot of if/else statements were not required. Change-Id: Ib78ac0a8891874b1c2e777fac8f3fb89304e6872 --- tasks/main.yml | 24 ++++++++---- templates/account-server-replicator.conf.j2 | 10 ++++- templates/account-server.conf.j2 | 10 ++++- templates/container-reconciler.conf.j2 | 10 ++++- templates/container-server-replicator.conf.j2 | 10 ++++- templates/container-server.conf.j2 | 10 ++++- templates/object-expirer.conf.j2 | 10 ++++- templates/object-server-replicator.conf.j2 | 10 ++++- templates/object-server.conf.j2 | 10 ++++- templates/proxy-server.conf.j2 | 37 ++++--------------- templates/statsd.j2 | 32 ---------------- 11 files changed, 95 insertions(+), 78 deletions(-) delete mode 100644 templates/statsd.j2 diff --git a/tasks/main.yml b/tasks/main.yml index 37b118cd..d68751d5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -31,6 +31,22 @@ tags: - swift-config +# We need swift_vars to exist for the "swift_vars.* is defined check" to work +- name: "Set swift_vars if undefined" + set_fact: + swift_vars: "{}" + when: swift_vars is not defined + tags: + - always + +# We need swift_proxy_vars to exist for the "swift_proxy_vars.* is defined check" to work +- name: "Set swift_proxy_vars if undefined" + set_fact: + swift_proxy_vars: "{}" + when: swift_proxy_vars is not defined + tags: + - always + - include: swift_pre_install.yml when: - swift_do_setup | bool @@ -52,14 +68,6 @@ tags: - swift-config -# We need swift_vars to exist for the "swift_vars.drives is defined check" to work -- name: "Set swift_vars if undefined" - set_fact: - swift_vars: "{}" - when: swift_vars is not defined - tags: - - always - - include: swift_calculate_addresses.yml when: - inventory_hostname in groups['swift_hosts'] diff --git a/templates/account-server-replicator.conf.j2 b/templates/account-server-replicator.conf.j2 index 05c75a82..f3b66140 100644 --- a/templates/account-server-replicator.conf.j2 +++ b/templates/account-server-replicator.conf.j2 @@ -11,7 +11,15 @@ bind_port = {{ swift_account_port }} devices = {{ swift_vars.mount_point | default(swift.mount_point) }} workers = {{ swift_account_server_replicator_workers | default(api_threads) }} log_facility = LOG_LOCAL2 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} [pipeline:main] pipeline = account-server diff --git a/templates/account-server.conf.j2 b/templates/account-server.conf.j2 index 5fb76344..78384850 100644 --- a/templates/account-server.conf.j2 +++ b/templates/account-server.conf.j2 @@ -13,7 +13,15 @@ workers = {{ swift_account_server_workers | default(api_threads) }} user = {{ swift_system_user_name }} devices = {{ swift_vars.mount_point | default(swift.mount_point) }} log_facility = LOG_LOCAL2 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} disable_fallocate = {{ swift_account_disable_fallocate }} fallocate_reserve = {{ swift_account_fallocate_reserve }} diff --git a/templates/container-reconciler.conf.j2 b/templates/container-reconciler.conf.j2 index 2b3b20c6..2e8f4a93 100644 --- a/templates/container-reconciler.conf.j2 +++ b/templates/container-reconciler.conf.j2 @@ -6,7 +6,15 @@ use_stderr = False swift_dir = /etc/swift user = {{ swift_system_user_name }} log_facility = LOG_LOCAL3 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} [container-reconciler] # The reconciler will re-attempt reconciliation if the source object is not diff --git a/templates/container-server-replicator.conf.j2 b/templates/container-server-replicator.conf.j2 index 309cbcea..8edb9b64 100644 --- a/templates/container-server-replicator.conf.j2 +++ b/templates/container-server-replicator.conf.j2 @@ -11,7 +11,15 @@ bind_port = {{ swift_container_port }} devices = {{ swift_vars.mount_point | default(swift.mount_point) }} workers = {{ swift_server_replicator_workers | default(api_threads) }} log_facility = LOG_LOCAL3 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} [pipeline:main] pipeline = container-server diff --git a/templates/container-server.conf.j2 b/templates/container-server.conf.j2 index 3b29dab0..a71b3a60 100644 --- a/templates/container-server.conf.j2 +++ b/templates/container-server.conf.j2 @@ -13,7 +13,15 @@ workers = {{ swift_container_server_workers | default(api_threads) }} user = {{ swift_system_user_name }} devices = {{ swift_vars.mount_point | default(swift.mount_point) }} log_facility = LOG_LOCAL3 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} disable_fallocate = {{ swift_container_disable_fallocate }} fallocate_reserve = {{ swift_container_fallocate_reserve }} diff --git a/templates/object-expirer.conf.j2 b/templates/object-expirer.conf.j2 index 7a5e579c..4908691b 100644 --- a/templates/object-expirer.conf.j2 +++ b/templates/object-expirer.conf.j2 @@ -6,7 +6,15 @@ use_stderr = False swift_dir = /etc/swift user = {{ swift_system_user_name }} log_facility = LOG_LOCAL4 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} [object-expirer] interval = 300 diff --git a/templates/object-server-replicator.conf.j2 b/templates/object-server-replicator.conf.j2 index 6873c46b..b83155a0 100644 --- a/templates/object-server-replicator.conf.j2 +++ b/templates/object-server-replicator.conf.j2 @@ -11,7 +11,15 @@ bind_port = {{ swift_object_port }} devices = {{ swift_vars.mount_point | default(swift.mount_point) }} workers = {{ swift_object_replicator_workers | default(api_threads) }} log_facility = LOG_LOCAL4 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} [pipeline:main] pipeline = object-server diff --git a/templates/object-server.conf.j2 b/templates/object-server.conf.j2 index f9ece71d..76f7c28c 100644 --- a/templates/object-server.conf.j2 +++ b/templates/object-server.conf.j2 @@ -14,7 +14,15 @@ user = {{ swift_system_user_name }} swift_dir = /etc/swift devices = {{ swift_vars.mount_point | default(swift.mount_point) }} log_facility = LOG_LOCAL4 -{% include "statsd.j2" %} + +{% set _statsd_host = swift_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} +{% endif %} disable_fallocate = {{ swift_object_disable_fallocate }} fallocate_reserve = {{ swift_object_fallocate_reserve }} diff --git a/templates/proxy-server.conf.j2 b/templates/proxy-server.conf.j2 index 758e9f63..2001efe6 100644 --- a/templates/proxy-server.conf.j2 +++ b/templates/proxy-server.conf.j2 @@ -13,36 +13,13 @@ workers = {{ swift_proxy_server_workers | default(api_threads) }} user = {{ swift_system_user_name }} log_facility = LOG_LOCAL1 -{% if swift_proxy_vars is defined %} -{% if swift_proxy_vars.statsd_host is defined %} -{% set statsd = 1 %} -log_statsd_host = {{ swift_proxy_vars.statsd_host | default(statsd_host) }} -{% elif swift.statsd_host is defined %} -{% set statsd = 1 %} -log_statsd_host = {{ swift.statsd_host | default(statsd_host) }} -{% endif %} -{% if statsd is defined %} -{% if swift_proxy_vars.statsd_port is defined %} -log_statsd_port = {{ swift_proxy_vars.statsd_port }} -{% else %} -log_statsd_port = {{ swift.statsd_port | default(statsd_port) }} -{% endif %} -{% if swift_proxy_vars.statsd_default_sample_rate is defined %} -log_statsd_default_sample_rate = {{ swift_proxy_vars.statsd_default_sample_rate }} -{% else %} -log_statsd_default_sample_rate = {{ swift.statsd_default_sample_rate | default(statsd_default_sample_rate) }} -{% endif %} -{% if swift_proxy_vars.statsd_sample_rate_factor is defined %} -log_statsd_sample_rate_factor = {{ swift_proxy_vars.statsd_sample_rate_factor }} -{% else %} -log_statsd_sample_rate_factor = {{ swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor) }} -{% endif %} -{% if swift_proxy_vars.statsd_metric_prefix is defined %} -log_statsd_metric_prefix = {{ swift_proxy_vars.statsd_metric_prefix }} -{% else %} -log_statsd_metric_prefix = {{ swift.statsd_metric_prefix | default(inventory_hostname) }} -{% endif %} -{% endif %} +{% set _statsd_host = swift_proxy_vars.statsd_host | default(swift.statsd_host | default(statsd_host | default(False))) %} +{% if _statsd_host | bool %} +log_statsd_host = {{ _statsd_host }} +log_statsd_port = {{ swift_proxy_vars.statsd_port | default(swift.statsd_port | default(statsd_port)) }} +log_statsd_default_sample_rate = {{ swift_proxy_vars.statsd_default_sample_rate | default(swift.statsd_default_sample_rate | default(statsd_default_sample_rate)) }} +log_statsd_sample_rate_factor = {{ swift_proxy_vars.statsd_sample_rate_factor | default(swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor))}} +log_statsd_metric_prefix = {{ swift_proxy_vars.statsd_metric_prefix | default(swift.statsd_metric_prefix | default(inventory_hostname)) }} {% endif %} [pipeline:main] diff --git a/templates/statsd.j2 b/templates/statsd.j2 deleted file mode 100644 index b4a9e53c..00000000 --- a/templates/statsd.j2 +++ /dev/null @@ -1,32 +0,0 @@ - -{% if swift_vars is defined %} -{% if swift_vars.statsd_host is defined %} -{% set statsd = 1 %} -log_statsd_host = {{ swift_vars.statsd_host | default(statsd_host) }} -{% elif swift.statsd_host is defined %} -{% set statsd =1 %} -log_statsd_host = {{ swift.statsd_host | default(statsd_host) }} -{% endif %} -{% if statsd is defined %} -{% if swift_vars.statsd_port is defined %} -log_statsd_port = {{ swift_vars.statsd_port }} -{% else %} -log_statsd_port = {{ swift.statsd_port | default(statsd_port) }} -{% endif %} -{% if swift_vars.statsd_default_sample_rate is defined %} -log_statsd_default_sample_rate = {{ swift_vars.statsd_default_sample_rate }} -{% else %} -log_statsd_default_sample_rate = {{ swift.statsd_default_sample_rate | default(statsd_default_sample_rate) }} -{% endif %} -{% if swift_vars.statsd_sample_rate_factor is defined %} -log_statsd_sample_rate_factor = {{ swift_vars.statsd_sample_rate_factor }} -{% else %} -log_statsd_sample_rate_factor = {{ swift.statsd_sample_rate_factor | default(statsd_sample_rate_factor) }} -{% endif %} -{% if swift_vars.statsd_metric_prefix is defined %} -log_statsd_metric_prefix = {{ swift_vars.statsd_metric_prefix }} -{% else %} -log_statsd_metric_prefix = {{ swift.statsd_metric_prefix | default(inventory_hostname) }} -{% endif %} -{% endif %} -{% endif %}