@@ -882,6 +882,86 @@ Y_UNIT_TEST_SUITE(TIndexTabletTest_Counters)
882882 }},
883883 });
884884 }
885+
886+ Y_UNIT_TEST (ShouldReportDirectHandleMetrics)
887+ {
888+ TTestEnv env;
889+ auto registry = env.GetRegistry ();
890+
891+ env.CreateSubDomain (" nfs" );
892+ ui32 nodeIdx = env.CreateNode (" nfs" );
893+ ui64 tabletId = env.BootIndexTablet (nodeIdx);
894+
895+ TIndexTabletClient tablet (env.GetRuntime (), nodeIdx, tabletId);
896+ tablet.InitSession (" client" , " session" );
897+
898+ const auto nodeId =
899+ CreateNode (tablet, TCreateNodeArgs::File (RootNodeId, " test" ));
900+
901+ auto advanceTime = [&]()
902+ {
903+ env.GetRuntime ().AdvanceCurrentTime (TDuration::Seconds (15 ));
904+ NActors::TDispatchOptions options;
905+ options.FinalEvents .emplace_back (
906+ TEvIndexTabletPrivate::EvUpdateCounters);
907+ env.GetRuntime ().DispatchEvents (options);
908+ };
909+
910+ auto checkHandlesCounters =
911+ [&](i64 expectedDirectHandles, i64 expectedUsedHandles)
912+ {
913+ TTestRegistryVisitor visitor;
914+ registry->Visit (TInstant::Zero (), visitor);
915+ visitor.ValidateExpectedCounters ({
916+ {{{" sensor" , " UsedDirectHandlesCount" }, {" filesystem" , " test" }},
917+ expectedDirectHandles},
918+ {{{" sensor" , " UsedHandlesCount" }, {" filesystem" , " test" }},
919+ expectedUsedHandles},
920+ });
921+ };
922+
923+ advanceTime ();
924+ checkHandlesCounters (0 , 0 );
925+
926+ const auto handleWithoutDirect =
927+ CreateHandle (tablet, nodeId, {}, TCreateHandleArgs::RDWR);
928+
929+ advanceTime ();
930+ checkHandlesCounters (0 , 1 );
931+
932+ const auto handleWithDirect = CreateHandle (
933+ tablet,
934+ nodeId,
935+ {},
936+ TCreateHandleArgs::RDWR | TCreateHandleArgs::DIRECT);
937+
938+ advanceTime ();
939+ checkHandlesCounters (1 , 2 );
940+
941+ const auto anotherDirectHandle = CreateHandle (
942+ tablet,
943+ nodeId,
944+ {},
945+ TCreateHandleArgs::RDWR | TCreateHandleArgs::DIRECT);
946+
947+ advanceTime ();
948+ checkHandlesCounters (2 , 3 );
949+
950+ tablet.DestroyHandle (handleWithoutDirect);
951+
952+ advanceTime ();
953+ checkHandlesCounters (2 , 2 );
954+
955+ tablet.DestroyHandle (handleWithDirect);
956+
957+ advanceTime ();
958+ checkHandlesCounters (1 , 1 );
959+
960+ tablet.DestroyHandle (anotherDirectHandle);
961+
962+ advanceTime ();
963+ checkHandlesCounters (0 , 0 );
964+ }
885965}
886966
887967} // namespace NCloud::NFileStore::NStorage
0 commit comments