Skip to content

Commit

Permalink
fix: fix various bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterPtato authored and NathanFlurry committed Nov 21, 2024
1 parent 4358148 commit 3415ead
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 28 deletions.
6 changes: 1 addition & 5 deletions packages/api/provision/src/route/datacenters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ pub async fn servers(
_watch_index: WatchIndexQuery,
query: ServerFilterQuery,
) -> GlobalResult<models::ProvisionDatacentersGetServersResponse> {
ctx.auth().server()?;

// Find server based on public ip
let servers_res = ctx
.op(cluster::ops::server::list::Input {
filter: cluster::types::Filter {
pool_types: query
.pools
.is_empty()
pool_types: (!query.pools.is_empty())
.then(|| query.pools.into_iter().map(ApiInto::api_into).collect()),
..Default::default()
},
Expand Down
1 change: 1 addition & 0 deletions packages/api/provision/src/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ define_router! {
GET: datacenters::servers(
query: datacenters::ServerFilterQuery,
internal_endpoint: true,
opt_auth: true,
),
},

Expand Down
2 changes: 1 addition & 1 deletion packages/infra/client/isolate-v8-runner/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# v8-isolate-runner
# isolate-v8-runner

This crate is used to run JavaScript on the pegboard servers themselves. This takes care of log shipping, rate
limiting logs, and more.
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/client/manager/src/actor/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ impl Actor {
) -> Result<()> {
let actor_path = ctx.actor_path(self.actor_id);

// TODO: Use schema in v8-isolate-runner (don't import v8-isolate-runner because its fat)
// TODO: Use schema in isolate-v8-runner (don't import isolate-v8-runner because its fat)
let config = json!({
"resources": {
"memory": self.config.resources.memory,
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/client/manager/src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ impl Ctx {

let working_path = self.isolate_runner_path();

// TODO: Use schema in v8-isolate-runner (don't import v8-isolate-runner because its fat)
// TODO: Use schema in isolate-v8-runner (don't import isolate-v8-runner because its fat)
let config = json!({
"actors_path": self.actors_path(),
"fdb_cluster_path": self.fdb_cluster_path(),
Expand Down
8 changes: 7 additions & 1 deletion packages/infra/client/manager/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ pub async fn init_sqlite_schema(pool: &SqlitePool) -> Result<()> {
pub async fn init_fdb_config(config: &Config) -> Result<()> {
let ips = match &config.client.cluster.foundationdb {
FoundationDb::Dynamic { fetch_endpoint } => {
#[derive(Deserialize)]
struct Response {
servers: Vec<Server>,
}

#[derive(Deserialize)]
struct Server {
vlan_ip: Option<Ipv4Addr>,
Expand All @@ -234,8 +239,9 @@ pub async fn init_fdb_config(config: &Config) -> Result<()> {
reqwest::get(fetch_endpoint.clone())
.await?
.error_for_status()?
.json::<Vec<Server>>()
.json::<Response>()
.await?
.servers
.into_iter()
.filter_map(|server| server.vlan_ip)
.map(|vlan_ip| SocketAddr::V4(SocketAddrV4::new(vlan_ip, 4500)))
Expand Down
6 changes: 3 additions & 3 deletions packages/infra/client/manager/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub async fn init_client(gen_path: &Path, working_path: &Path) -> Config {
.await
.unwrap();
tokio::fs::copy(
v8_isolate_runner_path(gen_path),
isolate_v8_runner_path(gen_path),
&isolate_runner_binary_path,
)
.await
Expand Down Expand Up @@ -408,7 +408,7 @@ async fn build_runner(gen_path: &Path, variant: &str) {
.arg(if variant == "container" {
container_runner_path(gen_path)
} else {
v8_isolate_runner_path(gen_path)
isolate_v8_runner_path(gen_path)
})
.status()
.await
Expand Down Expand Up @@ -580,7 +580,7 @@ pub fn container_runner_path(gen_path: &Path) -> PathBuf {
gen_path.join("pegboard-container-runner").to_path_buf()
}

pub fn v8_isolate_runner_path(gen_path: &Path) -> PathBuf {
pub fn isolate_v8_runner_path(gen_path: &Path) -> PathBuf {
gen_path.join("pegboard-isolate-v8-runner").to_path_buf()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn install(
provision_config.container_runner_binary_url.as_ref(),
)
.replace(
"__V8_ISOLATE_BINARY_URL__",
"__ISOLATE_V8_RUNNER_BINARY_URL__",
provision_config.isolate_runner_binary_url.as_ref(),
))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult<String> {
),
});

config_json["sources"]["pegboard_v8_isolate_runner"] = json!({
config_json["sources"]["pegboard_isolate_v8_runner"] = json!({
"type": "file",
"include": ["/var/lib/rivet-client/runner/log"]
});

config_json["transforms"]["pegboard_v8_isolate_runner_add_meta"] = json!({
config_json["transforms"]["pegboard_isolate_v8_runner_add_meta"] = json!({
"type": "remap",
"inputs": ["pegboard_v8_isolate_runner"],
"inputs": ["pegboard_isolate_v8_runner"],
"source": formatdoc!(
r#"
.source = "pegboard_v8_isolate_runner"
.source = "pegboard_isolate_v8_runner"
.client_id = "___SERVER_ID___"
.server_id = "___SERVER_ID___"
Expand Down Expand Up @@ -144,7 +144,7 @@ pub fn configure(config: &Config, pool_type: PoolType) -> GlobalResult<String> {

let inputs = unwrap!(config_json["sinks"]["vector_sink"]["inputs"].as_array_mut());
inputs.push(json!("pegboard_manager_add_meta"));
inputs.push(json!("pegboard_v8_isolate_runner_add_meta"));
inputs.push(json!("pegboard_isolate_v8_runner_add_meta"));
inputs.push(json!("pegboard_container_runner_add_meta"));
}
_ => {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cat << 'EOF' > /etc/rivet-client/config.json
"pegboard_endpoint": "__PEGBOARD_ENDPOINT__",
"foundationdb": {
"dynamic": {
"fetch_endpoint": "__TUNNEL_API_EDGE_API__/provision/datacenters/___DATACENTER_ID___/servers?pool=fdb"
"fetch_endpoint": "__TUNNEL_API_EDGE_API__/provision/datacenters/___DATACENTER_ID___/servers?pools=fdb"
}
}
},
Expand All @@ -28,7 +28,7 @@ cat << 'EOF' > /etc/rivet-client/config.json
},
"reserved_resources": {
"cpu": 0,
"reserved_memory": "__RESERVED_MEMORY__"
"memory": "__RESERVED_MEMORY__"
},
"vector": {
"address": "127.0.0.1:5021"
Expand Down Expand Up @@ -335,7 +335,7 @@ After=network-online.target setup_pegboard_networking.service
ConditionPathExists=/etc/rivet-client/
[Service]
ExecStart=/usr/bin/rivet-client -c /etc/rivet-client/config.json
ExecStart=/usr/local/bin/rivet-client -c /etc/rivet-client/config.json
Restart=always
RestartSec=2
TasksMax=infinity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ EOF

sysctl --system

mkdir -p /etc/rivet-client
mkdir -p /etc/rivet-client /var/lib/rivet-client

curl -Lf -o /usr/local/bin/rivet-client "__PEGBOARD_MANAGER_BINARY_URL__"
chmod +x /usr/local/bin/rivet-client
Expand All @@ -18,6 +18,6 @@ if [ "__FLAVOR__" = "container" ]; then
fi

if [ "__FLAVOR__" = "isolate" ]; then
curl -Lf -o /usr/local/bin/rivet-isolate-v8-runner "__V8_ISOLATE_BINARY_URL__"
curl -Lf -o /usr/local/bin/rivet-isolate-v8-runner "__ISOLATE_V8_RUNNER_BINARY_URL__"
chmod +x /usr/local/bin/rivet-isolate-v8-runner
fi
17 changes: 14 additions & 3 deletions packages/services/cluster/standalone/metrics-publish/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ServerRow {
is_tainted: bool,
}

#[derive(Debug)]
struct Server {
datacenter_id: Uuid,
pool_type: PoolType,
Expand Down Expand Up @@ -122,15 +123,25 @@ fn insert_metrics(dc: &Datacenter, servers: &[Server]) -> GlobalResult<()> {
let datacenter_id = dc.datacenter_id.to_string();
let cluster_id = dc.cluster_id.to_string();

let servers_per_pool = [PoolType::Job, PoolType::Gg, PoolType::Ats, PoolType::Pegboard, PoolType::PegboardIsolate, PoolType::Fdb].into_iter().map(|pool_type| {
let servers_per_pool = [
PoolType::Job,
PoolType::Gg,
PoolType::Ats,
PoolType::Pegboard,
PoolType::PegboardIsolate,
PoolType::Fdb,
]
.into_iter()
.map(|pool_type| {
(
pool_type,
servers_in_dc
.clone()
.filter(|s| matches!(s.pool_type, pool_type))
.filter(|s| &s.pool_type == pool_type)
.collect::<Vec<_>>(),
)
}).collect::<Vec<_>>();
})
.collect::<Vec<_>>();

// Aggregate all states per pool type
for (pool_type, servers) in servers_per_pool {
Expand Down
4 changes: 2 additions & 2 deletions packages/services/ds/src/workers/drain_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async fn worker(ctx: &OperationContext<ds::msg::drain_all::Message>) -> GlobalRe
JOIN db_ds.servers_pegboard AS spb
ON s.server_id = spb.server_id
JOIN db_pegboard.actors AS a
ON spb.pegboard_actor_id = co.actor_id
ON spb.pegboard_actor_id = a.actor_id
WHERE
co.client_id = $1 AND
a.client_id = $1 AND
s.destroy_ts IS NULL
",
pegboard_client_id,
Expand Down

0 comments on commit 3415ead

Please sign in to comment.