Skip to content

Commit

Permalink
don't panic when reading pcap files
Browse files Browse the repository at this point in the history
When reading pcap files the device is empty, so we can end up with a
metric ID collision. We don't need to record metrics when reading from
pcap files, so don't return a metric collector when this is the case.
  • Loading branch information
efd6 committed Dec 2, 2022
1 parent ef6bc07 commit a07435c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packetbeat/protos/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,13 @@ type inputMetrics struct {
processingTime metrics.Sample // histogram of the elapsed time between packet receipt and publication
}

// newInputMetrics returns an input metric for the TCP processor. If id is empty
// a nil inputMetric is returned.
// newInputMetrics returns an input metric for the TCP processor. If id or
// device is empty a nil inputMetric is returned.
func newInputMetrics(id, device string) *inputMetrics {
if id == "" {
if id == "" || device == "" {
// An empty id signals to not record metrics,
// while an empty device means we are reading
// from a pcap file and no metrics are needed.
return nil
}
reg, unreg := inputmon.NewInputRegistry("tcp", id+"::"+device, nil)
Expand Down
9 changes: 6 additions & 3 deletions packetbeat/protos/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ type inputMetrics struct {
processingTime metrics.Sample // histogram of the elapsed time between packet receipt and publication
}

// newInputMetrics returns an input metric for the UDP processor. If id is empty
// a nil inputMetric is returned.
// newInputMetrics returns an input metric for the UDP processor. If id or
// device is empty a nil inputMetric is returned.
func newInputMetrics(id, device string) *inputMetrics {
if id == "" {
if id == "" || device == "" {
// An empty id signals to not record metrics,
// while an empty device means we are reading
// from a pcap file and no metrics are needed.
return nil
}
reg, unreg := inputmon.NewInputRegistry("udp", id+"::"+device, nil)
Expand Down

0 comments on commit a07435c

Please sign in to comment.