will continue after bryan response

This commit is contained in:
yenicelik 2023-03-21 12:49:36 +01:00
parent 64505102ef
commit 1d72a3cd44

View File

@ -1,4 +1,5 @@
use std::net::IpAddr;
use std::net::{IpAddr, Ipv4Addr};
use std::num::NonZeroU64;
use anyhow::Context;
use argh::FromArgs;
use entities::{rpc_key, rpc_accounting, rpc_accounting_v2, user};
@ -10,7 +11,7 @@ use migration::sea_orm::{
QueryFilter, QuerySelect
};
use web3_proxy::app::AuthorizationChecks;
use web3_proxy::frontend::authorization::{Authorization, AuthorizationType, RequestMetadata};
use web3_proxy::frontend::authorization::{Authorization, AuthorizationType, RequestMetadata, RpcSecretKey};
use web3_proxy::stats::{BufferedRpcQueryStats, RpcQueryKey};
/// change a user's address.
@ -50,25 +51,36 @@ impl MigrateStatsToV2 {
// Get the rpc-key from the rpc_key_id
// Get the user-id from the rpc_key_id
let rpc_key_obj = rpc_key::Entity::find()
.filter(rpc_key::Column::id.eq(x.rpc_key_id))
.one(db_conn)
.await?;
let authorization_checks = match x.rpc_key_id {
Some(rpc_key_id) => {
let rpc_key_obj = rpc_key::Entity::find()
.filter(rpc_key::Column::Id.eq(rpc_key_id))
.one(db_conn)
.await?
.unwrap();
// TODO: Create authrization
// We can probably also randomly generate this, as we don't care about the user (?)
let authorization_checks = AuthorizationChecks {
user_id: rpc_key_id.user_id,
rpc_secret_key: rpc_key_id.secret_key,
rpc_secret_key_id: x.rpc_key_id,
..Default::default()
// TODO: Create authrization
// We can probably also randomly generate this, as we don't care about the user (?)
AuthorizationChecks {
user_id: rpc_key_obj.user_id,
rpc_secret_key: Some(RpcSecretKey::Uuid(rpc_key_obj.secret_key)),
rpc_secret_key_id: Some(NonZeroU64::new(rpc_key_id).unwrap()),
..Default::default()
}
},
None => {
AuthorizationChecks {
..Default::default()
}
}
};
// Then overwrite rpc_key_id and user_id (?)
let authorization_type = AuthorizationType::Frontend;
let authorization = Authorization::try_new(
authorization_checks,
None,
IpAddr::default(),
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
None,
None,
None,
@ -79,65 +91,25 @@ impl MigrateStatsToV2 {
// Iterate through all frontend requests
// For each frontend request, create one object that will be emitted (make sure the timestamp is new)
// TODO: Create RequestMetadata
let request_metadata = RequestMetadata {
start_instant: x.period_datetime.timestamp(),
request_bytes: x.request_bytes,
archive_request: x.archive_request,
backend_requests: todo!(),
no_servers: 0, // This is not relevant in the new version
error_response: x.error_response,
response_bytes: todo!(),
response_millis: todo!(),
response_from_backup_rpc: todo!() // I think we did not record this back then // Default::default()
};
for _ in 1..x.frontend_requests {
info!("Creating a new frontend request");
// TODO: Create RequestMetadata
let request_metadata = RequestMetadata {
start_instant: x.period_datetime.timestamp(),
request_bytes: x.request_bytes,
archive_request: x.archive_request,
backend_requests: todo!(),
no_servers: 0, // This is not relevant in the new version
error_response: x.error_response,
response_bytes: todo!(),
response_millis: todo!(),
response_from_backup_rpc: todo!() // I think we did not record this back then // Default::default()
};
}
// I suppose method cannot be empty ... (?)
// Ok, now we basically create a state event ..
RpcQueryStats::new(
x.method.unwrap(),
authorization
request_metadata,
x.response_bytes
)
// // For each of the old rows, create a (i) RpcQueryKey and a matching BufferedRpcQueryStats object
// let key = RpcQueryKey {
// response_timestamp: x.period_datetime.timestamp(),
// archive_needed: x.archive_needed,
// error_response: x.error_response,
// period_datetime: x.period_datetime.timestamp(),
// rpc_secret_key_id: x.rpc_key_id,
// origin: x.origin,
// method: x.method
// };
//
// // Create the corresponding BufferedRpcQueryStats object
// let val = BufferedRpcQueryStats {
// frontend_requests: x.frontend_requests,
// backend_requests: x.backend_requests,
// backend_retries: x.backend_retries,
// no_servers: x.no_servers,
// cache_misses: x.cache_misses,
// cache_hits: x.cache_hits,
// sum_request_bytes: x.sum_request_bytes,
// sum_response_bytes: x.sum_response_bytes,
// sum_response_millis: x.sum_response_millis
// };
//
// // TODO: Create authorization, request metadata, and bytes ... but bytes we don't really keep track of!
// // We can generate dummy bytes of the same length though, this may work as well
//
// // TODO: Period datetime is also a question of what it is
// // let response_stat = RpcQueryStats::new(
// // x.method,
// // authorization.clone(),
// // request_metadata.clone(),
// // response_bytes,
// // x.period_datetime
// // );
//
// // BufferedRpcQueryStats
}
// (N-1) Mark the batch as migrated