-
Notifications
You must be signed in to change notification settings - Fork 556
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
feat: Exit while cache is not configured correctly #1515
Changes from 4 commits
6db010b
fd10226
3de0c17
1196d49
79ef7d4
14b1488
e7f4d9a
6030517
b10bc06
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 |
---|---|---|
|
@@ -244,9 +244,9 @@ pub struct CacheConfigs { | |
} | ||
|
||
impl CacheConfigs { | ||
/// Return a vec of the available cache types in an arbitrary but | ||
/// Return cache type in an arbitrary but | ||
/// consistent ordering | ||
fn into_vec_and_fallback(self) -> (Vec<CacheType>, DiskCacheConfig) { | ||
fn into_fallback(self) -> (Option<CacheType>, DiskCacheConfig) { | ||
let CacheConfigs { | ||
azure, | ||
disk, | ||
|
@@ -257,18 +257,17 @@ impl CacheConfigs { | |
s3, | ||
} = self; | ||
|
||
let caches = s3 | ||
let cache_type = s3 | ||
.map(CacheType::S3) | ||
.into_iter() | ||
.chain(redis.map(CacheType::Redis)) | ||
.chain(memcached.map(CacheType::Memcached)) | ||
.chain(gcs.map(CacheType::GCS)) | ||
.chain(gha.map(CacheType::GHA)) | ||
.chain(azure.map(CacheType::Azure)) | ||
.collect(); | ||
.or_else(|| redis.map(CacheType::Redis)) | ||
.or_else(|| memcached.map(CacheType::Memcached)) | ||
.or_else(|| gcs.map(CacheType::GCS)) | ||
.or_else(|| gha.map(CacheType::GHA)) | ||
.or_else(|| azure.map(CacheType::Azure)); | ||
|
||
let fallback = disk.unwrap_or_default(); | ||
|
||
(caches, fallback) | ||
(cache_type, fallback) | ||
} | ||
|
||
/// Override self with any existing fields from other | ||
|
@@ -666,7 +665,7 @@ fn config_file(env_var: &str, leaf: &str) -> PathBuf { | |
|
||
#[derive(Debug, Default, PartialEq, Eq)] | ||
pub struct Config { | ||
pub caches: Vec<CacheType>, | ||
pub cache: Option<CacheType>, | ||
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. Was this used anywhere before? Did multiple backends ever work? 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.
No, they never works at the same time. The only case is users configure different backends at the same time, and some of them are wrong. For example, users configure s3, azure, redis at the same time, and s3, azure is invalid, only redis works. In old logic, the errors returned by s3 and azure will be ignore, and using redis finally. In this PR, we will only choose the first valid cache type and returns error happened which makes the behavior more predictable. In the future, I will return errors if users configured different backends at the same time. |
||
pub fallback_cache: DiskCacheConfig, | ||
pub dist: DistConfig, | ||
pub server_startup_timeout: Option<std::time::Duration>, | ||
|
@@ -700,9 +699,9 @@ impl Config { | |
let EnvConfig { cache } = env_conf; | ||
conf_caches.merge(cache); | ||
|
||
let (caches, fallback_cache) = conf_caches.into_vec_and_fallback(); | ||
let (caches, fallback_cache) = conf_caches.into_fallback(); | ||
Self { | ||
caches, | ||
cache: caches, | ||
fallback_cache, | ||
dist, | ||
server_startup_timeout, | ||
|
@@ -990,19 +989,9 @@ fn config_overrides() { | |
assert_eq!( | ||
Config::from_env_and_file_configs(env_conf, file_conf), | ||
Config { | ||
caches: vec![ | ||
CacheType::Redis(RedisCacheConfig { | ||
url: "myotherredisurl".to_owned() | ||
}), | ||
CacheType::Memcached(MemcachedCacheConfig { | ||
url: "memurl".to_owned() | ||
}), | ||
CacheType::Azure(AzureCacheConfig { | ||
connection_string: String::new(), | ||
container: String::new(), | ||
key_prefix: String::new() | ||
}), | ||
], | ||
cache: Some(CacheType::Redis(RedisCacheConfig { | ||
url: "myotherredisurl".to_owned() | ||
}),), | ||
fallback_cache: DiskCacheConfig { | ||
dir: "/env-cache".into(), | ||
size: 5, | ||
|
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.
Could it be removed altogether?
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.
This function will be used if feature like
s3
,azure
enabled. Adding adead_code
is the most simple way to address clippy errors under--no-default-feature
.