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

[types removal] Specifying types in bulk requests is deprecated #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
32 changes: 23 additions & 9 deletions cmreslogging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class IndexNameFrequency(Enum):
__DEFAULT_ES_DOC_TYPE = 'python_log'
__DEFAULT_RAISE_ON_EXCEPTION = False
__DEFAULT_TIMESTAMP_FIELD_NAME = "timestamp"
__DEFAULT_ES_ACTIVE_DOC_TYPE = True

__LOGGING_FILTER_FIELDS = ['msecs',
'relativeCreated',
Expand Down Expand Up @@ -138,7 +139,8 @@ 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_active_doc_type=__DEFAULT_ES_ACTIVE_DOC_TYPE):
""" Handler constructor

:param hosts: The list of hosts that elasticsearch clients will connect. The list can be provided
Expand Down Expand Up @@ -168,6 +170,8 @@ def __init__(self,
it uses daily indices.
:param es_doc_type: A string with the name of the document type that will be used ```python_log``` used
by default
:param es_active_doc_type: For versions> = 7.0 the type function is obsolete from the index,
if you use a version that is not compatible, mark it as False, the default is True
:param es_additional_fields: A dictionary with all the additional fields that you would like to add
to the logs, such the application, environment, etc.
:param raise_on_indexing_exceptions: A boolean, True only for debugging purposes to raise exceptions
Expand All @@ -189,6 +193,7 @@ def __init__(self,
self.es_index_name = es_index_name
self.index_name_frequency = index_name_frequency
self.es_doc_type = es_doc_type
self.es_active_doc_type = es_active_doc_type
self.es_additional_fields = es_additional_fields.copy()
self.es_additional_fields.update({'host': socket.gethostname(),
'host_ip': socket.gethostbyname(socket.gethostname())})
Expand Down Expand Up @@ -289,14 +294,23 @@ def flush(self):
with self._buffer_lock:
logs_buffer = self._buffer
self._buffer = []
actions = (
{
'_index': self._index_name_func.__func__(self.es_index_name),
'_type': self.es_doc_type,
'_source': log_record
}
for log_record in logs_buffer
)
if self.self.es_active_doc_type:
actions = (
{
'_index': self._index_name_func.__func__(self.es_index_name),
'_type': self.es_doc_type,
'_source': log_record
}
for log_record in logs_buffer
)
else:
actions = (
{
'_index': self._index_name_func.__func__(self.es_index_name),
'_source': log_record
}
for log_record in logs_buffer
)
eshelpers.bulk(
client=self.__get_es_client(),
actions=actions,
Expand Down