-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add prometheus env #56
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,29 +43,46 @@ macro_rules! env_get { | |
}; | ||
} | ||
|
||
// Server | ||
env_get!(port => u16); | ||
env_get!(cors_origin); | ||
env_get!(single_file_limit_mb => usize); | ||
env_get!(storage_provider); | ||
macro_rules! env_and_const { | ||
($($name:ident => $type:ty),* $(,)?) => { | ||
const ENV_VARS_BACKEND: &[&str] = &[$(stringify!($name),)*]; | ||
$( | ||
env_get!($name => $type); | ||
)* | ||
}; | ||
} | ||
|
||
// Generate the environment variables metadata and fetch functions | ||
env_and_const!( | ||
// Server | ||
hdrop_port => u16, | ||
prometheus_port => u16, | ||
cors_origin => String, | ||
single_file_limit_mb => usize, | ||
storage_provider => String, | ||
// Database | ||
env_get!(database_url); | ||
|
||
database_url => String, | ||
// Cache | ||
env_get!(cache_strategy); | ||
env_get!(cache_memory_limit_mb => usize); | ||
env_get!(cache_disk_limit_mb => usize); | ||
env_get!(cache_dir => PathBuf); | ||
|
||
cache_strategy => String, | ||
cache_memory_limit_mb => usize, | ||
cache_disk_limit_mb => usize, | ||
cache_dir => PathBuf, | ||
// S3 Provider | ||
env_get!(s3_region); | ||
env_get!(s3_endpoint); | ||
env_get!(s3_access_key_id); | ||
env_get!(s3_secret_access_key); | ||
env_get!(s3_bucket_name); | ||
env_get!(s3_public_url); | ||
|
||
s3_region => String, | ||
s3_endpoint => String, | ||
s3_access_key_id => String, | ||
s3_secret_access_key => String, | ||
s3_bucket_name => String, | ||
s3_public_url => String, | ||
// Local Provider | ||
env_get!(local_storage_dir => PathBuf); | ||
env_get!(local_storage_limit_mb => usize); | ||
local_storage_dir => PathBuf, | ||
local_storage_limit_mb => usize, | ||
); | ||
|
||
/// Get a list of all environment variables used in the hdrop backend. | ||
pub fn get_env_vars() -> Vec<String> { | ||
ENV_VARS_BACKEND | ||
.iter() | ||
.map(|&var| var.to_uppercase()) | ||
.collect() | ||
} | ||
Comment on lines
+82
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this being used for anything, what's the purpose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that hdrop-shared contains all formats for the API responses and requests, as well as the names of the metrics and the environment getters, it was a logical choice to include environment variables data in this crate. The objective is to minimize the maintenance required to update the environment variables across multiple tools. A metadata function has therefore been implemented that displays all available environment variables. This allows other programs to fetch these environment variables when using hdrop-shared as a dependency, thereby establishing it as the single source of truth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a name like
map_env
because it describes an action whereasenv_and_const
doesn't, but it's really not that important. Up to you if you wanna change it or notThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good suggestion. I will reconsider it later today. The term "generate" or "gen" could also be an appropriate choice.