Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log version information on startup #2474

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ default = []
fpvec_bounded_l2 = ["dep:fixed", "janus_core/fpvec_bounded_l2"]
tokio-console = ["dep:console-subscriber"]
otlp = [
"dep:git-version",
"dep:opentelemetry-otlp",
"dep:opentelemetry-semantic-conventions",
"dep:opentelemetry_sdk",
"dep:tracing-opentelemetry",
]
prometheus = [
"dep:git-version",
"dep:opentelemetry-prometheus",
"dep:opentelemetry_sdk",
"dep:prometheus",
Expand Down Expand Up @@ -52,7 +50,7 @@ deadpool-postgres = "0.12.1"
derivative.workspace = true
fixed = { version = "1.24", optional = true }
futures = "0.3.30"
git-version = { version = "0.3.9", optional = true }
git-version = "0.3.9"
inahga marked this conversation as resolved.
Show resolved Hide resolved
hex = { version = "0.4.3", features = ["serde"], optional = true }
http = "0.2.11"
http-api-problem = "0.57.0"
Expand Down
4 changes: 4 additions & 0 deletions aggregator/src/bin/janus_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use clap::Parser;
use janus_aggregator::{
binary_utils::{database_pool, datastore, read_config, CommonBinaryOptions},
config::{BinaryConfig, CommonConfig},
git_revision,
metrics::{install_metrics_exporter, MetricsExporterHandle},
trace::{install_trace_subscriber, TraceGuards},
};
Expand Down Expand Up @@ -37,6 +38,9 @@ async fn main() -> Result<()> {
info!(
common_options = ?&command_line_options.common_options,
config = ?config_file,
version = env!("CARGO_PKG_VERSION"),
git_revision = git_revision(),
rust_version = env!("RUSTC_SEMVER"),
"Starting up"
);

Expand Down
10 changes: 9 additions & 1 deletion aggregator/src/binary_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod job_driver;

use crate::{
config::{BinaryConfig, DbConfig},
git_revision,
metrics::install_metrics_exporter,
trace::{install_trace_subscriber, TraceReloadHandle},
};
Expand Down Expand Up @@ -251,7 +252,14 @@ where
let stopper = Stopper::new();
setup_signal_handler(stopper.clone()).context("failed to register SIGTERM signal handler")?;

info!(common_options = ?options.common_options(), ?config, "Starting up");
info!(
common_options = ?options.common_options(),
?config,
version = env!("CARGO_PKG_VERSION"),
git_revision = git_revision(),
rust_version = env!("RUSTC_SEMVER"),
"Starting up"
);

// Connect to database.
let pool = database_pool(
Expand Down
14 changes: 14 additions & 0 deletions aggregator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::too_many_arguments)]

use git_version::git_version;

pub mod aggregator;
pub mod binaries;
pub mod binary_utils;
Expand All @@ -14,3 +16,15 @@ enum Operation {
Put,
Update,
}

/// Returns the git revision used to build this crate, using `git describe` if available, or the
/// environment variable `GIT_REVISION`. Returns `"unknown"` instead if neither is available.
pub fn git_revision() -> &'static str {
let mut git_revision: &'static str = git_version!(fallback = "unknown");
if git_revision == "unknown" {
if let Some(value) = option_env!("GIT_REVISION") {
git_revision = value;
}
}
git_revision
}
11 changes: 2 additions & 9 deletions aggregator/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use {

#[cfg(any(feature = "otlp", feature = "prometheus"))]
use {
git_version::git_version,
crate::git_revision,
janus_aggregator_core::datastore::TRANSACTION_RETRIES_METER_NAME,
opentelemetry::{metrics::MetricsError, KeyValue},
opentelemetry_sdk::{
Expand Down Expand Up @@ -282,17 +282,10 @@ fn resource() -> Resource {
// Note that the implementation of `Default` pulls in attributes set via environment variables.
let default_resource = Resource::default();

let mut git_revision = git_version!(fallback = "unknown");
if git_revision == "unknown" {
if let Some(value) = option_env!("GIT_REVISION") {
git_revision = value;
}
}

let version_info_resource = Resource::new([
KeyValue::new(
"service.version",
format!("{}-{}", env!("CARGO_PKG_VERSION"), git_revision),
format!("{}-{}", env!("CARGO_PKG_VERSION"), git_revision()),
),
KeyValue::new("process.runtime.name", "Rust"),
KeyValue::new("process.runtime.version", env!("RUSTC_SEMVER")),
Expand Down
Loading