From 893463efca488f67813e53f69882ca56a66eccd6 Mon Sep 17 00:00:00 2001 From: Olivier Vielpeau Date: Thu, 27 Jul 2017 17:32:10 -0400 Subject: [PATCH] [dogstatsd] Parse distribution metrics and ignore them Instead of failing on known but unsupported metric types, ignore these metrics and continue parsing the rest of the packet. Without this, sending a new "distribution" type metric in a datagram makes dogstatsd drop the whole datagram. This change has virtually no impact on the performance of the dogstatsd parser. --- aggregator.py | 4 ++++ tests/core/test_aggregator.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/aggregator.py b/aggregator.py index 9bbbefd5aa..247652e60a 100644 --- a/aggregator.py +++ b/aggregator.py @@ -399,6 +399,8 @@ class Aggregator(object): """ # Types of metrics that allow strings ALLOW_STRINGS = ['s', ] + # Types that are not implemented and ignored + IGNORE_TYPES = ['d', ] def __init__(self, hostname, interval=1.0, expiry_seconds=300, formatter=None, recent_point_threshold=None, @@ -472,6 +474,8 @@ def parse_metric_packet(self, packet): if metric_type in self.ALLOW_STRINGS: value = raw_value + elif metric_type in self.IGNORE_TYPES: + continue else: # Try to cast as an int first to avoid precision issues, then as a # float. diff --git a/tests/core/test_aggregator.py b/tests/core/test_aggregator.py index b2d58d9808..8b95205b49 100644 --- a/tests/core/test_aggregator.py +++ b/tests/core/test_aggregator.py @@ -288,6 +288,18 @@ def test_string_sets(self): # Assert there are no more sets assert not stats.flush() + def test_ignore_distribution(self): + stats = MetricsAggregator('myhost') + stats.submit_packets('my.dist:5.0|d') + stats.submit_packets('my.gauge:1|g') + + # Assert that it's treated normally, and that the distribution is ignored + metrics = stats.flush() + nt.assert_equal(len(metrics), 1) + m = metrics[0] + nt.assert_equal(m['metric'], 'my.gauge') + nt.assert_equal(m['points'][0][1], 1) + @attr(requires='core_integration') def test_rate(self): stats = MetricsAggregator('myhost')