Skip to content

Commit

Permalink
fix: build info should use build time env var (#4343)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tisonkun authored Jul 12, 2024
1 parent ab22bba commit 285ffc5
Show file tree
Hide file tree
Showing 28 changed files with 320 additions and 270 deletions.
264 changes: 160 additions & 104 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/catalog/src/information_schema/memory_table/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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()])),
],
)
Expand Down
2 changes: 1 addition & 1 deletion src/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[dev-dependencies.substrait_proto]
package = "substrait"
version = "0.17"
version = "0.37"
4 changes: 1 addition & 3 deletions src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/cmd/src/bin/greptime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/src/datanode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/src/flownode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
[logging]
level = "debug"
dir = "/tmp/greptimedb/test/logs"
[failure_detector]
threshold = 8.0
min_std_deviation = "100ms"
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:#?}");
Expand Down
4 changes: 1 addition & 3 deletions src/common/greptimedb-telemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
17 changes: 0 additions & 17 deletions src/common/greptimedb-telemetry/build.rs

This file was deleted.

10 changes: 6 additions & 4 deletions src/common/greptimedb-telemetry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion src/common/substrait/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ snafu.workspace = true

[dependencies.substrait_proto]
package = "substrait"
version = "0.17"
version = "0.37"

[dev-dependencies]
datatypes.workspace = true
Expand Down
7 changes: 6 additions & 1 deletion src/common/version/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 13 additions & 4 deletions src/cmd/build.rs → src/common/version/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Loading

0 comments on commit 285ffc5

Please sign in to comment.