upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-04 15:17:04 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-04 15:24:19 +0000
commitfd0c87c787d0626b3546fa571541c9c809711821 (patch)
tree934f20d973127f380b807d2bd44b25c197cf349c /src/config.rs
parent762cd8e815e797f173f541795de774fbbf978fc3 (diff)
add prometheus metrics
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
index d095178..025e020 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -71,6 +71,18 @@ pub struct Config {
71 /// Database backend type 71 /// Database backend type
72 #[arg(long, env = "NGIT_DATABASE_BACKEND", value_enum, default_value_t = DatabaseBackend::Lmdb)] 72 #[arg(long, env = "NGIT_DATABASE_BACKEND", value_enum, default_value_t = DatabaseBackend::Lmdb)]
73 pub database_backend: DatabaseBackend, 73 pub database_backend: DatabaseBackend,
74
75 /// Enable Prometheus metrics endpoint
76 #[arg(long, env = "NGIT_METRICS_ENABLED", default_value_t = true)]
77 pub metrics_enabled: bool,
78
79 /// Connections per IP before flagging as potential abuse in metrics (display only, no rate limiting)
80 #[arg(long = "metrics-connection-per-ip-abuse-threshold", env = "NGIT_METRICS_CONNECTION_PER_IP_ABUSE_THRESHOLD", default_value_t = 10)]
81 pub metrics_connection_per_ip_abuse_threshold: u32,
82
83 /// Number of top bandwidth repos to track in metrics
84 #[arg(long = "metrics-top-n-repos", env = "NGIT_METRICS_TOP_N_REPOS", default_value_t = 10)]
85 pub metrics_top_n_repos: usize,
74} 86}
75 87
76impl Config { 88impl Config {
@@ -123,6 +135,9 @@ impl Config {
123 relay_data_path: "./test_data/relay".to_string(), 135 relay_data_path: "./test_data/relay".to_string(),
124 bind_address: "127.0.0.1:8080".to_string(), 136 bind_address: "127.0.0.1:8080".to_string(),
125 database_backend: DatabaseBackend::Memory, 137 database_backend: DatabaseBackend::Memory,
138 metrics_enabled: true,
139 metrics_connection_per_ip_abuse_threshold: 10,
140 metrics_top_n_repos: 10,
126 } 141 }
127 } 142 }
128} 143}
@@ -202,4 +217,25 @@ mod tests {
202 }; 217 };
203 assert!(config.owner_npub.is_none()); 218 assert!(config.owner_npub.is_none());
204 } 219 }
220
221 #[test]
222 fn test_metrics_config_defaults() {
223 let config = Config::for_testing();
224 assert!(config.metrics_enabled);
225 assert_eq!(config.metrics_connection_per_ip_abuse_threshold, 10);
226 assert_eq!(config.metrics_top_n_repos, 10);
227 }
228
229 #[test]
230 fn test_metrics_config_custom_values() {
231 let config = Config {
232 metrics_enabled: false,
233 metrics_connection_per_ip_abuse_threshold: 50,
234 metrics_top_n_repos: 25,
235 ..Config::for_testing()
236 };
237 assert!(!config.metrics_enabled);
238 assert_eq!(config.metrics_connection_per_ip_abuse_threshold, 50);
239 assert_eq!(config.metrics_top_n_repos, 25);
240 }
205} 241}