Skip to content

improve viewer tests #13888

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

Merged
merged 1 commit into from
Jan 30, 2025
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
1 change: 0 additions & 1 deletion .github/config/muted_ya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ ydb/core/tx/schemeshard/ut_pq_reboots TPqGroupTestReboots.AlterWithReboots-PQCon
ydb/core/tx/schemeshard/ut_pq_reboots TPqGroupTestReboots.CreateAlter-PQConfigTransactionsAtSchemeShard-true
ydb/core/tx/schemeshard/ut_pq_reboots TPqGroupTestReboots.CreateAlterDropPqGroupWithReboots-PQConfigTransactionsAtSchemeShard-true
ydb/core/tx/tiering/ut ColumnShardTiers.TTLUsage
ydb/core/viewer/tests test.py.test_viewer_healthcheck
ydb/core/viewer/ut Viewer.TabletMerging
ydb/core/viewer/ut Viewer.TabletMergingPacked
ydb/library/actors/http/ut sole chunk chunk
Expand Down
1 change: 1 addition & 0 deletions ydb/core/protos/node_whiteboard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ message TEvTabletStateRequest {
optional string Format = 5; // it could be "packed5"
optional string GroupBy = 20; // it's either empty or "Type,State" for now
repeated fixed64 FilterTabletId = 22;
optional NKikimrSubDomains.TDomainKey FilterTenantId = 23;
}

