From b183fd71afdd0bb49fcbee787929d8604164ca27 Mon Sep 17 00:00:00 2001 From: iurii Date: Thu, 28 May 2026 14:06:01 +0300 Subject: [PATCH] network/topics: clarify pubsub-received metric semantics, rename shadowed test var - Tighten the counter description to spell out that it counts deliveries to the topic validator *before* SSV validation runs, and reference inboundMessageCounter so operators can see the post-validation counterpart at a glance. - Add a brief comment on recordPubsubMessageReceived noting it is invoked from the validator wrapper before the inner validator, so all outcomes (including reject/timeout) are counted. - Rename the test loop variable that shadowed the imported metric package. --- network/topics/observability.go | 5 ++++- network/topics/observability_test.go | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/network/topics/observability.go b/network/topics/observability.go index 5b357054cc..2c05a9327a 100644 --- a/network/topics/observability.go +++ b/network/topics/observability.go @@ -38,7 +38,7 @@ var ( meter.Int64Counter( observability.InstrumentName(pubsubObservabilityNamespace, "received"), metric.WithUnit("{message}"), - metric.WithDescription("total number of messages received by the pubsub topic validator"))) + metric.WithDescription("total number of messages delivered to the pubsub topic validator, before SSV validation runs (compare with ssv_p2p_messages_in_total for the post-validation rate)"))) msgIDHandlerBufferFallbackCounter = metrics.New( meter.Int64Counter( @@ -62,6 +62,9 @@ func messageTypeAttribute(value uint64) attribute.KeyValue { } } +// recordPubsubMessageReceived is called from the topic validator wrapper before the inner SSV +// validator runs, so the counter increments for every message libp2p hands to the validator +// regardless of validation outcome (accept/ignore/reject/timeout). func recordPubsubMessageReceived(ctx context.Context, topic string) { pubsubMessagesReceivedCounter.Add(ctx, 1, metric.WithAttributes(pubsubTopicAttribute(topic))) } diff --git a/network/topics/observability_test.go b/network/topics/observability_test.go index 41f1dc650a..8e9b30ce60 100644 --- a/network/topics/observability_test.go +++ b/network/topics/observability_test.go @@ -27,12 +27,12 @@ func TestRecordPubsubMessageReceived(t *testing.T) { require.NoError(t, reader.Collect(t.Context(), &rm)) for _, scopeMetrics := range rm.ScopeMetrics { - for _, metric := range scopeMetrics.Metrics { - if metric.Name != "ssv.p2p.pubsub.messages.received" { + for _, m := range scopeMetrics.Metrics { + if m.Name != "ssv.p2p.pubsub.messages.received" { continue } - sum, ok := metric.Data.(metricdata.Sum[int64]) + sum, ok := m.Data.(metricdata.Sum[int64]) require.True(t, ok) require.Len(t, sum.DataPoints, 1) require.EqualValues(t, 2, sum.DataPoints[0].Value)