def metrics_client_from_config(raw_config: config.RawConfig) -> metrics.Client: """Configure and return a metrics client. This expects two configuration options: ``metrics.namespace`` The root key to prefix all metrics in this application with. ``metrics.endpoint`` A ``host:port`` pair, e.g. ``localhost:2014``. If an empty string, a client that discards all metrics will be returned. :param dict raw_config: The application configuration which should have settings for the metrics client. :return: A configured client. :rtype: :py:class:`baseplate.metrics.Client` """ cfg = config.parse_config( raw_config, { "metrics": { "namespace": config.String, "endpoint": config.Optional(config.Endpoint) } }, ) # pylint: disable=maybe-no-member return metrics.make_client(cfg.metrics.namespace, cfg.metrics.endpoint)
def test_valid_endpoint(self): client = metrics.make_client("namespace", EXAMPLE_ENDPOINT) self.assertIsInstance(client.transport, metrics.RawTransport)
def test_no_endpoint(self): client = metrics.make_client("namespace", None) self.assertIsInstance(client.transport, metrics.NullTransport)