Skip to content

Commit

Permalink
use switch statement in handleFetchError
Browse files Browse the repository at this point in the history
  • Loading branch information
pchila committed Nov 12, 2024
1 parent 7595020 commit 50e2336
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions metricbeat/mb/module/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,21 +308,25 @@ func (msw *metricSetWrapper) Test(d testing.Driver) {
}

func (msw *metricSetWrapper) handleFetchError(err error, reporter mb.PushReporterV2) {
if err != nil {
switch {

case errors.As(err, &mb.PartialMetricsError{}):
reporter.Error(err)
if errors.As(err, &mb.PartialMetricsError{}) {
msw.consecutiveErrors = 0
// mark module as running if metrics are partially available and display the error message
msw.module.UpdateStatus(status.Running, fmt.Sprintf("Error fetching data for metricset %s.%s: %v", msw.module.Name(), msw.MetricSet.Name(), err))
} else {
msw.consecutiveErrors++
if msw.failureThreshold > 0 && msw.consecutiveErrors >= msw.failureThreshold {
// mark it as degraded for any other issue encountered
msw.module.UpdateStatus(status.Degraded, fmt.Sprintf("Error fetching data for metricset %s.%s: %v", msw.module.Name(), msw.MetricSet.Name(), err))
}
msw.consecutiveErrors = 0
// mark module as running if metrics are partially available and display the error message
msw.module.UpdateStatus(status.Running, fmt.Sprintf("Error fetching data for metricset %s.%s: %v", msw.module.Name(), msw.MetricSet.Name(), err))
logp.Err("Error fetching data for metricset %s.%s: %s", msw.module.Name(), msw.Name(), err)

case err != nil:
reporter.Error(err)
msw.consecutiveErrors++
if msw.failureThreshold > 0 && msw.consecutiveErrors >= msw.failureThreshold {
// mark it as degraded for any other issue encountered
msw.module.UpdateStatus(status.Degraded, fmt.Sprintf("Error fetching data for metricset %s.%s: %v", msw.module.Name(), msw.MetricSet.Name(), err))
}
logp.Err("Error fetching data for metricset %s.%s: %s", msw.module.Name(), msw.Name(), err)
} else {

default:
msw.consecutiveErrors = 0
msw.module.UpdateStatus(status.Running, "")
}
Expand Down

0 comments on commit 50e2336

Please sign in to comment.