From e75cdad86417e33baec455fff00bb1846d205471 Mon Sep 17 00:00:00 2001 From: Luis Fernandez Alvarez <luis.fernandez.alvarez@cern.ch> Date: Wed, 16 Oct 2024 17:05:59 +0200 Subject: [PATCH] [OS-18349] Fix dblogger Manila quota metrics per project per type --- dblogger/producer/manila.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/dblogger/producer/manila.py b/dblogger/producer/manila.py index 6cc38e1..33f50c0 100644 --- a/dblogger/producer/manila.py +++ b/dblogger/producer/manila.py @@ -16,6 +16,8 @@ class Manila(BaseDB): # Create table mapping self.Quota = self.db.map_table('quotas') + self.ProjectShareTypeQuota = self.db.map_table( + 'project_share_type_quotas') self.QuotaUsage = self.db.map_table('quota_usages') self.Shares = self.db.map_table('shares') self.ShareInstances = self.db.map_table('share_instances') @@ -286,31 +288,38 @@ class Manila(BaseDB): # SELECT # quota_usages.project_id, # quota_usages.resource, - # share_types.name, - # sum(in_use), - # max(hard_limit) + # share_types.name AS share_type, + # sum(in_use) AS quota_usage, + # max(hard_limit) AS quota_limit # FROM quota_usages - # LEFT JOIN quotas - # ON quotas.project_id = quota_usages.project_id - # AND quotas.resource = quota_usages.resource + # LEFT JOIN project_share_type_quotas + # ON project_share_type_quotas.project_id = quota_usages.project_id + # AND project_share_type_quotas.resource = quota_usages.resource + # AND project_share_type_quotas.share_type_id = + # quota_usages.share_type_id # LEFT JOIN share_types # ON share_types.id = quota_usages.share_type_id - # WHERE share_type_id IS NOT NULL - # GROUP BY resource, project_id, share_type_id - # ORDER BY project_id, name, resource; + # WHERE quota_usages.share_type_id IS NOT NULL + # GROUP BY resource, project_id, quota_usages.share_type_id + # ORDER BY project_id, name, RESOURCE; return ( self.db.query( self.QuotaUsage.project_id.label("project_id"), self.QuotaUsage.resource.label("resource"), self.ShareTypes.name.label("share_type"), func.sum(self.QuotaUsage.in_use).label("quota_usage"), - func.max(self.Quota.hard_limit).label("quota_limit") + func.max(self.ProjectShareTypeQuota.hard_limit).label( + "quota_limit") ) .join( - self.Quota, + self.ProjectShareTypeQuota, and_( - self.Quota.project_id == self.QuotaUsage.project_id, - self.Quota.resource == self.QuotaUsage.resource + self.ProjectShareTypeQuota.project_id + == self.QuotaUsage.project_id, + self.ProjectShareTypeQuota.resource + == self.QuotaUsage.resource, + self.ProjectShareTypeQuota.share_type_id + == self.QuotaUsage.share_type_id ), isouter=True ) -- GitLab