fix: build info should use build time env var (#4343)

* fix: build info should use build time env var

Signed-off-by: tison <wander4096@gmail.com>

* catch up

Signed-off-by: tison <wander4096@gmail.com>

* fixup lifetime

Signed-off-by: tison <wander4096@gmail.com>

* fixup

Signed-off-by: tison <wander4096@gmail.com>

* fix more

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
tison
2024-07-11 20:08:30 -07:00
committed by GitHub
parent ab22bbac84
commit 285ffc5850
28 changed files with 333 additions and 283 deletions

286
Cargo.lock generated
View File

@@ -1180,12 +1180,11 @@ dependencies = [
[[package]]
name = "build-data"
version = "0.1.5"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aed3884e2cab7c973c8fd2d150314b6a932df7fdc830edcaf1e8e7c4ae9db3c0"
checksum = "eda20fcece9c23f3c3f4c2751a8a5ca9491c05fa7a69920af65953c3b39b7ce4"
dependencies = [
"chrono",
"safe-lock",
"safe-regex",
]
@@ -1670,7 +1669,7 @@ dependencies = [
"rand",
"serde_json",
"snafu 0.8.3",
"substrait 0.17.1",
"substrait 0.37.3",
"substrait 0.8.2",
"tokio",
"tokio-stream",
@@ -2265,8 +2264,10 @@ name = "common-version"
version = "0.8.2"
dependencies = [
"build-data",
"const_format",
"schemars",
"serde",
"shadow-rs",
]
[[package]]
@@ -2397,6 +2398,32 @@ dependencies = [
"tiny-keccak",
]
[[package]]
name = "const_fn"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "373e9fafaa20882876db20562275ff58d50e0caa2590077fe7ce7bef90211d0d"
[[package]]
name = "const_format"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673"
dependencies = [
"const_format_proc_macros",
]
[[package]]
name = "const_format_proc_macros"
version = "0.2.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "constant_time_eq"
version = "0.3.0"
@@ -4188,9 +4215,9 @@ checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
[[package]]
name = "git2"
version = "0.18.3"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70"
checksum = "b903b73e45dc0c6c596f2d37eccece7c1c8bb6e4407b001096387c63d0d93724"
dependencies = [
"bitflags 2.5.0",
"libc",
@@ -4264,15 +4291,6 @@ dependencies = [
"ahash 0.7.8",
]
[[package]]
name = "hashbrown"
version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e"
dependencies = [
"ahash 0.8.11",
]
[[package]]
name = "hashbrown"
version = "0.14.5"
@@ -5163,6 +5181,12 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "is_debug"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06d198e9919d9822d5f7083ba8530e04de87841eaf21ead9af8f2304efd57c89"
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
@@ -5635,9 +5659,9 @@ dependencies = [
[[package]]
name = "libgit2-sys"
version = "0.16.2+1.7.2"
version = "0.17.0+1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee4126d8b4ee5c9d9ea891dd875cfdc1e9d0950437179104b183d7d8a74d24e8"
checksum = "10472326a8a6477c3c20a64547b0059e4b0d086869eee31e6d7da728a8eb7224"
dependencies = [
"cc",
"libc",
@@ -7499,7 +7523,7 @@ dependencies = [
"pbjson",
"pbjson-build",
"prost 0.12.6",
"prost-build",
"prost-build 0.12.6",
"serde",
]
@@ -7955,7 +7979,7 @@ dependencies = [
"once_cell",
"parking_lot 0.12.3",
"prost 0.12.6",
"prost-build",
"prost-build 0.12.6",
"prost-derive 0.12.6",
"protobuf",
"sha2",
@@ -8200,6 +8224,16 @@ dependencies = [
"prost-derive 0.12.6",
]
[[package]]
name = "prost"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc"
dependencies = [
"bytes",
"prost-derive 0.13.1",
]
[[package]]
name = "prost-build"
version = "0.12.6"
@@ -8221,6 +8255,25 @@ dependencies = [
"tempfile",
]
[[package]]
name = "prost-build"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bb182580f71dd070f88d01ce3de9f4da5021db7115d2e1c3605a754153b77c1"
dependencies = [
"bytes",
"heck 0.5.0",
"itertools 0.12.1",
"log",
"multimap",
"once_cell",
"petgraph",
"prost 0.13.1",
"prost-types 0.13.1",
"regex",
"tempfile",
]
[[package]]
name = "prost-derive"
version = "0.11.9"
@@ -8247,6 +8300,19 @@ dependencies = [
"syn 2.0.66",
]
[[package]]
name = "prost-derive"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca"
dependencies = [
"anyhow",
"itertools 0.12.1",
"proc-macro2",
"quote",
"syn 2.0.66",
]
[[package]]
name = "prost-types"
version = "0.11.9"
@@ -8265,6 +8331,15 @@ dependencies = [
"prost 0.12.6",
]
[[package]]
name = "prost-types"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2"
dependencies = [
"prost 0.13.1",
]
[[package]]
name = "protobuf"
version = "2.28.0"
@@ -8780,16 +8855,6 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
[[package]]
name = "regress"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ed9969cad8051328011596bf549629f1b800cf1731e7964b1eef8dfc480d2c2"
dependencies = [
"hashbrown 0.13.2",
"memchr",
]
[[package]]
name = "regress"
version = "0.9.1"
@@ -9728,12 +9793,6 @@ version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "safe-lock"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "077d73db7973cccf63eb4aff1e5a34dc2459baa867512088269ea5f2f4253c90"
[[package]]
name = "safe-proc-macro2"
version = "1.0.67"
@@ -9754,18 +9813,18 @@ dependencies = [
[[package]]
name = "safe-regex"
version = "0.2.6"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6ab4bc484ef480a9ce79b381efd7b6767700f514d47bc599036e9d6f7f3c49d"
checksum = "5194fafa3cb9da89e0cab6dffa1f3fdded586bd6396d12be11b4cae0c7ee45c2"
dependencies = [
"safe-regex-macro",
]
[[package]]
name = "safe-regex-compiler"
version = "0.2.6"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d71f8c78bffb07962595e1bfa5ed11d24dd855eedc50b6a735f5ef648ce621b"
checksum = "e822ae1e61251bcfd698317c237cf83f7c57161a5dc24ee609a85697f1ed15b3"
dependencies = [
"safe-proc-macro2",
"safe-quote",
@@ -9773,9 +9832,9 @@ dependencies = [
[[package]]
name = "safe-regex-macro"
version = "0.2.6"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0909ab4b77511df24201cd66541d6a028887c77ecc065f277c68a12a663274ef"
checksum = "2768de7e6ef19f59c5fd3c3ac207ef12b68a49f95e3172d67e4a04cfd992ca06"
dependencies = [
"safe-proc-macro2",
"safe-regex-compiler",
@@ -10313,6 +10372,19 @@ dependencies = [
"keccak",
]
[[package]]
name = "shadow-rs"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a600f795d0894cda22235b44eea4b85c2a35b405f65523645ac8e35b306817a"
dependencies = [
"const_format",
"git2",
"is_debug",
"time",
"tzdb",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
@@ -11002,32 +11074,10 @@ dependencies = [
"promql",
"prost 0.12.6",
"snafu 0.8.3",
"substrait 0.17.1",
"substrait 0.37.3",
"tokio",
]
[[package]]
name = "substrait"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1e8440a1c9b95a7c9a00a19f78b980749e8c945eb880687a5d673cea83729c5"
dependencies = [
"git2",
"heck 0.4.1",
"prettyplease",
"prost 0.12.6",
"prost-build",
"prost-types 0.12.6",
"schemars",
"semver",
"serde",
"serde_json",
"serde_yaml",
"syn 2.0.66",
"typify 0.0.14",
"walkdir",
]
[[package]]
name = "substrait"
version = "0.34.1"
@@ -11040,7 +11090,7 @@ dependencies = [
"pbjson-types",
"prettyplease",
"prost 0.12.6",
"prost-build",
"prost-build 0.12.6",
"prost-types 0.12.6",
"schemars",
"semver",
@@ -11048,7 +11098,28 @@ dependencies = [
"serde_json",
"serde_yaml",
"syn 2.0.66",
"typify 0.1.0",
"typify",
"walkdir",
]
[[package]]
name = "substrait"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ec889155c56a34200d2c5aee147b8d29545fa7cce7f68b38d927f5d24ced8ef"
dependencies = [
"heck 0.5.0",
"prettyplease",
"prost 0.13.1",
"prost-build 0.13.1",
"prost-types 0.13.1",
"schemars",
"semver",
"serde",
"serde_json",
"serde_yaml",
"syn 2.0.66",
"typify",
"walkdir",
]
@@ -12090,7 +12161,7 @@ checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2"
dependencies = [
"prettyplease",
"proc-macro2",
"prost-build",
"prost-build 0.12.6",
"quote",
"syn 2.0.66",
]
@@ -12469,42 +12540,14 @@ dependencies = [
"syn 2.0.66",
]
[[package]]
name = "typify"
version = "0.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2e3b707a653e2915a2fc2c4ee96a3d30b9554b9435eb4cc8b5c6c74bbdd3044"
dependencies = [
"typify-impl 0.0.14",
"typify-macro 0.0.14",
]
[[package]]
name = "typify"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb6beec125971dda80a086f90b4a70f60f222990ce4d63ad0fc140492f53444"
dependencies = [
"typify-impl 0.1.0",
"typify-macro 0.1.0",
]
[[package]]
name = "typify-impl"
version = "0.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d9c752192779f666e4c868672dee56a652b82c08032c7e9d23f6a845b282298"
dependencies = [
"heck 0.4.1",
"log",
"proc-macro2",
"quote",
"regress 0.7.1",
"schemars",
"serde_json",
"syn 2.0.66",
"thiserror",
"unicode-ident",
"typify-impl",
"typify-macro",
]
[[package]]
@@ -12517,7 +12560,7 @@ dependencies = [
"log",
"proc-macro2",
"quote",
"regress 0.9.1",
"regress",
"schemars",
"semver",
"serde",
@@ -12527,22 +12570,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "typify-macro"
version = "0.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a14defd554507e72a2bb93cd081c8b374cfed43b3d986b141ad3839d9fd6986b"
dependencies = [
"proc-macro2",
"quote",
"schemars",
"serde",
"serde_json",
"serde_tokenstream",
"syn 2.0.66",
"typify-impl 0.0.14",
]
[[package]]
name = "typify-macro"
version = "0.1.0"
@@ -12557,7 +12584,36 @@ dependencies = [
"serde_json",
"serde_tokenstream",
"syn 2.0.66",
"typify-impl 0.1.0",
"typify-impl",
]
[[package]]
name = "tz-rs"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33851b15c848fad2cf4b105c6bb66eb9512b6f6c44a4b13f57c53c73c707e2b4"
dependencies = [
"const_fn",
]
[[package]]
name = "tzdb"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b580f6b365fa89f5767cdb619a55d534d04a4e14c2d7e5b9a31e94598687fb1"
dependencies = [
"iana-time-zone",
"tz-rs",
"tzdb_data",
]
[[package]]
name = "tzdb_data"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1889fdffac09d65c1d95c42d5202e9b21ad8c758f426e9fe09088817ea998d6"
dependencies = [
"tz-rs",
]
[[package]]

View File

@@ -80,7 +80,7 @@ pub fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec<VectorRef>) {
"GIT_BRANCH",
"GIT_COMMIT",
"GIT_COMMIT_SHORT",
"GIT_DIRTY",
"GIT_CLEAN",
"PKG_VERSION",
]),
vec![
@@ -89,7 +89,7 @@ pub fn get_schema_columns(table_name: &str) -> (SchemaRef, Vec<VectorRef>) {
Arc::new(StringVector::from(vec![build_info
.commit_short
.to_string()])),
Arc::new(StringVector::from(vec![build_info.dirty.to_string()])),
Arc::new(StringVector::from(vec![build_info.clean.to_string()])),
Arc::new(StringVector::from(vec![build_info.version.to_string()])),
],
)

View File

@@ -49,4 +49,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
[dev-dependencies.substrait_proto]
package = "substrait"
version = "0.17"
version = "0.37"

View File

@@ -83,12 +83,10 @@ tikv-jemallocator = "0.5"
[dev-dependencies]
client = { workspace = true, features = ["testing"] }
common-test-util.workspace = true
common-version.workspace = true
serde.workspace = true
temp-env = "0.3"
tempfile.workspace = true
[target.'cfg(not(windows))'.dev-dependencies]
rexpect = "0.5"
[build-dependencies]
common-version.workspace = true

View File

@@ -21,7 +21,7 @@ use cmd::{cli, datanode, flownode, frontend, metasrv, standalone, App};
use common_version::version;
#[derive(Parser)]
#[command(name = "greptime", author, version, long_version = version!(), about)]
#[command(name = "greptime", author, version, long_version = version(), about)]
#[command(propagate_version = true)]
pub(crate) struct Command {
#[clap(subcommand)]

View File

@@ -266,7 +266,7 @@ impl StartCommand {
&opts.component.tracing,
opts.component.node_id.map(|x| x.to_string()),
);
log_versions(version!(), short_version!());
log_versions(version(), short_version());
info!("Datanode start command: {:#?}", self);
info!("Datanode options: {:#?}", opts);
@@ -338,7 +338,7 @@ mod tests {
mode = "distributed"
enable_memory_catalog = false
node_id = 42
rpc_addr = "127.0.0.1:4001"
rpc_hostname = "192.168.0.1"
[grpc]
@@ -365,7 +365,7 @@ mod tests {
mode = "distributed"
enable_memory_catalog = false
node_id = 42
[grpc]
addr = "127.0.0.1:3001"
hostname = "127.0.0.1"

View File

@@ -214,7 +214,7 @@ impl StartCommand {
&opts.component.tracing,
opts.component.node_id.map(|x| x.to_string()),
);
log_versions(version!(), short_version!());
log_versions(version(), short_version());
info!("Flownode start command: {:#?}", self);
info!("Flownode options: {:#?}", opts);

View File

@@ -259,7 +259,7 @@ impl StartCommand {
&opts.component.tracing,
opts.component.node_id.clone(),
);
log_versions(version!(), short_version!());
log_versions(version(), short_version());
info!("Frontend start command: {:#?}", self);
info!("Frontend options: {:#?}", opts);

View File

@@ -233,7 +233,7 @@ impl StartCommand {
&opts.component.tracing,
None,
);
log_versions(version!(), short_version!());
log_versions(version(), short_version());
info!("Metasrv start command: {:#?}", self);
info!("Metasrv options: {:#?}", opts);
@@ -296,7 +296,7 @@ mod tests {
[logging]
level = "debug"
dir = "/tmp/greptimedb/test/logs"
[failure_detector]
threshold = 8.0
min_std_deviation = "100ms"

View File

@@ -413,7 +413,7 @@ impl StartCommand {
&opts.component.tracing,
None,
);
log_versions(version!(), short_version!());
log_versions(version(), short_version());
info!("Standalone start command: {:#?}", self);
info!("Standalone options: {opts:#?}");

View File

@@ -11,6 +11,7 @@ workspace = true
async-trait.workspace = true
common-runtime.workspace = true
common-telemetry.workspace = true
common-version.workspace = true
reqwest.workspace = true
serde.workspace = true
tokio.workspace = true
@@ -20,6 +21,3 @@ uuid.workspace = true
common-test-util.workspace = true
hyper = { version = "0.14", features = ["full"] }
tempfile.workspace = true
[build-dependencies]
common-version.workspace = true

View File

@@ -1,17 +0,0 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
fn main() {
common_version::setup_build_info();
}

View File

@@ -22,6 +22,7 @@ use std::time::Duration;
use common_runtime::error::{Error, Result};
use common_runtime::{BoxedTaskFunction, RepeatedTask, TaskFunction};
use common_telemetry::{debug, info};
use common_version::build_info;
use reqwest::{Client, Response};
use serde::{Deserialize, Serialize};
@@ -114,11 +115,11 @@ pub enum Mode {
#[async_trait::async_trait]
pub trait Collector {
fn get_version(&self) -> String {
env!("CARGO_PKG_VERSION").to_string()
build_info().version.to_string()
}
fn get_git_hash(&self) -> String {
env!("GIT_COMMIT").to_string()
build_info().commit.to_string()
}
fn get_os(&self) -> String {
@@ -286,6 +287,7 @@ mod tests {
use std::time::Duration;
use common_test_util::ports;
use common_version::build_info;
use hyper::service::{make_service_fn, service_fn};
use hyper::Server;
use reqwest::{Client, Response};
@@ -431,8 +433,8 @@ mod tests {
let body = response.json::<StatisticData>().await.unwrap();
assert_eq!(env::consts::ARCH, body.arch);
assert_eq!(env::consts::OS, body.os);
assert_eq!(env!("CARGO_PKG_VERSION"), body.version);
assert_eq!(env!("GIT_COMMIT"), body.git_commit);
assert_eq!(build_info().version, body.version);
assert_eq!(build_info().commit, body.git_commit);
assert_eq!(Mode::Standalone, body.mode);
assert_eq!(1, body.nodes.unwrap());

View File

@@ -23,7 +23,7 @@ snafu.workspace = true
[dependencies.substrait_proto]
package = "substrait"
version = "0.17"
version = "0.37"
[dev-dependencies]
datatypes.workspace = true

View File

@@ -11,6 +11,11 @@ workspace = true
codec = ["dep:serde", "dep:schemars"]
[dependencies]
build-data = "0.1.4"
const_format = "0.2"
schemars = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
shadow-rs = "0.29"
[build-dependencies]
build-data = "0.2"
shadow-rs = "0.29"

View File

@@ -12,9 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
fn main() {
// Trigger this script if the git branch/commit changes
println!("cargo:rerun-if-changed=.git/refs/heads");
use build_data::{format_timestamp, get_source_time};
common_version::setup_build_info();
fn main() -> shadow_rs::SdResult<()> {
println!("cargo:rerun-if-changed=.git/refs/heads");
println!(
"cargo:rustc-env=SOURCE_TIMESTAMP={}",
if let Ok(t) = get_source_time() {
format_timestamp(t)
} else {
"".to_string()
}
);
build_data::set_BUILD_TIMESTAMP();
shadow_rs::new()
}

View File

@@ -12,28 +12,23 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::borrow::Cow;
use std::fmt::Display;
use std::sync::OnceLock;
#![allow(clippy::print_stdout)]
const UNKNOWN: &str = "unknown";
use std::fmt::Display;
shadow_rs::shadow!(build);
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "codec",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
pub struct BuildInfo {
pub branch: Cow<'static, str>,
pub commit: Cow<'static, str>,
pub commit_short: Cow<'static, str>,
pub dirty: Cow<'static, str>,
pub timestamp: Cow<'static, str>,
/// Rustc Version
pub rustc: Cow<'static, str>,
/// GreptimeDB Version
pub version: Cow<'static, str>,
pub branch: &'static str,
pub commit: &'static str,
pub commit_short: &'static str,
pub clean: bool,
pub source_time: &'static str,
pub build_time: &'static str,
pub rustc: &'static str,
pub target: &'static str,
pub version: &'static str,
}
impl Display for BuildInfo {
@@ -45,7 +40,7 @@ impl Display for BuildInfo {
format!("branch: {}", self.branch),
format!("commit: {}", self.commit),
format!("commit_short: {}", self.commit_short),
format!("dirty: {}", self.dirty),
format!("clean: {}", self.clean),
format!("version: {}", self.version),
]
.join("\n")
@@ -53,78 +48,82 @@ impl Display for BuildInfo {
}
}
static BUILD: OnceLock<BuildInfo> = OnceLock::new();
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(
feature = "codec",
derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema)
)]
pub struct OwnedBuildInfo {
pub branch: String,
pub commit: String,
pub commit_short: String,
pub clean: bool,
pub source_time: String,
pub build_time: String,
pub rustc: String,
pub target: String,
pub version: String,
}
pub fn build_info() -> &'static BuildInfo {
BUILD.get_or_init(|| {
let branch = build_data::get_git_branch()
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(UNKNOWN));
let commit = build_data::get_git_commit()
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(UNKNOWN));
let commit_short = build_data::get_git_commit_short()
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(UNKNOWN));
let dirty = build_data::get_git_dirty()
.map(|b| Cow::Owned(b.to_string()))
.unwrap_or(Cow::Borrowed(UNKNOWN));
let timestamp = build_data::get_source_time()
.map(|ts| Cow::Owned(build_data::format_timestamp(ts)))
.unwrap_or(Cow::Borrowed(UNKNOWN));
let rustc = build_data::get_rustc_version()
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(UNKNOWN));
let version = Cow::Borrowed(env!("CARGO_PKG_VERSION"));
BuildInfo {
branch,
commit,
commit_short,
dirty,
timestamp,
rustc,
version,
impl From<BuildInfo> for OwnedBuildInfo {
fn from(info: BuildInfo) -> Self {
OwnedBuildInfo {
branch: info.branch.to_string(),
commit: info.commit.to_string(),
commit_short: info.commit_short.to_string(),
clean: info.clean,
source_time: info.source_time.to_string(),
build_time: info.build_time.to_string(),
rustc: info.rustc.to_string(),
target: info.target.to_string(),
version: info.version.to_string(),
}
})
}
}
#[allow(clippy::print_stdout)]
pub fn setup_build_info() {
let build_info = build_info();
println!("cargo:rustc-env=GIT_COMMIT={}", build_info.commit);
println!(
"cargo:rustc-env=GIT_COMMIT_SHORT={}",
build_info.commit_short
);
println!("cargo:rustc-env=GIT_BRANCH={}", build_info.branch);
println!("cargo:rustc-env=GIT_DIRTY={}", build_info.dirty);
println!("cargo:rustc-env=GIT_DIRTY={}", build_info.dirty);
println!("cargo:rustc-env=RUSTC_VERSION={}", build_info.rustc);
println!("cargo:rustc-env=SOURCE_TIMESTAMP={}", build_info.timestamp);
}
/// Get the string for the output of cli "--version".
#[macro_export]
macro_rules! version {
() => {
concat!(
"\nbranch: ",
env!("GIT_BRANCH"),
"\ncommit: ",
env!("GIT_COMMIT"),
"\ndirty: ",
env!("GIT_DIRTY"),
"\nversion: ",
env!("CARGO_PKG_VERSION")
impl Display for OwnedBuildInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
[
format!("branch: {}", self.branch),
format!("commit: {}", self.commit),
format!("commit_short: {}", self.commit_short),
format!("clean: {}", self.clean),
format!("version: {}", self.version),
]
.join("\n")
)
};
}
}
/// Short version for reporting metrics.
#[macro_export]
macro_rules! short_version {
() => {
concat!(env!("GIT_BRANCH"), "-", env!("GIT_COMMIT_SHORT"))
};
pub const fn build_info() -> BuildInfo {
BuildInfo {
branch: build::BRANCH,
commit: build::COMMIT_HASH,
commit_short: build::SHORT_COMMIT,
clean: build::GIT_CLEAN,
source_time: env!("SOURCE_TIMESTAMP"),
build_time: env!("BUILD_TIMESTAMP"),
rustc: build::RUST_VERSION,
target: build::BUILD_TARGET,
version: build::PKG_VERSION,
}
}
const BUILD_INFO: BuildInfo = build_info();
pub const fn version() -> &'static str {
const_format::formatcp!(
"\nbranch: {}\ncommit: {}\nclean: {}\nversion: {}",
BUILD_INFO.branch,
BUILD_INFO.commit,
BUILD_INFO.clean,
BUILD_INFO.version,
)
}
pub const fn short_version() -> &'static str {
const_format::formatcp!("{}-{}", BUILD_INFO.branch, BUILD_INFO.commit_short,)
}

View File

@@ -13,7 +13,6 @@
// limitations under the License.
fn main() {
common_version::setup_build_info();
#[cfg(feature = "dashboard")]
fetch_dashboard_assets();
}
@@ -24,7 +23,7 @@ fn fetch_dashboard_assets() {
let message = "Failed to fetch dashboard assets";
let help = r#"
You can manually execute "fetch-dashboard-assets.sh" to see why,
You can manually execute "fetch-dashboard-assets.sh" to see why,
or it's a network error, just try again or enable/disable some proxy."#;
// It's very unlikely to be failed to get the current dir here, see `current_dir`'s docs.

View File

@@ -13,7 +13,6 @@
// limitations under the License.
use std::collections::HashMap;
use std::env;
use std::time::Instant;
use aide::transform::TransformOperation;
@@ -311,13 +310,14 @@ pub async fn status() -> Json<StatusResponse<'static>> {
let hostname = hostname::get()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_else(|_| "unknown".to_string());
let build_info = common_version::build_info();
Json(StatusResponse {
source_time: env!("SOURCE_TIMESTAMP"),
commit: env!("GIT_COMMIT"),
branch: env!("GIT_BRANCH"),
rustc_version: env!("RUSTC_VERSION"),
source_time: build_info.source_time,
commit: build_info.commit,
branch: build_info.branch,
rustc_version: build_info.rustc,
hostname,
version: env!("CARGO_PKG_VERSION"),
version: build_info.version,
})
}

View File

@@ -26,7 +26,7 @@ use common_query::{Output, OutputData};
use common_recordbatch::RecordBatches;
use common_telemetry::tracing;
use common_time::util::{current_time_rfc3339, yesterday_rfc3339};
use common_version::BuildInfo;
use common_version::OwnedBuildInfo;
use datatypes::prelude::ConcreteDataType;
use datatypes::scalars::ScalarVector;
use datatypes::vectors::{Float64Vector, StringVector};
@@ -100,7 +100,7 @@ pub enum PrometheusResponse {
Series(Vec<HashMap<String, String>>),
LabelValues(Vec<String>),
FormatQuery(String),
BuildInfo(BuildInfo),
BuildInfo(OwnedBuildInfo),
}
impl Default for PrometheusResponse {
@@ -148,7 +148,7 @@ pub struct BuildInfoQuery {}
)]
pub async fn build_info_query() -> PrometheusJsonResponse {
let build_info = common_version::build_info().clone();
PrometheusJsonResponse::success(PrometheusResponse::BuildInfo(build_info))
PrometheusJsonResponse::success(PrometheusResponse::BuildInfo(build_info.into()))
}
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]

View File

@@ -568,13 +568,14 @@ async fn test_status() {
let hostname = hostname::get()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_else(|_| "unknown".to_string());
let build_info = common_version::build_info();
let expected_json = http_handler::StatusResponse {
source_time: env!("SOURCE_TIMESTAMP"),
commit: env!("GIT_COMMIT"),
branch: env!("GIT_BRANCH"),
rustc_version: env!("RUSTC_VERSION"),
source_time: build_info.source_time,
commit: build_info.commit,
branch: build_info.branch,
rustc_version: build_info.rustc,
hostname,
version: env!("CARGO_PKG_VERSION"),
version: build_info.version,
};
let Json(json) = http_handler::status().await;

View File

@@ -19,7 +19,7 @@ DESC TABLE CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -29,7 +29,7 @@ SELECT * FROM CLUSTER_INFO ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -39,7 +39,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'METASRV' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -49,7 +49,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'FRONTEND' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -59,7 +59,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'FRONTEND' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+

View File

@@ -4,7 +4,7 @@ DESC TABLE CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -12,7 +12,7 @@ SELECT * FROM CLUSTER_INFO ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -20,7 +20,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'METASRV' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -28,7 +28,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE = 'FRONTEND' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -36,7 +36,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'FRONTEND' ORDER BY peer_type;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\s\d\.\d\.\d\s) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+

View File

@@ -1,12 +1,12 @@
-- SQLNESS REPLACE branch:\s+.+ branch: BRANCH
-- SQLNESS REPLACE commit:\s+.+ commit: COMMIT
-- SQLNESS REPLACE commit_short:\s+.+ commit_short: COMMIT_SHORT
-- SQLNESS REPLACE dirty:\s+.+ dirty: DIRTY
-- SQLNESS REPLACE clean:\s+.+ clean: CLEAN
-- SQLNESS REPLACE version:\s+.+ version: VERSION
-- SQLNESS REPLACE [\s\-]+
SELECT build();
++|build()|++|branch:BRANCH|commit:COMMIT|commit_short:COMMIT_SHORT|dirty:DIRTY|version:VERSION++
++|build()|++|branch:BRANCH|commit:COMMIT|commit_short:COMMIT_SHORT|clean:CLEAN|version:VERSION++
-- SQLNESS REPLACE greptimedb-[\d\.]+ greptimedb-VERSION
SELECT version();

View File

@@ -1,7 +1,7 @@
-- SQLNESS REPLACE branch:\s+.+ branch: BRANCH
-- SQLNESS REPLACE commit:\s+.+ commit: COMMIT
-- SQLNESS REPLACE commit_short:\s+.+ commit_short: COMMIT_SHORT
-- SQLNESS REPLACE dirty:\s+.+ dirty: DIRTY
-- SQLNESS REPLACE clean:\s+.+ clean: CLEAN
-- SQLNESS REPLACE version:\s+.+ version: VERSION
-- SQLNESS REPLACE [\s\-]+
SELECT build();

View File

@@ -51,9 +51,9 @@ select * from information_schema.columns order by table_schema, table_name, colu
| table_catalog | table_schema | table_name | column_name | ordinal_position | character_maximum_length | character_octet_length | numeric_precision | numeric_scale | datetime_precision | character_set_name | collation_name | column_key | extra | privileges | generation_expression | greptime_data_type | data_type | semantic_type | column_default | is_nullable | column_type | column_comment | srs_id |
+---------------+--------------------+---------------------------------------+-----------------------------------+------------------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+------------+-------+---------------+-----------------------+----------------------+-----------------+---------------+----------------+-------------+-----------------+----------------+--------+
| greptime | information_schema | build_info | git_branch | 1 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | build_info | git_clean | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | build_info | git_commit | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | build_info | git_commit_short | 3 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | build_info | git_dirty | 4 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | build_info | pkg_version | 5 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | character_sets | character_set_name | 1 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
| greptime | information_schema | character_sets | default_collate_name | 2 | 2147483647 | 2147483647 | | | | utf8 | utf8_bin | | | select,insert | | String | string | FIELD | | No | string | | |
@@ -578,7 +578,7 @@ desc table build_info;
| git_branch | String | | NO | | FIELD |
| git_commit | String | | NO | | FIELD |
| git_commit_short | String | | NO | | FIELD |
| git_dirty | String | | NO | | FIELD |
| git_clean | String | | NO | | FIELD |
| pkg_version | String | | NO | | FIELD |
+------------------+--------+-----+------+---------+---------------+

View File

@@ -19,7 +19,7 @@ DESC TABLE CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -29,7 +29,7 @@ SELECT * FROM CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -44,7 +44,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'STANDALONE';
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+

View File

@@ -4,7 +4,7 @@ DESC TABLE CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -12,7 +12,7 @@ SELECT * FROM CLUSTER_INFO;
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+
@@ -22,7 +22,7 @@ SELECT * FROM CLUSTER_INFO WHERE PEER_TYPE != 'STANDALONE';
-- SQLNESS REPLACE version node_version
-- SQLNESS REPLACE (\d\.\d\.\d) Version
-- SQLNESS REPLACE (\s[a-z0-9]{7}\s) Hash
-- SQLNESS REPLACE (\s[a-z0-9]{7,8}\s) Hash
-- SQLNESS REPLACE (\s[\-0-9T:\.]{15,}) Start_time
-- SQLNESS REPLACE ((\d+(s|ms|m)\s)+) Duration
-- SQLNESS REPLACE [\s\-]+