Skip to content

Commit

Permalink
Merge pull request #4715 from stacks-network/chore/master-to-2.5.0.0.0
Browse files Browse the repository at this point in the history
Merge master into release/2.5.0.0.0
  • Loading branch information
obycode authored Apr 25, 2024
2 parents 52d425d + c2dcdde commit abe0a0a
Show file tree
Hide file tree
Showing 39 changed files with 277 additions and 37 deletions.
10 changes: 6 additions & 4 deletions stackslib/src/monitoring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use stacks_common::util::uint::{Uint256, Uint512};
use crate::burnchains::{BurnchainSigner, Txid};
use crate::core::MemPoolDB;
use crate::net::httpcore::{StacksHttpRequest, StacksHttpResponse};
use crate::net::rpc::ConversationHttp;
use crate::net::Error as net_error;
use crate::util_lib::db::{sqlite_open, tx_busy_handler, DBConn, Error as DatabaseError};

Expand All @@ -46,19 +47,20 @@ pub fn increment_rpc_calls_counter() {
}

pub fn instrument_http_request_handler<F, R>(
req: StacksHttpRequest,
conv_http: &mut ConversationHttp,
mut req: StacksHttpRequest,
handler: F,
) -> Result<R, net_error>
where
F: FnOnce(StacksHttpRequest) -> Result<R, net_error>,
F: FnOnce(&mut ConversationHttp, StacksHttpRequest) -> Result<R, net_error>,
{
#[cfg(feature = "monitoring_prom")]
increment_rpc_calls_counter();

#[cfg(feature = "monitoring_prom")]
let timer = prometheus::new_rpc_call_timer(req.request_path());
let timer = prometheus::new_rpc_call_timer(conv_http.metrics_identifier(&mut req));

let res = handler(req);
let res = handler(conv_http, req);

#[cfg(feature = "monitoring_prom")]
timer.stop_and_record();
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/callreadonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ impl HttpRequest for RPCCallReadOnlyRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/contracts/call-read/:principal/:contract_name/:func_name"
}

