diff --git a/config.yaml b/config.yaml index 40a9751..0df9bd9 100644 --- a/config.yaml +++ b/config.yaml @@ -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. diff --git a/lib/swift_context.py b/lib/swift_context.py index 3374f0f..396c465 100644 --- a/lib/swift_context.py +++ b/lib/swift_context.py @@ -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') diff --git a/templates/grizzly/proxy-server.conf b/templates/grizzly/proxy-server.conf index 3a00248..8215002 100644 --- a/templates/grizzly/proxy-server.conf +++ b/templates/grizzly/proxy-server.conf @@ -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 diff --git a/templates/havana/proxy-server.conf b/templates/havana/proxy-server.conf index dbf714e..bc651f1 100644 --- a/templates/havana/proxy-server.conf +++ b/templates/havana/proxy-server.conf @@ -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 diff --git a/templates/icehouse/proxy-server.conf b/templates/icehouse/proxy-server.conf index a5f0173..3c83612 100644 --- a/templates/icehouse/proxy-server.conf +++ b/templates/icehouse/proxy-server.conf @@ -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 }} diff --git a/templates/kilo/proxy-server.conf b/templates/kilo/proxy-server.conf index a57e66c..51dc2fd 100644 --- a/templates/kilo/proxy-server.conf +++ b/templates/kilo/proxy-server.conf @@ -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 }} diff --git a/templates/mitaka/proxy-server.conf b/templates/mitaka/proxy-server.conf index 2bfa305..52e7035 100644 --- a/templates/mitaka/proxy-server.conf +++ b/templates/mitaka/proxy-server.conf @@ -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 -%} \ No newline at end of file +{% endif -%} diff --git a/unit_tests/test_templates.py b/unit_tests/test_templates.py index 294704d..428994c 100644 --- a/unit_tests/test_templates.py +++ b/unit_tests/test_templates.py @@ -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)