def test_int64_user_counter(self):
        expected_labels = {}
        expected_labels[monitoring_infos.NAMESPACE_LABEL] = "counternamespace"
        expected_labels[monitoring_infos.NAME_LABEL] = "countername"

        metric = CounterCell().get_cumulative()
        result = monitoring_infos.int64_user_counter('counternamespace',
                                                     'countername', metric)
        counter_value = monitoring_infos.extract_counter_value(result)

        self.assertEqual(0, counter_value)
        self.assertEqual(result.labels, expected_labels)
    def test_int64_counter(self):
        expected_labels = {}
        expected_labels[monitoring_infos.PCOLLECTION_LABEL] = "collectionname"
        expected_labels[monitoring_infos.PTRANSFORM_LABEL] = "ptransformname"
        expected_labels[monitoring_infos.SERVICE_LABEL] = "BigQuery"

        labels = {
            monitoring_infos.SERVICE_LABEL: "BigQuery",
        }
        metric = CounterCell().get_cumulative()
        result = monitoring_infos.int64_counter(
            monitoring_infos.API_REQUEST_COUNT_URN,
            metric,
            ptransform="ptransformname",
            pcollection="collectionname",
            labels=labels)
        counter_value = monitoring_infos.extract_counter_value(result)

        self.assertEqual(0, counter_value)
        self.assertEqual(result.labels, expected_labels)
示例#3
0
 def verify_metrics(self, cache, expected_metrics):
     infos = cache.get_monitoring_infos()
     # Reconstruct metrics dictionary from monitoring infos
     metrics = {
         info.urn.rsplit(':', 1)[1]:
         monitoring_infos.extract_gauge_value(info)[1]
         for info in infos if "_total" not in info.urn
         and info.type == monitoring_infos.LATEST_INT64_TYPE
     }
     self.assertDictEqual(metrics, expected_metrics)
     # Metrics and total metrics should be identical for a single bundle.
     # The following two gauges are not part of the total metrics:
     try:
         del metrics['capacity']
         del metrics['size']
     except KeyError:
         pass
     total_metrics = {
         info.urn.rsplit(':', 1)[1].rsplit("_total")[0]:
         monitoring_infos.extract_counter_value(info)
         for info in infos if "_total" in info.urn
         and info.type == monitoring_infos.SUM_INT64_TYPE
     }
     self.assertDictEqual(metrics, total_metrics)