-
Notifications
You must be signed in to change notification settings - Fork 162
Add TOML configuration to the autopilot #4147
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7152f44
wip
jmg-duarte 808fc2a
Remove fairness_threshold
jmg-duarte ac3329f
Properly fix config in e2e test
jmg-duarte 65b2d5e
fmt
jmg-duarte e33f238
Use tempfile in e2e config setup
jmg-duarte 7a0cf93
fix potential bug
jmg-duarte 2ed0a34
fmt
jmg-duarte 16f93f6
Merge branch 'main' into jmgd/config-drivers
jmg-duarte dedda5a
fix compilation
jmg-duarte db3ad71
address comments
jmg-duarte 805753b
address comments
jmg-duarte 7bebe52
fmt
jmg-duarte d7edc26
address comments
jmg-duarte 513c6cc
Merge branch 'main' into jmgd/config-drivers
jmg-duarte 62c304b
fix compilation
jmg-duarte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| use { | ||
| crate::config::solver::Solver, | ||
| anyhow::{anyhow, ensure}, | ||
| serde::{Deserialize, Serialize}, | ||
| std::path::Path, | ||
| }; | ||
|
|
||
| pub mod solver; | ||
|
|
||
| #[derive(Debug, Default, Deserialize, Serialize)] | ||
| #[serde(rename_all = "kebab-case", deny_unknown_fields)] | ||
| pub struct Configuration { | ||
| // #[serde(default)] | ||
| pub drivers: Vec<Solver>, | ||
| } | ||
|
|
||
| impl Configuration { | ||
| pub async fn from_path<P: AsRef<Path>>(path: P) -> anyhow::Result<Self> { | ||
| match toml::from_str(&tokio::fs::read_to_string(&path).await?) { | ||
| Ok(self_) => Ok(self_), | ||
| Err(err) if std::env::var("TOML_TRACE_ERROR").is_ok_and(|v| v == "1") => Err(anyhow!( | ||
| "failed to parse TOML config at {}: {err:#?}", | ||
| path.as_ref().display() | ||
| )), | ||
| Err(_) => Err(anyhow!( | ||
| "failed to parse TOML config at: {}. Set TOML_TRACE_ERROR=1 to print parsing \ | ||
| error but this may leak secrets.", | ||
| path.as_ref().display() | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| pub async fn to_path<P: AsRef<Path>>(&self, path: P) -> anyhow::Result<()> { | ||
| Ok(tokio::fs::write(path, toml::to_string_pretty(self)?).await?) | ||
| } | ||
|
|
||
| #[cfg(any(test, feature = "test-util"))] | ||
| pub fn to_temp_path(&self) -> tempfile::NamedTempFile { | ||
| use std::io::Write; | ||
| let mut file = tempfile::NamedTempFile::new().expect("temp file creation should not fail"); | ||
| file.write_all( | ||
| toml::to_string_pretty(self) | ||
| .expect("serialization should not fail") | ||
| .as_bytes(), | ||
| ) | ||
| .expect("writing to temp file should not fail"); | ||
| file | ||
| } | ||
|
|
||
| // Note for reviewers: if this and other validations are always applied, | ||
| // we should instead move them to the deserialization stage | ||
| // https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ | ||
| pub fn validate(self) -> anyhow::Result<Self> { | ||
| ensure!( | ||
| !self.drivers.is_empty(), | ||
| "colocation is enabled but no drivers are configured" | ||
| ); | ||
| Ok(self) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.