will continue after bryan response
This commit is contained in:
parent
64505102ef
commit
1d72a3cd44
|
@ -1,4 +1,5 @@
|
||||||
use std::net::IpAddr;
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
use std::num::NonZeroU64;
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
use entities::{rpc_key, rpc_accounting, rpc_accounting_v2, user};
|
use entities::{rpc_key, rpc_accounting, rpc_accounting_v2, user};
|
||||||
|
@ -10,7 +11,7 @@ use migration::sea_orm::{
|
||||||
QueryFilter, QuerySelect
|
QueryFilter, QuerySelect
|
||||||
};
|
};
|
||||||
use web3_proxy::app::AuthorizationChecks;
|
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};
|
use web3_proxy::stats::{BufferedRpcQueryStats, RpcQueryKey};
|
||||||
|
|
||||||
/// change a user's address.
|
/// change a user's address.
|
||||||
|
@ -50,25 +51,36 @@ impl MigrateStatsToV2 {
|
||||||
|
|
||||||
// Get the rpc-key from the rpc_key_id
|
// Get the rpc-key from the rpc_key_id
|
||||||
// Get the user-id from the rpc_key_id
|
// Get the user-id from the rpc_key_id
|
||||||
let rpc_key_obj = rpc_key::Entity::find()
|
let authorization_checks = match x.rpc_key_id {
|
||||||
.filter(rpc_key::Column::id.eq(x.rpc_key_id))
|
Some(rpc_key_id) => {
|
||||||
.one(db_conn)
|
let rpc_key_obj = rpc_key::Entity::find()
|
||||||
.await?;
|
.filter(rpc_key::Column::Id.eq(rpc_key_id))
|
||||||
|
.one(db_conn)
|
||||||
|
.await?
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// TODO: Create authrization
|
// TODO: Create authrization
|
||||||
// We can probably also randomly generate this, as we don't care about the user (?)
|
// We can probably also randomly generate this, as we don't care about the user (?)
|
||||||
let authorization_checks = AuthorizationChecks {
|
AuthorizationChecks {
|
||||||
user_id: rpc_key_id.user_id,
|
user_id: rpc_key_obj.user_id,
|
||||||
rpc_secret_key: rpc_key_id.secret_key,
|
rpc_secret_key: Some(RpcSecretKey::Uuid(rpc_key_obj.secret_key)),
|
||||||
rpc_secret_key_id: x.rpc_key_id,
|
rpc_secret_key_id: Some(NonZeroU64::new(rpc_key_id).unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
AuthorizationChecks {
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Then overwrite rpc_key_id and user_id (?)
|
// Then overwrite rpc_key_id and user_id (?)
|
||||||
let authorization_type = AuthorizationType::Frontend;
|
let authorization_type = AuthorizationType::Frontend;
|
||||||
let authorization = Authorization::try_new(
|
let authorization = Authorization::try_new(
|
||||||
authorization_checks,
|
authorization_checks,
|
||||||
None,
|
None,
|
||||||
IpAddr::default(),
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -79,65 +91,25 @@ impl MigrateStatsToV2 {
|
||||||
// Iterate through all frontend requests
|
// Iterate through all frontend requests
|
||||||
// For each frontend request, create one object that will be emitted (make sure the timestamp is new)
|
// For each frontend request, create one object that will be emitted (make sure the timestamp is new)
|
||||||
|
|
||||||
// TODO: Create RequestMetadata
|
for _ in 1..x.frontend_requests {
|
||||||
let request_metadata = RequestMetadata {
|
info!("Creating a new frontend request");
|
||||||
start_instant: x.period_datetime.timestamp(),
|
|
||||||
request_bytes: x.request_bytes,
|
// TODO: Create RequestMetadata
|
||||||
archive_request: x.archive_request,
|
let request_metadata = RequestMetadata {
|
||||||
backend_requests: todo!(),
|
start_instant: x.period_datetime.timestamp(),
|
||||||
no_servers: 0, // This is not relevant in the new version
|
request_bytes: x.request_bytes,
|
||||||
error_response: x.error_response,
|
archive_request: x.archive_request,
|
||||||
response_bytes: todo!(),
|
backend_requests: todo!(),
|
||||||
response_millis: todo!(),
|
no_servers: 0, // This is not relevant in the new version
|
||||||
response_from_backup_rpc: todo!() // I think we did not record this back then // Default::default()
|
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
|
// (N-1) Mark the batch as migrated
|
||||||
|
|
Loading…
Reference in New Issue