コード例 #1
0
ファイル: _monitoring.py プロジェクト: zomglings/pydatalab
def _monitoring_metrics_list(args, _):
    """Lists the metric descriptors in the project."""
    project_id = args['project']
    pattern = args['type'] or '*'
    descriptors = gcm.MetricDescriptors(context=_make_context(project_id))
    dataframe = descriptors.as_dataframe(pattern=pattern)
    return _render_dataframe(dataframe)
コード例 #2
0
ファイル: metric_tests.py プロジェクト: snaik/pydatalab
    def test_constructor_minimal(self, mock_context_default):
        mock_context_default.return_value = self.context

        descriptors = gcm.MetricDescriptors()

        self.assertEqual(descriptors._client.project, DEFAULT_PROJECT)

        self.assertIsNone(descriptors._filter_string)
        self.assertIsNone(descriptors._type_prefix)
        self.assertIsNone(descriptors._descriptors)
コード例 #3
0
ファイル: metric_tests.py プロジェクト: snaik/pydatalab
    def test_constructor_maximal(self):
        context = self._create_context(PROJECT)
        descriptors = gcm.MetricDescriptors(filter_string=FILTER_STRING,
                                            type_prefix=TYPE_PREFIX,
                                            context=context)

        self.assertEqual(descriptors._client.project, PROJECT)

        self.assertEqual(descriptors._filter_string, FILTER_STRING)
        self.assertEqual(descriptors._type_prefix, TYPE_PREFIX)
        self.assertIsNone(descriptors._descriptors)
コード例 #4
0
    def test_list_w_api_filter(self, mock_gcloud_list_descriptors):
        mock_gcloud_list_descriptors.return_value = self._list_metrics_get_result(
            context=self.context)

        descriptors = gcm.MetricDescriptors(filter_string=FILTER_STRING,
                                            type_prefix=TYPE_PREFIX,
                                            context=self.context)
        metric_descriptor_list = descriptors.list()

        mock_gcloud_list_descriptors.assert_called_once_with(
            filter_string=FILTER_STRING, type_prefix=TYPE_PREFIX)
        self.assertEqual(len(metric_descriptor_list), 2)
        self.assertEqual(metric_descriptor_list[0].type, METRIC_TYPES[0])
        self.assertEqual(metric_descriptor_list[1].type, METRIC_TYPES[1])
コード例 #5
0
ファイル: metric_tests.py プロジェクト: snaik/pydatalab
    def test_list_w_api_filter(self, mock_gcloud_list_descriptors):
        mock_gcloud_list_descriptors.return_value = self._list_metrics_get_result(
            context=self.context)

        descriptors = gcm.MetricDescriptors(filter_string=FILTER_STRING,
                                            type_prefix=TYPE_PREFIX,
                                            context=self.context)
        metric_descriptor_list = descriptors.list()

        expected_filter = '{} AND metric.type = starts_with("{}")'.format(
            FILTER_STRING, TYPE_PREFIX)

        mock_gcloud_list_descriptors.assert_called_once_with(
            DEFAULT_PROJECT, filter_=expected_filter)
        self.assertEqual(len(metric_descriptor_list), 2)
        self.assertEqual(metric_descriptor_list[0].type, METRIC_TYPES[0])
        self.assertEqual(metric_descriptor_list[1].type, METRIC_TYPES[1])
コード例 #6
0
 def setUp(self):
     self.context = self._create_context(DEFAULT_PROJECT)
     self.descriptors = gcm.MetricDescriptors(context=self.context)