From a97cb6a0c5e208ccfa8767ad58801598bbf5e397 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 18 Jul 2023 09:50:51 -0700 Subject: [PATCH] lint --- web3_proxy/src/frontend/users/stats.rs | 2 +- web3_proxy/src/stats/influxdb_queries.rs | 2 +- web3_proxy/src/stats/mod.rs | 3 --- web3_proxy/tests/common/influx.rs | 28 ++++++++++++------------ web3_proxy/tests/test_multiple_proxy.rs | 11 ++++++---- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/web3_proxy/src/frontend/users/stats.rs b/web3_proxy/src/frontend/users/stats.rs index ee5fd158..e7a41640 100644 --- a/web3_proxy/src/frontend/users/stats.rs +++ b/web3_proxy/src/frontend/users/stats.rs @@ -150,7 +150,7 @@ pub async fn user_mysql_stats_get( .all(db_replica.as_ref()) .await?; - let stats = stats.into_iter().map(|x| x.1).flatten().collect::>(); + let stats = stats.into_iter().flat_map(|x| x.1).collect::>(); let mut response = HashMap::new(); response.insert("stats", stats); diff --git a/web3_proxy/src/stats/influxdb_queries.rs b/web3_proxy/src/stats/influxdb_queries.rs index 7ad0b9cf..b757363e 100644 --- a/web3_proxy/src/stats/influxdb_queries.rs +++ b/web3_proxy/src/stats/influxdb_queries.rs @@ -23,7 +23,7 @@ use influxdb2::api::query::FluxRecord; use influxdb2::models::Query; use migration::sea_orm::{ColumnTrait, EntityTrait, QueryFilter}; use serde_json::json; -use tracing::{error, info, trace, warn}; +use tracing::{error, trace, warn}; use ulid::Ulid; pub async fn query_user_influx_stats<'a>( diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index 8cfa432c..a410d943 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -16,9 +16,6 @@ use axum::headers::Origin; use chrono::{DateTime, Months, TimeZone, Utc}; use derive_more::From; use entities::{referee, referrer, rpc_accounting_v2}; -use ethers::prelude::rand; -use ethers::prelude::rand::distributions::Alphanumeric; -use ethers::prelude::rand::Rng; use influxdb2::models::DataPoint; use migration::sea_orm::prelude::Decimal; use migration::sea_orm::{ diff --git a/web3_proxy/tests/common/influx.rs b/web3_proxy/tests/common/influx.rs index a75f7648..4c052ab9 100644 --- a/web3_proxy/tests/common/influx.rs +++ b/web3_proxy/tests/common/influx.rs @@ -1,6 +1,5 @@ use ethers::prelude::rand::{self, distributions::Alphanumeric, Rng}; use influxdb2::Client; -use migration::sea_orm::DatabaseConnection; use std::process::Command as SyncCommand; use std::time::Duration; use tokio::{ @@ -8,8 +7,7 @@ use tokio::{ process::Command as AsyncCommand, time::{sleep, Instant}, }; -use tracing::{info, trace, warn}; -use web3_proxy::relational_db::{connect_db, get_migrated_db}; +use tracing::{info, trace}; /// on drop, the mysql docker container will be shut down #[derive(Debug)] @@ -31,9 +29,9 @@ impl TestInflux { .map(char::from) .collect(); - let db_container_name = format!("web3-proxy-test-influx-{}", random); + let container_name = format!("web3-proxy-test-influx-{}", random); - info!(%db_container_name); + info!(%container_name); // docker run -d -p 8086:8086 \ // --name influxdb2 \ @@ -56,7 +54,7 @@ impl TestInflux { .args([ "run", "--name", - &db_container_name, + &container_name, "--rm", "-d", "-e", @@ -87,7 +85,7 @@ impl TestInflux { sleep(Duration::from_secs(1)).await; let docker_inspect_output = AsyncCommand::new("docker") - .args(["inspect", &db_container_name]) + .args(["inspect", &container_name]) .output() .await .unwrap(); @@ -127,23 +125,23 @@ impl TestInflux { .get("HostIp") .and_then(|x| x.as_str()) .expect("unable to determine influx ip"); - info!("Influx IP is: {:?}", influx_ip); // let host = "http://localhost:8086"; - let host = format!("http://{}:{}", influx_ip, influx_port); + let influx_host = format!("http://{}:{}", influx_ip, influx_port); + info!(%influx_host); // Create the client ... - let influxdb_client = influxdb2::Client::new(host.clone(), org, admin_token); + let influxdb_client = influxdb2::Client::new(influx_host.clone(), org, admin_token); info!("Influx client is: {:?}", influxdb_client); - // create the db_data as soon as the url is known - // when this is dropped, the db will be stopped + // create the TestInflux as soon as the url is known + // when this is dropped, the docker container will be stopped let mut test_influx = Self { - host: host.to_string(), + host: influx_host, org: org.to_string(), token: admin_token.to_string(), bucket: init_bucket.to_string(), - container_name: db_container_name.clone(), + container_name: container_name.clone(), client: influxdb_client, }; @@ -167,6 +165,8 @@ impl TestInflux { sleep(Duration::from_secs(1)).await; + // TODO: try to use the influx client + info!(?test_influx, elapsed=%start.elapsed().as_secs_f32(), "influx post is open. Migrating now..."); test_influx diff --git a/web3_proxy/tests/test_multiple_proxy.rs b/web3_proxy/tests/test_multiple_proxy.rs index 7fa8f6ea..d8106ce9 100644 --- a/web3_proxy/tests/test_multiple_proxy.rs +++ b/web3_proxy/tests/test_multiple_proxy.rs @@ -3,15 +3,13 @@ mod common; use crate::common::create_provider_with_rpc_key::create_provider_for_user; use crate::common::influx::TestInflux; use crate::common::rpc_key::user_get_first_rpc_key; -use crate::common::stats_accounting::{ - user_get_influx_stats_aggregated, user_get_influx_stats_detailed, user_get_mysql_stats, -}; +use crate::common::stats_accounting::{user_get_influx_stats_aggregated, user_get_mysql_stats}; use crate::common::user_balance::user_get_balance; use crate::common::{ admin_increases_balance::admin_increase_balance, anvil::TestAnvil, create_admin::create_user_as_admin, create_user::create_user, mysql::TestMysql, TestApp, }; -use futures::future::{join_all, try_join_all}; +use futures::future::try_join_all; use rust_decimal::Decimal; use std::str::FromStr; use std::sync::Arc; @@ -150,6 +148,11 @@ async fn test_multiple_proxies_stats_add_up() { let influx_stats = influx_aggregate_stats["result"].get(0).unwrap(); let mysql_stats = mysql_stats["stats"].get(0).unwrap(); + assert_eq!( + user_0_balance_post.total_frontend_requests, + number_requests * 3 + ); + info!("Influx and mysql stats are"); info!(?influx_stats); info!(?mysql_stats);