From de91333fedf214835e978ccdf2e21798a41625e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Tue, 21 Nov 2023 13:48:19 -0300 Subject: [PATCH] Fix `TelemetryIpc` when using `tenant_name_discovery=False` Patches [1-2] introduced the variables `project_name` and `user_name` for the Ceilometer samples that are collected. The gathering of these attributes is controlled with the use of the parameter `tenant_name_discovery` , which defaults to False. However, when it (the parameter) is set as False, an error will happen at [2], as the key will not exist in the dictionary. This patch fixes the described issue. Without this patch, the error that happens is the follwoing: ``` ERROR ceilometer.pipeline.sample [-] Fail to process notification: KeyError: 'user_name' ERROR ceilometer.pipeline.sample Traceback (most recent call last): ERROR ceilometer.pipeline.sample File "/usr/lib/python3/dist-packages/ceilometer/pipeline/sample.py", line 44, in process_notifications ERROR ceilometer.pipeline.sample p(list(self.build_sample(message))) ERROR ceilometer.pipeline.sample File "/usr/lib/python3/dist-packages/ceilometer/telemetry/notifications.py", line 34, in build_sample ERROR ceilometer.pipeline.sample user_name=sample_dict['user_name'], ERROR ceilometer.pipeline.sample KeyError: 'user_name' ERROR ceilometer.pipeline.sample ``` [1] https://review.opendev.org/c/openstack/ceilometer/+/877647 [2] https://github.com/openstack/ceilometer/commit/2a5f63da95a26dae46707a2a22e593604726aeae Change-Id: I54a0fd43ac2da1b9a8bcdeae7ad7d160bc07f35b --- ceilometer/telemetry/notifications.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ceilometer/telemetry/notifications.py b/ceilometer/telemetry/notifications.py index cd739a4761..e807b5e752 100644 --- a/ceilometer/telemetry/notifications.py +++ b/ceilometer/telemetry/notifications.py @@ -31,11 +31,16 @@ class TelemetryIpc(endpoint.SampleEndpoint): unit=sample_dict['counter_unit'], volume=sample_dict['counter_volume'], user_id=sample_dict['user_id'], - user_name=sample_dict['user_name'], project_id=sample_dict['project_id'], - project_name=sample_dict['project_name'], resource_id=sample_dict['resource_id'], timestamp=sample_dict['timestamp'], resource_metadata=sample_dict['resource_metadata'], source=sample_dict['source'], - id=sample_dict['message_id']) + id=sample_dict['message_id'], + + # Project name and username might not be set, depending on the + # configuration `tenant_name_discovery`. Therefore, we cannot + # assume that they exist in the sample dictionary. + user_name=sample_dict.get('user_name'), + project_name=sample_dict.get('project_name') + )