Exemple #1
0
    def test_arg_timeit(self):
        @timeit(name='qdo.timeit',
                logger='timeit_logger',
                severity=5,
                fields={
                    'anumber': 42,
                    'atext': 'foo'
                },
                rate=7)
        def simple(x, y):
            return x + y

        simple(5, 6)
        msgs = [self._extract_msg(m) for m in self.client.sender.stream.msgs]
        eq_(len(msgs), 1)

        expected = {
            'severity': 5,
            'timestamp': msgs[0].timestamp,
            'fields': {
                'anumber': 42,
                'rate': 7,
                'name': 'qdo.timeit',
                'atext': 'foo',
            },
            'logger': 'timeit_logger',
            'type': 'timer',
            'payload': '0',
            'env_version': HekaClient.env_version,
            'heka_hostname': socket.gethostname(),
            'heka_pid': os.getpid(),
            'uuid': msgs[0].uuid,
        }
        eq_(msgs[0], dict_to_msg(expected))
Exemple #2
0
    def test_heka_full(self):
        heka_args = dict(payload='this is another test',
                         logger='alternate',
                         severity=2,
                         fields={
                             'foo': 'bar',
                             'boo': 'far'
                         })
        msgtype = 'bawlp'
        self.client.heka(msgtype, **heka_args)
        actual_msg = self._extract_full_msg()

        heka_args.update({
            'type': msgtype,
            'env_version': self.client.env_version,
            'heka_pid': os.getpid(),
            'heka_hostname': socket.gethostname(),
            'timestamp': actual_msg.timestamp
        })

        # Everything but the UUID should be identical
        expected_msg = dict_to_msg(heka_args)

        actual_dict = json.loads(JSONMessageEncoder().encode(actual_msg))
        expected_dict = json.loads(JSONMessageEncoder().encode(expected_msg))

        del expected_dict['uuid']
        del actual_dict['uuid']
        eq_(actual_dict, expected_dict)
Exemple #3
0
    def test_arg_incr(self):
        @incr_count(name='qdo.foo', count=5, logger='somelogger', severity=2)
        def simple(x, y):
            return x + y

        simple(5, 6)
        msgs = [self._extract_msg(m) for m in self.client.sender.stream.msgs]
        eq_(len(msgs), 1)

        expected = {
            'severity': 2,
            'timestamp': msgs[0].timestamp,
            'fields': {
                'name': 'qdo.foo',
                'rate': 1.0,
            },
            'logger': 'somelogger',
            'type': 'counter',
            'payload': '5',
            'env_version': HekaClient.env_version,
            'heka_hostname': socket.gethostname(),
            'heka_pid': os.getpid(),
            'uuid': msgs[0].uuid,
        }
        eq_(msgs[0], dict_to_msg(expected))
