Skip to content

Commit 59200b6

Browse files
committed
feat: made grpc host and health service configurable
1 parent c07fc24 commit 59200b6

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/configuration/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ pub struct Config {
3232
/// URL to the `Sagittarius` Server.
3333
pub backend_url: String,
3434

35+
// Port of the `Aquila` Server
3536
pub grpc_port: u16,
37+
38+
// Host of the `Aquila` Server
39+
pub grpc_host: String,
40+
41+
pub with_health_service: bool,
3642
}
3743

3844
/// Implementation for all relevant `Aquila` startup configurations
@@ -57,6 +63,8 @@ impl Config {
5763
String::from("../flow/test_flow_one.json"),
5864
),
5965
grpc_port: env_with_default("GRPC_PORT", 8081),
66+
grpc_host: env_with_default("GRPC_HOST", String::from("127.0.0.1")),
67+
with_health_service: env_with_default("WITH_HEALTH_SERVICE", false),
6068
runtime_token: env_with_default("RUNTIME_TOKEN", String::from("default_session_token")),
6169
backend_url: env_with_default("BACKEND_URL", String::from("http://localhost:8080")),
6270
}

src/server/mod.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ pub struct AquilaGRPCServer {
2727
sagittarius_url: String,
2828
nats_url: String,
2929
address: SocketAddr,
30+
with_health_service: bool,
3031
}
3132

3233
impl AquilaGRPCServer {
3334
pub fn new(config: &Config) -> Self {
34-
let address = match format!("127.0.0.1:{}", config.grpc_port).parse() {
35+
let address = match format!("{}:{}", config.grpc_host, config.grpc_port).parse() {
3536
Ok(addr) => {
3637
info!("Listening on {:?}", &addr);
3738
addr
@@ -43,55 +44,61 @@ impl AquilaGRPCServer {
4344
token: config.runtime_token.clone(),
4445
sagittarius_url: config.backend_url.clone(),
4546
nats_url: config.nats_url.clone(),
47+
with_health_service: config.with_health_service,
4648
address,
4749
}
4850
}
4951

50-
pub async fn start(&self) -> std::result::Result<(), tonic::transport::Error> {
52+
pub async fn start(&self) -> Result<(), tonic::transport::Error> {
5153
let data_type_service = SagittariusDataTypeServiceClient::new_arc(
5254
self.sagittarius_url.clone(),
5355
self.token.clone(),
5456
)
5557
.await;
5658

57-
log::info!("DataTypeService started");
59+
info!("DataTypeService started");
5860

5961
let flow_type_service = SagittariusFlowTypeServiceClient::new_arc(
6062
self.sagittarius_url.clone(),
6163
self.token.clone(),
6264
)
6365
.await;
6466

65-
log::info!("FlowTypeService started");
67+
info!("FlowTypeService started");
6668

6769
let runtime_function_service = SagittariusRuntimeFunctionServiceClient::new_arc(
6870
self.sagittarius_url.clone(),
6971
self.token.clone(),
7072
)
7173
.await;
7274

73-
log::info!("RuntimeFunctionService started");
74-
75-
let health_service = code0_flow::flow_health::HealthService::new(self.nats_url.clone());
76-
log::info!("HealthService started");
75+
info!("RuntimeFunctionService started");
7776

7877
let data_type_server = AquilaDataTypeServiceServer::new(data_type_service.clone());
7978
let flow_type_server = AquilaFlowTypeServiceServer::new(flow_type_service.clone());
8079
let runtime_function_server =
8180
AquilaRuntimeFunctionServiceServer::new(runtime_function_service.clone());
8281

83-
log::info!("Starting gRPC Server...");
82+
info!("Starting gRPC Server...");
83+
84+
if self.with_health_service {
85+
info!("Starting with HealthService");
86+
let health_service = code0_flow::flow_health::HealthService::new(self.nats_url.clone());
8487

85-
Server::builder()
86-
.add_service(tonic_health::pb::health_server::HealthServer::new(
87-
health_service,
88-
))
89-
.add_service(DataTypeServiceServer::new(data_type_server))
90-
.add_service(FlowTypeServiceServer::new(flow_type_server))
91-
.add_service(RuntimeFunctionDefinitionServiceServer::new(
92-
runtime_function_server,
93-
))
94-
.serve(self.address)
95-
.await
88+
Server::builder()
89+
.add_service(tonic_health::pb::health_server::HealthServer::new(health_service))
90+
.add_service(DataTypeServiceServer::new(data_type_server))
91+
.add_service(FlowTypeServiceServer::new(flow_type_server))
92+
.add_service(RuntimeFunctionDefinitionServiceServer::new(runtime_function_server))
93+
.serve(self.address)
94+
.await
95+
} else {
96+
97+
Server::builder()
98+
.add_service(DataTypeServiceServer::new(data_type_server))
99+
.add_service(FlowTypeServiceServer::new(flow_type_server))
100+
.add_service(RuntimeFunctionDefinitionServiceServer::new(runtime_function_server)).serve(self.address)
101+
.await
102+
}
96103
}
97104
}

0 commit comments

Comments
 (0)