Skip to content

Treat unavailable CPU/load metrics as unhealthy - #202

Open
sksamuel wants to merge 1 commit into
mainfrom
fix/cpu-load-checks-unavailable-sentinel
Open

Treat unavailable CPU/load metrics as unhealthy#202
sksamuel wants to merge 1 commit into
mainfrom
fix/cpu-load-checks-unavailable-sentinel

Conversation

@sksamuel

Copy link
Copy Markdown
Owner

Summary

SystemCpuHealthCheck, ProcessCpuHealthCheck, and SystemLoadHealthCheck all compare a metric against maxLoad ∈ [0,1] without first checking for the sentinel -1.0 that OperatingSystemMXBean returns when the metric is unavailable. Since -1.0 < maxLoad is always true, an unsupported platform silently reports healthy.

Add an explicit guard that reports unhealthy with a clear "metric unavailable" message.

Test plan

  • Existing tests pass
  • Run on a JVM/platform where one of the metrics is unavailable and confirm the check goes unhealthy

🤖 Generated with Claude Code

`OperatingSystemMXBean.processCpuLoad`, `systemCpuLoad`, and
`systemLoadAverage` return a negative value (typically -1.0) when the
metric is not available — for example on some Windows JVMs, or when the
underlying counter has not yet been initialized.

Because `maxLoad` is in the range [0,1], the comparison `-1.0 < maxLoad`
is always true, so all three checks silently reported the broken metric
as **healthy**. Add an explicit negative-value guard that reports
unhealthy with a clear "metric unavailable" message.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant