Skip to content

Commit b8ac7ac

Browse files
committed
propolis, aws: diagnostics for propolis factory, target-level overrides
1 parent ecafae5 commit b8ac7ac

File tree

10 files changed

+381
-20
lines changed

10 files changed

+381
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

factory/aws/src/aws.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,16 @@ async fn aws_worker_one(
299299
i.id,
300300
w.id
301301
);
302+
let md = c.metadata(t).map_err(|e| {
303+
anyhow!("building worker metadata: {e}")
304+
})?;
302305
c.client
303306
.factory_worker_associate()
304307
.worker(&w.id)
305308
.body_map(|body| {
306309
body.private(&i.id)
307310
.ip(i.ip.clone())
308-
.metadata(Some(c.metadata(t)))
311+
.metadata(Some(md))
309312
})
310313
.send()
311314
.await?;
@@ -540,6 +543,10 @@ async fn aws_worker_one(
540543
break;
541544
};
542545

546+
let md = c
547+
.metadata(t)
548+
.map_err(|e| anyhow!("building worker metadata: {e}"))?;
549+
543550
let w = c
544551
.client
545552
.factory_worker_create()
@@ -562,9 +569,7 @@ async fn aws_worker_one(
562569
c.client
563570
.factory_worker_associate()
564571
.worker(&w.id)
565-
.body_map(|body| {
566-
body.private(&i.id).ip(i.ip).metadata(Some(c.metadata(t)))
567-
})
572+
.body_map(|body| body.private(&i.id).ip(i.ip).metadata(Some(md)))
568573
.send()
569574
.await?;
570575
}

factory/aws/src/config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use std::collections::HashMap;
66

7+
use buildomat_types::config::ConfigFileDiag;
78
use serde::Deserialize;
89

910
#[derive(Deserialize, Debug)]
@@ -13,6 +14,8 @@ pub(crate) struct ConfigFile {
1314
pub general: ConfigFileGeneral,
1415
pub factory: ConfigFileFactory,
1516
pub target: HashMap<String, ConfigFileAwsTarget>,
17+
#[serde(default)]
18+
pub diag: ConfigFileDiag,
1619
}
1720

1821
#[derive(Deserialize, Debug)]
@@ -33,8 +36,8 @@ pub(crate) struct ConfigFileAwsTarget {
3336
pub instance_type: String,
3437
pub root_size_gb: i32,
3538
pub ami: String,
36-
pub post_job_diagnostic_script: Option<String>,
37-
pub pre_job_diagnostic_script: Option<String>,
39+
#[serde(default)]
40+
pub diag: ConfigFileDiag,
3841
}
3942

4043
#[derive(Deserialize, Debug)]
@@ -49,9 +52,6 @@ pub(crate) struct ConfigFileAws {
4952
pub key: String,
5053
pub security_group: String,
5154
pub limit_total: usize,
52-
pub root_password_hash: Option<String>,
53-
pub root_authorized_keys: Option<String>,
54-
pub dump_to_rpool: Option<u32>,
5555
}
5656

