Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RequescoS committed Jan 4, 2024
1 parent 6823c42 commit cc77a5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion nft_ingester/src/bin/ingester/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub async fn main() -> Result<(), IngesterError> {
info!("Starting Ingester");
let args = Args::parse();

init_logger();
let config: IngesterConfig = setup_config();
init_logger(&config.get_log_level());
let bg_tasks_config = config
.clone()
.background_task_runner_config
Expand Down Expand Up @@ -297,6 +297,7 @@ pub async fn main() -> Result<(), IngesterError> {
let index_storage = Arc::new(
PgClient::new(
&config.database_config.get_database_url().unwrap(),
&config.get_log_level(),
100,
max_postgre_connections,
)
Expand Down
14 changes: 10 additions & 4 deletions nft_ingester/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct IngesterConfig {
pub gapfiller_peer_addr: String,
pub peer_grpc_port: u16,
pub peer_grpc_max_gap_slots: u64,
pub rust_log: Option<String>,
}

impl IngesterConfig {
Expand Down Expand Up @@ -122,6 +123,10 @@ impl IngesterConfig {
pub fn get_is_snapshot(&self) -> bool {
self.is_snapshot.unwrap_or_default()
}

pub fn get_log_level(&self) -> String {
self.rust_log.clone().unwrap_or("warn".to_string())
}
}

// Types and constants used for Figment configuration items.
Expand Down Expand Up @@ -364,7 +369,9 @@ impl PeerDiscovery for IngesterConfig {
}

pub fn setup_config<'a, T: Deserialize<'a>>() -> T {
let figment = Figment::new().join(Env::prefixed("INGESTER_"));
let figment = Figment::new()
.join(Env::prefixed("INGESTER_"))
.join(Env::raw());

figment
.extract()
Expand All @@ -374,8 +381,7 @@ pub fn setup_config<'a, T: Deserialize<'a>>() -> T {
.unwrap()
}

pub fn init_logger() {
let env_filter = env::var("RUST_LOG").unwrap_or("info".to_string());
let t = tracing_subscriber::fmt().with_env_filter(env_filter);
pub fn init_logger(log_level: &str) {
let t = tracing_subscriber::fmt().with_env_filter(log_level);
t.event_format(fmt::format::json()).init();
}
11 changes: 7 additions & 4 deletions postgre-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use sqlx::{
ConnectOptions, PgPool, Postgres, QueryBuilder, Row, Transaction,
};
use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use tracing::log::LevelFilter;

Expand All @@ -18,10 +17,14 @@ pub struct PgClient {
}

impl PgClient {
pub async fn new(url: &str, min_connections: u32, max_connections: u32) -> Self {
pub async fn new(
url: &str,
log_level: &str,
min_connections: u32,
max_connections: u32,
) -> Self {
let mut options: PgConnectOptions = url.parse().unwrap();
let log_statements = env::var("RUST_LOG").unwrap_or_else(|_| "warn".to_string());
options.log_statements(LevelFilter::from_str(&log_statements).unwrap_or(LevelFilter::Warn));
options.log_statements(LevelFilter::from_str(log_level).unwrap_or(LevelFilter::Warn));

let pool = PgPoolOptions::new()
.min_connections(min_connections)
Expand Down

0 comments on commit cc77a5c

Please sign in to comment.