Skip to content

Commit

Permalink
Merge pull request #2002 from input-output-hk/djo/1981/enhance_logs_i…
Browse files Browse the repository at this point in the history
…n_aggregator

Enhance logs construction and usage in aggregator
  • Loading branch information
Alenar authored Oct 14, 2024
2 parents a404b02 + 01bf63f commit 28dd7ae
Show file tree
Hide file tree
Showing 57 changed files with 917 additions and 518 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.

4 changes: 2 additions & 2 deletions 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.80"
version = "0.5.81"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down Expand Up @@ -44,7 +44,6 @@ slog = { version = "2.7.0", features = [
] }
slog-async = "2.8.0"
slog-bunyan = "2.5.0"
slog-scope = "4.4.0"
sqlite = { version = "0.36.1", features = ["bundled"] }
tar = "0.4.41"
thiserror = "1.0.63"
Expand All @@ -70,6 +69,7 @@ mithril-common = { path = "../mithril-common", features = [
"test_tools",
] }
mockall = "0.13.0"
slog-scope = "4.4.0"
slog-term = "2.9.1"
tempfile = "3.12.0"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use async_trait::async_trait;
use semver::Version;
use slog_scope::{debug, warn};
use slog::{debug, warn, Logger};
use std::sync::Arc;
use thiserror::Error;

Expand All @@ -11,6 +11,7 @@ use crate::{
};

