Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add version log #86

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.git
**/target/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Added rollups-node version to the logs in all services
fmoura marked this conversation as resolved.
Show resolved Hide resolved

## [1.1.0] 2023-10-02

### Added
Expand Down
2 changes: 2 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
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.

1 change: 1 addition & 0 deletions offchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
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
}
2 changes: 1 addition & 1 deletion offchain/data/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl From<RepositoryCLIConfig> 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(
Expand Down
2 changes: 1 addition & 1 deletion offchain/dispatcher/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could remove this log since it doesn't add much else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Could that be a "trace" instead of "info" then, as logs also acts as "execution markers" that helps spot bugs. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to trace is fine as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gligneul @fmoura, are we going to keep the info instead of changing it to a trace?


let dapp_metadata = DAppMetadata {
chain_id: config.tx_config.chain_id,
Expand Down
6 changes: 2 additions & 4 deletions offchain/dispatcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -12,6 +9,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())
}
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())
}
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, "Indexer");

indexer::run(config).await.map_err(|e| e.into())
}
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())
}
4 changes: 4 additions & 0 deletions offchain/log/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
7 changes: 7 additions & 0 deletions offchain/log/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
17 changes: 17 additions & 0 deletions offchain/log/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -52,3 +61,11 @@ pub fn configure(config: &LogConfig) {
subscribe_builder.init();
}
}

pub fn log_service_start<C: Debug>(config: &C, service_name: &str) {
let git_ref = built_info::GIT_HEAD_REF.unwrap_or("N/A");
let git_hash = built_info::GIT_COMMIT_HASH.unwrap_or("N/A");

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);
}
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
Loading