Skip to content

Commit a792e46

Browse files
committed
Make get_collector_config return Option<CollectorConfig>
Since the config can be missing.
1 parent 858c710 commit a792e46

File tree

4 files changed

+43
-26
lines changed

4 files changed

+43
-26
lines changed

collector/src/bin/collector.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,8 +1340,9 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
13401340

13411341
// Obtain the configuration and validate that it matches the
13421342
// collector's setup
1343-
let collector_config: database::CollectorConfig =
1344-
rt.block_on(conn.get_collector_config(&collector_name))?;
1343+
let collector_config: database::CollectorConfig = rt
1344+
.block_on(conn.get_collector_config(&collector_name))?
1345+
.unwrap();
13451346

13461347
let collector_target = collector_config.target();
13471348
if collector_target.as_str() != target {

database/src/pool.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,13 @@ pub trait Connection: Send + Sync {
243243
is_active: bool,
244244
) -> anyhow::Result<CollectorConfig>;
245245

246-
/// Get the confiuguration for a collector by the name of the collector
247-
async fn get_collector_config(&self, collector_name: &str) -> anyhow::Result<CollectorConfig>;
246+
/// Get the configuration for a collector by its name.
247+
async fn get_collector_config(
248+
&self,
249+
collector_name: &str,
250+
) -> anyhow::Result<Option<CollectorConfig>>;
248251

249-
/// Dequeue benchmark job
252+
/// Dequeues a single job for the given collector, target and benchmark set.
250253
async fn dequeue_benchmark_job(
251254
&self,
252255
collector_name: &str,
@@ -775,9 +778,9 @@ mod tests {
775778
run_postgres_test(|ctx| async {
776779
let db = ctx.db_client().connection().await;
777780

778-
let collector_config_result = db.get_collector_config("collector-1").await;
781+
let collector_config_result = db.get_collector_config("collector-1").await.unwrap();
779782

780-
assert!(collector_config_result.is_err());
783+
assert!(collector_config_result.is_none());
781784

782785
Ok(ctx)
783786
})
@@ -789,17 +792,20 @@ mod tests {
789792
run_postgres_test(|ctx| async {
790793
let db = ctx.db_client().connection().await;
791794

792-
let insert_config_result = db
795+
let inserted_config = db
793796
.add_collector_config("collector-1", &Target::X86_64UnknownLinuxGnu, 1, true)
794-
.await;
795-
assert!(insert_config_result.is_ok());
797+
.await
798+
.unwrap();
796799

797-
let get_config_result = db.get_collector_config("collector-1").await;
798-
assert!(get_config_result.is_ok());
800+
let config = db
801+
.get_collector_config("collector-1")
802+
.await
803+
.unwrap()
804+
.expect("collector config not found");
799805

800806
// What we entered into the database should be identical to what is
801807
// returned from the database
802-
assert_eq!(insert_config_result.unwrap(), get_config_result.unwrap());
808+
assert_eq!(inserted_config, config);
803809
Ok(ctx)
804810
})
805811
.await;
@@ -880,7 +886,7 @@ mod tests {
880886
);
881887
assert_eq!(
882888
benchmark_job.benchmark_set(),
883-
collector_config.benchmark_set()
889+
*collector_config.benchmark_set()
884890
);
885891
assert_eq!(
886892
benchmark_job.collector_name().unwrap(),

database/src/pool/postgres.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,10 +1783,13 @@ where
17831783
Ok(collector_config)
17841784
}
17851785

1786-
async fn get_collector_config(&self, collector_name: &str) -> anyhow::Result<CollectorConfig> {
1786+
async fn get_collector_config(
1787+
&self,
1788+
collector_name: &str,
1789+
) -> anyhow::Result<Option<CollectorConfig>> {
17871790
let row = self
17881791
.conn()
1789-
.query_one(
1792+
.query_opt(
17901793
"SELECT
17911794
target,
17921795
benchmark_set,
@@ -1801,15 +1804,19 @@ where
18011804
)
18021805
.await?;
18031806

1804-
let collector_config = CollectorConfig {
1805-
name: collector_name.into(),
1806-
target: Target::from_str(&row.get::<_, String>(0)).map_err(|e| anyhow::anyhow!(e))?,
1807-
benchmark_set: BenchmarkSet(row.get::<_, i32>(1) as u32),
1808-
is_active: row.get::<_, bool>(2),
1809-
last_heartbeat_at: row.get::<_, DateTime<Utc>>(3),
1810-
date_added: row.get::<_, DateTime<Utc>>(4),
1811-
};
1812-
Ok(collector_config)
1807+
Ok(row
1808+
.map(|row| {
1809+
anyhow::Ok(CollectorConfig {
1810+
name: collector_name.into(),
1811+
target: Target::from_str(row.get::<_, &str>(0))
1812+
.map_err(|e| anyhow::anyhow!(e))?,
1813+
benchmark_set: BenchmarkSet(row.get::<_, i32>(1) as u32),
1814+
is_active: row.get::<_, bool>(2),
1815+
last_heartbeat_at: row.get::<_, DateTime<Utc>>(3),
1816+
date_added: row.get::<_, DateTime<Utc>>(4),
1817+
})
1818+
})
1819+
.transpose()?)
18131820
}
18141821

18151822
async fn dequeue_benchmark_job(

database/src/pool/sqlite.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,10 @@ impl Connection for SqliteConnection {
13311331
.collect::<Result<_, _>>()?)
13321332
}
13331333

1334-
async fn get_collector_config(&self, _collector_name: &str) -> anyhow::Result<CollectorConfig> {
1334+
async fn get_collector_config(
1335+
&self,
1336+
_collector_name: &str,
1337+
) -> anyhow::Result<Option<CollectorConfig>> {
13351338
no_queue_implementation_abort!()
13361339
}
13371340

0 commit comments

Comments
 (0)