Skip to content

Commit

Permalink
balance is inside the influx query again
Browse files Browse the repository at this point in the history
  • Loading branch information
yenicelik committed Jun 8, 2023
1 parent 591d34e commit e35629d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion scripts/generate-requests-and-stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
# https://github.com/INFURA/versus
# ./ethspam | ./versus --stop-after 100 "http://localhost:8544/" # Pipe into the endpoint ..., add a bearer token and all that

./ethspam http://127.0.0.1:8544/rpc/01H0ZZJDNNEW49FRFS4D9SPR8B | ./versus --concurrency=4 --stop-after 100 http://localhost:8544/rpc/01H0ZZJDNNEW49FRFS4D9SPR8B
./ethspam http://127.0.0.1:8544/rpc/01H2D5DN4D423VR2KFWBZE46TR | ./versus --concurrency=4 --stop-after 10000 http://localhost:8544/rpc/01H2D5DN4D423VR2KFWBZE46TR

./ethspam http://127.0.0.1:8544/rpc/01H2D5CAP1KF2NKRS30SGATDSD | ./versus --concurrency=4 --stop-after 10000 http://localhost:8544/rpc/01H2D5CAP1KF2NKRS30SGATDSD
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,9 @@ curl \
curl \
-H "Authorization: Bearer 01H2D5CAQJF7P80222P4ZAFQ26" \
-X GET "127.0.0.1:8544/user/referral/stats/shared-codes"


# Finally also get some stats
curl -X GET \
-H "Authorization: Bearer 01H2D5DN564M4Q2T6PETEZY83Q" \
"http://localhost:8544/user/stats/detailed?query_start=1686236378&query_window_seconds=3600"
21 changes: 18 additions & 3 deletions web3_proxy/src/stats/influxdb_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ pub async fn query_user_stats<'a>(
|> filter(fn: (r) => r["_measurement"] == "{measurement}")
{filter_chain_id}
{drop_method}
base
cumsum = base
|> aggregateWindow(every: {query_window_seconds}s, fn: sum, createEmpty: false)
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> drop(columns: ["balance"])
Expand All @@ -186,7 +186,22 @@ pub async fn query_user_stats<'a>(
|> sort(columns: ["frontend_requests"], desc: true)
|> limit(n: 1)
|> group()
|> sort(columns: ["_time", "_measurement", "archive_needed", "chain_id", "error_response", "method", "rpc_secret_key_id"], desc: true)
balance = base
|> toFloat()
|> aggregateWindow(every: {query_window_seconds}s, fn: mean, createEmpty: false)
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> group(columns: ["_time", "_measurement", "chain_id", "method", "rpc_secret_key_id"])
|> mean(column: "balance")
|> group()
|> sort(columns: ["_time", "_measurement", "chain_id", "method", "rpc_secret_key_id"], desc: true)
join(
tables: {{cumsum, balance}},
on: ["_time", "_measurement", "chain_id", "method", "rpc_secret_key_id"]
)
|> sort(columns: ["_time", "_measurement", "chain_id", "method", "rpc_secret_key_id"], desc: true)
"#);

debug!("Raw query to db is: {:#?}", query);
Expand Down

0 comments on commit e35629d

Please sign in to comment.