Skip to content

Commit

Permalink
make bpfink more fail-tolerant during startup & runtime (#46)
Browse files Browse the repository at this point in the history
1. Bad consumer initialization during startup does not lead to crash anymore
2. BPF kernel metrics file bad closing doesn't lead to crash anymore
3. Links to socket files are not monitored anymore
4. Removed some unreachable/redundant code

Co-authored-by: Nick Loginov <>
  • Loading branch information
nloginov authored Nov 26, 2020
1 parent 3aac2f3 commit 5494c22
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
11 changes: 6 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ func (c Configuration) resolvePath(pathFull string) (string, os.FileInfo) {
}
return "", nil
}
if fileInfo.Mode()&os.ModeSocket != 0 {
return "", nil
}

fi = fileInfo
pathFull = linkPath
}
Expand Down Expand Up @@ -409,7 +413,7 @@ func (c Configuration) watcher() (*pkg.Watcher, error) {

for _, consumer := range consumers {
if err := consumer.Init(); err != nil {
logger.Fatal().Err(err).Msg("failed to init consumer")
logger.Error().Err(err).Msg("failed to init consumer")
}
}
return pkg.NewWatcher(func(w *pkg.Watcher) {
Expand Down Expand Up @@ -472,10 +476,7 @@ func run() error {
metrics.RecordByInstalledHost()
// send version metric
metrics.RecordVersion(Version)
err = metrics.RecordBPFMetrics()
if err != nil {
logger.Fatal().Err(err).Msg("error starting bpf metrics")
}
metrics.RecordBPFMetrics()
key := make([]byte, keySize)
if config.Keyfile == "" {
if _, err := io.ReadFull(rand.Reader, key); err != nil {
Expand Down
7 changes: 3 additions & 4 deletions pkg/graphite.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (m *Metrics) RecordByInstalledHost() {
}

// RecordBPFMetrics send metrics for BPF hits and misses per probe
func (m *Metrics) RecordBPFMetrics() error {
func (m *Metrics) RecordBPFMetrics() {
go func() {
for range time.Tick(m.MetricsInterval) {
BPFMetrics, err := m.fetchBPFMetrics()
Expand All @@ -138,7 +138,6 @@ func (m *Metrics) RecordBPFMetrics() error {
}
}
}()
return nil
}

func (m *Metrics) fetchBPFMetrics() (map[string]bpfMetrics, error) {
Expand All @@ -150,7 +149,7 @@ func (m *Metrics) fetchBPFMetrics() (map[string]bpfMetrics, error) {
}
defer func() {
if err := file.Close(); err != nil {
log.Fatal(err)
log.Print(err)
}
}()

Expand Down Expand Up @@ -209,7 +208,7 @@ func (m *Metrics) fetchBPFMetrics() (map[string]bpfMetrics, error) {
}

if err := scanner.Err(); err != nil {
log.Fatal(err)
log.Print(err)
}
return BPFMetrics, nil
}
Expand Down
4 changes: 0 additions & 4 deletions pkg/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ func (w *Watcher) removeInode(key uint64) {
func (w *Watcher) Start() error {
defer func() {
if i := recover(); i != nil {
w.Fatal().Msgf("Panic Caught")
w.Fatal().Msgf("Caught panic: %v", i)
if err := w.Start(); err != nil {
w.Error().Err(err)
}
}
}()
w.Debug().Msgf("consumer Count: %v", len(w.Consumers))
Expand Down

0 comments on commit 5494c22

Please sign in to comment.