diff options
author | Yadnesh Kulkarni <ykulkarn@redhat.com> | 2022-11-08 03:01:11 -0500 |
---|---|---|
committer | Yadnesh Kulkarni <ykulkarn@redhat.com> | 2022-11-21 09:17:08 -0500 |
commit | b4a2801ec6a99df400d353d27a11de9be879c2a3 (patch) | |
tree | b80e121031f6968850dbebc4a62dc0bf82861171 /ceilometer/publisher | |
parent | 9fe3674e4705837ef4dbe1a4cd433e6bfd5f9fbd (diff) | |
download | ceilometer-b4a2801ec6a99df400d353d27a11de9be879c2a3.tar.gz |
Change oslo_cache implementation
As of now to leverage caching, oslo_cache library has to be imported
and configured everytime it's needed.
This change migrates such implementatio to use `cache_utils.py`
which returns a cache client to perform caching operations. This
eliminates the purpose of importing oslo_cache everytime when needed.
To get a cache client:
```
from ceilometer import cache_utils
.
cache_client = cache_utils.get_client(conf)
```
Signed-off-by: Yadnesh Kulkarni <ykulkarn@redhat.com>
Change-Id: I14f9e1cbe84a953b092c3a88345d5faa9bcc9fb2
Diffstat (limited to 'ceilometer/publisher')
-rw-r--r-- | ceilometer/publisher/gnocchi.py | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/ceilometer/publisher/gnocchi.py b/ceilometer/publisher/gnocchi.py index 2741ba00..355f5320 100644 --- a/ceilometer/publisher/gnocchi.py +++ b/ceilometer/publisher/gnocchi.py @@ -14,39 +14,29 @@ # under the License. from collections import defaultdict import fnmatch -import hashlib import itertools import json import operator import pkg_resources import threading -import uuid from gnocchiclient import exceptions as gnocchi_exc from keystoneauth1 import exceptions as ka_exceptions -import oslo_cache from oslo_log import log from oslo_utils import timeutils from stevedore import extension from urllib import parse as urlparse +from ceilometer import cache_utils from ceilometer import declarative from ceilometer import gnocchi_client from ceilometer.i18n import _ from ceilometer import keystone_client from ceilometer import publisher -NAME_ENCODED = __name__.encode('utf-8') -CACHE_NAMESPACE = uuid.UUID(bytes=hashlib.md5(NAME_ENCODED).digest()) LOG = log.getLogger(__name__) -def cache_key_mangler(key): - """Construct an opaque cache key.""" - - return uuid.uuid5(CACHE_NAMESPACE, key).hex - - EVENT_CREATE, EVENT_UPDATE, EVENT_DELETE = ("create", "update", "delete") @@ -213,20 +203,11 @@ class GnocchiPublisher(publisher.ConfigPublisherBase): timeout = options.get('timeout', [6.05])[-1] self._ks_client = keystone_client.get_client(conf) - self.cache = None - try: - oslo_cache.configure(conf) - # NOTE(cdent): The default cache backend is a real but - # noop backend. We don't want to use that here because - # we want to avoid the cache pathways entirely if the - # cache has not been configured explicitly. - if conf.cache.enabled: - cache_region = oslo_cache.create_region() - self.cache = oslo_cache.configure_cache_region( - conf, cache_region) - self.cache.key_mangler = cache_key_mangler - except oslo_cache.exception.ConfigurationError as exc: - LOG.warning('unable to configure oslo_cache: %s', exc) + # NOTE(cdent): The default cache backend is a real but + # noop backend. We don't want to use that here because + # we want to avoid the cache pathways entirely if the + # cache has not been configured explicitly. + self.cache = cache_utils.get_client(conf) self._gnocchi_project_id = None self._gnocchi_project_id_lock = threading.Lock() |