Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused metrics namespaces #3062

Merged
merged 4 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions chains/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
68 changes: 22 additions & 46 deletions snow/consensus/snowman/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type metrics struct {

func newMetrics(
log logging.Logger,
namespace string,
reg prometheus.Registerer,
lastAcceptedHeight uint64,
lastAcceptedTime time.Time,
Expand All @@ -75,97 +74,74 @@ 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,
&errs,
),

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",
}),
}

Expand Down
8 changes: 3 additions & 5 deletions snow/consensus/snowman/poll/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) Is the namespace sticking around for the metric.* functions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be removed in a followup

"poll_duration",
"time (in ns) this poll took to complete",
reg,
Expand Down
30 changes: 10 additions & 20 deletions snow/consensus/snowman/poll/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion snow/consensus/snowman/topological.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (ts *Topological) Initialize(

ts.metrics, err = newMetrics(
ctx.Log,
"",
ctx.Registerer,
lastAcceptedHeight,
lastAcceptedTime,
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/avalanche/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 9 additions & 16 deletions snow/engine/avalanche/bootstrap/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions snow/engine/avalanche/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
17 changes: 7 additions & 10 deletions snow/engine/common/tracker/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion snow/engine/snowman/bootstrap/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading