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

Target metrics #1811

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 36 additions & 6 deletions internal/gossiper/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,65 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

const namespace = "gossiper"

type metrics struct {
txsReceived prometheus.Counter
seenTxsReceived prometheus.Counter
txsGossiped prometheus.Counter
txsReceived prometheus.Counter
seenTxsReceived prometheus.Counter
txsGossiped prometheus.Counter
selectTxsToGossipCount prometheus.Counter
selectTxsToGossipSum prometheus.Gauge
selectedTxsToGossip prometheus.Counter
targetTxsSum prometheus.Gauge
Comment on lines +18 to +20
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason to use a Gauge? I feel like only Inc/Add method are used to represent the metric.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm was just copying how we had handled durations elsewhere. This will never decrease, so we could use a counter instead.

}

func newMetrics(r prometheus.Registerer) (*metrics, error) {
m := &metrics{
txsReceived: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gossiper",
Namespace: namespace,
Name: "txs_received",
Help: "number of txs received over gossip",
}),
txsGossiped: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gossiper",
Namespace: namespace,
Name: "txs_gossiped",
Help: "number of txs gossiped",
}),
seenTxsReceived: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "gossiper",
Namespace: namespace,
Name: "seen_txs_received",
Help: "number of txs received over gossip that were already seen",
}),
selectTxsToGossipCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "select_txs_to_gossip_count",
Help: "number of times gossiper iterates mempool to select txs for gossip",
}),
selectTxsToGossipSum: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "select_txs_to_gossip_sum",
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not obvious this + target_txs_sum are latency metrics from the naming - can we put time or something in the name to make it more clear?

Help: "sum of time spent iterating mempool to select txs for gossip",
}),
selectedTxsToGossip: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "selected_txs_to_gossip",
Copy link
Contributor

Choose a reason for hiding this comment

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

should we call this select_ to be consistent w/ the other metrics?

Help: "number of txs selected for gossip",
}),
targetTxsSum: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "target_txs_sum",
Help: "sum of time spent selecting target for txs gossip",
}),
}
errs := wrappers.Errs{}
errs.Add(
r.Register(m.txsReceived),
r.Register(m.txsGossiped),
r.Register(m.seenTxsReceived),
r.Register(m.selectTxsToGossipCount),
r.Register(m.selectTxsToGossipSum),
r.Register(m.selectedTxsToGossip),
r.Register(m.targetTxsSum),
)
return m, errs.Err
}
5 changes: 5 additions & 0 deletions internal/gossiper/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
)

var (
_ TargetStrategy[Tx] = (*TargetProposers[Tx])(nil)
_ TargetStrategy[Tx] = (*TargetAssigner[Tx])(nil)
)

type TargetStrategy[T any] interface {
Target(ctx context.Context, txs []T) ([]GossipContainer[T], error)
}
Expand Down
Loading
Loading