Use config for pubsub tracing
This commit is contained in:
parent
3a8100fd3c
commit
c7c422abbd
@ -312,6 +312,9 @@ func ConfigFullNode(c interface{}) Option {
|
||||
return Options(
|
||||
ConfigCommon(&cfg.Common),
|
||||
Override(HeadMetricsKey, metrics.SendHeadNotifs(cfg.Metrics.Nickname)),
|
||||
If(cfg.Metrics.PubsubTracing,
|
||||
Override(new(*pubsub.PubSub), lp2p.GossipSub(lp2p.PubsubTracer())),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,8 @@ type Libp2p struct {
|
||||
// // Full Node
|
||||
|
||||
type Metrics struct {
|
||||
Nickname string
|
||||
Nickname string
|
||||
PubsubTracing bool
|
||||
}
|
||||
|
||||
// // Storage Miner
|
||||
|
@ -12,28 +12,34 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
)
|
||||
|
||||
func withTracer(host host.Host, opts []pubsub.Option) []pubsub.Option {
|
||||
pi, err := peer.AddrInfoFromP2pAddr(ma.StringCast("/ip4/147.75.67.199/tcp/4001/p2p/QmTd6UvR47vUidRNZ1ZKXHrAFhqTJAD27rKL9XYghEKgKX"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
type PubsubOpt func(host.Host) pubsub.Option
|
||||
|
||||
tr, err := pubsub.NewRemoteTracer(context.TODO(), host, *pi)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
func PubsubTracer() PubsubOpt {
|
||||
return func(host host.Host) pubsub.Option {
|
||||
pi, err := peer.AddrInfoFromP2pAddr(ma.StringCast("/ip4/147.75.67.199/tcp/4001/p2p/QmTd6UvR47vUidRNZ1ZKXHrAFhqTJAD27rKL9XYghEKgKX"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return append(opts, pubsub.WithEventTracer(tr))
|
||||
tr, err := pubsub.NewRemoteTracer(context.TODO(), host, *pi)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return pubsub.WithEventTracer(tr)
|
||||
}
|
||||
}
|
||||
|
||||
func FloodSub(pubsubOptions ...pubsub.Option) interface{} {
|
||||
func GossipSub(pubsubOptions ...PubsubOpt) interface{} {
|
||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) (service *pubsub.PubSub, err error) {
|
||||
return pubsub.NewFloodSub(helpers.LifecycleCtx(mctx, lc), host, pubsubOptions...)
|
||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, paresOpts(host, pubsubOptions)...)
|
||||
}
|
||||
}
|
||||
|
||||
func GossipSub(pubsubOptions ...pubsub.Option) interface{} {
|
||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host) (service *pubsub.PubSub, err error) {
|
||||
return pubsub.NewGossipSub(helpers.LifecycleCtx(mctx, lc), host, withTracer(host, pubsubOptions)...)
|
||||
func paresOpts(host host.Host, in []PubsubOpt) []pubsub.Option {
|
||||
out := make([]pubsub.Option, len(in))
|
||||
for k, v := range in {
|
||||
out[k] = v(host)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
@ -40,6 +40,12 @@ func ApplyIf(check func(s *Settings) bool, opts ...Option) Option {
|
||||
}
|
||||
}
|
||||
|
||||
func If(b bool, opts ...Option) Option {
|
||||
return ApplyIf(func(s *Settings) bool {
|
||||
return b
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
// Override option changes constructor for a given type
|
||||
func Override(typ, constructor interface{}) Option {
|
||||
return func(s *Settings) error {
|
||||
|
Loading…
Reference in New Issue
Block a user