diff --git a/autopush/metrics.py b/autopush/metrics.py index a8047b56..372aa7b7 100644 --- a/autopush/metrics.py +++ b/autopush/metrics.py @@ -71,12 +71,13 @@ def timing(self, name, duration, **kwargs): class DatadogMetrics(object): """DataDog Metric backend""" def __init__(self, api_key, app_key, flush_interval=10, - namespace="autopush"): + namespace="autopush", hostname="localhost"): - datadog.initialize(api_key=api_key, app_key=app_key) + datadog.initialize(api_key=api_key, app_key=app_key, + host_name=hostname) self._client = ThreadStats() self._flush_interval = flush_interval - self._host = get_hostname() + self._host = hostname or get_hostname() self._namespace = namespace def _prefix_name(self, name): diff --git a/autopush/settings.py b/autopush/settings.py index 1f49569c..5c41f6e6 100644 --- a/autopush/settings.py +++ b/autopush/settings.py @@ -100,17 +100,6 @@ def __init__(self, pool = HTTPConnectionPool(reactor) self.agent = Agent(reactor, connectTimeout=5, pool=pool) - # Metrics setup - if datadog_api_key: - self.metrics = DatadogMetrics( - api_key=datadog_api_key, - app_key=datadog_app_key, - flush_interval=datadog_flush_interval - ) - elif statsd_host: - self.metrics = TwistedMetrics(statsd_host, statsd_port) - else: - self.metrics = SinkMetrics() if not crypto_key: crypto_key = [Fernet.generate_key()] if not isinstance(crypto_key, list): @@ -133,6 +122,19 @@ def __init__(self, if resolve_hostname: self.hostname = resolve_ip(self.hostname) + # Metrics setup + if datadog_api_key: + self.metrics = DatadogMetrics( + api_key=datadog_api_key, + app_key=datadog_app_key, + flush_interval=datadog_flush_interval, + hostname=self.hostname, + ) + elif statsd_host: + self.metrics = TwistedMetrics(statsd_host, statsd_port) + else: + self.metrics = SinkMetrics() + self.port = port self.endpoint_hostname = endpoint_hostname or self.hostname self.router_hostname = router_hostname or self.hostname diff --git a/autopush/tests/test_integration.py b/autopush/tests/test_integration.py index d56b1c1c..02514113 100644 --- a/autopush/tests/test_integration.py +++ b/autopush/tests/test_integration.py @@ -1318,7 +1318,7 @@ def test_with_key(self): yield client.send_notification( vapid=vapid, - status=400) + status=404) yield self.shut_down(client) diff --git a/autopush/tests/test_metrics.py b/autopush/tests/test_metrics.py index bbb5a9e7..b09f9b38 100644 --- a/autopush/tests/test_metrics.py +++ b/autopush/tests/test_metrics.py @@ -52,9 +52,10 @@ def test_basic(self, mock_reactor): class DatadogMetricsTestCase(unittest.TestCase): @patch("autopush.metrics.datadog") def test_basic(self, mock_dog): - hostname = get_hostname() + hostname = "localhost" - m = DatadogMetrics("someapikey", "someappkey", namespace="testpush") + m = DatadogMetrics("someapikey", "someappkey", namespace="testpush", + hostname="localhost") ok_(len(mock_dog.mock_calls) > 0) m._client = Mock() m.start() diff --git a/autopush/web/validation.py b/autopush/web/validation.py index 36c74e4b..ef4a29e9 100644 --- a/autopush/web/validation.py +++ b/autopush/web/validation.py @@ -199,7 +199,7 @@ def extract_subscription(self, d): ckey_header=d["ckey_header"], ) except (InvalidTokenException, InvalidToken): - raise InvalidRequest("invalid token", errno=102) + raise InvalidRequest("invalid token", status_code=404, errno=102) return result @validates_schema(skip_on_field_errors=True) diff --git a/docs/http.rst b/docs/http.rst index 424ffbad..611a4b07 100644 --- a/docs/http.rst +++ b/docs/http.rst @@ -89,7 +89,6 @@ Unless otherwise specified, all calls return the following error codes: - 400 - Bad Parameters - errno 101 - Missing neccessary crypto keys - - errno 102 - Invalid URL endpoint - errno 108 - Router type is invalid - errno 110 - Invalid crypto keys specified - errno 111 - Missing Required Header @@ -103,6 +102,10 @@ Unless otherwise specified, all calls return the following error codes: - errno 109 - Invalid authentication +- 404 - Not Found + + - errno 102 - Invalid URL endpoint + - 410 - `{UAID}` or `{CHID}` not found - errno 103 - Expired URL endpoint