Skip to content

Commit

Permalink
feat(cli): add analytics timings to fill-analytics CLI command (#898)
Browse files Browse the repository at this point in the history
* Add analytics timings to `fill-analytics` CLI command

* Remove network name from metrics
  • Loading branch information
Alexandcoats authored Nov 18, 2022
1 parent b4f803b commit de6f640
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
14 changes: 14 additions & 0 deletions src/bin/inx-chronicle/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,22 @@ impl ClArgs {
.get_milestone_timestamp(index)
.await?
{
#[cfg(feature = "metrics")]
let start_time = std::time::Instant::now();
let analytics = db.get_all_analytics(index).await?;
influx_db.insert_all_analytics(timestamp, index, analytics).await?;
#[cfg(feature = "metrics")]
{
let elapsed = start_time.elapsed();
influx_db
.insert(chronicle::db::collections::metrics::AnalyticsMetrics {
time: chrono::Utc::now(),
milestone_index: index,
analytics_time: elapsed.as_millis() as u64,
chronicle_version: std::env!("CARGO_PKG_VERSION").to_string(),
})
.await?;
}
tracing::info!("Finished analytics for milestone {}", index);
} else {
tracing::info!("No milestone in database for index {}", index);
Expand Down
31 changes: 18 additions & 13 deletions src/bin/inx-chronicle/stardust_inx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ impl InxWorker {
tracing::Span::current().record("consumed", consumed_count);

self.handle_cone_stream(inx, milestone_index).await?;
#[allow(unused)]
let network_name = self.handle_protocol_params(inx, milestone_index).await?;
self.handle_protocol_params(inx, milestone_index).await?;
self.handle_node_configuration(inx, milestone_index).await?;

// This acts as a checkpoint for the syncing and has to be done last, after everything else completed.
Expand All @@ -342,10 +341,21 @@ impl InxWorker {
}
}
#[cfg(all(feature = "analytics", feature = "metrics"))]
let analytics_elapsed = self
.influx_db
.as_ref()
.and_then(|db| db.config().analytics_enabled.then_some(analytics_start_time.elapsed()));
{
if let Some(influx_db) = &self.influx_db {
if influx_db.config().analytics_enabled {
let analytics_elapsed = analytics_start_time.elapsed();
influx_db
.insert(chronicle::db::collections::metrics::AnalyticsMetrics {
time: chrono::Utc::now(),
milestone_index,
analytics_time: analytics_elapsed.as_millis() as u64,
chronicle_version: std::env!("CARGO_PKG_VERSION").to_string(),
})
.await?;
}
}
}

#[cfg(feature = "metrics")]
if let Some(influx_db) = &self.influx_db {
Expand All @@ -356,9 +366,6 @@ impl InxWorker {
time: chrono::Utc::now(),
milestone_index,
milestone_time: elapsed.as_millis() as u64,
#[cfg(feature = "analytics")]
analytics_time: analytics_elapsed.map(|d| d.as_millis() as u64),
network_name,
chronicle_version: std::env!("CARGO_PKG_VERSION").to_string(),
})
.await?;
Expand All @@ -369,21 +376,19 @@ impl InxWorker {
}

#[instrument(skip_all, level = "trace")]
async fn handle_protocol_params(&self, inx: &mut Inx, milestone_index: MilestoneIndex) -> Result<String> {
async fn handle_protocol_params(&self, inx: &mut Inx, milestone_index: MilestoneIndex) -> Result<()> {
let parameters = inx
.read_protocol_parameters(milestone_index.0.into())
.await?
.params
.inner(&())?;

let network_name = parameters.network_name().to_string();

self.db
.collection::<ProtocolUpdateCollection>()
.update_latest_protocol_parameters(milestone_index, parameters.into())
.await?;

Ok(network_name)
Ok(())
}

#[instrument(skip_all, level = "trace")]
Expand Down
5 changes: 5 additions & 0 deletions src/db/collections/metrics/influx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ use crate::db::influxdb::InfluxDbMeasurement;
impl InfluxDbMeasurement for SyncMetrics {
const NAME: &'static str = "sync_metrics";
}

#[cfg(feature = "analytics")]
impl InfluxDbMeasurement for AnalyticsMetrics {
const NAME: &'static str = "analytics_metrics";
}
13 changes: 10 additions & 3 deletions src/db/collections/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ pub struct SyncMetrics {
pub time: DateTime<Utc>,
pub milestone_index: MilestoneIndex,
pub milestone_time: u64,
#[cfg(feature = "analytics")]
pub analytics_time: Option<u64>,
#[influxdb(tag)]
pub chronicle_version: String,
}

#[cfg(feature = "analytics")]
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, InfluxDbWriteable)]
#[allow(missing_docs)]
pub struct AnalyticsMetrics {
pub time: DateTime<Utc>,
pub milestone_index: MilestoneIndex,
pub analytics_time: u64,
#[influxdb(tag)]
pub network_name: String,
pub chronicle_version: String,
}

0 comments on commit de6f640

Please sign in to comment.