Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout parameters passed to Elasticsearch object #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions cmreslogging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class IndexNameFrequency(Enum):
__DEFAULT_ES_DOC_TYPE = 'python_log'
__DEFAULT_RAISE_ON_EXCEPTION = False
__DEFAULT_TIMESTAMP_FIELD_NAME = "timestamp"
__DEFAULT_ES_RETRY_ON_TIMEOUT = False
__DEFAULT_ES_TIMEOUT = 10

__LOGGING_FILTER_FIELDS = ['msecs',
'relativeCreated',
Expand Down Expand Up @@ -138,7 +140,9 @@ def __init__(self,
es_doc_type=__DEFAULT_ES_DOC_TYPE,
es_additional_fields=__DEFAULT_ADDITIONAL_FIELDS,
raise_on_indexing_exceptions=__DEFAULT_RAISE_ON_EXCEPTION,
default_timestamp_field_name=__DEFAULT_TIMESTAMP_FIELD_NAME):
default_timestamp_field_name=__DEFAULT_TIMESTAMP_FIELD_NAME,
es_retry_on_timeout=__DEFAULT_ES_RETRY_ON_TIMEOUT,
es_timeout=__DEFAULT_ES_TIMEOUT):
""" Handler constructor

:param hosts: The list of hosts that elasticsearch clients will connect. The list can be provided
Expand Down Expand Up @@ -172,6 +176,10 @@ def __init__(self,
to the logs, such the application, environment, etc.
:param raise_on_indexing_exceptions: A boolean, True only for debugging purposes to raise exceptions
caused when
:param es_retry_on_timeout: A bool value, passed to Elasticsearch object. Specifies if bulk_send retry
kusha marked this conversation as resolved.
Show resolved Hide resolved
sending logs after timeout.
:param es_timeout: An integer value, in seconds, passed to Elasticsearch object. Specifies client-side
kusha marked this conversation as resolved.
Show resolved Hide resolved
timeout when performing bulk_send.
:return: A ready to be used CMRESHandler.
"""
logging.Handler.__init__(self)
Expand All @@ -194,6 +202,8 @@ def __init__(self,
'host_ip': socket.gethostbyname(socket.gethostname())})
self.raise_on_indexing_exceptions = raise_on_indexing_exceptions
self.default_timestamp_field_name = default_timestamp_field_name
self.es_retry_on_timeout = es_retry_on_timeout
self.es_timeout = es_timeout

self._client = None
self._buffer = []
Expand All @@ -215,7 +225,9 @@ def __get_es_client(self):
use_ssl=self.use_ssl,
verify_certs=self.verify_certs,
connection_class=RequestsHttpConnection,
serializer=self.serializer)
serializer=self.serializer,
retry_on_timeout=self.es_retry_on_timeout,
timeout=self.es_timeout)
return self._client

if self.auth_type == CMRESHandler.AuthType.BASIC_AUTH:
Expand All @@ -225,7 +237,9 @@ def __get_es_client(self):
use_ssl=self.use_ssl,
verify_certs=self.verify_certs,
connection_class=RequestsHttpConnection,
serializer=self.serializer)
serializer=self.serializer,
retry_on_timeout=self.es_retry_on_timeout,
timeout=self.es_timeout)
return self._client

if self.auth_type == CMRESHandler.AuthType.KERBEROS_AUTH:
Expand All @@ -237,7 +251,9 @@ def __get_es_client(self):
verify_certs=self.verify_certs,
connection_class=RequestsHttpConnection,
http_auth=HTTPKerberosAuth(mutual_authentication=DISABLED),
serializer=self.serializer)
serializer=self.serializer,
retry_on_timeout=self.es_retry_on_timeout,
timeout=self.es_timeout)

if self.auth_type == CMRESHandler.AuthType.AWS_SIGNED_AUTH:
if not AWS4AUTH_SUPPORTED:
Expand All @@ -250,8 +266,9 @@ def __get_es_client(self):
use_ssl=self.use_ssl,
verify_certs=True,
connection_class=RequestsHttpConnection,
serializer=self.serializer
)
serializer=self.serializer,
retry_on_timeout=self.es_retry_on_timeout,
timeout=self.es_timeout)
return self._client

raise ValueError("Authentication method not supported")
Expand Down