Skip to content

Commit

Permalink
quota tenantinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
StekPerepolnen committed Jun 5, 2024
1 parent 7156a4e commit be72fed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
57 changes: 42 additions & 15 deletions ydb/core/viewer/json_tenantinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
TString RootId; // id of root domain (tenant)
NKikimrViewer::TTenantInfo Result;

struct TStorageQuota {
uint64 SoftQuota = 0;
uint64 HardQuota = 0;
};

public:
static constexpr NKikimrServices::TActivity::EType ActorActivityType() {
return NKikimrServices::TActivity::VIEWER_HANDLER;
Expand Down Expand Up @@ -476,6 +481,17 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
}
}

NKikimrViewer::TStorageUsage::EType GetStorageType(const TString& poolKind) {
auto kind = to_lower(poolKind);
if (kind.StartsWith("ssd") || kind.StartsWith("nvme")) {
return NKikimrViewer::TStorageUsage::SSD;
}
if (kind.StartsWith("hdd") || kind.StartsWith("rot")) {
return NKikimrViewer::TStorageUsage::HDD;
}
return NKikimrViewer::TStorageUsage::None;
}

void ReplyAndPassAway() {
BLOG_TRACE("ReplyAndPassAway() started");
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
Expand Down Expand Up @@ -628,22 +644,33 @@ class TJsonTenantInfo : public TViewerPipeClient<TJsonTenantInfo> {
tenant.SetStorageAllocatedLimit(storageAllocatedLimit);
tenant.SetStorageMinAvailableSize(storageMinAvailableSize);
tenant.SetStorageGroups(storageGroups);
}

THashMap<NKikimrViewer::TStorageUsage::EType, ui64> storageUsageByType;
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageQuota> storageQuotasByType;
if (entry.DomainDescription) {
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
auto type = GetStorageType(poolUsage.GetPoolKind());
storageUsageByType[type] += poolUsage.GetTotalSize();
}
}

for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
auto type = GetStorageType(quota.unit_kind());
auto& usage = storageQuotasByType[type];
usage.SoftQuota += quota.data_size_soft_quota();
usage.HardQuota += quota.data_size_hard_quota();
}

auto& ssdUsage = *tenant.AddStorageUsage();
ssdUsage.SetType(NKikimrViewer::TStorageUsage::SSD);
ssdUsage.SetSize(storageAllocatedSize);
ssdUsage.SetLimit(storageAllocatedLimit);
// TODO(andrew-rykov)
auto& hddUsage = *tenant.AddStorageUsage();
hddUsage.SetType(NKikimrViewer::TStorageUsage::HDD);

if (tenant.databasequotas().data_size_hard_quota()) {
auto& ssdQuotaUsage = *tenant.AddQuotaUsage();
ssdQuotaUsage.SetType(NKikimrViewer::TStorageUsage::SSD);
ssdQuotaUsage.SetSize(tenant.GetMetrics().GetStorage());
ssdQuotaUsage.SetLimit(tenant.databasequotas().data_size_hard_quota());
auto& hddQuotaUsage = *tenant.AddQuotaUsage();
hddQuotaUsage.SetType(NKikimrViewer::TStorageUsage::HDD);
for (const auto& [type, size] : storageUsageByType) {
auto& storageUsage = *tenant.AddStorageUsage();
storageUsage.SetType(type);
storageUsage.SetSize(size);
auto it = storageQuotasByType.find(type);
if (it != storageQuotasByType.end()) {
storageUsage.SetLimit(it->second.HardQuota);
storageUsage.SetSoftQuota(it->second.SoftQuota);
storageUsage.SetHardQuota(it->second.HardQuota);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/viewer/protos/viewer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ message TStorageUsage {
EType Type = 1;
uint64 Size = 2;
uint64 Limit = 3;
uint64 SoftQuota = 4;
uint64 HardQuota = 5;
}

message TTenant {
Expand Down Expand Up @@ -375,7 +377,6 @@ message TTenant {
uint64 StorageAllocatedLimit = 41;
Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42;
repeated TStorageUsage StorageUsage = 43;
repeated TStorageUsage QuotaUsage = 44;
}

message TTenants {
Expand Down

0 comments on commit be72fed

Please sign in to comment.