Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(metrics): Current protocol version #9030

Merged
merged 3 commits into from
May 9, 2023
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
16 changes: 13 additions & 3 deletions chain/client/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ pub struct InfoHelper {
/// Telemetry actor.
// The field can be None for testing. This allows avoiding running actix in tests.
telemetry_actor: Option<Addr<TelemetryActor>>,
/// Log coloring enabled
/// Log coloring enabled.
log_summary_style: LogSummaryStyle,
/// Epoch height
/// Epoch id.
epoch_id: Option<EpochId>,
/// Timestamp of starting the client.
pub boot_time_seconds: i64,
Expand Down Expand Up @@ -239,6 +239,13 @@ impl InfoHelper {
}
}

/// Records protocol version of the current epoch.
fn record_protocol_version(head: &Tip, client: &crate::client::Client) {
if let Ok(version) = client.runtime_adapter.get_epoch_protocol_version(&head.epoch_id) {
metrics::CURRENT_PROTOCOL_VERSION.set(version as i64);
}
}

/// Print current summary.
pub fn log_summary(
&mut self,
Expand Down Expand Up @@ -297,8 +304,11 @@ impl InfoHelper {
InfoHelper::record_chunk_producers(&head, &client);
let next_epoch_id = Some(head.epoch_id.clone());
if self.epoch_id.ne(&next_epoch_id) {
// We only want to compute this once per epoch.
// We only want to compute this once per epoch to avoid heavy computational work, that can last up to 100ms.
InfoHelper::record_epoch_settlement_info(&head, &client);
// This isn't heavy computationally.
InfoHelper::record_protocol_version(&head, &client);

self.epoch_id = next_epoch_id;
}

Expand Down
5 changes: 5 additions & 0 deletions chain/client/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ pub(crate) static NODE_PROTOCOL_VERSION: Lazy<IntGauge> = Lazy::new(|| {
.unwrap()
});

pub(crate) static CURRENT_PROTOCOL_VERSION: Lazy<IntGauge> = Lazy::new(|| {
try_create_int_gauge("near_current_protocol_version", "Protocol version of the current epoch")
.unwrap()
});

pub(crate) static NODE_PROTOCOL_UPGRADE_VOTING_START: Lazy<IntGauge> = Lazy::new(|| {
try_create_int_gauge(
"near_node_protocol_upgrade_voting_start",
Expand Down