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 <jlarriba@redhat.com>
This commit is contained in:
Juan Larriba
2025-12-16 14:46:44 +01:00
parent 38de7d1b28
commit 6990952bd7

View File

@@ -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):