Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tenantinfo handler added DatabaseStorage #7554

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ydb/core/viewer/json_handlers_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void InitViewerHiveStatsJsonHandler(TJsonHandlers& handlers) {
}

void InitViewerTenantInfoJsonHandler(TJsonHandlers &handlers) {
handlers.AddHandler("/viewer/tenantinfo", new TJsonHandler<TJsonTenantInfo>(TJsonTenantInfo::GetSwagger()));
handlers.AddHandler("/viewer/tenantinfo", new TJsonHandler<TJsonTenantInfo>(TJsonTenantInfo::GetSwagger()), 2);
}

void InitViewerWhoAmIJsonHandler(TJsonHandlers& handlers) {
Expand Down
4 changes: 3 additions & 1 deletion ydb/core/viewer/protos/viewer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ message TTenant {
uint64 StorageGroups = 40;
uint64 StorageAllocatedLimit = 41;
Ydb.Cms.DatabaseQuotas DatabaseQuotas = 42;
repeated TStorageUsage StorageUsage = 43;
repeated TStorageUsage TablesStorage = 44;
repeated TStorageUsage DatabaseStorage = 45;
}

message TTenants {
Expand All @@ -391,6 +392,7 @@ message TTenants {
message TTenantInfo {
repeated TTenant TenantInfo = 1;
repeated string Errors = 2;
uint32 Version = 3;
}

message TStoragePDisk {
Expand Down
63 changes: 51 additions & 12 deletions ydb/core/viewer/viewer_tenantinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ class TJsonTenantInfo : public TViewerPipeClient {
THashMap<TString, std::vector<TNodeId>> TenantNodes;
THashMap<TString, NKikimrViewer::TEvViewerResponse> OffloadMergedTabletStateResponse;
THashMap<TString, NKikimrViewer::TEvViewerResponse> OffloadMergedSystemStateResponse;
THashMap<TString, NKikimrViewer::TStorageUsage::EType> StoragePoolType;
TTabletId RootHiveId = 0;
TString RootId; // id of root domain (tenant)
NKikimrViewer::TTenantInfo Result;
std::optional<TRequestResponse<NSysView::TEvSysView::TEvGetStoragePoolsResponse>> GetStoragePoolsResponse;

struct TStorageQuota {
uint64 SoftQuota = 0;
Expand Down Expand Up @@ -124,6 +126,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
if (Storage) {
RequestHiveStorageStats(RootHiveId);
}
GetStoragePoolsResponse = RequestBSControllerPools();

if (Requests == 0) {
ReplyAndPassAway();
Expand Down Expand Up @@ -154,9 +157,10 @@ class TJsonTenantInfo : public TViewerPipeClient {
hFunc(TEvViewer::TEvViewerResponse, Handle);
hFunc(TEvents::TEvUndelivered, Undelivered);
hFunc(TEvInterconnect::TEvNodeDisconnected, Disconnected);
hFunc(TEvTabletPipe::TEvClientConnected, TBase::Handle);
hFunc(TEvTabletPipe::TEvClientConnected, Handle);
hFunc(TEvStateStorage::TEvBoardInfo, Handle);
hFunc(NHealthCheck::TEvSelfCheckResultProto, Handle);
hFunc(NSysView::TEvSysView::TEvGetStoragePoolsResponse, Handle);
cFunc(TEvents::TSystem::Wakeup, HandleTimeout);
}
}
Expand Down Expand Up @@ -534,8 +538,33 @@ class TJsonTenantInfo : public TViewerPipeClient {
return type;
}

void Handle(TEvTabletPipe::TEvClientConnected::TPtr& ev) {
if (ev->Get()->Status != NKikimrProto::OK) {
TString error = TStringBuilder() << "Failed to establish pipe: " << NKikimrProto::EReplyStatus_Name(ev->Get()->Status);
if (ev->Get()->TabletId == GetBSControllerId()) {
if (GetStoragePoolsResponse.has_value()) {
GetStoragePoolsResponse->Error(error);
}
}
}
TBase::Handle(ev); // all RequestDone() are handled by base handler
}

void Handle(NSysView::TEvSysView::TEvGetStoragePoolsResponse::TPtr& ev) {
GetStoragePoolsResponse->Set(std::move(ev));

if (GetStoragePoolsResponse && GetStoragePoolsResponse->IsOk()) {
for (const NKikimrSysView::TStoragePoolEntry& entry : GetStoragePoolsResponse->Get()->Record.GetEntries()) {
StoragePoolType[entry.GetInfo().GetName()] = GetStorageType(entry.GetInfo().GetKind());
}
}

RequestDone();
}

void ReplyAndPassAway() override {
BLOG_TRACE("ReplyAndPassAway() started");
Result.SetVersion(2);
TIntrusivePtr<TDomainsInfo> domains = AppData()->DomainsInfo;
auto *domain = domains->GetDomain();
THashMap<TString, NKikimrViewer::EFlag> OverallByDomainId;
Expand Down Expand Up @@ -666,6 +695,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
}

if (Storage) {
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> databaseStorageByType;
auto itHiveStorageStats = HiveStorageStats.find(hiveId);
if (itHiveStorageStats != HiveStorageStats.end()) {
const NKikimrHive::TEvResponseHiveStorageStats& record = itHiveStorageStats->second.Get()->Record;
Expand All @@ -675,9 +705,12 @@ class TJsonTenantInfo : public TViewerPipeClient {
uint64 storageGroups = 0;
for (const NKikimrHive::THiveStoragePoolStats& poolStat : record.GetPools()) {
if (poolStat.GetName().StartsWith(tenantBySubDomainKey.GetName())) {
NKikimrViewer::TStorageUsage::EType storageType = StoragePoolType[poolStat.GetName()];
for (const NKikimrHive::THiveStorageGroupStats& groupStat : poolStat.GetGroups()) {
storageAllocatedSize += groupStat.GetAllocatedSize();
storageAvailableSize += groupStat.GetAvailableSize();
databaseStorageByType[storageType] += groupStat.GetAllocatedSize();
databaseStorageByType[storageType] += groupStat.GetAvailableSize();
storageMinAvailableSize = std::min(storageMinAvailableSize, groupStat.GetAvailableSize());
++storageGroups;
}
Expand All @@ -690,7 +723,7 @@ class TJsonTenantInfo : public TViewerPipeClient {
tenant.SetStorageGroups(storageGroups);
}

THashMap<NKikimrViewer::TStorageUsage::EType, ui64> storageUsageByType;
THashMap<NKikimrViewer::TStorageUsage::EType, ui64> tablesStorageByType;
THashMap<NKikimrViewer::TStorageUsage::EType, TStorageQuota> storageQuotasByType;

for (const auto& quota : tenant.GetDatabaseQuotas().storage_quotas()) {
Expand All @@ -703,11 +736,11 @@ class TJsonTenantInfo : public TViewerPipeClient {
if (entry.DomainDescription) {
for (const auto& poolUsage : entry.DomainDescription->Description.GetDiskSpaceUsage().GetStoragePoolsUsage()) {
auto type = GetStorageType(poolUsage.GetPoolKind());
storageUsageByType[type] += poolUsage.GetTotalSize();
tablesStorageByType[type] += poolUsage.GetTotalSize();
}

if (storageUsageByType.empty() && entry.DomainDescription->Description.HasDiskSpaceUsage()) {
storageUsageByType[GuessStorageType(entry.DomainDescription->Description)] =
if (tablesStorageByType.empty() && entry.DomainDescription->Description.HasDiskSpaceUsage()) {
tablesStorageByType[GuessStorageType(entry.DomainDescription->Description)] =
entry.DomainDescription->Description.GetDiskSpaceUsage().GetTables().GetTotalSize();
}

Expand All @@ -718,17 +751,23 @@ class TJsonTenantInfo : public TViewerPipeClient {
}
}

for (const auto& [type, size] : storageUsageByType) {
auto& storageUsage = *tenant.AddStorageUsage();
storageUsage.SetType(type);
storageUsage.SetSize(size);
for (const auto& [type, size] : tablesStorageByType) {
auto it = storageQuotasByType.find(type);
auto& tablesStorage = *tenant.AddTablesStorage();
tablesStorage.SetType(type);
tablesStorage.SetSize(size);
if (it != storageQuotasByType.end()) {
storageUsage.SetLimit(it->second.HardQuota);
storageUsage.SetSoftQuota(it->second.SoftQuota);
storageUsage.SetHardQuota(it->second.HardQuota);
tablesStorage.SetLimit(it->second.SoftQuota);
tablesStorage.SetSoftQuota(it->second.SoftQuota);
tablesStorage.SetHardQuota(it->second.HardQuota);
}
}

for (const auto& [type, size] : databaseStorageByType) {
auto& databaseStorage = *tenant.AddDatabaseStorage();
databaseStorage.SetType(type);
databaseStorage.SetSize(size);
}
}

THashSet<TNodeId> tenantNodes;
Expand Down
Loading