Skip to content

Commit

Permalink
check ping if healthz returns non 200
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 27cbefa commit 5a9b293
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/monitor/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
})
}

// If API is not returning 200, don't need to run the next checks
// If API is not returning 200, fallback to checking ping and short circuit the rest of the checks
statusCode, err := mon.emitAPIServerHealthzCode(ctx)
if err != nil {
errs = append(errs, err)
Expand All @@ -146,6 +146,11 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) {
mon.emitGauge("monitor.clustererrors", 1, map[string]string{"monitor": friendlyFuncName})
}
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)
}
return
}
for _, f := range []func(context.Context) error{
Expand Down
16 changes: 16 additions & 0 deletions pkg/monitor/cluster/healthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,19 @@ func (mon *Monitor) emitAPIServerHealthzCode(ctx context.Context) (int, error) {

return statusCode, err
}

func (mon *Monitor) emitAPIServerPingCode(ctx context.Context) error {
var statusCode int
err := mon.cli.Discovery().RESTClient().
Get().
AbsPath("/healthz/ping").
Do(ctx).
StatusCode(&statusCode).
Error()

mon.emitGauge("apiserver.healthz.ping.code", 1, map[string]string{
"code": strconv.FormatInt(int64(statusCode), 10),
})

return err
}

0 comments on commit 5a9b293

Please sign in to comment.