コード例 #1
0
    def test_dispatches_service_check(self):
        datadog = pretend.stub(
            service_check=pretend.call_recorder(lambda *a, **k: None)
        )
        metrics = DataDogMetrics(datadog)

        metrics.service_check(
            "name!",
            "ok",
            tags=["one", "two"],
            timestamp="now",
            hostname="example.com",
            message="my message",
        )

        assert datadog.service_check.calls == [
            pretend.call(
                "name!",
                "ok",
                tags=["one", "two"],
                timestamp="now",
                hostname="example.com",
                message="my message",
            )
        ]
コード例 #2
0
    def test_dispatches_event(self):
        datadog = pretend.stub(event=pretend.call_recorder(lambda *a, **k: None))
        metrics = DataDogMetrics(datadog)

        metrics.event(
            "my title",
            "this is text",
            alert_type="thing",
            aggregation_key="wat",
            source_type_name="ok?",
            date_happened="now?",
            priority="who knows",
            tags=["one", "two"],
            hostname="example.com",
        )

        assert datadog.event.calls == [
            pretend.call(
                "my title",
                "this is text",
                alert_type="thing",
                aggregation_key="wat",
                source_type_name="ok?",
                date_happened="now?",
                priority="who knows",
                tags=["one", "two"],
                hostname="example.com",
            )
        ]
コード例 #3
0
    def test_dispatches_timed(self):
        timer = pretend.stub()
        datadog = pretend.stub(timed=pretend.call_recorder(lambda *a, **k: timer))

        metrics = DataDogMetrics(datadog)

        assert (
            metrics.timed("thing.timed", tags=["wat"], sample_rate=0.4, use_ms=True)
            is timer
        )
        assert datadog.timed.calls == [
            pretend.call("thing.timed", tags=["wat"], sample_rate=0.4, use_ms=True)
        ]
コード例 #4
0
    def test_dispatches_basic(self, method):
        method_fn = pretend.call_recorder(lambda *a, **kw: None)
        datadog = pretend.stub(**{method: method_fn})

        metrics = DataDogMetrics(datadog)
        getattr(metrics, method)("my metric", 3, tags=["foo", "bar"], sample_rate=0.5)

        assert method_fn.calls == [
            pretend.call("my metric", 3, tags=["foo", "bar"], sample_rate=0.5)
        ]
コード例 #5
0
    def test_create_service_defaults(self, monkeypatch):
        datadog_obj = pretend.stub()
        datadog_cls = pretend.call_recorder(lambda **kw: datadog_obj)

        monkeypatch.setattr(services, "DogStatsd", datadog_cls)

        context = pretend.stub()
        request = pretend.stub(registry=pretend.stub(settings={}))

        metrics = DataDogMetrics.create_service(context, request)

        assert metrics._datadog is datadog_obj
        assert datadog_cls.calls == [
            pretend.call(host="127.0.0.1", port=8125, namespace=None, use_ms=True)
        ]
コード例 #6
0
    def test_create_service_overrides(self, monkeypatch):
        datadog_obj = pretend.stub()
        datadog_cls = pretend.call_recorder(lambda **kw: datadog_obj)

        monkeypatch.setattr(services, "DogStatsd", datadog_cls)

        context = pretend.stub()
        request = pretend.stub(
            registry=pretend.stub(
                settings={
                    "metrics.host": "example.com",
                    "metrics.port": "9152",
                    "metrics.namespace": "thing",
                }
            )
        )

        metrics = DataDogMetrics.create_service(context, request)

        assert metrics._datadog is datadog_obj
        assert datadog_cls.calls == [
            pretend.call(host="example.com", port=9152, namespace="thing", use_ms=True)
        ]