Skip to content
Merged
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
4 changes: 0 additions & 4 deletions fern/definition/servers/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ types:
This should be set to a safe default, and can be overridden during a
DELETE request if needed.
type: optional<long>
webhook_url:
docs: >-
A url to send to which events from the server running will be sent
type: optional<string>

CreateServerNetworkRequest:
properties:
Expand Down
7 changes: 2 additions & 5 deletions lib/util/core/src/route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ pub fn billing(team_id: Uuid) -> String {
format!("{}/groups/{}/billing", origin_hub(), team_id)
}

pub fn opengb_env(project_name_id: &str, env_name_id: &str) -> GlobalResult<String> {
pub fn backend_endpoint(backend_slug: &str) -> GlobalResult<String> {
let domain_main = unwrap!(domain_main(), "dns not enabled");

Ok(format!(
"https://{}--{}.backend.{}",
project_name_id, env_name_id, domain_main,
))
Ok(format!("https://{}.backend.{}", backend_slug, domain_main,))
}
3 changes: 2 additions & 1 deletion proto/backend/ds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import "proto/backend/captcha.proto";
import "proto/backend/region.proto";

message Server {
reserved 8;

rivet.common.Uuid server_id = 1;
rivet.common.Uuid game_id = 2;
rivet.common.Uuid datacenter_id = 3;
rivet.common.Uuid cluster_id = 4;
map<string, string> tags = 5;
rivet.backend.ds.ServerResources resources = 6;
int64 kill_timeout_ms = 7;
optional string webhook_url = 8;
int64 create_ts = 9;
optional int64 start_ts = 10;
optional int64 destroy_ts = 11;
Expand Down
1 change: 0 additions & 1 deletion svc/api/servers/src/route/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ pub async fn create(
tags: tags,
resources: Some((*body.resources).api_into()),
kill_timeout_ms: body.kill_timeout.unwrap_or_default(),
webhook_url: body.webhook_url,
image_id: Some(body.image.into()),
args: body.arguments.unwrap_or_default(),
network_mode: backend::ds::NetworkMode::api_from(
Expand Down
2 changes: 0 additions & 2 deletions svc/api/servers/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ async fn create_http() -> GlobalResult<()> {
environment: Some(HashMap::new()),
image: ctx.image_id,
kill_timeout: Some(0),
webhook_url: None,
tags: None,
network: Box::new(models::ServersCreateServerNetworkRequest {
mode: Some(models::ServersNetworkMode::Bridge),
Expand Down Expand Up @@ -202,7 +201,6 @@ async fn list_builds_with_tags() -> GlobalResult<()> {
environment: Some(HashMap::new()),
image: ctx.image_id,
kill_timeout: Some(0),
webhook_url: None,
tags: None,
network: Box::new(models::ServersCreateServerNetworkRequest {
mode: Some(models::ServersNetworkMode::Bridge),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ CREATE TABLE servers (
resources_cpu_millicores INT NOT NULL,
resources_memory_mib INT NOT NULL,
kill_timeout_ms INT NOT NULL,
webhook_url STRING,

create_ts INT NOT NULL,
start_ts INT,
Expand Down
3 changes: 0 additions & 3 deletions svc/pkg/ds/ops/server-create/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ pub async fn handle(
resources_cpu_millicores,
resources_memory_mib,
kill_timeout_ms,
webhook_url,
create_ts,
image_id,
args,
Expand Down Expand Up @@ -247,7 +246,6 @@ pub async fn handle(
resources.cpu_millicores,
resources.memory_mib,
ctx.kill_timeout_ms,
ctx.webhook_url.clone(),
create_ts, // 10
unwrap!(ctx.image_id).as_uuid(),
&ctx.args,
Expand Down Expand Up @@ -1400,7 +1398,6 @@ pub async fn handle(
memory_mib: resources.memory_mib,
}),
kill_timeout_ms: ctx.kill_timeout_ms,
webhook_url: ctx.webhook_url.clone(),
create_ts,
start_ts: None,
destroy_ts: None,
Expand Down
2 changes: 1 addition & 1 deletion svc/pkg/ds/ops/server-create/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async fn create(ctx: TestCtx) {
datacenter_id: faker_region.region_id,
resources: Some(proto::backend::ds::ServerResources { cpu_millicores: 100, memory_mib: 200 }),
kill_timeout_ms: 0,
webhook_url: Some("https://rivettest.free.beeceptor.com".to_string()),
// webhook_url: Some("https://rivettest.free.beeceptor.com".to_string()),
tags: vec![(String::from("test"), String::from("123"))]
.into_iter()
.collect(),
Expand Down
3 changes: 0 additions & 3 deletions svc/pkg/ds/ops/server-get/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct Server {
resources_cpu_millicores: i64,
resources_memory_mib: i64,
kill_timeout_ms: i64,
webhook_url: Option<String>,
create_ts: i64,
start_ts: Option<i64>,
destroy_ts: Option<i64>,
Expand Down Expand Up @@ -83,7 +82,6 @@ pub async fn handle(
resources_cpu_millicores,
resources_memory_mib,
kill_timeout_ms,
webhook_url,
create_ts,
start_ts,
destroy_ts,
Expand Down Expand Up @@ -218,7 +216,6 @@ pub async fn handle(
memory_mib: server.resources_memory_mib.try_into()?,
}),
kill_timeout_ms: server.kill_timeout_ms,
webhook_url: server.webhook_url,
args: server.args,
environment,
image_id: Some(server.image_id.into()),
Expand Down
3 changes: 2 additions & 1 deletion svc/pkg/ds/proto/server-create.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import "proto/common.proto";
import "proto/backend/ds.proto";

message Request {
reserved 8;

rivet.common.Uuid game_id = 1;
rivet.common.Uuid datacenter_id = 2;
rivet.common.Uuid cluster_id = 3;
map<string, string> tags = 5;
rivet.backend.ds.ServerResources resources = 6;
int64 kill_timeout_ms = 7;
optional string webhook_url = 8;
rivet.common.Uuid image_id = 9;
repeated string args = 10;
rivet.backend.ds.NetworkMode network_mode = 11;
Expand Down
154 changes: 77 additions & 77 deletions svc/pkg/ds/worker/src/workers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,83 +22,83 @@ pub async fn webhook_call(
alloc_id: String,
) -> GlobalResult<()> {
let ctx = ctx.clone();
tokio::spawn(async move {
// Get the server from the database. If it has a webhook_url, send all
// of the info about the server to it
tracing::error!(?alloc_id, "Checking Alloc ID");

let server_id = match sql_fetch_optional!(
[ctx, (Uuid,)]
"
SELECT
server_id
FROM
db_dynamic_servers.server_nomad
WHERE
nomad_alloc_id = $1
",
alloc_id,
)
.await
{
Ok(Some(row)) => row,
Err(err) => {
tracing::error!(?err, "Could not find server from Nomad alloc");
return;
}
_ => {
tracing::error!("Could not find server from Nomad alloc");
return;
}
}
.0;

let server = match op!([ctx] ds_server_get {
server_ids: vec![server_id.into()],
})
.await
{
Ok(server_res) => match server_res.servers.first() {
Some(server) => server.to_owned(),
None => {
tracing::error!("Could not get server from database");
return;
}
},
Err(err) => {
tracing::error!(?err, "Could not get server from database");
return;
}
};

let client = reqwest::Client::builder()
.timeout(std::time::Duration::from_secs(15))
.build()
.expect("Failed to build client");

let webhook_url = match &server.webhook_url {
Some(url) => url,
None => {
return;
}
};

// Example of a JSON payload
let payload = serde_json::json!({
"message": match rivet_api::models::ServersServer::api_try_from(server.clone()) {
Ok(server) => server,
Err(err) => {
tracing::error!(?err, "Could not convert server to API");
return;
}
},
});

match client.post(webhook_url).json(&payload).send().await {
Ok(response) => tracing::info!(?response, "Sent webhook"),
Err(err) => tracing::warn!(?err, "Issue sending webhook"),
};
});
// tokio::spawn(async move {
// // Get the server from the database. If it has a webhook_url, send all
// // of the info about the server to it
// tracing::error!(?alloc_id, "Checking Alloc ID");
//
// let server_id = match sql_fetch_optional!(
// [ctx, (Uuid,)]
// "
// SELECT
// server_id
// FROM
// db_dynamic_servers.server_nomad
// WHERE
// nomad_alloc_id = $1
// ",
// alloc_id,
// )
// .await
// {
// Ok(Some(row)) => row,
// Err(err) => {
// tracing::error!(?err, "Could not find server from Nomad alloc");
// return;
// }
// _ => {
// tracing::error!("Could not find server from Nomad alloc");
// return;
// }
// }
// .0;
//
// let server = match op!([ctx] ds_server_get {
// server_ids: vec![server_id.into()],
// })
// .await
// {
// Ok(server_res) => match server_res.servers.first() {
// Some(server) => server.to_owned(),
// None => {
// tracing::error!("Could not get server from database");
// return;
// }
// },
// Err(err) => {
// tracing::error!(?err, "Could not get server from database");
// return;
// }
// };
//
// let client = reqwest::Client::builder()
// .timeout(std::time::Duration::from_secs(15))
// .build()
// .expect("Failed to build client");
//
// let webhook_url = match &server.webhook_url {
// Some(url) => url,
// None => {
// return;
// }
// };
//
// // Example of a JSON payload
// let payload = serde_json::json!({
// "message": match rivet_api::models::ServersServer::api_try_from(server.clone()) {
// Ok(server) => server,
// Err(err) => {
// tracing::error!(?err, "Could not convert server to API");
// return;
// }
// },
// });
//
// match client.post(webhook_url).json(&payload).send().await {
// Ok(response) => tracing::info!(?response, "Sent webhook"),
// Err(err) => tracing::warn!(?err, "Issue sending webhook"),
// };
// });

Ok(())
}