feat: add version information in health state. (#363)

* feat: add git_hash in health state

* add more version information in health state
release-0.0
Meng Zhang 2023-08-20 23:21:12 +08:00 committed by GitHub
parent df45573501
commit b1ad936033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 11 deletions

49
Cargo.lock generated
View File

@ -719,6 +719,15 @@ dependencies = [
"parking_lot_core", "parking_lot_core",
] ]
[[package]]
name = "deranged"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946"
dependencies = [
"serde",
]
[[package]] [[package]]
name = "derive_builder" name = "derive_builder"
version = "0.12.0" version = "0.12.0"
@ -1778,6 +1787,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "number_prefix" name = "number_prefix"
version = "0.3.0" version = "0.3.0"
@ -2470,9 +2488,9 @@ dependencies = [
[[package]] [[package]]
name = "rustversion" name = "rustversion"
version = "1.0.12" version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
[[package]] [[package]]
name = "ryu" name = "ryu"
@ -2833,6 +2851,7 @@ dependencies = [
"utoipa", "utoipa",
"utoipa-swagger-ui", "utoipa-swagger-ui",
"uuid 1.4.1", "uuid 1.4.1",
"vergen",
] ]
[[package]] [[package]]
@ -2943,7 +2962,7 @@ dependencies = [
"tantivy-query-grammar", "tantivy-query-grammar",
"tempfile", "tempfile",
"thiserror", "thiserror",
"time 0.3.21", "time 0.3.26",
"uuid 1.4.1", "uuid 1.4.1",
"winapi", "winapi",
] ]
@ -3068,11 +3087,14 @@ dependencies = [
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.21" version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" checksum = "a79d09ac6b08c1ab3906a2f7cc2e81a0e27c7ae89c63812df75e52bef0751e07"
dependencies = [ dependencies = [
"deranged",
"itoa", "itoa",
"libc",
"num_threads",
"serde", "serde",
"time-core", "time-core",
"time-macros", "time-macros",
@ -3086,9 +3108,9 @@ checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb"
[[package]] [[package]]
name = "time-macros" name = "time-macros"
version = "0.2.9" version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" checksum = "75c65469ed6b3a4809d987a41eb1dc918e9bc1d92211cbad7ae82931846f7451"
dependencies = [ dependencies = [
"time-core", "time-core",
] ]
@ -3767,6 +3789,17 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vergen"
version = "8.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbc5ad0d9d26b2c49a5ab7da76c3e79d3ee37e7821799f8223fcb8f2f391a2e7"
dependencies = [
"anyhow",
"rustversion",
"time 0.3.26",
]
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -4135,7 +4168,7 @@ dependencies = [
"hmac", "hmac",
"pbkdf2", "pbkdf2",
"sha1", "sha1",
"time 0.3.21", "time 0.3.26",
"zstd", "zstd",
] ]

View File

@ -48,3 +48,6 @@ features = [
default = ["scheduler"] default = ["scheduler"]
link_shared = ["ctranslate2-bindings/link_shared"] link_shared = ["ctranslate2-bindings/link_shared"]
scheduler = ["tabby-scheduler"] scheduler = ["tabby-scheduler"]
[build-dependencies]
vergen = { version = "8.0.0", features = ["build", "git", "gitcl"] }

8
crates/tabby/build.rs Normal file
View File

@ -0,0 +1,8 @@
use std::error::Error;
use vergen::EmitBuilder;
fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder().all_build().all_git().emit()?;
Ok(())
}

View File

@ -13,6 +13,7 @@ pub struct HealthState {
arch: String, arch: String,
cpu_info: String, cpu_info: String,
cpu_count: usize, cpu_count: usize,
version: Version,
} }
impl HealthState { impl HealthState {
@ -20,7 +21,7 @@ impl HealthState {
let mut sys = System::new_all(); let mut sys = System::new_all();
sys.refresh_cpu(); sys.refresh_cpu();
let cpus = sys.cpus(); let cpus = sys.cpus();
let cpu_info = if cpus.len() > 0 { let cpu_info = if !cpus.is_empty() {
let cpu = &cpus[0]; let cpu = &cpus[0];
cpu.brand().to_string() cpu.brand().to_string()
} else { } else {
@ -34,6 +35,26 @@ impl HealthState {
arch: ARCH.to_string(), arch: ARCH.to_string(),
cpu_info, cpu_info,
cpu_count: cpus.len(), cpu_count: cpus.len(),
version: Version::new(),
}
}
}
#[derive(Serialize, Deserialize, ToSchema, Clone, Debug)]
pub struct Version {
build_date: String,
build_timestamp: String,
git_sha: String,
git_describe: String,
}
impl Version {
fn new() -> Self {
Self {
build_date: env!("VERGEN_BUILD_DATE").to_string(),
build_timestamp: env!("VERGEN_BUILD_TIMESTAMP").to_string(),
git_sha: env!("VERGEN_GIT_SHA").to_string(),
git_describe: env!("VERGEN_GIT_DESCRIBE").to_string(),
} }
} }
} }