5757
impl ConfigFileAws {

factory/aws/src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,12 @@ impl Central {
6767
fn metadata(
6868
&self,
6969
t: &config::ConfigFileAwsTarget,
70-
) -> metadata::FactoryMetadata {
71-
metadata::FactoryMetadata::V1(metadata::FactoryMetadataV1 {
72-
addresses: Default::default(),
73-
root_password_hash: self.config.aws.root_password_hash.clone(),
74-
root_authorized_keys: self.config.aws.root_authorized_keys.clone(),
75-
dump_to_rpool: self.config.aws.dump_to_rpool,
76-
post_job_diagnostic_script: t.post_job_diagnostic_script.clone(),
77-
pre_job_diagnostic_script: t.pre_job_diagnostic_script.clone(),
78-
})
70+
) -> Result<metadata::FactoryMetadata> {
71+
/*
72+
* Allow the per-target diagnostic configuration to override the base
73+
* diagnostic configuration.
74+
*/
75+
Ok(self.config.diag.apply_overrides(&t.diag)?.build()?)
7976
}
8077
}
8178

factory/propolis/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use std::{collections::HashMap, net::Ipv4Addr, path::PathBuf};
66

77
use anyhow::{bail, Result};
8+
use buildomat_types::config::ConfigFileDiag;
89
use serde::Deserialize;
910

1011
use crate::db::types::InstanceId;
@@ -20,6 +21,9 @@ pub(crate) struct ConfigFile {
2021
pub slots: u32,
2122
pub software_dir: String,
2223
pub nodename: String,
24+
25+
#[serde(default)]
26+
pub diag: ConfigFileDiag,
2327
}
2428

2529
#[derive(Deserialize, Debug, Clone)]
@@ -58,6 +62,9 @@ pub(crate) struct ConfigFileSlotTemplate {
5862
pub(crate) struct ConfigFileTarget {
5963
pub image_path: Option<String>,
6064
pub image_zvol: Option<String>,
65+
66+
#[serde(default)]
67+
pub diag: ConfigFileDiag,
6168
}
6269

6370
impl ConfigFileTarget {

factory/propolis/src/factory.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,31 @@ async fn factory_task_one(log: &Logger, c: &Arc<Central>) -> Result<()> {
6161
log,
6262
"associating instance {id} with worker {}", w.id,
6363
);
64+
65+
/*
66+
* We need to be able to load the target configuration in
67+
* order to get any potential per-target diagnostic
68+
* configuration.
69+
*/
70+
let Some(targ) = c.config.target.get(&i.target) else {
71+
error!(
72+
log,
73+
"instance {id} for worker {} has target {} which \
74+
no longer exists?",
75+
w.id,
76+
i.target,
77+
);
78+
continue;
79+
};
80+
let md = c.metadata(targ)?;
81+
6482
c.client
6583
.factory_worker_associate()
6684
.worker(&w.id)
6785
.body_map(|b| {
6886
b.private(id.to_string())
6987
.ip(Some(t.ip().to_string()))
88+
.metadata(Some(md))
7089
})
7190
.send()
7291
.await?;
@@ -240,7 +259,7 @@ async fn factory_task_one(log: &Logger, c: &Arc<Central>) -> Result<()> {
240259
/*
241260
* Locate target-specific configuration.
242261
*/
243-
if !c.config.target.contains_key(&lease.target) {
262+
let Some(targ) = c.config.target.get(&lease.target) else {
244263
error!(log, "server wants target we do not support: {lease:?}");
245264
return Ok(());
246265
};
@@ -269,11 +288,14 @@ async fn factory_task_one(log: &Logger, c: &Arc<Central>) -> Result<()> {
269288
/*
270289
* Record the instance ID against the worker for which it was created:
271290
*/
291+
let md = c.metadata(targ)?;
272292
c.client
273293
.factory_worker_associate()
274294
.worker(&w.id)
275295
.body_map(|b| {
276-
b.private(instance_id.to_string()).ip(Some(t.ip().to_string()))
296+
b.private(instance_id.to_string())
297+
.ip(Some(t.ip().to_string()))
298+
.metadata(Some(md))
277299
})
278300
.send()
279301
.await?;

factory/propolis/src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{sync::Arc, time::Duration};
66

77
use anyhow::{bail, Context, Result};
88
use buildomat_common::*;
9+
use buildomat_types::metadata;
910
use getopts::Options;
1011
use slog::{info, o, Logger};
1112

@@ -29,6 +30,19 @@ struct Central {
2930
serial: serial::Serial,
3031
}
3132

33+
impl Central {
34+
fn metadata(
35+
&self,
36+
t: &config::ConfigFileTarget,
37+
) -> Result<metadata::FactoryMetadata> {
38+
/*
39+
* Allow the per-target diagnostic configuration to override the base
40+
* diagnostic configuration.
41+
*/
42+
Ok(self.config.diag.apply_overrides(&t.diag)?.build()?)
43+
}
44+
}
45+
3246
/*
3347
* This factory runs on large AMD machines (e.g., 100+ SMT threads) and thus
3448
* ends up with far too many worker threads by default.

types/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license = "MPL-2.0"
88
doctest = false
99

1010
[dependencies]
11+
anyhow = { workspace = true }
1112
schemars = { workspace = true }
1213
serde = { workspace = true }
1314
serde_json = { workspace = true }

0 commit comments

Comments
 (0)