Skip to content
Open
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions node/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ workspace = true
features = [ "parking_lot" ]
optional = true

[dependencies.metrics]
version = "0.22"

[dependencies.metrics-exporter-prometheus]
version = "0.13"

Expand All @@ -43,3 +46,6 @@ features = [ "console", "ledger", "metrics" ]

[dependencies.time]
workspace = true

[build-dependencies.built]
workspace = true
18 changes: 18 additions & 0 deletions node/metrics/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2019-2025 Provable Inc.
// This file is part of the snarkOS library.

// 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() {
built::write_built_file().expect("Failed to acquire build-time information");
}
25 changes: 24 additions & 1 deletion node/metrics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod names;
pub mod names;

// Expose the names at the crate level for easy access.
pub use names::*;
Expand Down Expand Up @@ -63,6 +63,9 @@ pub fn initialize_metrics(ip: Option<SocketAddr>) {
for name in crate::names::HISTOGRAM_NAMES {
register_histogram(name);
}

// Set the build information metric
set_build_info();
}

pub fn update_block_metrics<N: Network>(block: &Block<N>) {
Expand Down Expand Up @@ -154,3 +157,23 @@ pub fn add_transmission_latency_metric<N: Network>(
transmissions_tracker.remove(&key);
}
}

// Include the generated build information
mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

/// Sets the build information metric with version details as labels.
/// The resulting metric will show as:
/// snarkos_build_info{version="4.2.1",git_commit="abc123",git_branch="main",features="cuda,metrics"} 1
pub fn set_build_info() {
let version = built_info::PKG_VERSION;
let git_commit = built_info::GIT_COMMIT_HASH.unwrap_or("unknown");
let git_branch = built_info::GIT_HEAD_REF.unwrap_or("unknown");
let features = built_info::FEATURES_LOWERCASE_STR.replace(' ', "");

::metrics::gauge!(build::BUILD_INFO, "version" => version.to_string()).set(1.0);
::metrics::gauge!(build::BUILD_INFO, "git_commit" => git_commit.to_string()).set(1.0);
::metrics::gauge!(build::BUILD_INFO, "git_branch" => git_branch.to_string()).set(1.0);
::metrics::gauge!(build::BUILD_INFO, "features" => features).set(1.0);
}
4 changes: 4 additions & 0 deletions node/metrics/src/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ pub mod router {
pub mod tcp {
pub const TCP_TASKS: &str = "snarkos_tcp_tasks_total";
}

pub mod build {
Copy link
Collaborator

@vicsn vicsn Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be added to GAUGE_NAMES above?

I think for this PR, manual testing should suffice. If you haven't checked the endpoint already, can you run the top level devnet.sh script from this repo, query the :5000/metrics endpoint, and see if the build info shows up as expected?

I can hear you thinking that we should also have tests to prevent unexpected changes to our API endpoints, it is on the roadmap, and will be tracking how the explorer designs and implements these tests.

pub const BUILD_INFO: &str = "snarkos_build_info";
}