def validate(self):
        if not self.validate_es:
            return

        if not self.es.ping():
            raise InvalidConfiguration('Can not connect to elasticsearch')

        try:
            self.es.indices.get_template(name=self.template_name)
        except NotFoundError:
            raise InvalidConfiguration(self.template_not_found_msg)
Exemple #2
0
    def validate(self) -> None:
        if not self.is_enabled():
            return

        if self.storage_options is not None and self.storage_options[
                "options"] is None:
            raise InvalidConfiguration(
                "`chart-rendering.storage.options` must be configured if `chart-rendering.storage.backend` is configured"
            )

        if not self.service_url:
            raise InvalidConfiguration(
                "`chart-rendering.chartcuterie.url` is not configured")
Exemple #3
0
    def validate(self):
        if not self.is_enabled():
            return

        if not self.service_url:
            raise InvalidConfiguration(
                "`chart-rendering.chartcuterie.url` is not configured")
Exemple #4
0
def check_versions(service, versions, required, recommended=None):
    """
    Check that hosts fulfill version requirements.

    :param service: service label, such as ``Redis``
    :param versions: mapping of host to ``Version``
    :param required: lowest supported ``Version``. If any host does not fulfill
        this requirement, an ``InvalidConfiguration`` exception is raised.
    :param recommended: recommended version. If any host does not fulfill this
        requirement, a ``PendingDeprecationWarning`` is raised.
    """
    # x = (host, version)
    must_upgrade = dict([x for x in versions.items() if required > x[1]])
    if must_upgrade:
        raise InvalidConfiguration(
            make_upgrade_message(service, "must", required, must_upgrade))

    if recommended:
        # x = (host, version)
        should_upgrade = dict(
            [x for x in versions.items() if recommended > x[1]])
        if should_upgrade:
            warnings.warn(
                make_upgrade_message(service, "should", recommended,
                                     should_upgrade),
                PendingDeprecationWarning,
            )
Exemple #5
0
def get_cluster_from_options(setting, options, cluster_manager=clusters):
    cluster_option_name = 'cluster'
    default_cluster_name = 'default'
    cluster_constructor_option_names = frozenset(('hosts',))

    options = options.copy()
    cluster_options = {key: options.pop(key) for key in set(options.keys()).intersection(cluster_constructor_option_names)}
    if cluster_options:
        if cluster_option_name in options:
            raise InvalidConfiguration(
                'Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.'.format(
                    cluster_option_name,
                    ', '.join(map(repr, cluster_constructor_option_names)),
                )
            )
        else:
            warnings.warn(
                DeprecatedSettingWarning(
                    '{} parameter of {}'.format(
                        ', '.join(map(repr, cluster_constructor_option_names)),
                        setting,
                    ),
                    '{}["{}"]'.format(
                        setting,
                        cluster_option_name,
                    ),
                    removed_in_version='8.5',
                ),
                stacklevel=2
            )
        cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options)
    else:
        cluster = cluster_manager.get(options.pop(cluster_option_name, default_cluster_name))

    return cluster, options
Exemple #6
0
    def validate(self) -> None:
        if self._counter_bucket_size <= 0:
            raise InvalidConfiguration(
                "counter bucket size must be at least 1")

        if self._duration_bucket_size <= 0:
            raise InvalidConfiguration(
                "duration bucket size must be at least 1")

        if self._counter_time_window < 0:
            raise InvalidConfiguration(
                "counter time window must be nonnegative")

        if self._duration_time_window < 0:
            raise InvalidConfiguration(
                "duration time window must be nonnegative")
Exemple #7
0
    def validate(self) -> None:
        if not 0 < self._counter_bucket_size <= 60:
            raise InvalidConfiguration(
                "counter bucket size must be 1-60 seconds")

        if not 0 < self._duration_bucket_size <= 60:
            raise InvalidConfiguration(
                "duration bucket size must be 1-60 seconds")

        if self._counter_time_window < 60:
            raise InvalidConfiguration(
                "counter time window must be at least a minute")

        if self._duration_time_window < 60:
            raise InvalidConfiguration(
                "duration time window must be at least a minute")
def get_cluster_from_options(setting, options, cluster_manager=clusters):
    cluster_option_name = "cluster"
    default_cluster_name = "default"
    cluster_constructor_option_names = frozenset(("hosts",))

    options = options.copy()
    cluster_options = {
        key: options.pop(key)
        for key in set(options.keys()).intersection(cluster_constructor_option_names)
    }
    if cluster_options:
        if cluster_option_name in options:
            raise InvalidConfiguration(
                "Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.".format(
                    cluster_option_name, ", ".join(map(repr, cluster_constructor_option_names))
                )
            )
        else:
            warnings.warn(
                DeprecatedSettingWarning(
                    "{} parameter of {}".format(
                        ", ".join(map(repr, cluster_constructor_option_names)), setting
                    ),
                    f'{setting}["{cluster_option_name}"]',
                    removed_in_version="8.5",
                ),
                stacklevel=2,
            )
        cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options)
    else:
        cluster = cluster_manager.get(options.pop(cluster_option_name, default_cluster_name))

    return cluster, options
