Skip to content

Commit

Permalink
Minor linera-service tracing output improvements (#2467)
Browse files Browse the repository at this point in the history
* `linera-service`: improve tracing output
  • Loading branch information
Twey authored Oct 4, 2024
1 parent 27c53b0 commit 22c9c97
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion linera-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ path = "src/server.rs"

[[bin]]
name = "linera-proxy"
path = "src/proxy.rs"
path = "src/proxy/main.rs"

[[bin]]
name = "linera-schema-export"
Expand Down
1 change: 0 additions & 1 deletion linera-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

pub mod cli_wrappers;
pub mod faucet;
pub mod grpc_proxy;
pub mod node_service;
pub mod project;
#[cfg(with_metrics)]
Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ fn main() -> anyhow::Result<()> {
builder
};

let span = tracing::info_span!("run");
let span = tracing::info_span!("linera::main");
if let Some(wallet_id) = options.with_wallet {
span.record("wallet_id", wallet_id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use tonic::{
Request, Response, Status,
};
use tower::{builder::ServiceBuilder, Layer, Service};
use tracing::{debug, info, instrument};
use tracing::{debug, info, instrument, Instrument as _};
#[cfg(with_metrics)]
use {
linera_base::prometheus_util,
Expand Down Expand Up @@ -231,7 +231,16 @@ where

/// Runs the proxy. If either the public server or private server dies for whatever
/// reason we'll kill the proxy.
#[instrument(skip_all, fields(public_address = %self.public_address(), internal_address = %self.internal_address(), metrics_address = %self.metrics_address()), err)]
#[instrument(
name = "GrpcProxy::run",
skip_all,
fields(
public_address = %self.public_address(),
internal_address = %self.internal_address(),
metrics_address = %self.metrics_address(),
),
err,
)]
pub async fn run(self, shutdown_signal: CancellationToken) -> Result<()> {
info!("Starting gRPC server");
let mut join_set = JoinSet::new();
Expand All @@ -246,7 +255,8 @@ where
let internal_server = join_set.spawn_task(
Server::builder()
.add_service(self.as_notifier_service())
.serve(self.internal_address()),
.serve(self.internal_address())
.in_current_span(),
);
let reflection_service = tonic_reflection::server::Builder::configure()
.register_encoded_file_descriptor_set(linera_rpc::FILE_DESCRIPTOR_SET)
Expand All @@ -262,7 +272,8 @@ where
.add_service(health_service)
.add_service(tonic_web::enable(self.as_validator_node()))
.add_service(tonic_web::enable(reflection_service))
.serve_with_shutdown(self.public_address(), shutdown_signal.cancelled_owned()),
.serve_with_shutdown(self.public_address(), shutdown_signal.cancelled_owned())
.in_current_span(),
);

select! {
Expand Down
11 changes: 7 additions & 4 deletions linera-service/src/proxy.rs → linera-service/src/proxy/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ use linera_rpc::{
};
#[cfg(with_metrics)]
use linera_service::prometheus_server;
use linera_service::{grpc_proxy::GrpcProxy, util};
use linera_service::util;
use linera_storage::Storage;
use linera_views::store::CommonStoreConfig;
use tokio::task::JoinSet;
use tokio_util::sync::CancellationToken;
use tracing::{error, info, instrument};

mod grpc;
use grpc::GrpcProxy;

/// Options for running the proxy.
#[derive(clap::Parser, Debug, Clone)]
#[command(
Expand Down Expand Up @@ -115,7 +118,7 @@ impl Runnable for ProxyContext {
{
let shutdown_notifier = CancellationToken::new();
tokio::spawn(util::listen_for_shutdown_signals(shutdown_notifier.clone()));
let proxy = Proxy::from_context(self, storage).await?;
let proxy = Proxy::from_context(self, storage)?;
match proxy {
Proxy::Simple(simple_proxy) => simple_proxy.run(shutdown_notifier).await,
Proxy::Grpc(grpc_proxy) => grpc_proxy.run(shutdown_notifier).await,
Expand All @@ -128,7 +131,7 @@ where
S: Storage + Clone + Send + Sync + 'static,
{
/// Constructs and configures the [`Proxy`] given [`ProxyContext`].
async fn from_context(context: ProxyContext, storage: S) -> Result<Self> {
fn from_context(context: ProxyContext, storage: S) -> Result<Self> {
let internal_protocol = context.config.internal_network.protocol;
let external_protocol = context.config.validator.network.protocol;
let proxy = match (internal_protocol, external_protocol) {
Expand Down Expand Up @@ -236,7 +239,7 @@ impl<S> SimpleProxy<S>
where
S: Storage + Clone + Send + Sync + 'static,
{
#[instrument(skip_all, fields(port = self.public_config.port, metrics_port = self.internal_config.metrics_port), err)]
#[instrument(name = "SimpleProxy::run", skip_all, fields(port = self.public_config.port, metrics_port = self.internal_config.metrics_port), err)]
async fn run(self, shutdown_signal: CancellationToken) -> Result<()> {
info!("Starting simple server");
let mut join_set = JoinSet::new();
Expand Down

0 comments on commit 22c9c97

Please sign in to comment.