rpc/system_metrics.rs: Added rustversion label to garage_build_info metric. #524

Merged
lx merged 5 commits from jpds/garage:rustversion-label into main 2023-03-13 15:46:49 +00:00
8 changed files with 28 additions and 6 deletions

1
Cargo.lock generated
View file

@ -1309,6 +1309,7 @@ dependencies = [
"opentelemetry",
"rand",
"rmp-serde",
"rustc_version",
"serde",
"serde_json",
"sha2 0.10.6",

View file

@ -32,7 +32,7 @@ args@{
ignoreLockHash,
}:
let
nixifiedLockHash = "12ff12e9210c87ac93e2f2bdb7007b6232e7efcfa302c272bf0caee6e78abd10";
nixifiedLockHash = "d36a8590fdf6eeb128a5a852d55945b595d5830291ad0aca95a21dcc1fab8681";
workspaceSrc = if args.workspaceSrc == null then ./. else args.workspaceSrc;
currentLockHash = builtins.hashFile "sha256" (workspaceSrc + /Cargo.lock);
lockHashIgnored = if ignoreLockHash
@ -1861,6 +1861,9 @@ in
devDependencies = {
mktemp = (rustPackages."registry+https://github.com/rust-lang/crates.io-index".mktemp."0.5.0" { inherit profileName; }).out;
};
buildDependencies = {
rustc_version = (buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".rustc_version."0.4.0" { profileName = "__noProfile"; }).out;
};
});
"unknown".garage_web."0.8.1" = overridableMkRustCrate (profileName: rec {

View file

@ -20,6 +20,7 @@ pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<
node: hex::encode(garage.system.id),
garage_version: garage_util::version::garage_version(),
garage_features: garage_util::version::garage_features(),
rust_version: garage_util::version::rust_version(),
db_engine: garage.db.engine(),
known_nodes: garage
.system
@ -106,6 +107,7 @@ struct GetClusterStatusResponse {
node: String,
garage_version: &'static str,
garage_features: Option<&'static [&'static str]>,
rust_version: &'static str,
db_engine: String,
known_nodes: HashMap<String, KnownNodeResp>,
layout: GetClusterLayoutResponse,

View file

@ -820,11 +820,12 @@ impl AdminRpcHandler {
let mut ret = String::new();
writeln!(
&mut ret,
"\nGarage version: {} [features: {}]",
"\nGarage version: {} [features: {}]\nRust compiler version: {}",
garage_util::version::garage_version(),
garage_util::version::garage_features()
.map(|list| list.join(", "))
.unwrap_or_else(|| "(unknown)".into()),
garage_util::version::rust_version(),
)
.unwrap();

View file

@ -31,10 +31,10 @@ impl SystemMetrics {
.u64_value_observer("garage_build_info", move |observer| {
observer.observe(
1,
&[KeyValue::new(
"version",
garage_util::version::garage_version(),
)],
&[
KeyValue::new("rustversion", garage_util::version::rust_version()),
KeyValue::new("version", garage_util::version::garage_version()),
],
)
})
.with_description("Garage build info")

View file

@ -47,6 +47,9 @@ hyper = "0.14"
opentelemetry = { version = "0.17", features = [ "rt-tokio", "metrics", "trace" ] }
[build-dependencies]
rustc_version = "0.4.0"
[dev-dependencies]
mktemp = "0.5"

8
src/util/build.rs Normal file
View file

@ -0,0 +1,8 @@
use rustc_version::version;
fn main() {
// Acquire the version of Rust used to compile, this is added as a label to
// the garage_build_info metric.
let v = version().unwrap();
println!("cargo:rustc-env=RUSTC_VERSION={v}");
}

View file

@ -26,3 +26,7 @@ pub fn init_version(version: &'static str) {
pub fn init_features(features: &'static [&'static str]) {
FEATURES.store(Some(Arc::new(features)));
}
pub fn rust_version() -> &'static str {
env!("RUSTC_VERSION")
}