Skip to content

Commit

Permalink
SidecarVersion message now has version based on CARGO_PKG_VERSION_* e…
Browse files Browse the repository at this point in the history
…nv variables. (#205)
  • Loading branch information
zajko authored Oct 11, 2023
1 parent fb8fec4 commit 906022e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 8 additions & 1 deletion listener/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ enum EventListenerStatus {
/// with node and there are no more `max_connection_attempts` left. There will be no futhrer
/// tries to establish the connection.
Defunct,
/// If Event Listener reports this state it means that the node it was trying to connect to has a
/// version which sidecar can't work with
IncompatibleVersion,
}

impl EventListenerStatus {
Expand All @@ -115,6 +118,7 @@ impl EventListenerStatus {
EventListenerStatus::Connected => 2,
EventListenerStatus::Reconnecting => 3,
EventListenerStatus::Defunct => -1,
EventListenerStatus::IncompatibleVersion => -2,
} as f64;
let node_label = format!("{}:{}", node_address, sse_port);
metrics::NODE_STATUSES
Expand Down Expand Up @@ -162,7 +166,10 @@ impl EventListener {
);
match self.fetch_build_version_from_status().await {
Ok(version) => {
validate_version(&version)?;
validate_version(&version).map_err(|err| {
EventListenerStatus::IncompatibleVersion.log_status_for_event_listener(self);
err
})?;
let new_node_build_version = version;
// Compare versions to reset attempts in the case that the version changed.
// This guards against endlessly retrying when the version hasn't changed, suggesting
Expand Down
2 changes: 1 addition & 1 deletion sidecar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ utoipa = { version = "3.4.4", features = ["rc_schema"]}
utoipa-swagger-ui = { version = "3.1.5" }
warp = { version = "0.3.6", features = ["compression"] }
wheelbuf = "0.2.0"
once_cell = {workspace = true}

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5"
Expand All @@ -67,7 +68,6 @@ tabled = { version = "0.10.0", features = ["derive", "color"] }
tempfile = "3"
tokio-util = "0.7.8"
pg-embed = { git = "https://github.com/faokunega/pg-embed", tag = "v0.8.0" }
once_cell = {workspace = true}

[package.metadata.deb]
revision = "0"
Expand Down
15 changes: 10 additions & 5 deletions sidecar/src/event_stream_server/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::str::FromStr;

use super::{
config::Config,
event_indexer::EventIndex,
Expand All @@ -6,6 +8,7 @@ use super::{
use casper_event_types::{sse_data::SseData, Filter};
use casper_types::ProtocolVersion;
use futures::{future, Future, FutureExt};
use once_cell::sync::Lazy;
use tokio::{
select,
sync::{
Expand All @@ -20,7 +23,12 @@ use wheelbuf::WheelBuf;
pub type InboundData = (Option<u32>, SseData, Option<Filter>, Option<String>);
pub type OutboundReceiver =
mpsc::UnboundedReceiver<(Option<EventIndex>, SseData, Option<Filter>, Option<String>)>;

pub static SIDECAR_VERSION: Lazy<ProtocolVersion> = Lazy::new(|| {
let major: u32 = FromStr::from_str(env!("CARGO_PKG_VERSION_MAJOR")).unwrap();
let minor: u32 = FromStr::from_str(env!("CARGO_PKG_VERSION_MINOR")).unwrap();
let patch: u32 = FromStr::from_str(env!("CARGO_PKG_VERSION_PATCH")).unwrap();
ProtocolVersion::from_parts(major, minor, patch)
});
/// Run the HTTP server.
///
/// * `server_with_shutdown` is the actual server as a future which can be gracefully shut down.
Expand Down Expand Up @@ -95,12 +103,9 @@ async fn send_api_version_from_global_state(
async fn send_sidecar_version(
subscriber: &NewSubscriberInfo,
) -> Result<(), SendError<ServerSentEvent>> {
// #TODO this version shouldn't be hardcoded, it should come from the build process
subscriber
.initial_events_sender
.send(ServerSentEvent::sidecar_version_event(
ProtocolVersion::from_parts(1, 1, 0),
))
.send(ServerSentEvent::sidecar_version_event(*SIDECAR_VERSION))
}

async fn handle_incoming_data(
Expand Down
2 changes: 1 addition & 1 deletion types/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub static INTERNAL_EVENTS: Lazy<IntCounterVec> = Lazy::new(|| {
});
pub static NODE_STATUSES: Lazy<GaugeVec> = Lazy::new(|| {
let counter = GaugeVec::new(
Opts::new("node_statuses", "Current status of node to which sidecar is connected. Numbers mean: 0 - preparing; 1 - connecting; 2 - connected; 3 - reconnecting; -1 - defunct (used up all connection attempts)"),
Opts::new("node_statuses", "Current status of node to which sidecar is connected. Numbers mean: 0 - preparing; 1 - connecting; 2 - connected; 3 - reconnecting; -1 - defunct -> used up all connection attempts ; -2 - defunct -> node is in an incompatible version"),
&["node"]
)
.expect("metric can't be created");
Expand Down

0 comments on commit 906022e

Please sign in to comment.