about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6edeed6..765660c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -185,10 +185,14 @@ struct VersionInfo {
 #[gnauth(disabled)]
 async fn version(ctx: Ctx) -> Json<Envelope<VersionInfo>> {
     let git = env!("GN4_GIT_HASH");
-    // No `notes` here: the fields say what they are (see VersionInfo's
-    // doc comments), and /version is the cheapest endpoint for the
-    // envelope test's "notes is an empty array" case.
-    Json(ctx.envelope(VersionInfo {
+    // No `notes` in the ordinary case: the fields say what they are (see
+    // VersionInfo's doc comments), and /version is the cheapest endpoint
+    // for the envelope test's "notes is an empty array" case. The
+    // exception is a database failure in the last few minutes, which is
+    // the one thing a caller cannot otherwise see from here -- `database`
+    // is a *now* probe, so an intermittent fault leaves every data
+    // endpoint failing with nothing on this endpoint to say so.
+    let mut envelope = ctx.envelope(VersionInfo {
         name: "GeneNetwork4",
         short_name: "GN4AI",
         version: 4.0,
@@ -203,5 +207,18 @@ async fn version(ctx: Ctx) -> Json<Envelope<VersionInfo>> {
         } else {
             "unreachable"
         },
-    }))
+    });
+    if let Some(failure) = crate::db::recent_failure(std::time::Duration::from_secs(600)) {
+        let seconds = failure.at.elapsed().as_secs();
+        envelope = envelope.with_note(&format!(
+            "A database request failed {}s ago ({}): {}. `database` is a probe of the \
+             connection pool as well, so `reachable` here does not mean the failure did not \
+             happen -- it means one is not happening now. The pool is rebuilt when a \
+             connection dies, so a single such line is usually recovered from.",
+            seconds,
+            failure.kind.as_str(),
+            failure.detail.chars().take(200).collect::<String>()
+        ));
+    }
+    Json(envelope)
 }