Skip to content

Commit 55388f1

Browse files
authored
Merge pull request #2245 from Jamesbarford/fix/error-table
Add job ID to error table
2 parents 888c0a2 + f2ece09 commit 55388f1

File tree

8 files changed

+153
-38
lines changed

8 files changed

+153
-38
lines changed

collector/src/bin/collector.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ struct SharedBenchmarkConfig {
137137
artifact_id: ArtifactId,
138138
toolchain: Toolchain,
139139
record_duration: bool,
140+
job_id: Option<u32>,
140141
}
141142

142143
fn check_measureme_installed() -> Result<(), String> {
@@ -847,12 +848,14 @@ fn main_result() -> anyhow::Result<i32> {
847848
runtime.group,
848849
&toolchain,
849850
&artifact_id,
851+
None,
850852
))?;
851853

852854
let shared = SharedBenchmarkConfig {
853855
artifact_id,
854856
toolchain,
855857
record_duration: true,
858+
job_id: None,
856859
};
857860
let config = RuntimeBenchmarkConfig::new(
858861
runtime_suite,
@@ -996,6 +999,7 @@ fn main_result() -> anyhow::Result<i32> {
996999
toolchain,
9971000
artifact_id,
9981001
record_duration: true,
1002+
job_id: None,
9991003
};
10001004
let config = CompileBenchmarkConfig {
10011005
benchmarks,
@@ -1048,7 +1052,12 @@ fn main_result() -> anyhow::Result<i32> {
10481052
let toolchain =
10491053
create_toolchain_from_published_version(&tag, &host_target_tuple)?;
10501054
let conn = rt.block_on(pool.connection());
1051-
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))
1055+
rt.block_on(bench_published_artifact(
1056+
conn,
1057+
toolchain,
1058+
&benchmark_dirs,
1059+
None,
1060+
))
10521061
}
10531062
NextArtifact::Commit {
10541063
commit,
@@ -1132,6 +1141,7 @@ fn main_result() -> anyhow::Result<i32> {
11321141
None,
11331142
&toolchain,
11341143
&artifact_id,
1144+
None,
11351145
))?;
11361146

