Add statsd logging support to the swift-proxy charm

By default, statsd metrics can be sent by swift-proxy
for diagnostic and monitoring purposes, but are disabled
by default. This change exposes charm config settings
that allow it to be enabled by setting 'statsd_host'
to a non-empty value. 'statsd_port' and 'statsd_sample_rate'
are also supported for changing the destination port
and rate at which metrics are collected.

Closes-Bug: #1729771

Change-Id: I2d5cca233d48022073b5975c06c3da2b1896d8d9
This commit is contained in:
James Hebden 2017-11-03 14:58:24 +11:00 committed by James Hebden
parent 27c669a657
commit a11ff79fc7
8 changed files with 70 additions and 1 deletions

View File

@ -335,3 +335,22 @@ options:
type: string
default: openstack
description: Rabbitmq vhost name.
statsd-host:
default: ''
type: string
description: |
Enable statsd metrics to be sent to the specified host.
If this value is empty, statsd logging will be disabled.
statsd-port:
default: 3125
type: int
description: |
Destination port on the provided statsd host to send samples to.
Only takes effect if statsd-host is set.
statsd-sample-rate:
default: 1.0
type: float
description: |
Sample rate determines what percentage of the metric points a
client should send to the server.
Only takes effect if statsd-host is set.

View File

@ -108,6 +108,9 @@ class SwiftIdentityContext(OSContextGenerator):
'node_timeout': config('node-timeout'),
'recoverable_node_timeout': config('recoverable-node-timeout'),
'log_headers': config('log-headers'),
'statsd_host': config('statsd-host'),
'statsd_port': config('statsd-port'),
'statsd_sample_rate': config('statsd-sample-rate')
}
admin_key = leader_get('swauth-admin-key')

View File

@ -7,6 +7,12 @@ cert_file = {{ ssl_cert }}
key_file = {{ ssl_key }}
{% endif %}
{% if statsd_host %}
log_statsd_host = {{ statsd_host }}
log_statsd_port = {{ statsd_port }}
log_statsd_default_sample_rate = {{ statsd_sample_rate }}
{% endif %}
{% if auth_type == 'keystone' %}
[pipeline:main]
pipeline = healthcheck cache swift3 s3token authtoken keystone container-quotas account-quotas proxy-server

View File

@ -7,6 +7,12 @@ cert_file = {{ ssl_cert }}
key_file = {{ ssl_key }}
{% endif %}
{% if statsd_host %}
log_statsd_host = {{ statsd_host }}
log_statsd_port = {{ statsd_port }}
log_statsd_default_sample_rate = {{ statsd_sample_rate }}
{% endif %}
{% if auth_type == 'keystone' %}
[pipeline:main]
pipeline = healthcheck cache swift3 authtoken keystoneauth container-quotas account-quotas proxy-server

View File

@ -9,6 +9,12 @@ log_level = {{ log_level }}
log_address = /dev/log
log_headers = {{ log_headers }}
{% if statsd_host %}
log_statsd_host = {{ statsd_host }}
log_statsd_port = {{ statsd_port }}
log_statsd_default_sample_rate = {{ statsd_sample_rate }}
{% endif %}
{% if ssl %}
cert_file = {{ ssl_cert }}
key_file = {{ ssl_key }}

View File

@ -9,6 +9,12 @@ log_level = {{ log_level }}
log_address = /dev/log
log_headers = {{ log_headers }}
{% if statsd_host %}
log_statsd_host = {{ statsd_host }}
log_statsd_port = {{ statsd_port }}
log_statsd_default_sample_rate = {{ statsd_sample_rate }}
{% endif %}
{% if ssl %}
cert_file = {{ ssl_cert }}
key_file = {{ ssl_key }}

View File

@ -9,6 +9,12 @@ log_level = {{ log_level }}
log_address = /dev/log
log_headers = {{ log_headers }}
{% if statsd_host %}
log_statsd_host = {{ statsd_host }}
log_statsd_port = {{ statsd_port }}
log_statsd_default_sample_rate = {{ statsd_sample_rate }}
{% endif %}
{% if ssl %}
cert_file = {{ ssl_cert }}
key_file = {{ ssl_key }}
@ -132,4 +138,4 @@ url = {{ transport_url }}
driver = messagingv2
topic = notifications
log_level = WARN
{% endif -%}
{% endif -%}

View File

@ -77,3 +77,20 @@ class ProxyServerTemplateTestCase(unittest.TestCase):
result = template.render()
self.assertTrue(result.startswith("[DEFAULT]"))
def test_statsd_config_for_all_releases(self):
"""The configs contain statsd settings if statsd-host is set."""
for release in ('grizzly', 'havana', 'icehouse', 'mitaka'):
template = self.get_template_for_release(release)
result = template.render(statsd_host='127.0.0.1')
self.assertTrue("log_statsd_host" in result)
self.assertTrue("log_statsd_port" in result)
self.assertTrue("log_statsd_default_sample_rate" in result)
result = template.render()
self.assertFalse("log_statsd_host" in result)
self.assertFalse("log_statsd_port" in result)
self.assertFalse("log_statsd_default_sample_rate" in result)