Skip to content

Commit

Permalink
dashboard: link to screenshot when profile image rebuild is needed (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Jan 2, 2025
1 parent cb0c1d0 commit 37b7bd0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
9 changes: 8 additions & 1 deletion monitor/src/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use jane_eyre::eyre;
use serde_json::json;

use crate::{
profile::RunnerCounts,
profile::{Profile, RunnerCounts},
runner::{Runner, Runners},
TOML,
};
Expand All @@ -19,12 +19,14 @@ pub struct Dashboard {
#[derive(Clone, Debug, Template)]
#[template(path = "dashboard.html")]
struct DashboardTemplate<'monitor> {
profiles: &'monitor BTreeMap<String, Profile>,
profile_runner_counts: &'monitor BTreeMap<String, RunnerCounts>,
runners: &'monitor Runners,
}

impl Dashboard {
pub fn render(
profiles: &BTreeMap<String, Profile>,
profile_runner_counts: &BTreeMap<String, RunnerCounts>,
runners: &Runners,
) -> eyre::Result<Self> {
Expand All @@ -42,6 +44,7 @@ impl Dashboard {
.collect::<Vec<_>>(),
}))?;
let html = DashboardTemplate {
profiles,
profile_runner_counts,
runners,
}
Expand All @@ -52,6 +55,10 @@ impl Dashboard {
}

impl DashboardTemplate<'_> {
fn profile(&self, key: impl AsRef<str>) -> Option<&Profile> {
self.profiles.get(key.as_ref())
}

fn status(&self, runner: &Runner) -> String {
format!("{:?}", runner.status())
}
Expand Down
6 changes: 5 additions & 1 deletion monitor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,11 @@ fn monitor_thread() -> eyre::Result<()> {

// Update dashboard data, for the API.
if let Ok(mut dashboard) = DASHBOARD.write() {
*dashboard = Some(Dashboard::render(&profile_runner_counts, &runners)?);
*dashboard = Some(Dashboard::render(
&profiles,
&profile_runner_counts,
&runners,
)?);
runners.update_screenshots();
for (_key, profile) in profiles.iter() {
profile.update_screenshot();
Expand Down
5 changes: 5 additions & 0 deletions monitor/templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{% for (key, counts) in profile_runner_counts.iter() %}
<h2>{{ counts.healthy }}/{{ counts.target }} runners for {{ key }}</h2>
<ul>
{% if let Some(profile) = self.profile(key) %}
{% if profile.image_needs_rebuild().unwrap_or(true) %}
<li>image rebuild, <a class="screenshot" href="/profile/{{ key }}/screenshot.png" data-profile-key="{{ key }}">screenshot</a>
{% endif %}
{% endif %}
{% for (id, runner) in runners.by_profile(key) %}
<li>id {{ id }}, <a class="screenshot" href="/runner/{{ id }}/screenshot.png" data-runner-id="{{ id }}">screenshot</a>, status {{ self.status(runner) }}, age {{ self.age(runner)? }}, reserved for {{ self.reserved_since(runner)? }}
<div class="labels">
Expand Down
8 changes: 7 additions & 1 deletion monitor/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@
if (event.target.matches("a.screenshot") && !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
// Force reload with timestamp in fragment (not sent to server)
screenshotImg.src = force_reload(event.target.href);
document.querySelector("#screenshot legend").textContent = event.target.dataset.runnerId;
if (event.target.dataset.profileKey != null) {
document.querySelector("#screenshot legend").textContent = `image rebuild for ${event.target.dataset.profileKey}`;
} else if (event.target.dataset.runnerId != null) {
document.querySelector("#screenshot legend").textContent = `runner id ${event.target.dataset.runnerId}`;
} else {
document.querySelector("#screenshot legend").textContent = `screenshot`;
}
document.querySelector("#screenshot").style.display = "initial";
event.preventDefault();
}
Expand Down

0 comments on commit 37b7bd0

Please sign in to comment.