Skip to content

Commit

Permalink
emit a metric when we fail to gather ping metric
Browse files Browse the repository at this point in the history
  • Loading branch information
s-amann authored and cadenmarchese committed Jul 11, 2023
1 parent ff5b656 commit 6cfcd6e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/monitor/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,14 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
statusCode, err := mon.emitAPIServerHealthzCode(ctx)
if err != nil {
errs = append(errs, err)
friendlyFuncName := steps.FriendlyName(mon.emitAPIServerHealthzCode)
mon.log.Printf("%s: %s", friendlyFuncName, err)
mon.emitGauge("monitor.clustererrors", 1, map[string]string{"monitor": friendlyFuncName})
mon.emitFailureToGatherMetric(steps.FriendlyName(mon.emitAPIServerHealthzCode), err)
}
// If API is not returning 200, fallback to checking ping and short circuit the rest of the checks
if statusCode != http.StatusOK {
err := mon.emitAPIServerPingCode(ctx)
if err != nil {
errs = append(errs, err)
mon.log.Printf("%s: %s", steps.FriendlyName(mon.emitAPIServerPingCode), err)
mon.emitFailureToGatherMetric(steps.FriendlyName(mon.emitAPIServerPingCode), err)
}
return
}
Expand Down Expand Up @@ -181,16 +179,19 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
err = f(ctx)
if err != nil {
errs = append(errs, err)
friendlyFuncName := steps.FriendlyName(f)
mon.log.Printf("%s: %s", friendlyFuncName, err)
mon.emitGauge("monitor.clustererrors", 1, map[string]string{"monitor": friendlyFuncName})
mon.emitFailureToGatherMetric(steps.FriendlyName(f), err)
// keep going
}
}

return
}

func (mon *Monitor) emitFailureToGatherMetric(friendlyFuncName string, err error) {
mon.log.Printf("%s: %s", friendlyFuncName, err)
mon.emitGauge("monitor.clustererrors", 1, map[string]string{"monitor": friendlyFuncName})
}

func (mon *Monitor) emitGauge(m string, value int64, dims map[string]string) {
if dims == nil {
dims = map[string]string{}
Expand Down

0 comments on commit 6cfcd6e

Please sign in to comment.