Skip to content

Commit b409dd0

Browse files
committed
refactor(aggregator): general log function for http server route calls
There is a caveat: payload and query strings can't be logs this way, so in this cas a local "function enter" log is done. This ensure that those data are logged at the price of routes producing two logs for one call.
1 parent 2b840e2 commit b409dd0

13 files changed

+36
-61
lines changed

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub mod handlers {
5252
use crate::services::MessageService;
5353

5454
use mithril_common::entities::Epoch;
55-
use slog::{debug, warn, Logger};
55+
use slog::{warn, Logger};
5656
use std::convert::Infallible;
5757
use std::sync::Arc;
5858
use warp::http::StatusCode;
@@ -64,8 +64,6 @@ pub mod handlers {
6464
logger: Logger,
6565
http_message_service: Arc<dyn MessageService>,
6666
) -> Result<impl warp::Reply, Infallible> {
67-
debug!(logger, "GET /artifact/cardano-stake-distributions");
68-
6967
match http_message_service
7068
.get_cardano_stake_distribution_list_message(LIST_MAX_ITEMS)
7169
.await
@@ -84,11 +82,6 @@ pub mod handlers {
8482
logger: Logger,
8583
http_message_service: Arc<dyn MessageService>,
8684
) -> Result<impl warp::Reply, Infallible> {
87-
debug!(
88-
logger,
89-
"GET /artifact/cardano-stake-distribution/{signed_entity_id}"
90-
);
91-
9285
match http_message_service
9386
.get_cardano_stake_distribution_message(&signed_entity_id)
9487
.await
@@ -111,11 +104,6 @@ pub mod handlers {
111104
logger: Logger,
112105
http_message_service: Arc<dyn MessageService>,
113106
) -> Result<impl warp::Reply, Infallible> {
114-
debug!(
115-
logger,
116-
"GET /artifact/cardano-stake-distributions/epoch/{epoch}"
117-
);
118-
119107
let artifact_epoch = match epoch.parse::<u64>() {
120108
Ok(epoch) => Epoch(epoch),
121109
Err(err) => {

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub mod handlers {
3535
use crate::http_server::routes::reply;
3636
use crate::services::MessageService;
3737

38-
use slog::{debug, warn, Logger};
38+
use slog::{warn, Logger};
3939
use std::convert::Infallible;
4040
use std::sync::Arc;
4141
use warp::http::StatusCode;
@@ -47,8 +47,6 @@ pub mod handlers {
4747
logger: Logger,
4848
http_message_service: Arc<dyn MessageService>,
4949
) -> Result<impl warp::Reply, Infallible> {
50-
debug!(logger, "GET /artifact/cardano-transactions");
51-
5250
match http_message_service
5351
.get_cardano_transaction_list_message(LIST_MAX_ITEMS)
5452
.await
@@ -68,11 +66,6 @@ pub mod handlers {
6866
logger: Logger,
6967
http_message_service: Arc<dyn MessageService>,
7068
) -> Result<impl warp::Reply, Infallible> {
71-
debug!(
72-
logger,
73-
"GET /artifact/cardano-transaction/{signed_entity_id}"
74-
);
75-
7669
match http_message_service
7770
.get_cardano_transaction_message(&signed_entity_id)
7871
.await

mithril-aggregator/src/http_server/routes/artifact_routes/mithril_stake_distribution.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub mod handlers {
3636
use crate::http_server::routes::reply;
3737
use crate::services::MessageService;
3838

39-
use slog::{debug, warn, Logger};
39+
use slog::{warn, Logger};
4040
use std::convert::Infallible;
4141
use std::sync::Arc;
4242
use warp::http::StatusCode;
@@ -48,8 +48,6 @@ pub mod handlers {
4848
logger: Logger,
4949
http_message_service: Arc<dyn MessageService>,
5050
) -> Result<impl warp::Reply, Infallible> {
51-
debug!(logger, "GET /artifact/mithril-stake-distributions");
52-
5351
match http_message_service
5452
.get_mithril_stake_distribution_list_message(LIST_MAX_ITEMS)
5553
.await
@@ -68,11 +66,6 @@ pub mod handlers {
6866
logger: Logger,
6967
http_message_service: Arc<dyn MessageService>,
7068
) -> Result<impl warp::Reply, Infallible> {
71-
debug!(
72-
logger,
73-
"GET /artifact/mithril-stake-distribution/{signed_entity_id}"
74-
);
75-
7669
match http_message_service
7770
.get_mithril_stake_distribution_message(&signed_entity_id)
7871
.await

mithril-aggregator/src/http_server/routes/artifact_routes/snapshot.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ mod handlers {
109109
logger: Logger,
110110
http_message_service: Arc<dyn MessageService>,
111111
) -> Result<impl warp::Reply, Infallible> {
112-
debug!(logger, "GET /artifact/snapshots");
113-
114112
match http_message_service
115113
.get_snapshot_list_message(LIST_MAX_ITEMS)
116114
.await
@@ -129,7 +127,6 @@ mod handlers {
129127
logger: Logger,
130128
http_message_service: Arc<dyn MessageService>,
131129
) -> Result<impl warp::Reply, Infallible> {
132-
debug!(logger, "GET /artifact/snapshot/{signed_entity_id}");
133130
match http_message_service
134131
.get_snapshot_message(&signed_entity_id)
135132
.await
@@ -188,8 +185,6 @@ mod handlers {
188185
config: Configuration,
189186
signed_entity_service: Arc<dyn SignedEntityService>,
190187
) -> Result<impl warp::Reply, Infallible> {
191-
debug!(logger, "GET /snapshot_download/snapshot/{digest}");
192-
193188
match signed_entity_service
194189
.get_signed_snapshot_by_id(&digest)
195190
.await

mithril-aggregator/src/http_server/routes/certificate_routes.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mod handlers {
5151
ToCertificatePendingMessageAdapter,
5252
};
5353

54-
use slog::{debug, warn, Logger};
54+
use slog::{warn, Logger};
5555
use std::convert::Infallible;
5656
use std::sync::Arc;
5757
use warp::http::StatusCode;
@@ -63,8 +63,6 @@ mod handlers {
6363
logger: Logger,
6464
certificate_pending_store: Arc<CertificatePendingStore>,
6565
) -> Result<impl warp::Reply, Infallible> {
66-
debug!(logger, "GET /certificate-pending");
67-
6866
match certificate_pending_store.get().await {
6967
Ok(Some(certificate_pending)) => Ok(reply::json(
7068
&ToCertificatePendingMessageAdapter::adapt(certificate_pending),
@@ -83,8 +81,6 @@ mod handlers {
8381
logger: Logger,
8482
http_message_service: Arc<dyn MessageService>,
8583
) -> Result<impl warp::Reply, Infallible> {
86-
debug!(logger, "GET /certificates");
87-
8884
match http_message_service
8985
.get_certificate_list_message(LIST_MAX_ITEMS)
9086
.await
@@ -103,8 +99,6 @@ mod handlers {
10399
logger: Logger,
104100
http_message_service: Arc<dyn MessageService>,
105101
) -> Result<impl warp::Reply, Infallible> {
106-
debug!(logger, "GET /certificate/{certificate_hash}");
107-
108102
match http_message_service
109103
.get_certificate_message(&certificate_hash)
110104
.await

mithril-aggregator/src/http_server/routes/epoch_routes.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ async fn get_epoch_settings_message(
6969
}
7070

7171
mod handlers {
72-
use slog::{debug, Logger};
72+
use slog::{warn, Logger};
7373
use std::collections::BTreeSet;
7474
use std::convert::Infallible;
7575
use warp::http::StatusCode;
@@ -86,13 +86,15 @@ mod handlers {
8686
epoch_service: EpochServiceWrapper,
8787
allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
8888
) -> Result<impl warp::Reply, Infallible> {
89-
debug!(logger, "GET /epoch-settings");
9089
let epoch_settings_message =
9190
get_epoch_settings_message(epoch_service, allowed_discriminants).await;
9291

9392
match epoch_settings_message {
9493
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
95-
Err(err) => Ok(reply::server_error(err)),
94+
Err(err) => {
95+
warn!(logger,"epoch_settings::error"; "error" => ?err);
96+
Ok(reply::server_error(err))
97+
}
9698
}
9799
}
98100
}

mithril-aggregator/src/http_server/routes/middlewares.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use slog::Logger;
1+
use slog::{debug, Logger};
22
use std::collections::BTreeSet;
33
use std::convert::Infallible;
44
use std::sync::Arc;
@@ -25,6 +25,24 @@ pub(crate) fn with_logger(
2525
warp::any().map(move || logger.clone())
2626
}
2727

28+
/// Log to apply each time a route is called
29+
///
30+
/// Example of log produced: `POST /aggregator/register-signatures 202 Accepted`
31+
pub(crate) fn log_route_call(
32+
dependency_manager: &DependencyContainer,
33+
) -> warp::log::Log<impl Fn(warp::log::Info<'_>) + Clone> {
34+
let logger = http_server_child_logger(&dependency_manager.root_logger);
35+
warp::log::custom(move |info| {
36+
debug!(
37+
logger,
38+
"{} {} {}",
39+
info.method(),
40+
info.path(),
41+
info.status()
42+
)
43+
})
44+
}
45+
2846
/// With certificate pending store
2947
pub(crate) fn with_certificate_pending_store(
3048
dependency_manager: &DependencyContainer,

mithril-aggregator/src/http_server/routes/proof_routes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ mod handlers {
7373
) -> Result<impl warp::Reply, Infallible> {
7474
let transaction_hashes = transaction_parameters.split_transactions_hashes();
7575
debug!(
76-
logger,
77-
"GET /proof/cardano-transaction?transaction_hashes={}",
78-
transaction_parameters.transaction_hashes
76+
logger, ">> proof_cardano_transaction";
77+
"transaction_hashes" => &transaction_parameters.transaction_hashes
7978
);
8079

8180
if let Err(error) = validator.validate(&transaction_hashes) {

mithril-aggregator/src/http_server/routes/root_routes.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod handlers {
2727
use std::collections::BTreeSet;
2828
use std::{convert::Infallible, sync::Arc};
2929

30-
use slog::{debug, Logger};
30+
use slog::Logger;
3131
use warp::http::StatusCode;
3232

3333
use mithril_common::api_version::APIVersionProvider;
@@ -46,8 +46,6 @@ mod handlers {
4646
allowed_signed_entity_type_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
4747
configuration: Configuration,
4848
) -> Result<impl warp::Reply, Infallible> {
49-
debug!(logger, "GET /");
50-
5149
let open_api_version = unwrap_to_internal_server_error!(
5250
api_version_provider.compute_current_version(),
5351
logger => "root::error"

mithril-aggregator/src/http_server/routes/router.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub fn routes(
7474
.to_string(),
7575
)
7676
})
77+
.with(middlewares::log_route_call(&dependency_manager))
7778
}
7879

7980
/// API Version verification

0 commit comments

Comments
 (0)