summaryrefslogtreecommitdiff
path: root/ceilometer/polling
diff options
context:
space:
mode:
authorYadnesh Kulkarni <ykulkarn@redhat.com>2022-08-01 10:42:02 +0000
committerYadnesh Kulkarni <ykulkarn@redhat.com>2022-09-13 11:15:51 +0000
commit79454d6b22787627ae6239aa7b2707101ba30212 (patch)
treecba04acbc58b7ee581eb0001837f6216940b2a33 /ceilometer/polling
parent6f88ee6be9a3ae5c78587f1a2bc8cd2e9a5a2fa7 (diff)
downloadceilometer-79454d6b22787627ae6239aa7b2707101ba30212.tar.gz
Add user/project names to polled samples
Project and user names would be first fetched from cache, if not found, they will be requested from keystone and then cached. Using cache will significanlty reduce the number of calls made to keystone. If ceilometer is configured with no caching backend, the results will always be fetched by querying request to keystone. A new config option, `tenant_name_discovery` is introduced to operate this feature. This feature is optional and is disabled by default. No attempts to identify names will be made if uuids are found to be `None`. Signed-off-by: Yadnesh Kulkarni <ykulkarn@redhat.com> Change-Id: Iee5dbf09a1fd3ac571746fc66d2683eb8e6a1b27
Diffstat (limited to 'ceilometer/polling')
-rw-r--r--ceilometer/polling/manager.py63
1 files changed, 62 insertions, 1 deletions
diff --git a/ceilometer/polling/manager.py b/ceilometer/polling/manager.py
index 6b9289d1..e5776a3e 100644
--- a/ceilometer/polling/manager.py
+++ b/ceilometer/polling/manager.py
@@ -35,6 +35,7 @@ from tooz import coordination
from urllib import parse as urlparse
from ceilometer import agent
+from ceilometer import cache_utils
from ceilometer import declarative
from ceilometer import keystone_client
from ceilometer import messaging
@@ -45,6 +46,8 @@ from ceilometer import utils
LOG = log.getLogger(__name__)
+CACHE_DURATION = 3600
+
POLLING_OPTS = [
cfg.StrOpt('cfg_file',
default="polling.yaml",
@@ -64,7 +67,18 @@ POLLING_OPTS = [
cfg.MultiStrOpt('pollsters_definitions_dirs',
default=["/etc/ceilometer/pollsters.d"],
help="List of directories with YAML files used "
- "to created pollsters.")
+ "to created pollsters."),
+ cfg.BoolOpt('tenant_name_discovery',
+ default=False,
+ help="Identify project and user names from polled samples"
+ "By default, collecting these values is disabled due"
+ "to the fact that it could overwhelm keystone service"
+ "with lots of continuous requests depending upon the"
+ "number of projects, users and samples polled from"
+ "the environment. While using this feature, it is"
+ "recommended that ceilometer be configured with a"
+ "caching backend to reduce the number of calls"
+ "made to keystone"),
]
@@ -138,11 +152,39 @@ class PollingTask(object):
self._telemetry_secret = self.manager.conf.publisher.telemetry_secret
+ self.ks_client = self.manager.keystone
+
+ self.cache_client = cache_utils.get_client(
+ self.manager.conf,
+ expiration_time=CACHE_DURATION
+ )
+
def add(self, pollster, source):
self.pollster_matches[source.name].add(pollster)
key = Resources.key(source.name, pollster)
self.resources[key].setup(source)
+ def resolve_uuid_from_cache(self, attr, uuid):
+ if self.cache_client:
+ name = self.cache_client.get(uuid)
+ if name:
+ return name
+ name = self.resolve_uuid_from_keystone(attr, uuid)
+ self.cache_client.set(uuid, name)
+ return name
+
+ # Retrieve project and user names from Keystone only
+ # if ceilometer doesn't have a caching backend
+ return self.resolve_uuid_from_keystone(attr, uuid)
+
+ def resolve_uuid_from_keystone(self, attr, uuid):
+ try:
+ return getattr(self.ks_client, attr).get(uuid).name
+ except AttributeError as e:
+ LOG.warning("Found '%s' while resolving uuid %s to name", e, uuid)
+ except ka_exceptions.NotFound as e:
+ LOG.warning(e.message)
+
def poll_and_notify(self):
"""Polling sample and notify."""
cache = {}
@@ -194,6 +236,25 @@ class PollingTask(object):
for sample in samples:
# Note(yuywz): Unify the timestamp of polled samples
sample.set_timestamp(polling_timestamp)
+
+ if self.manager.conf.tenant_name_discovery:
+
+ # Try to resolve project UUIDs from cache first,
+ # and then keystone
+ if sample.project_id:
+ sample.project_name = \
+ self.resolve_uuid_from_cache(
+ "projects", sample.project_id
+ )
+
+ # Try to resolve user UUIDs from cache first,
+ # and then keystone
+ if sample.user_id:
+ sample.user_name = \
+ self.resolve_uuid_from_cache(
+ "users", sample.user_id
+ )
+
sample_dict = (
publisher_utils.meter_message_from_counter(
sample, self._telemetry_secret