Skip to content

Commit

Permalink
report yagna version as metrics
Browse files Browse the repository at this point in the history
closes #838
  • Loading branch information
etam committed Jan 19, 2021
1 parent d4f5401 commit b3c3462
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 16 deletions.
43 changes: 39 additions & 4 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ dotenv = "0.15.0"
futures = "0.3"
lazy_static = "1.4"
log = "0.4"
metrics = "0.12"
openssl = "0.10"
structopt = "0.3"
url = "2.1.1"
tokio = {version = "0.2.22", features=["uds"]}
url = "2.1.1"

[package.metadata.deb]
name="golem-requestor"
Expand Down
25 changes: 21 additions & 4 deletions core/serv/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use actix_web::{middleware, web, App, HttpServer, Responder};
use anyhow::{Context, Result};
use futures::prelude::*;
use metrics::value;
use std::{
any::TypeId,
collections::HashMap,
Expand All @@ -11,15 +12,14 @@ use std::{
};
use structopt::{clap, StructOpt};
use url::Url;

use ya_activity::service::Activity as ActivityService;
use ya_file_logging::start_logger;
use ya_identity::service::Identity as IdentityService;
use ya_market::MarketService;
use ya_metrics::{MetricsPusherOpts, MetricsService};
use ya_net::Net as NetService;
use ya_payment::{accounts as payment_accounts, PaymentService};
use ya_sgx::SgxService;

use ya_file_logging::start_logger;
use ya_persistence::executor::DbExecutor;
use ya_sb_proto::{DEFAULT_GSB_URL, GSB_URL_ENV_VAR};
use ya_service_api::{CliCtx, CommandOutput};
Expand All @@ -28,6 +28,7 @@ use ya_service_api_web::{
middleware::{auth, Identity},
rest_api_host_port, DEFAULT_YAGNA_API_URL, YAGNA_API_URL_ENV_VAR,
};
use ya_sgx::SgxService;
use ya_utils_path::data_dir::DataDir;
use ya_utils_process::lock::ProcLock;

Expand Down Expand Up @@ -315,6 +316,20 @@ async fn sd_notify(_unset_environment: bool, _state: &str) -> std::io::Result<()
Ok(())
}

fn report_version_to_metrics() {
let version = ya_compile_time_utils::semver();
value!("yagna.version.major", version.major);
value!("yagna.version.minor", version.minor);
value!("yagna.version.patch", version.patch);
value!(
"yagna.version.is_prerelease",
(!version.pre.is_empty()) as u64
);
if let Some(build_number) = ya_compile_time_utils::build_number() {
value!("yagna.version.build_number", build_number);
}
}

impl ServiceCommand {
async fn run_command(&self, ctx: &CliCtx) -> Result<CommandOutput> {
if !ctx.accept_terms {
Expand Down Expand Up @@ -371,8 +386,10 @@ impl ServiceCommand {
let mut context: ServiceContext = ctx.clone().try_into()?;
context.set_metrics_ctx(metrics_opts);
Services::gsb(&context).await?;
let drivers = start_payment_drivers(&ctx.data_dir).await?;

report_version_to_metrics();

let drivers = start_payment_drivers(&ctx.data_dir).await?;
payment_accounts::save_default_account(&ctx.data_dir, drivers)
.await
.unwrap_or_else(|e| {
Expand Down
4 changes: 2 additions & 2 deletions golem_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ async fn my_main() -> Result</*exit code*/ i32> {
pub fn banner() {
terminal::fade_in(&format!(
include_str!("banner.txt"),
version = ya_compile_time_utils::semver(),
version = ya_compile_time_utils::semver_str(),
git_commit = ya_compile_time_utils::git_rev(),
build = ya_compile_time_utils::build_number().unwrap_or("-"),
build = ya_compile_time_utils::build_number_str().unwrap_or("-"),
date = ya_compile_time_utils::build_date()
))
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions utils/compile-time-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "Compile-time utilities"

[dependencies]
git-version = "0.3.4"
semver = "0.11.0"

[build-dependencies]
vergen = "3.1.0"
30 changes: 25 additions & 5 deletions utils/compile-time-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use git_version::git_version;
use semver::Version;

/// Returns latest tag or version from Cargo.toml`.
pub fn git_tag() -> &'static str {
Expand All @@ -19,12 +20,19 @@ pub fn build_date() -> &'static str {
}

/// Returns Github Actions build number if available or None.
pub fn build_number() -> Option<&'static str> {
pub fn build_number_str() -> Option<&'static str> {
option_env!("GITHUB_RUN_NUMBER")
}

pub fn build_number() -> Option<u64> {
build_number_str().map(|i| {
// should not panic
i.parse().unwrap()
})
}

/// convert tag to a semantic version
pub fn semver() -> &'static str {
pub fn semver_str() -> &'static str {
let mut version = git_tag();
for prefix in ["pre-rel-", "v"].iter() {
if version.starts_with(prefix) {
Expand All @@ -34,12 +42,17 @@ pub fn semver() -> &'static str {
version
}

pub fn semver() -> Version {
// It must parse correctly and if it passes test it won't change later.
Version::parse(semver_str()).unwrap()
}

#[macro_export]
macro_rules! version_describe {
() => {
Box::leak(
[
$crate::semver(),
$crate::semver_str(),
" (",
$crate::git_rev(),
" ",
Expand All @@ -60,7 +73,14 @@ mod test {
use super::*;

#[test]
fn test() {
println!("{}", semver())
fn test_semver() {
// should not panic
semver();
}

#[test]
fn test_build_number() {
// should not panic
build_number();
}
}

0 comments on commit b3c3462

Please sign in to comment.