mirror of
https://github.com/Noratrieb/cargo-bisect-rustc-service.git
synced 2026-01-15 16:45:02 +01:00
Compare commits
14 commits
v0.1-alpha
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 95480163c9 | |||
| 557edb1abd | |||
| 316a40442e | |||
| 13f89b68ef | |||
| 8bd8676314 | |||
| 89f533e357 | |||
| e4d1c77422 | |||
|
|
ae0ea732e9 | ||
| 9a2f8ecdbc | |||
| 4bb561df9b | |||
| 43e63d28d2 | |||
| edcda4d5b5 | |||
| 5d3b9c99d0 | |||
| 80c6b2a8a2 |
11 changed files with 974 additions and 347 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use nix
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,2 +1,2 @@
|
|||
/target
|
||||
bisect.sqlite
|
||||
bisect.sqlite
|
||||
|
|
|
|||
965
Cargo.lock
generated
965
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -9,10 +9,14 @@ edition = "2021"
|
|||
axum = "0.5.16"
|
||||
chrono = { version = "0.4.22", features = ["serde", "clock"] }
|
||||
color-eyre = "0.6.2"
|
||||
metrics = "0.22.3"
|
||||
metrics-exporter-prometheus = { version = "0.14.0", default-features = false, features = ["http-listener"] }
|
||||
once_cell = "1.19.0"
|
||||
rusqlite = { version = "0.28.0", features = ["bundled", "uuid", "chrono"] }
|
||||
serde = { version = "1.0.145", features = ["derive"] }
|
||||
tempdir = "0.3.7"
|
||||
tokio = { version = "1.21.2", features = ["full"] }
|
||||
tower-http = { version = "0.3.4", features = ["trace"] }
|
||||
tracing = "0.1.36"
|
||||
tracing-subscriber = { version = "0.3.15", features = ["env-filter"] }
|
||||
uuid = { version = "1.1.2", features = ["serde", "v4"] }
|
||||
|
|
|
|||
16
Dockerfile
16
Dockerfile
|
|
@ -1,4 +1,4 @@
|
|||
FROM rust as build
|
||||
FROM rust:1.77 as build
|
||||
|
||||
RUN rustup toolchain install nightly
|
||||
RUN rustup default nightly
|
||||
|
|
@ -12,22 +12,30 @@ COPY Cargo.toml Cargo.lock ./
|
|||
RUN mkdir src
|
||||
RUN echo "fn main() {}" > src/main.rs
|
||||
|
||||
RUN cargo build --release -Zsparse-registry
|
||||
RUN cargo build --release
|
||||
|
||||
COPY src ./src
|
||||
COPY index.html index.html
|
||||
|
||||
# now rebuild with the proper main
|
||||
RUN touch src/main.rs
|
||||
RUN cargo build --release -Zsparse-registry
|
||||
RUN cargo build --release
|
||||
|
||||
### RUN
|
||||
FROM rust
|
||||
FROM rust:1.77
|
||||
|
||||
RUN cargo install cargo-bisect-rustc
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# random user
|
||||
RUN useradd --create-home bisector
|
||||
USER bisector
|
||||
|
||||
# this server listens on port 4000 and 4001 (metrics)
|
||||
EXPOSE 4000
|
||||
EXPOSE 4001
|
||||
|
||||
COPY --from=build /app/target/release/cargo-bisect-rustc-service cargo-bisect-rustc-service
|
||||
|
||||
CMD ["/app/cargo-bisect-rustc-service"]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
# cargo-bisect-rustc-service
|
||||
|
||||
**⚠️ this service has been turned off due to lack of usage ⚠️**
|
||||
|
||||
if you think it's useful you should tell me so i can turn it on again
|
||||
|
||||
a small web service that bisects rustc for you
|
||||
|
||||
https://nilstrieb.dev/bisect-rustc
|
||||
https://bisect-rustc.noratrieb.dev
|
||||
|
|
|
|||
207
index.html
207
index.html
|
|
@ -32,12 +32,16 @@
|
|||
<body>
|
||||
<h1>Bisect rustc</h1>
|
||||
|
||||
<textarea
|
||||
id="code"
|
||||
rows="30"
|
||||
cols="80"
|
||||
placeholder="// Rust code goes here..."
|
||||
>
|
||||
<form name="bisect" id="bisect-form">
|
||||
<label for="code">Code</label>
|
||||
<br />
|
||||
<textarea
|
||||
id="code"
|
||||
rows="30"
|
||||
cols="80"
|
||||
placeholder="// Rust code goes here..."
|
||||
name="code"
|
||||
>
|
||||
struct Struct<T>(T);
|
||||
|
||||
impl<T> Struct<T> {
|
||||
|
|
@ -46,25 +50,27 @@ impl<T> Struct<T> {
|
|||
};
|
||||
}
|
||||
</textarea
|
||||
>
|
||||
<br />
|
||||
<label for="start">Start</label>
|
||||
<input id="start" value="2022-01-01" />
|
||||
<label for="end">End (optional)</label>
|
||||
<input id="end" value="2022-06-01" />
|
||||
<label for="kind">Regression Kind</label>
|
||||
<select id="kind">
|
||||
<option>error</option>
|
||||
<option>success</option>
|
||||
<option selected="selected">ice</option>
|
||||
<option>non-ice</option>
|
||||
<option>non-error</option>
|
||||
</select>
|
||||
>
|
||||
<br />
|
||||
<label for="start">Start</label>
|
||||
<input id="start" value="2022-01-01" name="start" />
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<label for="end">End (optional)</label>
|
||||
<input id="end" value="2022-06-01" name="end" />
|
||||
|
||||
<button class="bisect-btn" onclick="bisect()">Bisect!</button>
|
||||
<label for="kind">Regression Kind</label>
|
||||
<select id="kind" name="select">
|
||||
<option>error</option>
|
||||
<option>success</option>
|
||||
<option selected="selected">ice</option>
|
||||
<option>non-ice</option>
|
||||
<option>non-error</option>
|
||||
</select>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
<input type="submit" class="bisect-btn" value="Bisect!" />
|
||||
</form>
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
|
@ -78,17 +84,53 @@ impl<T> Struct<T> {
|
|||
readonly
|
||||
></textarea>
|
||||
|
||||
<div>
|
||||
Made by Nilstrieb
|
||||
<a href="https://github.com/Nilstrieb/cargo-bisect-rustc-service"
|
||||
>Github</a
|
||||
>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const BASE_URL = `${document.location}`;
|
||||
const htmlCode = document.getElementById("code");
|
||||
let BASE_URL = `${document.location}`.split("?")[0];
|
||||
if (!BASE_URL.endsWith("/")) {
|
||||
// ugh, i hate url paths and their subtle interactions with things
|
||||
BASE_URL = `${BASE_URL}/`;
|
||||
}
|
||||
|
||||
// The important HTML elements.
|
||||
const htmlStatus = document.getElementById("status");
|
||||
const htmlResult = document.getElementById("result");
|
||||
const htmlStart = document.getElementById("start");
|
||||
const htmlEnd = document.getElementById("end");
|
||||
const htmlKind = document.getElementById("kind");
|
||||
const htmlCode = document.getElementById("code");
|
||||
|
||||
// A list of all ongoing fetches in fetchAndUpdate.
|
||||
const fetches = [];
|
||||
|
||||
let bisecting = false;
|
||||
|
||||
initialLoad();
|
||||
|
||||
document.getElementById("bisect-form").addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
submitForm();
|
||||
});
|
||||
|
||||
async function initialLoad() {
|
||||
const params = document.location.search;
|
||||
const urlParams = new URLSearchParams(params);
|
||||
const bisection = urlParams.get("bisection");
|
||||
|
||||
if (bisection) {
|
||||
const response = await fetchAndUpdate(bisection);
|
||||
if (!response) {
|
||||
fatal(`Bisection with ID \`${bisection}\` not found.`);
|
||||
return;
|
||||
}
|
||||
code.value = response.code;
|
||||
}
|
||||
}
|
||||
|
||||
// Report a fatal error to the console and screen.
|
||||
function fatal(err, ...extra) {
|
||||
console.error(err, ...(extra || []));
|
||||
htmlStatus.innerHTML = `ERROR: ${err}`;
|
||||
|
|
@ -97,15 +139,30 @@ impl<T> Struct<T> {
|
|||
bisecting = false;
|
||||
}
|
||||
|
||||
async function bisect() {
|
||||
function submitForm() {
|
||||
const form = document.forms.bisect;
|
||||
const options = {
|
||||
code: form.code.value,
|
||||
start: form.start.value?.trim(),
|
||||
end: form.end.value?.trim(),
|
||||
kind: form.kind.value,
|
||||
};
|
||||
console.log("Options", options);
|
||||
|
||||
if (!options.start) {
|
||||
fatal("Must provide a start");
|
||||
return;
|
||||
}
|
||||
|
||||
bisect(options);
|
||||
}
|
||||
|
||||
async function bisect(options) {
|
||||
if (bisecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!htmlStart.value.trim()) {
|
||||
fatal("Must provide a start");
|
||||
return;
|
||||
}
|
||||
fetches.forEach((fetchId) => clearTimeout(fetchId));
|
||||
|
||||
bisecting = true;
|
||||
|
||||
|
|
@ -116,16 +173,14 @@ impl<T> Struct<T> {
|
|||
|
||||
const params = new URLSearchParams();
|
||||
|
||||
params.append("start", htmlStart.value.trim());
|
||||
params.append("kind", htmlKind.value);
|
||||
params.append("start", options.start);
|
||||
params.append("kind", options.kind);
|
||||
|
||||
if (htmlEnd.value.trim()) {
|
||||
params.append("end", htmlEnd.value.trim());
|
||||
if (options.end) {
|
||||
params.append("end", options.end);
|
||||
}
|
||||
|
||||
const body = htmlCode.value;
|
||||
|
||||
console.log("Bisecting", body);
|
||||
const body = options.code;
|
||||
|
||||
let jobId;
|
||||
try {
|
||||
|
|
@ -143,6 +198,11 @@ impl<T> Struct<T> {
|
|||
}
|
||||
const data = await fetched.json();
|
||||
jobId = data?.job_id;
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
urlParams.set("bisection", jobId);
|
||||
window.location.search = urlParams;
|
||||
|
||||
if (!jobId) {
|
||||
fatal("Received invalid response", data);
|
||||
return;
|
||||
|
|
@ -152,38 +212,51 @@ impl<T> Struct<T> {
|
|||
return;
|
||||
}
|
||||
|
||||
async function tryFetch() {
|
||||
let response;
|
||||
try {
|
||||
const fetched = await fetch(`${BASE_URL}bisect/${jobId}`);
|
||||
if (!fetched.ok) {
|
||||
fatal("Failed to fetch", fetched);
|
||||
return;
|
||||
}
|
||||
response = await fetched.json();
|
||||
} catch (e) {
|
||||
fatal(e);
|
||||
fetchAndUpdate(jobId);
|
||||
}
|
||||
|
||||
async function fetchAndUpdate(jobId) {
|
||||
htmlStatus.innerHTML = `Waiting for result, job id=${jobId}`;
|
||||
htmlStatus.classList.remove("hidden");
|
||||
|
||||
let response;
|
||||
try {
|
||||
const fetched = await fetch(`${BASE_URL}bisect/${jobId}`);
|
||||
if (!fetched.ok) {
|
||||
fatal("Failed to fetch bisection.", fetched);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.status.status !== "InProgress") {
|
||||
bisecting = false;
|
||||
console.log(response.status.output);
|
||||
|
||||
htmlStatus.classList.add("hidden");
|
||||
htmlResult.classList.remove("hidden");
|
||||
|
||||
htmlResult.value = response.status.output;
|
||||
htmlStatus.innerHTML = `Bisected job ${jobId}`;
|
||||
} else {
|
||||
console.log("Waiting for bisection", response.status.status);
|
||||
setTimeout(tryFetch, 3000);
|
||||
}
|
||||
response = await fetched.json();
|
||||
} catch (e) {
|
||||
fatal(e);
|
||||
return;
|
||||
}
|
||||
|
||||
tryFetch();
|
||||
if (!response) {
|
||||
console.log("Waiting for bisection", response.status.status);
|
||||
const timeout = setTimeout(() => fetchAndUpdate(jobId), 3000);
|
||||
fetches.push(timeout);
|
||||
return response;
|
||||
}
|
||||
|
||||
htmlStatus.innerHTML = `Waiting for result, job id=${jobId}`;
|
||||
const status = response.status;
|
||||
|
||||
if (response.status.status !== "InProgress") {
|
||||
bisecting = false;
|
||||
console.log(response.status.output);
|
||||
|
||||
htmlStatus.classList.add("hidden");
|
||||
htmlResult.classList.remove("hidden");
|
||||
|
||||
htmlResult.value = response.status.output;
|
||||
htmlStatus.innerHTML = `Bisected job ${jobId}`;
|
||||
} else {
|
||||
console.log("Waiting for bisection", response.status.status);
|
||||
const timeout = setTimeout(() => fetchAndUpdate(jobId), 3000);
|
||||
fetches.push(timeout);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
|
|||
3
shell.nix
Normal file
3
shell.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{ pkgs ? import <nixpkgs> { } }: pkgs.mkShell {
|
||||
packages = with pkgs; [ rustup ];
|
||||
}
|
||||
|
|
@ -107,6 +107,8 @@ pub fn process_job(job: Job, conn: &Connection) -> Result<()> {
|
|||
|
||||
trace!(?bisect, "Finished bisection job");
|
||||
|
||||
crate::toolchain::clean_toolchains()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
41
src/main.rs
41
src/main.rs
|
|
@ -2,9 +2,14 @@
|
|||
|
||||
mod bisect;
|
||||
mod db;
|
||||
mod toolchain;
|
||||
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::{
|
||||
future,
|
||||
sync::{mpsc, Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::bisect::Job;
|
||||
use axum::{
|
||||
extract::{Path, Query},
|
||||
http::StatusCode,
|
||||
|
|
@ -12,16 +17,17 @@ use axum::{
|
|||
routing::{get, post, Router},
|
||||
Extension, Json,
|
||||
};
|
||||
use bisect::Job;
|
||||
use color_eyre::eyre::Context;
|
||||
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
|
||||
use rusqlite::Connection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::env;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::{error, info, metadata::LevelFilter};
|
||||
use tracing_subscriber::EnvFilter;
|
||||
use uuid::Uuid;
|
||||
|
||||
type SendChannel = Arc<Mutex<mpsc::Sender<Job>>>;
|
||||
type SendChannel = Arc<Mutex<mpsc::SyncSender<Job>>>;
|
||||
type Conn = Arc<Mutex<Connection>>;
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -36,7 +42,23 @@ async fn main() -> color_eyre::Result<()> {
|
|||
)
|
||||
.init();
|
||||
|
||||
let (job_queue_send, job_queue_recv) = mpsc::channel(); // FIXME: make this a sync_channel because bounds are cool
|
||||
let metrics_app = async {
|
||||
let prom_handle = setup_metrics();
|
||||
let router: Router =
|
||||
Router::new().route("/metrics", get(move || future::ready(prom_handle.render())));
|
||||
info!("Starting up metrics server on port 4001");
|
||||
axum::Server::bind(&"0.0.0.0:4001".parse().unwrap())
|
||||
.serve(router.into_make_service())
|
||||
.await
|
||||
.wrap_err("failed to start server")
|
||||
};
|
||||
|
||||
tokio::try_join!(metrics_app, main_server())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn main_server() -> color_eyre::Result<()> {
|
||||
let (job_queue_send, job_queue_recv) = mpsc::sync_channel(10);
|
||||
|
||||
let sqlite_db = env::var("SQLITE_DB").unwrap_or_else(|_| "bisect.sqlite".to_string());
|
||||
|
||||
|
|
@ -49,6 +71,8 @@ async fn main() -> color_eyre::Result<()> {
|
|||
|
||||
db::setup(&worker_conn).wrap_err("db setup")?;
|
||||
|
||||
toolchain::clean_toolchains()?;
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(|| async { index_html() }))
|
||||
.route("/bisect/:id", get(get_bisection))
|
||||
|
|
@ -56,11 +80,12 @@ async fn main() -> color_eyre::Result<()> {
|
|||
.route("/bisect", post(do_bisection))
|
||||
// this is really stupid and hacky
|
||||
.layer(Extension(Arc::new(Mutex::new(job_queue_send))))
|
||||
.layer(Extension(main_conn));
|
||||
.layer(Extension(main_conn))
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
std::thread::spawn(|| bisect::bisect_worker(job_queue_recv, worker_conn));
|
||||
|
||||
info!("Starting up server");
|
||||
info!("Starting up server on port 4000");
|
||||
|
||||
axum::Server::bind(&"0.0.0.0:4000".parse().unwrap())
|
||||
.serve(app.into_make_service())
|
||||
|
|
@ -110,6 +135,7 @@ async fn do_bisection(
|
|||
body: String,
|
||||
send_channel: Extension<SendChannel>,
|
||||
) -> impl IntoResponse {
|
||||
metrics::counter!("bisections").increment(1);
|
||||
let job_id = Uuid::new_v4();
|
||||
|
||||
let job = Job::new(job_id, body, options.0);
|
||||
|
|
@ -125,3 +151,6 @@ async fn do_bisection(
|
|||
)),
|
||||
}
|
||||
}
|
||||
pub fn setup_metrics() -> PrometheusHandle {
|
||||
PrometheusBuilder::new().install_recorder().unwrap()
|
||||
}
|
||||
|
|
|
|||
73
src/toolchain.rs
Normal file
73
src/toolchain.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
use std::process::Command;
|
||||
|
||||
use color_eyre::{
|
||||
eyre::{eyre, Context},
|
||||
Result,
|
||||
};
|
||||
use tracing::debug;
|
||||
|
||||
const MAX_BISECTOR_TOOLCHAINS: usize = 15;
|
||||
|
||||
#[tracing::instrument]
|
||||
pub fn clean_toolchains() -> Result<()> {
|
||||
let toolchains = get_toolchains()?;
|
||||
let for_removal = filter_toolchain_for_removal(toolchains);
|
||||
if !for_removal.is_empty() {
|
||||
remove_toolchains(&for_removal)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn filter_toolchain_for_removal(mut toolchains: Vec<String>) -> Vec<String> {
|
||||
toolchains.retain(|toolchain| toolchain.starts_with("bisector-"));
|
||||
|
||||
let amount = toolchains.len();
|
||||
if amount <= MAX_BISECTOR_TOOLCHAINS {
|
||||
debug!(%amount, "No toolchains removed");
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let to_remove = amount - MAX_BISECTOR_TOOLCHAINS;
|
||||
|
||||
toolchains.into_iter().take(to_remove).collect()
|
||||
}
|
||||
|
||||
fn get_toolchains() -> Result<Vec<String>> {
|
||||
let mut command = Command::new("rustup");
|
||||
command.args(["toolchain", "list"]);
|
||||
|
||||
let output = command
|
||||
.output()
|
||||
.wrap_err("running `rustup toolchain list`")?;
|
||||
|
||||
if output.status.success() {
|
||||
let stdout =
|
||||
String::from_utf8(output.stdout).wrap_err("rustup returned non-utf-8 bytes")?;
|
||||
|
||||
let toolchains = stdout.lines().map(ToOwned::to_owned).collect();
|
||||
|
||||
Ok(toolchains)
|
||||
} else {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
|
||||
Err(eyre!("`rustup toolchain list` failed").wrap_err(stderr))
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_toolchains(toolchains: &[String]) -> Result<()> {
|
||||
debug!(?toolchains, "Removing toolchains");
|
||||
let mut command = Command::new("rustup");
|
||||
command.args(["toolchain", "remove"]);
|
||||
command.args(toolchains);
|
||||
|
||||
let output = command
|
||||
.output()
|
||||
.wrap_err("running `rustup toolchain remove`")?;
|
||||
|
||||
if output.status.success() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let stderr = String::from_utf8_lossy(&output.stderr).into_owned();
|
||||
Err(eyre!("`rustup toolchain remove` failed").wrap_err(stderr))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue