From b69237e9cc1cc63d3be8aa0927cb9091b00ffc18 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Fri, 17 Mar 2023 12:57:26 -0400 Subject: [PATCH] include rx|tx byte counts in limits journals (#273) --- controller/store/accountLimitJournal.go | 6 ++++-- controller/store/environmentLimitJournal.go | 6 ++++-- controller/store/shareLimitJournal.go | 6 ++++-- .../store/sql/postgresql/009_v0_4_0_limits_journals.sql | 6 ++++++ controller/store/sql/sqlite3/009_v0_4_0_limits_journals.sql | 6 ++++++ 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/controller/store/accountLimitJournal.go b/controller/store/accountLimitJournal.go index 3760dc03..ca86a93f 100644 --- a/controller/store/accountLimitJournal.go +++ b/controller/store/accountLimitJournal.go @@ -8,16 +8,18 @@ import ( type AccountLimitJournal struct { Model AccountId int + RxBytes int64 + TxBytes int64 Action string } func (self *Store) CreateAccountLimitJournal(j *AccountLimitJournal, tx *sqlx.Tx) (int, error) { - stmt, err := tx.Prepare("insert into account_limit_journal (account_id, action) values ($1, $2) returning id") + stmt, err := tx.Prepare("insert into account_limit_journal (account_id, rx_bytes, tx_bytes, action) values ($1, $2, $3, $4) returning id") if err != nil { return 0, errors.Wrap(err, "error preparing account_limit_journal insert statement") } var id int - if err := stmt.QueryRow(j.AccountId, j.AccountId).Scan(&id); err != nil { + if err := stmt.QueryRow(j.AccountId, j.RxBytes, j.TxBytes, j.AccountId).Scan(&id); err != nil { return 0, errors.Wrap(err, "error executing account_limit_journal insert statement") } return id, nil diff --git a/controller/store/environmentLimitJournal.go b/controller/store/environmentLimitJournal.go index c721022c..077d03ac 100644 --- a/controller/store/environmentLimitJournal.go +++ b/controller/store/environmentLimitJournal.go @@ -8,16 +8,18 @@ import ( type EnvironmentLimitJournal struct { Model EnvironmentId int + RxBytes int64 + TxBytes int64 Action string } func (self *Store) CreateEnvironmentLimitJournal(j *EnvironmentLimitJournal, tx *sqlx.Tx) (int, error) { - stmt, err := tx.Prepare("insert into environment_limit_journal (environment_id, action) values ($1, $2) returning id") + stmt, err := tx.Prepare("insert into environment_limit_journal (environment_id, rx_bytes, tx_bytes, action) values ($1, $2, $3, $4) returning id") if err != nil { return 0, errors.Wrap(err, "error preparing environment_limit_journal insert statement") } var id int - if err := stmt.QueryRow(j.EnvironmentId, j.Action).Scan(&id); err != nil { + if err := stmt.QueryRow(j.EnvironmentId, j.RxBytes, j.TxBytes, j.Action).Scan(&id); err != nil { return 0, errors.Wrap(err, "error executing environment_limit_journal insert statement") } return id, nil diff --git a/controller/store/shareLimitJournal.go b/controller/store/shareLimitJournal.go index f8ac92ea..fe97733a 100644 --- a/controller/store/shareLimitJournal.go +++ b/controller/store/shareLimitJournal.go @@ -8,16 +8,18 @@ import ( type ShareLimitJournal struct { Model ShareId int + RxBytes int64 + TxBytes int64 Action string } func (self *Store) CreateShareLimitJournal(j *ShareLimitJournal, tx *sqlx.Tx) (int, error) { - stmt, err := tx.Prepare("insert into share_limit_journal (share_id, action) values ($1, $2) returning id") + stmt, err := tx.Prepare("insert into share_limit_journal (share_id, rx_bytes, tx_bytes, action) values ($1, $2, $3, $4) returning id") if err != nil { return 0, errors.Wrap(err, "error preparing share_limit_journal insert statement") } var id int - if err := stmt.QueryRow(j.ShareId, j.Action).Scan(&id); err != nil { + if err := stmt.QueryRow(j.ShareId, j.RxBytes, j.TxBytes, j.Action).Scan(&id); err != nil { return 0, errors.Wrap(err, "error executing share_limit_journal insert statement") } return id, nil diff --git a/controller/store/sql/postgresql/009_v0_4_0_limits_journals.sql b/controller/store/sql/postgresql/009_v0_4_0_limits_journals.sql index 0b1d75b5..9238c2cc 100644 --- a/controller/store/sql/postgresql/009_v0_4_0_limits_journals.sql +++ b/controller/store/sql/postgresql/009_v0_4_0_limits_journals.sql @@ -5,6 +5,8 @@ create type limit_action_type as enum ('clear', 'warning', 'limit'); create table account_limit_journal ( id serial primary key, account_id integer references accounts(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp) @@ -13,6 +15,8 @@ create table account_limit_journal ( create table environment_limit_journal ( id serial primary key, environment_id integer references environments(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp) @@ -21,6 +25,8 @@ create table environment_limit_journal ( create table share_limit_journal ( id serial primary key, share_id integer references shares(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp) diff --git a/controller/store/sql/sqlite3/009_v0_4_0_limits_journals.sql b/controller/store/sql/sqlite3/009_v0_4_0_limits_journals.sql index a76c45b5..e9b14ebd 100644 --- a/controller/store/sql/sqlite3/009_v0_4_0_limits_journals.sql +++ b/controller/store/sql/sqlite3/009_v0_4_0_limits_journals.sql @@ -3,6 +3,8 @@ create table account_limit_journal ( id serial primary key, account_id integer references accounts(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp) @@ -11,6 +13,8 @@ create table account_limit_journal ( create table environment_limit_journal ( id serial primary key, environment_id integer references environments(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp) @@ -19,6 +23,8 @@ create table environment_limit_journal ( create table share_limit_journal ( id serial primary key, share_id integer references shares(id), + rx_bytes bigint not null, + tx_bytes bigint not null, action limit_action_type not null, created_at timestamptz not null default(current_timestamp), updated_at timestamptz not null default(current_timestamp)