Exemple #9
0
def check_cluster_versions(cluster,
                           required,
                           recommended=Version((3, 0, 4)),
                           label=None):
    try:
        with cluster.all() as client:
            results = client.info()
    except Exception as e:
        # Any connection issues should be caught here.
        raise InvalidConfiguration(unicode(e))

    versions = {}
    for id, info in results.value.items():
        host = cluster.hosts[id]
        # NOTE: This assumes there is no routing magic going on here, and
        # all requests to this host are being served by the same database.
        key = '{host}:{port}'.format(host=host.host, port=host.port)
        versions[key] = Version(map(int, info['redis_version'].split('.', 3)))

    check_versions(
        'Redis' if label is None else 'Redis (%s)' % (label, ),
        versions,
        required,
        recommended,
    )
Exemple #10
0
 def validate(self):
     try:
         if self.is_redis_cluster:
             self.cluster.ping()
         else:
             with self.cluster.all() as client:
                 client.ping()
     except Exception as e:
         raise InvalidConfiguration(six.text_type(e))
Exemple #11
0
def validate_dynamic_cluster(is_redis_cluster, cluster):
    try:
        if is_redis_cluster:
            cluster.ping()
        else:
            with cluster.all() as client:
                client.ping()
    except Exception as e:
        raise InvalidConfiguration(str(e))
Exemple #12
0
def check_cluster_versions(cluster, required, recommended=None, label=None):
    try:
        with cluster.all() as client:
            results = client.info()
    except Exception as e:
        # Any connection issues should be caught here.
        raise InvalidConfiguration(str(e))

    versions = {}
    for id, info in results.value.items():
        host = cluster.hosts[id]
        # NOTE: This assumes there is no routing magic going on here, and
        # all requests to this host are being served by the same database.
        key = f"{host.host}:{host.port}"
        versions[key] = Version(map(int, info["redis_version"].split(".", 3)))

    check_versions("Redis" if label is None else f"Redis ({label})", versions,
                   required, recommended)
Exemple #13
0
    def validate(self):
        logger.info('Validating Redis version...')

        try:
            with self.cluster.all() as client:
                results = client.info()
        except Exception as e:
            # Any connection issues should be caught here.
            raise InvalidConfiguration(unicode(e))

        versions = {}
        for id, info in results.value.items():
            host = self.cluster.hosts[id]
            # NOTE: This assumes there is no routing magic going on here, and
            # all requests to this host are being served by the same database.
            key = '{host}:{port}'.format(host=host.host, port=host.port)
            versions[key] = Version(
                map(int, info['redis_version'].split('.', 3)))

        check_versions('Redis (TSDB)', versions, Version((2, 8, 9)),
                       Version((3, 0, 4)))
Exemple #14
0
def get_cluster_from_options(backend, options, cluster_manager=clusters):
    cluster_option_name = 'cluster'
    default_cluster_name = 'default'
    cluster_constructor_option_names = frozenset(('hosts', ))

    options = options.copy()
    cluster_options = {
        key: options.pop(key)
        for key in set(options.keys()).intersection(
            cluster_constructor_option_names)
    }
    if cluster_options:
        if cluster_option_name in options:
            raise InvalidConfiguration(
                'Cannot provide both named cluster ({!r}) and cluster configuration ({}) options.'
                .format(
                    cluster_option_name,
                    ', '.join(map(repr, cluster_constructor_option_names)),
                ))
        else:
            warnings.warn(
                'Providing Redis cluster configuration options ({}) to {!r} is '
                'deprecated, please update your configuration to use named Redis '
                'clusters ({!r}).'.format(
                    ', '.join(map(repr, cluster_constructor_option_names)),
                    backend,
                    cluster_option_name,
                ),
                DeprecationWarning,
                stacklevel=2)
        cluster = rb.Cluster(pool_cls=_shared_pool, **cluster_options)
    else:
        cluster = cluster_manager.get(
            options.pop(cluster_option_name, default_cluster_name))

    return cluster, options
Exemple #15
0
 def validate(self):
     try:
         self.conn.ping()
     except Exception as e:
         raise InvalidConfiguration(unicode(e))
Exemple #16
0
    def validate(self) -> None:
        if self._counter_bucket_size <= 0:
            raise InvalidConfiguration("counter bucket size must be at least 1")

        if self._histogram_bucket_size <= 0:
            raise InvalidConfiguration("histogram bucket size must be at least 1")
Exemple #17
0
 def validate(self):
     try:
         with self.cluster.all() as client:
             client.ping()
     except Exception as e:
         raise InvalidConfiguration(unicode(e))
Exemple #18
0
 def validate(self) -> None:
     try:
         self.client.ping()
     except Exception as e:
         raise InvalidConfiguration(str(e))