From cebe29d29c824b0985aa74db4567b3ae5fafb564 Mon Sep 17 00:00:00 2001 From: Alexey Efimov Date: Fri, 18 Oct 2024 12:22:04 +0200 Subject: [PATCH] add node name filter, improve filter behavior (#10585) --- ydb/core/viewer/storage_groups.h | 31 +++++++++++++++++--------- ydb/core/viewer/viewer_nodes.h | 38 ++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/ydb/core/viewer/storage_groups.h b/ydb/core/viewer/storage_groups.h index 4469239ccee6..40d199c70939 100644 --- a/ydb/core/viewer/storage_groups.h +++ b/ydb/core/viewer/storage_groups.h @@ -1042,20 +1042,29 @@ class TStorageGroups : public TViewerPipeClient { With = EWith::Everything; GroupsByGroupId.clear(); } - if (!Filter.empty() && FieldsAvailable.test(+EGroupFields::PoolName) && FieldsAvailable.test(+EGroupFields::GroupId)) { - TVector filterWords = SplitString(Filter, " "); - TGroupView groupView; - for (TGroup* group : GroupView) { - for (const TString& word : filterWords) { - if (group->PoolName.Contains(word) || ::ToString(group->GroupId).Contains(word)) { - groupView.push_back(group); - break; + if (!Filter.empty()) { + bool allFieldsPresent = + (!FieldsRequired.test(+EGroupFields::GroupId) || FieldsAvailable.test(+EGroupFields::GroupId)) && + (!FieldsRequired.test(+EGroupFields::PoolName) || FieldsAvailable.test(+EGroupFields::PoolName)); + if (allFieldsPresent) { + TVector filterWords = SplitString(Filter, " "); + TGroupView groupView; + for (TGroup* group : GroupView) { + for (const TString& word : filterWords) { + if (FieldsRequired.test(+EGroupFields::GroupId) && ::ToString(group->GroupId).Contains(word)) { + groupView.push_back(group); + break; + } + if (FieldsRequired.test(+EGroupFields::PoolName) && group->PoolName.Contains(word)) { + groupView.push_back(group); + break; + } } } + GroupView.swap(groupView); + Filter.clear(); + GroupsByGroupId.clear(); } - GroupView.swap(groupView); - Filter.clear(); - GroupsByGroupId.clear(); } if (!FilterGroup.empty() && FieldsAvailable.test(+FilterGroupBy)) { TGroupView groupView; diff --git a/ydb/core/viewer/viewer_nodes.h b/ydb/core/viewer/viewer_nodes.h index 6ab28f8798a3..20cc3706c143 100644 --- a/ydb/core/viewer/viewer_nodes.h +++ b/ydb/core/viewer/viewer_nodes.h @@ -620,7 +620,7 @@ class TJsonNodes : public TViewerPipeClient { ENodeFields result = ENodeFields::COUNT; if (field == "NodeId" || field == "Id") { result = ENodeFields::NodeId; - } else if (field == "Host") { + } else if (field == "Host" || field == "HostName") { result = ENodeFields::HostName; } else if (field == "NodeName") { result = ENodeFields::NodeName; @@ -1023,20 +1023,34 @@ class TJsonNodes : public TViewerPipeClient { UptimeSeconds = 0; InvalidateNodes(); } - if (!Filter.empty() && FieldsAvailable.test(+ENodeFields::NodeInfo)) { - TVector filterWords = SplitString(Filter, " "); - TNodeView nodeView; - for (TNode* node : NodeView) { - for (const TString& word : filterWords) { - if (node->GetHostName().Contains(word) || ::ToString(node->GetNodeId()).Contains(word)) { - nodeView.push_back(node); - break; + if (!Filter.empty()) { + bool allFieldsPresent = + (!FieldsRequired.test(+ENodeFields::NodeId) || FieldsAvailable.test(+ENodeFields::NodeId)) && + (!FieldsRequired.test(+ENodeFields::HostName) || FieldsAvailable.test(+ENodeFields::HostName)) && + (!FieldsRequired.test(+ENodeFields::NodeName) || FieldsAvailable.test(+ENodeFields::NodeName)); + if (allFieldsPresent) { + TVector filterWords = SplitString(Filter, " "); + TNodeView nodeView; + for (TNode* node : NodeView) { + for (const TString& word : filterWords) { + if (FieldsRequired.test(+ENodeFields::NodeId) && ::ToString(node->GetNodeId()).Contains(word)) { + nodeView.push_back(node); + break; + } + if (FieldsRequired.test(+ENodeFields::HostName) && node->GetHostName().Contains(word)) { + nodeView.push_back(node); + break; + } + if (FieldsRequired.test(+ENodeFields::NodeName) && node->GetNodeName().Contains(word)) { + nodeView.push_back(node); + break; + } } } + NodeView.swap(nodeView); + Filter.clear(); + InvalidateNodes(); } - NodeView.swap(nodeView); - Filter.clear(); - InvalidateNodes(); } if (!FilterGroup.empty() && FieldsAvailable.test(+FilterGroupBy)) { TNodeView nodeView;