Skip to content

Commit b50f7bf

Browse files
committed
add command line option to log full error
1 parent 679693e commit b50f7bf

8 files changed

Lines changed: 29 additions & 5 deletions

File tree

cmd/nebula/cmd.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var rootConfig = &config.Root{
3333
LogLevel: 4,
3434
LogFormat: "text",
3535
LogDisableColor: false,
36+
LogErrors: false,
3637
DialTimeout: 10 * time.Second,
3738
MetricsHost: "0.0.0.0",
3839
MetricsPort: 6666,
@@ -99,6 +100,14 @@ func main() {
99100
Destination: &rootConfig.LogDisableColor,
100101
Category: flagCategoryDebugging,
101102
},
103+
&cli.BoolFlag{
104+
Name: "log-errors",
105+
Usage: "Whether to log the full errors",
106+
EnvVars: []string{"NEBULA_LOG_ERRORS"},
107+
Value: rootConfig.LogErrors,
108+
Destination: &rootConfig.LogErrors,
109+
Category: flagCategoryDebugging,
110+
},
102111
&cli.DurationFlag{
103112
Name: "dial-timeout",
104113
Usage: "Global timeout when trying to connect to or dial another peer in the network.",

cmd/nebula/cmd_crawl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ func CrawlAction(c *cli.Context) error {
246246
KeepENR: crawlConfig.KeepENR,
247247
TracerProvider: cfg.Root.TracerProvider,
248248
MeterProvider: cfg.Root.MeterProvider,
249+
LogErrors: cfg.Root.LogErrors,
249250
}
250251

251252
// init the crawl driver
@@ -287,6 +288,7 @@ func CrawlAction(c *cli.Context) error {
287288
AddrTrackType: cfg.AddrTrackType(),
288289
TracerProvider: cfg.Root.TracerProvider,
289290
MeterProvider: cfg.Root.MeterProvider,
291+
LogErrors: cfg.Root.LogErrors,
290292
}
291293

292294
// init the crawl driver

config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type Root struct {
7171
// Specify the log format (text or json)
7272
LogFormat string
7373

74+
// Whether to log the full error string
75+
LogErrors bool
76+
7477
// Whether to have colorized log output
7578
LogDisableColor bool
7679

core/handler_crawl.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type CrawlResult[I PeerInfo[I]] struct {
5959

6060
// Additional properties of that specific peer we have crawled
6161
Properties json.RawMessage
62+
63+
// Debug flag that indicates whether to log the full error string
64+
LogErrors bool
6265
}
6366

6467
func (r CrawlResult[I]) PeerInfo() I {
@@ -74,17 +77,16 @@ func (r CrawlResult[I]) LogEntry() *log.Entry {
7477
})
7578

7679
if r.ConnectError != nil {
77-
if r.ConnectErrorStr == models.NetErrorUnknown {
78-
logEntry = logEntry.WithError(r.ConnectError)
80+
if r.LogErrors || r.ConnectErrorStr == models.NetErrorUnknown {
81+
logEntry = logEntry.WithField("connErr", r.ConnectError)
7982
} else {
8083
logEntry = logEntry.WithField("connErr", r.ConnectErrorStr)
8184
}
8285
}
8386

8487
if r.CrawlError != nil {
85-
// Log and count crawl errors
86-
if r.CrawlErrorStr == models.NetErrorUnknown {
87-
logEntry = logEntry.WithError(r.CrawlError)
88+
if r.LogErrors || r.CrawlErrorStr == models.NetErrorUnknown {
89+
logEntry = logEntry.WithField("crawlErr", r.CrawlError)
8890
} else {
8991
logEntry = logEntry.WithField("crawlErr", r.CrawlErrorStr)
9092
}

discv5/crawler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type CrawlerConfig struct {
2828
DialTimeout time.Duration
2929
AddrDialType config.AddrType
3030
KeepENR bool
31+
LogErrors bool
3132
}
3233

3334
type Crawler struct {
@@ -75,6 +76,7 @@ func (c *Crawler) Work(ctx context.Context, task PeerInfo) (core.CrawlResult[Pee
7576
ConnectStartTime: libp2pResult.ConnectStartTime,
7677
ConnectEndTime: libp2pResult.ConnectEndTime,
7778
Properties: c.PeerProperties(task.Node),
79+
LogErrors: c.cfg.LogErrors,
7880
}
7981

8082
// We've now crawled this peer, so increment

discv5/driver_crawler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,15 @@ type CrawlDriverConfig struct {
120120
KeepENR bool
121121
MeterProvider metric.MeterProvider
122122
TracerProvider trace.TracerProvider
123+
LogErrors bool
123124
}
124125

125126
func (cfg *CrawlDriverConfig) CrawlerConfig() *CrawlerConfig {
126127
return &CrawlerConfig{
127128
DialTimeout: cfg.DialTimeout,
128129
AddrDialType: cfg.AddrDialType,
129130
KeepENR: cfg.KeepENR,
131+
LogErrors: cfg.LogErrors,
130132
}
131133
}
132134

libp2p/crawler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type CrawlerConfig struct {
2222
DialTimeout time.Duration
2323
CheckExposed bool
2424
AddrDialType config.AddrType
25+
LogErrors bool
2526
}
2627

2728
type Crawler struct {
@@ -48,6 +49,7 @@ func (c *Crawler) Work(ctx context.Context, task PeerInfo) (core.CrawlResult[Pee
4849
CrawlerID: c.id,
4950
Info: task,
5051
CrawlStartTime: time.Now(),
52+
LogErrors: c.cfg.LogErrors,
5153
}
5254

5355
// adhere to the addr-dial-type command line flag and only work with

libp2p/driver_crawler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type CrawlDriverConfig struct {
6060
AddrDialType config.AddrType
6161
MeterProvider metric.MeterProvider
6262
TracerProvider trace.TracerProvider
63+
LogErrors bool
6364
}
6465

6566
func (cfg *CrawlDriverConfig) CrawlerConfig() *CrawlerConfig {
@@ -68,6 +69,7 @@ func (cfg *CrawlDriverConfig) CrawlerConfig() *CrawlerConfig {
6869
DialTimeout: cfg.DialTimeout,
6970
CheckExposed: cfg.CheckExposed,
7071
AddrDialType: cfg.AddrDialType,
72+
LogErrors: cfg.LogErrors,
7173
}
7274
}
7375

0 commit comments

Comments
 (0)