示例#1
0
def test_timing(mockdogstatsd):
    rec = MetricsRecord("timing", key="foo", value=1234, tags=["key1:val"])
    ddm = datadog.DatadogMetrics()
    ddm.emit_to_backend(rec)
    assert ddm.client.calls == [("timing", (), {
        "metric": "foo",
        "value": 1234,
        "tags": ["key1:val"]
    })]
示例#2
0
def test_histogram(mockdogstatsd):
    rec = MetricsRecord("histogram", key="foo", value=4321, tags=["key1:val"])
    ddm = datadog.DatadogMetrics()
    ddm.emit_to_backend(rec)
    assert ddm.client.calls == [("histogram", (), {
        "metric": "foo",
        "value": 4321,
        "tags": ["key1:val"]
    })]
示例#3
0
def test_timing(mockdogstatsd):
    ddm = datadog.DatadogMetrics({})

    ddm.timing('foo', value=1234, tags=['key1:val'])

    assert (ddm.client.calls == [('timing', (), {
        'metric': 'foo',
        'value': 1234,
        'tags': ['key1:val']
    })])
示例#4
0
def test_gauge(mockdogstatsd):
    ddm = datadog.DatadogMetrics({})

    ddm.gauge('foo', value=100, tags=['key1:val'])

    assert (ddm.client.calls == [('gauge', (), {
        'metric': 'foo',
        'value': 100,
        'tags': ['key1:val']
    })])
示例#5
0
def test_incr(mockdogstatsd):
    ddm = datadog.DatadogMetrics({})

    ddm.incr('foo', value=10, tags=['key1:val'])

    assert (ddm.client.calls == [('increment', (), {
        'metric': 'foo',
        'value': 10,
        'tags': ['key1:val']
    })])
示例#6
0
def test_histogram(mockdogstatsd):
    ddm = datadog.DatadogMetrics({})

    ddm.histogram('foo', value=4321, tags=['key1:val'])

    assert (ddm.client.calls == [('histogram', (), {
        'metric': 'foo',
        'value': 4321,
        'tags': ['key1:val']
    })])
示例#7
0
def test_default_options(mockdogstatsd):
    ddm = datadog.DatadogMetrics({})

    assert ddm.host == 'localhost'
    assert ddm.port == 8125
    assert ddm.namespace == ''

    # NOTE(willkg): ddm.client is the mock instance
    assert ddm.client.initargs == ()
    assert ddm.client.initkwargs == {
        'host': 'localhost',
        'port': 8125,
        'namespace': ''
    }
示例#8
0
def test_default_options(mockdogstatsd):
    ddm = datadog.DatadogMetrics()

    assert ddm.host == "localhost"
    assert ddm.port == 8125
    assert ddm.namespace == ""

    # NOTE(willkg): ddm.client is the mock instance
    assert ddm.client.initargs == ()
    assert ddm.client.initkwargs == {
        "host": "localhost",
        "port": 8125,
        "namespace": ""
    }
示例#9
0
def test_filters(mockdogstatsd):
    class BlueFilter(MetricsFilter):
        def filter(self, record):
            if "blue" not in record.key:
                return
            return record

    ddm = datadog.DatadogMetrics(filters=[BlueFilter()])
    ddm.emit_to_backend(MetricsRecord("incr", key="foo", value=1, tags=[]))
    ddm.emit_to_backend(MetricsRecord("incr", key="foo.blue", value=2,
                                      tags=[]))
    assert ddm.client.calls == [("increment", (), {
        "metric": "foo.blue",
        "value": 2,
        "tags": []
    })]
示例#10
0
def test_options(mockdogstatsd):
    ddm = datadog.DatadogMetrics({
        'statsd_host': 'example.com',
        'statsd_port': 5000,
        'statsd_namespace': 'joe',
    })

    assert ddm.host == 'example.com'
    assert ddm.port == 5000
    assert ddm.namespace == 'joe'

    # NOTE(willkg): ddm.client is the mock instance
    assert ddm.client.initargs == ()
    assert ddm.client.initkwargs == {
        'host': 'example.com',
        'port': 5000,
        'namespace': 'joe'
    }
示例#11
0
def test_options(mockdogstatsd):
    ddm = datadog.DatadogMetrics({
        "statsd_host": "example.com",
        "statsd_port": 5000,
        "statsd_namespace": "joe"
    })

    assert ddm.host == "example.com"
    assert ddm.port == 5000
    assert ddm.namespace == "joe"

    # NOTE(willkg): ddm.client is the mock instance
    assert ddm.client.initargs == ()
    assert ddm.client.initkwargs == {
        "host": "example.com",
        "port": 5000,
        "namespace": "joe",
    }