Exemplo n.º 1
0
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)
Exemplo n.º 2
0
 def test_valid_endpoint(self):
     client = metrics.make_client("namespace", EXAMPLE_ENDPOINT)
     self.assertIsInstance(client.transport, metrics.RawTransport)
Exemplo n.º 3
0
 def test_no_endpoint(self):
     client = metrics.make_client("namespace", None)
     self.assertIsInstance(client.transport, metrics.NullTransport)
Exemplo n.º 4
0
 def test_valid_endpoint(self):
     client = metrics.make_client("namespace", EXAMPLE_ENDPOINT)
     self.assertIsInstance(client.transport, metrics.RawTransport)
Exemplo n.º 5
0
 def test_no_endpoint(self):
     client = metrics.make_client("namespace", None)
     self.assertIsInstance(client.transport, metrics.NullTransport)