Skip to content

Commit

Permalink
Added MetadataService with GetHealth and GetVersion (#267)
Browse files Browse the repository at this point in the history
Added an additional service. "MetadataService" for admin functionality that does not touch DCS itself.

GetHealth => for getting the gRPC server status
GetVersion => for getting the version of the cargo package.

Nothing too fancy, but can be handy for the client and verification.

Co-authored-by: dutchie032 <dutchie032>
  • Loading branch information
dutchie032 authored Sep 28, 2024
1 parent 36a187d commit 64d5dc3
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions protos/dcs/dcs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
26 changes: 26 additions & 0 deletions protos/dcs/metadata/v0/metadata.proto
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod controller;
mod custom;
mod group;
mod hook;
mod metadata;
mod mission;
mod net;
mod srs;
Expand Down
26 changes: 26 additions & 0 deletions src/rpc/metadata.rs
Original file line number Diff line number Diff line change
@@ -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<metadata::v0::GetHealthRequest>,
) -> Result<Response<metadata::v0::GetHealthResponse>, Status> {
let alive: bool = true;
return Ok(Response::new(metadata::v0::GetHealthResponse { alive }));
}

async fn get_version(
&self,
_request: Request<metadata::v0::GetVersionRequest>,
) -> Result<Response<metadata::v0::GetVersionResponse>, 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 }));
}
}
4 changes: 3 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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()))
Expand Down
1 change: 1 addition & 0 deletions stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions stubs/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod v0 {
tonic::include_proto!("dcs.metadata.v0");
}

0 comments on commit 64d5dc3

Please sign in to comment.