@@ -3,6 +3,7 @@ package metrics
33import (
44 "fmt"
55 "sort"
6+ "strings"
67 "sync"
78 "time"
89
@@ -60,6 +61,9 @@ type Metrics struct {
6061 // internal tracking for block time calculation (uses arrival time for ms precision)
6162 lastBlockArrivalTime map [string ]time.Time // key: chainID
6263
64+ // lastSubmissionDurations tracks the most recent submission durations.
65+ lastSubmissionDurations map [string ]time.Duration // key: chainID:namespace
66+
6367 mu sync.Mutex
6468 ranges map [string ][]* blockRange // key: blobType -> sorted slice of ranges
6569}
@@ -257,8 +261,9 @@ func NewWithRegistry(namespace string, registerer prometheus.Registerer) *Metric
257261 },
258262 []string {"chain_id" , "endpoint" , "error_type" },
259263 ),
260- ranges : make (map [string ][]* blockRange ),
261- lastBlockArrivalTime : make (map [string ]time.Time ),
264+ ranges : make (map [string ][]* blockRange ),
265+ lastBlockArrivalTime : make (map [string ]time.Time ),
266+ lastSubmissionDurations : make (map [string ]time.Duration ),
262267 }
263268
264269 return m
@@ -490,7 +495,27 @@ func (m *Metrics) RecordBlockHeightDrift(chainID, targetEndpoint string, referen
490495
491496// RecordSubmissionDuration records the da submission duration for a given submission type
492497func (m * Metrics ) RecordSubmissionDuration (chainID , submissionType string , duration time.Duration ) {
498+ m .mu .Lock ()
499+ defer m .mu .Unlock ()
500+
493501 m .SubmissionDuration .WithLabelValues (chainID , submissionType ).Observe (duration .Seconds ())
502+
503+ key := fmt .Sprintf ("%s:%s" , chainID , submissionType )
504+ m .lastSubmissionDurations [key ] = duration
505+ }
506+
507+ // RefreshSubmissionDuration re-observes the last known submission duration to keep the metric alive.
508+ func (m * Metrics ) RefreshSubmissionDuration () {
509+ m .mu .Lock ()
510+ defer m .mu .Unlock ()
511+
512+ for key , duration := range m .lastSubmissionDurations {
513+ // assuming format "chainID:namespace"
514+ parts := strings .Split (key , ":" )
515+ if len (parts ) == 2 {
516+ m .SubmissionDuration .WithLabelValues (parts [0 ], parts [1 ]).Observe (duration .Seconds ())
517+ }
518+ }
494519}
495520
496521// RecordBlockTime records the time between consecutive blocks using arrival time
0 commit comments