def test_es_log_extra_argument_insertion(self): self.log.info("About to test elasticsearch insertion") handler = CMRESHandler(hosts=[{ 'host': self.getESHost(), 'port': self.getESPort() }], auth_type=CMRESHandler.AuthType.NO_AUTH, use_ssl=False, es_index_name="pythontest", es_additional_fields={ 'App': 'Test', 'Environment': 'Dev' }, raise_on_indexing_exceptions=True) es_test_server_is_up = handler.test_es_source() self.log.info( "ES services status is: {0!s}".format(es_test_server_is_up)) self.assertEqual(True, es_test_server_is_up) log = logging.getLogger("PythonTest") log.addHandler(handler) log.warning("Extra arguments Message", extra={ "Arg1": 300, "Arg2": 400 }) self.assertEqual(1, len(handler._buffer)) self.assertEqual(handler._buffer[0]['Arg1'], 300) self.assertEqual(handler._buffer[0]['Arg2'], 400) self.assertEqual(handler._buffer[0]['App'], 'Test') self.assertEqual(handler._buffer[0]['Environment'], 'Dev') handler.flush() self.assertEqual(0, len(handler._buffer))
def test_fast_insertion_of_hundred_logs(self): handler = CMRESHandler(hosts=[{'host': self.getESHost(), 'port': self.getESPort()}], auth_type=CMRESHandler.AuthType.NO_AUTH, use_ssl=False, buffer_size=500, flush_frequency_in_sec=0.5, es_index_name="pythontest", raise_on_indexing_exceptions=True) log = logging.getLogger("PythonTest") log.setLevel(logging.DEBUG) log.addHandler(handler) for i in range(100): log.info("Logging line {0:d}".format(i), extra={'LineNum': i}) handler.flush() self.assertEqual(0, len(handler._buffer))
def test_fast_insertion_of_hundred_logs(self): handler = CMRESHandler(hosts=[{'host': self.getESHost(), 'port': self.getESPort()}], auth_type=CMRESHandler.AuthType.NO_AUTH, use_ssl=False, buffer_size=500, flush_frequency_in_sec=0.5, es_index_name="pythontest", raise_on_indexing_exceptions=True) log = logging.getLogger("PythonTest") log.setLevel(logging.DEBUG) log.addHandler(handler) for i in range(100): log.info("Logging line {0:d}".format(i), extra={'LineNum': i}) handler.flush() self.assertEqual(0, len(handler._buffer))
def test_new_index_has_messages(self): index_name = "pythontest-index-messages" handler = CMRESHandler(hosts=[{ 'host': self.getESHost(), 'port': self.getESPort() }], auth_type=CMRESHandler.AuthType.NO_AUTH, use_ssl=False, es_index_name=index_name, es_additional_fields={ 'App': 'Test', 'Environment': 'Dev' }, raise_on_indexing_exceptions=True) message = "Specific message %s" es_test_server_is_up = handler.test_es_source() index = handler._index_name_func.__func__(index_name) client = handler._client client.indices.delete(index, ignore=404) self.log.info( "ES services status is: {0!s}".format(es_test_server_is_up)) self.assertEqual(True, es_test_server_is_up) log = logging.getLogger("PythonTest") log.setLevel(logging.DEBUG) log.addHandler(handler) log.info(message, 1) log.info(message, 'str') handler.flush() self.assertEqual(0, len(handler._buffer)) # Wait a little while elasticsearch creating mapping and indexing messages time.sleep(1) self.assertEqual( 2, client.search(index, body={"query": { "match": { 'message': message } }})['hits']['total']) handler.close()
def test_es_log_extra_argument_insertion(self): self.log.info("About to test elasticsearch insertion") handler = CMRESHandler(hosts=[{'host': 'localhost', 'port': 9200}], auth_type=CMRESHandler.AuthType.NO_AUTH, use_ssl=False, es_index_name="pythontest", es_additional_fields={'App': 'Test', 'Environment': 'Dev'}) es_test_server_is_up = handler.test_es_source() self.log.info("ES services status is: {0!s}".format(es_test_server_is_up)) self.assertEquals(True, es_test_server_is_up) log = logging.getLogger("PythonTest") log.addHandler(handler) log.warning("Extra arguments Message", extra={"Arg1": 300, "Arg2": 400}) self.assertEquals(1, len(handler._buffer)) self.assertEquals(handler._buffer[0]['Arg1'], 300) self.assertEquals(handler._buffer[0]['Arg2'], 400) self.assertEquals(handler._buffer[0]['App'], 'Test') self.assertEquals(handler._buffer[0]['Environment'], 'Dev') handler.flush() self.assertEquals(0, len(handler._buffer))