diff --git a/CHANGELOG.md b/CHANGELOG.md index 450e623f..19ae1b2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `GetClients` to `SrsService`, which retrieves a list of units that are connected to SRS and the frequencies they are connected to. - Added `SrsConnectEvent` and `SrsDisconnectEvent` events - Added `GetDrawArgumentValue` API for units, which returns the value for drawing. (useful for "hook down", "doors open" checks) +- Added `MetadataService` with `GetHealth` and `GetVersion` for quick checks on health (even when DCS mission is unresponsive) and version. - Added Authentication Interceptor. This enables authentication on a per client basis. ### Fixed diff --git a/protos/dcs/dcs.proto b/protos/dcs/dcs.proto index 87d45cb0..293d3221 100644 --- a/protos/dcs/dcs.proto +++ b/protos/dcs/dcs.proto @@ -9,6 +9,7 @@ import "dcs/controller/v0/controller.proto"; import "dcs/custom/v0/custom.proto"; import "dcs/group/v0/group.proto"; import "dcs/hook/v0/hook.proto"; +import "dcs/metadata/v0/metadata.proto"; import "dcs/mission/v0/mission.proto"; import "dcs/net/v0/net.proto"; import "dcs/srs/v0/srs.proto"; diff --git a/protos/dcs/metadata/v0/metadata.proto b/protos/dcs/metadata/v0/metadata.proto new file mode 100644 index 00000000..938d4ce3 --- /dev/null +++ b/protos/dcs/metadata/v0/metadata.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +package dcs.metadata.v0; +option csharp_namespace = "RurouniJones.Dcs.Grpc.V0.Metadata"; +option go_package = "github.com/DCS-gRPC/go-bindings/dcs/v0/metadata"; + +//A service to get administrative/meta data like server health checks and version +service MetadataService { + + rpc GetHealth(GetHealthRequest) returns (GetHealthResponse) {} + + rpc GetVersion(GetVersionRequest) returns (GetVersionResponse) {} +} + +message GetHealthRequest { +} + +message GetHealthResponse { + bool alive = 1; +} + +message GetVersionRequest { +} + +message GetVersionResponse { + string version = 1; +} \ No newline at end of file diff --git a/src/rpc.rs b/src/rpc.rs index 4572d2e1..499c005a 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -16,6 +16,7 @@ mod controller; mod custom; mod group; mod hook; +mod metadata; mod mission; mod net; mod srs; diff --git a/src/rpc/metadata.rs b/src/rpc/metadata.rs new file mode 100644 index 00000000..415c82db --- /dev/null +++ b/src/rpc/metadata.rs @@ -0,0 +1,26 @@ +use stubs::metadata::v0::metadata_service_server::MetadataService; +use stubs::*; +use tonic::async_trait; +use tonic::{Request, Response, Status}; + +use super::MissionRpc; + +#[async_trait] +impl MetadataService for MissionRpc { + async fn get_health( + &self, + _request: Request, + ) -> Result, Status> { + let alive: bool = true; + return Ok(Response::new(metadata::v0::GetHealthResponse { alive })); + } + + async fn get_version( + &self, + _request: Request, + ) -> Result, Status> { + const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); + let version = VERSION.unwrap_or("unknown").to_string(); + return Ok(Response::new(metadata::v0::GetVersionResponse { version })); + } +} diff --git a/src/server.rs b/src/server.rs index 28803b1b..c775612d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -17,6 +17,7 @@ use stubs::controller::v0::controller_service_server::ControllerServiceServer; use stubs::custom::v0::custom_service_server::CustomServiceServer; use stubs::group::v0::group_service_server::GroupServiceServer; use stubs::hook::v0::hook_service_server::HookServiceServer; +use stubs::metadata::v0::metadata_service_server::MetadataServiceServer; use stubs::mission::v0::mission_service_server::MissionServiceServer; use stubs::mission::v0::StreamEventsResponse; use stubs::net::v0::net_service_server::NetServiceServer; @@ -209,7 +210,7 @@ async fn try_run( auth_config, } = state; - let mut mission_rpc = + let mut mission_rpc: MissionRpc = MissionRpc::new(ipc_mission.clone(), stats.clone(), shutdown_signal.clone()); let mut hook_rpc = HookRpc::new(ipc_hook, stats, shutdown_signal.clone()); @@ -260,6 +261,7 @@ async fn try_run( .add_service(CustomServiceServer::new(mission_rpc.clone())) .add_service(GroupServiceServer::new(mission_rpc.clone())) .add_service(HookServiceServer::new(hook_rpc)) + .add_service(MetadataServiceServer::new(mission_rpc.clone())) .add_service(MissionServiceServer::new(mission_rpc.clone())) .add_service(NetServiceServer::new(mission_rpc.clone())) .add_service(TimerServiceServer::new(mission_rpc.clone())) diff --git a/stubs/src/lib.rs b/stubs/src/lib.rs index bd60b350..9b107bf4 100644 --- a/stubs/src/lib.rs +++ b/stubs/src/lib.rs @@ -10,6 +10,7 @@ pub mod controller; pub mod custom; pub mod group; pub mod hook; +pub mod metadata; pub mod mission; pub mod net; pub mod srs; diff --git a/stubs/src/metadata.rs b/stubs/src/metadata.rs new file mode 100644 index 00000000..3e83a462 --- /dev/null +++ b/stubs/src/metadata.rs @@ -0,0 +1,3 @@ +pub mod v0 { + tonic::include_proto!("dcs.metadata.v0"); +}