Skip to content
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

Investigate adding a lint or some automated check which detects when a serde default is defined on a config setting which is of type Option<T>. #16756

Open
neuronull opened this issue Mar 9, 2023 · 0 comments
Labels
domain: config Anything related to configuring Vector meta: idea Anything in the idea phase. Needs further discussion and consensus before work can begin. type: tech debt A code change that does not add user value.

Comments

@neuronull
Copy link
Contributor

As part of the postmortem to #16630 , one long(er) term idea was to automate the detection of for example

struct FooConfig {
   #[serde(default = "default_setting")]
    my_setting: Option<WhatverType>,
}

fn default_setting() -> Option<WhateverType> {
    Some(WhateverType::suits_your_fancy())
}

, since that shouldn't be an Option<T> at this point. It should just be a the type itself.

This is a code smell and can lead to the issues like in the aforementioned bug.

It looks like we are doing that in a few places already:

 grep -r "#\[serde(default =" -A 1 | grep "Option<"

./config/api.rs-    pub address: Option<SocketAddr>,
./sources/host_metrics/mod.rs-    pub collectors: Option<Vec<Collector>>,
./sources/host_metrics/mod.rs-    pub namespace: Option<String>,
./sources/host_metrics/mod.rs-    pub cgroups: Option<CGroupsConfig>,
./sources/docker_logs/mod.rs-    partial_event_marker_field: Option<String>,
@neuronull neuronull added the meta: idea Anything in the idea phase. Needs further discussion and consensus before work can begin. label Mar 9, 2023
@neuronull neuronull changed the title Investigate adding a lint or some automated check which detects when a serde default is defined on a config setting which of type Option<T>. Investigate adding a lint or some automated check which detects when a serde default is defined on a config setting which is of type Option<T>. Mar 9, 2023
@jszwedko jszwedko added type: tech debt A code change that does not add user value. domain: config Anything related to configuring Vector labels Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: config Anything related to configuring Vector meta: idea Anything in the idea phase. Needs further discussion and consensus before work can begin. type: tech debt A code change that does not add user value.
Projects
None yet
Development

No branches or pull requests

2 participants