approval-voting: more spans and metrics (#2742)

* approval-voting: more spans and metrics

* s/db/approval db
This commit is contained in:
Andronik Ordian
2021-03-28 23:28:49 +02:00
committed by GitHub
parent e3dc9024ce
commit 171fc69961
2 changed files with 31 additions and 3 deletions
@@ -502,9 +502,14 @@ impl Transaction {
let _ = self.candidate_entries.insert(hash, entry);
}
/// Returns true if the transaction contains no actions
pub(crate) fn is_empty(&self) -> bool {
self.block_entries.is_empty() && self.candidate_entries.is_empty()
}
/// Write the contents of the transaction, atomically, to the DB.
pub(crate) fn write(self, db: &dyn KeyValueDB) -> Result<()> {
if self.block_entries.is_empty() && self.candidate_entries.is_empty() {
if self.is_empty() {
return Ok(())
}
+25 -2
View File
@@ -109,6 +109,7 @@ struct MetricsInner {
wakeups_triggered_total: prometheus::Counter<prometheus::U64>,
candidate_approval_time_ticks: prometheus::Histogram,
block_approval_time_ticks: prometheus::Histogram,
time_db_transaction: prometheus::Histogram,
}
/// Aproval Voting metrics.
@@ -157,6 +158,10 @@ impl Metrics {
metrics.block_approval_time_ticks.observe(ticks as f64);
}
}
fn time_db_transaction(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.time_db_transaction.start_timer())
}
}
impl metrics::Metrics for Metrics {
@@ -217,6 +222,15 @@ impl metrics::Metrics for Metrics {
)?,
registry,
)?,
time_db_transaction: prometheus::register(
prometheus::Histogram::with_opts(
prometheus::HistogramOpts::new(
"parachain_time_approval_db_transaction",
"Time spent writing an approval db transaction.",
)
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
@@ -570,8 +584,12 @@ async fn handle_actions(
}
}
transaction.write(db)
.map_err(|e| SubsystemError::with_origin("approval-voting", e))?;
if !transaction.is_empty() {
let _timer = metrics.time_db_transaction();
transaction.write(db)
.map_err(|e| SubsystemError::with_origin("approval-voting", e))?;
}
Ok(conclude)
}
@@ -1609,6 +1627,11 @@ async fn launch_approval(
let candidate = candidate.clone();
let background = async move {
let _span = jaeger::Span::from_encodable((block_hash, candidate_hash), "launch-approval")
.with_relay_parent(block_hash)
.with_candidate(candidate_hash)
.with_stage(jaeger::Stage::ApprovalChecking);
let available_data = match a_rx.await {
Err(_) => return,
Ok(Ok(a)) => a,