Skip to content

Commit 758818a

Browse files
authored
omdb could interpret status of blueprint tasks (#6440)
1 parent 6207e19 commit 758818a

File tree

3 files changed

+69
-4
lines changed

3 files changed

+69
-4
lines changed

dev-tools/omdb/src/bin/omdb/nexus.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,62 @@ fn print_task_details(bgtask: &BackgroundTask, details: &serde_json::Value) {
15561556
}
15571557
}
15581558
}
1559+
} else if name == "blueprint_loader" {
1560+
#[derive(Deserialize)]
1561+
struct BlueprintLoaderStatus {
1562+
target_id: Uuid,
1563+
time_created: DateTime<Utc>,
1564+
status: String,
1565+
enabled: bool,
1566+
}
1567+
1568+
match serde_json::from_value::<BlueprintLoaderStatus>(details.clone()) {
1569+
Err(error) => eprintln!(
1570+
"warning: failed to interpret task details: {:?}: {:?}",
1571+
error, details
1572+
),
1573+
Ok(status) => {
1574+
println!(" target blueprint: {}", status.target_id);
1575+
println!(
1576+
" execution: {}",
1577+
if status.enabled { "enabled" } else { "disabled" }
1578+
);
1579+
println!(
1580+
" created at: {}",
1581+
humantime::format_rfc3339_millis(
1582+
status.time_created.into()
1583+
)
1584+
);
1585+
println!(" status: {}", status.status);
1586+
}
1587+
}
1588+
} else if name == "blueprint_executor" {
1589+
#[derive(Deserialize)]
1590+
struct BlueprintExecutorStatus {
1591+
target_id: Uuid,
1592+
enabled: bool,
1593+
errors: Option<Vec<String>>,
1594+
}
1595+
1596+
match serde_json::from_value::<BlueprintExecutorStatus>(details.clone())
1597+
{
1598+
Err(error) => eprintln!(
1599+
"warning: failed to interpret task details: {:?}: {:?}",
1600+
error, details
1601+
),
1602+
Ok(status) => {
1603+
println!(" target blueprint: {}", status.target_id);
1604+
println!(
1605+
" execution: {}",
1606+
if status.enabled { "enabled" } else { "disabled" }
1607+
);
1608+
let errors = status.errors.as_deref().unwrap_or(&[]);
1609+
println!(" errors: {}", errors.len());
1610+
for (i, e) in errors.iter().enumerate() {
1611+
println!(" error {}: {}", i, e);
1612+
}
1613+
}
1614+
}
15591615
} else {
15601616
println!(
15611617
"warning: unknown background task: {:?} \

nexus/src/app/background/tasks/blueprint_execution.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl BlueprintExecutor {
8383
"target_id" => %blueprint.id);
8484
return json!({
8585
"target_id": blueprint.id.to_string(),
86-
"error": "blueprint disabled"
86+
"enabled": false,
8787
});
8888
}
8989

@@ -111,6 +111,7 @@ impl BlueprintExecutor {
111111

112112
json!({
113113
"target_id": blueprint.id.to_string(),
114+
"enabled": true,
114115
"needs_saga_recovery": needs_saga_recovery,
115116
})
116117
}
@@ -119,6 +120,7 @@ impl BlueprintExecutor {
119120
errors.into_iter().map(|e| format!("{:#}", e)).collect();
120121
json!({
121122
"target_id": blueprint.id.to_string(),
123+
"enabled": true,
122124
"errors": errors
123125
})
124126
}
@@ -316,6 +318,7 @@ mod test {
316318
value,
317319
json!({
318320
"target_id": blueprint_id,
321+
"enabled": true,
319322
"needs_saga_recovery": false,
320323
})
321324
);
@@ -410,6 +413,7 @@ mod test {
410413
value,
411414
json!({
412415
"target_id": blueprint.1.id.to_string(),
416+
"enabled": true,
413417
"needs_saga_recovery": false,
414418
})
415419
);
@@ -427,7 +431,7 @@ mod test {
427431
assert_eq!(
428432
value,
429433
json!({
430-
"error": "blueprint disabled",
434+
"enabled": false,
431435
"target_id": blueprint.1.id.to_string()
432436
})
433437
);

nexus/src/app/background/tasks/blueprint_load.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl BackgroundTask for TargetBlueprintLoader {
7878
};
7979

8080
// Decide what to do with the new blueprint
81+
let enabled = new_bp_target.enabled;
8182
let Some((old_bp_target, old_blueprint)) = self.last.as_deref()
8283
else {
8384
// We've found a target blueprint for the first time.
@@ -97,6 +98,7 @@ impl BackgroundTask for TargetBlueprintLoader {
9798
"time_created": time_created,
9899
"time_found": chrono::Utc::now(),
99100
"status": "first target blueprint",
101+
"enabled": enabled,
100102
});
101103
};
102104

@@ -116,7 +118,8 @@ impl BackgroundTask for TargetBlueprintLoader {
116118
"target_id": target_id,
117119
"time_created": time_created,
118120
"time_found": chrono::Utc::now(),
119-
"status": "target blueprint updated"
121+
"status": "target blueprint updated",
122+
"enabled": enabled,
120123
})
121124
} else {
122125
// The new target id matches the old target id
@@ -159,6 +162,7 @@ impl BackgroundTask for TargetBlueprintLoader {
159162
"time_created": time_created,
160163
"time_found": chrono::Utc::now(),
161164
"status": format!("target blueprint {status}"),
165+
"enabled": enabled,
162166
})
163167
} else {
164168
// We found a new target blueprint that exactly
@@ -173,7 +177,8 @@ impl BackgroundTask for TargetBlueprintLoader {
173177
json!({
174178
"target_id": target_id,
175179
"time_created": time_created,
176-
"status": "target blueprint unchanged"
180+
"status": "target blueprint unchanged",
181+
"enabled": enabled,
177182
})
178183
}
179184
}

0 commit comments

Comments
 (0)