@@ -718,7 +718,7 @@ Y_UNIT_TEST(PartitionKeyCompaction) {
718718 tc.Prepare (dispatchName, setup, activeZone, true , true , true );
719719
720720 tc.Runtime ->GetAppData (0 ).FeatureFlags .SetEnableTopicCompactificationByKey (true );
721- tc.Runtime ->GetAppData (0 ).PQConfig .MutableCompactionConfig ()->SetBlobsSize (1 );
721+ tc.Runtime ->GetAppData (0 ).PQConfig .MutableCompactionConfig ()->SetBlobsSize (10_MB );
722722 tc.Runtime ->SetScheduledLimit (10000 );
723723
724724 tc.Runtime ->SetObserverFunc ([&](TAutoPtr<IEventHandle>& event) {
@@ -843,6 +843,110 @@ Y_UNIT_TEST(PartitionKeyCompaction) {
843843 });
844844}
845845
846+
847+ Y_UNIT_TEST (PartitionBlobCompactionCounters) {
848+ SetEnv (" FAST_UT" , " 1" );
849+ TTestContext tc;
850+ RunTestWithReboots (tc.TabletIds , [&]() { return tc.InitialEventsFilter .Prepare (); }, [&](const TString& dispatchName, std::function<void (TTestActorRuntime&)> setup, bool & activeZone) {
851+ TFinalizer finalizer (tc);
852+ activeZone = false ;
853+ bool dbRegistered = false ;
854+
855+ tc.EnableDetailedPQLog = true ;
856+ tc.Prepare (dispatchName, setup, activeZone, true , true , true );
857+
858+ tc.Runtime ->GetAppData (0 ).PQConfig .MutableCompactionConfig ()->SetBlobsSize (10_MB);
859+ tc.Runtime ->SetScheduledLimit (10000 );
860+
861+ tc.Runtime ->SetObserverFunc ([&](TAutoPtr<IEventHandle>& event) {
862+ if (event->GetTypeRewrite () == NSysView::TEvSysView::EvRegisterDbCounters) {
863+ auto database = event.Get ()->Get <NSysView::TEvSysView::TEvRegisterDbCounters>()->Database ;
864+ UNIT_ASSERT_VALUES_EQUAL (database, " /Root/PQ" );
865+ dbRegistered = true ;
866+ } else if (event->GetTypeRewrite () == TEvPQ::EEv::EvRunCompaction) {
867+ Cerr << " ===Dropped TEvRunCompaction with blobs count: " << event->Get <TEvPQ::TEvRunCompaction>()->BlobsCount << Endl;
868+ return TTestActorRuntime::EEventAction::DROP;
869+ }
870+ return TTestActorRuntime::DefaultObserverFunc (event);
871+ });
872+ PQTabletPrepare ({.deleteTime = 3600 , .writeSpeed = 2_MB, .enableCompactificationByKey = false }, {}, tc);
873+
874+ TFakeSchemeShardState::TPtr state{new TFakeSchemeShardState ()};
875+ ui64 ssId = 325 ;
876+ BootFakeSchemeShard (*tc.Runtime , ssId, state);
877+
878+ auto balancerParams = TBalancerParams::FromContext (" topic" , {{0 , {tc.TabletId , 1 }}}, ssId, tc);
879+ balancerParams.EnableKeyCompaction = false ;
880+ PQBalancerPrepare (balancerParams);
881+
882+ IActor* actor = CreateTabletCountersAggregator (false );
883+ auto aggregatorId = tc.Runtime ->Register (actor);
884+ tc.Runtime ->EnableScheduleForActor (aggregatorId);
885+ TString s{5_MB, ' c' };
886+ ui64 currentOffset = 0 ;
887+ auto writeData = [&](ui32 count) {
888+ TVector<std::pair<ui64, TString>> data;
889+ for (auto i = 0u ; i < count; ++i) {
890+ data.push_back ({i + 1 , s});
891+ }
892+ CmdWrite (0 , " sourceid0" , std::move (data), tc, false , {}, false , " " , -1 , currentOffset, false , false , true );
893+ currentOffset += count;
894+ };
895+ writeData (3 );
896+ writeData (3 );
897+
898+ {
899+ NSchemeCache::TDescribeResult::TPtr result = new NSchemeCache::TDescribeResult{};
900+ result->SetPath (" /Root" );
901+ TVector<TString> attrs = {" folder_id" , " cloud_id" , " database_id" };
902+ for (auto & attr : attrs) {
903+ auto ua = result->MutablePathDescription ()->AddUserAttributes ();
904+ ua->SetKey (attr);
905+ ua->SetValue (attr);
906+ }
907+ NSchemeCache::TDescribeResult::TCPtr cres = result;
908+ auto event = MakeHolder<TEvTxProxySchemeCache::TEvWatchNotifyUpdated>(0 , " /Root" , TPathId{}, cres);
909+ TActorId pipeClient = tc.Runtime ->ConnectToPipe (tc.BalancerTabletId , tc.Edge , 0 , GetPipeConfigWithRetries ());
910+ tc.Runtime ->SendToPipe (tc.BalancerTabletId , tc.Edge , event.Release (), 0 , GetPipeConfigWithRetries (), pipeClient);
911+
912+ TDispatchOptions options;
913+ options.FinalEvents .emplace_back (TEvTxProxySchemeCache::EvWatchNotifyUpdated);
914+ options.FinalEvents .emplace_back (TEvPQ::EEv::EvRunCompaction);
915+ auto processedCountersEvent = tc.Runtime ->DispatchEvents (options);
916+ UNIT_ASSERT (processedCountersEvent);
917+ }
918+ {
919+ TDispatchOptions options;
920+ options.FinalEvents .emplace_back (TEvPersQueue::EvPeriodicTopicStats);
921+ auto processedCountersEvent = tc.Runtime ->DispatchEvents (options);
922+ UNIT_ASSERT_VALUES_EQUAL (processedCountersEvent, true );
923+ }
924+
925+ auto counters = tc.Runtime ->GetAppData (0 ).Counters ;
926+ {
927+ auto dbGroup = GetServiceCounters (counters, " topics_serverless" , false );
928+ auto group = dbGroup->GetSubgroup (" host" , " " )
929+ ->GetSubgroup (" database" , " /Root" )
930+ ->GetSubgroup (" cloud_id" , " cloud_id" )
931+ ->GetSubgroup (" folder_id" , " folder_id" )
932+ ->GetSubgroup (" database_id" , " database_id" )
933+ ->GetSubgroup (" topic" , " topic" );
934+
935+
936+ TStringStream countersStr;
937+ dbGroup->OutputHtml (countersStr);
938+ Cerr << " COUNTERS: " << countersStr.Str () << " \n " ;
939+
940+ UNIT_ASSERT_VALUES_EQUAL (
941+ group->FindNamedCounter (" name" , " topic.partition.blobs.uncompacted_count_max" )->Val (), 4 );
942+ UNIT_ASSERT_VALUES_EQUAL (
943+ group->FindNamedCounter (" name" , " topic.partition.blobs.uncompacted_bytes_max" )->Val (), 31461348 );
944+ UNIT_ASSERT_GE (group->FindNamedCounter (" name" , " topic.partition.blobs.compaction_lag_milliseconds_max" )->Val (), 1000 );
945+ }
946+ });
947+ }
948+
949+
846950Y_UNIT_TEST (NewConsumersCountersAppear) {
847951 TTestContext tc;
848952 tc.InitialEventsFilter .Prepare ();
0 commit comments