From e44d2087c81b77996fbf4bc839a33d53fa2af997 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Tue, 5 Mar 2024 20:44:10 -0500 Subject: [PATCH] feat: you can embed log tables now. --- src/main.rs | 4 ++++ src/routes.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/main.rs b/src/main.rs index 495eedc..cfa31d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,10 @@ async fn main() -> anyhow::Result<()> { "/embed/dash/:dash_idx/graph/:graph_idx", get(routes::graph_embed).with_state(State(config.clone())), ) + .route( + "/embed/dash/:dash_idx/log/:graph_idx", + get(routes::log_embed).with_state(State(config.clone())), + ) .route("/dash/:dash_idx", get(routes::dashboard_direct)) .route("/", get(routes::index).with_state(State(config.clone()))) .layer(TraceLayer::new_for_http()) diff --git a/src/routes.rs b/src/routes.rs index f5106dd..6348728 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -163,6 +163,21 @@ pub async fn graph_ui( graph_component(dash_idx, graph_idx, graph) } +pub async fn log_ui( + State(config): State, + Path((dash_idx, log_idx)): Path<(usize, usize)>, +) -> Markup { + let log = config + .get(dash_idx) + .expect(&format!("No such dashboard {}", dash_idx)) + .logs + .as_ref() + .expect("No graphs in this dashboard") + .get(log_idx) + .expect("No such graph"); + log_component(dash_idx, log_idx, log) +} + pub async fn dash_ui(State(config): State, Path(dash_idx): Path) -> Markup { // TODO(zaphar): Should do better http error reporting here. dash_elements(config, dash_idx) @@ -241,6 +256,23 @@ pub async fn graph_embed( } } +pub async fn log_embed( + State(config): State, + Path((dash_idx, log_idx)): Path<(usize, usize)>, +) -> Markup { + html! { + html { + head { + title { ("Heracles - Prometheus Unshackled") } + } + body { + (graph_lib_prelude()) + (log_ui(State(config.clone()), Path((dash_idx, log_idx))).await) + } + } + } +} + async fn index_html(config: Config, dash_idx: Option) -> Markup { html! { html {