diff --git a/monascastatsd/__init__.py b/monascastatsd/__init__.py index 9773706..0f4e57e 100644 --- a/monascastatsd/__init__.py +++ b/monascastatsd/__init__.py @@ -2,7 +2,5 @@ from monascastatsd.client import Client from monascastatsd.connection import Connection from monascastatsd.counter import Counter from monascastatsd.gauge import Gauge -from monascastatsd.histogram import Histogram from monascastatsd.metricbase import MetricBase -from monascastatsd.set import Set from monascastatsd.timer import Timer diff --git a/monascastatsd/client.py b/monascastatsd/client.py index 26c8802..aeb03f3 100644 --- a/monascastatsd/client.py +++ b/monascastatsd/client.py @@ -1,4 +1,4 @@ -# (C) Copyright 2014 Hewlett Packard Enterprise Development Company LP +# (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ from monascastatsd.connection import Connection from monascastatsd.counter import Counter from monascastatsd.gauge import Gauge -from monascastatsd.histogram import Histogram -from monascastatsd.set import Set from monascastatsd.timer import Timer @@ -66,26 +64,6 @@ class Client(object): connection=connection, dimensions=self._update_dimensions(dimensions)) - def get_histogram(self, name=None, connection=None, dimensions=None): - """Gets a Histogram object. - - """ - if connection is None: - connection = self.connection - return Histogram(name=self._update_name(name), - connection=connection, - dimensions=self._update_dimensions(dimensions)) - - def get_set(self, name=None, connection=None, dimensions=None): - """Gets a Set object. - - """ - if connection is None: - connection = self.connection - return Set(name=self._update_name(name), - connection=connection, - dimensions=self._update_dimensions(dimensions)) - def get_timer(self, name=None, connection=None, dimensions=None): """Gets a Timer object. diff --git a/monascastatsd/histogram.py b/monascastatsd/histogram.py deleted file mode 100644 index 4cfacdc..0000000 --- a/monascastatsd/histogram.py +++ /dev/null @@ -1,39 +0,0 @@ -# (C) Copyright 2014 Hewlett Packard Enterprise Development Company LP -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from monascastatsd.metricbase import MetricBase - - -class Histogram(MetricBase): - - def __init__(self, connection, name=None, dimensions=None): - super(self.__class__, self).__init__(name=name, - connection=connection, - dimensions=dimensions) - - def send(self, name, value, dimensions=None, sample_rate=1): - """Sample a histogram value, optionally setting dimensions and a - - sample rate. - - >>> monascastatsd.histogram('uploaded.file.size', 1445) - >>> monascastatsd.histogram('album.photo.count', 26, - >>> dimensions={"gender": "female"}) - """ - self._connection.report(metric=self.update_name(name), - metric_type='h', - value=value, - dimensions=self.update_dimensions(dimensions), - sample_rate=sample_rate) diff --git a/monascastatsd/set.py b/monascastatsd/set.py deleted file mode 100644 index 7c7f73f..0000000 --- a/monascastatsd/set.py +++ /dev/null @@ -1,36 +0,0 @@ -# (C) Copyright 2014 Hewlett Packard Enterprise Development Company LP -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from monascastatsd.metricbase import MetricBase - - -class Set(MetricBase): - - def __init__(self, connection, name=None, dimensions=None): - super(self.__class__, self).__init__(name=name, - connection=connection, - dimensions=dimensions) - - def send(self, name, value, dimensions=None, sample_rate=1): - """Sample a set value. - - >>> monascastatsd.set('visitors.uniques', 999) - """ - - self._connection.report(metric=self.update_name(name), - metric_type='s', - value=value, - dimensions=self.update_dimensions(dimensions), - sample_rate=sample_rate) diff --git a/monascastatsd/timer.py b/monascastatsd/timer.py index b3e76a7..8d5b6ef 100644 --- a/monascastatsd/timer.py +++ b/monascastatsd/timer.py @@ -1,4 +1,4 @@ -# (C) Copyright 2014 Hewlett Packard Enterprise Development Company LP +# (C) Copyright 2014,2016 Hewlett Packard Enterprise Development LP # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ class Timer(MetricBase): >>> monascastatsd.timing("query.response.time", 1234) """ self._connection.report(metric=self.update_name(name), - metric_type='ms', + metric_type='g', value=value, dimensions=self.update_dimensions(dimensions), sample_rate=sample_rate) diff --git a/test-requirements.txt b/test-requirements.txt index ac3198c..159a5b4 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,3 +2,5 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. hacking<0.12,>=0.11.0 # Apache-2.0 +nose # LGPL +nosexcover # BSD diff --git a/tests/test_monascastatsd.py b/tests/test_monascastatsd.py index 75e6940..547f7da 100644 --- a/tests/test_monascastatsd.py +++ b/tests/test_monascastatsd.py @@ -100,47 +100,41 @@ class TestMonascaStatsd(unittest.TestCase): dimensions={'date': '10/24', 'time': '23:00'}) counter.increment(dimensions={'country': 'canada', 'color': 'red'}) - self.assertEqual("counter_with_dims:1|c|#{'date': '10/24', 'color': 'red', " + - "'country': 'canada', 'env': 'test', 'time': '23:00'}", - self.recv(counter)) + + result = self.recv(counter) + self.assertRegexpMatches(result, "counter_with_dims:1|c|#{") + self.assertRegexpMatches(result, "'country': 'canada'") + self.assertRegexpMatches(result, "'date': '10/24'") + self.assertRegexpMatches(result, "'color': 'red'") + self.assertRegexpMatches(result, "'env': 'test'") + self.assertRegexpMatches(result, "'time': '23:00'") counter += 1 - self.assertEqual("counter_with_dims:1|c|#{'date': '10/24', 'env': 'test', 'time': '23:00'}", - self.recv(counter)) - def test_set(self): - set = self.client.get_set('set') - set.send('metric', 123) - assert self.recv(set) == "set.metric:123|s|#{'env': 'test'}" + result = self.recv(counter) + self.assertRegexpMatches(result, "counter_with_dims:1|c|#{") + self.assertRegexpMatches(result, "'date': '10/24'") + self.assertRegexpMatches(result, "'env': 'test'") + self.assertRegexpMatches(result, "'time': '23:00'") def test_gauge(self): gauge = self.client.get_gauge('gauge') gauge.send('metric', 123.4) assert self.recv(gauge) == "gauge.metric:123.4|g|#{'env': 'test'}" - def test_histogram(self): - histogram = self.client.get_histogram('histogram') - - histogram.send('metric', 123.4) - self.assertEqual("histogram.metric:123.4|h|#{'env': 'test'}", self.recv(histogram)) - def test_gauge_with_dimensions(self): gauge = self.client.get_gauge('gauge') gauge.send('gt', 123.4, dimensions={'country': 'china', 'age': 45, 'color': 'blue'}) - self.assertEqual("gauge.gt:123.4|g|#{" + - "'color': 'blue', " + - "'country': 'china', " + - "'age': 45, " + - "'env': 'test'}", - self.recv(gauge)) - def test_histogram_with_dimensions(self): - histogram = self.client.get_histogram('my_hist') - histogram.send('h', 1, dimensions={'color': 'red'}) - self.assertEqual("my_hist.h:1|h|#{'color': 'red', 'env': 'test'}", self.recv(histogram)) + result = self.recv(gauge) + self.assertRegexpMatches(result, "gauge.gt:123.4|g|#{") + self.assertRegexpMatches(result, "'country': 'china'") + self.assertRegexpMatches(result, "'age': 45") + self.assertRegexpMatches(result, "'color': 'blue'") + self.assertRegexpMatches(result, "'env': 'test'") def test_sample_rate(self): counter = self.client.get_counter('sampled_counter') @@ -164,7 +158,7 @@ class TestMonascaStatsd(unittest.TestCase): def test_timing(self): timer = self.client.get_timer() timer.timing('t', 123) - self.assertEqual("t:123|ms|#{'env': 'test'}", self.recv(timer)) + self.assertEqual("t:123|g|#{'env': 'test'}", self.recv(timer)) def test_time(self): timer = self.client.get_timer() @@ -174,7 +168,7 @@ class TestMonascaStatsd(unittest.TestCase): name_value, type_, dimensions = packet.split('|') name, value = name_value.split(':') - self.assertEqual('ms', type_) + self.assertEqual('g', type_) self.assertEqual('t', name) self.assert_almost_equal(2.0, float(value), 0.1) self.assertEqual("{'env': 'test'}", dimensions.lstrip('#')) @@ -199,7 +193,7 @@ class TestMonascaStatsd(unittest.TestCase): name_value, type_, dimensions = packet.split('|') name, value = name_value.split(':') - self.assertEqual('ms', type_) + self.assertEqual('g', type_) self.assertEqual('timed.test', name) self.assert_almost_equal(0.5, float(value), 0.1) self.assertEqual("{'env': 'test'}", dimensions.lstrip('#')) @@ -218,7 +212,7 @@ class TestMonascaStatsd(unittest.TestCase): timer.timing('timer', 123) self.client.connection.close_buffer() - self.assertEqual("site.views:123|g|#{'env': 'test'}\nsite.timer:123|ms|#{'env': 'test'}", + self.assertEqual("site.views:123|g|#{'env': 'test'}\nsite.timer:123|g|#{'env': 'test'}", self.recv(gauge)) def test_context_manager(self): @@ -229,7 +223,7 @@ class TestMonascaStatsd(unittest.TestCase): client.get_gauge('page').send('views', 123) client.get_timer('page').timing('timer', 12) - self.assertEqual('ContextTester.page.views:123|g\nContextTester.page.timer:12|ms', + self.assertEqual('ContextTester.page.views:123|g\nContextTester.page.timer:12|g', fake_socket.recv()) def test_batched_buffer_autoflush(self): diff --git a/tox.ini b/tox.ini index 25e362f..f69a91c 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,9 @@ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/test-requirements.txt whitelist_externals = bash find -commands = find . -type f -name "*.pyc" -delete +commands = + find . -type f -name "*.pyc" -delete + nosetests [testenv:pep8] commands = flake8