From c81623a61add18cb652f12e6d80c23bde3e70ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan-=C8=98tefan=20Neac=C5=9Fu?= Date: Mon, 25 Jul 2022 16:59:45 +0300 Subject: [PATCH] Add gateway id in the gateway stats (#1478) * Add gateway id in the gateway stats * Update CHANGELOG --- CHANGELOG.md | 2 ++ common/statistics/src/lib.rs | 8 ++++++-- gateway/src/node/mod.rs | 1 + gateway/src/node/statistics/collector.rs | 13 +++++++++++-- .../migrations/20220512120000_mixnet_statistics.sql | 1 + .../network-statistics/src/api/routes.rs | 2 ++ .../network-statistics/src/storage/manager.rs | 4 +++- .../network-statistics/src/storage/mod.rs | 6 +++++- .../network-statistics/src/storage/models.rs | 1 + 9 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 570e00c8da..61f0798fcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// - validator-api: fee payment for multisig operations comes from the gateway account instead of the validator APIs' accounts ([#1419]) - multisig-contract: Limit the proposal creating functionality to one address (coconut-bandwidth-contract address) ([#1457]) - All binaries and cosmwasm blobs are configured at runtime now; binaries are configured using environment variables or .env files and contracts keep the configuration parameters in storage ([#1463]) +- gateway, network-statistics: include gateway id in the sent statistical data ([#1478]) [#1249]: https://github.com/nymtech/nym/pull/1249 @@ -71,6 +72,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// [#1419]: https://github.com/nymtech/nym/pull/1419 [#1457]: https://github.com/nymtech/nym/pull/1457 [#1463]: https://github.com/nymtech/nym/pull/1463 +[#1478]: https://github.com/nymtech/nym/pull/1478 ## [nym-connect-v1.0.1](https://github.com/nymtech/nym/tree/nym-connect-v1.0.1) (2022-07-22) diff --git a/common/statistics/src/lib.rs b/common/statistics/src/lib.rs index 9e107fc119..5423106648 100644 --- a/common/statistics/src/lib.rs +++ b/common/statistics/src/lib.rs @@ -34,12 +34,16 @@ pub enum StatsData { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct StatsGatewayData { + pub gateway_id: String, pub inbox_count: u32, } impl StatsGatewayData { - pub fn new(inbox_count: u32) -> Self { - StatsGatewayData { inbox_count } + pub fn new(gateway_id: String, inbox_count: u32) -> Self { + StatsGatewayData { + gateway_id, + inbox_count, + } } } diff --git a/gateway/src/node/mod.rs b/gateway/src/node/mod.rs index 9eb825792c..379aae5fe2 100644 --- a/gateway/src/node/mod.rs +++ b/gateway/src/node/mod.rs @@ -336,6 +336,7 @@ where if self.config.get_enabled_statistics() { let statistics_service_url = self.config.get_statistics_service_url(); let stats_collector = GatewayStatisticsCollector::new( + self.identity_keypair.public_key().to_base58_string(), active_clients_store.clone(), statistics_service_url, ); diff --git a/gateway/src/node/statistics/collector.rs b/gateway/src/node/statistics/collector.rs index 18f290d006..62014d0d16 100644 --- a/gateway/src/node/statistics/collector.rs +++ b/gateway/src/node/statistics/collector.rs @@ -14,13 +14,19 @@ use statistics_common::{ use crate::node::client_handling::active_clients::ActiveClientsStore; pub(crate) struct GatewayStatisticsCollector { + gateway_id: String, active_clients_store: ActiveClientsStore, statistics_service_url: Url, } impl GatewayStatisticsCollector { - pub fn new(active_clients_store: ActiveClientsStore, statistics_service_url: Url) -> Self { + pub fn new( + gateway_id: String, + active_clients_store: ActiveClientsStore, + statistics_service_url: Url, + ) -> Self { GatewayStatisticsCollector { + gateway_id, active_clients_store, statistics_service_url, } @@ -35,7 +41,10 @@ impl StatisticsCollector for GatewayStatisticsCollector { timestamp: DateTime, ) -> StatsMessage { let inbox_count = self.active_clients_store.size() as u32; - let stats_data = vec![StatsData::Gateway(StatsGatewayData { inbox_count })]; + let stats_data = vec![StatsData::Gateway(StatsGatewayData::new( + self.gateway_id.clone(), + inbox_count, + ))]; StatsMessage { stats_data, interval_seconds: interval.as_secs() as u32, diff --git a/service-providers/network-statistics/migrations/20220512120000_mixnet_statistics.sql b/service-providers/network-statistics/migrations/20220512120000_mixnet_statistics.sql index 5e6b2aa348..da13b953ca 100644 --- a/service-providers/network-statistics/migrations/20220512120000_mixnet_statistics.sql +++ b/service-providers/network-statistics/migrations/20220512120000_mixnet_statistics.sql @@ -16,6 +16,7 @@ CREATE TABLE service_statistics CREATE TABLE gateway_statistics ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + gateway_id VARCHAR NOT NULL, inbox_count INTEGER NOT NULL, timestamp DATETIME NOT NULL ); \ No newline at end of file diff --git a/service-providers/network-statistics/src/api/routes.rs b/service-providers/network-statistics/src/api/routes.rs index 7316d2c375..0a1c558128 100644 --- a/service-providers/network-statistics/src/api/routes.rs +++ b/service-providers/network-statistics/src/api/routes.rs @@ -35,6 +35,7 @@ pub struct ServiceStatistic { #[derive(Clone, Serialize, Deserialize, Debug)] pub struct GatewayStatistic { + pub gateway_id: String, pub inbox_count: u32, pub timestamp: String, } @@ -70,6 +71,7 @@ pub(crate) async fn post_all_statistics( .into_iter() .map(|data| { GenericStatistic::Gateway(GatewayStatistic { + gateway_id: data.gateway_id, inbox_count: data.inbox_count as u32, timestamp: data.timestamp.to_string(), }) diff --git a/service-providers/network-statistics/src/storage/manager.rs b/service-providers/network-statistics/src/storage/manager.rs index 07e0cc751b..f77a5aace4 100644 --- a/service-providers/network-statistics/src/storage/manager.rs +++ b/service-providers/network-statistics/src/storage/manager.rs @@ -52,11 +52,13 @@ impl StorageManager { /// * `timestamp`: The moment in time when the data started being collected. pub(super) async fn insert_gateway_statistics( &self, + gateway_id: String, inbox_count: u32, timestamp: DateTime, ) -> Result<(), sqlx::Error> { sqlx::query!( - "INSERT INTO gateway_statistics(inbox_count, timestamp) VALUES (?, ?)", + "INSERT INTO gateway_statistics(gateway_id, inbox_count, timestamp) VALUES (?, ?, ?)", + gateway_id, inbox_count, timestamp, ) diff --git a/service-providers/network-statistics/src/storage/mod.rs b/service-providers/network-statistics/src/storage/mod.rs index 6ae4e08646..ea468c8606 100644 --- a/service-providers/network-statistics/src/storage/mod.rs +++ b/service-providers/network-statistics/src/storage/mod.rs @@ -71,7 +71,11 @@ impl NetworkStatisticsStorage { } statistics_common::StatsData::Gateway(gateway_data) => { self.manager - .insert_gateway_statistics(gateway_data.inbox_count, timestamp) + .insert_gateway_statistics( + gateway_data.gateway_id, + gateway_data.inbox_count, + timestamp, + ) .await? } } diff --git a/service-providers/network-statistics/src/storage/models.rs b/service-providers/network-statistics/src/storage/models.rs index f04a333495..d179914540 100644 --- a/service-providers/network-statistics/src/storage/models.rs +++ b/service-providers/network-statistics/src/storage/models.rs @@ -17,6 +17,7 @@ pub(crate) struct ServiceStatistics { pub(crate) struct GatewayStatistics { #[allow(dead_code)] pub(crate) id: i64, + pub(crate) gateway_id: String, pub(crate) inbox_count: i64, pub(crate) timestamp: NaiveDateTime, }