From 081734aa6666223186083a76de01b4c80b3b866d Mon Sep 17 00:00:00 2001 From: Daniel Xifra Date: Tue, 22 Oct 2024 12:43:32 -0300 Subject: [PATCH] New bidding service version metric. --- .../bidding_service.rs | 19 ++++++++++++++++--- .../client/bidding_service_client_adapter.rs | 16 +++++++++++++--- .../proto/bidding_service.proto | 10 +++++++++- src/metrics.rs | 19 +++++++++++++++++-- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/bidding_service_wrapper/bidding_service.rs b/src/bidding_service_wrapper/bidding_service.rs index b863818..53712b1 100644 --- a/src/bidding_service_wrapper/bidding_service.rs +++ b/src/bidding_service_wrapper/bidding_service.rs @@ -1,3 +1,14 @@ +/// Mapping of build_info::Version +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct BidderVersionInfo { + #[prost(string, tag = "1")] + pub git_commit: ::prost::alloc::string::String, + #[prost(string, tag = "2")] + pub git_ref: ::prost::alloc::string::String, + #[prost(string, tag = "3")] + pub build_time_utc: ::prost::alloc::string::String, +} #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct Empty {} @@ -190,10 +201,11 @@ pub mod bidding_service_client { self } /// Call after connection before calling anything. This will really create the BiddingService on the server side. + /// Returns the version info for the server side. pub async fn initialize( &mut self, request: impl tonic::IntoRequest, - ) -> Result, tonic::Status> { + ) -> Result, tonic::Status> { self.inner .ready() .await @@ -358,10 +370,11 @@ pub mod bidding_service_server { #[async_trait] pub trait BiddingService: Send + Sync + 'static { /// Call after connection before calling anything. This will really create the BiddingService on the server side. + /// Returns the version info for the server side. async fn initialize( &self, request: tonic::Request, - ) -> Result, tonic::Status>; + ) -> Result, tonic::Status>; /// Server streaming response type for the CreateSlotBidder method. type CreateSlotBidderStream: futures_core::Stream< Item = Result, @@ -476,7 +489,7 @@ pub mod bidding_service_server { T: BiddingService, > tonic::server::UnaryService for InitializeSvc { - type Response = super::Empty; + type Response = super::BidderVersionInfo; type Future = BoxFuture< tonic::Response, tonic::Status, diff --git a/src/bidding_service_wrapper/client/bidding_service_client_adapter.rs b/src/bidding_service_wrapper/client/bidding_service_client_adapter.rs index 5e074e2..4c81a3c 100644 --- a/src/bidding_service_wrapper/client/bidding_service_client_adapter.rs +++ b/src/bidding_service_wrapper/client/bidding_service_client_adapter.rs @@ -1,6 +1,9 @@ use alloy_primitives::U256; -use rbuilder::live_builder::block_output::bidding::interfaces::{ - BiddingServiceWinControl, LandedBlockInfo as RealLandedBlockInfo, +use rbuilder::{ + live_builder::block_output::bidding::interfaces::{ + BiddingServiceWinControl, LandedBlockInfo as RealLandedBlockInfo, + }, + utils::build_info::Version, }; use std::{ path::PathBuf, @@ -19,6 +22,7 @@ use crate::{ MustWinBlockParams, NewBlockParams, UpdateNewBidParams, }, block_descriptor_bidding::traits::{Bid, BidMaker, BiddingService, BlockId, SlotBidder}, + metrics::set_bidding_service_version, }; use super::slot_bidder_client::SlotBidderClient; @@ -102,10 +106,16 @@ impl BiddingServiceClientAdapter { .map(real2rpc_landed_block_info) .collect(), }; - client + let bidding_service_version = client .initialize(init_params) .await .map_err(|_| Error::InitFailed)?; + let bidding_service_version = bidding_service_version.into_inner(); + set_bidding_service_version(Version { + git_commit: bidding_service_version.git_commit, + git_ref: bidding_service_version.git_ref, + build_time_utc: bidding_service_version.build_time_utc, + }); let (commands_sender, mut rx) = mpsc::unbounded_channel::(); // Spawn a task to execute received futures tokio::spawn(async move { diff --git a/src/bidding_service_wrapper/proto/bidding_service.proto b/src/bidding_service_wrapper/proto/bidding_service.proto index 3ab5f60..103e068 100644 --- a/src/bidding_service_wrapper/proto/bidding_service.proto +++ b/src/bidding_service_wrapper/proto/bidding_service.proto @@ -14,7 +14,8 @@ package bidding_service; service BiddingService { // Call after connection before calling anything. This will really create the BiddingService on the server side. - rpc Initialize(LandedBlocksParams) returns (Empty); + // Returns the version info for the server side. + rpc Initialize(LandedBlocksParams) returns (BidderVersionInfo); // BiddingService rpc CreateSlotBidder(CreateSlotBidderParams) returns (stream Callback); @@ -36,6 +37,13 @@ service BiddingService { // uint64 block + uint64 slot should be something like BidderId +// Mapping of build_info::Version +message BidderVersionInfo { + string git_commit = 1; + string git_ref = 2; + string build_time_utc = 3; +} + message Empty { } diff --git a/src/metrics.rs b/src/metrics.rs index ccdfd29..e403392 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -1,8 +1,8 @@ use ctor::ctor; use lazy_static::lazy_static; use metrics_macros::register_metrics; -use prometheus::{IntCounter, IntCounterVec, Opts}; -use rbuilder::telemetry::REGISTRY; +use prometheus::{IntCounter, IntCounterVec, IntGaugeVec, Opts}; +use rbuilder::{telemetry::REGISTRY, utils::build_info::Version}; register_metrics! { pub static BLOCK_API_ERRORS: IntCounterVec = IntCounterVec::new( @@ -17,6 +17,11 @@ register_metrics! { ) .unwrap(); + pub static BIDDING_SERVICE_VERSION: IntGaugeVec = IntGaugeVec::new( + Opts::new("bidding_service_version", "Version of the bidding service"), + &["git", "git_ref", "build_time_utc"] + ) + .unwrap(); } pub fn inc_blocks_api_errors() { @@ -26,3 +31,13 @@ pub fn inc_blocks_api_errors() { pub fn inc_non_0_competition_bids() { NON_0_COMPETITION_BIDS.inc(); } + +pub(super) fn set_bidding_service_version(version: Version) { + BIDDING_SERVICE_VERSION + .with_label_values(&[ + &version.git_commit, + &version.git_ref, + &version.build_time_utc, + ]) + .set(1); +}