Beispiel #1
0
    def test_name_argument_deprecated(self, recwarn):
        warnings.simplefilter("always")
        StatsD('test', name='statsd')

        assert len(recwarn) == 1
        warn = recwarn.pop()
        assert str(warn.message) == (
            "The `name` argument to `StatsD` is no longer needed and has been"
            " deprecated.")
Beispiel #2
0
class DummyServiceTCP(ServiceBase):
    """Fake Service to test the `StatsD.timer` decorator. """

    name = 'dummy_service'

    statsd = StatsD('test-tcp')

    @dummy
    @statsd.timer('nice-tcp-stat', rate=3)
    def method(self, *args, **kwargs):
        sentinel = Mock()
        sentinel(*args, **kwargs)
        return sentinel
Beispiel #3
0
class DummyServiceDisabled(ServiceBase):
    """Fake Service to test the `StatsD.timer` decorator when disabled. """

    name = 'dummy_service'

    statsd = StatsD('test-disabled')

    @dummy
    @statsd.timer('disabled-nice-stat')
    def method(self, *args, **kwargs):
        sentinel = Mock()
        sentinel(*args, **kwargs)
        return sentinel
Beispiel #4
0
class DummyServiceManual(object):
    """Fake Service to test the `StatsD.timer` decorator without metaclass. """

    name = 'dummy_service'

    statsd = StatsD('test', name='statsd')

    @dummy
    @statsd.timer('nice-stat', rate=3)
    def method(self, *args, **kwargs):
        sentinel = Mock()
        sentinel(*args, **kwargs)
        return sentinel
Beispiel #5
0
class RPCDummyService(object):

    """Fake Service to test the `StatsD.timer` decorator. """

    name = 'dummy_service'

    statsd = StatsD('test')

    @rpc
    @statsd.timer('nice-stat', rate=3)
    def method(self, *args, **kwargs):
        sentinel = Mock()
        sentinel(*args, **kwargs)
        return sentinel
Beispiel #6
0
class DummyServiceMeta(ServiceBase):
    """
    Fake Service to test the `StatsD.timer` decorator with the deprecated
    metaclass
    """

    name = 'dummy_service'

    statsd = StatsD('test')

    @dummy
    @statsd.timer('nice-stat', rate=3)
    def method(self, *args, **kwargs):
        sentinel = Mock()
        sentinel(*args, **kwargs)
        return sentinel
Beispiel #7
0
    def test_get_dependency_tcp(self, lazy_client_cls, stats_config):
        statsd = StatsD('test-tcp')
        statsd.container = Mock()
        statsd.container.config = stats_config
        statsd.setup()

        worker_ctx = Mock()

        dep = statsd.get_dependency(worker_ctx)

        assert lazy_client_cls.call_args_list == [
            call(host='tcp.statsd.host',
                 port=4321,
                 prefix='tcp.statsd.prefix',
                 timeout=5,
                 enabled=True,
                 protocol='tcp')
        ]
        assert dep == lazy_client_cls.return_value
Beispiel #8
0
    def test_get_dependency(self, lazy_client_cls, stats_config):
        statsd = StatsD('test')
        statsd.container = Mock()
        statsd.container.config = stats_config
        statsd.setup()

        worker_ctx = Mock()

        dep = statsd.get_dependency(worker_ctx)

        assert lazy_client_cls.call_args_list == [
            call(
                host='statsd.host',
                port=1234,
                prefix='statsd.prefix',
                maxudpsize=1024,
                enabled=True,
            )
        ]
        assert dep == lazy_client_cls.return_value