Skip to content

Commit f3dfce2

Browse files
quota tenantinfo
1 parent 7156a4e commit f3dfce2

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

ydb/core/viewer/json_tenantinfo.h

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ 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 SoftQuota = 0;
61+
uint64 HardQuota = 0;
62+
};
63+
5864
public:
5965
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
6066
return NKikimrServices::TActivity::VIEWER_HANDLER;
@@ -476,6 +482,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
476482
}
477483
}
478484

485+
NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) {
486+
auto kind = to_lower(poolKind);
487+
if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) {
488+
return NKikimrViewer::TStorageUsage::SSD;
489+
}
490+
if (kind.StartsWith("hdd") || kind.StartsWith("rot")) {
491+
return NKikimrViewer::TStorageUsage::HDD;
492+
}
493+
return NKikimrViewer::TStorageUsage::None;
494+
}
495+
479496
void ReplyAndPassAway() {
480497
BLOG_TRACE("ReplyAndPassAway() started");
481498
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
@@ -628,23 +645,42 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
628645
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
629646
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
630647
tenant.SetStorageGroups(storageGroups);
648+
}
649+
650+
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageUsage> storageUsageByType;
651+
if (entry.DomainDescription) {
652+
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
653+
auto type = GetStorageType(poolUsage.GetPoolKind());
654+
auto& usage = storageUsageByType[type];
655+
usage.Size += poolUsage.GetTotalSize();
656+
}
657+
}
658+
659+
for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
660+
auto type = GetStorageType(quota.unit_kind());
661+
auto& usage = storageUsageByType[type];
662+
usage.SoftQuota += quota.data_size_soft_quota();
663+
usage.HardQuota += quota.data_size_hard_quota();
664+
}
665+
666+
auto priorityType = NKikimrViewer::TStorageUsage::None;
667+
for (const auto& [type, usage] : storageUsageByType) {
668+
if (type > priorityType) {
669+
priorityType = type;
670+
}
671+
}
631672

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);
673+
for (const auto& [type, usage] : storageUsageByType) {
674+
auto& storageUsage = *tenant.AddStorageUsage();
675+
storageUsage.SetType(type);
676+
storageUsage.SetSize(usage.Size);
677+
if (usage.HardQuota) {
678+
storageUsage.SetLimit(usage.HardQuota);
679+
} else if (type == priorityType) {
680+
storageUsage.SetLimit(tenant.GetStorageAllocatedLimit());
647681
}
682+
storageUsage.SetSoftQuota(usage.SoftQuota);
683+
storageUsage.SetHardQuota(usage.HardQuota);
648684
}
649685
}
650686

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)