/// Try to decode this request.
fn try_parse_request(
&mut self,
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getaccount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl HttpRequest for RPCGetAccountRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/accounts/:principal"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getattachment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl HttpRequest for RPCGetAttachmentRequestHandler {
Regex::new(r#"^/v2/attachments/(?P<attachment_hash>[0-9a-f]{40})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/attachments/:hash"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getattachmentsinv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl HttpRequest for RPCGetAttachmentsInvRequestHandler {
Regex::new("^/v2/attachments/inv$").unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/attachments/inv"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ impl HttpRequest for RPCBlocksRequestHandler {
Regex::new(r#"^/v2/blocks/(?P<block_id>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/blocks/:block_id"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getblock_v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ impl HttpRequest for RPCNakamotoBlockRequestHandler {
Regex::new(r#"^/v3/blocks/(?P<block_id>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v3/blocks/:block_id"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getconstantval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ impl HttpRequest for RPCGetConstantValRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/constant_val/:principal/:contract_name/:const_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getcontractabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ impl HttpRequest for RPCGetContractAbiRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/contracts/interface/:principal/:contract_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getcontractsrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl HttpRequest for RPCGetContractSrcRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/contracts/source/:principal/:contract_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getdatavar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl HttpRequest for RPCGetDataVarRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/data_var/:principal/:contract_name/:var_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getheaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl HttpRequest for RPCHeadersRequestHandler {
Regex::new(r#"^/v2/headers/(?P<quantity>[0-9]+)$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/headers/:height"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl HttpRequest for RPCPeerInfoRequestHandler {
Regex::new(r#"^/v2/info$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/info"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getistraitimplemented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ impl HttpRequest for RPCGetIsTraitImplementedRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/traits/:principal/:contract_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getmapentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ impl HttpRequest for RPCGetMapEntryRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/map_entry/:principal/:contract_name/:map_name"
}

/// Try to decode this request.
/// The body must be a hex string, encoded as a JSON string.
/// So, something like `"123abc"`. It encodes the map key as a serialized Clarity value.
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getmicroblocks_confirmed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl HttpRequest for RPCMicroblocksConfirmedRequestHandler {
Regex::new(r#"^/v2/microblocks/confirmed/(?P<block_id>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/microblocks/confirmed/:block_id"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getmicroblocks_indexed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ impl HttpRequest for RPCMicroblocksIndexedRequestHandler {
Regex::new(r#"^/v2/microblocks/(?P<tail_microblock_id>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/microblocks/:microblock_id"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getmicroblocks_unconfirmed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl HttpRequest for RPCMicroblocksUnconfirmedRequestHandler {
Regex::new(r#"^/v2/microblocks/unconfirmed/(?P<parent_block_id>[0-9a-f]{64})/(?P<start_sequence>[0-9]{1,6})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/microblocks/unconfirmed/:block_id/:seq"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getneighbors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl HttpRequest for RPCNeighborsRequestHandler {
Regex::new(r#"^/v2/neighbors$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/neighbors"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getpoxinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ impl HttpRequest for RPCPoxInfoRequestHandler {
Regex::new(r#"^/v2/pox$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/pox"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getstackerdbchunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl HttpRequest for RPCGetStackerDBChunkRequestHandler {
)).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/stackerdb/:principal/:contract_name/:slot_id/:slot_version"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getstackerdbmetadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ impl HttpRequest for RPCGetStackerDBMetadataRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/stackerdb/:principal/:contract_name"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getstackers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ impl HttpRequest for GetStackersRequestHandler {
Regex::new(r#"^/v2/stacker_set/(?P<cycle_num>[0-9]{1,20})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/stacker_set/:cycle_num"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/getstxtransfercost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ impl HttpRequest for RPCGetStxTransferCostRequestHandler {
Regex::new(r#"^/v2/fees/transfer$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/fees/transfer"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/gettenure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ impl HttpRequest for RPCNakamotoTenureRequestHandler {
Regex::new(r#"^/v3/tenures/(?P<block_id>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v3/tenures/:block_id"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/gettenureinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ impl HttpRequest for RPCNakamotoTenureInfoRequestHandler {
Regex::new(r#"^/v3/tenures/info"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v3/tenures/info"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/gettransaction_unconfirmed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ impl HttpRequest for RPCGetTransactionUnconfirmedRequestHandler {
Regex::new(r#"^/v2/transactions/unconfirmed/(?P<txid>[0-9a-f]{64})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/transactions/unconfirmed/:txid"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/liststackerdbreplicas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl HttpRequest for RPCListStackerDBReplicasRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/stackedb/:principal/:contract_name/replicas"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/postblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ impl HttpRequest for RPCPostBlockRequestHandler {
Regex::new(r#"^/v2/blocks/upload/(?P<consensus_hash>[0-9a-f]{40})$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/blocks/upload/:block"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/postblock_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ impl HttpRequest for RPCBlockProposalRequestHandler {
Regex::new(r#"^/v2/block_proposal$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/block_proposal"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/postfeerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ impl HttpRequest for RPCPostFeeRateRequestHandler {
Regex::new(r#"^/v2/fees/transaction$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/fees/transaction"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/postmempoolquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ impl HttpRequest for RPCMempoolQueryRequestHandler {
Regex::new(r#"^/v2/mempool/query$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/mempool/query"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/postmicroblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl HttpRequest for RPCPostMicroblockRequestHandler {
Regex::new(r#"^/v2/microblocks$"#).unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/microblocks"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
4 changes: 4 additions & 0 deletions stackslib/src/net/api/poststackerdbchunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ impl HttpRequest for RPCPostStackerDBChunkRequestHandler {
.unwrap()
}

fn metrics_identifier(&self) -> &str {
"/v2/block_proposal/:principal/:contract_name/chunks"
}

/// Try to decode this request.
/// There's nothing to load here, so just make sure the request is well-formed.
fn try_parse_request(
Expand Down
Loading

0 comments on commit abe0a0a

Please sign in to comment.