Skip to content

Commit 5019233

Browse files
devin-ai-integration[bot]Convex, Inc.
authored and
Convex, Inc.
committed
Open source load generator (#35772)
## Description Move load_generator, backend_harness, health_check, log_interleaver, performance_stats, big_brain_client, and big_brain_private_api_types from crates_private to crates directory. Update all references in Cargo.toml files to point to the new locations. ## Testing Verified with lint-rust that all license issues are fixed and dependencies are correctly updated. Link to Devin run: https://app.devin.ai/sessions/a55322e782f049d9a8ba5bc89265ecd2 Co-Authored-By: nipunn@convex.dev GitOrigin-RevId: 3d1bd23d9bc79965adf3c42a52c70a16c097a833
1 parent 52beec9 commit 5019233

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4731
-5
lines changed

Cargo.lock

Lines changed: 279 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ aws-smithy-http = "0.60.8"
2222
aws-types = "1.1"
2323
axum = { version = "0.8", features = [ "ws", "original-uri", "macros", "multipart" ] }
2424
axum-extra = { version = "0.10", features = [ "typed-header", "cookie" ] }
25+
backoff = { version = "0.4", features = [ "tokio" ] }
2526
base32 = "0.5.0"
2627
base-62 = { rev = "6f91a3da4b83f20379469835f64195bd52d7b9dd", git = "https://github.com/kryptco/base62.rs" }
2728
base64 = "0.13"
@@ -39,6 +40,7 @@ criterion = "0.5"
3940
crossbeam-channel = "0.5"
4041
csf = "0.1.11"
4142
cstr = "0.2.11"
43+
ctrlc = "3.4"
4244
deadpool-postgres = "^0.14.0"
4345
deno_core = "0.284.0"
4446
deno_core_icudata = "0.73.0"
@@ -76,6 +78,9 @@ hyper-util = { version = "0.1.5", features = [ "server-graceful", "tokio" ] }
7678
proc-macro2 = { version = "1.0" }
7779
imbl = "5.0.0"
7880
itertools = "0.14"
81+
tikv-jemallocator = { version = "0.6", features = [ "profiling", "unprefixed_malloc_on_supported_platforms" ] }
82+
tikv-jemalloc-sys = { version = "0.6", features = [ "profiling", "unprefixed_malloc_on_supported_platforms" ] }
83+
jemalloc_pprof = "0.6"
7984
jsonschema = "0.28"
8085
levenshtein_automata = "0.2.1"
8186
libc = "0.2"
@@ -143,6 +148,7 @@ syn = { version = "2.0", features = [ "full" ] }
143148
tantivy = { git = "https://github.com/get-convex/tantivy", rev = "c745b0977df94bc22fe4fc75db0200a8023f9a2c" }
144149
tantivy-common = { git = "https://github.com/get-convex/tantivy", rev = "c745b0977df94bc22fe4fc75db0200a8023f9a2c" }
145150
tempfile = "3"
151+
textplots = "0.8"
146152
thiserror = "2"
147153
thousands = "0.2.0"
148154
tld = "2.36.0"

crates/backend_harness/Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "backend_harness"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "LicenseRef-FSL-1.1-Apache-2.0"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
anyhow = { workspace = true }
12+
backoff = { workspace = true }
13+
big_brain_client = { path = "../../crates/big_brain_client" }
14+
big_brain_private_api_types = { path = "../../crates/big_brain_private_api_types" }
15+
clap = { workspace = true }
16+
cmd_util = { path = "../../crates/cmd_util" }
17+
crossbeam-channel = { workspace = true }
18+
ctrlc = { workspace = true }
19+
dotenvy = { workspace = true }
20+
futures = { workspace = true }
21+
health_check = { path = "../../crates/health_check" }
22+
home = { workspace = true }
23+
keybroker = { path = "../../crates/keybroker" }
24+
log_interleaver = { path = "../../crates/log_interleaver" }
25+
metrics = { path = "../../crates/metrics" }
26+
serde = { workspace = true }
27+
serde_json = { workspace = true }
28+
tempfile = { workspace = true }
29+
tokio = { workspace = true }
30+
tracing = { workspace = true }
31+
32+
[lints]
33+
workspace = true

crates/backend_harness/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Backend Harness library which provides methods that spin up / spin down a
2+
backend for testing. Supports production backends and local process backends.
3+
4+
Other scripts can use the backend-harness library to manage backend coming up /
5+
going down (eg load tester)
6+
7+
There's a small binary included to show off how to use backend-harness
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#![feature(exit_status_error)]
2+
use std::path::PathBuf;
3+
4+
use backend_harness::{
5+
with_provision,
6+
BackendProvisioner,
7+
ProvisionRequest,
8+
};
9+
use clap::Parser;
10+
use cmd_util::env::config_tool;
11+
use log_interleaver::LogInterleaver;
12+
use metrics::StaticMetricLabel;
13+
use tokio::process::Command;
14+
15+
/// Run the command while a backend is provisioned.
16+
#[derive(Parser, Debug)]
17+
struct Args {
18+
/// Provisioner
19+
#[clap(long, value_enum)]
20+
provisioner: BackendProvisioner,
21+
22+
/// Path under which to provision backend
23+
#[clap(long)]
24+
package_dir: PathBuf,
25+
26+
/// Command to run while backend is provisioned
27+
cmd: Vec<String>,
28+
}
29+
30+
#[tokio::main]
31+
async fn main() -> anyhow::Result<()> {
32+
let _guard = config_tool();
33+
let Args {
34+
provisioner,
35+
package_dir,
36+
cmd,
37+
} = Args::parse();
38+
let logs = LogInterleaver::new();
39+
40+
let (tx, rx) = crossbeam_channel::bounded(1);
41+
if cmd.is_empty() {
42+
ctrlc::set_handler(move || {
43+
tx.send(()).unwrap();
44+
})?;
45+
}
46+
47+
with_provision(
48+
&logs.clone(),
49+
provisioner,
50+
&ProvisionRequest::NewProject,
51+
&package_dir,
52+
StaticMetricLabel::new("load_description", "backend-harness"),
53+
|host, _, _| async move {
54+
if cmd.is_empty() {
55+
println!("Provisioned {host}. Ctrl-C to quit");
56+
rx.recv()?;
57+
println!("Cleaning up {host}");
58+
} else {
59+
Command::new(cmd[0].clone())
60+
.args(&cmd[1..])
61+
.spawn()?
62+
.wait()
63+
.await?
64+
.exit_ok()?;
65+
}
66+
Ok(())
67+
},
68+
)
69+
.await?;
70+
71+
Ok(())
72+
}

crates/backend_harness/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(exit_status_error)]
2+
#![feature(try_blocks)]
3+
4+
/// Harness for spawning/testing a backend for a given package
5+
mod metrics;
6+
mod provision;
7+
8+
pub use provision::{
9+
get_cli_version,
10+
get_configured_deployment_name,
11+
with_provision,
12+
BackendProvisioner,
13+
ProvisionHostCredentials,
14+
ProvisionRequest,
15+
};

