diff --git a/ydb/core/viewer/json_tenantinfo.h b/ydb/core/viewer/json_tenantinfo.h index 1bf9d724dcf9..10c917c3eaa3 100644 --- a/ydb/core/viewer/json_tenantinfo.h +++ b/ydb/core/viewer/json_tenantinfo.h @@ -55,6 +55,12 @@ class TJsonTenantInfo : public TViewerPipeClient { TString RootId; // id of root domain (tenant) NKikimrViewer::TTenantInfo Result; + struct TStorageUsage { + uint64 Size = 0; + uint64 SoftQuota = 0; + uint64 HardQuota = 0; + }; + public: static constexpr NKikimrServices::TActivity::EType ActorActivityType() { return NKikimrServices::TActivity::VIEWER_HANDLER; @@ -476,6 +482,17 @@ class TJsonTenantInfo : public TViewerPipeClient { } } + NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) { + auto kind = to_lower(poolKind); + if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) { + return NKikimrViewer::TStorageUsage::SSD; + } + if (kind.StartsWith("hdd") || kind.StartsWith("rot")) { + return NKikimrViewer::TStorageUsage::HDD; + } + return NKikimrViewer::TStorageUsage::None; + } + void ReplyAndPassAway() { BLOG_TRACE("ReplyAndPassAway() started"); TIntrusivePtr domains = AppData()->DomainsInfo; @@ -628,24 +645,32 @@ class TJsonTenantInfo : public TViewerPipeClient { tenant.SetStorageAllocatedLimit(storageAllocatedLimit); tenant.SetStorageMinAvailableSize(storageMinAvailableSize); tenant.SetStorageGroups(storageGroups); + } - auto& ssdUsage = *tenant.AddStorageUsage(); - ssdUsage.SetType(NKikimrViewer::TStorageUsage::SSD); - ssdUsage.SetSize(storageAllocatedSize); - ssdUsage.SetLimit(storageAllocatedLimit); - // TODO(andrew-rykov) - auto& hddUsage = *tenant.AddStorageUsage(); - hddUsage.SetType(NKikimrViewer::TStorageUsage::HDD); - - if (tenant.databasequotas().data_size_hard_quota()) { - auto& ssdQuotaUsage = *tenant.AddQuotaUsage(); - ssdQuotaUsage.SetType(NKikimrViewer::TStorageUsage::SSD); - ssdQuotaUsage.SetSize(tenant.GetMetrics().GetStorage()); - ssdQuotaUsage.SetLimit(tenant.databasequotas().data_size_hard_quota()); - auto& hddQuotaUsage = *tenant.AddQuotaUsage(); - hddQuotaUsage.SetType(NKikimrViewer::TStorageUsage::HDD); + THashMap storageUsageByType; + if (entry.DomainDescription) { + for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) { + auto type = GetStorageType(poolUsage.GetPoolKind()); + auto& usage = storageUsageByType[type]; + usage.Size += poolUsage.GetTotalSize(); } } + + for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) { + auto type = GetStorageType(quota.unit_kind()); + auto& usage = storageUsageByType[type]; + usage.SoftQuota += quota.data_size_soft_quota(); + usage.HardQuota += quota.data_size_hard_quota(); + } + + for (const auto& [type, usage] : storageUsageByType) { + auto& storageUsage = *tenant.AddStorageUsage(); + storageUsage.SetType(type); + storageUsage.SetSize(usage.Size); + storageUsage.SetLimit(usage.HardQuota); + storageUsage.SetSoftQuota(usage.SoftQuota); + storageUsage.SetHardQuota(usage.HardQuota); + } } THashSet tenantNodes; diff --git a/ydb/core/viewer/protos/viewer.proto b/ydb/core/viewer/protos/viewer.proto index e194ad7ac6e8..478fa9ca5094 100644 --- a/ydb/core/viewer/protos/viewer.proto +++ b/ydb/core/viewer/protos/viewer.proto @@ -344,6 +344,8 @@ message TStorageUsage { EType Type = 1; uint64 Size = 2; uint64 Limit = 3; + uint64 SoftQuota = 4; + uint64 HardQuota = 5; } message TTenant { @@ -375,7 +377,6 @@ message TTenant { uint64 StorageAllocatedLimit = 41; Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42; repeated TStorageUsage StorageUsage = 43; - repeated TStorageUsage QuotaUsage = 44; } message TTenants {