Skip to content

Commit 6637a03

Browse files
Merge 8f9859e into 4b60d4d
2 parents 4b60d4d + 8f9859e commit 6637a03

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

ydb/core/viewer/json_tenantinfo.h

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
5656
TString RootId; // id of root domain (tenant)
5757
NKikimrViewer::TTenantInfo Result;
5858

59+
struct TStorageUsage {
60+
uint64 Size = 0;
61+
uint64 Limit = 0;
62+
uint64 SoftQuota = 0;
63+
uint64 HardQuota = 0;
64+
};
65+
5966
public:
6067
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
6168
return NKikimrServices::TActivity::VIEWER_HANDLER;
@@ -478,6 +485,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
478485
}
479486
}
480487

488+
NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) {
489+
auto kind = to_lower(poolKind);
490+
if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) {
491+
return NKikimrViewer::TStorageUsage::SSD;
492+
}
493+
if (kind.StartsWith("hdd") || kind.StartsWith("rot")) {
494+
return NKikimrViewer::TStorageUsage::HDD;
495+
}
496+
return NKikimrViewer::TStorageUsage::None;
497+
}
498+
481499
void ReplyAndPassAway() {
482500
BLOG_TRACE("ReplyAndPassAway() started");
483501
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -632,23 +650,32 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
632650
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
633651
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
634652
tenant.SetStorageGroups(storageGroups);
653+
}
635654

636-
auto& ssdUsage = *tenant.AddStorageUsage();
637-
ssdUsage.SetType(NKikimrViewer::TStorageUsage::SSD);
638-
ssdUsage.SetSize(storageAllocatedSize);
639-
ssdUsage.SetLimit(storageAllocatedLimit);
640-
// TODO(andrew-rykov)
641-
auto& hddUsage = *tenant.AddStorageUsage();
642-
hddUsage.SetType(NKikimrViewer::TStorageUsage::HDD);
643-
644-
if (tenant.databasequotas().data_size_hard_quota()) {
645-
auto& ssdQuotaUsage = *tenant.AddQuotaUsage();
646-
ssdQuotaUsage.SetType(NKikimrViewer::TStorageUsage::SSD);
647-
ssdQuotaUsage.SetSize(tenant.GetMetrics().GetStorage());
648-
ssdQuotaUsage.SetLimit(tenant.databasequotas().data_size_hard_quota());
649-
auto& hddQuotaUsage = *tenant.AddQuotaUsage();
650-
hddQuotaUsage.SetType(NKikimrViewer::TStorageUsage::HDD);
651-
}
655+
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageUsage> StorageUsageByType;
656+
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
657+
auto type = GetStorageType(poolUsage.GetPoolKind());
658+
auto& usage = StorageUsageByType[type];
659+
660+
usage.Size += poolUsage.GetDataSize();
661+
usage.Limit += poolUsage.GetTotalSize();
662+
}
663+
664+
for (auto& quota: tenant.databasequotas().storage_quotas()) {
665+
auto type = GetStorageType(quota.unit_kind());
666+
auto& usage = StorageUsageByType[type];
667+
668+
usage.SoftQuota += quota.data_size_soft_quota();
669+
usage.HardQuota += quota.data_size_hard_quota();
670+
}
671+
672+
for (const auto& [type, usage] : StorageUsageByType) {
673+
auto& storageUsage = *tenant.AddStorageUsage();
674+
storageUsage.SetType(type);
675+
storageUsage.SetSize(usage.Size);
676+
storageUsage.SetLimit(usage.Limit);
677+
storageUsage.SetSoftQuota(usage.SoftQuota);
678+
storageUsage.SetHardQuota(usage.HardQuota);
652679
}
653680
}
654681

0 commit comments

Comments
 (0)