From e8c43f554e4e01354e728df8ae2a28b9916a6e3a Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 31 May 2024 10:10:03 -0400 Subject: [PATCH] Remove unused metrics namespaces (#3062) --- chains/manager.go | 4 +- snow/consensus/snowman/metrics.go | 68 +++++---------- snow/consensus/snowman/poll/set.go | 8 +- snow/consensus/snowman/poll/set_test.go | 30 +++---- snow/consensus/snowman/topological.go | 1 - .../avalanche/bootstrap/bootstrapper.go | 2 +- snow/engine/avalanche/bootstrap/metrics.go | 25 ++---- snow/engine/avalanche/getter/getter.go | 4 +- snow/engine/common/tracker/peers.go | 17 ++-- snow/engine/snowman/bootstrap/bootstrapper.go | 2 +- snow/engine/snowman/bootstrap/metrics.go | 12 ++- snow/engine/snowman/getter/getter.go | 4 +- snow/engine/snowman/metrics.go | 83 ++++++++----------- snow/engine/snowman/transitive.go | 3 +- snow/engine/snowman/transitive_test.go | 2 +- snow/networking/sender/sender.go | 5 +- utils/metric/api_interceptor.go | 15 ++-- vms/avm/block/builder/builder_test.go | 2 +- vms/avm/metrics/metrics.go | 24 ++---- vms/avm/metrics/tx_metrics.go | 10 +-- vms/avm/vm.go | 2 +- vms/metervm/block_metrics.go | 55 ++++++------ vms/metervm/block_vm.go | 1 - vms/metervm/metrics.go | 4 +- vms/metervm/vertex_metrics.go | 17 ++-- vms/metervm/vertex_vm.go | 2 +- vms/platformvm/block/builder/helpers_test.go | 2 +- vms/platformvm/metrics/block_metrics.go | 12 +-- vms/platformvm/metrics/metrics.go | 49 +++++------ vms/platformvm/metrics/tx_metrics.go | 10 +-- .../validators/manager_benchmark_test.go | 2 +- vms/platformvm/vm.go | 2 +- 32 files changed, 188 insertions(+), 291 deletions(-) diff --git a/chains/manager.go b/chains/manager.go index c5b79dd470e1..7fee70b8f816 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -753,7 +753,7 @@ func (m *manager) createAvalancheChain( sampleK = int(bootstrapWeight) } - connectedValidators, err := tracker.NewMeteredPeers("", ctx.Registerer) + connectedValidators, err := tracker.NewMeteredPeers(ctx.Registerer) if err != nil { return nil, fmt.Errorf("error creating peer tracker: %w", err) } @@ -1098,7 +1098,7 @@ func (m *manager) createSnowmanChain( sampleK = int(bootstrapWeight) } - connectedValidators, err := tracker.NewMeteredPeers("", ctx.Registerer) + connectedValidators, err := tracker.NewMeteredPeers(ctx.Registerer) if err != nil { return nil, fmt.Errorf("error creating peer tracker: %w", err) } diff --git a/snow/consensus/snowman/metrics.go b/snow/consensus/snowman/metrics.go index 6b48e868aaab..1db1bdbc1c53 100644 --- a/snow/consensus/snowman/metrics.go +++ b/snow/consensus/snowman/metrics.go @@ -65,7 +65,6 @@ type metrics struct { func newMetrics( log logging.Logger, - namespace string, reg prometheus.Registerer, lastAcceptedHeight uint64, lastAcceptedTime time.Time, @@ -75,82 +74,61 @@ func newMetrics( log: log, currentMaxVerifiedHeight: lastAcceptedHeight, maxVerifiedHeight: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "max_verified_height", - Help: "highest verified height", + Name: "max_verified_height", + Help: "highest verified height", }), lastAcceptedHeight: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "last_accepted_height", - Help: "last height accepted", + Name: "last_accepted_height", + Help: "last height accepted", }), lastAcceptedTimestamp: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "last_accepted_timestamp", - Help: "timestamp of the last accepted block in unix seconds", + Name: "last_accepted_timestamp", + Help: "timestamp of the last accepted block in unix seconds", }), processingBlocks: linked.NewHashmap[ids.ID, processingStart](), - // e.g., - // "avalanche_X_blks_processing" reports how many blocks are currently processing numProcessing: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blks_processing", - Help: "number of currently processing blocks", + Name: "blks_processing", + Help: "number of currently processing blocks", }), blockSizeAcceptedSum: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blks_accepted_container_size_sum", - Help: "cumulative size of all accepted blocks", + Name: "blks_accepted_container_size_sum", + Help: "cumulative size of all accepted blocks", }), pollsAccepted: metric.NewAveragerWithErrs( - namespace, + "", "blks_polls_accepted", "number of polls from the issuance of a block to its acceptance", reg, &errs, ), - // e.g., - // "avalanche_C_blks_accepted_count" reports how many times "Observe" has been called which is the total number of blocks accepted - // "avalanche_C_blks_accepted_sum" reports the cumulative sum of all block acceptance latencies in nanoseconds - // "avalanche_C_blks_accepted_sum / avalanche_C_blks_accepted_count" is the average block acceptance latency in nanoseconds - // "avalanche_C_blks_accepted_container_size_sum" reports the cumulative sum of all accepted blocks' sizes in bytes - // "avalanche_C_blks_accepted_container_size_sum / avalanche_C_blks_accepted_count" is the average accepted block size in bytes latAccepted: metric.NewAveragerWithErrs( - namespace, + "", "blks_accepted", "time (in ns) from the issuance of a block to its acceptance", reg, &errs, ), buildLatencyAccepted: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blks_build_accept_latency", - Help: "time (in ns) from the timestamp of a block to the time it was accepted", + Name: "blks_build_accept_latency", + Help: "time (in ns) from the timestamp of a block to the time it was accepted", }), blockSizeRejectedSum: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blks_rejected_container_size_sum", - Help: "cumulative size of all rejected blocks", + Name: "blks_rejected_container_size_sum", + Help: "cumulative size of all rejected blocks", }), pollsRejected: metric.NewAveragerWithErrs( - namespace, + "", "blks_polls_rejected", "number of polls from the issuance of a block to its rejection", reg, &errs, ), - // e.g., - // "avalanche_P_blks_rejected_count" reports how many times "Observe" has been called which is the total number of blocks rejected - // "avalanche_P_blks_rejected_sum" reports the cumulative sum of all block rejection latencies in nanoseconds - // "avalanche_P_blks_rejected_sum / avalanche_P_blks_rejected_count" is the average block rejection latency in nanoseconds - // "avalanche_P_blks_rejected_container_size_sum" reports the cumulative sum of all rejected blocks' sizes in bytes - // "avalanche_P_blks_rejected_container_size_sum / avalanche_P_blks_rejected_count" is the average rejected block size in bytes latRejected: metric.NewAveragerWithErrs( - namespace, + "", "blks_rejected", "time (in ns) from the issuance of a block to its rejection", reg, @@ -158,14 +136,12 @@ func newMetrics( ), numSuccessfulPolls: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "polls_successful", - Help: "number of successful polls", + Name: "polls_successful", + Help: "number of successful polls", }), numFailedPolls: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "polls_failed", - Help: "number of failed polls", + Name: "polls_failed", + Help: "number of failed polls", }), } diff --git a/snow/consensus/snowman/poll/set.go b/snow/consensus/snowman/poll/set.go index 87a751584c74..7ef519ea7f50 100644 --- a/snow/consensus/snowman/poll/set.go +++ b/snow/consensus/snowman/poll/set.go @@ -55,20 +55,18 @@ type set struct { func NewSet( factory Factory, log logging.Logger, - namespace string, reg prometheus.Registerer, ) (Set, error) { numPolls := prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "polls", - Help: "Number of pending network polls", + Name: "polls", + Help: "Number of pending network polls", }) if err := reg.Register(numPolls); err != nil { return nil, fmt.Errorf("%w: %w", errFailedPollsMetric, err) } durPolls, err := metric.NewAverager( - namespace, + "", "poll_duration", "time (in ns) this poll took to complete", reg, diff --git a/snow/consensus/snowman/poll/set_test.go b/snow/consensus/snowman/poll/set_test.go index 0717242060d9..97166e0e9379 100644 --- a/snow/consensus/snowman/poll/set_test.go +++ b/snow/consensus/snowman/poll/set_test.go @@ -32,15 +32,13 @@ func TestNewSetErrorOnPollsMetrics(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(1, 1) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() require.NoError(registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "polls", + Name: "polls", }))) - _, err := NewSet(factory, log, namespace, registerer) + _, err := NewSet(factory, log, registerer) require.ErrorIs(err, errFailedPollsMetric) } @@ -49,15 +47,13 @@ func TestNewSetErrorOnPollDurationMetrics(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(1, 1) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() require.NoError(registerer.Register(prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "poll_duration_count", + Name: "poll_duration_count", }))) - _, err := NewSet(factory, log, namespace, registerer) + _, err := NewSet(factory, log, registerer) require.ErrorIs(err, errFailedPollDurationMetrics) } @@ -69,9 +65,8 @@ func TestCreateAndFinishPollOutOfOrder_NewerFinishesFirst(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) // create two polls for the two blocks @@ -106,9 +101,8 @@ func TestCreateAndFinishPollOutOfOrder_OlderFinishesFirst(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) // create two polls for the two blocks @@ -143,9 +137,8 @@ func TestCreateAndFinishPollOutOfOrder_UnfinishedPollsGaps(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) // create three polls for the two blocks @@ -188,9 +181,8 @@ func TestCreateAndFinishSuccessfulPoll(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) require.Zero(s.Len()) @@ -221,9 +213,8 @@ func TestCreateAndFinishFailedPoll(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) require.Zero(s.Len()) @@ -251,9 +242,8 @@ func TestSetString(t *testing.T) { factory := NewEarlyTermNoTraversalFactory(alpha, alpha) log := logging.NoLog{} - namespace := "" registerer := prometheus.NewRegistry() - s, err := NewSet(factory, log, namespace, registerer) + s, err := NewSet(factory, log, registerer) require.NoError(err) expected := `current polls: (Size = 1) diff --git a/snow/consensus/snowman/topological.go b/snow/consensus/snowman/topological.go index 0eb8b55c1f6f..f2ef015654c7 100644 --- a/snow/consensus/snowman/topological.go +++ b/snow/consensus/snowman/topological.go @@ -111,7 +111,6 @@ func (ts *Topological) Initialize( ts.metrics, err = newMetrics( ctx.Log, - "", ctx.Registerer, lastAcceptedHeight, lastAcceptedTime, diff --git a/snow/engine/avalanche/bootstrap/bootstrapper.go b/snow/engine/avalanche/bootstrap/bootstrapper.go index b79c9c8cb5ff..55e3307e9337 100644 --- a/snow/engine/avalanche/bootstrap/bootstrapper.go +++ b/snow/engine/avalanche/bootstrap/bootstrapper.go @@ -66,7 +66,7 @@ func New( processedCache: &cache.LRU[ids.ID, struct{}]{Size: cacheSize}, onFinished: onFinished, } - return b, b.metrics.Initialize("bs", config.Ctx.AvalancheRegisterer) + return b, b.metrics.Initialize(config.Ctx.AvalancheRegisterer) } // Note: To align with the Snowman invariant, it should be guaranteed the VM is diff --git a/snow/engine/avalanche/bootstrap/metrics.go b/snow/engine/avalanche/bootstrap/metrics.go index 5ad1b3713647..fdf68f5ecff2 100644 --- a/snow/engine/avalanche/bootstrap/metrics.go +++ b/snow/engine/avalanche/bootstrap/metrics.go @@ -14,30 +14,23 @@ type metrics struct { numFetchedTxs, numAcceptedTxs prometheus.Counter } -func (m *metrics) Initialize( - namespace string, - registerer prometheus.Registerer, -) error { +func (m *metrics) Initialize(registerer prometheus.Registerer) error { m.numFetchedVts = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "fetched_vts", - Help: "Number of vertices fetched during bootstrapping", + Name: "bs_fetched_vts", + Help: "Number of vertices fetched during bootstrapping", }) m.numAcceptedVts = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "accepted_vts", - Help: "Number of vertices accepted during bootstrapping", + Name: "bs_accepted_vts", + Help: "Number of vertices accepted during bootstrapping", }) m.numFetchedTxs = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "fetched_txs", - Help: "Number of transactions fetched during bootstrapping", + Name: "bs_fetched_txs", + Help: "Number of transactions fetched during bootstrapping", }) m.numAcceptedTxs = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "accepted_txs", - Help: "Number of transactions accepted during bootstrapping", + Name: "bs_accepted_txs", + Help: "Number of transactions accepted during bootstrapping", }) return utils.Err( diff --git a/snow/engine/avalanche/getter/getter.go b/snow/engine/avalanche/getter/getter.go index 796cade92fac..6866e7a54ba0 100644 --- a/snow/engine/avalanche/getter/getter.go +++ b/snow/engine/avalanche/getter/getter.go @@ -44,8 +44,8 @@ func New( var err error gh.getAncestorsVtxs, err = metric.NewAverager( - "bs", - "get_ancestors_vtxs", + "", + "bs_get_ancestors_vtxs", "vertices fetched in a call to GetAncestors", reg, ) diff --git a/snow/engine/common/tracker/peers.go b/snow/engine/common/tracker/peers.go index 1e76d42f4268..94ed46764785 100644 --- a/snow/engine/common/tracker/peers.go +++ b/snow/engine/common/tracker/peers.go @@ -113,21 +113,18 @@ type meteredPeers struct { totalWeight prometheus.Gauge } -func NewMeteredPeers(namespace string, reg prometheus.Registerer) (Peers, error) { +func NewMeteredPeers(reg prometheus.Registerer) (Peers, error) { percentConnected := prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "percent_connected", - Help: "Percent of connected stake", + Name: "percent_connected", + Help: "Percent of connected stake", }) totalWeight := prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "total_weight", - Help: "Total stake", + Name: "total_weight", + Help: "Total stake", }) numValidators := prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "num_validators", - Help: "Total number of validators", + Name: "num_validators", + Help: "Total number of validators", }) err := utils.Err( reg.Register(percentConnected), diff --git a/snow/engine/snowman/bootstrap/bootstrapper.go b/snow/engine/snowman/bootstrap/bootstrapper.go index 095ba4e63b17..6b8462f83f63 100644 --- a/snow/engine/snowman/bootstrap/bootstrapper.go +++ b/snow/engine/snowman/bootstrap/bootstrapper.go @@ -116,7 +116,7 @@ type Bootstrapper struct { } func New(config Config, onFinished func(ctx context.Context, lastReqID uint32) error) (*Bootstrapper, error) { - metrics, err := newMetrics("bs", config.Ctx.Registerer) + metrics, err := newMetrics(config.Ctx.Registerer) return &Bootstrapper{ Config: config, metrics: metrics, diff --git a/snow/engine/snowman/bootstrap/metrics.go b/snow/engine/snowman/bootstrap/metrics.go index 311ed05f136d..7b28b8b969b7 100644 --- a/snow/engine/snowman/bootstrap/metrics.go +++ b/snow/engine/snowman/bootstrap/metrics.go @@ -13,17 +13,15 @@ type metrics struct { numFetched, numAccepted prometheus.Counter } -func newMetrics(namespace string, registerer prometheus.Registerer) (*metrics, error) { +func newMetrics(registerer prometheus.Registerer) (*metrics, error) { m := &metrics{ numFetched: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "fetched", - Help: "Number of blocks fetched during bootstrapping", + Name: "bs_fetched", + Help: "Number of blocks fetched during bootstrapping", }), numAccepted: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "accepted", - Help: "Number of blocks accepted during bootstrapping", + Name: "bs_accepted", + Help: "Number of blocks accepted during bootstrapping", }), } diff --git a/snow/engine/snowman/getter/getter.go b/snow/engine/snowman/getter/getter.go index b58d7eb87428..aed51298cd22 100644 --- a/snow/engine/snowman/getter/getter.go +++ b/snow/engine/snowman/getter/getter.go @@ -43,8 +43,8 @@ func New( var err error gh.getAncestorsBlks, err = metric.NewAverager( - "bs", - "get_ancestors_blks", + "", + "bs_get_ancestors_blks", "blocks fetched in a call to GetAncestors", reg, ) diff --git a/snow/engine/snowman/metrics.go b/snow/engine/snowman/metrics.go index 193b067a14cd..bd46eb002fcf 100644 --- a/snow/engine/snowman/metrics.go +++ b/snow/engine/snowman/metrics.go @@ -38,104 +38,89 @@ type metrics struct { issued *prometheus.CounterVec } -func newMetrics(namespace string, reg prometheus.Registerer) (*metrics, error) { +func newMetrics(reg prometheus.Registerer) (*metrics, error) { errs := wrappers.Errs{} m := &metrics{ bootstrapFinished: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "bootstrap_finished", - Help: "Whether or not bootstrap process has completed. 1 is success, 0 is fail or ongoing.", + Name: "bootstrap_finished", + Help: "Whether or not bootstrap process has completed. 1 is success, 0 is fail or ongoing.", }), numRequests: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "requests", - Help: "Number of outstanding block requests", + Name: "requests", + Help: "Number of outstanding block requests", }), numBlocked: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blocked", - Help: "Number of blocks that are pending issuance", + Name: "blocked", + Help: "Number of blocks that are pending issuance", }), numBlockers: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "blockers", - Help: "Number of blocks that are blocking other blocks from being issued because they haven't been issued", + Name: "blockers", + Help: "Number of blocks that are blocking other blocks from being issued because they haven't been issued", }), numNonVerifieds: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "non_verified_blks", - Help: "Number of non-verified blocks in the memory", + Name: "non_verified_blks", + Help: "Number of non-verified blocks in the memory", }), numBuilt: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "blks_built", - Help: "Number of blocks that have been built locally", + Name: "blks_built", + Help: "Number of blocks that have been built locally", }), numBuildsFailed: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "blk_builds_failed", - Help: "Number of BuildBlock calls that have failed", + Name: "blk_builds_failed", + Help: "Number of BuildBlock calls that have failed", }), numUselessPutBytes: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_useless_put_bytes", - Help: "Amount of useless bytes received in Put messages", + Name: "num_useless_put_bytes", + Help: "Amount of useless bytes received in Put messages", }), numUselessPushQueryBytes: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_useless_push_query_bytes", - Help: "Amount of useless bytes received in PushQuery messages", + Name: "num_useless_push_query_bytes", + Help: "Amount of useless bytes received in PushQuery messages", }), numMissingAcceptedBlocks: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_missing_accepted_blocks", - Help: "Number of times an accepted block height was referenced and it wasn't locally available", + Name: "num_missing_accepted_blocks", + Help: "Number of times an accepted block height was referenced and it wasn't locally available", }), numProcessingAncestorFetchesFailed: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_processing_ancestor_fetches_failed", - Help: "Number of votes that were dropped due to unknown blocks", + Name: "num_processing_ancestor_fetches_failed", + Help: "Number of votes that were dropped due to unknown blocks", }), numProcessingAncestorFetchesDropped: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_processing_ancestor_fetches_dropped", - Help: "Number of votes that were dropped due to decided blocks", + Name: "num_processing_ancestor_fetches_dropped", + Help: "Number of votes that were dropped due to decided blocks", }), numProcessingAncestorFetchesSucceeded: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_processing_ancestor_fetches_succeeded", - Help: "Number of votes that were applied to ancestor blocks", + Name: "num_processing_ancestor_fetches_succeeded", + Help: "Number of votes that were applied to ancestor blocks", }), numProcessingAncestorFetchesUnneeded: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "num_processing_ancestor_fetches_unneeded", - Help: "Number of votes that were directly applied to blocks", + Name: "num_processing_ancestor_fetches_unneeded", + Help: "Number of votes that were directly applied to blocks", }), getAncestorsBlks: metric.NewAveragerWithErrs( - namespace, + "", "get_ancestors_blks", "blocks fetched in a call to GetAncestors", reg, &errs, ), selectedVoteIndex: metric.NewAveragerWithErrs( - namespace, + "", "selected_vote_index", "index of the voteID that was passed into consensus", reg, &errs, ), issuerStake: metric.NewAveragerWithErrs( - namespace, + "", "issuer_stake", "stake weight of the peer who provided a block that was issued into consensus", reg, &errs, ), issued: prometheus.NewCounterVec(prometheus.CounterOpts{ - Namespace: namespace, - Name: "blks_issued", - Help: "number of blocks that have been issued into consensus by discovery mechanism", + Name: "blks_issued", + Help: "number of blocks that have been issued into consensus by discovery mechanism", }, []string{"source"}), } diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index 32bf4ac5d5a4..9e89fedd22b2 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -118,14 +118,13 @@ func New(config Config) (*Transitive, error) { polls, err := poll.NewSet( factory, config.Ctx.Log, - "", config.Ctx.Registerer, ) if err != nil { return nil, err } - metrics, err := newMetrics("", config.Ctx.Registerer) + metrics, err := newMetrics(config.Ctx.Registerer) if err != nil { return nil, err } diff --git a/snow/engine/snowman/transitive_test.go b/snow/engine/snowman/transitive_test.go index 75040d9a1f53..2961b018c8ce 100644 --- a/snow/engine/snowman/transitive_test.go +++ b/snow/engine/snowman/transitive_test.go @@ -2866,7 +2866,7 @@ func TestGetProcessingAncestor(t *testing.T) { unissuedBlock = snowmantest.BuildChild(issuedBlock) ) - metrics, err := newMetrics("", prometheus.NewRegistry()) + metrics, err := newMetrics(prometheus.NewRegistry()) require.NoError(t, err) c := &snowman.Topological{} diff --git a/snow/networking/sender/sender.go b/snow/networking/sender/sender.go index c13b9e22682a..37076972fe12 100644 --- a/snow/networking/sender/sender.go +++ b/snow/networking/sender/sender.go @@ -67,9 +67,8 @@ func New( timeouts: timeouts, failedDueToBench: prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: "", - Name: "failed_benched", - Help: "requests dropped because a node was benched", + Name: "failed_benched", + Help: "requests dropped because a node was benched", }, opLabels, ), diff --git a/utils/metric/api_interceptor.go b/utils/metric/api_interceptor.go index 7d970b22b833..50027fde1478 100644 --- a/utils/metric/api_interceptor.go +++ b/utils/metric/api_interceptor.go @@ -29,27 +29,24 @@ type apiInterceptor struct { requestErrors *prometheus.CounterVec } -func NewAPIInterceptor(namespace string, registerer prometheus.Registerer) (APIInterceptor, error) { +func NewAPIInterceptor(registerer prometheus.Registerer) (APIInterceptor, error) { requestDurationCount := prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: namespace, - Name: "request_duration_count", - Help: "Number of times this type of request was made", + Name: "request_duration_count", + Help: "Number of times this type of request was made", }, []string{"method"}, ) requestDurationSum := prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Namespace: namespace, - Name: "request_duration_sum", - Help: "Amount of time in nanoseconds that has been spent handling this type of request", + Name: "request_duration_sum", + Help: "Amount of time in nanoseconds that has been spent handling this type of request", }, []string{"method"}, ) requestErrors := prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: namespace, - Name: "request_error_count", + Name: "request_error_count", }, []string{"method"}, ) diff --git a/vms/avm/block/builder/builder_test.go b/vms/avm/block/builder/builder_test.go index 89f043844b54..36159598b706 100644 --- a/vms/avm/block/builder/builder_test.go +++ b/vms/avm/block/builder/builder_test.go @@ -544,7 +544,7 @@ func TestBlockBuilderAddLocalTx(t *testing.T) { state.AddBlock(parentBlk) state.SetLastAccepted(parentBlk.ID()) - metrics, err := metrics.New("", registerer) + metrics, err := metrics.New(registerer) require.NoError(err) manager := blkexecutor.NewManager(mempool, metrics, state, backend, clk, onAccept) diff --git a/vms/avm/metrics/metrics.go b/vms/avm/metrics/metrics.go index 9e4053e1fcc6..7d122ce6e42e 100644 --- a/vms/avm/metrics/metrics.go +++ b/vms/avm/metrics/metrics.go @@ -66,32 +66,26 @@ func (m *metrics) MarkTxAccepted(tx *txs.Tx) error { return tx.Unsigned.Visit(m.txMetrics) } -func New( - namespace string, - registerer prometheus.Registerer, -) (Metrics, error) { - txMetrics, err := newTxMetrics(namespace, registerer) +func New(registerer prometheus.Registerer) (Metrics, error) { + txMetrics, err := newTxMetrics(registerer) errs := wrappers.Errs{Err: err} m := &metrics{txMetrics: txMetrics} m.numTxRefreshes = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "tx_refreshes", - Help: "Number of times unique txs have been refreshed", + Name: "tx_refreshes", + Help: "Number of times unique txs have been refreshed", }) m.numTxRefreshHits = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "tx_refresh_hits", - Help: "Number of times unique txs have not been unique, but were cached", + Name: "tx_refresh_hits", + Help: "Number of times unique txs have not been unique, but were cached", }) m.numTxRefreshMisses = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "tx_refresh_misses", - Help: "Number of times unique txs have not been unique and weren't cached", + Name: "tx_refresh_misses", + Help: "Number of times unique txs have not been unique and weren't cached", }) - apiRequestMetric, err := metric.NewAPIInterceptor(namespace, registerer) + apiRequestMetric, err := metric.NewAPIInterceptor(registerer) m.APIInterceptor = apiRequestMetric errs.Add( err, diff --git a/vms/avm/metrics/tx_metrics.go b/vms/avm/metrics/tx_metrics.go index 8b9bf2c0ed47..3c8d1bac79ad 100644 --- a/vms/avm/metrics/tx_metrics.go +++ b/vms/avm/metrics/tx_metrics.go @@ -21,16 +21,12 @@ type txMetrics struct { numTxs *prometheus.CounterVec } -func newTxMetrics( - namespace string, - registerer prometheus.Registerer, -) (*txMetrics, error) { +func newTxMetrics(registerer prometheus.Registerer) (*txMetrics, error) { m := &txMetrics{ numTxs: prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: namespace, - Name: "txs_accepted", - Help: "number of transactions accepted", + Name: "txs_accepted", + Help: "number of transactions accepted", }, txLabels, ), diff --git a/vms/avm/vm.go b/vms/avm/vm.go index b8fe322ef959..ab05b053b393 100644 --- a/vms/avm/vm.go +++ b/vms/avm/vm.go @@ -182,7 +182,7 @@ func (vm *VM) Initialize( vm.connectedPeers = make(map[ids.NodeID]*version.Application) // Initialize metrics as soon as possible - vm.metrics, err = metrics.New("", registerer) + vm.metrics, err = metrics.New(registerer) if err != nil { return fmt.Errorf("failed to initialize metrics: %w", err) } diff --git a/vms/metervm/block_metrics.go b/vms/metervm/block_metrics.go index 0a6473f617bd..2bdc247c4062 100644 --- a/vms/metervm/block_metrics.go +++ b/vms/metervm/block_metrics.go @@ -49,43 +49,42 @@ func (m *blockMetrics) Initialize( supportsBlockBuildingWithContext bool, supportsBatchedFetching bool, supportsStateSync bool, - namespace string, reg prometheus.Registerer, ) error { errs := wrappers.Errs{} - m.buildBlock = newAverager(namespace, "build_block", reg, &errs) - m.buildBlockErr = newAverager(namespace, "build_block_err", reg, &errs) - m.parseBlock = newAverager(namespace, "parse_block", reg, &errs) - m.parseBlockErr = newAverager(namespace, "parse_block_err", reg, &errs) - m.getBlock = newAverager(namespace, "get_block", reg, &errs) - m.getBlockErr = newAverager(namespace, "get_block_err", reg, &errs) - m.setPreference = newAverager(namespace, "set_preference", reg, &errs) - m.lastAccepted = newAverager(namespace, "last_accepted", reg, &errs) - m.verify = newAverager(namespace, "verify", reg, &errs) - m.verifyErr = newAverager(namespace, "verify_err", reg, &errs) - m.accept = newAverager(namespace, "accept", reg, &errs) - m.reject = newAverager(namespace, "reject", reg, &errs) - m.shouldVerifyWithContext = newAverager(namespace, "should_verify_with_context", reg, &errs) - m.verifyWithContext = newAverager(namespace, "verify_with_context", reg, &errs) - m.verifyWithContextErr = newAverager(namespace, "verify_with_context_err", reg, &errs) - m.getBlockIDAtHeight = newAverager(namespace, "get_block_id_at_height", reg, &errs) + m.buildBlock = newAverager("build_block", reg, &errs) + m.buildBlockErr = newAverager("build_block_err", reg, &errs) + m.parseBlock = newAverager("parse_block", reg, &errs) + m.parseBlockErr = newAverager("parse_block_err", reg, &errs) + m.getBlock = newAverager("get_block", reg, &errs) + m.getBlockErr = newAverager("get_block_err", reg, &errs) + m.setPreference = newAverager("set_preference", reg, &errs) + m.lastAccepted = newAverager("last_accepted", reg, &errs) + m.verify = newAverager("verify", reg, &errs) + m.verifyErr = newAverager("verify_err", reg, &errs) + m.accept = newAverager("accept", reg, &errs) + m.reject = newAverager("reject", reg, &errs) + m.shouldVerifyWithContext = newAverager("should_verify_with_context", reg, &errs) + m.verifyWithContext = newAverager("verify_with_context", reg, &errs) + m.verifyWithContextErr = newAverager("verify_with_context_err", reg, &errs) + m.getBlockIDAtHeight = newAverager("get_block_id_at_height", reg, &errs) if supportsBlockBuildingWithContext { - m.buildBlockWithContext = newAverager(namespace, "build_block_with_context", reg, &errs) - m.buildBlockWithContextErr = newAverager(namespace, "build_block_with_context_err", reg, &errs) + m.buildBlockWithContext = newAverager("build_block_with_context", reg, &errs) + m.buildBlockWithContextErr = newAverager("build_block_with_context_err", reg, &errs) } if supportsBatchedFetching { - m.getAncestors = newAverager(namespace, "get_ancestors", reg, &errs) - m.batchedParseBlock = newAverager(namespace, "batched_parse_block", reg, &errs) + m.getAncestors = newAverager("get_ancestors", reg, &errs) + m.batchedParseBlock = newAverager("batched_parse_block", reg, &errs) } if supportsStateSync { - m.stateSyncEnabled = newAverager(namespace, "state_sync_enabled", reg, &errs) - m.getOngoingSyncStateSummary = newAverager(namespace, "get_ongoing_state_sync_summary", reg, &errs) - m.getLastStateSummary = newAverager(namespace, "get_last_state_summary", reg, &errs) - m.parseStateSummary = newAverager(namespace, "parse_state_summary", reg, &errs) - m.parseStateSummaryErr = newAverager(namespace, "parse_state_summary_err", reg, &errs) - m.getStateSummary = newAverager(namespace, "get_state_summary", reg, &errs) - m.getStateSummaryErr = newAverager(namespace, "get_state_summary_err", reg, &errs) + m.stateSyncEnabled = newAverager("state_sync_enabled", reg, &errs) + m.getOngoingSyncStateSummary = newAverager("get_ongoing_state_sync_summary", reg, &errs) + m.getLastStateSummary = newAverager("get_last_state_summary", reg, &errs) + m.parseStateSummary = newAverager("parse_state_summary", reg, &errs) + m.parseStateSummaryErr = newAverager("parse_state_summary_err", reg, &errs) + m.getStateSummary = newAverager("get_state_summary", reg, &errs) + m.getStateSummaryErr = newAverager("get_state_summary_err", reg, &errs) } return errs.Err } diff --git a/vms/metervm/block_vm.go b/vms/metervm/block_vm.go index 0ecb982c4742..6d951f344b2b 100644 --- a/vms/metervm/block_vm.go +++ b/vms/metervm/block_vm.go @@ -63,7 +63,6 @@ func (vm *blockVM) Initialize( vm.buildBlockVM != nil, vm.batchedVM != nil, vm.ssVM != nil, - "", registerer, ) if err != nil { diff --git a/vms/metervm/metrics.go b/vms/metervm/metrics.go index d4c9304e7696..09d85a770585 100644 --- a/vms/metervm/metrics.go +++ b/vms/metervm/metrics.go @@ -10,9 +10,9 @@ import ( "github.com/ava-labs/avalanchego/utils/wrappers" ) -func newAverager(namespace, name string, reg prometheus.Registerer, errs *wrappers.Errs) metric.Averager { +func newAverager(name string, reg prometheus.Registerer, errs *wrappers.Errs) metric.Averager { return metric.NewAveragerWithErrs( - namespace, + "", name, "time (in ns) of a "+name, reg, diff --git a/vms/metervm/vertex_metrics.go b/vms/metervm/vertex_metrics.go index 67caa50b610e..04096f2ae035 100644 --- a/vms/metervm/vertex_metrics.go +++ b/vms/metervm/vertex_metrics.go @@ -19,16 +19,13 @@ type vertexMetrics struct { reject metric.Averager } -func (m *vertexMetrics) Initialize( - namespace string, - reg prometheus.Registerer, -) error { +func (m *vertexMetrics) Initialize(reg prometheus.Registerer) error { errs := wrappers.Errs{} - m.parse = newAverager(namespace, "parse_tx", reg, &errs) - m.parseErr = newAverager(namespace, "parse_tx_err", reg, &errs) - m.verify = newAverager(namespace, "verify_tx", reg, &errs) - m.verifyErr = newAverager(namespace, "verify_tx_err", reg, &errs) - m.accept = newAverager(namespace, "accept", reg, &errs) - m.reject = newAverager(namespace, "reject", reg, &errs) + m.parse = newAverager("parse_tx", reg, &errs) + m.parseErr = newAverager("parse_tx_err", reg, &errs) + m.verify = newAverager("verify_tx", reg, &errs) + m.verifyErr = newAverager("verify_tx_err", reg, &errs) + m.accept = newAverager("accept", reg, &errs) + m.reject = newAverager("reject", reg, &errs) return errs.Err } diff --git a/vms/metervm/vertex_vm.go b/vms/metervm/vertex_vm.go index 7cd112ffde24..7cbd47a67475 100644 --- a/vms/metervm/vertex_vm.go +++ b/vms/metervm/vertex_vm.go @@ -46,7 +46,7 @@ func (vm *vertexVM) Initialize( appSender common.AppSender, ) error { registerer := prometheus.NewRegistry() - if err := vm.vertexMetrics.Initialize("", registerer); err != nil { + if err := vm.vertexMetrics.Initialize(registerer); err != nil { return err } diff --git a/vms/platformvm/block/builder/helpers_test.go b/vms/platformvm/block/builder/helpers_test.go index 0108162649d6..909d7adefe5e 100644 --- a/vms/platformvm/block/builder/helpers_test.go +++ b/vms/platformvm/block/builder/helpers_test.go @@ -177,7 +177,7 @@ func newEnvironment(t *testing.T, f fork) *environment { //nolint:unparam return nil } - metrics, err := metrics.New("", registerer) + metrics, err := metrics.New(registerer) require.NoError(err) res.mempool, err = mempool.New("mempool", registerer, nil) diff --git a/vms/platformvm/metrics/block_metrics.go b/vms/platformvm/metrics/block_metrics.go index cc1acd7eb862..bf05de8e8dd8 100644 --- a/vms/platformvm/metrics/block_metrics.go +++ b/vms/platformvm/metrics/block_metrics.go @@ -22,11 +22,8 @@ type blockMetrics struct { numBlocks *prometheus.CounterVec } -func newBlockMetrics( - namespace string, - registerer prometheus.Registerer, -) (*blockMetrics, error) { - txMetrics, err := newTxMetrics(namespace, registerer) +func newBlockMetrics(registerer prometheus.Registerer) (*blockMetrics, error) { + txMetrics, err := newTxMetrics(registerer) if err != nil { return nil, err } @@ -35,9 +32,8 @@ func newBlockMetrics( txMetrics: txMetrics, numBlocks: prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: namespace, - Name: "blks_accepted", - Help: "number of blocks accepted", + Name: "blks_accepted", + Help: "number of blocks accepted", }, blkLabels, ), diff --git a/vms/platformvm/metrics/metrics.go b/vms/platformvm/metrics/metrics.go index 98b611a017ed..82b51dc8c34c 100644 --- a/vms/platformvm/metrics/metrics.go +++ b/vms/platformvm/metrics/metrics.go @@ -40,61 +40,50 @@ type Metrics interface { SetTimeUntilSubnetUnstake(subnetID ids.ID, timeUntilUnstake time.Duration) } -func New( - namespace string, - registerer prometheus.Registerer, -) (Metrics, error) { - blockMetrics, err := newBlockMetrics(namespace, registerer) +func New(registerer prometheus.Registerer) (Metrics, error) { + blockMetrics, err := newBlockMetrics(registerer) m := &metrics{ blockMetrics: blockMetrics, timeUntilUnstake: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "time_until_unstake", - Help: "Time (in ns) until this node leaves the Primary Network's validator set", + Name: "time_until_unstake", + Help: "Time (in ns) until this node leaves the Primary Network's validator set", }), timeUntilSubnetUnstake: prometheus.NewGaugeVec( prometheus.GaugeOpts{ - Namespace: namespace, - Name: "time_until_unstake_subnet", - Help: "Time (in ns) until this node leaves the subnet's validator set", + Name: "time_until_unstake_subnet", + Help: "Time (in ns) until this node leaves the subnet's validator set", }, []string{"subnetID"}, ), localStake: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "local_staked", - Help: "Amount (in nAVAX) of AVAX staked on this node", + Name: "local_staked", + Help: "Amount (in nAVAX) of AVAX staked on this node", }), totalStake: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "total_staked", - Help: "Amount (in nAVAX) of AVAX staked on the Primary Network", + Name: "total_staked", + Help: "Amount (in nAVAX) of AVAX staked on the Primary Network", }), validatorSetsCached: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "validator_sets_cached", - Help: "Total number of validator sets cached", + Name: "validator_sets_cached", + Help: "Total number of validator sets cached", }), validatorSetsCreated: prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Name: "validator_sets_created", - Help: "Total number of validator sets created from applying difflayers", + Name: "validator_sets_created", + Help: "Total number of validator sets created from applying difflayers", }), validatorSetsHeightDiff: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "validator_sets_height_diff_sum", - Help: "Total number of validator sets diffs applied for generating validator sets", + Name: "validator_sets_height_diff_sum", + Help: "Total number of validator sets diffs applied for generating validator sets", }), validatorSetsDuration: prometheus.NewGauge(prometheus.GaugeOpts{ - Namespace: namespace, - Name: "validator_sets_duration_sum", - Help: "Total amount of time generating validator sets in nanoseconds", + Name: "validator_sets_duration_sum", + Help: "Total amount of time generating validator sets in nanoseconds", }), } errs := wrappers.Errs{Err: err} - apiRequestMetrics, err := metric.NewAPIInterceptor(namespace, registerer) + apiRequestMetrics, err := metric.NewAPIInterceptor(registerer) errs.Add(err) m.APIInterceptor = apiRequestMetrics errs.Add( diff --git a/vms/platformvm/metrics/tx_metrics.go b/vms/platformvm/metrics/tx_metrics.go index 5526a6a0be57..02f45f011624 100644 --- a/vms/platformvm/metrics/tx_metrics.go +++ b/vms/platformvm/metrics/tx_metrics.go @@ -21,16 +21,12 @@ type txMetrics struct { numTxs *prometheus.CounterVec } -func newTxMetrics( - namespace string, - registerer prometheus.Registerer, -) (*txMetrics, error) { +func newTxMetrics(registerer prometheus.Registerer) (*txMetrics, error) { m := &txMetrics{ numTxs: prometheus.NewCounterVec( prometheus.CounterOpts{ - Namespace: namespace, - Name: "txs_accepted", - Help: "number of transactions accepted", + Name: "txs_accepted", + Help: "number of transactions accepted", }, txLabels, ), diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 912f3619e3e0..3a756f73c6af 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -104,7 +104,7 @@ func BenchmarkGetValidatorSet(b *testing.B) { execConfig, err := config.GetExecutionConfig(nil) require.NoError(err) - metrics, err := metrics.New("", prometheus.NewRegistry()) + metrics, err := metrics.New(prometheus.NewRegistry()) require.NoError(err) s, err := state.New( diff --git a/vms/platformvm/vm.go b/vms/platformvm/vm.go index b6417bbd0c45..565960cff599 100644 --- a/vms/platformvm/vm.go +++ b/vms/platformvm/vm.go @@ -119,7 +119,7 @@ func (vm *VM) Initialize( } // Initialize metrics as soon as possible - vm.metrics, err = metrics.New("", registerer) + vm.metrics, err = metrics.New(registerer) if err != nil { return fmt.Errorf("failed to initialize metrics: %w", err) }