This commit is contained in:
Bryan Stitt 2023-07-18 09:50:51 -07:00
parent 600c1bafb4
commit a97cb6a0c5
5 changed files with 23 additions and 23 deletions

View File

@ -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::<Vec<_>>();
let stats = stats.into_iter().flat_map(|x| x.1).collect::<Vec<_>>();
let mut response = HashMap::new();
response.insert("stats", stats);

View File

@ -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>(

View File

@ -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::{

View File

@ -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

View File

@ -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);