-
Notifications
You must be signed in to change notification settings - Fork 66
[inventory] Add unhealthy zpools from each sled #9615
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
Open
karencfv
wants to merge
25
commits into
oxidecomputer:main
Choose a base branch
from
karencfv:zpool-health-check
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+11,072
−64
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
ed4d1ee
pseudo-code
karencfv b30e767
add some thoughts
karencfv 27204f4
Merge branch 'main' into zpool-health-check
karencfv b038f6e
[inventory] Add unhealthy zpools from each sled
karencfv 25db966
add some tests
karencfv cc6d397
Add unhealthy zpool functionality
karencfv 219918c
add zpool health info to API
karencfv 407a068
fix cmd order
karencfv c817b9c
address comments
karencfv d01216d
get serde/schemars working with Option<Result<T,E>>
karencfv b1fecc8
clean up
karencfv 8eb5001
make time_of_status required
karencfv 7cd8f4b
add json file and fmt
karencfv c5baf76
merge main
karencfv e6944dc
generate openapi doc
karencfv 0458330
sigh...
karencfv 4c7cad3
untagged so it works on none
karencfv 2771225
linter
karencfv b8157ea
report zpool health state as well
karencfv a2e3e90
add generated openapi spec
karencfv c734654
Remove manual testing code
karencfv 030b11f
Make smf_services_in_maintenance optional too
karencfv bc8eb04
merge main
karencfv fe84464
fixes after merge
karencfv 3332389
remove manual testing code
karencfv 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
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,115 @@ | ||
| // This Source Code Form is subject to the terms of the Mozilla Public | ||
| // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
|
||
| //! A serializable `Option<Result>` that plays nicely with OpenAPI lints. | ||
|
|
||
| use crate::snake_case_result::SnakeCaseResult; | ||
| use schemars::JsonSchema; | ||
| use serde::Deserialize; | ||
| use serde::Serialize; | ||
|
|
||
| #[derive(Serialize, Deserialize)] | ||
| #[serde(rename_all = "snake_case")] | ||
| #[serde(rename = "OptionResult{T}Or{E}")] | ||
| #[serde(untagged)] | ||
| pub enum SnakeCaseOptionResult<T, E> { | ||
| Some(SnakeCaseResult<T, E>), | ||
| None, | ||
| } | ||
|
|
||
| impl<T, E> JsonSchema for SnakeCaseOptionResult<T, E> | ||
| where | ||
| T: JsonSchema, | ||
| E: JsonSchema, | ||
| { | ||
| fn schema_name() -> String { | ||
| format!("OptionResult{}Or{}", T::schema_name(), E::schema_name()) | ||
| } | ||
|
|
||
| fn json_schema( | ||
| generator: &mut schemars::r#gen::SchemaGenerator, | ||
| ) -> schemars::schema::Schema { | ||
| let mut ok_schema = schemars::schema::SchemaObject { | ||
| instance_type: Some(schemars::schema::InstanceType::Object.into()), | ||
| ..Default::default() | ||
| }; | ||
| let obj = ok_schema.object(); | ||
| obj.required.insert("ok".to_owned()); | ||
| obj.properties.insert("ok".to_owned(), generator.subschema_for::<T>()); | ||
|
|
||
| let mut err_schema = schemars::schema::SchemaObject { | ||
| instance_type: Some(schemars::schema::InstanceType::Object.into()), | ||
| ..Default::default() | ||
| }; | ||
| let obj = err_schema.object(); | ||
| obj.required.insert("err".to_owned()); | ||
| obj.properties.insert("err".to_owned(), generator.subschema_for::<E>()); | ||
|
|
||
| let mut schema = schemars::schema::SchemaObject::default(); | ||
| schema.subschemas().one_of = | ||
| Some(vec![ok_schema.into(), err_schema.into()]); | ||
|
|
||
| schema | ||
| .extensions | ||
| .insert(String::from("nullable"), serde_json::json!(true)); | ||
| schema.extensions.insert( | ||
| String::from("x-rust-type"), | ||
| serde_json::json!({ | ||
| "crate": "std", | ||
| "version": "*", | ||
| "path": "::std::result::Result", | ||
| "parameters": [ | ||
| generator.subschema_for::<T>(), | ||
| generator.subschema_for::<E>(), | ||
| ], | ||
| }), | ||
| ); | ||
| schema.into() | ||
| } | ||
| } | ||
|
|
||
| /// Serialize an Option<Result<T, E>> as a `SnakeCaseOptionResult`. | ||
| pub fn serialize<S, T, E>( | ||
| value: &Option<Result<T, E>>, | ||
| serializer: S, | ||
| ) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::Serializer, | ||
| T: Serialize, | ||
| E: Serialize, | ||
| { | ||
| match value { | ||
| None => serializer.serialize_none(), | ||
| Some(Ok(val)) => { | ||
| SnakeCaseOptionResult::<&T, &E>::Some(SnakeCaseResult::Ok(val)) | ||
| .serialize(serializer) | ||
| } | ||
| Some(Err(err)) => { | ||
| SnakeCaseOptionResult::<&T, &E>::Some(SnakeCaseResult::Err(err)) | ||
| .serialize(serializer) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Deserialize a `SnakeCaseOptionResult` into an `Option<Result>`. | ||
| pub fn deserialize<'de, D, T, E>( | ||
| deserializer: D, | ||
| ) -> Result<Option<Result<T, E>>, D::Error> | ||
| where | ||
| D: serde::Deserializer<'de>, | ||
| T: Deserialize<'de>, | ||
| E: Deserialize<'de>, | ||
| { | ||
| SnakeCaseOptionResult::<T, E>::deserialize(deserializer).map(|snek| { | ||
| match snek { | ||
| SnakeCaseOptionResult::Some(SnakeCaseResult::Ok(val)) => { | ||
| Some(Ok(val)) | ||
| } | ||
| SnakeCaseOptionResult::Some(SnakeCaseResult::Err(err)) => { | ||
| Some(Err(err)) | ||
| } | ||
| SnakeCaseOptionResult::None => None, | ||
| } | ||
| }) | ||
| } | ||
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
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.
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.
Oof, sorry, I didn't realize proposing
Option<Result<_, _>>would lead to this.Would it be cleaner to squish this down into an enum of our own? Something like
? (I don't have strong feelings either way.)
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.
Hm, the code is cleaner yes, but the OpenAPI linter forces me to use tags and the result of this ends up being a somewhat weird looking API 😄
I tried out how the API would look using the enum with services in maintenance and the
Option<Result<T>>with the unhealthy zpools, and I think the API is much cleaner when using theOption<Result<T>>:If it's not super important, perhaps we can keep it as is?