Skip to content

Commit 53a2b23

Browse files
Merge 2973cd1 into ec70ba4
2 parents ec70ba4 + 2973cd1 commit 53a2b23

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

ydb/core/viewer/json_tenantinfo.h

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ 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 SoftQuota = 0;
62+
uint64 HardQuota = 0;
63+
};
64+
5965
public:
6066
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
6167
return NKikimrServices::TActivity::VIEWER_HANDLER;
@@ -478,6 +484,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
478484
}
479485
}
480486

487+
NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) {
488+
auto kind = to_lower(poolKind);
489+
if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) {
490+
return NKikimrViewer::TStorageUsage::SSD;
491+
}
492+
if (kind.StartsWith("hdd") || kind.StartsWith("rot")) {
493+
return NKikimrViewer::TStorageUsage::HDD;
494+
}
495+
return NKikimrViewer::TStorageUsage::None;
496+
}
497+
481498
void ReplyAndPassAway() {
482499
BLOG_TRACE("ReplyAndPassAway() started");
483500
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -632,22 +649,32 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
632649
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
633650
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
634651
tenant.SetStorageGroups(storageGroups);
652+
}
653+
654+
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageUsage> storageUsageByType;
655+
if (entry.DomainDescription) {
656+
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
657+
auto type = GetStorageType(poolUsage.GetPoolKind());
658+
auto& usage = storageUsageByType[type];
659+
usage.Size += poolUsage.GetTotalSize();
660+
}
661+
}
662+
663+
for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
664+
auto type = GetStorageType(quota.unit_kind());
665+
auto& usage = storageUsageByType[type];
666+
usage.SoftQuota += quota.data_size_soft_quota();
667+
usage.HardQuota += quota.data_size_hard_quota();
668+
}
635669

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);
670+
for (const auto& [type, usage] : storageUsageByType) {
671+
if (usage.Size && usage.SoftQuota && usage.HardQuota) {
672+
auto& storageUsage = *tenant.AddStorageUsage();
673+
storageUsage.SetType(type);
674+
storageUsage.SetSize(usage.Size);
675+
storageUsage.SetLimit(usage.HardQuota);
676+
storageUsage.SetSoftQuota(usage.SoftQuota);
677+
storageUsage.SetHardQuota(usage.HardQuota);
651678
}
652679
}
653680
}

ydb/core/viewer/protos/viewer.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ message TStorageUsage {
345345
EType Type = 1;
346346
uint64 Size = 2;
347347
uint64 Limit = 3;
348+
uint64 SoftQuota = 4;
349+
uint64 HardQuota = 5;
348350
}
349351

350352
message TTenant {
@@ -376,7 +378,6 @@ message TTenant {
376378
uint64 StorageAllocatedLimit = 41;
377379
Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42;
378380
repeated TStorageUsage StorageUsage = 43;
379-
repeated TStorageUsage QuotaUsage = 44;
380381
}
381382

382383
message TTenants {

0 commit comments

Comments
 (0)