From 0a699beb8762a5c644b134570e310309fd51edb2 Mon Sep 17 00:00:00 2001 From: Francisco Moura Date: Fri, 29 Sep 2023 16:14:16 -0300 Subject: [PATCH] Add version log --- .dockerignore | 1 - CHANGELOG.md | 1 + build/Dockerfile | 2 + offchain/Cargo.lock | 61 ++++++++++++++++++++++++++ offchain/Cargo.toml | 1 + offchain/advance-runner/src/main.rs | 4 +- offchain/authority-claimer/src/main.rs | 4 +- offchain/data/src/config.rs | 2 +- offchain/dispatcher/src/dispatcher.rs | 2 +- offchain/dispatcher/src/main.rs | 6 +-- offchain/graphql-server/src/main.rs | 5 +-- offchain/host-runner/src/main.rs | 3 +- offchain/indexer/src/main.rs | 4 +- offchain/inspect-server/src/main.rs | 3 +- offchain/log/Cargo.toml | 4 ++ offchain/log/build.rs | 7 +++ offchain/log/src/lib.rs | 17 +++++++ offchain/state-server/src/main.rs | 2 +- 18 files changed, 108 insertions(+), 21 deletions(-) create mode 100644 offchain/log/build.rs diff --git a/.dockerignore b/.dockerignore index cf579a49c..f4ceea785 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1 @@ -.git **/target/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 7748626a2..4d407a18d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added `PROVIDER_HTTP_ENDPOINT` to advance-runner config - Added `cartesi/rollups-node` docker image with all node binaries - Added completion status to GraphQL API +- Added rollups-node version to the logs in all services ### Changed diff --git a/build/Dockerfile b/build/Dockerfile index 8815c16ff..61c8fbb2a 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -65,6 +65,8 @@ RUN cargo chef cook --release --recipe-path recipe.json # Build application COPY ./offchain/ . +# needed to log commit hash in runtime +COPY ./.git ../ RUN cargo build --release # diff --git a/offchain/Cargo.lock b/offchain/Cargo.lock index 84649dfeb..31183cee4 100644 --- a/offchain/Cargo.lock +++ b/offchain/Cargo.lock @@ -850,6 +850,16 @@ dependencies = [ "uuid 0.8.2", ] +[[package]] +name = "built" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99c4cdc7b2c2364182331055623bdf45254fcb679fea565c40c3c11c101889a" +dependencies = [ + "cargo-lock", + "git2", +] + [[package]] name = "bumpalo" version = "3.14.0" @@ -922,6 +932,18 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo-lock" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" +dependencies = [ + "semver", + "serde", + "toml 0.7.8", + "url", +] + [[package]] name = "cargo-platform" version = "0.1.3" @@ -2377,6 +2399,19 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fb8d784f27acf97159b40fc4db5ecd8aa23b9ad5ef69cdd136d3bc80665f0c0" +[[package]] +name = "git2" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044" +dependencies = [ + "bitflags 1.3.2", + "libc", + "libgit2-sys", + "log 0.4.20", + "url", +] + [[package]] name = "glob" version = "0.3.1" @@ -3028,6 +3063,30 @@ version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +[[package]] +name = "libgit2-sys" +version = "0.15.2+1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + +[[package]] +name = "libz-sys" +version = "1.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -3077,7 +3136,9 @@ checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" name = "log" version = "1.1.0" dependencies = [ + "built", "clap", + "tracing", "tracing-subscriber", ] diff --git a/offchain/Cargo.toml b/offchain/Cargo.toml index 48bb5750f..b83b82518 100644 --- a/offchain/Cargo.toml +++ b/offchain/Cargo.toml @@ -37,6 +37,7 @@ awc = "3.2" axum = "0.6" backoff = "0.4" base64 = "0.21" +built = "0.6" byteorder = "1.4" clap = "4.4" diesel = "2.1" diff --git a/offchain/advance-runner/src/main.rs b/offchain/advance-runner/src/main.rs index 062a5a295..4f57a2f66 100644 --- a/offchain/advance-runner/src/main.rs +++ b/offchain/advance-runner/src/main.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0 (see LICENSE) use advance_runner::config::AdvanceRunnerConfig; -use tracing::info; #[tokio::main] async fn main() -> Result<(), Box> { @@ -10,6 +9,7 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); - info!(?config, "Starting Advance Runner"); + log::log_service_start(&config, "Advance Runner"); + advance_runner::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/authority-claimer/src/main.rs b/offchain/authority-claimer/src/main.rs index f08f7cd75..0185876db 100644 --- a/offchain/authority-claimer/src/main.rs +++ b/offchain/authority-claimer/src/main.rs @@ -3,7 +3,6 @@ use authority_claimer::config::Config; use std::error::Error; -use tracing::info; #[tokio::main] async fn main() -> Result<(), Box> { @@ -13,7 +12,8 @@ async fn main() -> Result<(), Box> { // Setting up the logging environment. log::configure(&config.authority_claimer_config.log_config); - info!(?config, "Starting Authority Claimer"); + //Log Service info + log::log_service_start(&config, "Authority Claimer"); authority_claimer::run(config).await } diff --git a/offchain/data/src/config.rs b/offchain/data/src/config.rs index cf4bf4270..e93c514d5 100644 --- a/offchain/data/src/config.rs +++ b/offchain/data/src/config.rs @@ -50,7 +50,7 @@ impl From for RepositoryConfig { let redacted_endpoint = match cli_config.postgres_endpoint { None => None, Some(endpoint) => { - if endpoint == "" { + if endpoint.is_empty() { None } else { Some(RedactedUrl::new( diff --git a/offchain/dispatcher/src/dispatcher.rs b/offchain/dispatcher/src/dispatcher.rs index 8959ba748..6359ab254 100644 --- a/offchain/dispatcher/src/dispatcher.rs +++ b/offchain/dispatcher/src/dispatcher.rs @@ -25,7 +25,7 @@ pub async fn start( config: DispatcherConfig, metrics: DispatcherMetrics, ) -> Result<(), DispatcherError> { - info!("Setting up dispatcher with config: {:?}", config); + info!("Setting up dispatcher"); let dapp_metadata = DAppMetadata { chain_id: config.tx_config.chain_id, diff --git a/offchain/dispatcher/src/main.rs b/offchain/dispatcher/src/main.rs index dae55bf57..2ef8247e3 100644 --- a/offchain/dispatcher/src/main.rs +++ b/offchain/dispatcher/src/main.rs @@ -1,9 +1,6 @@ // (c) Cartesi and individual authors (see AUTHORS) // SPDX-License-Identifier: Apache-2.0 (see LICENSE) -use log; -use tracing::info; - // NOTE: doesn't support History upgradability. // NOTE: doesn't support changing epoch_duration in the middle of things. #[tokio::main] @@ -12,6 +9,7 @@ async fn main() -> Result<(), Box> { log::configure(&config.dispatcher_config.log_config); - info!(?config, "Starting Dispatcher"); + log::log_service_start(&config, "Dispatcher"); + dispatcher::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/graphql-server/src/main.rs b/offchain/graphql-server/src/main.rs index ff7df3c6e..9ac649376 100644 --- a/offchain/graphql-server/src/main.rs +++ b/offchain/graphql-server/src/main.rs @@ -5,14 +5,13 @@ use clap::Parser; use graphql_server::{CLIConfig, GraphQLConfig}; -use tracing::info; - #[actix_web::main] async fn main() -> Result<(), Box> { let config: GraphQLConfig = CLIConfig::parse().into(); log::configure(&config.log_config); - info!(?config, "Starting GraphQL Server"); + log::log_service_start(&config, "GraphQL Server"); + graphql_server::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/host-runner/src/main.rs b/offchain/host-runner/src/main.rs index 60d009dd1..cefeb5841 100644 --- a/offchain/host-runner/src/main.rs +++ b/offchain/host-runner/src/main.rs @@ -16,7 +16,6 @@ use futures_util::FutureExt; use std::sync::{atomic::AtomicBool, atomic::Ordering, Arc}; use std::time::Duration; use tokio::sync::oneshot; -use tracing::info; use clap::Parser; use config::{CLIConfig, Config}; @@ -36,7 +35,7 @@ async fn main() { log::configure(&config.log_config); - info!(?config, "Starting Host Runner"); + log::log_service_start(&config, "Host Runner"); let controller = Controller::new(Duration::from_millis(config.finish_timeout)); diff --git a/offchain/indexer/src/main.rs b/offchain/indexer/src/main.rs index 8bd930980..4ca5f6955 100644 --- a/offchain/indexer/src/main.rs +++ b/offchain/indexer/src/main.rs @@ -4,7 +4,6 @@ use clap::Parser; use indexer::{CLIConfig, IndexerConfig}; -use tracing::info; #[tokio::main] async fn main() -> Result<(), Box> { @@ -12,6 +11,7 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); - info!(?config, "Starting Indexer"); + log::log_service_start(&config, "Indexer"); + indexer::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/inspect-server/src/main.rs b/offchain/inspect-server/src/main.rs index 65fadbf81..07cff6f75 100644 --- a/offchain/inspect-server/src/main.rs +++ b/offchain/inspect-server/src/main.rs @@ -4,7 +4,6 @@ use clap::Parser; use inspect_server::{config::CLIConfig, InspectServerConfig}; -use tracing::info; #[tokio::main] async fn main() -> Result<(), Box> { @@ -12,7 +11,7 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); - info!(?config, "Starting Inspect Server"); + log::log_service_start(&config, "Inspect Server"); inspect_server::run(config).await.map_err(|e| e.into()) } diff --git a/offchain/log/Cargo.toml b/offchain/log/Cargo.toml index e82a3e157..b8b1f33d8 100644 --- a/offchain/log/Cargo.toml +++ b/offchain/log/Cargo.toml @@ -6,4 +6,8 @@ version.workspace = true [dependencies] clap = { workspace = true, features = ["derive", "env"] } +tracing.workspace = true tracing-subscriber = { workspace = true, features = ["env-filter"] } + +[build-dependencies] +built = { workspace = true, features = ["git2"] } diff --git a/offchain/log/build.rs b/offchain/log/build.rs new file mode 100644 index 000000000..5b20b4b6d --- /dev/null +++ b/offchain/log/build.rs @@ -0,0 +1,7 @@ +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) + +pub(crate) fn main() { + built::write_built_file() + .expect("Failed to acquire build-time information"); +} diff --git a/offchain/log/src/lib.rs b/offchain/log/src/lib.rs index 4d4c36aa5..e28a8df6e 100644 --- a/offchain/log/src/lib.rs +++ b/offchain/log/src/lib.rs @@ -1,6 +1,15 @@ +// (c) Cartesi and individual authors (see AUTHORS) +// SPDX-License-Identifier: Apache-2.0 (see LICENSE) +use std::fmt::Debug; + use clap::Parser; +use tracing::info; use tracing_subscriber::filter::{EnvFilter, LevelFilter}; +pub mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + #[derive(Debug, Parser)] #[command(name = "log_config")] pub struct LogEnvCliConfig { @@ -52,3 +61,11 @@ pub fn configure(config: &LogConfig) { subscribe_builder.init(); } } + +pub fn log_service_start(config: &C, service_name: &str) { + let git_ref = built_info::GIT_HEAD_REF.ok_or("N/A").unwrap(); + let git_hash = built_info::GIT_COMMIT_HASH.ok_or("N/A").unwrap(); + + let message = format!("Starting {service} (version={version}, git ref={git_ref}, git hash={git_hash}) with config {:?}",config, service = service_name, version = built_info::PKG_VERSION, git_ref = git_ref, git_hash = git_hash); + info!(message); +} diff --git a/offchain/state-server/src/main.rs b/offchain/state-server/src/main.rs index 3f13118a8..fc420c87e 100644 --- a/offchain/state-server/src/main.rs +++ b/offchain/state-server/src/main.rs @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box> { log::configure(&config.log_config); - tracing::info!(?config, "Starting State Server"); + log::log_service_start(&config, "State Server"); state_server::run_server::(config.state_server_config) .await