11371147
let runtime_config = RuntimeBenchmarkConfig {
@@ -1143,6 +1153,7 @@ fn main_result() -> anyhow::Result<i32> {
11431153
artifact_id,
11441154
toolchain,
11451155
record_duration: true,
1156+
job_id: None,
11461157
};
11471158

11481159
rt.block_on(run_benchmarks(
@@ -1173,7 +1184,12 @@ fn main_result() -> anyhow::Result<i32> {
11731184
let conn = rt.block_on(pool.connection());
11741185
let toolchain =
11751186
create_toolchain_from_published_version(&toolchain, &host_target_tuple)?;
1176-
rt.block_on(bench_published_artifact(conn, toolchain, &benchmark_dirs))?;
1187+
rt.block_on(bench_published_artifact(
1188+
conn,
1189+
toolchain,
1190+
&benchmark_dirs,
1191+
None,
1192+
))?;
11771193
Ok(0)
11781194
}
11791195

@@ -1495,8 +1511,9 @@ async fn run_job_queue_benchmarks(
14951511
// not with a benchmark.
14961512
conn.record_error(
14971513
artifact_row_id,
1498-
&format!("job:{}", benchmark_job.id()),
1514+
"Job failure",
14991515
&format!("Error while benchmarking job {benchmark_job:?}: {error:?}"),
1516+
Some(benchmark_job.id()),
15001517
)
15011518
.await;
15021519

@@ -1656,6 +1673,7 @@ async fn run_benchmark_job(
16561673
artifact_id,
16571674
toolchain,
16581675
record_duration: false,
1676+
job_id: Some(job.id()),
16591677
};
16601678

16611679
// A failure here means that it was not possible to compile something, that likely won't resolve
@@ -1723,6 +1741,7 @@ async fn create_benchmark_configs(
17231741
None,
17241742
toolchain,
17251743
artifact_id,
1744+
Some(job.id()),
17261745
)
17271746
.await?;
17281747
Some(RuntimeBenchmarkConfig {
@@ -2047,6 +2066,7 @@ async fn load_runtime_benchmarks(
20472066
group: Option<String>,
20482067
toolchain: &Toolchain,
20492068
artifact_id: &ArtifactId,
2069+
job_id: Option<u32>,
20502070
) -> anyhow::Result<BenchmarkSuite> {
20512071
let BenchmarkSuiteCompilation {
20522072
suite,
@@ -2059,19 +2079,20 @@ async fn load_runtime_benchmarks(
20592079
RuntimeCompilationOpts::default(),
20602080
)?;
20612081

2062-
record_runtime_compilation_errors(conn, artifact_id, failed_to_compile).await;
2082+
record_runtime_compilation_errors(conn, artifact_id, failed_to_compile, job_id).await;
20632083
Ok(suite)
20642084
}
20652085

20662086
async fn record_runtime_compilation_errors(
20672087
connection: &mut dyn Connection,
20682088
artifact_id: &ArtifactId,
20692089
errors: HashMap<String, String>,
2090+
job_id: Option<u32>,
20702091
) {
20712092
let artifact_row_number = connection.artifact_id(artifact_id).await;
20722093
for (krate, error) in errors {
20732094
connection
2074-
.record_error(artifact_row_number, &krate, &error)
2095+
.record_error(artifact_row_number, &krate, &error, job_id)
20752096
.await;
20762097
}
20772098
}
@@ -2153,6 +2174,7 @@ async fn run_benchmarks(
21532174
&collector,
21542175
runtime.filter,
21552176
runtime.iterations,
2177+
shared.job_id,
21562178
)
21572179
.await
21582180
.context("Runtime benchmarks failed")
@@ -2175,6 +2197,7 @@ async fn bench_published_artifact(
21752197
mut connection: Box<dyn Connection>,
21762198
toolchain: Toolchain,
21772199
dirs: &BenchmarkDirs<'_>,
2200+
job_id: Option<u32>,
21782201
) -> anyhow::Result<()> {
21792202
let artifact_id = ArtifactId::Tag(toolchain.id.clone());
21802203

@@ -2200,13 +2223,15 @@ async fn bench_published_artifact(
22002223
None,
22012224
&toolchain,
22022225
&artifact_id,
2226+
job_id,
22032227
)
22042228
.await?;
22052229

22062230
let shared = SharedBenchmarkConfig {
22072231
artifact_id,
22082232
toolchain,
22092233
record_duration: true,
2234+
job_id: None,
22102235
};
22112236
run_benchmarks(
22122237
connection.as_mut(),
@@ -2295,6 +2320,7 @@ async fn bench_compile(
22952320
collector.artifact_row_id,
22962321
&benchmark_name.0,
22972322
&format!("{s:?}"),
2323+
shared.job_id,
22982324
)
22992325
.await;
23002326
};

collector/src/runtime/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub async fn bench_runtime(
3535
collector: &CollectorCtx,
3636
filter: RuntimeBenchmarkFilter,
3737
iterations: u32,
38+
job_id: Option<u32>,
3839
) -> anyhow::Result<()> {
3940
let filtered = suite.filtered_benchmark_count(&filter);
4041
println!("Executing {filtered} benchmarks\n");
@@ -89,7 +90,12 @@ pub async fn bench_runtime(
8990
if let Err(error) = result {
9091
eprintln!("collector error: {error:#}");
9192
tx.conn()
92-
.record_error(collector.artifact_row_id, &step_name, &format!("{error:?}"))
93+
.record_error(
94+
collector.artifact_row_id,
95+
&step_name,
96+
&format!("{error:?}"),
97+
job_id,
98+
)
9399
.await;
94100
};
95101

database/schema.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,21 @@ bors_sha pr parent_sha complete requested include exclude runs commi
250250

251251
### error
252252

253-
Records a compilation or runtime error for an artifact and a benchmark.
253+
Records an error within the application namely a;
254+
- compilation
255+
- runtime
256+
- error contextual to a benchmark job
254257

255-
```
256-
sqlite> select * from error limit 1;
257-
aid benchmark error
258-
---------- --- -----
259-
1 syn-1.0.89 Failed to compile...
260-
```
258+
Columns:
259+
260+
* **id** (`BIGINT` / `SERIAL`): Primary key identifier for the error row;
261+
auto increments with each new error.
262+
* **aid** (`INTERGER`): References the artifact id column.
263+
* **context** (`TEXT NOT NULL`): A little message to be able to understand a
264+
bit more about why or where the error occured.
265+
* **message** (`TEXT NOT NULL`): The error message.
266+
* **job_id** (`INTEGER`): A nullable job_id which, if it exists it will inform
267+
us as to which job this error is part of.
261268

262269
## New benchmarking design
263270
We are currently implementing a new design for dispatching benchmarks to collector(s) and storing

database/src/bin/postgres-to-sqlite.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ impl Table for Error {
191191
}
192192

193193
fn postgres_select_statement(&self, since_weeks_ago: Option<u32>) -> String {
194-
let s = "select benchmark, aid, error from ".to_string() + self.name();
194+
let s = "select context, aid, message from ".to_string() + self.name();
195195
with_filter_clause_maybe(s, ARTIFACT_JOIN_AND_WHERE, since_weeks_ago)
196196
}
197197

198198
fn sqlite_insert_statement(&self) -> &'static str {
199-
"insert into error (benchmark, aid, error) VALUES (?, ?, ?)"
199+
"insert into error (context, aid, message) VALUES (?, ?, ?)"
200200
}
201201

202202
fn sqlite_execute_insert(&self, statement: &mut rusqlite::Statement, row: tokio_postgres::Row) {

database/src/bin/sqlite-to-postgres.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ struct Error;
241241

242242
#[derive(Serialize)]
243243
struct ErrorRow<'a> {
244+
id: i32,
244245
aid: i32,
245-
benchmark: &'a str,
246-
error: Nullable<&'a str>,
246+
context: &'a str,
247+
message: Nullable<&'a str>,
247248
}
248249

249250
impl Table for Error {
@@ -252,11 +253,11 @@ impl Table for Error {
252253
}
253254

254255
fn sqlite_attributes() -> &'static str {
255-
"aid, benchmark, error"
256+
"id, aid, context, message, job_id"
256257
}
257258

258259
fn postgres_attributes() -> &'static str {
259-
"aid, benchmark, error"
260+
"id, aid, context, message, job_id"
260261
}
261262

262263
fn postgres_generated_id_attribute() -> Option<&'static str> {
@@ -266,9 +267,10 @@ impl Table for Error {
266267
fn write_postgres_csv_row<W: Write>(writer: &mut csv::Writer<W>, row: &rusqlite::Row) {
267268
writer
268269
.serialize(ErrorRow {
269-
aid: row.get(0).unwrap(),
270-
benchmark: row.get_ref(1).unwrap().as_str().unwrap(),
271-
error: row.get_ref(2).unwrap().try_into().unwrap(),
270+
id: row.get(0).unwrap(),
271+
aid: row.get(1).unwrap(),
272+
context: row.get_ref(2).unwrap().as_str().unwrap(),
273+
message: row.get_ref(3).unwrap().try_into().unwrap(),
272274
})
273275
.unwrap();
274276
}

database/src/pool.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ pub trait Connection: Send + Sync {
7474
profile: Profile,
7575
scenario: Scenario,
7676
);
77-
async fn record_error(&self, artifact: ArtifactIdNumber, krate: &str, error: &str);
77+
async fn record_error(
78+
&self,
79+
artifact: ArtifactIdNumber,
80+
context: &str,
81+
message: &str,
82+
job_id: Option<u32>,
83+
);
7884
async fn record_rustc_crate(
7985
&self,
8086
collection: CollectionId,
@@ -1094,8 +1100,8 @@ mod tests {
10941100

10951101
// Request 1 will have artifact with errors
10961102
let aid1 = ctx.upsert_master_artifact("sha1").await;
1097-
db.record_error(aid1, "crate1", "error1").await;
1098-
db.record_error(aid1, "crate2", "error2").await;
1103+
db.record_error(aid1, "crate1", "error1", None).await;
1104+
db.record_error(aid1, "crate2", "error2", None).await;
10991105

11001106
// Request 2 will have artifact without errors
11011107
let _aid2 = ctx.upsert_master_artifact("sha2").await;

database/src/pool/postgres.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,29 @@ static MIGRATIONS: &[&str] = &[
387387
r#"
388388
ALTER TABLE collector_config ADD COLUMN commit_sha TEXT NULL;
389389
"#,
390+
r#"
391+
CREATE TABLE error_new (
392+
id SERIAL PRIMARY KEY,
393+
aid INTEGER NOT NULL REFERENCES artifact(id) ON DELETE CASCADE ON UPDATE CASCADE,
394+
message TEXT NOT NULL,
395+
context TEXT NOT NULL,
396+
job_id INTEGER
397+
);
398+
399+
INSERT INTO
400+
error_new (aid, message, context)
401+
SELECT
402+
aid,
403+
error,
404+
benchmark
405+
FROM
406+
error;
407+
408+
DROP TABLE error;
409+
ALTER TABLE error_new RENAME TO error;
410+
411+
CREATE INDEX error_artifact_idx ON error(aid);
412+
"#,
390413
];
391414

392415
#[async_trait::async_trait]
@@ -577,7 +600,7 @@ impl PostgresConnection {
577600
.prepare("insert into rustc_compilation (aid, cid, crate, duration) VALUES ($1, $2, $3, $4)")
578601
.await
579602
.unwrap(),
580-
get_error: conn.prepare("select benchmark, error from error where aid = $1").await.unwrap(),
603+
get_error: conn.prepare("select context, message from error where aid = $1").await.unwrap(),
581604
insert_pstat_series: conn.prepare("insert into pstat_series (crate, profile, scenario, backend, target, metric) VALUES ($1, $2, $3, $4, $5, $6) ON CONFLICT DO NOTHING RETURNING id").await.unwrap(),
582605
select_pstat_series: conn.prepare("select id from pstat_series where crate = $1 and profile = $2 and scenario = $3 and backend = $4 and target = $5 and metric = $6").await.unwrap(),
583606
collection_id: conn.prepare("insert into collection (perf_commit) VALUES ($1) returning id").await.unwrap(),
@@ -684,21 +707,21 @@ impl PostgresConnection {
684707
), errors AS (
685708
SELECT
686709
artifacts.name AS tag,
687-
error.benchmark,
688-
error.error
710+
error.context,
711+
error.message
689712
FROM error
690713
-- Use right join to only return errors for selected artifacts
691714
RIGHT JOIN artifacts ON error.aid = artifacts.id
692715
)
693716
-- Select request duplicated for each pair of (benchmark, error)
694717
SELECT
695718
completed.*,
696-
errors.benchmark,
697-
errors.error
719+
errors.context,
720+
errors.message
698721
FROM completed
699722
LEFT JOIN errors ON errors.tag = completed.tag
700723
-- Re-sort the requests, because the original order may be lost
701-
ORDER BY completed.completed_at DESC;
724+
ORDER BY completed.completed_at DESC
702725
")).await.unwrap(),
703726
get_jobs_of_in_progress_benchmark_requests: conn.prepare(&format!("
704727
-- Get in progress requests
@@ -1180,11 +1203,22 @@ where
11801203
ArtifactIdNumber(aid)
11811204
}
11821205

1183-
async fn record_error(&self, artifact: ArtifactIdNumber, krate: &str, error: &str) {
1206+
async fn record_error(
1207+
&self,
1208+
artifact: ArtifactIdNumber,
1209+
context: &str,
1210+
message: &str,
1211+
job_id: Option<u32>,
1212+
) {
11841213
self.conn()
11851214
.execute(
1186-
"insert into error (benchmark, aid, error) VALUES ($1, $2, $3)",
1187-
&[&krate, &(artifact.0 as i32), &error],
1215+
"insert into error (context, aid, message, job_id) VALUES ($1, $2, $3, $4)",
1216+
&[
1217+
&context,
1218+
&(artifact.0 as i32),
1219+
&message,
1220+
&job_id.map(|id| id as i32),
1221+
],
11881222
)
11891223
.await
11901224
.unwrap();

0 commit comments

Comments
 (0)