Skip to content

Commit 8f9859e

Browse files
quota tenantinfo
1 parent 7156a4e commit 8f9859e

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
@@ -55,6 +55,13 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
5555
TString RootId; // id of root domain (tenant)
5656
NKikimrViewer::TTenantInfo Result;
5757

58+
struct TStorageUsage {
59+
uint64 Size = 0;
60+
uint64 Limit = 0;
61+
uint64 SoftQuota = 0;
62+
uint64 HardQuota = 0;
63+
};
64+
5865
public:
5966
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
6067
return NKikimrServices::TActivity::VIEWER_HANDLER;
@@ -476,6 +483,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
476483
}
477484
}
478485

486+
NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) {
487+
auto kind = to_lower(poolKind);
488+
if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) {
489+
return NKikimrViewer::TStorageUsage::SSD;
490+
}
491+
if (kind.StartsWith("hdd") || kind.StartsWith("rot")) {
492+
return NKikimrViewer::TStorageUsage::HDD;
493+
}
494+
return NKikimrViewer::TStorageUsage::None;
495+
}
496+
479497
void ReplyAndPassAway() {
480498
BLOG_TRACE("ReplyAndPassAway() started");
481499
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -628,23 +646,32 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
628646
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
629647
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
630648
tenant.SetStorageGroups(storageGroups);
649+
}
631650

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

0 commit comments

Comments
 (0)