Skip to content

Commit

Permalink
feat: Add version log
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoura committed Sep 23, 2023
1 parent c7959f1 commit 1cb321f
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 19 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.git
**/target/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support to `POST` *inspect state* requests
- Added snapshot validation. The node will now check whether the snapshot's template hash matches the one stored in the blockchain
- Added `cartesi/rollups-node` docker image with all node binaries
- Added versioning logs to all services

### Changed

Expand Down
1 change: 1 addition & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ RUN cargo chef cook --release --recipe-path recipe.json

# Build application
COPY ./offchain/ .
COPY ./.git ../
RUN cargo build --release

#
Expand Down
61 changes: 61 additions & 0 deletions offchain/Cargo.lock

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

3 changes: 1 addition & 2 deletions offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ awc = "3.1"
axum = "0.6"
backoff = "0.4"
base64 = "0.21"
built = "0.6"
byteorder = "1.4"
clap = "4.3"
diesel = "2.1"
Expand Down Expand Up @@ -91,5 +92,3 @@ urlencoding = "2.1"
users = "0.11"
uuid = "1.4"

[profile.release]
strip = true # Automatically strip symbols from the binary.
4 changes: 2 additions & 2 deletions offchain/advance-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

use advance_runner::config::AdvanceRunnerConfig;
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AdvanceRunnerConfig::parse()?;

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())
}
4 changes: 2 additions & 2 deletions offchain/authority-claimer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

use authority_claimer::config::Config;
use std::error::Error;
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -13,7 +12,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
// 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
}
5 changes: 5 additions & 0 deletions offchain/dispatcher/src/built/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use built;

pub(crate) fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
4 changes: 2 additions & 2 deletions offchain/dispatcher/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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.
Expand All @@ -12,6 +11,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

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())
}
1 change: 1 addition & 0 deletions offchain/graphql-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ test-fixtures = { path = "../test-fixtures" }
awc.workspace = true
serial_test.workspace = true
testcontainers.workspace = true

5 changes: 2 additions & 3 deletions offchain/graphql-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use clap::Parser;

use graphql_server::{CLIConfig, GraphQLConfig};

use tracing::info;

#[actix_web::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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())
}
1 change: 1 addition & 0 deletions offchain/host-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ mockall.workspace = true
rand.workspace = true
serial_test.workspace = true
tracing-test.workspace = true

3 changes: 1 addition & 2 deletions offchain/host-runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions offchain/indexer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use clap::Parser;

use indexer::{CLIConfig, IndexerConfig};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config: IndexerConfig = CLIConfig::parse().into();

log::configure(&config.log_config);

info!(?config, "Starting Indexer");
log::log_service_start(&config, "Starting Indexer");

indexer::run(config).await.map_err(|e| e.into())
}
1 change: 1 addition & 0 deletions offchain/inspect-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ uuid = { workspace = true, features = ["v4"] }
futures.workspace = true
reqwest = { workspace = true, features = ["json"] }
serial_test.workspace = true

3 changes: 1 addition & 2 deletions offchain/inspect-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
use clap::Parser;

use inspect_server::{config::CLIConfig, InspectServerConfig};
use tracing::info;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config: InspectServerConfig = CLIConfig::parse().into();

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())
}
5 changes: 5 additions & 0 deletions offchain/log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ license.workspace = true
version.workspace = true

[dependencies]
built.workspace = true
clap = { workspace = true, features = ["derive", "env"] }
tracing.workspace = true
tracing-subscriber = { workspace = true, features = ["env-filter"] }

[build-dependencies]
built = { workspace = true, features = ["git2"] }
6 changes: 6 additions & 0 deletions offchain/log/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use built;

pub(crate) fn main() {
built::write_built_file()
.expect("Failed to acquire build-time information");
}
6 changes: 6 additions & 0 deletions offchain/log/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use built;

pub(crate) fn main() {
built::write_built_file()
.expect("Failed to acquire build-time information");
}
27 changes: 27 additions & 0 deletions offchain/log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
use std::any::Any;
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 {
Expand Down Expand Up @@ -52,3 +60,22 @@ pub fn configure(config: &LogConfig) {
subscribe_builder.init();
}
}

pub fn log_service_start<C: Any + Debug>(config: &C, service_name: &str) {
let message = format!("Starting {service}", service = service_name);
info!(message);
log_build_info();
info!(?config);
}

pub fn log_build_info() {
info!("Version: {}", built_info::PKG_VERSION);
match built_info::GIT_HEAD_REF {
Some(v) => info!("Git ref: {}", v),
None => (),
}
match built_info::GIT_COMMIT_HASH {
Some(v) => info!("Git hash: {}", v),
None => (),
}
}
2 changes: 1 addition & 1 deletion offchain/state-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

log::configure(&config.log_config);

tracing::info!(?config, "Starting State Server");
log::log_service_start(&config, "State Server");

state_server::run_server::<RollupsState>(config.state_server_config)
.await
Expand Down

0 comments on commit 1cb321f

Please sign in to comment.