def set_config(self, config: ValueExtractor) -> None: cfg = config.new_parent(logger=__package__) super().set_config(cfg) # TODO: Remove deprecated code. if self.config.get("connection.init"): warnings.warn("Do not use connection.init config. Use pool.init", DeprecationWarning) self._pool_init = self.context.get_object( self.config.get("connection.init")) pool_config = dict(self.config.get("pool", {})) if not pool_config: # Do not process pool config if there is no any parameter return pool_init: Optional[str] = pool_config.pop("init", None) if pool_init: self._pool_init = self.context.get_object(pool_init) pool_setup: Optional[str] = pool_config.pop("setup", None) if pool_setup: self._pool_setup = self.context.get_object(pool_setup) connection_class: Optional[str] = pool_config.pop( "connection_class", None) if connection_class: self._connection_class = self.context.get_object(connection_class) record_class: Optional[str] = pool_config.pop("record_class", None) if record_class: self._record_class = self.context.get_object(record_class) self._connect_kwargs = pool_config
def set_config(self, config: ValueExtractor) -> None: cfg = config.new_parent(logger=__package__) super().set_config(cfg) client_config = dict(self.config.get("client", {})) if client_config: self._client_config = client_config return # Support old uri only config. self._client_config = { "host": self.config.get("uri", self.default_mongo_uri), }
def set_config(self, config: ValueExtractor) -> None: cfg = config.new_parent(logger=__package__) super().set_config(cfg) registry: str = self.config.get('registry', REGISTRY) namespace: Optional[str] = self.config.get('namespace') cfg_metrics = self.config.get('metrics', {}) for attr, params in cfg_metrics.items(): kw = dict(params) m_name: str = kw.setdefault('name', attr) kw.setdefault('documentation', '') m_type: str = kw.pop('type', 'gauge') cls = self.METRICS[m_type] m_registry: str = kw.get('registry', registry) kw['registry'] = get_registry(m_registry) m_namespace: Optional[str] = kw.setdefault('namespace', namespace) cache_key: Tuple = (m_registry, m_namespace, m_name, m_type) cache_key += tuple(kw.get('labelnames', ())) metric: Optional[metrics.MetricWrapperBase] = self._cache.get(cache_key) if metric is None: metric = cls(**kw) self._cache[cache_key] = metric setattr(self, attr, metric)
def test_value_extractor_order_keys(): v = ValueExtractor(MergeDict(a=1)) assert list(v.new_child(b=1)) == ['a', 'b'] assert list(v.new_parent(b=1)) == ['a', 'b'] assert list(v.new_parent(b=1).new_child(c=1)) == ['a', 'b', 'c']