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)
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)
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)
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)
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")
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")
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)
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)
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)