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

Fix p2p sdk metric labels #2561

Merged
merged 1 commit into from
Dec 29, 2023
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
25 changes: 11 additions & 14 deletions network/p2p/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ var (
_ Accumulator[*testTx] = (*TestAccumulator[*testTx])(nil)

metricLabels = []string{typeLabel}
pushLabels = prometheus.Labels{
typeLabel: pushType,
}
pullLabels = prometheus.Labels{
typeLabel: pullType,
}
)

// Gossiper gossips Gossipables to other nodes
Expand Down Expand Up @@ -131,9 +137,6 @@ func NewPullGossiper[T Gossipable](
client: client,
metrics: metrics,
pollSize: pollSize,
labels: prometheus.Labels{
typeLabel: pullType,
},
}
}

Expand All @@ -144,7 +147,6 @@ type PullGossiper[T Gossipable] struct {
client *p2p.Client
metrics Metrics
pollSize int
labels prometheus.Labels
}

func (p *PullGossiper[_]) Gossip(ctx context.Context) error {
Expand Down Expand Up @@ -223,13 +225,13 @@ func (p *PullGossiper[_]) handleResponse(
}
}

receivedCountMetric, err := p.metrics.receivedCount.GetMetricWith(p.labels)
receivedCountMetric, err := p.metrics.receivedCount.GetMetricWith(pullLabels)
if err != nil {
p.log.Error("failed to get received count metric", zap.Error(err))
return
}

receivedBytesMetric, err := p.metrics.receivedBytes.GetMetricWith(p.labels)
receivedBytesMetric, err := p.metrics.receivedBytes.GetMetricWith(pullLabels)
if err != nil {
p.log.Error("failed to get received bytes metric", zap.Error(err))
return
Expand All @@ -246,10 +248,7 @@ func NewPushGossiper[T Gossipable](marshaller Marshaller[T], client *p2p.Client,
client: client,
metrics: metrics,
targetGossipSize: targetGossipSize,
labels: prometheus.Labels{
typeLabel: pushType,
},
pending: buffer.NewUnboundedDeque[T](0),
pending: buffer.NewUnboundedDeque[T](0),
}
}

Expand All @@ -260,8 +259,6 @@ type PushGossiper[T Gossipable] struct {
metrics Metrics
targetGossipSize int

labels prometheus.Labels

lock sync.Mutex
pending buffer.Deque[T]
}
Expand Down Expand Up @@ -303,12 +300,12 @@ func (p *PushGossiper[T]) Gossip(ctx context.Context) error {
return err
}

sentCountMetric, err := p.metrics.sentCount.GetMetricWith(p.labels)
sentCountMetric, err := p.metrics.sentCount.GetMetricWith(pushLabels)
if err != nil {
return fmt.Errorf("failed to get sent count metric: %w", err)
}

sentBytesMetric, err := p.metrics.sentBytes.GetMetricWith(p.labels)
sentBytesMetric, err := p.metrics.sentBytes.GetMetricWith(pushLabels)
if err != nil {
return fmt.Errorf("failed to get sent bytes metric: %w", err)
}
Expand Down
16 changes: 4 additions & 12 deletions network/p2p/gossip/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (

bloomfilter "github.com/holiman/bloomfilter/v2"

"github.com/prometheus/client_golang/prometheus"

"go.uber.org/zap"

"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -40,9 +38,6 @@ func NewHandler[T Gossipable](
set: set,
metrics: metrics,
targetResponseSize: targetResponseSize,
pullLabels: prometheus.Labels{
typeLabel: pullType,
},
}
}

Expand All @@ -54,9 +49,6 @@ type Handler[T Gossipable] struct {
set Set[T]
metrics Metrics
targetResponseSize int

pullLabels prometheus.Labels
pushLabels prometheus.Labels
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was the source of the bug - only pullLabels was initialized in NewHandler.

}

func (h Handler[T]) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, requestBytes []byte) ([]byte, error) {
Expand Down Expand Up @@ -108,12 +100,12 @@ func (h Handler[T]) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, req
Gossip: gossipBytes,
}

sentCountMetric, err := h.metrics.sentCount.GetMetricWith(h.pullLabels)
sentCountMetric, err := h.metrics.sentCount.GetMetricWith(pullLabels)
if err != nil {
return nil, fmt.Errorf("failed to get sent count metric: %w", err)
}

sentBytesMetric, err := h.metrics.sentBytes.GetMetricWith(h.pullLabels)
sentBytesMetric, err := h.metrics.sentBytes.GetMetricWith(pullLabels)
if err != nil {
return nil, fmt.Errorf("failed to get sent bytes metric: %w", err)
}
Expand Down Expand Up @@ -162,13 +154,13 @@ func (h Handler[_]) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipByte
return
}

receivedCountMetric, err := h.metrics.receivedCount.GetMetricWith(h.pushLabels)
receivedCountMetric, err := h.metrics.receivedCount.GetMetricWith(pushLabels)
if err != nil {
h.log.Error("failed to get received count metric", zap.Error(err))
return
}

receivedBytesMetric, err := h.metrics.receivedBytes.GetMetricWith(h.pushLabels)
receivedBytesMetric, err := h.metrics.receivedBytes.GetMetricWith(pushLabels)
if err != nil {
h.log.Error("failed to get received bytes metric", zap.Error(err))
return
Expand Down
Loading