Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

Add backend for Redis Sentinel - #1

Closed
MatusJenca2 wants to merge 1 commit into
masterfrom
redis-sentinel-tls
Closed

MatusJenca2 wants to merge 1 commit into
masterfrom
redis-sentinel-tls

Conversation

@MatusJenca2

Copy link
Copy Markdown
Collaborator

Just for internal review before upstream PR in openstack gerrit repo.

@fdobrovolny fdobrovolny left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, excellent work. PEP8 formatting would be nice, and I added a few comments.

Comment thread oslo_cache/_opts.py Outdated
default=60,
help='Time in seconds before attempting to add a node '
'back in the pool in the HashClient\'s internal mechanisms.'),
'back in the pool in the HashClient\'s internal mechanisms.')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'back in the pool in the HashClient\'s internal mechanisms.')
'back in the pool in the HashClient\'s internal mechanisms.'),

Extra change

Comment thread oslo_cache/core.py Outdated
conf_dict['%s.arguments.dead_timeout' % prefix] = \
conf.cache.dead_timeout

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Extra change

Comment thread oslo_cache/backends/redis.py Outdated
"""
del arguments['username']
del arguments['password']
return super(RedisSentinelTLSBackend, self).__init__(arguments) No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return super(RedisSentinelTLSBackend, self).__init__(arguments)
return super(RedisSentinelTLSBackend, self).__init__(arguments)

Newline at the end of file.

Comment thread oslo_cache/backends/redis.py Outdated
Comment on lines +22 to +37
username=arguments['username'],
password=arguments['password']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
username=arguments['username'],
password=arguments['password']
username=arguments['username'],
password=arguments['password']

Incorrect padding.

Comment thread oslo_cache/backends/redis.py Outdated
__all__ = [
'RedisSentinelTLSBackend'
]
class RedisSentinelTLSBackend(redis_backend.RedisSentinelBackend):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class RedisSentinelTLSBackend(redis_backend.RedisSentinelBackend):
class RedisSentinelTLSBackend(redis_backend.RedisSentinelBackend):

https://peps.python.org/pep-0008/#blank-lines

Comment thread oslo_cache/backends/redis.py Outdated
connection_kwargs=reformated_kwargs,
sentinel_kwargs=reformated_kwargs
)
"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
"""

I would probably add a blank line here as well.

Comment thread oslo_cache/backends/redis.py Outdated
because user is unable to pass them using oslo config in it's current format
arguments:
sentinels: list of sentinels formated as sentinel1IP:port,sentinel2IP:port
ssl: turns on TLS

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is ssl a bool or a dict or something of extra options?

ssl: turns on TLS
ssl-<keyfile,certfile,ca_certs>: TLS certificate, key and CA
username,password: login credentials
"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably rewrite the docstring to be in Google docstring format so it is consistent with other backends already in oslo:

https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html

