From 374cbfd936bec13d35991e8e5bc917ec6ff0b214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Tudur=C3=AD?= Date: Mon, 2 May 2016 12:56:07 +0200 Subject: [PATCH] ElasticBackend now can be configured passing a list of 'hosts' or a list of 'connection_urls'. --- kaneda/backends/elasticsearch.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kaneda/backends/elasticsearch.py b/kaneda/backends/elasticsearch.py index 763cd28..f6d122c 100644 --- a/kaneda/backends/elasticsearch.py +++ b/kaneda/backends/elasticsearch.py @@ -17,11 +17,13 @@ class ElasticsearchBackend(BaseBackend): """ Elasticsearch backend. - :param index_name: name of the Elasticsearch index used to store metrics data. Default name format will be app_name-YYYY.MM.DD. + :param index_name: name of the Elasticsearch index used to store metrics data. Default name format will be \ + index_name-YYYY.MM.DD. :param app_name: name of the app/project where metrics are used. :param client: client instance of Elasticsearch class. - :param connection_url: Elasticsearch connection url (https://user:secret@localhost:9200). - :param host: server host. + :param connection_url: Elasticsearch connection url (https://user:secret@localhost:9200). \ + It can be used passing a single connection_url (a string) or passing multiple connection_urls (a list). + :param host: server host. It can be used passing a single host (a string) or passing multiple hosts (a list). :param port: server port. :param username: http auth username. :param password: http auth password. @@ -38,9 +40,13 @@ def __init__(self, index_name, app_name, client=None, connection_url=None, host= raise ImproperlyConfigured('"client" parameter is not an instance of Elasticsearch client') self.client = client elif connection_url: - self.client = Elasticsearch([connection_url], timeout=timeout) + if not isinstance(connection_url, list): + connection_url = [connection_url] + self.client = Elasticsearch(connection_url, timeout=timeout) else: - self.client = Elasticsearch([host], port=port, http_auth=(username, password), timeout=timeout) + if not isinstance(host, list): + host = [host] + self.client = Elasticsearch(host, port=port, http_auth=(username, password), timeout=timeout) self.index_name = index_name self.app_name = app_name