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
This commit is contained in:
Andy McCrae 2017-02-13 15:02:05 +00:00
parent 7406ce4e82
commit 352969e2d1
11 changed files with 95 additions and 78 deletions

View File

@ -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']

View File

@ -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

View File

@ -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 }}

View File

@ -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

View File

@ -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

View File

@ -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 }}

View File

@ -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

View File

@ -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

View File

@ -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 }}

View File

@ -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]

View File

@ -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 %}