Skip to content

Commit

Permalink
chore(bors): merge pull request #130
Browse files Browse the repository at this point in the history
130: feat(call-home): use version_info crate to generate git version r=niladrih a=niladrih

This ports the changes from #125 for release/2.0 branch

Co-authored-by: Niladri Halder <[email protected]>
  • Loading branch information
mayastor-bors and niladrih committed Mar 10, 2023
2 parents e582d1b + 701b0d4 commit f673649
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
39 changes: 20 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion call-home/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ reqwest-retry = "0.1.5"
chrono = "0.4.22"
rand = "0.8.5"
mktemp = "0.4.1"
humantime = "2.1.0"
humantime = "2.1.0"
utils = { path = "../dependencies/control-plane/utils/utils-lib" }
11 changes: 9 additions & 2 deletions call-home/src/common/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{
env,
path::{Path, PathBuf},
};
use utils::version_info;

/// PRODUCT is the name of the project for which this call-home component is deployed.
pub(crate) const PRODUCT: &str = "Mayastor";
Expand Down Expand Up @@ -63,5 +64,11 @@ pub(crate) fn call_home_frequency() -> std::time::Duration {
.unwrap()
}

/// Release version
pub(crate) const RELEASE_VERSION: &str = "2.0.1";
/// Returns the git tag version (if tag is found) or simply returns the commit hash (12 characters).
pub(crate) fn release_version() -> String {
let version_info = version_info!();
match version_info.version_tag {
Some(tag) => tag,
None => version_info.commit_hash,
}
}
5 changes: 3 additions & 2 deletions call-home/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ use tokio::time::sleep;
use tracing::{error, info};
use tracing_subscriber::EnvFilter;
use url::Url;
use utils::{package_description, version_info_str};

#[derive(Parser)]
#[clap(author, version, about)]
#[clap(name = package_description!(), version = version_info_str!())]
struct CliArgs {
/// An URL endpoint to the control plane's rest endpoint.
#[clap(short, long, default_value = "http://mayastor-api-rest:8081")]
Expand Down Expand Up @@ -50,7 +51,7 @@ async fn main() {

async fn run() -> anyhow::Result<()> {
let args = CliArgs::args();
let version = RELEASE_VERSION.to_string();
let version = release_version();
let endpoint = args.endpoint;
let namespace = digest(args.namespace);

Expand Down
2 changes: 1 addition & 1 deletion call-home/src/transmitter/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Receiver {
.client
.post(&self.url)
.header("CAStor-Cluster-Id", &self.cluster_id)
.header("CAStor-Version", RELEASE_VERSION)
.header("CAStor-Version", release_version())
.header("CAStor-Report-Type", "health_report")
.header("CAStor-Product", PRODUCT)
.header("CAStor-Time", Utc::now().to_string())
Expand Down

0 comments on commit f673649

Please sign in to comment.