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_series_list_to_result_pbs_order_by_instance(self):
        data = {
            u"resultType":
            u"matrix",
            u"result": [{
                u"metric": {
                    u"instance": u"fake_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"fake_vm_0"
                },
                u"values": [[1509653823, u"2.123"], [1509653828, u"3.123"],
                            [1509653833, u"4.123"], [1509653843, u"6.123"]]
            }]
        }
        series_list = prometheus.to_series_list(data, dropna=False)
        result = VMGroupResult(self.scenario,
                               "fake_result",
                               self.vm_group,
                               result_type="bandwidth")
        ret = result.series_list_to_result_pbs(series_list)

        self.assertEqual("fake_result (VM 0)", ret[0].name)
        unpickled_x = pickle.loads(
            ret[0].data_2d.pickled_2d_data.x_vals_pickled)
        unpickled_y = pickle.loads(
            ret[0].data_2d.pickled_2d_data.y_vals_pickled)
        self.assertEqual(
            [1509653823, 1509653828, 1509653833, 1509653838, 1509653843],
            unpickled_x)
        for expected, y in zip([2.123, 3.123, 4.123, None, 6.123],
                               unpickled_y):
            self.assertAlmostEqual(y, expected)

        self.assertEqual("fake_result (VM 1)", ret[1].name)
        unpickled_x = pickle.loads(
            ret[1].data_2d.pickled_2d_data.x_vals_pickled)
        unpickled_y = pickle.loads(
            ret[1].data_2d.pickled_2d_data.y_vals_pickled)
        self.assertEqual(
            [1509653822, 1509653827, 1509653832, 1509653837, 1509653842],
            unpickled_x)
        for expected, y in zip([1.123, 2.123, 3.123, None, 5.123],
                               unpickled_y):
            self.assertAlmostEqual(y, expected)
Beispiel #3
0
 def get_result_pbs(self):
     """
 Produce the results for a given VM Group.
 """
     if not self.scenario.prometheus_address:
         log.debug("Unable to get protobufs from VMGroupResult: "
                   "scenario.prometheus_address not configured")
         return []
     host, port = self.scenario.prometheus_address.split(":")
     prometheus_adapter = prometheus.PrometheusAdapter(host=host, port=port)
     if self.workload_mask:
         run_start = self.workload_mask.iogen().get_workload_start_time()
         run_end = self.workload_mask.iogen().get_workload_end_time()
     else:
         run_start = self.scenario.phase_start_time_secs(Phase.RUN)
         run_end = self.scenario.phase_start_time_secs(Phase.TEARDOWN)
     if not run_start:
         return []
     if self.result_type == "iops":
         data = prometheus_adapter.get_disk_ops(self.vm_group,
                                                run_start,
                                                run_end,
                                                agg_func=self.aggregate,
                                                step=self.step)
     elif self.result_type == "bandwidth":
         data = prometheus_adapter.get_disk_octets(self.vm_group,
                                                   run_start,
                                                   run_end,
                                                   agg_func=self.aggregate,
                                                   step=self.step)
     elif self.result_type == "latency":
         data = prometheus_adapter.get_avg_disk_latency(
             self.vm_group,
             run_start,
             run_end,
             agg_func=self.aggregate,
             step=self.step)
     elif self.result_type == "generic":
         data = prometheus_adapter.get_generic(self.vm_group,
                                               run_start,
                                               run_end,
                                               query=self.kwargs["query"],
                                               agg_func=self.aggregate,
                                               step=self.step)
     else:
         raise ValueError("Unexpected result_type %r" % self.result_type)
     return self.series_list_to_result_pbs(prometheus.to_series_list(data))