log what arrives: one line per sync and per minute of gossip, every listing at debug; --log-level
A sync with a peer logs one info line when it brought something new (new and updated counts, per region). Listings that arrive by gossip are summed up once a minute. At debug level every stored listing gets a line with its id, region, outcome and the peer it came from. A duplicate is not news and logs nothing. --log-level takes debug, info, warn or error. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
+17
-5
@@ -102,8 +102,12 @@ type Config struct {
|
||||
// it shares a region with, to repair what gossip lost while connected
|
||||
// (default 30 min).
|
||||
AntiEntropyInterval time.Duration
|
||||
Clock func() time.Time // default time.Now
|
||||
Logger *slog.Logger
|
||||
// IntakeSummaryEvery is how often the node logs how many listings reached
|
||||
// it by gossip since the last time (default 1 min; nothing is logged when
|
||||
// none did).
|
||||
IntakeSummaryEvery time.Duration
|
||||
Clock func() time.Time // default time.Now
|
||||
Logger *slog.Logger
|
||||
// Bandwidth, if set, counts the bytes this node sends and receives (the
|
||||
// simulator uses it; a real node leaves it nil).
|
||||
Bandwidth metrics.Reporter
|
||||
@@ -124,6 +128,8 @@ type Node struct {
|
||||
ps *pubsub.PubSub
|
||||
clock func() time.Time
|
||||
log *slog.Logger
|
||||
// gossipIn counts listings that arrived by gossip since the last summary.
|
||||
gossipIn tally
|
||||
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
@@ -166,6 +172,9 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
|
||||
if cfg.AntiEntropyInterval <= 0 {
|
||||
cfg.AntiEntropyInterval = 30 * time.Minute
|
||||
}
|
||||
if cfg.IntakeSummaryEvery <= 0 {
|
||||
cfg.IntakeSummaryEvery = defaultIntakeSummary
|
||||
}
|
||||
if cfg.RelayBootDelay <= 0 {
|
||||
cfg.RelayBootDelay = 10 * time.Second
|
||||
}
|
||||
@@ -301,12 +310,13 @@ func New(ctx context.Context, cfg Config) (*Node, error) {
|
||||
|
||||
// Finding the first peers can take a while (DNS, unreachable servers), so it
|
||||
// does not hold up starting the node.
|
||||
n.wg.Add(5)
|
||||
n.wg.Add(6)
|
||||
go func() {
|
||||
defer n.wg.Done()
|
||||
n.dialBootstrap()
|
||||
n.dialCached()
|
||||
}()
|
||||
go n.summarizeIntake()
|
||||
go n.maintain()
|
||||
go n.redial()
|
||||
go n.antiEntropy()
|
||||
@@ -591,8 +601,10 @@ func (n *Node) subscribeRegion(region string) error {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
switch _, err := n.cfg.Store.Put(n.ctx, l); {
|
||||
case err == nil, errors.Is(err, store.ErrRevoked):
|
||||
switch out, err := n.cfg.Store.Put(n.ctx, l); {
|
||||
case err == nil:
|
||||
n.noteListing(n.ctx, l, out, "gossip", msg.ReceivedFrom)
|
||||
case errors.Is(err, store.ErrRevoked):
|
||||
default:
|
||||
n.log.Warn("store listing", "err", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user