Ejemplo n.º 1
0
    def test_event_tags(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{6,4}:title1|text')
        stats.submit_packets('_e{6,4}:title2|text|#t1')
        stats.submit_packets('_e{6,4}:title3|text|#t1,t2:v2,t3,t4')
        stats.submit_packets('_e{6,4}:title4|text|k:key|p:normal|#t1,t2')

        events = self.sort_events(stats.flush_events())

        assert len(events) == 4
        first, second, third, fourth = events

        try:
            first['dimensions']
        except Exception:
            assert True
        else:
            assert False, "event['tags'] shouldn't be defined when no tags aren't explicited in the packet"
        nt.assert_equal(first['title'], 'title1')
        nt.assert_equal(first['text'], 'text')

        nt.assert_equal(second['title'], 'title2')
        nt.assert_equal(second['text'], 'text')
        nt.assert_equal(second['dimensions'], sorted(['t1']))

        nt.assert_equal(third['title'], 'title3')
        nt.assert_equal(third['text'], 'text')
        nt.assert_equal(third['dimensions'],
                        sorted(['t1', 't2:v2', 't3', 't4']))

        nt.assert_equal(fourth['title'], 'title4')
        nt.assert_equal(fourth['text'], 'text')
        nt.assert_equal(fourth['aggregation_key'], 'key')
        nt.assert_equal(fourth['priority'], 'normal')
        nt.assert_equal(fourth['dimensions'], sorted(['t1', 't2']))
Ejemplo n.º 2
0
    def test_event_tags(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{6,4}:title1|text')
        stats.submit_packets('_e{6,4}:title2|text|#t1')
        stats.submit_packets('_e{6,4}:title3|text|#t1,t2:v2,t3,t4')
        stats.submit_packets('_e{6,4}:title4|text|k:key|p:normal|#t1,t2')

        events = self.sort_events(stats.flush_events())

        assert len(events) == 4
        first, second, third, fourth = events

        try:
            first['dimensions']
        except Exception:
            assert True
        else:
            assert False, "event['tags'] shouldn't be defined when no tags aren't explicited in the packet"
        nt.assert_equal(first['title'], 'title1')
        nt.assert_equal(first['text'], 'text')

        nt.assert_equal(second['title'], 'title2')
        nt.assert_equal(second['text'], 'text')
        nt.assert_equal(second['dimensions'], sorted(['t1']))

        nt.assert_equal(third['title'], 'title3')
        nt.assert_equal(third['text'], 'text')
        nt.assert_equal(third['dimensions'], sorted(['t1', 't2:v2', 't3', 't4']))

        nt.assert_equal(fourth['title'], 'title4')
        nt.assert_equal(fourth['text'], 'text')
        nt.assert_equal(fourth['aggregation_key'], 'key')
        nt.assert_equal(fourth['priority'], 'normal')
        nt.assert_equal(fourth['dimensions'], sorted(['t1', 't2']))
Ejemplo n.º 3
0
    def test_event_text(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{2,0}:t1|')
        stats.submit_packets('_e{2,12}:t2|text|content')
        stats.submit_packets('_e{2,23}:t3|First line\\nSecond line')  # \n is a newline
        stats.submit_packets(u'_e{2,19}:t4|��� �����U �����U ����u T0�� ���')  # utf-8 compliant

        events = self.sort_events(stats.flush_events())

        assert len(events) == 4
        first, second, third, fourth = events

        nt.assert_equal(first['text'], '')
        nt.assert_equal(second['text'], 'text|content')
        nt.assert_equal(third['text'], 'First line\nSecond line')
        nt.assert_equal(fourth['text'], u'��� �����U �����U ����u T0�� ���')
Ejemplo n.º 4
0
    def test_event_text(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{2,0}:t1|')
        stats.submit_packets('_e{2,12}:t2|text|content')
        stats.submit_packets(
            '_e{2,23}:t3|First line\\nSecond line')  # \n is a newline
        stats.submit_packets(
            u'_e{2,19}:t4|��� �����U �����U ����u T0�� ���')  # utf-8 compliant

        events = self.sort_events(stats.flush_events())

        assert len(events) == 4
        first, second, third, fourth = events

        nt.assert_equal(first['text'], '')
        nt.assert_equal(second['text'], 'text|content')
        nt.assert_equal(third['text'], 'First line\nSecond line')
        nt.assert_equal(fourth['text'], u'��� �����U �����U ����u T0�� ���')
Ejemplo n.º 5
0
    def test_event_title(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{0,4}:|text')
        stats.submit_packets(u'_e{9,4}:2intitul��|text')
        stats.submit_packets('_e{14,4}:3title content|text')
        stats.submit_packets('_e{14,4}:4title|content|text')
        stats.submit_packets('_e{13,4}:5title\\ntitle|text')  # \n stays escaped

        events = self.sort_events(stats.flush_events())

        assert len(events) == 5
        first, second, third, fourth, fifth = events

        nt.assert_equal(first['title'], '')
        nt.assert_equal(second['title'], u'2intitul��')
        nt.assert_equal(third['title'], '3title content')
        nt.assert_equal(fourth['title'], '4title|content')
        nt.assert_equal(fifth['title'], '5title\\ntitle')
Ejemplo n.º 6
0
    def test_event_title(self):
        stats = MetricsAggregator('myhost')
        stats.submit_packets('_e{0,4}:|text')
        stats.submit_packets(u'_e{9,4}:2intitul��|text')
        stats.submit_packets('_e{14,4}:3title content|text')
        stats.submit_packets('_e{14,4}:4title|content|text')
        stats.submit_packets(
            '_e{13,4}:5title\\ntitle|text')  # \n stays escaped

        events = self.sort_events(stats.flush_events())

        assert len(events) == 5
        first, second, third, fourth, fifth = events

        nt.assert_equal(first['title'], '')
        nt.assert_equal(second['title'], u'2intitul��')
        nt.assert_equal(third['title'], '3title content')
        nt.assert_equal(fourth['title'], '4title|content')
        nt.assert_equal(fifth['title'], '5title\\ntitle')