def test_record_summary_metric(self):
   self.options['spectator'] = {'summarize_compound_kinds': True}
   self.service = stackdriver_service.StackdriverMetricsService(
       lambda: self.mockStub, self.options)
   bucketOptions = {
       'explicitBuckets': {'bounds': [0]}
   }
   self._do_test_add_metric('Timer', 'CUMULATIVE', 'DISTRIBUTION',
                            {'count': 4, 'totalTime': 201},
                            {'distributionValue': {
                                'bucketOptions': bucketOptions,
                                'bucketCounts': [4],
                                'count': 4,
                                'mean': 50.25
                            }})
Esempio n. 2
0
    def __do_setup(self):
        project = 'test-project'
        instance = 'test-instance'
        options = {
            'project': project,
            'zone': 'us-central1-f',
            'instance_id': instance,
            'config_dir': '/notfound',
            'metric_filter_dir': self.filter_dir,
            'fix_stackdriver_labels_unsafe': True
        }

        self.options = options
        self.mockStub = mock.create_autospec(['projects'])
        self.mockProjects = mock.create_autospec(
            ['metricDescriptors', 'timeSeries'])
        self.mockMetricDescriptors = mock.create_autospec(
            ['create', 'delete', 'get', 'list', 'list_next'])
        self.mockTimeSeries = mock.create_autospec(['create'])
        self.mockStub.projects = Mock(return_value=self.mockProjects)
        self.mockProjects.metricDescriptors = Mock(
            return_value=self.mockMetricDescriptors)
        self.mockProjects.timeSeries = Mock(return_value=self.mockTimeSeries)

        # pylint: disable=invalid-name
        self.mockCreateTimeSeries = Mock(spec=['execute'])
        self.mockCreateDescriptor = Mock(spec=['execute'])
        self.mockGetDescriptor = Mock(spec=['execute'])
        self.mockDeleteDescriptor = Mock(spec=['execute'])
        self.mockListDescriptors = Mock(spec=['execute'])

        self.mockMetricDescriptors.create = Mock(
            return_value=self.mockCreateDescriptor)
        self.mockMetricDescriptors.delete = Mock(
            return_value=self.mockDeleteDescriptor)
        self.mockMetricDescriptors.get = Mock(
            return_value=self.mockGetDescriptor)
        self.mockMetricDescriptors.list = Mock(
            return_value=self.mockListDescriptors)
        self.mockMetricDescriptors.list_next = Mock(return_value=None)

        self.mockTimeSeries.create = Mock(
            return_value=self.mockCreateTimeSeries)
        self.service = stackdriver_service.StackdriverMetricsService(
            lambda: self.mockStub, options)
 def test_record_summary_metric(self):
     self.options['spectator'] = {'summarize_timers': True}
     self.service = stackdriver_service.StackdriverMetricsService(
         lambda: self.mockStub, self.options)
     bucketOptions = {
         'linearBuckets': {
             'numFiniteBuckets': 1,
             'offset': 50.25,
             'width': 1
         }
     }
     self._do_test_add_metric('Timer', 'CUMULATIVE', 'DISTRIBUTION', {
         'count': 4,
         'totalTime': 201
     }, {
         'distributionValue': {
             'bucketOptions': bucketOptions,
             'bucketCounts': [4],
             'count': 4,
             'mean': 50.25
         }
     })