Arguments accepted in the arguments dictionary:
:param db_hosts: string (required), hostname or IP address of the
MongoDB server instance. This can be a single MongoDB connection URI,
or a list of MongoDB connection URIs.
:param db_name: string (required), the name of the database to be used.
:param cache_collection: string (required), the name of collection to store
cached data.
*Note:* Different collection name can be provided if there is need to
create separate container (i.e. collection) for cache data. So region
configuration is done per collection.
Following are optional parameters for MongoDB backend configuration,
:param username: string, the name of the user to authenticate.
:param password: string, the password of the user to authenticate.
:param max_pool_size: integer, the maximum number of connections that the
pool will open simultaneously. By default the pool size is 10.
:param w: integer, write acknowledgement for MongoDB client
If not provided, then no default is set on MongoDB and then write
acknowledgement behavior occurs as per MongoDB default. This parameter
name is same as what is used in MongoDB docs. This value is specified
at collection level so its applicable to `cache_collection` db write
operations.
If this is a replica set, write operations will block until they have
been replicated to the specified number or tagged set of servers.
Setting w=0 disables write acknowledgement and all other write concern
options.
:param read_preference: string, the read preference mode for MongoDB client
Expected value is ``primary``, ``primaryPreferred``, ``secondary``,
``secondaryPreferred``, or ``nearest``. This read_preference is
specified at collection level so its applicable to `cache_collection`
db read operations.
:param use_replica: boolean, flag to indicate if replica client to be
used. Default is `False`. `replicaset_name` value is required if
`True`.
:param replicaset_name: string, name of replica set.
Becomes required if `use_replica` is `True`
:param son_manipulator: string, name of class with module name which
implements MongoDB SONManipulator.
Default manipulator used is :class:`.BaseTransform`.
This manipulator is added per database. In multiple cache
configurations, the manipulator name should be same if same
database name ``db_name`` is used in those configurations.
SONManipulator is used to manipulate custom data types as they are
saved or retrieved from MongoDB. Custom impl is only needed if cached
data is custom class and needs transformations when saving or reading
from db. If dogpile cached value contains built-in data types, then
BaseTransform class is sufficient as it already handles dogpile
CachedValue class transformation.
:param mongo_ttl_seconds: integer, interval in seconds to indicate maximum
time-to-live value.
If value is greater than 0, then its assumed that cache_collection
needs to be TTL type (has index at 'doc_date' field).
By default, the value is -1 and its disabled.
Reference: <http://docs.mongodb.org/manual/tutorial/expire-data/>
.. NOTE::
This parameter is different from Dogpile own
expiration_time, which is the number of seconds after which Dogpile
will consider the value to be expired. When Dogpile considers a
value to be expired, it continues to use the value until generation
of a new value is complete, when using CacheRegion.get_or_create().
Therefore, if you are setting `mongo_ttl_seconds`, you will want to
make sure it is greater than expiration_time by at least enough
seconds for new values to be generated, else the value would not
be available during a regeneration, forcing all threads to wait for
a regeneration each time a value expires.
:param ssl: boolean, If True, create the connection to the server
using SSL. Default is `False`. Client SSL connection parameters depends
on server side SSL setup. For further reference on SSL configuration:
<http://docs.mongodb.org/manual/tutorial/configure-ssl/>
:param ssl_keyfile: string, the private keyfile used to identify the
local connection against mongod. If included with the certfile then
only the `ssl_certfile` is needed. Used only when `ssl` is `True`.
:param ssl_certfile: string, the certificate file used to identify the
local connection against mongod. Used only when `ssl` is `True`.
:param ssl_ca_certs: string, the ca_certs file contains a set of
concatenated 'certification authority' certificates, which are used to
validate certificates passed from the other end of the connection.
Used only when `ssl` is `True`.
:param ssl_cert_reqs: string, the parameter cert_reqs specifies whether
a certificate is required from the other side of the connection, and
whether it will be validated if provided. It must be one of the three
values ``ssl.CERT_NONE`` (certificates ignored), ``ssl.CERT_OPTIONAL``
(not required, but validated if provided), or
``ssl.CERT_REQUIRED`` (required and validated). If the value of this
parameter is not ``ssl.CERT_NONE``, then the ssl_ca_certs parameter
must point to a file of CA certificates. Used only when `ssl`
is `True`.
Rest of arguments are passed to mongo calls for read, write and remove.
So related options can be specified to pass to these operations.
Further details of various supported arguments can be referred from
<http://api.mongodb.org/python/current/api/pymongo/>

Comment thread oslo_cache/core.py
Comment on lines +165 to +172
# This removes username and password that are needed for redis_sentinel backend
if conf.cache.backend != "oslo_cache.redis_sentinel":
for arg in ('dead_retry', 'socket_timeout', 'pool_maxsize',
'pool_unused_timeout', 'pool_connection_get_timeout',
'pool_flush_on_reconnect', 'sasl_enabled', 'username',
'password'):
value = getattr(conf.cache, 'memcache_' + arg)
conf_dict['%s.arguments.%s' % (prefix, arg)] = value

@fdobrovolny fdobrovolny Jan 26, 2024 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 This may be an area where upstream will request a change. I suggest including line 162 as well. But I have to think about this bit more if there is a better way to achieve this 🤔

Comment thread oslo_cache/backends/redis.py Outdated
Comment on lines +38 to +42
"""
Usename and password must be deleted from arguments dict
after being added to connection_kwargs, otherwise there
will be AUTH error
"""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the core.py, they use # for multiline comment inside function. I would probably consider using that here, too.

@MatusJenca2
MatusJenca2 force-pushed the redis-sentinel-tls branch 3 times, most recently from be2908e to c523383 Compare January 26, 2024 15:11
@fdobrovolny

Copy link
Copy Markdown

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants