1717// ----------------------
1818// These are internal modules for handling the proxy logic, caching layers,
1919// configuration loading, and in-memory eviction based on memory pressure.
20- mod proxy;
21- mod storage;
22- mod memory;
2320mod config;
2421mod eviction;
22+ mod memory;
23+ mod proxy;
2524mod rules;
25+ mod storage;
2626
2727// ----------------------
2828// External dependencies
2929// ----------------------
30- use axum:: { routing:: get, Router } ; // Axum: Web framework for routing and request handling
31- use hyper:: Server ; // Hyper: High-performance HTTP server
32- use std:: { net:: SocketAddr , process:: exit} ; // Network + system utilities
30+ use axum:: { Router , routing:: get} ; // Axum: Web framework for routing and request handling
31+ use hyper:: Server ; // Hyper: High-performance HTTP server
32+ use std:: { net:: SocketAddr , process:: exit} ; // Network + system utilities
3333
34- use clap:: Parser ; // CLI argument parsing (via `--config`)
35- use tracing:: { info , warn , error } ; // Structured logging macros
36- use tracing_subscriber:: EnvFilter ; // Log filtering via LOG_LEVEL
34+ use clap:: Parser ; // CLI argument parsing (via `--config`)
35+ use tracing:: { error , info , warn } ; // Structured logging macros
36+ use tracing_subscriber:: EnvFilter ; // Log filtering via LOG_LEVEL
3737
3838// ----------------------
3939// Internal dependencies
4040// ----------------------
41- use crate :: config:: { Config , CONFIG , StorageBackend } ; // App-wide config definitions
42- use crate :: eviction:: start_background_eviction_task; // Memory pressure eviction
43- use crate :: storage:: { gcs, s3, azure} ; // Persistent storage backends
41+ use crate :: config:: { CONFIG , Config , StorageBackend } ; // App-wide config definitions
42+ use crate :: eviction:: start_background_eviction_task; // Memory pressure eviction
43+ use crate :: storage:: { azure, gcs, s3} ; // Persistent storage backends
44+ use metrics_exporter_prometheus:: PrometheusBuilder ;
4445
4546/// ----------------------------
4647/// CLI ARGUMENT STRUCTURE
@@ -79,9 +80,9 @@ fn init_logging(app_id: &str) {
7980 . unwrap_or_else ( |_| EnvFilter :: new ( "info" ) ) ;
8081
8182 tracing_subscriber:: fmt ( )
82- . with_env_filter ( filter) // Uses LOG_LEVEL to filter verbosity
83- . with_target ( false ) // Hides the module path in each log line
84- . compact ( ) // Compact single-line logs (less verbose)
83+ . with_env_filter ( filter) // Uses LOG_LEVEL to filter verbosity
84+ . with_target ( false ) // Hides the module path in each log line
85+ . compact ( ) // Compact single-line logs (less verbose)
8586 . init ( ) ;
8687
8788 info ! ( "🚀 Logging initialized for app_id: {app_id}" ) ;
@@ -159,11 +160,17 @@ async fn main() {
159160 // 3. Initialize the logger using app_id for context
160161 // ------------------------------------------------------
161162 init_logging ( & config. app_id ) ;
163+ let builder = PrometheusBuilder :: new ( ) ;
164+ let handle = builder
165+ . install_recorder ( )
166+ . expect ( "❌ Failed to install Prometheus recorder" ) ;
162167
163168 // ------------------------------------------------------
164169 // 4. Set global CONFIG (OnceCell) for use across modules
165170 // ------------------------------------------------------
166- CONFIG . set ( config) . expect ( "❌ CONFIG was already initialized" ) ;
171+ CONFIG
172+ . set ( config)
173+ . expect ( "❌ CONFIG was already initialized" ) ;
167174
168175 // ------------------------------------------------------
169176 // 5. Initialize persistent storage backend (GCS, S3, Azure, Local)
@@ -181,7 +188,9 @@ async fn main() {
181188 // 7. Define Axum router with a single wildcard route
182189 // All incoming GET requests will be handled by the proxy logic.
183190 // ------------------------------------------------------
184- let app = Router :: new ( ) . route ( "/*path" , get ( proxy:: proxy_handler) ) ;
191+ let app = Router :: new ( )
192+ . route ( "/metrics" , get ( move || async move { handle. render ( ) } ) )
193+ . route ( "/*path" , get ( proxy:: proxy_handler) ) ;
185194
186195 // ------------------------------------------------------
187196 // 8. Bind the server to all interfaces on port 3000
@@ -196,4 +205,4 @@ async fn main() {
196205 . serve ( app. into_make_service ( ) )
197206 . await
198207 . unwrap ( ) ;
199- }
208+ }
0 commit comments