web3-proxy/migration/src/m20221007_213828_accounting.rs

241 lines
8.4 KiB
Rust
Raw Normal View History

2022-10-10 07:15:07 +03:00
use sea_orm_migration::prelude::*;
2022-10-25 07:31:27 +03:00
use sea_orm_migration::sea_query::table::ColumnDef;
2022-10-10 07:15:07 +03:00
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
// create a table for rpc request accounting
manager
.create_table(
Table::create()
.table(RpcAccounting::Table)
.col(
ColumnDef::new(RpcAccounting::Id)
.big_unsigned()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(RpcAccounting::UserKeyId)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::ChainId)
.big_unsigned()
.not_null(),
)
2022-10-11 08:13:00 +03:00
.col(ColumnDef::new(RpcAccounting::Method).string().not_null())
.col(
ColumnDef::new(RpcAccounting::ErrorResponse)
.boolean()
.not_null(),
)
2022-10-10 07:15:07 +03:00
.col(
2022-10-11 08:13:00 +03:00
ColumnDef::new(RpcAccounting::PeriodDatetime)
2022-10-10 07:15:07 +03:00
.timestamp()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::FrontendRequests)
2022-10-11 08:13:00 +03:00
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::BackendRequests)
2022-10-11 08:13:00 +03:00
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
.col(
2022-10-11 08:13:00 +03:00
ColumnDef::new(RpcAccounting::BackendRetries)
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
2022-10-12 00:31:34 +03:00
.col(
ColumnDef::new(RpcAccounting::NoServers)
.big_unsigned()
.not_null(),
)
2022-10-10 07:15:07 +03:00
.col(
2022-10-11 08:13:00 +03:00
ColumnDef::new(RpcAccounting::CacheMisses)
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
.col(
2022-10-11 08:13:00 +03:00
ColumnDef::new(RpcAccounting::CacheHits)
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
.col(
2022-10-11 08:13:00 +03:00
ColumnDef::new(RpcAccounting::SumRequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MinRequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MeanRequestBytes)
2022-10-11 20:34:25 +03:00
.double()
2022-10-11 08:13:00 +03:00
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P50RequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P90RequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P99RequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MaxRequestBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::SumResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MinResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MeanResponseMillis)
2022-10-11 20:34:25 +03:00
.double()
2022-10-11 08:13:00 +03:00
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P50ResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P90ResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P99ResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MaxResponseMillis)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::SumResponseBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MinResponseBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MeanResponseBytes)
2022-10-11 20:34:25 +03:00
.double()
2022-10-11 08:13:00 +03:00
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P50ResponseBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P90ResponseBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::P99ResponseBytes)
.big_unsigned()
.not_null(),
)
.col(
ColumnDef::new(RpcAccounting::MaxResponseBytes)
.big_unsigned()
2022-10-10 07:15:07 +03:00
.not_null(),
)
.foreign_key(
sea_query::ForeignKey::create()
.from(RpcAccounting::Table, RpcAccounting::UserKeyId)
.to(UserKeys::Table, UserKeys::Id),
)
2022-10-11 08:13:00 +03:00
.index(sea_query::Index::create().col(RpcAccounting::PeriodDatetime))
.index(sea_query::Index::create().col(RpcAccounting::Method))
2022-10-10 07:15:07 +03:00
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(RpcAccounting::Table).to_owned())
.await
}
}
/// Partial table definition
#[derive(Iden)]
pub enum UserKeys {
Table,
Id,
}
#[derive(Iden)]
enum RpcAccounting {
Table,
Id,
UserKeyId,
ChainId,
Method,
2022-10-11 08:13:00 +03:00
ErrorResponse,
PeriodDatetime,
2022-10-10 07:15:07 +03:00
FrontendRequests,
BackendRequests,
2022-10-11 08:13:00 +03:00
BackendRetries,
2022-10-12 00:31:34 +03:00
NoServers,
2022-10-11 08:13:00 +03:00
CacheMisses,
CacheHits,
SumRequestBytes,
MinRequestBytes,
MeanRequestBytes,
P50RequestBytes,
P90RequestBytes,
P99RequestBytes,
MaxRequestBytes,
SumResponseMillis,
MinResponseMillis,
MeanResponseMillis,
P50ResponseMillis,
P90ResponseMillis,
P99ResponseMillis,
MaxResponseMillis,
SumResponseBytes,
MinResponseBytes,
MeanResponseBytes,
P50ResponseBytes,
P90ResponseBytes,
P99ResponseBytes,
MaxResponseBytes,
2022-10-10 07:15:07 +03:00
}