mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 01:57:45 +08:00 
			
		
		
		
	fix(router_env): resolve/remove FIXME's and redundent files (#168)
				
					
				
			This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @ -2799,6 +2799,7 @@ dependencies = [ | |||||||
|  "rustc-hash", |  "rustc-hash", | ||||||
|  "serde", |  "serde", | ||||||
|  "serde_json", |  "serde_json", | ||||||
|  |  "serde_path_to_error", | ||||||
|  "strum", |  "strum", | ||||||
|  "time", |  "time", | ||||||
|  "tokio", |  "tokio", | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ opentelemetry-otlp = { git = "https://github.com/open-telemetry/opentelemetry-ru | |||||||
| rustc-hash = "1.1" | rustc-hash = "1.1" | ||||||
| serde = { version = "1.0.149", features = ["derive"] } | serde = { version = "1.0.149", features = ["derive"] } | ||||||
| serde_json = "1.0.89" | serde_json = "1.0.89" | ||||||
|  | serde_path_to_error = "0.1.8" | ||||||
| strum = { version = "0.24.1", features = ["derive"] } | strum = { version = "0.24.1", features = ["derive"] } | ||||||
| time = { version = "0.3.17", default-features = false, features = ["formatting"] } | time = { version = "0.3.17", default-features = false, features = ["formatting"] } | ||||||
| tokio = { version = "1.23.0" } | tokio = { version = "1.23.0" } | ||||||
|  | |||||||
| @ -22,8 +22,6 @@ pub fn sample() -> () { | |||||||
|  |  | ||||||
| ## Files Tree Layout | ## Files Tree Layout | ||||||
|  |  | ||||||
| <!-- FIXME: fill missing --> |  | ||||||
|  |  | ||||||
| ```text | ```text | ||||||
| ├── src                        : source code | ├── src                        : source code | ||||||
| │   └── logger                 : logger | │   └── logger                 : logger | ||||||
|  | |||||||
| @ -115,22 +115,15 @@ impl Config { | |||||||
|         let environment = crate::env::which(); |         let environment = crate::env::which(); | ||||||
|         let config_path = Self::config_path(&environment.to_string(), explicit_config_path); |         let config_path = Self::config_path(&environment.to_string(), explicit_config_path); | ||||||
|  |  | ||||||
|         // println!( |  | ||||||
|         //     "config_path : {:?} {:?}", |  | ||||||
|         //     config_path, |  | ||||||
|         //     std::path::Path::new(&config_path).exists() |  | ||||||
|         // ); |  | ||||||
|  |  | ||||||
|         let config = Self::builder(&environment.to_string())? |         let config = Self::builder(&environment.to_string())? | ||||||
|             .add_source(config::File::from(config_path).required(true)) |             .add_source(config::File::from(config_path).required(true)) | ||||||
|             .add_source(config::Environment::with_prefix("ROUTER").separator("__")) |             .add_source(config::Environment::with_prefix("ROUTER").separator("__")) | ||||||
|             .build()?; |             .build()?; | ||||||
|         // FIXME: in case config is missing information about error is not readable |  | ||||||
|  |  | ||||||
|         config.try_deserialize().map_err(|e| { |         serde_path_to_error::deserialize(config).map_err(|error| { | ||||||
|             crate::error!("Unable to source config file"); |             crate::error!(%error, "Unable to deserialize configuration"); | ||||||
|             eprintln!("Unable to source config file"); |             eprintln!("Unable to deserialize application configuration: {error}"); | ||||||
|             e |             error.into_inner() | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -144,6 +137,7 @@ impl Config { | |||||||
|             // Should be single source of truth. |             // Should be single source of truth. | ||||||
|             .set_override("env", environment)? |             .set_override("env", environment)? | ||||||
|             .add_source(config::File::from_str( |             .add_source(config::File::from_str( | ||||||
|  |                 // Plan on handling with the changes in crates/router | ||||||
|                 // FIXME: embedding of textual file into bin files has several disadvantages |                 // FIXME: embedding of textual file into bin files has several disadvantages | ||||||
|                 // 1. larger bin file |                 // 1. larger bin file | ||||||
|                 // 2. slower initialization of program |                 // 2. slower initialization of program | ||||||
|  | |||||||
| @ -22,8 +22,7 @@ use tracing_subscriber::{ | |||||||
| }; | }; | ||||||
|  |  | ||||||
| use crate::Storage; | use crate::Storage; | ||||||
|  | // TODO: Documentation coverage for this crate | ||||||
| // FIXME: xxx: Describe each implicit field with examples. |  | ||||||
|  |  | ||||||
| // Implicit keys | // Implicit keys | ||||||
|  |  | ||||||
| @ -52,14 +51,6 @@ const REQUEST_METHOD: &str = "request_method"; | |||||||
| const REQUEST_URL_PATH: &str = "request_url_path"; | const REQUEST_URL_PATH: &str = "request_url_path"; | ||||||
| const REQUEST_ID: &str = "request_id"; | const REQUEST_ID: &str = "request_id"; | ||||||
|  |  | ||||||
| //const TAG: &str = "tag"; |  | ||||||
| //const CATEGORY: &str = "category"; |  | ||||||
| //const SESSION_ID: &str = "session_id"; |  | ||||||
| //const PAYMENT_ID: &str = "payment_id"; |  | ||||||
| //const PAYMENT_ATTEMPT_ID: &str = "payment_attempt_id"; |  | ||||||
| //const MERCHANT_ID: &str = "merchant_id"; |  | ||||||
| //const FLOW: &str = "flow"; |  | ||||||
|  |  | ||||||
| /// Set of predefined implicit keys. | /// Set of predefined implicit keys. | ||||||
| pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| { | pub static IMPLICIT_KEYS: Lazy<rustc_hash::FxHashSet<&str>> = Lazy::new(|| { | ||||||
|     let mut set = rustc_hash::FxHashSet::default(); |     let mut set = rustc_hash::FxHashSet::default(); | ||||||
|  | |||||||
| @ -1,104 +0,0 @@ | |||||||
| //! |  | ||||||
| //! Macros. |  | ||||||
| //! |  | ||||||
|  |  | ||||||
| pub use crate::log; |  | ||||||
|  |  | ||||||
| /// |  | ||||||
| /// Make a new log Event. |  | ||||||
| /// |  | ||||||
| /// The event macro is invoked with a Level and up to 32 key-value fields. |  | ||||||
| /// Optionally, a format string and arguments may follow the fields; this will be used to construct an implicit field named “message”. |  | ||||||
| /// See the top-level [documentation of tracing](https://docs.rs/tracing/latest/tracing/index.html#using-the-macros) for details on the syntax accepted by this macro. |  | ||||||
| /// |  | ||||||
| /// # Example |  | ||||||
| /// ```rust |  | ||||||
| /// // FIXME: write |  | ||||||
| /// ``` |  | ||||||
| /// |  | ||||||
|  |  | ||||||
| #[macro_export] |  | ||||||
| macro_rules! log { |  | ||||||
|  |  | ||||||
|     // done |  | ||||||
|  |  | ||||||
|     ( |  | ||||||
|         @MUNCH |  | ||||||
|         { |  | ||||||
|             level : { $level:ident }, |  | ||||||
|             tag : { $tag:ident }, |  | ||||||
|             category : { $category:ident }, |  | ||||||
|             flow : { $flow:expr }, |  | ||||||
|             // $( session_id : { $session_id:expr }, )? |  | ||||||
|             // $( payment_id : { $payment_id:expr }, )? |  | ||||||
|             // $( payment_attempt_id : { $payment_attempt_id:expr }, )? |  | ||||||
|             // $( merchant_id : { $merchant_id:expr }, )? |  | ||||||
|         }, |  | ||||||
|         $( $tail:tt )* |  | ||||||
|     ) |  | ||||||
|     => |  | ||||||
|     ( |  | ||||||
|         ::tracing::event! |  | ||||||
|         ( |  | ||||||
|             ::router_env::Level::$level, |  | ||||||
|             level = ?::router_env::Level::$level, |  | ||||||
|             tag = ?::router_env::Tag::$tag, |  | ||||||
|             category = ?::router_env::Category::$category, |  | ||||||
|             flow = ?$flow, |  | ||||||
|             // $( session_id = $session_id, )? |  | ||||||
|             // $( payment_id = $payment_id, )? |  | ||||||
|             // $( payment_attempt_id = $payment_attempt_id, )? |  | ||||||
|             // $( merchant_id = $merchant_id, )? |  | ||||||
|             $( $tail )* |  | ||||||
|         ); |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     // entry with colon |  | ||||||
|  |  | ||||||
|     ( |  | ||||||
|         level : $level:ident, |  | ||||||
|         tag : $tag:ident, |  | ||||||
|         category : $category:ident, |  | ||||||
|         flow : $(?)?$flow:expr, |  | ||||||
|         $( $tail:tt )* |  | ||||||
|     ) |  | ||||||
|     => |  | ||||||
|     ( |  | ||||||
|         $crate::log! |  | ||||||
|         { |  | ||||||
|             @MUNCH |  | ||||||
|             { |  | ||||||
|                 level : { $level }, |  | ||||||
|                 tag : { $tag }, |  | ||||||
|                 category : { $category }, |  | ||||||
|                 flow : { $flow }, |  | ||||||
|             }, |  | ||||||
|             $( $tail )* |  | ||||||
|         } |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     // entry without colon |  | ||||||
|  |  | ||||||
|     ( |  | ||||||
|         $level:ident, |  | ||||||
|         $tag:ident, |  | ||||||
|         $category:ident, |  | ||||||
|         $flow:expr, |  | ||||||
|         $( $tail:tt )* |  | ||||||
|     ) |  | ||||||
|     => |  | ||||||
|     ( |  | ||||||
|         $crate::log! |  | ||||||
|         { |  | ||||||
|             @MUNCH |  | ||||||
|             { |  | ||||||
|                 level : { $level }, |  | ||||||
|                 tag : { $tag }, |  | ||||||
|                 category : { $category }, |  | ||||||
|                 flow : { $flow }, |  | ||||||
|             }, |  | ||||||
|             $( $tail )* |  | ||||||
|         } |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @ -22,30 +22,6 @@ use tracing_subscriber::{ | |||||||
|  |  | ||||||
| use crate::{config, FormattingLayer, Level, StorageSubscription}; | use crate::{config, FormattingLayer, Level, StorageSubscription}; | ||||||
|  |  | ||||||
| // FIXME: xxx: clean |  | ||||||
| pub struct DebugLayer; |  | ||||||
| impl<S> Layer<S> for DebugLayer |  | ||||||
| where |  | ||||||
|     S: tracing::Subscriber, |  | ||||||
| { |  | ||||||
|     fn on_event( |  | ||||||
|         &self, |  | ||||||
|         event: &tracing::Event<'_>, |  | ||||||
|         _ctx: tracing_subscriber::layer::Context<'_, S>, |  | ||||||
|     ) { |  | ||||||
|         if event.metadata().level() == &Level::TRACE { |  | ||||||
|             return; |  | ||||||
|         } |  | ||||||
|         println!("Got event!"); |  | ||||||
|         println!("  level={:?}", event.metadata().level()); |  | ||||||
|         println!("  target={:?}", event.metadata().target()); |  | ||||||
|         println!("  name={:?}", event.metadata().name()); |  | ||||||
|         for field in event.fields() { |  | ||||||
|             println!("  field={}", field.name()); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /// TelemetryGuard which helps with | /// TelemetryGuard which helps with | ||||||
| #[derive(Debug)] | #[derive(Debug)] | ||||||
| pub struct TelemetryGuard { | pub struct TelemetryGuard { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Nishant Joshi
					Nishant Joshi