[inventory] Add svcs enabled not online to DB#10195
[inventory] Add svcs enabled not online to DB#10195karencfv wants to merge 17 commits intooxidecomputer:mainfrom
Conversation
schema/crdb/dbinit.sql
Outdated
| id UUID NOT NULL, | ||
| fmri TEXT NOT NULL, | ||
| zone TEXT NOT NULL, | ||
| state omicron.public.inv_svc_state_enum NOT NULL, |
There was a problem hiding this comment.
This maybe gets at a design issue with the types on the Rust side, but - what would it mean to have a row in a table named ..._not_online_service with the state online?
There was a problem hiding this comment.
I see where you're getting at 🤔 . What about using an enum on the DB side (inv_svc_not_online_state ?) that does not include the online state?
There was a problem hiding this comment.
I think not including the online state is the right call, if the intent of this is to store "not online" statuses. But we probably need to remove it on the Rust side too, right? For a couple reasons: the same question applies there (what would it mean for a SvcsEnabledNotOnline to contain a service in the state SvcState::Online), and what would you do at runtime if you had that and needed to store it in the db?
That does make the type names awkward; it probably needs to be something like SvcState becomes NotOnlineSvcState and Svc becomes NotOnlineSvc? I don't love that but it does seem like we probably don't want the generic-sounding Svc and SvcState types to not be able to represent online services.
There was a problem hiding this comment.
Ha! Looks like this was already on my mind 😄
https://github.com/oxidecomputer/omicron/blob/main/sled-agent/types/versions/src/modify_services_in_inventory/inventory.rs#L56-L58
There was a problem hiding this comment.
In the end I decided to keep the SvcState enum for the initial parse() method. It seemed just wrong not have a complete enum of all of the possible states as part of the svcs module. I did add additional enums SvcEnabledNotOnlineState and InvSvcEnabledNotOnlineState for the "enabled not online" filtering functionality.
There was a problem hiding this comment.
Thanks, I think that makes perfect sense. 👍
karencfv
left a comment
There was a problem hiding this comment.
Thanks for the review! I think I've addressed all of your comments @jgallagher
schema/crdb/dbinit.sql
Outdated
| id UUID NOT NULL, | ||
| fmri TEXT NOT NULL, | ||
| zone TEXT NOT NULL, | ||
| state omicron.public.inv_svc_state_enum NOT NULL, |
There was a problem hiding this comment.
I see where you're getting at 🤔 . What about using an enum on the DB side (inv_svc_not_online_state ?) that does not include the online state?
|
Changes look good - just one nit with the error string conversion, and then the somewhat-painful "what do we do about online services" question in #10195 (comment). |
| "offline" => SvcEnabledNotOnlineState::Offline, | ||
| "degraded" => SvcEnabledNotOnlineState::Degraded, | ||
| "maintenance" => SvcEnabledNotOnlineState::Maintenance, | ||
| _ => SvcEnabledNotOnlineState::Unknown, |
There was a problem hiding this comment.
This doesn't seem right - I could call SvcEnabledNotOnlineState::from("sled 23") and get back SvcEnabledNotOnlineState::Unknown, which I guess it kind of is an unknown state but it doesn't seem like we should infallibly convert any string at all into a service state. I'm also not sure we should have an Unknown state variant. It looks like the only use of this is converting from SvcState::Unknown. I think SvcState::Unknown has the same problems: we shouldn't have a blanket From<&str> impl for it, and I'm not sure we actually need an Unknown variant. The only use of that I'm seeing is inside SvcsResult::parse(), where if we get Unknown, we skip the state and don't include it in the result at all.
Could we do this instead:
- Remove both
From<&str>impls - Remove both
::Unknownvariants - Put a private
parse_svc_state(&str) -> Option<SvcState>insideillumos-utils/src/svcs.rs, and useNonewhere we're currently usingSvcState::Unknownto skip invalid states
?
| let mut svcs_enabled_not_online_errors = Vec::new(); | ||
| for sled_agent in &collection.sled_agents { | ||
| match &sled_agent.smf_services_enabled_not_online { | ||
| SvcsEnabledNotOnlineResult::SvcsEnabledNotOnline(svcs) => { |
There was a problem hiding this comment.
Tiny nit - the comments on lines 233 and 244 are the same and maybe not quite right. I wonder if it would be more future-proof to destructure svcs here:
let SvcsEnabledNotOnline {
services,
errors,
time_of_status,
} = svcs;and then we wouldn't really need the comments as much - we'd be forced to use all the fields to avoid warnings?
Follow up to #9977
Closes: #9516
Manual testing with no data from services
Happy system
With failed services
With a command error