Skip to content

Commit

Permalink
Merge pull request #274 from Kuadrant/default_args
Browse files Browse the repository at this point in the history
cmdline uses default values from crate, rather than its own
  • Loading branch information
alexsnaps authored Mar 21, 2024
2 parents de261a8 + 74ab548 commit 2bf2497
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions limitador-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use opentelemetry::KeyValue;
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::{trace, Resource};
use std::env::VarError;
use std::fmt::Display;
use std::fs;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -614,7 +615,7 @@ fn create_config() -> (Configuration, &'static str) {
.value_parser(clap::value_parser!(u64))
.default_value(
config::env::REDIS_LOCAL_CACHE_MAX_TTL_CACHED_COUNTERS_MS
.unwrap_or("5000"),
.unwrap_or(leak(DEFAULT_MAX_TTL_CACHED_COUNTERS_SEC * 1000)),
)
.display_order(2)
.help("TTL for cached counters in milliseconds"),
Expand All @@ -626,7 +627,7 @@ fn create_config() -> (Configuration, &'static str) {
.value_parser(clap::value_parser!(u64))
.default_value(
config::env::REDIS_LOCAL_CACHE_TTL_RATIO_CACHED_COUNTERS
.unwrap_or("10000"),
.unwrap_or(leak(DEFAULT_TTL_RATIO_CACHED_COUNTERS)),
)
.display_order(3)
.help("Ratio to apply to the TTL from Redis on cached counters"),
Expand All @@ -637,7 +638,8 @@ fn create_config() -> (Configuration, &'static str) {
.action(ArgAction::Set)
.value_parser(clap::value_parser!(i64))
.default_value(
config::env::REDIS_LOCAL_CACHE_FLUSHING_PERIOD_MS.unwrap_or("1000"),
config::env::REDIS_LOCAL_CACHE_FLUSHING_PERIOD_MS
.unwrap_or(leak(DEFAULT_FLUSHING_PERIOD_SEC * 1000)),
)
.display_order(4)
.help("Flushing period for counters in milliseconds"),
Expand All @@ -647,7 +649,7 @@ fn create_config() -> (Configuration, &'static str) {
.long("max-cached")
.action(ArgAction::Set)
.value_parser(clap::value_parser!(usize))
.default_value("10000")
.default_value(leak(DEFAULT_MAX_CACHED_COUNTERS))
.display_order(5)
.help("Maximum amount of counters cached"),
),
Expand All @@ -670,7 +672,10 @@ fn create_config() -> (Configuration, &'static str) {
.short('n')
.long("cache-name")
.action(ArgAction::Set)
.default_value(config::env::INFINISPAN_CACHE_NAME.unwrap_or("infinispan"))
.default_value(
config::env::INFINISPAN_CACHE_NAME
.unwrap_or(storage::infinispan::DEFAULT_INFINISPAN_LIMITS_CACHE_NAME),
)
.display_order(2)
.help("Name of the cache to store counters in"),
)
Expand All @@ -679,7 +684,10 @@ fn create_config() -> (Configuration, &'static str) {
.short('c')
.long("consistency")
.action(ArgAction::Set)
.default_value(config::env::INFINISPAN_COUNTERS_CONSISTENCY.unwrap_or("Strong"))
.default_value(
config::env::INFINISPAN_COUNTERS_CONSISTENCY
.unwrap_or(leak(storage::infinispan::DEFAULT_INFINISPAN_CONSISTENCY)),
)
.value_parser(clap::builder::PossibleValuesParser::new(["Strong", "Weak"]))
.display_order(3)
.help("The consistency to use to read from the cache"),
Expand Down Expand Up @@ -882,6 +890,10 @@ fn env_option_is_enabled(env_name: &str) -> bool {
}
}

fn leak<D: Display>(s: D) -> &'static str {
return Box::leak(format!("{}", s).into_boxed_str());
}

#[cfg(test)]
mod tests {
use crate::find_first_negative_limit;
Expand Down

0 comments on commit 2bf2497

Please sign in to comment.