Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sqlx log level #33

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ INGESTER_METRICS_PORT_SECOND_CONSUMER=9095
INGESTER_BG_TASK_RUNNER_METRICS_PORT=9093
INGESTER_BACKFILL_CONSUMER_METRICS_PORT=9096

INGESTER_SQL_LOG_LEVEL="error"

APP_DATABASE_URL="postgres://solana:solana@localhost:5432/solana"
APP_SERVER_PORT=9090
APP_METRICS_PORT=8125
Expand Down
1 change: 1 addition & 0 deletions nft_ingester/scripts/run_ingester.bash
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export INGESTER_SYNCHRONIZER_BATCH_SIZE=500
export PEER_GRPC_PORT=9091
export PEER_GRPC_MAX_GAP_SLOTS=1000000

export INGESTER_SQL_LOG_LEVEL="error"
cargo run --package nft_ingester --bin ingester
# start with restore rocks DB
#cargo run --package nft_ingester --bin ingester -- --restore-rocks-db
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_sql_log_level(),
100,
max_postgre_connections,
)
Expand Down
18 changes: 14 additions & 4 deletions nft_ingester/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ 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>,
pub sql_log_level: Option<String>,
}

impl IngesterConfig {
Expand Down Expand Up @@ -122,6 +124,13 @@ 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())
}
pub fn get_sql_log_level(&self) -> String {
self.sql_log_level.clone().unwrap_or("error".to_string())
}
}

// Types and constants used for Figment configuration items.
Expand Down Expand Up @@ -364,7 +373,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 +385,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();
}
14 changes: 11 additions & 3 deletions postgre-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
PgPool, Postgres, QueryBuilder, Row, Transaction,
ConnectOptions, PgPool, Postgres, QueryBuilder, Row, Transaction,
};
use std::collections::HashMap;
use std::str::FromStr;
use tracing::log::LevelFilter;

pub mod asset_filter_client;
pub mod asset_index_client;
Expand All @@ -15,8 +17,14 @@ pub struct PgClient {
}

impl PgClient {
pub async fn new(url: &str, min_connections: u32, max_connections: u32) -> Self {
let options: PgConnectOptions = url.parse().unwrap();
pub async fn new(
url: &str,
log_level: &str,
min_connections: u32,
max_connections: u32,
) -> Self {
let mut options: PgConnectOptions = url.parse().unwrap();
options.log_statements(LevelFilter::from_str(log_level).unwrap_or(LevelFilter::Warn));

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