-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into test/nightly-schemathesis
- Loading branch information
Showing
44 changed files
with
1,454 additions
and
764 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
catalyst-gateway/bin/src/db/index/queries/cql/get_all_stake_addrs.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT | ||
stake_address,vote_key | ||
FROM cip36_registration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
catalyst-gateway/bin/src/db/index/queries/registrations/get_all_stakes_and_vote_keys.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//! Get all stake and vote keys (`stake_pub_key,vote_key`) | ||
//! Result is used to compose various query registrations for snapshot. | ||
use std::sync::Arc; | ||
|
||
use scylla::{ | ||
prepared_statement::PreparedStatement, transport::iterator::TypedRowStream, DeserializeRow, | ||
SerializeRow, Session, | ||
}; | ||
use tracing::error; | ||
|
||
use crate::db::index::{ | ||
queries::{PreparedQueries, PreparedSelectQuery}, | ||
session::CassandraSession, | ||
}; | ||
|
||
/// Get all (`stake_addr,vote` keys) | ||
/// [(`stake_addr,vote_key`)] | ||
const GET_ALL_STAKES_AND_VOTE_KEYS: &str = include_str!("../cql/get_all_stake_addrs.cql"); | ||
|
||
/// Get all stake and vote keys from cip36 registration | ||
#[derive(SerializeRow)] | ||
pub(crate) struct GetAllStakesAndVoteKeysParams {} | ||
|
||
/// Get stakes and vote keys for snapshot. | ||
#[derive(DeserializeRow)] | ||
pub(crate) struct GetAllStakesAndVoteKeysQuery { | ||
/// Full Stake Address (not hashed, 32 byte ED25519 Public key). | ||
pub stake_address: Vec<u8>, | ||
/// Voting Public Key | ||
pub vote_key: Vec<u8>, | ||
} | ||
|
||
impl GetAllStakesAndVoteKeysQuery { | ||
/// Prepares get all `stake_addr` paired with vote keys [(`stake_addr,vote_key`)] | ||
pub(crate) async fn prepare(session: Arc<Session>) -> anyhow::Result<PreparedStatement> { | ||
let get_all_stake_and_vote_keys = PreparedQueries::prepare( | ||
session, | ||
GET_ALL_STAKES_AND_VOTE_KEYS, | ||
scylla::statement::Consistency::All, | ||
true, | ||
) | ||
.await; | ||
|
||
get_all_stake_and_vote_keys.inspect_err( | ||
|error| error!(error=%error, "Failed to prepare get all (stake addrs, vote_keys)"), | ||
) | ||
} | ||
|
||
/// Executes get all `stake_addr` paired with vote keys [(`stake_addr,vote_key`)] | ||
pub(crate) async fn execute( | ||
session: &CassandraSession, params: GetAllStakesAndVoteKeysParams, | ||
) -> anyhow::Result<TypedRowStream<GetAllStakesAndVoteKeysQuery>> { | ||
let iter = session | ||
.execute_iter(PreparedSelectQuery::GetAllStakesAndVoteKeys, params) | ||
.await? | ||
.rows_stream::<GetAllStakesAndVoteKeysQuery>()?; | ||
|
||
Ok(iter) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
catalyst-gateway/bin/src/db/index/schema/cql/cip36_registration_for_vote_key.cql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ mod cli; | |
mod db; | ||
mod jinja; | ||
mod logger; | ||
mod metrics; | ||
mod service; | ||
mod settings; | ||
mod utils; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//! Metrics related to Chain Follower analytics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//! Metrics related to Chain Indexer analytics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//! Metrics related to endpoint analytics. | ||
use std::sync::LazyLock; | ||
|
||
use prometheus::{register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec}; | ||
|
||
/// Labels for the metrics | ||
const METRIC_LABELS: [&str; 3] = ["endpoint", "method", "status_code"]; | ||
/// Labels for the client metrics | ||
const CLIENT_METRIC_LABELS: [&str; 2] = ["client", "status_code"]; | ||
|
||
// Prometheus Metrics maintained by the service | ||
|
||
/// HTTP Request duration histogram. | ||
pub(crate) static HTTP_REQ_DURATION_MS: LazyLock<HistogramVec> = LazyLock::new(|| { | ||
register_histogram_vec!( | ||
"http_request_duration_ms", | ||
"Duration of HTTP requests in milliseconds", | ||
&METRIC_LABELS | ||
) | ||
.unwrap() | ||
}); | ||
|
||
/// HTTP Request CPU Time histogram. | ||
pub(crate) static HTTP_REQ_CPU_TIME_MS: LazyLock<HistogramVec> = LazyLock::new(|| { | ||
register_histogram_vec!( | ||
"http_request_cpu_time_ms", | ||
"CPU Time of HTTP requests in milliseconds", | ||
&METRIC_LABELS | ||
) | ||
.unwrap() | ||
}); | ||
|
||
// No Tacho implemented to enable this. | ||
// static ref HTTP_REQUEST_RATE: GaugeVec = register_gauge_vec!( | ||
// "http_request_rate", | ||
// "Rate of HTTP requests per second", | ||
// &METRIC_LABELS | ||
// ) | ||
// .unwrap(); | ||
|
||
/// HTTP Request count histogram. | ||
pub(crate) static HTTP_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| { | ||
register_int_counter_vec!( | ||
"http_request_count", | ||
"Number of HTTP requests", | ||
&METRIC_LABELS | ||
) | ||
.unwrap() | ||
}); | ||
|
||
/// Client Request Count histogram. | ||
pub(crate) static CLIENT_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| { | ||
register_int_counter_vec!( | ||
"client_request_count", | ||
"Number of HTTP requests per client", | ||
&CLIENT_METRIC_LABELS | ||
) | ||
.unwrap() | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//! Metrics related to memory analytics. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! This module contains submodules related to metrics report and analytics. | ||
use prometheus::{default_registry, Registry}; | ||
|
||
pub(crate) mod chain_follower; | ||
pub(crate) mod chain_indexer; | ||
pub(crate) mod endpoint; | ||
pub(crate) mod memory; | ||
|
||
/// Initialize Prometheus metrics. | ||
/// | ||
/// ## Returns | ||
/// | ||
/// Returns the default prometheus registry. | ||
#[must_use] | ||
pub(crate) fn init_prometheus() -> Registry { | ||
default_registry().clone() | ||
} |
Oops, something went wrong.