From 6990952bd7abfca524ba9f4eef4c9ea79da75177 Mon Sep 17 00:00:00 2001 From: Juan Larriba Date: Tue, 16 Dec 2025 14:46:44 +0100 Subject: [PATCH] Use scope_key in summary API operation The user can define any label of their metrics as the scope key, the scope_key parameter exists. However, it is not taken in account for the summary operation, where project_id is hardcoded instead of using the appropiate scope_key. This fixes that behaviour and extends the scope_key parameter usage to the summary operation Change-Id: Iaa092d33f6cbd02b415116cdd4337ef9299c429e Signed-off-by: Juan Larriba --- cloudkitty/api/v2/summary/summary.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cloudkitty/api/v2/summary/summary.py b/cloudkitty/api/v2/summary/summary.py index 8d34f721..77d1094d 100644 --- a/cloudkitty/api/v2/summary/summary.py +++ b/cloudkitty/api/v2/summary/summary.py @@ -13,6 +13,7 @@ # under the License. # import flask +from oslo_config import cfg import voluptuous from cloudkitty.api.v2 import base @@ -25,6 +26,10 @@ OBJECT_RESPONSE_FORMAT = "object" ALL_RESPONSE_FORMATS = [TABLE_RESPONSE_FORMAT, OBJECT_RESPONSE_FORMAT] +CONF = cfg.CONF + +CONF.import_opt('scope_key', 'cloudkitty.collector', 'collect') + class Summary(base.BaseResource): """Resource allowing to retrieve a rating summary.""" @@ -66,7 +71,11 @@ class Summary(base.BaseResource): 'columns': [], 'results': [], } - filters['project_id'] = flask.request.context.project_id + scope_key = CONF.collect.scope_key + if filters: + filters[scope_key] = flask.request.context.project_id + else: + filters = {scope_key: flask.request.context.project_id} metric_types = filters.pop('type', []) if not isinstance(metric_types, list):