def test_fallback_option_works(self): parser = config.Fallback(config.Percent, config.Float) self.assertAlmostEqual(parser(".44"), .44)
def tracing_client_from_config( raw_config: config.RawConfig, log_if_unconfigured: bool = True) -> tracing.TracingClient: """Configure and return a tracing client. This expects one configuration option and can take many optional ones: ``tracing.service_name`` The name for the service this observer is registered to. ``tracing.endpoint`` (optional) (Deprecated in favor of the sidecar model.) Destination to record span data. ``tracing.queue_name`` (optional) Name of POSIX queue where spans are recorded ``tracing.max_span_queue_size`` (optional) Span processing queue limit. ``tracing.num_span_workers`` (optional) Number of worker threads for span processing. ``tracing.span_batch_interval`` (optional) Wait time for span processing in seconds. ``tracing.num_conns`` (optional) Pool size for remote recorder connection pool. ``tracing.sample_rate`` (optional) Percentage of unsampled requests to record traces for (e.g. "37%") :param dict raw_config: The application configuration which should have settings for the tracing client. :param bool log_if_unconfigured: When the client is not configured, should trace spans be logged or discarded silently? :return: A configured client. :rtype: :py:class:`baseplate.diagnostics.tracing.TracingClient` """ cfg = config.parse_config( raw_config, { "tracing": { "service_name": config.String, "endpoint": config.Optional(config.Endpoint), "queue_name": config.Optional(config.String), "max_span_queue_size": config.Optional(config.Integer, default=50000), "num_span_workers": config.Optional(config.Integer, default=5), "span_batch_interval": config.Optional(config.Timespan, default=config.Timespan("500 milliseconds")), "num_conns": config.Optional(config.Integer, default=100), "sample_rate": config.Optional(config.Fallback(config.Percent, config.Float), default=0.1), } }, ) # pylint: disable=maybe-no-member return tracing.make_client( service_name=cfg.tracing.service_name, tracing_endpoint=cfg.tracing.endpoint, tracing_queue_name=cfg.tracing.queue_name, max_span_queue_size=cfg.tracing.max_span_queue_size, num_span_workers=cfg.tracing.num_span_workers, span_batch_interval=cfg.tracing.span_batch_interval.total_seconds(), num_conns=cfg.tracing.num_conns, sample_rate=cfg.tracing.sample_rate, log_if_unconfigured=log_if_unconfigured, )
def test_primary_option_works(self): parser = config.Fallback(config.Percent, config.Float) self.assertAlmostEqual(parser("33%"), .33)