message TEvTabletStateResponse {
Expand Down
29 changes: 20 additions & 9 deletions ydb/core/tablet/node_whiteboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,24 +839,32 @@ class TNodeWhiteboardService : public TActorBootstrapped<TNodeWhiteboardService>
void Handle(TEvWhiteboard::TEvTabletStateRequest::TPtr &ev, const TActorContext &ctx) {
auto now = TMonotonic::Now();
const auto& request = ev->Get()->Record;
auto matchesFilter = [
changedSince = request.has_changedsince() ? request.changedsince() : 0,
filterTenantId = request.has_filtertenantid() ? NKikimr::TSubDomainKey(request.filtertenantid()) : NKikimr::TSubDomainKey()
](const NKikimrWhiteboard::TTabletStateInfo& tabletStateInfo) {
return tabletStateInfo.changetime() >= changedSince
&& (!filterTenantId || filterTenantId == NKikimr::TSubDomainKey(tabletStateInfo.tenantid()));
};
std::unique_ptr<TEvWhiteboard::TEvTabletStateResponse> response = std::make_unique<TEvWhiteboard::TEvTabletStateResponse>();
auto& record = response->Record;
if (request.format() == "packed5") {
TEvWhiteboard::TEvTabletStateResponsePacked5* ptr = response->AllocatePackedResponse(TabletStateInfo.size());
for (const auto& [tabletId, tabletInfo] : TabletStateInfo) {
ptr->TabletId = tabletInfo.tabletid();
ptr->FollowerId = tabletInfo.followerid();
ptr->Generation = tabletInfo.generation();
ptr->Type = tabletInfo.type();
ptr->State = tabletInfo.state();
++ptr;
if (matchesFilter(tabletInfo)) {
ptr->TabletId = tabletInfo.tabletid();
ptr->FollowerId = tabletInfo.followerid();
ptr->Generation = tabletInfo.generation();
ptr->Type = tabletInfo.type();
ptr->State = tabletInfo.state();
++ptr;
}
}
} else {
if (request.groupby().empty()) {
ui64 changedSince = request.has_changedsince() ? request.changedsince() : 0;
if (request.filtertabletid_size() == 0) {
for (const auto& pr : TabletStateInfo) {
if (pr.second.changetime() >= changedSince) {
if (matchesFilter(pr.second)) {
NKikimrWhiteboard::TTabletStateInfo& tabletStateInfo = *record.add_tabletstateinfo();
Copy(tabletStateInfo, pr.second, request);
}
Expand All @@ -865,7 +873,7 @@ class TNodeWhiteboardService : public TActorBootstrapped<TNodeWhiteboardService>
for (auto tabletId : request.filtertabletid()) {
auto it = TabletStateInfo.find({tabletId, 0});
if (it != TabletStateInfo.end()) {
if (it->second.changetime() >= changedSince) {
if (matchesFilter(it->second)) {
NKikimrWhiteboard::TTabletStateInfo& tabletStateInfo = *record.add_tabletstateinfo();
Copy(tabletStateInfo, it->second, request);
}
Expand All @@ -876,6 +884,9 @@ class TNodeWhiteboardService : public TActorBootstrapped<TNodeWhiteboardService>
std::unordered_map<std::pair<NKikimrTabletBase::TTabletTypes::EType,
NKikimrWhiteboard::TTabletStateInfo::ETabletState>, NKikimrWhiteboard::TTabletStateInfo> stateGroupBy;
for (const auto& [id, stateInfo] : TabletStateInfo) {
if (!matchesFilter(stateInfo)) {
continue;
}
NKikimrWhiteboard::TTabletStateInfo& state = stateGroupBy[{stateInfo.type(), stateInfo.state()}];
auto count = state.count();
if (count == 0) {
Expand Down
24 changes: 13 additions & 11 deletions ydb/core/viewer/json_pipe_req.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,13 +825,9 @@ void TViewerPipeClient::HandleResolveResource(TEvTxProxySchemeCache::TEvNavigate
if (ResourceNavigateResponse->IsOk()) {
TSchemeCacheNavigate::TEntry& entry(ResourceNavigateResponse->Get()->Request->ResultSet.front());
SharedDatabase = CanonizePath(entry.Path);
if (SharedDatabase == AppData()->TenantName) {
Direct = true;
Bootstrap(); // retry bootstrap without redirect this time
} else {
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(SharedDatabase);
--Requests; // don't count this request
}
Direct |= (SharedDatabase == AppData()->TenantName);
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(SharedDatabase);
--Requests; // don't count this request
} else {
AddEvent("Failed to resolve database - shared database not found");
Direct = true;
Expand All @@ -850,7 +846,8 @@ void TViewerPipeClient::HandleResolveDatabase(TEvTxProxySchemeCache::TEvNavigate
--Requests; // don't count this request
Become(&TViewerPipeClient::StateResolveResource);
} else {
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(CanonizePath(entry.Path));
Database = CanonizePath(entry.Path);
DatabaseBoardInfoResponse = MakeRequestStateStorageEndpointsLookup(Database);
--Requests; // don't count this request
}
} else {
Expand All @@ -865,7 +862,11 @@ void TViewerPipeClient::HandleResolve(TEvStateStorage::TEvBoardInfo::TPtr& ev) {
if (DatabaseBoardInfoResponse) {
DatabaseBoardInfoResponse->Set(std::move(ev));
if (DatabaseBoardInfoResponse->IsOk()) {
return ReplyAndPassAway(MakeForward(GetNodesFromBoardReply(DatabaseBoardInfoResponse->GetRef())));
if (Direct) {
Bootstrap(); // retry bootstrap without redirect this time
} else {
ReplyAndPassAway(MakeForward(GetNodesFromBoardReply(DatabaseBoardInfoResponse->GetRef())));
}
} else {
AddEvent("Failed to resolve database nodes");
Direct = true;
Expand Down Expand Up @@ -902,10 +903,11 @@ void TViewerPipeClient::RedirectToDatabase(const TString& database) {

bool TViewerPipeClient::NeedToRedirect() {
auto request = GetRequest();
if (request) {
if (NeedRedirect && request) {
NeedRedirect = false;
Direct |= !request.GetHeader("X-Forwarded-From-Node").empty(); // we're already forwarding
Direct |= (Database == AppData()->TenantName) || Database.empty(); // we're already on the right node or don't use database filter
if (Database && !Direct) {
if (Database) {
RedirectToDatabase(Database); // to find some dynamic node and redirect query there
return true;
}
Expand Down
1 change: 1 addition & 0 deletions ydb/core/viewer/json_pipe_req.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TViewerPipeClient : public TActorBootstrapped<TViewerPipeClient> {
TString Database;
TString SharedDatabase;
bool Direct = false;
bool NeedRedirect = true;
ui32 Requests = 0;
bool PassedAway = false;
ui32 MaxRequestsInFlight = 200;
Expand Down
Loading
Loading