@@ -547,6 +547,8 @@ void TPersQueueReadBalancer::Handle(TEvPersQueue::TEvUpdateBalancerConfig::TPtr
547547 }
548548
549549 Balancer->UpdateConfig (newPartitionsIds, deletedPartitions, ctx);
550+
551+ UpdateConfigCounters ();
550552}
551553
552554
@@ -799,50 +801,74 @@ void TPersQueueReadBalancer::CheckStat(const TActorContext& ctx) {
799801 UpdateCounters (ctx);
800802}
801803
802- void TPersQueueReadBalancer::UpdateCounters (const TActorContext& ctx) {
803- if (!AggregatedStats. Stats . size ())
804+ void TPersQueueReadBalancer::InitCounters (const TActorContext& ctx) {
805+ if (!DatabasePath) {
804806 return ;
807+ }
805808
806- if (!DatabasePath)
809+ if (DynamicCounters) {
807810 return ;
808-
809- using TPartitionLabeledCounters = TProtobufTabletLabeledCounters<EPartitionLabeledCounters_descriptor>;
810- THolder<TPartitionLabeledCounters> labeledCounters;
811- using TConsumerLabeledCounters = TProtobufTabletLabeledCounters<EClientLabeledCounters_descriptor>;
812- THolder<TConsumerLabeledCounters> labeledConsumerCounters;
813-
814-
815- labeledCounters.Reset (new TPartitionLabeledCounters (" topic" , 0 , DatabasePath));
816- labeledConsumerCounters.Reset (new TConsumerLabeledCounters (" topic|x|consumer" , 0 , DatabasePath));
817-
818- auto counters = AppData (ctx)->Counters ;
819- bool isServerless = AppData (ctx)->FeatureFlags .GetEnableDbCounters (); // TODO: find out it via describe
811+ }
820812
821813 TStringBuf name = TStringBuf (Path);
822814 name.SkipPrefix (DatabasePath);
823815 name.SkipPrefix (" /" );
824- counters = counters->GetSubgroup (" counters" , isServerless ? " topics_serverless" : " topics" )
816+
817+ bool isServerless = AppData (ctx)->FeatureFlags .GetEnableDbCounters (); // TODO: find out it via describe
818+ DynamicCounters = AppData (ctx)->Counters ->GetSubgroup (" counters" , isServerless ? " topics_serverless" : " topics" )
825819 ->GetSubgroup (" host" , " " )
826820 ->GetSubgroup (" database" , DatabasePath)
827821 ->GetSubgroup (" cloud_id" , CloudId)
828822 ->GetSubgroup (" folder_id" , FolderId)
829823 ->GetSubgroup (" database_id" , DatabaseId)
830824 ->GetSubgroup (" topic" , TString (name));
831825
826+ ActivePartitionCountCounter = DynamicCounters->GetExpiringNamedCounter (" name" , " topic.partition.active_count" , false );
827+ InactivePartitionCountCounter = DynamicCounters->GetExpiringNamedCounter (" name" , " topic.partition.inactive_count" , false );
828+ }
829+
830+ void TPersQueueReadBalancer::UpdateConfigCounters () {
831+ if (!DynamicCounters) {
832+ return ;
833+ }
834+
835+ size_t inactiveCount = std::count_if (TabletConfig.GetPartitions ().begin (), TabletConfig.GetPartitions ().end (), [](auto & p) {
836+ return p.GetStatus () == NKikimrPQ::ETopicPartitionStatus::Inactive;
837+ });
838+
839+ ActivePartitionCountCounter->Set (PartitionsInfo.size () - inactiveCount);
840+ InactivePartitionCountCounter->Set (inactiveCount);
841+ }
842+
843+ void TPersQueueReadBalancer::UpdateCounters (const TActorContext& ctx) {
844+ if (!AggregatedStats.Stats .size ())
845+ return ;
846+
847+ if (!DynamicCounters)
848+ return ;
849+
850+ using TPartitionLabeledCounters = TProtobufTabletLabeledCounters<EPartitionLabeledCounters_descriptor>;
851+ THolder<TPartitionLabeledCounters> labeledCounters;
852+ using TConsumerLabeledCounters = TProtobufTabletLabeledCounters<EClientLabeledCounters_descriptor>;
853+ THolder<TConsumerLabeledCounters> labeledConsumerCounters;
854+
855+ labeledCounters.Reset (new TPartitionLabeledCounters (" topic" , 0 , DatabasePath));
856+ labeledConsumerCounters.Reset (new TConsumerLabeledCounters (" topic|x|consumer" , 0 , DatabasePath));
857+
832858 if (AggregatedCounters.empty ()) {
833859 for (ui32 i = 0 ; i < labeledCounters->GetCounters ().Size (); ++i) {
834860 TString name = labeledCounters->GetNames ()[i];
835861 TStringBuf nameBuf = name;
836862 nameBuf.SkipPrefix (" PQ/" );
837863 name = nameBuf;
838- AggregatedCounters.push_back (name.empty () ? nullptr : counters ->GetExpiringNamedCounter (" name" , name, false ));
864+ AggregatedCounters.push_back (name.empty () ? nullptr : DynamicCounters ->GetExpiringNamedCounter (" name" , name, false ));
839865 }
840866 }
841867
842868 for (auto & [consumer, info]: Consumers) {
843869 info.Aggr .Reset (new TTabletLabeledCountersBase{});
844870 if (info.AggregatedCounters .empty ()) {
845- auto clientCounters = counters ->GetSubgroup (" consumer" , NPersQueue::ConvertOldConsumerName (consumer, ctx));
871+ auto clientCounters = DynamicCounters ->GetSubgroup (" consumer" , NPersQueue::ConvertOldConsumerName (consumer, ctx));
846872 for (ui32 i = 0 ; i < labeledConsumerCounters->GetCounters ().Size (); ++i) {
847873 TString name = labeledConsumerCounters->GetNames ()[i];
848874 TStringBuf nameBuf = name;
@@ -1106,6 +1132,9 @@ void TPersQueueReadBalancer::Handle(TEvTxProxySchemeCache::TEvWatchNotifyUpdated
11061132 if (attr.GetKey () == " cloud_id" ) CloudId = attr.GetValue ();
11071133 if (attr.GetKey () == " database_id" ) DatabaseId = attr.GetValue ();
11081134 }
1135+
1136+ InitCounters (ctx);
1137+ UpdateConfigCounters ();
11091138 }
11101139
11111140 if (PartitionsScaleManager) {
0 commit comments