@@ -241,25 +241,6 @@ module BenchmarkCounters = {
241241  }
242242}
243243
244- module  PartitionBlockFetched  =  {
245-   type  labels  =  {chainId : int , partitionId : string }
246- 
247-   let  labelSchema  =  S .schema (s  =>  {
248-     chainId : s .matches (S .string -> S .coerce (S .int )),
249-     partitionId : s .matches (S .string ),
250-   })
251- 
252-   let  counter  =  SafeGauge .makeOrThrow (
253-     ~name = "partition_block_fetched" ,
254-     ~help = "The latest fetched block number for each partition" ,
255-     ~labelSchema ,
256-   )
257- 
258-   let  set  =  (~blockNumber , ~partitionId , ~chainId ) =>  {
259-     counter -> SafeGauge .handleInt (~labels = {chainId , partitionId }, ~value = blockNumber )
260-   }
261- }
262- 
263244let  chainIdLabelsSchema  =  S .object (s  =>  {
264245  s .field ("chainId" , S .string -> S .coerce (S .int ))
265246})
@@ -440,22 +421,13 @@ module SourceGetHeightDuration = {
440421}
441422
442423module  ReorgCount  =  {
443-   let  deprecatedCounter  =  PromClient .Counter .makeCounter ({
444-     "name" : "reorgs_detected" ,
445-     "help" : "Total number of reorgs detected" ,
446-     "labelNames" : ["chainId" ],
447-   })
448- 
449424  let  gauge  =  SafeGauge .makeOrThrow (
450425    ~name = "envio_reorg_count" ,
451426    ~help = "Total number of reorgs detected" ,
452427    ~labelSchema = chainIdLabelsSchema ,
453428  )
454429
455430  let  increment  =  (~chain ) =>  {
456-     deprecatedCounter 
457-     -> PromClient .Counter .labels ({"chainId" : chain -> ChainMap .Chain .toString })
458-     -> PromClient .Counter .inc 
459431    gauge -> SafeGauge .increment (~labels = chain -> ChainMap .Chain .toChainId )
460432  }
461433}
@@ -642,3 +614,79 @@ module EffectCacheCount = {
642614    gauge -> SafeGauge .handleInt (~labels = effectName , ~value = count )
643615  }
644616}
617+ 
618+ module  StorageLoad  =  {
619+   let  operationLabelsSchema  =  S .object (s  =>  s .field ("operation" , S .string ))
620+ 
621+   let  timeCounter  =  SafeCounter .makeOrThrow (
622+     ~name = "envio_storage_load_time" ,
623+     ~help = "Processing time taken to load data from storage. (milliseconds)" ,
624+     ~labelSchema = operationLabelsSchema ,
625+   )
626+ 
627+   let  totalTimeCounter  =  SafeCounter .makeOrThrow (
628+     ~name = "envio_storage_load_total_time" ,
629+     ~help = "Cumulative time spent loading data from storage during the indexing process. (milliseconds)" ,
630+     ~labelSchema = operationLabelsSchema ,
631+   )
632+ 
633+   let  counter  =  SafeCounter .makeOrThrow (
634+     ~name = "envio_storage_load_count" ,
635+     ~help = "Cumulative number of successful storage load operations during the indexing process." ,
636+     ~labelSchema = operationLabelsSchema ,
637+   )
638+ 
639+   let  whereSizeCounter  =  SafeCounter .makeOrThrow (
640+     ~name = "envio_storage_load_where_size" ,
641+     ~help = "Cumulative number of filter conditions ('where' items) used in storage load operations during the indexing process." ,
642+     ~labelSchema = operationLabelsSchema ,
643+   )
644+ 
645+   let  sizeCounter  =  SafeCounter .makeOrThrow (
646+     ~name = "envio_storage_load_size" ,
647+     ~help = "Cumulative number of records loaded from storage during the indexing process." ,
648+     ~labelSchema = operationLabelsSchema ,
649+   )
650+ 
651+   type  operationRef  =  {
652+     mutable  pendingCount : int ,
653+     timerRef : Hrtime .timeRef ,
654+   }
655+   let  operations  =  Js .Dict .empty ()
656+ 
657+   let  startOperation  =  (~operation ) =>  {
658+     switch  operations -> Utils .Dict .dangerouslyGetNonOption (operation ) {
659+     | Some (operationRef ) =>  operationRef .pendingCount  =  operationRef .pendingCount  +  1 
660+     | None  => 
661+       operations -> Js .Dict .set (
662+         operation ,
663+         (
664+           {
665+             pendingCount : 1 ,
666+             timerRef : Hrtime .makeTimer (),
667+           }: operationRef 
668+         ),
669+       )
670+     }
671+     Hrtime .makeTimer ()
672+   }
673+ 
674+   let  endOperation  =  (timerRef , ~operation , ~whereSize , ~size ) =>  {
675+     let  operationRef  =  operations -> Js .Dict .unsafeGet (operation )
676+     operationRef .pendingCount  =  operationRef .pendingCount  -  1 
677+     if  operationRef .pendingCount  ===  0  {
678+       timeCounter -> SafeCounter .handleInt (
679+         ~labels = {operation },
680+         ~value = operationRef .timerRef -> Hrtime .timeSince -> Hrtime .toMillis -> Hrtime .intFromMillis ,
681+       )
682+       operations -> Utils .Dict .deleteInPlace (operation )
683+     }
684+     totalTimeCounter -> SafeCounter .handleInt (
685+       ~labels = {operation },
686+       ~value = timerRef -> Hrtime .timeSince -> Hrtime .toMillis -> Hrtime .intFromMillis ,
687+     )
688+     counter -> SafeCounter .increment (~labels = {operation })
689+     whereSizeCounter -> SafeCounter .handleInt (~labels = {operation }, ~value = whereSize )
690+     sizeCounter -> SafeCounter .handleInt (~labels = {operation }, ~value = size )
691+   }
692+ }
0 commit comments