use super::ArtifactBuilder;
use mithril_common::logging::LoggerExtensions;
use mithril_common::{
entities::{
CardanoDbBeacon, Certificate, CompressionAlgorithm, ProtocolMessagePartKey, Snapshot,
Expand All @@ -33,6 +34,7 @@ pub struct CardanoImmutableFilesFullArtifactBuilder {
snapshotter: Arc<dyn Snapshotter>,
snapshot_uploader: Arc<dyn SnapshotUploader>,
compression_algorithm: CompressionAlgorithm,
logger: Logger,
}

impl CardanoImmutableFilesFullArtifactBuilder {
Expand All @@ -42,12 +44,14 @@ impl CardanoImmutableFilesFullArtifactBuilder {
snapshotter: Arc<dyn Snapshotter>,
snapshot_uploader: Arc<dyn SnapshotUploader>,
compression_algorithm: CompressionAlgorithm,
logger: Logger,
) -> Self {
Self {
cardano_node_version: cardano_node_version.clone(),
snapshotter,
snapshot_uploader,
compression_algorithm,
logger: logger.new_with_component_name::<Self>(),
}
}

Expand All @@ -56,7 +60,10 @@ impl CardanoImmutableFilesFullArtifactBuilder {
beacon: &CardanoDbBeacon,
snapshot_digest: &str,
) -> StdResult<OngoingSnapshot> {
debug!("CardanoImmutableFilesFullArtifactBuilder: create snapshot archive");
debug!(
self.logger,
"CardanoImmutableFilesFullArtifactBuilder: create snapshot archive"
);

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

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

Ok(ongoing_snapshot)
}
Expand All @@ -83,16 +90,19 @@ impl CardanoImmutableFilesFullArtifactBuilder {
&self,
ongoing_snapshot: &OngoingSnapshot,
) -> StdResult<Vec<SnapshotLocation>> {
debug!("CardanoImmutableFilesFullArtifactBuilder: upload snapshot archive");
debug!(
self.logger,
"CardanoImmutableFilesFullArtifactBuilder: 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!(
" > Post upload ongoing snapshot file removal failure: {}",
error
self.logger,
" > Post upload ongoing snapshot file removal failure: {error}"
);
}

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

let snapshot = Snapshot::new(
snapshot_digest,
Expand Down Expand Up @@ -167,7 +180,10 @@ mod tests {

use super::*;

use crate::{snapshot_uploaders::MockSnapshotUploader, DumbSnapshotUploader, DumbSnapshotter};
use crate::{
snapshot_uploaders::MockSnapshotUploader, test_tools::TestLogger, DumbSnapshotUploader,
DumbSnapshotter,
};

#[tokio::test]
async fn should_compute_valid_artifact() {
Expand All @@ -187,6 +203,7 @@ mod tests {
dumb_snapshotter.clone(),
dumb_snapshot_uploader.clone(),
CompressionAlgorithm::Zstandard,
TestLogger::stdout(),
);
let artifact = cardano_immutable_files_full_artifact_builder
.compute_artifact(beacon.clone(), &certificate)
Expand Down Expand Up @@ -224,6 +241,7 @@ mod tests {
Arc::new(DumbSnapshotter::new()),
Arc::new(DumbSnapshotUploader::new()),
CompressionAlgorithm::default(),
TestLogger::stdout(),
);

cardano_immutable_files_full_artifact_builder
Expand All @@ -248,6 +266,7 @@ mod tests {
Arc::new(DumbSnapshotter::new()),
Arc::new(DumbSnapshotUploader::new()),
CompressionAlgorithm::Gzip,
TestLogger::stdout(),
);

let ongoing_snapshot = cardano_immutable_files_full_artifact_builder
Expand Down Expand Up @@ -275,6 +294,7 @@ mod tests {
Arc::new(DumbSnapshotter::new()),
Arc::new(DumbSnapshotUploader::new()),
algorithm,
TestLogger::stdout(),
);

let ongoing_snapshot = cardano_immutable_files_full_artifact_builder
Expand Down Expand Up @@ -316,6 +336,7 @@ mod tests {
Arc::new(DumbSnapshotter::new()),
Arc::new(snapshot_uploader),
CompressionAlgorithm::default(),
TestLogger::stdout(),
);

cardano_immutable_files_full_artifact_builder
Expand Down
5 changes: 1 addition & 4 deletions mithril-aggregator/src/artifact_builder/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ use mithril_common::{
StdResult,
};

#[cfg(test)]
use mockall::automock;

/// ArtifactBuilder is trait for building an artifact
#[cfg_attr(test, automock)]
#[cfg_attr(test, mockall::automock)]
#[async_trait]
pub trait ArtifactBuilder<U, W>: Send + Sync
where
Expand Down
38 changes: 28 additions & 10 deletions mithril-aggregator/src/commands/era_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use mithril_common::{
entities::{Epoch, HexEncodedEraMarkersSecretKey},
StdResult,
};
use slog_scope::debug;
use slog::{debug, Logger};

use crate::tools::EraTools;

Expand All @@ -21,8 +21,14 @@ pub struct EraCommand {
}

impl EraCommand {
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> StdResult<()> {
self.era_subcommand.execute(config_builder).await
pub async fn execute(
&self,
root_logger: Logger,
config_builder: ConfigBuilder<DefaultState>,
) -> StdResult<()> {
self.era_subcommand
.execute(root_logger, config_builder)
.await
}
}

Expand All @@ -37,10 +43,14 @@ pub enum EraSubCommand {
}

impl EraSubCommand {
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> StdResult<()> {
pub async fn execute(
&self,
root_logger: Logger,
config_builder: ConfigBuilder<DefaultState>,
) -> StdResult<()> {
match self {
Self::List(cmd) => cmd.execute(config_builder).await,
Self::GenerateTxDatum(cmd) => cmd.execute(config_builder).await,
Self::List(cmd) => cmd.execute(root_logger, config_builder).await,
Self::GenerateTxDatum(cmd) => cmd.execute(root_logger, config_builder).await,
}
}
}
Expand All @@ -54,8 +64,12 @@ pub struct ListEraSubCommand {
}

impl ListEraSubCommand {
pub async fn execute(&self, _config_builder: ConfigBuilder<DefaultState>) -> StdResult<()> {
debug!("LIST ERA command");
pub async fn execute(
&self,
root_logger: Logger,
_config_builder: ConfigBuilder<DefaultState>,
) -> StdResult<()> {
debug!(root_logger, "LIST ERA command");
let era_tools = EraTools::new();
let eras = era_tools.get_supported_eras_list()?;

Expand Down Expand Up @@ -91,8 +105,12 @@ pub struct GenerateTxDatumEraSubCommand {
}

impl GenerateTxDatumEraSubCommand {
pub async fn execute(&self, _config_builder: ConfigBuilder<DefaultState>) -> StdResult<()> {
debug!("GENERATETXDATUM ERA command");
pub async fn execute(
&self,
root_logger: Logger,
_config_builder: ConfigBuilder<DefaultState>,
) -> StdResult<()> {
debug!(root_logger, "GENERATETXDATUM ERA command");
let era_tools = EraTools::new();

let era_markers_secret_key =
Expand Down
Loading

0 comments on commit 28dd7ae

Please sign in to comment.