Skip to content

Commit

Permalink
perf(metrics): recover from single collector panic
Browse files Browse the repository at this point in the history
  • Loading branch information
tydra-wang committed Jan 15, 2024
1 parent a6a9cea commit 5156ac2
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/metric/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metric

import (
"errors"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -98,6 +99,11 @@ func (csi CSICollector) Collect(ch chan<- prometheus.Metric) {
}

func execute(name string, c Collector, ch chan<- prometheus.Metric) {
defer func() {
if err := recover(); err != nil {
logrus.Errorf("Collecotor panic occurred: %v. stacktrace: %s", err, string(debug.Stack()))
}
}()
begin := time.Now()
err := c.Update(ch)
duration := time.Since(begin)
Expand Down

0 comments on commit 5156ac2

Please sign in to comment.