Skip to content
Closed
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 68 additions & 56 deletions out/openapi.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/common/api-builder/src/extract.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::anyhow;
use axum::{
extract::{
Request,
Expand Down
1 change: 1 addition & 0 deletions packages/common/api-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub mod actors;
pub mod datacenters;
pub mod namespaces;
pub mod pagination;
pub mod runner_configs;
pub mod runners;
29 changes: 29 additions & 0 deletions packages/common/api-types/src/runner_configs/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::collections::HashMap;

use serde::{Deserialize, Serialize};
use utoipa::IntoParams;

use crate::pagination::Pagination;

#[derive(Debug, Serialize, Deserialize, Clone, IntoParams)]
#[serde(deny_unknown_fields)]
#[into_params(parameter_in = Query)]
pub struct ListQuery {
pub namespace: String,
pub limit: Option<usize>,
pub cursor: Option<String>,
pub variant: Option<rivet_types::keys::namespace::runner_config::RunnerConfigVariant>,
#[serde(default)]
pub runner_names: Option<String>,
}

#[derive(Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct ListPath {}

#[derive(Deserialize, Serialize)]
#[serde(deny_unknown_fields)]
pub struct ListResponse {
pub runner_configs: HashMap<String, rivet_types::runner_configs::RunnerConfig>,
pub pagination: Pagination,
}
1 change: 1 addition & 0 deletions packages/common/api-types/src/runner_configs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod list;
29 changes: 16 additions & 13 deletions packages/common/api-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ where
Q: Serialize + Clone + Send + 'static,
F: Fn(ApiCtx, Q) -> Fut + Clone + Send + 'static,
Fut: Future<Output = Result<I>> + Send,
A: Fn(I, &mut R),
A: Fn(u16, I, &mut R),
R: Default + Send + 'static,
{
let dcs = &ctx.config().topology().datacenters;
Expand All @@ -117,19 +117,22 @@ where
async move {
if dc.datacenter_label == ctx.config().dc_label() {
// Local datacenter - use direct API call
local_handler(ctx, query).await
(dc.datacenter_label, local_handler(ctx, query).await)
} else {
// Remote datacenter - HTTP request
request_remote_datacenter::<I>(
ctx.config(),
(
dc.datacenter_label,
&endpoint,
Method::GET,
headers,
Some(&query),
Option::<&()>::None,
request_remote_datacenter::<I>(
ctx.config(),
dc.datacenter_label,
&endpoint,
Method::GET,
headers,
Some(&query),
Option::<&()>::None,
)
.await,
)
.await
}
}
}))
Expand All @@ -141,11 +144,11 @@ where
let result_count = results.len();
let mut errors = Vec::new();
let mut aggregated = R::default();
for res in results {
for (dc_label, res) in results {
match res {
Ok(data) => aggregator(data, &mut aggregated),
Ok(data) => aggregator(dc_label, data, &mut aggregated),
Err(err) => {
tracing::error!(?err, "failed to request edge dc");
tracing::error!(?dc_label, ?err, "failed to request edge dc");
errors.push(err);
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/common/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rivet-data.workspace = true
rivet-runner-protocol.workspace = true
rivet-util.workspace = true
serde.workspace = true
strum.workspace = true
universaldb.workspace = true
utoipa.workspace = true
vbare.workspace = true
1 change: 1 addition & 0 deletions packages/common/types/src/keys/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod namespace;
pub mod pegboard;
1 change: 1 addition & 0 deletions packages/common/types/src/keys/namespace/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod runner_config;
25 changes: 25 additions & 0 deletions packages/common/types/src/keys/namespace/runner_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use gas::prelude::*;
use utoipa::ToSchema;

#[derive(Clone, Copy, Debug, Serialize, Deserialize, strum::FromRepr, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum RunnerConfigVariant {
Serverless = 0,
}

impl RunnerConfigVariant {
pub fn parse(v: &str) -> Option<Self> {
match v {
"serverless" => Some(RunnerConfigVariant::Serverless),
_ => None,
}
}
}

impl std::fmt::Display for RunnerConfigVariant {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
RunnerConfigVariant::Serverless => write!(f, "serverless"),
}
}
}
1 change: 1 addition & 0 deletions packages/common/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod datacenters;
pub mod keys;
pub mod msgs;
pub mod namespaces;
pub mod runner_configs;
pub mod runners;
61 changes: 0 additions & 61 deletions packages/common/types/src/namespaces.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use gas::prelude::*;
use utoipa::ToSchema;

Expand All @@ -10,62 +8,3 @@ pub struct Namespace {
pub display_name: String,
pub create_ts: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum RunnerConfig {
Serverless {
url: String,
headers: HashMap<String, String>,
/// Seconds.
request_lifespan: u32,
slots_per_runner: u32,
min_runners: u32,
max_runners: u32,
runners_margin: u32,
},
}

impl From<RunnerConfig> for rivet_data::generated::namespace_runner_config_v1::Data {
fn from(value: RunnerConfig) -> Self {
match value {
RunnerConfig::Serverless {
url,
headers,
request_lifespan,
slots_per_runner,
min_runners,
max_runners,
runners_margin,
} => rivet_data::generated::namespace_runner_config_v1::Data::Serverless(
rivet_data::generated::namespace_runner_config_v1::Serverless {
url,
headers: headers.into(),
request_lifespan,
slots_per_runner,
min_runners,
max_runners,
runners_margin,
},
),
}
}
}

impl From<rivet_data::generated::namespace_runner_config_v1::Data> for RunnerConfig {
fn from(value: rivet_data::generated::namespace_runner_config_v1::Data) -> Self {
match value {
rivet_data::generated::namespace_runner_config_v1::Data::Serverless(o) => {
RunnerConfig::Serverless {
url: o.url,
headers: o.headers.into(),
request_lifespan: o.request_lifespan,
slots_per_runner: o.slots_per_runner,
min_runners: o.min_runners,
max_runners: o.max_runners,
runners_margin: o.runners_margin,
}
}
}
}
}
Loading
Loading