Skip to content

Commit

Permalink
add a health service to the gRPC server
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Mar 20, 2024
1 parent 5a1e17b commit 7e557ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/astria-composer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ tracing = { workspace = true, features = ["attributes"] }
tryhard = { workspace = true }
tonic = "0.10.2"
tokio-stream = { version = "0.1.14", features = ["net"] }
tonic-health = "0.10.2"

[dependencies.sequencer-client]
package = "astria-sequencer-client"
Expand Down
17 changes: 14 additions & 3 deletions crates/astria-composer/src/collectors/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ use tonic::{
Response,
};

use crate::executor;
use crate::{
executor,
executor::Handle,
};

/// `GrpcCollector` listens for incoming gRPC requests and sends the Rollup transactions to the
/// Executor. The Executor then sends the transactions to the Astria Shared Sequencer.
Expand Down Expand Up @@ -65,16 +68,24 @@ impl Grpc {
})
}

/// Returns the socker address the grpc collector is served over
/// Returns the socket address the grpc collector is served over
/// # Errors
/// Returns an error if the listener is not bound
pub(crate) fn local_addr(&self) -> io::Result<SocketAddr> {
self.listener.local_addr()
}

pub(crate) async fn run_until_stopped(self) -> eyre::Result<()> {
let (mut health_reporter, health_service) = tonic_health::server::health_reporter();

let composer_service = GrpcCollectorServiceServer::new(self.executor_handle);
let grpc_server = tonic::transport::Server::builder().add_service(composer_service);
let grpc_server = tonic::transport::Server::builder()
.add_service(health_service)
.add_service(composer_service);

health_reporter
.set_serving::<GrpcCollectorServiceServer<Handle>>()
.await;

grpc_server
.serve_with_incoming(tokio_stream::wrappers::TcpListenerStream::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-composer/src/composer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Composer {
executor_handle,
mut geth_collector_tasks,
mut geth_collectors,
rollup_id_to_url: rollups,
rollup_id_to_url,
mut geth_collector_statuses,
grpc_collector,
} = self;
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Composer {
&mut geth_collector_statuses,
&mut geth_collector_tasks,
executor_handle.clone(),
&rollups,
&rollup_id_to_url,
rollup,
collector_exit,
);
Expand Down

0 comments on commit 7e557ca

Please sign in to comment.