Skip to content

Commit

Permalink
Merge pull request #2009 from input-output-hk/djo/1981/rework-aggrega…
Browse files Browse the repository at this point in the history
…tor-log-msgs

Rework & harmonize aggregator log messages
  • Loading branch information
Alenar authored Oct 15, 2024
2 parents 8fbaaee + 20156b9 commit 0d4d6bc
Show file tree
Hide file tree
Showing 39 changed files with 397 additions and 318 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.5.82"
version = "0.5.83"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {
beacon: &CardanoDbBeacon,
snapshot_digest: &str,
) -> StdResult<OngoingSnapshot> {
debug!(
self.logger,
"CardanoImmutableFilesFullArtifactBuilder: create snapshot archive"
);
debug!(self.logger, ">> create_snapshot_archive");

let snapshotter = self.snapshotter.clone();
let snapshot_name = format!(
Expand All @@ -81,7 +78,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {
})
.await??;

debug!(self.logger, " > snapshot created: '{ongoing_snapshot:?}'");
debug!(self.logger, " > Snapshot created: '{ongoing_snapshot:?}'");

Ok(ongoing_snapshot)
}
Expand All @@ -90,19 +87,16 @@ impl CardanoImmutableFilesFullArtifactBuilder {
&self,
ongoing_snapshot: &OngoingSnapshot,
) -> StdResult<Vec<SnapshotLocation>> {
debug!(
self.logger,
"CardanoImmutableFilesFullArtifactBuilder: upload snapshot archive"
);
debug!(self.logger, ">> upload_snapshot_archive");
let location = self
.snapshot_uploader
.upload_snapshot(ongoing_snapshot.get_file_path())
.await;

if let Err(error) = tokio::fs::remove_file(ongoing_snapshot.get_file_path()).await {
warn!(
self.logger,
" > Post upload ongoing snapshot file removal failure: {error}"
self.logger, " > Post upload ongoing snapshot file removal failure";
"error" => error
);
}

Expand All @@ -116,10 +110,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {
snapshot_digest: String,
remote_locations: Vec<String>,
) -> StdResult<Snapshot> {
debug!(
self.logger,
"CardanoImmutableFilesFullArtifactBuilder: create snapshot"
);
debug!(self.logger, ">> create_snapshot");

let snapshot = Snapshot::new(
snapshot_digest,
Expand Down
9 changes: 4 additions & 5 deletions mithril-aggregator/src/commands/serve_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,9 @@ impl ServeCommand {
}
Err(error) => {
warn!(
root_logger,
"Failed to build the `SignersImporter`:\n url to import `{}`\n Error: {:?}",
cexplorer_pools_url,
error
root_logger, "Failed to build the `SignersImporter`";
"url_to_import" => cexplorer_pools_url,
"error" => ?error
);
}
}
Expand All @@ -190,7 +189,7 @@ impl ServeCommand {
dependencies_builder.vanish().await;

if let Err(e) = join_set.join_next().await.unwrap()? {
crit!(root_logger, "A critical error occurred: {e}");
crit!(root_logger, "A critical error occurred"; "error" => e);
}

// stop servers
Expand Down
3 changes: 2 additions & 1 deletion mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ impl DependenciesBuilder {
let epoch_settings_configuration = self.get_epoch_settings_configuration()?;
debug!(
logger,
"Handle discrepancies at startup of epoch settings store, will record epoch settings from the configuration for epoch {current_epoch}: {epoch_settings_configuration:?}"
"Handle discrepancies at startup of epoch settings store, will record epoch settings from the configuration for epoch {current_epoch}";
"epoch_settings_configuration" => ?epoch_settings_configuration,
);
epoch_settings_store
.handle_discrepancies_at_startup(current_epoch, &epoch_settings_configuration)
Expand Down
6 changes: 3 additions & 3 deletions mithril-aggregator/src/event_store/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ impl EventStore {
let persister = EventPersister::new(connection);
info!(
self.logger,
"monitoring: starting event loop to log messages."
"Starting monitoring event loop to log messages."
);
loop {
if let Some(message) = self.receiver.recv().await {
debug!(self.logger, "Event received: {message:?}");
debug!(self.logger, "Event received"; "event" => ?message);
let event = persister
.persist(message)
.with_context(|| "event persist failure")?;
debug!(self.logger, "event ID={} created", event.event_id);
debug!(self.logger, "Event ID={} created", event.event_id);
} else {
info!(self.logger, "No more events to proceed, quitting…");
break;
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/event_store/transmitter_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl TransmitterService<EventMessage> {
{
let content = serde_json::to_string(content).map_err(|e| {
let error_msg = format!("Serialization error while forging event message: {e}");
warn!(self.logger, "Event message error => «{error_msg}»");
warn!(self.logger, "Event message error"; "error" => &error_msg);

error_msg
})?;
Expand All @@ -68,7 +68,7 @@ impl TransmitterService<EventMessage> {
self.get_transmitter().send(message.clone()).map_err(|e| {
let error_msg =
format!("An error occurred when sending message {message:?} to monitoring: '{e}'.");
warn!(self.logger, "Event message error => «{error_msg}»");
warn!(self.logger, "Event message error"; "error" => &error_msg);

error_msg
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub mod handlers {
use crate::services::MessageService;

use mithril_common::entities::Epoch;
use slog::{debug, warn, Logger};
use slog::{warn, Logger};
use std::convert::Infallible;
use std::sync::Arc;
use warp::http::StatusCode;
Expand All @@ -64,15 +64,13 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifacts");

match http_message_service
.get_cardano_stake_distribution_list_message(LIST_MAX_ITEMS)
.await
{
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
Err(err) => {
warn!(logger, "list_artifacts_cardano_stake_distribution"; "error" => ?err);
warn!(logger, "get_cardano_stake_distribution_list::error"; "error" => ?err);
Ok(reply::server_error(err))
}
}
Expand All @@ -84,8 +82,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifact/{signed_entity_id}");

match http_message_service
.get_cardano_stake_distribution_message(&signed_entity_id)
.await
Expand All @@ -108,8 +104,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifact/epoch/{epoch}");

let artifact_epoch = match epoch.parse::<u64>() {
Ok(epoch) => Epoch(epoch),
Err(err) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub mod handlers {
use crate::http_server::routes::reply;
use crate::services::MessageService;

use slog::{debug, warn, Logger};
use slog::{warn, Logger};
use std::convert::Infallible;
use std::sync::Arc;
use warp::http::StatusCode;
Expand All @@ -47,8 +47,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifacts");

match http_message_service
.get_cardano_transaction_list_message(LIST_MAX_ITEMS)
.await
Expand All @@ -68,8 +66,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifact/{signed_entity_id}");

match http_message_service
.get_cardano_transaction_message(&signed_entity_id)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod handlers {
use crate::http_server::routes::reply;
use crate::services::MessageService;

use slog::{debug, warn, Logger};
use slog::{warn, Logger};
use std::convert::Infallible;
use std::sync::Arc;
use warp::http::StatusCode;
Expand All @@ -48,8 +48,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifacts");

match http_message_service
.get_mithril_stake_distribution_list_message(LIST_MAX_ITEMS)
.await
Expand All @@ -68,8 +66,6 @@ pub mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifact/{signed_entity_id}");

match http_message_service
.get_mithril_stake_distribution_message(&signed_entity_id)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifacts");

match http_message_service
.get_snapshot_list_message(LIST_MAX_ITEMS)
.await
Expand All @@ -129,7 +127,6 @@ mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: artifact/{signed_entity_id}");
match http_message_service
.get_snapshot_message(&signed_entity_id)
.await
Expand All @@ -155,7 +152,7 @@ mod handlers {
let filepath = reply.path().to_path_buf();
debug!(
logger,
"⇄ HTTP SERVER: ensure_downloaded_file_is_a_snapshot / file: `{}`",
">> ensure_downloaded_file_is_a_snapshot / file: `{}`",
filepath.display()
);

Expand Down Expand Up @@ -188,8 +185,6 @@ mod handlers {
config: Configuration,
signed_entity_service: Arc<dyn SignedEntityService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: snapshot_download/{}", digest);

match signed_entity_service
.get_signed_snapshot_by_id(&digest)
.await
Expand Down
11 changes: 1 addition & 10 deletions mithril-aggregator/src/http_server/routes/certificate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod handlers {
ToCertificatePendingMessageAdapter,
};

use slog::{debug, warn, Logger};
use slog::{warn, Logger};
use std::convert::Infallible;
use std::sync::Arc;
use warp::http::StatusCode;
Expand All @@ -63,8 +63,6 @@ mod handlers {
logger: Logger,
certificate_pending_store: Arc<CertificatePendingStore>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: certificate_pending");

match certificate_pending_store.get().await {
Ok(Some(certificate_pending)) => Ok(reply::json(
&ToCertificatePendingMessageAdapter::adapt(certificate_pending),
Expand All @@ -83,8 +81,6 @@ mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: certificate_certificates",);

match http_message_service
.get_certificate_list_message(LIST_MAX_ITEMS)
.await
Expand All @@ -103,11 +99,6 @@ mod handlers {
logger: Logger,
http_message_service: Arc<dyn MessageService>,
) -> Result<impl warp::Reply, Infallible> {
debug!(
logger,
"⇄ HTTP SERVER: certificate_certificate_hash/{}", certificate_hash
);

match http_message_service
.get_certificate_message(&certificate_hash)
.await
Expand Down
8 changes: 5 additions & 3 deletions mithril-aggregator/src/http_server/routes/epoch_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async fn get_epoch_settings_message(
}

mod handlers {
use slog::{debug, Logger};
use slog::{warn, Logger};
use std::collections::BTreeSet;
use std::convert::Infallible;
use warp::http::StatusCode;
Expand All @@ -86,13 +86,15 @@ mod handlers {
epoch_service: EpochServiceWrapper,
allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
) -> Result<impl warp::Reply, Infallible> {
debug!(logger, "⇄ HTTP SERVER: epoch_settings");
let epoch_settings_message =
get_epoch_settings_message(epoch_service, allowed_discriminants).await;

match epoch_settings_message {
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
Err(err) => Ok(reply::server_error(err)),
Err(err) => {
warn!(logger,"epoch_settings::error"; "error" => ?err);
Ok(reply::server_error(err))
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion mithril-aggregator/src/http_server/routes/middlewares.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use slog::Logger;
use slog::{debug, Logger};
use std::collections::BTreeSet;
use std::convert::Infallible;
use std::sync::Arc;
Expand All @@ -25,6 +25,24 @@ pub(crate) fn with_logger(
warp::any().map(move || logger.clone())
}

/// Log to apply each time a route is called
///
/// Example of log produced: `POST /aggregator/register-signatures 202 Accepted`
pub(crate) fn log_route_call(
dependency_manager: &DependencyContainer,
) -> warp::log::Log<impl Fn(warp::log::Info<'_>) + Clone> {
let logger = http_server_child_logger(&dependency_manager.root_logger);
warp::log::custom(move |info| {
debug!(
logger,
"{} {} {}",
info.method(),
info.path(),
info.status()
)
})
}

/// With certificate pending store
pub(crate) fn with_certificate_pending_store(
dependency_manager: &DependencyContainer,
Expand Down
5 changes: 2 additions & 3 deletions mithril-aggregator/src/http_server/routes/proof_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ mod handlers {
) -> Result<impl warp::Reply, Infallible> {
let transaction_hashes = transaction_parameters.split_transactions_hashes();
debug!(
logger,
"⇄ HTTP SERVER: proof_cardano_transaction?transaction_hashes={}",
transaction_parameters.transaction_hashes
logger, ">> proof_cardano_transaction";
"transaction_hashes" => &transaction_parameters.transaction_hashes
);

if let Err(error) = validator.validate(&transaction_hashes) {
Expand Down
Loading

0 comments on commit 0d4d6bc

Please sign in to comment.