Skip to content

chore: added ods version compatibility check#41

Merged
JoergZeidler merged 7 commits intoomnect:mainfrom
JoergZeidler:ods_compatibility
May 19, 2025
Merged

chore: added ods version compatibility check#41
JoergZeidler merged 7 commits intoomnect:mainfrom
JoergZeidler:ods_compatibility

Conversation

@JoergZeidler
Copy link
Contributor

No description provided.

Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
Comment on lines 117 to 129

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"),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

healthcheck must be called in another PR during startup and handle the result

Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
src/common.rs Outdated
Comment on lines 235 to 248
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(())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we should get rid of expect and unwrap
  2. OnceLock would be better as LazyLock. You could move the code into get_or_init function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored to used OnceLock and removed unnecessary Mutex handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
Signed-off-by: Joerg Zeidler <62105035+JoergZeidler@users.noreply.github.com>
src/common.rs Outdated
Comment on lines 226 to 227
let min_version = Version::parse(MIN_ODS_VERSION)
.map_err(|e| anyhow!("failed to parse MIN_ODS_VERSION: {e}"))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use a VersionReq for the target version, we are more flexible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +126 to +131
fs::exists(&ods_socket_path).unwrap_or_else(|_| {
panic!(
"omnect device service socket file {} does not exist",
&ods_socket_path
)
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I just saw, that this is pre-existing code. Still: just drop the check :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@empwilli what do you mean by "...attempt to create a file..."?

src/main.rs Outdated
Comment on lines 32 to 33
pub const MIN_ODS_VERSION: &str = "0.39.0";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use VersionReq instead, I'd adjust the name so that it is REQ_ODS_VERSION

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/common.rs Outdated
Comment on lines 220 to 224
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")
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@JanZachmann JanZachmann May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Comment on lines 117 to 125
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")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Contributor

@JanZachmann JanZachmann May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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>
@JoergZeidler JoergZeidler requested a review from JanZachmann May 15, 2025 15:21
@JoergZeidler JoergZeidler merged commit b557cab into omnect:main May 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants