Beispiel #1
0
 def test_to_series_list_dropna_false(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {u"instance": u"mock_vm_1"},
         u"values": [[1509653822, u"1.123"],
                     [1509653827, u"2.123"],
                     [1509653832, u"3.123"],
                     [1509653842, u"5.123"]]
       },
       {
         u"metric": {u"instance": u"mock_vm_0"},
         u"values": [[1509653822, u"1.234"],
                     [1509653827, u"2.234"],
                     [1509653837, u"4.234"],
                     [1509653842, u"5.234"]]
       },
     ]
   }
   s_list = prometheus.to_series_list(data, dropna=False)
   self.assertTrue(
     prometheus.to_series(data["result"][0], dropna=False).equals(s_list[0]))
   self.assertEqual("mock_vm_1", s_list[0].name)
   self.assertTrue(pandas.np.isnan(s_list[0].values[3]))
   self.assertTrue(
     prometheus.to_series(data["result"][1], dropna=False).equals(s_list[1]))
   self.assertEqual("mock_vm_0", s_list[1].name)
   self.assertTrue(pandas.np.isnan(s_list[1].values[2]))
Beispiel #2
0
 def test_to_series_default(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {u"instance": u"mock_vm_0"},
         u"values": [[1509653822, u"1.123"],
                     [1509653827, u"2.123"],
                     [1509653832, u"3.123"],
                     [1509653842, u"5.123"]]
       }
     ]
   }
   result = data["result"][0]
   s = prometheus.to_series(result)
   self.assertEqual("mock_vm_0", s.name)
   self.assertEqual(pandas.np.float64, s.dtype)
   for expected, actual in zip([1509653822,
                                1509653827,
                                1509653832,
                                1509653837,
                                1509653842], s.index):
     self.assertEqual(expected, actual)
   for expected, actual in zip([1.123,
                                2.123,
                                3.123,
                                pandas.np.nan,
                                5.123], s.values):
     if pandas.np.isnan(expected):
       self.assertTrue(pandas.np.isnan(actual))
     else:
       self.assertAlmostEqual(expected, actual)
Beispiel #3
0
 def test_to_series_values_length_one(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {u"instance": u"mock_vm_0"},
         u"values": [[1509653822, u"1.234"]]
       }
     ]
   }
   result = data["result"][0]
   s = prometheus.to_series(result)
   self.assertEqual(len(s), 1)
Beispiel #4
0
 def test_to_series_values_empty(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {u"instance": u"mock_vm_0"},
         u"values": []
       }
     ]
   }
   result = data["result"][0]
   s = prometheus.to_series(result)
   self.assertTrue(s.empty)
Beispiel #5
0
 def test_to_series_metric_empty(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {},
         u"values": [[1509653822, u"1.123"],
                     [1509653827, u"2.123"],
                     [1509653832, u"3.123"],
                     [1509653842, u"4.123"]]
       }
     ]
   }
   result = data["result"][0]
   s = prometheus.to_series(result, dropna=False)
   self.assertEqual(None, s.name)
Beispiel #6
0
 def test_to_series_dropna_false(self):
   data = {
     u"resultType": u"matrix",
     u"result": [
       {
         u"metric": {u"instance": u"mock_vm_0"},
         u"values": [[1509653822, u"1.123"],
                     [1509653827, u"2.123"],
                     [1509653832, u"3.123"],
                     [1509653842, u"5.123"]]
       }
     ]
   }
   result = data["result"][0]
   s = prometheus.to_series(result, dropna=False)
   # 5 instead of 4 due to gap in the index.
   self.assertEqual(5, len(s.index))
   self.assertEqual(5, len(s.values))
   self.assertTrue(pandas.np.isnan(s.values[3]))