crates/backend_harness/src/metrics.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use metrics::{
2+
log_counter_with_labels,
3+
register_convex_counter,
4+
StaticMetricLabel,
5+
};
6+
7+
use crate::ProvisionRequest;
8+
9+
register_convex_counter!(
10+
PROVISIONS_TOTAL,
11+
"Number of provisions",
12+
&["status", "load_description", "provision_type"]
13+
);
14+
pub fn log_provision(
15+
metric_label: StaticMetricLabel,
16+
is_ok: bool,
17+
provision_type: &ProvisionRequest,
18+
) {
19+
let provision_type_label = match provision_type {
20+
ProvisionRequest::ExistingProject { .. } => "existing_project",
21+
ProvisionRequest::NewProject => "new_project",
22+
ProvisionRequest::Preview { .. } => "preview",
23+
};
24+
log_counter_with_labels(
25+
&PROVISIONS_TOTAL,
26+
1,
27+
vec![
28+
metric_label,
29+
StaticMetricLabel::status(is_ok),
30+
StaticMetricLabel::new("provision_type", provision_type_label),
31+
],
32+
);
33+
}
34+
35+
register_convex_counter!(
36+
DEACTIVATES_TOTAL,
37+
"Number of deactivates",
38+
&["status", "load_description"]
39+
);
40+
pub fn log_deactivate(metric_label: StaticMetricLabel, is_ok: bool) {
41+
log_counter_with_labels(
42+
&DEACTIVATES_TOTAL,
43+
1,
44+
vec![metric_label, StaticMetricLabel::status(is_ok)],
45+
);
46+
}
47+
48+
register_convex_counter!(
49+
PUSH_TOTAL,
50+
"Number of pushes",
51+
&["status", "load_description"]
52+
);
53+
pub fn log_push(metric_label: StaticMetricLabel, is_ok: bool) {
54+
log_counter_with_labels(
55+
&PUSH_TOTAL,
56+
1,
57+
vec![metric_label, StaticMetricLabel::status(is_ok)],
58+
);
59+
}

0 commit comments

Comments
 (0)