about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-19 11:41:31 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-19 11:41:31 +0000
commit0f1d324c4a2186dee71e99d35aaaa41c9f7481b6 (patch)
treef1b8eccbdb0db9019e9bd863c15fa839930a03a9
parent6bd032d565233016f2c658840ab2769cf2359fe2 (diff)
downloadgenenetwork4-0f1d324c4a2186dee71e99d35aaaa41c9f7481b6.tar.gz
monitor: say which engine answered, and probe slurmrestd
/compute/gemma now runs the Slurm route first and can answer 200 from the
local wrapper when that route fails, so the HTTP side alone cannot tell the
reader which engine produced a reply, or that the cluster behind the default
engine is dead.

compute-gemma's judge reads the reply's own notes: "engine: slurm (ravanan)"
normally, "engine: fallback: local gemma-wrapper" when the route fell back,
"engine: unstated" for a binary too old to say.  Its depends now name the
route (ravanan + ccwl + slurmrestd) with gemma-wrapper, GEMMA_WRAPPER_CMD and
R as the fallback's requirements, and GEMMA_ENGINE=local is the way to skip
Slurm.  A slurmrestd check in the compute tier probes ravanan's endpoint
directly, reading RAVANAN_SLURM_API_ENDPOINT and RAVANAN_SLURM_JWT on the
monitoring side and skipping when they are unset, so "the cluster is down" is
named before it is waited on.

Runs against the live database and tokens: default tiers were 28 ok, 0
failed, 1 skipped (the listener check, production runs outside the PID
namespace) on :3000 with the previous binary and 29 ok, 0 failed on :3002
with the new build.  The full compute tier on :3002 was 15 ok, 1 failed in
four minutes -- slurmrestd ok (container UP, 1 ms), compute-gemma ok in
3.6 s reporting engine: slurm (ravanan) -- and the failure is
compute-bulklmm: "Package CSV ... is required but does not seem to be
installed", which passes on production with the same env.sh.  That is the
hand-started scratch instance's Julia depot, not the engine switch; a
scratch instance is not a full stand-in for the deployment for the
Julia-backed engines.
-rwxr-xr-xbin/monitor-gn476
1 files changed, 73 insertions, 3 deletions
diff --git a/bin/monitor-gn4 b/bin/monitor-gn4
index f7f0365..962f0f1 100755
--- a/bin/monitor-gn4
+++ b/bin/monitor-gn4
@@ -295,6 +295,36 @@ def has_rows(reply):
     return FAIL, "answered, but no rows"
 
 
+def engine_of(reply):
+    """Which engine answered /compute/gemma, from the reply's own notes.
+
+    Since GEMMA_ENGINE=slurm (the default) that endpoint runs the same
+    per-chromosome workflow /compute/gemma/ravanan does, and only falls back to
+    the in-process gemma-wrapper run when the Slurm route answers 5xx. The
+    notes say which happened -- a ravanan note when the cluster answered, an
+    "Engine: the Slurm route was unavailable ..." note when the wrapper did --
+    so the monitor can report it rather than leaving the reader to guess from
+    the timing.
+    """
+    data = reply.json or {}
+    notes = data.get("notes") or (data.get("meta") or {}).get("notes") or []
+    for note in notes:
+        if not isinstance(note, str):
+            continue
+        if note.startswith("Engine: the Slurm route was unavailable"):
+            return "fallback: local gemma-wrapper"
+        if note.startswith("ravanan"):
+            return "slurm (ravanan)"
+    return "unstated"
+
+
+def has_rows_and_engine(reply):
+    verdict, why = has_rows(reply)
+    if verdict != OK:
+        return verdict, why
+    return OK, "%s, engine: %s" % (why, engine_of(reply))
+
+
 def has_permutation(reply):
     """A qtl2 reply carrying the permutation null: n, thresholds, and values."""
     data = reply.json or {}
