Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions database/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ pub trait Connection: Send + Sync {
) -> anyhow::Result<()>;

async fn get_status_page_data(&self) -> anyhow::Result<PartialStatusPageData>;

/// Get all of the configuration for all of the collectors
async fn get_collector_configs(&self) -> anyhow::Result<Vec<CollectorConfig>>;
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -1121,4 +1124,39 @@ mod tests {
})
.await;
}

#[tokio::test]
async fn get_collector_configs() {
run_postgres_test(|ctx| async {
let db = ctx.db_client().connection().await;
let target = Target::X86_64UnknownLinuxGnu;

let benchmark_set_one = BenchmarkSet(0u32);
let collector_name_one = "collector-1";
db.add_collector_config(collector_name_one, target, benchmark_set_one.0, true)
.await
.unwrap();

let benchmark_set_two = BenchmarkSet(1u32);
let collector_name_two = "collector-2";
db.add_collector_config(collector_name_two, target, benchmark_set_two.0, true)
.await
.unwrap();

let collector_configs = db.get_collector_configs().await;
assert!(collector_configs.is_ok());
let collector_configs = collector_configs.unwrap();

assert_eq!(collector_configs[0].name(), collector_name_one);
assert_eq!(collector_configs[0].benchmark_set(), benchmark_set_one);
assert_eq!(collector_configs[0].is_active(), true);

assert_eq!(collector_configs[1].name(), collector_name_two);
assert_eq!(collector_configs[1].benchmark_set(), benchmark_set_two);
assert_eq!(collector_configs[1].is_active(), true);

Ok(ctx)
})
.await;
}
}
33 changes: 33 additions & 0 deletions database/src/pool/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2171,6 +2171,39 @@ where
in_progress,
})
}

async fn get_collector_configs(&self) -> anyhow::Result<Vec<CollectorConfig>> {
let rows = self
.conn()
.query(
"SELECT
name,
target,
benchmark_set,
is_active,
last_heartbeat_at,
date_added
FROM
collector_config;",
&[],
)
.await?;

let mut configs = vec![];
for row in rows {
let config = CollectorConfig {
name: row.get::<_, String>(0),
target: Target::from_str(row.get::<_, &str>(1)).map_err(|e| anyhow::anyhow!(e))?,
benchmark_set: BenchmarkSet(row.get::<_, i32>(2) as u32),
is_active: row.get::<_, bool>(3),
last_heartbeat_at: row.get::<_, DateTime<Utc>>(4),
date_added: row.get::<_, DateTime<Utc>>(5),
};
configs.push(config);
}

Ok(configs)
}
}

fn row_to_benchmark_request(row: &Row) -> BenchmarkRequest {
Expand Down
4 changes: 4 additions & 0 deletions database/src/pool/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,10 @@ impl Connection for SqliteConnection {
async fn get_status_page_data(&self) -> anyhow::Result<PartialStatusPageData> {
no_queue_implementation_abort!()
}

async fn get_collector_configs(&self) -> anyhow::Result<Vec<CollectorConfig>> {
no_queue_implementation_abort!()
}
}

fn parse_artifact_id(ty: &str, sha: &str, date: Option<i64>) -> ArtifactId {
Expand Down
Loading