diff --git a/pkg/monitor/cluster/cluster.go b/pkg/monitor/cluster/cluster.go index f6e97f362ac..b4e934bcf53 100644 --- a/pkg/monitor/cluster/cluster.go +++ b/pkg/monitor/cluster/cluster.go @@ -137,18 +137,18 @@ func (mon *Monitor) Monitor(ctx context.Context) (errs []error) { }) } - // If API Server is unreachable, don't need to run the next checks - statusCode, err := mon.getAPIServerPingCode(ctx) - if err != nil || statusCode != http.StatusOK { + // If API is not returning 200, don't need to run the next checks + statusCode, err := mon.emitAPIServerHealthzCode(ctx) + if err != nil { errs = append(errs, err) - friendlyFuncName := steps.FriendlyName(mon.getAPIServerPingCode) + friendlyFuncName := steps.FriendlyName(mon.emitAPIServerHealthzCode) mon.log.Printf("%s: %s", friendlyFuncName, err) mon.emitGauge("monitor.clustererrors", 1, map[string]string{"monitor": friendlyFuncName}) + } + if statusCode != http.StatusOK { return } - for _, f := range []func(context.Context) error{ - mon.emitAPIServerHealthzCode, mon.emitAroOperatorHeartbeat, mon.emitAroOperatorConditions, mon.emitNSGReconciliation, diff --git a/pkg/monitor/cluster/healthz.go b/pkg/monitor/cluster/healthz.go index 9140bc06a14..2cd271aa23a 100644 --- a/pkg/monitor/cluster/healthz.go +++ b/pkg/monitor/cluster/healthz.go @@ -8,7 +8,7 @@ import ( "strconv" ) -func (mon *Monitor) emitAPIServerHealthzCode(ctx context.Context) error { +func (mon *Monitor) emitAPIServerHealthzCode(ctx context.Context) (int, error) { var statusCode int err := mon.cli.Discovery().RESTClient(). Get(). @@ -21,21 +21,5 @@ func (mon *Monitor) emitAPIServerHealthzCode(ctx context.Context) error { "code": strconv.FormatInt(int64(statusCode), 10), }) - return err -} - -func (mon *Monitor) getAPIServerPingCode(ctx context.Context) (int, 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 statusCode, err }