Skip to content

Commit

Permalink
feat(ctl/http/worker): add hello and bye routes
Browse files Browse the repository at this point in the history
  • Loading branch information
lffg committed Jun 20, 2024
1 parent d9d2fec commit 268e5ac
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ctl/src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ pub struct HttpState {

pub fn mk_app(state: HttpState) -> Router {
Router::new()
.route("/worker/push-metrics", post(worker::push_metrics))
.nest(
"/worker",
Router::new()
.route("/hello", post(worker::hello))
.route("/bye", post(worker::bye))
.route("/push-metrics", post(worker::push_metrics)),
)
.nest(
"/deployer",
Router::new()
Expand Down
14 changes: 13 additions & 1 deletion ctl/src/http/worker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
use axum::Json;
use proto::ctl::worker::{PushWorkerMetricsReq, PushWorkerMetricsRes};
use proto::ctl::worker::{
ByeReq, ByeRes, HelloReq, HelloRes, PushWorkerMetricsReq, PushWorkerMetricsRes,
};
use tracing::info;

pub async fn hello(Json(payload): Json<HelloReq>) -> Json<HelloRes> {
info!("{payload:#?}");
Json(HelloRes {})
}

pub async fn bye(Json(payload): Json<ByeReq>) -> Json<ByeRes> {
info!("{payload:#?}");
Json(ByeRes {})
}

pub async fn push_metrics(Json(payload): Json<PushWorkerMetricsReq>) -> Json<PushWorkerMetricsRes> {
info!("{payload:#?}");
Json(PushWorkerMetricsRes {})
Expand Down
14 changes: 13 additions & 1 deletion proto/src/clients/ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ use crate::{
DeployServiceReq, DeployServiceRes, RedeploymentPolicy, ReportDeployInstanceStatusReq,
ReportDeployInstanceStatusRes, TerminateServiceReq, TerminateServiceRes,
},
worker::{PushWorkerMetricsReq, PushWorkerMetricsRes},
worker::{
ByeRes, HelloReq, HelloRes, PortsMap, PushWorkerMetricsReq, PushWorkerMetricsRes,
},
},
};

Expand All @@ -37,6 +39,16 @@ impl CtlClient {
format!("{base}{path}", base = self.base_url)
}

pub async fn hello(&self, ports: PortsMap) -> eyre::Result<HelloRes> {
let body = HelloReq { ports };
self.client.send(self.url("/worker/hello"), &body).await
}

pub async fn bye(&self) -> eyre::Result<ByeRes> {
let body = ByeRes {};
self.client.send(self.url("/worker/bye"), &body).await
}

pub async fn push_metrics(
&self,
metrics: Metrics,
Expand Down
22 changes: 22 additions & 0 deletions proto/src/ctl/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ use serde::{Deserialize, Serialize};

use crate::common::node::Metrics;

#[derive(Debug, Serialize, Deserialize)]
pub struct HelloReq {
pub ports: PortsMap,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct PortsMap {
#[serde(rename = "h")]
pub http: u16,
#[serde(rename = "p")]
pub proxy: u16,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct HelloRes {}

#[derive(Debug, Serialize, Deserialize)]
pub struct ByeReq {}

#[derive(Debug, Serialize, Deserialize)]
pub struct ByeRes {}

/// Pushes new metrics of a given worker node.
///
/// The controller associates the provided metrics to the node that sent them,
Expand Down

0 comments on commit 268e5ac

Please sign in to comment.