summaryrefslogtreecommitdiffstats
path: root/src/http
diff options
context:
space:
mode:
Diffstat (limited to 'src/http')
-rw-r--r--src/http/mod.rs5
-rw-r--r--src/http/routes.rs19
2 files changed, 23 insertions, 1 deletions
diff --git a/src/http/mod.rs b/src/http/mod.rs
index 7ca4875..16ff6b1 100644
--- a/src/http/mod.rs
+++ b/src/http/mod.rs
@@ -223,6 +223,11 @@ fn dispatch(state: &State, req: &Req) -> Res {
("GET", ["login"]) => return routes::login_form(state, req),
("POST", ["login"]) => return routes::login(state, req),
("GET", ["healthz"]) => return Res::text(200, "ok\n".into()),
+ // Metrics are counts only — no package names, no versions, no audit
+ // detail — and a Prometheus scraper has no session to present. Serving
+ // them unauthenticated is what makes them scrapeable at all; the bind
+ // address is loopback by default, which is where that is safe.
+ ("GET", ["metrics"]) => return routes::metrics(state),
_ => {}
}
diff --git a/src/http/routes.rs b/src/http/routes.rs
index 26aaa89..9efb90b 100644
--- a/src/http/routes.rs
+++ b/src/http/routes.rs
@@ -6,7 +6,7 @@
use crate::db::{self, builds, model::*, Db};
use crate::review::{approve as ap, candidates, diff, risk};
-use crate::{pipeline, time};
+use crate::{ops, pipeline, time};
use super::auth;
use super::render::*;
@@ -995,6 +995,23 @@ fn audit(state: &State, req: &Req) -> Res {
page_to_res(Audit { page, rows }, 200)
}
+/// `GET /metrics` in Prometheus text exposition format (§12, §15).
+///
+/// Everything here is computed from live state on every scrape. There are no
+/// counters incremented at event sites, because a counter that has to be
+/// maintained by every code path is a counter that quietly drifts the first time
+/// a path is added; a query cannot drift.
+pub fn metrics(state: &State) -> Res {
+ match ops::metrics(&state.cfg, &state.db) {
+ Ok(m) => {
+ let mut res = Res::text(200, m.to_prometheus());
+ res.content_type = "text/plain; version=0.0.4; charset=utf-8".into();
+ res
+ }
+ Err(e) => Res::text(500, format!("metrics unavailable: {e}\n")),
+ }
+}
+
fn settings(state: &State, req: &Req) -> Res {
let page = chrome(state, req, "Settings", "nav_settings");
let rows = db::all_settings(&state.db)