Skip to content

Commit 43e2e7d

Browse files
Merge 01150cf into dd3fb68
2 parents dd3fb68 + 01150cf commit 43e2e7d

File tree

2 files changed

+42
-16
lines changed

2 files changed

+42
-16
lines changed

ydb/core/viewer/json_tenantinfo.h

Lines changed: 40 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,24 +649,32 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
632649
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
633650
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
634651
tenant.SetStorageGroups(storageGroups);
652+
}
635653

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

655680
THashSet<TNodeId> tenantNodes;

ydb/core/viewer/protos/viewer.proto

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

349351
message TTenant {
@@ -375,7 +377,6 @@ message TTenant {
375377
uint64 StorageAllocatedLimit = 41;
376378
Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42;
377379
repeated TStorageUsage StorageUsage = 43;
378-
repeated TStorageUsage QuotaUsage = 44;
379380
}
380381

381382
message TTenants {

0 commit comments

Comments
 (0)