Skip to content

Commit 9d1edfe

Browse files
Merge be72fed into 2d68e78
2 parents 2d68e78 + be72fed commit 9d1edfe

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

59+
struct TStorageQuota {
60+
uint64 SoftQuota = 0;
61+
uint64 HardQuota = 0;
62+
};
63+
5964
public:
6065
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
6166
return NKikimrServices::TActivity::VIEWER_HANDLER;
@@ -478,6 +483,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
478483
}
479484
}
480485

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+
481497
void ReplyAndPassAway() {
482498
BLOG_TRACE("ReplyAndPassAway() started");
483499
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -632,22 +648,33 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
632648
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
633649
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
634650
tenant.SetStorageGroups(storageGroups);
651+
}
652+
653+
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> storageUsageByType;
654+
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageQuota> storageQuotasByType;
655+
if (entry.DomainDescription) {
656+
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
657+
auto type = GetStorageType(poolUsage.GetPoolKind());
658+
storageUsageByType[type] += poolUsage.GetTotalSize();
659+
}
660+
}
661+
662+
for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
663+
auto type = GetStorageType(quota.unit_kind());
664+
auto& usage = storageQuotasByType[type];
665+
usage.SoftQuota += quota.data_size_soft_quota();
666+
usage.HardQuota += quota.data_size_hard_quota();
667+
}
635668

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);
669+
for (const auto& [type, size] : storageUsageByType) {
670+
auto& storageUsage = *tenant.AddStorageUsage();
671+
storageUsage.SetType(type);
672+
storageUsage.SetSize(size);
673+
auto it = storageQuotasByType.find(type);
674+
if (it != storageQuotasByType.end()) {
675+
storageUsage.SetLimit(it->second.HardQuota);
676+
storageUsage.SetSoftQuota(it->second.SoftQuota);
677+
storageUsage.SetHardQuota(it->second.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)