@@ -663,10 +693,12 @@ def build_checks(found, tiers):
                           judge=has_clustering,
                           hint="no external tool: pure Rust + MariaDB"))
             add(Check("compute-gemma", "compute", "POST", "/compute/gemma",
-                      "gemma-wrapper + gemma + R (R_LIBS_SITE)",
+                      "slurm route (ravanan + ccwl + slurmrestd), wrapper fallback",
                       body={"group": g, "lmm": 9, "samples": samples},
-                      judge=has_rows, caches=True,
-                      hint="gemma-wrapper, GEMMA_WRAPPER_CMD/GEMMA_DIR"))
+                      judge=has_rows_and_engine, caches=True,
+                      hint="ravanan/ccwl/slurmrestd for the default engine; "
+                           "gemma-wrapper, GEMMA_WRAPPER_CMD/GEMMA_DIR and R for "
+                           "the fallback, and GEMMA_ENGINE=local to skip Slurm"))
             if found.control_trait:
                 # The partial axis: same endpoint, a second trait held constant.
                 # Two traits out of a publish set give a low n, but the path
@@ -990,6 +1022,36 @@ def bnw_matrix():
             variable("V4", [0.4, 5.1, 1.3, 4.8, 2.2])]
 
 
+def slurm_probe():
+    """Ping slurmrestd directly, so a dead cluster is named before it is waited on.
+
+    Every /compute/gemma request now goes through ravanan to Slurm first, so
+    "Slurm is down" is the most likely reason for that endpoint to fall back.
+    The monitor cannot see that from the HTTP side (the fallback answers 200),
+    hence this out-of-band probe: it reads RAVANAN_SLURM_API_ENDPOINT and
+    RAVANAN_SLURM_JWT (the same two variables the server is configured with),
+    and SKIPs when they are not set on the monitoring side.
+    """
+    endpoint = os.environ.get("RAVANAN_SLURM_API_ENDPOINT", "http://127.0.0.1:6820")
+    jwt_file = os.environ.get("RAVANAN_SLURM_JWT", "")
+    if not jwt_file or not os.path.exists(jwt_file):
+        return SKIP, "no RAVANAN_SLURM_JWT on the monitoring side"
+    try:
+        request = urllib.request.Request(endpoint.rstrip("/") + "/slurm/v0.0.41/ping")
+        request.add_header("X-SLURM-USER-TOKEN", open(jwt_file).read().strip())
+        request.add_header("X-SLURM-USER-NAME", os.environ.get("SLURM_USER", "testuser"))
+        with urllib.request.urlopen(request, timeout=10) as answer:
+            data = json.load(answer)
+    except Exception as error:              # noqa: BLE001
+        return FAIL, "%s: %s" % (endpoint, error)
+    pings = data.get("pings") or [{}]
+    first = pings[0]
+    if first.get("pinged") != "UP":
+        return FAIL, "%s: %s" % (endpoint, first.get("pinged"))
+    return OK, "%s -> %s UP (%s us)" % (endpoint, first.get("hostname"),
+                                        first.get("latency"))
+
+
 def report(results, quiet_skips=True):
     width = max([len(r.name) for r in results] + [12])
     print("%-*s %-8s %-7s %7s  %s" % (width, "check", "tier", "verdict",
@@ -1103,6 +1165,14 @@ def main(argv):
         results.append(Result(LocalCheck("listener", "core",
                                          "the listening process, from /proc"),
                               Reply(0, None, 0), verdict, text))
+    if "compute" in tiers:
+        # The default engine's first dependency, probed out of band: the Slurm
+        # route can fail while /compute/gemma still answers 200 from the
+        # fallback, and a monitor should say which of the two happened.
+        verdict, text = slurm_probe()
+        results.append(Result(LocalCheck("slurmrestd", "compute",
+                                         "ravanan's slurm-api endpoint (direct probe)"),
+                              Reply(0, None, 0), verdict, text))
     for check in checks:
         if not token and needs_token(check.path):
             results.append(Result(check, Reply(0, None, 0), SKIP, "no token"))