Skip to content

Commit b10a1db

Browse files
fix: update DASubmitterPendingBlobs to track total backlog
Changes the DASubmitterPendingBlobs metric to track the total number of blobs awaiting submission across the entire queue, rather than just the current batch being submitted. This provides better visibility into the submission backlog for monitoring and alerting. - Added getTotalPendingFn parameter to submitToDA() - Updated metric to call NumPendingHeaders() or NumPendingData() - Updated metric documentation and help text - Updated all test calls with new parameter Co-authored-by: Marko <tac0turtle@users.noreply.github.com>
1 parent 5ea1adb commit b10a1db

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

block/internal/common/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Metrics struct {
6767
// DA Submitter metrics
6868
DASubmitterFailures map[string]metrics.Counter // Counter with reason label
6969
DASubmitterLastFailure map[string]metrics.Gauge // Timestamp gauge with reason label
70-
DASubmitterPendingBlobs metrics.Gauge // Number of pending blobs
70+
DASubmitterPendingBlobs metrics.Gauge // Total number of blobs awaiting submission (backlog)
7171
DASubmitterResends metrics.Counter // Number of resend attempts
7272
}
7373

@@ -362,7 +362,7 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
362362
Namespace: namespace,
363363
Subsystem: MetricsSubsystem,
364364
Name: "da_submitter_pending_blobs",
365-
Help: "Number of blobs pending DA submission",
365+
Help: "Total number of blobs awaiting DA submission (backlog)",
366366
}, labels).With(labelsAndValues...)
367367

368368
m.DASubmitterResends = prometheus.NewCounterFrom(stdprometheus.CounterOpts{

block/internal/submitting/da_submitter.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func (s *DASubmitter) SubmitHeaders(ctx context.Context, cache cache.Manager) er
231231
s.namespaceBz,
232232
[]byte(s.config.DA.SubmitOptions),
233233
cache,
234+
func() uint64 { return cache.NumPendingHeaders() },
234235
)
235236
}
236237

@@ -274,6 +275,7 @@ func (s *DASubmitter) SubmitData(ctx context.Context, cache cache.Manager, signe
274275
s.namespaceDataBz,
275276
[]byte(s.config.DA.SubmitOptions),
276277
cache,
278+
func() uint64 { return cache.NumPendingData() },
277279
)
278280
}
279281

@@ -344,6 +346,7 @@ func submitToDA[T any](
344346
namespace []byte,
345347
options []byte,
346348
cache cache.Manager,
349+
getTotalPendingFn func() uint64,
347350
) error {
348351
marshaled, err := marshalItems(ctx, items, marshalFn, itemType)
349352
if err != nil {
@@ -368,9 +371,9 @@ func submitToDA[T any](
368371
marshaled = batchMarshaled
369372
}
370373

371-
// Update pending blobs metric
372-
if s.metrics != nil {
373-
s.metrics.DASubmitterPendingBlobs.Set(float64(len(items)))
374+
// Update pending blobs metric to track total backlog
375+
if s.metrics != nil && getTotalPendingFn != nil {
376+
s.metrics.DASubmitterPendingBlobs.Set(float64(getTotalPendingFn()))
374377
}
375378

376379
// Start the retry loop
@@ -401,19 +404,19 @@ func submitToDA[T any](
401404
s.logger.Info().Str("itemType", itemType).Float64("gasPrice", rs.GasPrice).Uint64("count", res.SubmittedCount).Msg("successfully submitted items to DA layer")
402405
if int(res.SubmittedCount) == len(items) {
403406
rs.Next(reasonSuccess, pol, gm, sentinelNoGas)
404-
// Clear pending blobs on success
405-
if s.metrics != nil {
406-
s.metrics.DASubmitterPendingBlobs.Set(0)
407+
// Update pending blobs metric to reflect total backlog
408+
if s.metrics != nil && getTotalPendingFn != nil {
409+
s.metrics.DASubmitterPendingBlobs.Set(float64(getTotalPendingFn()))
407410
}
408411
return nil
409412
}
410413
// partial success: advance window
411414
items = items[res.SubmittedCount:]
412415
marshaled = marshaled[res.SubmittedCount:]
413416
rs.Next(reasonSuccess, pol, gm, sentinelNoGas)
414-
// Update pending blobs count
415-
if s.metrics != nil {
416-
s.metrics.DASubmitterPendingBlobs.Set(float64(len(items)))
417+
// Update pending blobs count to reflect total backlog
418+
if s.metrics != nil && getTotalPendingFn != nil {
419+
s.metrics.DASubmitterPendingBlobs.Set(float64(getTotalPendingFn()))
417420
}
418421

419422
case coreda.StatusTooBig:
@@ -433,9 +436,9 @@ func submitToDA[T any](
433436
marshaled = marshaled[:half]
434437
s.logger.Debug().Int("newBatchSize", half).Msg("batch too big; halving and retrying")
435438
rs.Next(reasonTooBig, pol, gm, sentinelNoGas)
436-
// Update pending blobs count
437-
if s.metrics != nil {
438-
s.metrics.DASubmitterPendingBlobs.Set(float64(len(items)))
439+
// Update pending blobs count to reflect total backlog
440+
if s.metrics != nil && getTotalPendingFn != nil {
441+
s.metrics.DASubmitterPendingBlobs.Set(float64(getTotalPendingFn()))
439442
}
440443

441444
case coreda.StatusNotIncludedInBlock:

block/internal/submitting/da_submitter_mocks_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestSubmitToDA_MempoolRetry_IncreasesGasAndSucceeds(t *testing.T) {
8686
nsBz,
8787
opts,
8888
nil,
89+
nil,
8990
)
9091
assert.NoError(t, err)
9192

@@ -137,6 +138,7 @@ func TestSubmitToDA_UnknownError_RetriesSameGasThenSucceeds(t *testing.T) {
137138
nsBz,
138139
opts,
139140
nil,
141+
nil,
140142
)
141143
assert.NoError(t, err)
142144
assert.Equal(t, []float64{5.5, 5.5}, usedGas)
@@ -193,6 +195,7 @@ func TestSubmitToDA_TooBig_HalvesBatch(t *testing.T) {
193195
nsBz,
194196
opts,
195197
nil,
198+
nil,
196199
)
197200
assert.NoError(t, err)
198201
assert.Equal(t, []int{4, 2}, batchSizes)
@@ -242,6 +245,7 @@ func TestSubmitToDA_SentinelNoGas_PreservesGasAcrossRetries(t *testing.T) {
242245
nsBz,
243246
opts,
244247
nil,
248+
nil,
245249
)
246250
assert.NoError(t, err)
247251
assert.Equal(t, []float64{-1, -1}, usedGas)
@@ -282,6 +286,7 @@ func TestSubmitToDA_PartialSuccess_AdvancesWindow(t *testing.T) {
282286
nsBz,
283287
opts,
284288
nil,
289+
nil,
285290
)
286291
assert.NoError(t, err)
287292
assert.Equal(t, 3, totalSubmitted)

0 commit comments

Comments
 (0)