Skip to content

Commit

Permalink
feat(analytics): compute daily active addresses (#968)
Browse files Browse the repository at this point in the history
* feat(analytics): compute daily active addresses

* Fix CI

* Add dashboard panel

* Fix

* minor tweak

* barAlignment

* Remove `AddressActivityAnalytics`

* Remove more `AddressActivity`

* Fmt

* revert alignment

* fix test

* fix dashboard

* address feedback

* minor improvements

* change timestamp

* fmt

* Update src/db/collections/analytics/mod.rs

Co-authored-by: /alex/ <alexander.schmidt@iota.org>

Co-authored-by: /alex/ <alexander.schmidt@iota.org>
  • Loading branch information
grtlr and Alex6323 authored Dec 13, 2022
1 parent 6fa03e2 commit 04015f3
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 276 deletions.
122 changes: 120 additions & 2 deletions docker/assets/grafana/dashboards/analytics_dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,122 @@
"title": "SMR Tokens Transferred/$aggregation_interval",
"type": "timeseries"
},
{
"datasource": {
"type": "influxdb",
"uid": "PE5723DBC504634E6"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "bars",
"fillOpacity": 30,
"gradientMode": "hue",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "stepAfter",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "auto",
"spanNulls": false,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 9,
"w": 12,
"x": 12,
"y": 27
},
"id": 63,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"alias": "Addresses",
"datasource": {
"type": "influxdb",
"uid": "PE5723DBC504634E6"
},
"groupBy": [
{
"params": [
"1d"
],
"type": "time"
}
],
"measurement": "stardust_daily_active_addresses",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"count"
],
"type": "field"
},
{
"params": [],
"type": "last"
}
]
],
"tags": []
}
],
"title": "Number of Daily Active Addresses",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
Expand Down Expand Up @@ -1379,7 +1495,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down Expand Up @@ -1562,7 +1679,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down
29 changes: 20 additions & 9 deletions src/bin/inx-chronicle/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub struct MongoDbArgs {
/// The MongoDB connection string.
#[arg(long, env = "MONGODB_CONN_STR")]
pub mongodb_conn_str: Option<String>,
/// The MongoDB database.
#[arg(long, env = "MONGODB_DATABASE")]
pub mongodb_database: Option<String>,
}

#[cfg(any(feature = "analytics", feature = "metrics"))]
Expand Down Expand Up @@ -117,6 +120,10 @@ impl ClArgs {
config.mongodb.conn_str = conn_str.clone();
}

if let Some(db_name) = &self.mongodb.mongodb_database {
config.mongodb.database_name = db_name.clone();
}

#[cfg(all(feature = "stardust", feature = "inx"))]
{
if let Some(connect_url) = &self.inx.inx_url {
Expand Down Expand Up @@ -258,6 +265,8 @@ impl ClArgs {
tmp.drain().map(Into::into).collect()
};

tracing::info!("Computing the following analytics: {:?}", selected_analytics);

for index in (*start_milestone..*end_milestone).skip(i).step_by(num_tasks) {
let milestone_index = index.into();
if let Some(milestone_timestamp) = db
Expand Down Expand Up @@ -331,38 +340,40 @@ impl ClArgs {

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, ValueEnum)]
pub enum AnalyticsChoice {
AddressActivity,
// Please keep the alphabetic order.
Addresses,
BaseToken,
BlockActivity,
DailyActiveAddresses,
LedgerOutputs,
OutputActivity,
LedgerSize,
OutputActivity,
ProtocolParameters,
UnclaimedTokens,
BlockActivity,
UnlockConditions,
ProtocolParameters,
}

#[cfg(all(feature = "analytics", feature = "stardust"))]
impl From<AnalyticsChoice> for Box<dyn chronicle::db::collections::analytics::Analytic> {
fn from(value: AnalyticsChoice) -> Self {
use chronicle::db::collections::analytics::{
AddressActivityAnalytics, AddressAnalytics, BaseTokenActivityAnalytics, BlockActivityAnalytics,
AddressAnalytics, BaseTokenActivityAnalytics, BlockActivityAnalytics, DailyActiveAddressesAnalytics,
LedgerOutputAnalytics, LedgerSizeAnalytics, OutputActivityAnalytics, ProtocolParametersAnalytics,
UnclaimedTokenAnalytics, UnlockConditionAnalytics,
};

match value {
AnalyticsChoice::AddressActivity => Box::new(AddressActivityAnalytics),
// Please keep the alphabetic order.
AnalyticsChoice::Addresses => Box::new(AddressAnalytics),
AnalyticsChoice::BaseToken => Box::new(BaseTokenActivityAnalytics),
AnalyticsChoice::BlockActivity => Box::new(BlockActivityAnalytics),
AnalyticsChoice::DailyActiveAddresses => Box::new(DailyActiveAddressesAnalytics::default()),
AnalyticsChoice::LedgerOutputs => Box::new(LedgerOutputAnalytics),
AnalyticsChoice::OutputActivity => Box::new(OutputActivityAnalytics),
AnalyticsChoice::LedgerSize => Box::new(LedgerSizeAnalytics),
AnalyticsChoice::OutputActivity => Box::new(OutputActivityAnalytics),
AnalyticsChoice::ProtocolParameters => Box::new(ProtocolParametersAnalytics),
AnalyticsChoice::UnclaimedTokens => Box::new(UnclaimedTokenAnalytics),
AnalyticsChoice::BlockActivity => Box::new(BlockActivityAnalytics),
AnalyticsChoice::UnlockConditions => Box::new(UnlockConditionAnalytics),
AnalyticsChoice::ProtocolParameters => Box::new(ProtocolParametersAnalytics),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/bin/inx-chronicle/stardust_inx/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use thiserror::Error;

#[derive(Debug, Error)]
pub enum InxWorkerError {
#[cfg(feature = "analytics")]
#[error("Analytics error: {0}")]
Analytics(#[from] chronicle::db::collections::analytics::Error),
#[error("failed to establish connection")]
ConnectionError,
#[cfg(any(feature = "analytics", feature = "metrics"))]
Expand Down
7 changes: 5 additions & 2 deletions src/bin/inx-chronicle/stardust_inx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ pub async fn gather_analytics(
let influxdb = influxdb.clone();
tasks.spawn(async move {
let mut a: Box<dyn chronicle::db::collections::analytics::Analytic> = analytic;
if let Some(measurement) = a.get_measurement(&mongodb, milestone_index, milestone_timestamp).await {
influxdb.insert_measurement(measurement?).await?;
if let Some(measurement) = a
.get_measurement(&mongodb, milestone_index, milestone_timestamp)
.await?
{
influxdb.insert_measurement(measurement).await?;
}
Ok::<_, InxWorkerError>(a)
});
Expand Down
126 changes: 0 additions & 126 deletions src/db/collections/analytics/address_activity.rs

This file was deleted.

Loading

0 comments on commit 04015f3

Please sign in to comment.