Display Windows fixed volumes individually in both fleet views
This commit is contained in:
@@ -261,7 +261,6 @@ pub async fn detail(
|
||||
.ok_or(Error(StatusCode::NOT_FOUND, "NOT_FOUND"))?;
|
||||
let hosts = assigned_hosts(&mut tx, tenant, now, std::slice::from_ref(&row)).await?;
|
||||
let mut item = project(&row, now, true, &hosts);
|
||||
item["volumes"] = volumes(&item["inventory"]);
|
||||
item["recent_jobs"] = if p.permits_scope("operations:read")
|
||||
&& crate::permissions::allowed(&mut tx, &p.name, "operations:read").await?
|
||||
{
|
||||
@@ -296,6 +295,14 @@ fn observed<'a>(data: &'a Value, scope: &str) -> &'a Value {
|
||||
}
|
||||
fn volumes(data: &Value) -> Value {
|
||||
let mut items = Vec::new();
|
||||
if let Some(drives) = observed(data, "windows.volumes")["drives"].as_array() {
|
||||
let mut seen = std::collections::HashSet::new();
|
||||
for drive in drives.iter().take(26) {
|
||||
let Some(name) = drive["name"].as_str() else { continue };
|
||||
if !matches!(name.as_bytes(), [b'A'..=b'Z', b':']) || !seen.insert(name) { continue; }
|
||||
items.push(json!({"name":name,"free_bytes":drive["free_bytes"].as_u64(),"total_bytes":drive["total_bytes"].as_u64()}));
|
||||
}
|
||||
}
|
||||
if let Some(rows) = observed(data, "linux.volumes").as_array() {
|
||||
for entry in rows.iter().filter(|entry| entry["quality"] == "valid") {
|
||||
let v = &entry["data"];
|
||||
@@ -552,6 +559,9 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
||||
"source_id":row.get::<Option<String>,_>("source_id"),"quality":if data.is_null(){"unknown"}else{"valid"},
|
||||
"completeness":"partial","health":"unknown"
|
||||
});
|
||||
if full || observed(&data, "windows.volumes").is_object() {
|
||||
item["volumes"] = volumes(&data);
|
||||
}
|
||||
if device_type == Some(DeviceType::Virtual) && row.get::<String, _>("lifecycle") == "current" {
|
||||
let assigned_id: Option<Uuid> = row.get("hypervisor_asset_id");
|
||||
let assigned = assigned_id.and_then(|id| hosts.get(&id));
|
||||
@@ -578,6 +588,18 @@ fn project(row: &PgRow, now: DateTime<Utc>, full: bool, hosts: &HashMap<Uuid, Ho
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn windows_drives_include_other_letters_and_preserve_legacy_system_volume() {
|
||||
let mut snapshot = json!({"root_available_bytes":4,"root_total_bytes":8,"observations":[
|
||||
{"scope":"windows.volumes","quality":"valid","data":{}}]});
|
||||
assert_eq!(volumes(&snapshot)[0]["name"], "Systemvolume");
|
||||
let drives = json!([{"name":"C:","free_bytes":4,"total_bytes":8},
|
||||
{"name":"D:","free_bytes":0,"total_bytes":64},
|
||||
{"name":"E:","free_bytes":null,"total_bytes":null}]);
|
||||
snapshot["observations"][0]["data"]["drives"] = drives.clone();
|
||||
assert_eq!(volumes(&snapshot), drives);
|
||||
}
|
||||
|
||||
fn windows_os(name: &str, build: &str) -> String {
|
||||
let old = json!({"os":name,"observations":[{"scope":"windows.os","quality":"valid",
|
||||
"data":{"product_name":name,"build":build,"display_version":"26H2"}}]});
|
||||
|
||||
@@ -48,7 +48,12 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
|
||||
json: listing(readings.map(([hostname, free, total]) => ({
|
||||
tenant_id: customer.tenant_id, customer_name: customer.name, asset_id: hostname, agent_id: hostname,
|
||||
lifecycle: 'current', status: 'online', hostname, ram_available_bytes: free, ram_total_bytes: total,
|
||||
disk_free_bytes: free, disk_total_bytes: total
|
||||
disk_free_bytes: free, disk_total_bytes: total,
|
||||
...(hostname === 'mostly-free' ? { volumes: [
|
||||
{ name: 'C:', free_bytes: free, total_bytes: total },
|
||||
{ name: 'D:', free_bytes: 0, total_bytes: 64 * gib },
|
||||
{ name: 'E:', free_bytes: null, total_bytes: null }
|
||||
] } : {})
|
||||
})))
|
||||
});
|
||||
return route.fulfill({ status: 404 });
|
||||
@@ -58,7 +63,11 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
|
||||
for (const width of [1280, 900, 390]) {
|
||||
await page.setViewportSize({ width, height: 844 });
|
||||
for (const label of ['RAM', 'Speicher']) {
|
||||
const cell = (host: string) => row(host).locator(`[data-label="${label} belegt / gesamt"]`);
|
||||
const cell = (host: string) => {
|
||||
const column = row(host).locator(`[data-label="${label} belegt / gesamt"]`);
|
||||
return host === 'mostly-free' && label === 'Speicher'
|
||||
? column.locator('.drive-capacity').filter({ hasText: 'C:' }) : column;
|
||||
};
|
||||
for (const [host, used, usedGiB] of [['mostly-free', 25, 4], ['all-used', 100, 16], ['all-free', 0, 0]] as const) {
|
||||
await expect(cell(host)).toContainText(`${usedGiB} / 16 GiB`);
|
||||
await expect(cell(host).locator('.capacity-caption')).toHaveText(`${used} % belegt`);
|
||||
@@ -77,6 +86,12 @@ test('shows used disk and RAM in GiB and draws the occupied share in red on desk
|
||||
await expect(cell(host)).toHaveText(host === 'invalid-total' ? 'Nicht gemeldet' : '– / 16 GiB');
|
||||
}
|
||||
}
|
||||
const drives = row('mostly-free').locator('.drive-capacity');
|
||||
await expect(drives).toHaveCount(3);
|
||||
await expect(drives.nth(1)).toContainText('D: 64 / 64 GiB');
|
||||
await expect(drives.nth(1).getByRole('img', { name: '100 % belegt, 0 % frei' })).toBeVisible();
|
||||
await expect(drives.nth(2)).toHaveText('E: Nicht gemeldet');
|
||||
await expect(drives.nth(2).getByRole('img')).toHaveCount(0);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+14
-1
@@ -119,6 +119,19 @@ function Capacity({ free, total }: {
|
||||
);
|
||||
}
|
||||
|
||||
function DiskCapacity({ device }: { device: RecordValue }) {
|
||||
// Only Windows fleet rows use drive letters. Linux mount inventories remain
|
||||
// available in the detail view, without expanding every fleet row.
|
||||
const drives = Array.isArray(device.volumes)
|
||||
? device.volumes.map(v => record(v)).filter(v => typeof v.name === 'string' && /^[A-Z]:$/.test(v.name)) : [];
|
||||
if (!drives.length) return <Capacity free={device.disk_free_bytes} total={device.disk_total_bytes} />;
|
||||
return <>{drives.map(drive => (
|
||||
<div className="drive-capacity" key={String(drive.name)}>
|
||||
<strong>{String(drive.name)}</strong>{' '}<Capacity free={drive.free_bytes} total={drive.total_bytes} />
|
||||
</div>
|
||||
))}</>;
|
||||
}
|
||||
|
||||
type Target = { customer: string; ids: string[] };
|
||||
type Props = {
|
||||
detailPath: string;
|
||||
@@ -699,7 +712,7 @@ export function Devices({
|
||||
)}
|
||||
</td>
|
||||
<td data-label="Speicher belegt / gesamt" className="capacity-cell">
|
||||
<Capacity free={d.disk_free_bytes} total={d.disk_total_bytes} />
|
||||
<DiskCapacity device={d} />
|
||||
</td>
|
||||
<td data-label="RAM belegt / gesamt" className="capacity-cell" title={measuredAt(d.ram_observed_at)}>
|
||||
<Capacity free={d.ram_available_bytes} total={d.ram_total_bytes} />
|
||||
|
||||
@@ -105,6 +105,7 @@ section.fleet { padding:0; overflow:hidden; }
|
||||
.fleet-table input[type=checkbox] { margin:0; }
|
||||
.host-link { padding:0; background:none; color:var(--accent); text-align:left; font-weight:680; margin:0; overflow-wrap:anywhere; }
|
||||
.fleet-table .capacity-cell { font-variant-numeric:tabular-nums; }
|
||||
.drive-capacity + .drive-capacity { margin-top:8px; }
|
||||
.capacity-track { display:flex; width:min(90px,100%); border-radius:2px; background:#e1ebe6; height:6px; margin-top:6px; overflow:hidden; }
|
||||
.capacity-used { flex:none; background:#c78980; }
|
||||
.capacity-free { flex:1; background:#2e7657; }
|
||||
|
||||
Reference in New Issue
Block a user