From 6c6282dba19dff87282b98b9378db695786ac8cc Mon Sep 17 00:00:00 2001 From: NathanFlurry Date: Tue, 13 Aug 2024 07:34:45 +0000 Subject: [PATCH] chore: remove servers webhook (#1051) ## Changes --- fern/definition/servers/__package__.yml | 4 - lib/util/core/src/route.rs | 7 +- proto/backend/ds.proto | 3 +- svc/api/servers/src/route/servers.rs | 1 - svc/api/servers/tests/basic.rs | 2 - .../migrations/20240501133910_init.up.sql | 1 - svc/pkg/ds/ops/server-create/src/lib.rs | 3 - .../ds/ops/server-create/tests/integration.rs | 2 +- svc/pkg/ds/ops/server-get/src/lib.rs | 3 - svc/pkg/ds/proto/server-create.proto | 3 +- svc/pkg/ds/worker/src/workers/mod.rs | 154 +++++++++--------- 11 files changed, 84 insertions(+), 99 deletions(-) diff --git a/fern/definition/servers/__package__.yml b/fern/definition/servers/__package__.yml index 6d38a8e7aa..d692c6ceeb 100644 --- a/fern/definition/servers/__package__.yml +++ b/fern/definition/servers/__package__.yml @@ -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 - webhook_url: - docs: >- - A url to send to which events from the server running will be sent - type: optional CreateServerNetworkRequest: properties: diff --git a/lib/util/core/src/route.rs b/lib/util/core/src/route.rs index e6f8ffb764..9d96c9350e 100644 --- a/lib/util/core/src/route.rs +++ b/lib/util/core/src/route.rs @@ -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 { +pub fn backend_endpoint(backend_slug: &str) -> GlobalResult { 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,)) } diff --git a/proto/backend/ds.proto b/proto/backend/ds.proto index ea90ab19a5..72fcfbb238 100644 --- a/proto/backend/ds.proto +++ b/proto/backend/ds.proto @@ -7,6 +7,8 @@ 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; @@ -14,7 +16,6 @@ message Server { map 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; diff --git a/svc/api/servers/src/route/servers.rs b/svc/api/servers/src/route/servers.rs index 8cd9ecd5a1..40e5f1d33d 100644 --- a/svc/api/servers/src/route/servers.rs +++ b/svc/api/servers/src/route/servers.rs @@ -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( diff --git a/svc/api/servers/tests/basic.rs b/svc/api/servers/tests/basic.rs index 67e3846832..84e7a8b4e2 100644 --- a/svc/api/servers/tests/basic.rs +++ b/svc/api/servers/tests/basic.rs @@ -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), @@ -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), diff --git a/svc/pkg/ds/db/servers/migrations/20240501133910_init.up.sql b/svc/pkg/ds/db/servers/migrations/20240501133910_init.up.sql index 9ff3af0560..cb512075ed 100644 --- a/svc/pkg/ds/db/servers/migrations/20240501133910_init.up.sql +++ b/svc/pkg/ds/db/servers/migrations/20240501133910_init.up.sql @@ -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, diff --git a/svc/pkg/ds/ops/server-create/src/lib.rs b/svc/pkg/ds/ops/server-create/src/lib.rs index 7bc1c71c7d..2d1a2d33e9 100644 --- a/svc/pkg/ds/ops/server-create/src/lib.rs +++ b/svc/pkg/ds/ops/server-create/src/lib.rs @@ -192,7 +192,6 @@ pub async fn handle( resources_cpu_millicores, resources_memory_mib, kill_timeout_ms, - webhook_url, create_ts, image_id, args, @@ -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, @@ -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, diff --git a/svc/pkg/ds/ops/server-create/tests/integration.rs b/svc/pkg/ds/ops/server-create/tests/integration.rs index 2abad2d171..bcafd87b06 100644 --- a/svc/pkg/ds/ops/server-create/tests/integration.rs +++ b/svc/pkg/ds/ops/server-create/tests/integration.rs @@ -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(), diff --git a/svc/pkg/ds/ops/server-get/src/lib.rs b/svc/pkg/ds/ops/server-get/src/lib.rs index eac46df97b..cb58dd162c 100644 --- a/svc/pkg/ds/ops/server-get/src/lib.rs +++ b/svc/pkg/ds/ops/server-get/src/lib.rs @@ -13,7 +13,6 @@ struct Server { resources_cpu_millicores: i64, resources_memory_mib: i64, kill_timeout_ms: i64, - webhook_url: Option, create_ts: i64, start_ts: Option, destroy_ts: Option, @@ -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, @@ -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()), diff --git a/svc/pkg/ds/proto/server-create.proto b/svc/pkg/ds/proto/server-create.proto index 7aa0c89dc1..b3497ad531 100644 --- a/svc/pkg/ds/proto/server-create.proto +++ b/svc/pkg/ds/proto/server-create.proto @@ -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 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; diff --git a/svc/pkg/ds/worker/src/workers/mod.rs b/svc/pkg/ds/worker/src/workers/mod.rs index 0e6d4981bf..afb0a7df41 100644 --- a/svc/pkg/ds/worker/src/workers/mod.rs +++ b/svc/pkg/ds/worker/src/workers/mod.rs @@ -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(()) }