Example #1
0
    def test_blacklist_metrics(self, mock_publish):
        c = Collector(self.config_object(), [])
        c.config['metrics_blacklist'] = re.compile('metric1')
        dimensions = {
            'dim1': 'val1',
            'dim2': 'val2',
        }
        c.dimensions = dimensions
        c.publish('metric1', 1)

        assert not mock_publish.called
        self.assertEqual(c.dimensions, None)

        dimensions = {
            'dim3': 'val3',
            'dim4': 'val4',
        }
        c.dimensions = dimensions
        c.publish('metric2', 2)

        assert mock_publish.called

        for call in mock_publish.mock_calls:
            name, args, kwargs = call
            metric = args[0]
            self.assertEquals(metric.dimensions, dimensions)
        self.assertEqual(c.dimensions, None)
Example #2
0
 def test_failed_error_metric_publish(self, mock_publish):
     c = Collector(self.config_object(), [])
     self.assertFalse(c.can_publish_metric())
     with patch.object(c, "log"):
         try:
             c.publish("metric", "baz")
         except DiamondException:
             pass
     self.assertEquals(len(mock_publish.mock_calls), 0)
Example #3
0
 def test_failed_error_metric_publish(self, mock_publish):
     c = Collector(self.config_object(), [])
     self.assertFalse(c.can_publish_metric())
     with patch.object(c, 'log'):
         try:
             c.publish('metric', "baz")
         except DiamondException:
             pass
     self.assertEquals(len(mock_publish.mock_calls), 0)
Example #4
0
    def test_SetDimensions(self, mock_publish):
        c = Collector(self.config_object(), [])
        dimensions = {"dim1": "alice", "dim2": "chains"}
        c.dimensions = dimensions
        c.publish("metric1", 1)

        for call in mock_publish.mock_calls:
            name, args, kwargs = call
            metric = args[0]
            self.assertEquals(metric.dimensions, dimensions)
        self.assertEqual(c.dimensions, None)
Example #5
0
 def test_successful_error_metric(self, mock_publish):
     c = Collector(self.config_object(), [])
     mock_socket = Mock()
     c._socket = mock_socket
     with patch.object(c, "log"):
         try:
             c.publish("metric", "bar")
         except DiamondException:
             pass
     for call in mock_publish.mock_calls:
         name, args, kwargs = call
         metric = args[0]
         self.assertEqual(metric.path, "servers.Collector.fullerite.collector_errors")
Example #6
0
 def test_successful_error_metric(self, mock_publish):
     c = Collector(self.config_object(), [])
     mock_socket = Mock()
     c._socket = mock_socket
     with patch.object(c, 'log'):
         try:
             c.publish('metric', "bar")
         except DiamondException:
             pass
     for call in mock_publish.mock_calls:
         name, args, kwargs = call
         metric = args[0]
         self.assertEqual(metric.path, "servers.Collector.qcollect.collector_errors")
Example #7
0
    def test_SetDimensions(self, mock_publish):
        c = Collector(self.config_object(), [])
        dimensions = {
            'dim1': 'alice',
            'dim2': 'chains',
        }
        c.dimensions = dimensions
        c.publish('metric1', 1)

        for call in mock_publish.mock_calls:
            name, args, kwargs = call
            metric = args[0]
            self.assertEquals(metric.dimensions, dimensions)
        self.assertEqual(c.dimensions, None)
Example #8
0
    def test_SetDimensions(self, mock_publish):
        c = Collector(self.config_object(), [])
        dimensions = {
            'dim1': 'alice',
            'dim2': 'chains',
        }
        c.dimensions = dimensions
        c.publish('metric1', 1)

        for call in mock_publish.mock_calls:
            name, args, kwargs = call
            metric = args[0]
            self.assertEquals(metric.dimensions, dimensions)
        self.assertEqual(c.dimensions, None)
Example #9
0
 def test_batch_size_flush(self):
     c = Collector(self.config_object(), [])
     mock_socket = Mock()
     c._socket = mock_socket
     c._reconnect = False
     c.config["max_buffer_size"] = 2
     with patch.object(c, "log"):
         try:
             c.publish("metric1", 1)
             c.publish("metric2", 2)
             c.publish("metric3", 3)
         except DiamondException:
             pass
     self.assertEquals(mock_socket.sendall.call_count, 1)
     self.assertEquals(len(c.payload), 1)
Example #10
0
 def test_batch_size_flush(self):
     c = Collector(self.config_object(), [])
     mock_socket = Mock()
     c._socket = mock_socket
     c._reconnect = False
     c.config['max_buffer_size'] = 2
     with patch.object(c, 'log'):
         try:
             c.publish('metric1', 1)
             c.publish('metric2', 2)
             c.publish('metric3', 3)
         except DiamondException:
             pass
     self.assertEquals(mock_socket.sendall.call_count, 1)
     self.assertEquals(len(c.payload), 1)