Skip to content

Commit

Permalink
Update launcher traces to have request ids for http requests (#695)
Browse files Browse the repository at this point in the history
* Update launcher traces to have automatic request_id attached for http requests

* Update once_cell version to v1 to make it less restrictive

* Update eth-bytecode-db to use updated tracing launcher

* Update CompactSpanBuilder to handle cases when tracing is disabled

* Update cargo.lock

* Make sea-orm logs to have DEBUG level

* Update Cargo.lock

* Remove 'message' keywords from tracing details

* Set verifier_alliance_database log level to be debug

* Remove excessive verifier test_case
  • Loading branch information
rimrakhimov authored Dec 18, 2023
1 parent 62a05e4 commit b5bac55
Show file tree
Hide file tree
Showing 26 changed files with 348 additions and 162 deletions.
41 changes: 39 additions & 2 deletions eth-bytecode-db/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 eth-bytecode-db/eth-bytecode-db-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ amplify = { version = "3.13.0", features = ["derive"] }
anyhow = "1.0"
async-trait = "0.1"
blockscout-display-bytes = "1.0"
blockscout-service-launcher = { version = "0.9.0", features = [ "database-0_12" ] }
blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs/", branch = "rimrakhimov/verifier/tracing-logs", features = [ "database-0_12" ] }
config = "0.13"
ethers = "2.0.0"
sea-orm = "0.12.2"
Expand All @@ -33,7 +33,7 @@ smart-contract-verifier-proto = { git = "https://github.com/blockscout/blockscou
verifier-alliance-entity = { path = "../eth-bytecode-db/verifier-alliance-entity" }
verifier-alliance-migration = { path = "../eth-bytecode-db/verifier-alliance-migration" }

blockscout-service-launcher = { version = "*", features = [ "test-server", "test-database" ] }
blockscout-service-launcher = { git = "https://github.com/blockscout/blockscout-rs/", branch = "rimrakhimov/verifier/tracing-logs", features = [ "test-server", "test-database", "database-0_12" ] }
bytes = "1.5.0"
hex = "0.4.3"
mockall = "0.11"
Expand Down
25 changes: 17 additions & 8 deletions eth-bytecode-db/eth-bytecode-db-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
use blockscout_service_launcher::{database, launcher, launcher::LaunchSettings, tracing};
use eth_bytecode_db::verification::Client;
use migration::Migrator;
use sea_orm::ConnectOptions;
use std::{collections::HashSet, sync::Arc};

const SERVICE_NAME: &str = "eth_bytecode_db";
Expand Down Expand Up @@ -76,17 +77,25 @@ pub async fn run(settings: Settings) -> Result<(), anyhow::Error> {

let health = Arc::new(HealthService::default());

let db_connection = database::initialize_postgres::<Migrator>(
&settings.database.url,
settings.database.create_database,
settings.database.run_migrations,
)
.await?;
let db_connection = {
let mut connect_options = ConnectOptions::new(settings.database.url);
connect_options.sqlx_logging_level(::tracing::log::LevelFilter::Debug);

database::initialize_postgres::<Migrator>(
connect_options,
settings.database.create_database,
settings.database.run_migrations,
)
.await?
};

let mut client = Client::new(db_connection, settings.verifier.uri).await?;
if settings.verifier_alliance_database.enabled {
let alliance_db_connection =
sea_orm::Database::connect(settings.verifier_alliance_database.url).await?;
let alliance_db_connection = {
let mut connect_options = ConnectOptions::new(settings.verifier_alliance_database.url);
connect_options.sqlx_logging_level(::tracing::log::LevelFilter::Debug);
sea_orm::Database::connect(connect_options).await?
};
client = client.with_alliance_db(alliance_db_connection);
}

Expand Down
12 changes: 12 additions & 0 deletions eth-bytecode-db/eth-bytecode-db-server/src/services/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use eth_bytecode_db::{
verification::sourcify_from_etherscan,
};
use std::str::FromStr;
use tracing::instrument;

pub struct DatabaseService {
pub client: verification::Client,
Expand All @@ -32,6 +33,7 @@ impl DatabaseService {

#[async_trait]
impl Database for DatabaseService {
#[instrument(skip_all)]
async fn search_sources(
&self,
request: tonic::Request<SearchSourcesRequest>,
Expand All @@ -46,11 +48,16 @@ impl Database for DatabaseService {
Ok(tonic::Response::new(SearchSourcesResponse { sources }))
}

#[instrument(skip_all)]
async fn search_sourcify_sources(
&self,
request: tonic::Request<SearchSourcifySourcesRequest>,
) -> Result<tonic::Response<SearchSourcesResponse>, tonic::Status> {
let request = request.into_inner();
super::trace_request_metadata!(
chain_id = request.chain,
contract_address = request.address
);

let chain_id = request.chain;
let contract_address = request.address;
Expand All @@ -64,11 +71,16 @@ impl Database for DatabaseService {
}))
}

#[instrument(skip_all)]
async fn search_all_sources(
&self,
request: tonic::Request<SearchAllSourcesRequest>,
) -> Result<tonic::Response<SearchAllSourcesResponse>, tonic::Status> {
let request = request.into_inner();
super::trace_request_metadata!(
chain_id = request.chain,
contract_address = request.address
);

let bytecode_type = request.bytecode_type();
let bytecode = request.bytecode;
Expand Down
35 changes: 16 additions & 19 deletions eth-bytecode-db/eth-bytecode-db-server/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ fn is_key_authorized(
Ok(is_authorized)
}

macro_rules! trace_verification_request {
($prefix:expr, $contract_address:expr, $chain_id:expr) => {{
let request_id = blockscout_display_bytes::Bytes::from(uuid::Uuid::new_v4().as_bytes());
macro_rules! trace_request_metadata {
($($field:ident=$value:expr),+) => {
tracing::info!(
request_id = request_id.to_string(),
$($field = $value,)+
)
};
}

macro_rules! trace_verification_request {
($contract_address:expr, $chain_id:expr) => {{
$crate::services::trace_request_metadata!(
chain_id = $chain_id,
contract_address = $contract_address,
"{} verification request received",
$prefix
);
request_id
contract_address = $contract_address
)
}};
($prefix:expr, $request:expr) => {{
($request:expr) => {{
let chain_id = $request
.metadata
.as_ref()
Expand All @@ -58,15 +61,9 @@ macro_rules! trace_verification_request {
.as_ref()
.and_then(|metadata| metadata.contract_address.clone())
.unwrap_or_default();
let request_id = blockscout_display_bytes::Bytes::from(uuid::Uuid::new_v4().as_bytes());
tracing::info!(
request_id = request_id.to_string(),
chain_id = chain_id,
contract_address = contract_address,
"{} verification request received",
$prefix
);
request_id
$crate::services::trace_verification_request!(chain_id, contract_address)
}};
}

use trace_request_metadata;
use trace_verification_request;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use eth_bytecode_db::verification::{
compiler_versions, solidity_multi_part, solidity_standard_json, Client, VerificationRequest,
};
use std::collections::HashSet;
use tracing::instrument;

pub struct SolidityVerifierService {
client: Client,
Expand All @@ -34,12 +35,13 @@ impl SolidityVerifierService {

#[async_trait]
impl solidity_verifier_server::SolidityVerifier for SolidityVerifierService {
#[instrument(skip_all)]
async fn verify_multi_part(
&self,
request: tonic::Request<VerifySolidityMultiPartRequest>,
) -> Result<tonic::Response<VerifyResponse>, tonic::Status> {
let (metadata, _, request) = request.into_parts();
let request_id = super::trace_verification_request!("Solidity multi-part", &request);
super::trace_verification_request!(&request);

let bytecode_type = request.bytecode_type();
let verification_request = VerificationRequest {
Expand All @@ -58,22 +60,18 @@ impl solidity_verifier_server::SolidityVerifier for SolidityVerifierService {
.transpose()?,
is_authorized: super::is_key_authorized(&self.authorized_keys, metadata)?,
};
let result = solidity_multi_part::verify(
self.client.clone(),
verification_request,
request_id.clone(),
)
.await;
let result = solidity_multi_part::verify(self.client.clone(), verification_request).await;

verifier_base::process_verification_result(result, request_id)
verifier_base::process_verification_result(result)
}

#[instrument(skip_all)]
async fn verify_standard_json(
&self,
request: tonic::Request<VerifySolidityStandardJsonRequest>,
) -> Result<tonic::Response<VerifyResponse>, tonic::Status> {
let (metadata, _, request) = request.into_parts();
let request_id = super::trace_verification_request!("Solidity standard-json", &request);
super::trace_verification_request!(&request);

let bytecode_type = request.bytecode_type();
let verification_request = VerificationRequest {
Expand All @@ -89,16 +87,13 @@ impl solidity_verifier_server::SolidityVerifier for SolidityVerifierService {
.transpose()?,
is_authorized: super::is_key_authorized(&self.authorized_keys, metadata)?,
};
let result = solidity_standard_json::verify(
self.client.clone(),
verification_request,
request_id.clone(),
)
.await;
let result =
solidity_standard_json::verify(self.client.clone(), verification_request).await;

verifier_base::process_verification_result(result, request_id)
verifier_base::process_verification_result(result)
}

#[instrument(skip_all)]
async fn list_compiler_versions(
&self,
_request: tonic::Request<ListCompilerVersionsRequest>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::proto::{
};
use async_trait::async_trait;
use eth_bytecode_db::verification::{sourcify, sourcify_from_etherscan, Client};
use tracing::instrument;

pub struct SourcifyVerifierService {
client: Client,
Expand All @@ -18,13 +19,13 @@ impl SourcifyVerifierService {

#[async_trait]
impl sourcify_verifier_server::SourcifyVerifier for SourcifyVerifierService {
#[instrument(skip_all)]
async fn verify(
&self,
request: tonic::Request<VerifySourcifyRequest>,
) -> Result<tonic::Response<VerifyResponse>, tonic::Status> {
let request = request.into_inner();
let request_id =
super::trace_verification_request!("Sourcify verify", &request.address, &request.chain);
super::trace_verification_request!(&request.address, &request.chain);

let verification_request = sourcify::VerificationRequest {
address: request.address,
Expand All @@ -35,19 +36,16 @@ impl sourcify_verifier_server::SourcifyVerifier for SourcifyVerifierService {

let result = sourcify::verify(self.client.clone(), verification_request).await;

verifier_base::process_verification_result(result, request_id)
verifier_base::process_verification_result(result)
}

#[instrument(skip_all)]
async fn verify_from_etherscan(
&self,
request: tonic::Request<VerifyFromEtherscanSourcifyRequest>,
) -> Result<tonic::Response<VerifyResponse>, tonic::Status> {
let request = request.into_inner();
let request_id = super::trace_verification_request!(
"Sourcify verify-from-etherscan",
&request.address,
&request.chain
);
super::trace_verification_request!(&request.address, &request.chain);

let verification_request = sourcify_from_etherscan::VerificationRequest {
address: request.address,
Expand All @@ -57,6 +55,6 @@ impl sourcify_verifier_server::SourcifyVerifier for SourcifyVerifierService {
let result =
sourcify_from_etherscan::verify(self.client.clone(), verification_request).await;

verifier_base::process_verification_result(result, request_id)
verifier_base::process_verification_result(result)
}
}
Loading

0 comments on commit b5bac55

Please sign in to comment.