Exemplo n.º 1
0
 def test_add_id(self):
     log_item = LogItem()
     doc = {
         "_id": 1,
         "_source": {},
         "_index": "all_data_types",
         "_type": "_doc"
     }
     DocLogItemConverter._add_id(doc, log_item)
     self.assertSetEqual({("_id", "1")}, set(log_item.contents))
Exemplo n.º 2
0
 def test_to_log_item(self):
     log_item = DocLogItemConverter.to_log_item(self.doc, "es_date")
     self.assertEqual(1532354400, log_item.get_time())
     excepted_contents = [
         ('es_short', '-2'), ('es_boolean', 'true'),
         ('__tag__:__es_index__', 'all_data_types'),
         ('__tag__:__es_type__', '_doc'), ('es_ip_range', '192.168.0.0/16'),
         ('es_double_range', '{"gte": 1.23}'), ('es_long', '1'),
         ('es_integer_range', '{"gte": 10, "lte": 20}'), ('_id', '1'),
         ('es_binary', 'U29tZSBiaW5hcnkgYmxvYg=='),
         ('es_geo_shape',
          '{"type": "point", "coordinates": [-77.03653, 38.897676]}'),
         ('es_byte', '127'),
         ('es_geo_point', '{"lat": 41.12, "lon": -71.34}'),
         ('es_long_range', '{"lt": 20}'), ('es_scaled_float', '12.3456789'),
         ('es_half_float', '12.3456789'),
         ('es_date_range',
          '{"gte": "2015-10-31 12:00:00", "lte": "2015-11-01"}'),
         ('es_double', '12.3456789'), ('es_array', "['x', 'y', 'z']"),
         ('es_float', '-3.14'), ('es_keyword', 'es_keyword'),
         ('es_object', '{"sub_double_range": {"lt": 4.56, "gt": 1.23}, '
          '"sub_long": 123, '
          '"sub_double": 12.345, '
          '"sub_object": {"sub_sub_text": "sub_sub_text", "sub_sub_boolean": "true"}, '
          '"sub_text": "sub_text", '
          '"sub_date": 1420070400001, '
          '"sub_boolean": "false", '
          '"sub_byte": -128}'),
         ('es_float_range', '{"lt": 4.56, "gt": 1.23}'),
         ('es_text', 'es_text')
     ]
     self.assertSetEqual(set(excepted_contents),
                         set(log_item.get_contents()))
 def _put_docs(self, docs):
     if len(docs) <= 0:
         return
     logitems = [
         DocLogItemConverter.to_log_item(doc, self._time_reference)
         for doc in docs
     ]
     self._logstore.put_logs(logitems)
Exemplo n.º 4
0
 def test_add_type_without_index_field(self):
     log_item = LogItem()
     doc = {"_id": 1, "_source": {}, "_index": "all_data_types"}
     DocLogItemConverter._add_type(doc, log_item)
     self.assertSetEqual(set(), set(log_item.contents))
Exemplo n.º 5
0
 def test_add_type(self):
     log_item = LogItem()
     doc = {"_type": "_doc"}
     DocLogItemConverter._add_type(doc, log_item)
     self.assertSetEqual({("__tag__:__es_type__", "_doc")},
                         set(log_item.contents))
Exemplo n.º 6
0
 def test_add_index(self):
     log_item = LogItem()
     doc = {"_index": "index1"}
     DocLogItemConverter._add_index(doc, log_item)
     self.assertSetEqual({("__tag__:__es_index__", "index1")},
                         set(log_item.contents))
Exemplo n.º 7
0
 def test_get_index(self):
     index = DocLogItemConverter.get_index(self.doc)
     self.assertEqual("all_data_types", index)
Exemplo n.º 8
0
 def test_to_log_item(self):
     log_item = DocLogItemConverter.to_log_item(self.doc, "es_date")
     self.assertEqual(1532354400, log_item.get_time())