chore: added ods version compatibility check#41
Conversation
Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
|
|
||
| let info = VERSION_CHECK.lock().unwrap().clone(); | ||
|
|
||
| match info { | ||
| Some(result) => { | ||
| if result.is_below_min { | ||
| HttpResponse::InternalServerError().json(result) | ||
| } else { | ||
| HttpResponse::Ok().json(result) | ||
| } | ||
| } | ||
| None => HttpResponse::Ok().body("No version check performed yet"), | ||
| } |
There was a problem hiding this comment.
healthcheck must be called in another PR during startup and handle the result
src/common.rs
Outdated
| let min_version = Version::parse(MIN_ODS_VERSION).expect("parse MIN_ODS_VERSION"); | ||
| let current_version = Version::parse(&ods_version).expect("parse ods_version"); | ||
| let is_below_min = current_version < min_version; | ||
| { | ||
| let mut version_check = VERSION_CHECK.lock().unwrap(); | ||
| *version_check = Some(VersionCheckResult { | ||
| min_version: MIN_ODS_VERSION.to_string(), | ||
| current_version: ods_version.clone(), | ||
| is_below_min, | ||
| }); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
There was a problem hiding this comment.
- we should get rid of
expectandunwrap OnceLockwould be better asLazyLock. You could move the code intoget_or_initfunction
There was a problem hiding this comment.
refactored to used OnceLock and removed unnecessary Mutex handling.
src/common.rs
Outdated
| let min_version = Version::parse(MIN_ODS_VERSION) | ||
| .map_err(|e| anyhow!("failed to parse MIN_ODS_VERSION: {e}"))?; |
There was a problem hiding this comment.
If we use a VersionReq for the target version, we are more flexible.
| fs::exists(&ods_socket_path).unwrap_or_else(|_| { | ||
| panic!( | ||
| "omnect device service socket file {} does not exist", | ||
| &ods_socket_path | ||
| ) | ||
| }); |
There was a problem hiding this comment.
IMHO we don't need this check. There might be cases where the unix domain socket exists and is deleted later on. We should instead ensure, that the open call to the unix domain socket does not attempt to create a file if the file does not exist, and handle the error on opening.
There was a problem hiding this comment.
Ah, I just saw, that this is pre-existing code. Still: just drop the check :)
There was a problem hiding this comment.
There was a problem hiding this comment.
@empwilli what do you mean by "...attempt to create a file..."?
src/main.rs
Outdated
| pub const MIN_ODS_VERSION: &str = "0.39.0"; | ||
|
|
There was a problem hiding this comment.
If we use VersionReq instead, I'd adjust the name so that it is REQ_ODS_VERSION
src/common.rs
Outdated
| let Some(omnect_device_service_version) = | ||
| &status_response.system_info.omnect_device_service_version | ||
| else { | ||
| bail!("failed to get omnect_device_service_version from status response") | ||
| }; |
There was a problem hiding this comment.
We expect the response of the ODS to contain omnect_device_service_version in any case and error out if it is not set. IMHO we don't set the type as Option then.
src/common.rs
Outdated
| use std::{fs, io::Write, path::Path}; | ||
| use std::{fs, io::Write, path::Path, sync::OnceLock}; | ||
|
|
||
| pub static VERSION_CHECK: OnceLock<VersionCheckResult> = OnceLock::new(); |
There was a problem hiding this comment.
IMHO use a lazy lock here: this would drop the case in the healthcheck route above for the case where VERSION_CHECK.get() returns None.
There was a problem hiding this comment.
@JoergZeidler @empwilli @ronny-standtke
I had a closer look and we shouldn't use any (std::sync::***Lock) at all. Therefore we should add a new function to Api and call get_status once and parse and save all data we need later on in Api calls. Thus we can get rid of further calls of get_status (e.g. for fleet_id) and we need no global static std::sync::***Lock
There was a problem hiding this comment.
removed OnceLock handling. Imho refactoring with new get_status() handline should be done after refinement with @ronny-standtke and @JanZachmann
Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
src/api.rs
Outdated
| if let Some(result) = VERSION_CHECK.get() { | ||
| if result.version_mismatch { | ||
| HttpResponse::ServiceUnavailable().json(result) | ||
| } else { | ||
| HttpResponse::Ok().json(result) | ||
| } | ||
| } else { | ||
| HttpResponse::Ok().body("No version check performed yet") | ||
| } |
There was a problem hiding this comment.
can be done all in one match
match VERSION_CHECK.get() {
Some(result) if result.version_mismatch => {
HttpResponse::ServiceUnavailable().json(result)
}
Some(result) => HttpResponse::Ok().json(result),
_ => HttpResponse::Ok().body("No version check performed yet"),
}
src/common.rs
Outdated
| use std::{fs, io::Write, path::Path}; | ||
| use std::{fs, io::Write, path::Path, sync::OnceLock}; | ||
|
|
||
| pub static VERSION_CHECK: OnceLock<VersionCheckResult> = OnceLock::new(); |
There was a problem hiding this comment.
@JoergZeidler @empwilli @ronny-standtke
I had a closer look and we shouldn't use any (std::sync::***Lock) at all. Therefore we should add a new function to Api and call get_status once and parse and save all data we need later on in Api calls. Thus we can get rid of further calls of get_status (e.g. for fleet_id) and we need no global static std::sync::***Lock
Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
No description provided.