Exemple #4
0
    def test_heka_full(self):
        heka_args = dict(payload='this is another test',
                         logger='alternate',
                         severity=2,
                         fields={'foo': 'bar',
                                 'boo': 'far'})
        msgtype = 'bawlp'
        self.client.heka(msgtype, **heka_args)
        actual_msg = self._extract_full_msg()

        heka_args.update({'type': msgtype,
                          'env_version': self.client.env_version,
                          'heka_pid': os.getpid(),
                          'heka_hostname': socket.gethostname(),
                          'timestamp': actual_msg.timestamp})

        # Everything but the UUID should be identical
        expected_msg = dict_to_msg(heka_args)

        pbencoder = ProtobufEncoder()
        h, actual_msg = decode_message(pbencoder.encode(actual_msg))
        h, expected_msg = decode_message(pbencoder.encode(expected_msg))

        expected_msg.uuid = ''
        actual_msg.uuid = ''
        eq_(actual_msg, expected_msg)
    def test_arg_timeit(self):
        @timeit(name='qdo.timeit', logger='timeit_logger', severity=5,
                fields={'anumber': 42, 'atext': 'foo'}, rate=7)
        def simple(x, y):
            return x + y

        simple(5, 6)
        msgs = [self._extract_msg(m) for m in self.stream.msgs]
        eq_(len(msgs), 1)

        expected = {'severity': 5, 'timestamp': msgs[0].timestamp,
                    'fields': {'anumber': 42, 'rate': 7,
                               'name': 'qdo.timeit', 'atext': 'foo',
                               },
                    'logger': 'timeit_logger', 'type': 'timer',
                    'payload': '0', 'env_version': HekaClient.env_version,
                    'heka_hostname': socket.gethostname(),
                    'heka_pid': os.getpid(),
                    'uuid': msgs[0].uuid,
                    }
        eq_(msgs[0], dict_to_msg(expected))
    def test_arg_incr(self):
        @incr_count(name='qdo.foo', count=5, logger='somelogger',
                    severity=2)
        def simple(x, y):
            return x + y

        simple(5, 6)
        msgs = [self._extract_msg(m) for m in self.stream.msgs]
        eq_(len(msgs), 1)

        expected = {'severity': 2, 'timestamp': msgs[0].timestamp,
                    'fields': {'name': 'qdo.foo',
                               'rate': 1.0,
                               },
                    'logger': 'somelogger', 'type': 'counter',
                    'payload': '5', 'env_version': HekaClient.env_version,
                    'heka_hostname': socket.gethostname(),
                    'heka_pid': os.getpid(),
                    'uuid': msgs[0].uuid,
                    }
        eq_(msgs[0], dict_to_msg(expected))
Exemple #7
0
from heka.encoders import UNIT_SEPARATOR, RECORD_SEPARATOR
from heka.message import first_value, Header, Message
from heka.tests.helpers import decode_message
from heka.tests.helpers import dict_to_msg
from nose.tools import eq_
import base64
import hmac
import json
import uuid

SAMPLE_MSG = dict_to_msg({'uuid': '0123456789012345',
                          'type': 'sentry',
                          'logger': '',
                          'severity': 3,
                          'env_version': '0.8', 'heka_pid': 55,
                          'heka_hostname': 'localhost',
                          'timestamp': int(datetime.utcnow().strftime('%s')) * 1000000,
                          'payload': 'some_data', 'fields': {'foo': 'bar',
                          'blah': 42,
                          'cef_meta': {'syslog_name': 'some-syslog-thing',
                          'syslog_level': 5}}})


class TestProtobufEncoder(object):
    def test_protobuf_encoding(self):
        enc = ProtobufEncoder()

        bytes = enc.encode(SAMPLE_MSG)

        eq_(ord(bytes[0]), RECORD_SEPARATOR)
        header_len = ord(bytes[1])
Exemple #8
0
from heka.encoders import UNIT_SEPARATOR, RECORD_SEPARATOR
from heka.message import first_value, Header, Message
from heka.tests.helpers import decode_message
from heka.tests.helpers import dict_to_msg
from nose.tools import eq_
import base64
import hmac
import json
import uuid

SAMPLE_MSG = dict_to_msg({'uuid': uuid.uuid4().bytes,
                          'type': 'sentry',
                          'logger': '',
                          'severity': 3,
                          'env_version': '0.8', 'heka_pid': 55,
                          'heka_hostname': 'localhost',
                          'timestamp': int(datetime.utcnow().strftime('%s')) * 1000000,
                          'payload': 'some_data', 'fields': {'foo': 'bar',
                          'blah': 42,
                          'cef_meta': {'syslog_name': 'some-syslog-thing',
                          'syslog_level': 5}}})


class TestJSONEncoder(object):
    def test_json_encoding(self):
        enc = JSONEncoder()

        bytes = enc.encode(SAMPLE_MSG)

        eq_(ord(bytes[0]), RECORD_SEPARATOR)
        header_len = ord(bytes[1])