tweaks, improvements, and minor fixes to limits infrastructure as a result of share limit testing (#276)

This commit is contained in:
Michael Quigley 2023-03-28 14:39:42 -04:00
parent d279fbb8cb
commit 9a6f6a8e2f
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 22 additions and 16 deletions

View File

@ -9,6 +9,7 @@ import (
type WarningEmail struct {
EmailAddress string
Detail string
Version string
}
func (we WarningEmail) MergeTemplate(filename string) (string, error) {

View File

@ -10,6 +10,7 @@ import (
"github.com/openziti/zrok/util"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"reflect"
"time"
)
@ -167,7 +168,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run account limit actions
for _, action := range a.acctLimitActions {
if err := action.HandleAccount(acct, rxBytes, txBytes, a.cfg.Bandwidth.PerAccount, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -204,7 +205,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run account warning actions
for _, action := range a.acctWarningActions {
if err := action.HandleAccount(acct, rxBytes, txBytes, a.cfg.Bandwidth.PerAccount, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -243,7 +244,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run environment limit actions
for _, action := range a.envLimitActions {
if err := action.HandleEnvironment(env, rxBytes, txBytes, a.cfg.Bandwidth.PerEnvironment, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -280,7 +281,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run environment warning actions
for _, action := range a.envWarningActions {
if err := action.HandleEnvironment(env, rxBytes, txBytes, a.cfg.Bandwidth.PerEnvironment, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -320,7 +321,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run share limit actions
for _, action := range a.shrLimitActions {
if err := action.HandleShare(shr, rxBytes, txBytes, a.cfg.Bandwidth.PerShare, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -358,7 +359,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
// run share warning actions
for _, action := range a.shrWarningActions {
if err := action.HandleShare(shr, rxBytes, txBytes, a.cfg.Bandwidth.PerShare, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := trx.Commit(); err != nil {
@ -403,7 +404,7 @@ func (a *Agent) relax() error {
// run relax actions for share
for _, action := range a.shrRelaxActions {
if err := action.HandleShare(shr, rxBytes, txBytes, a.cfg.Bandwidth.PerShare, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := a.str.DeleteShareLimitJournalForShare(shr.Id, trx); err == nil {
@ -435,7 +436,7 @@ func (a *Agent) relax() error {
// run relax actions for environment
for _, action := range a.envRelaxActions {
if err := action.HandleEnvironment(env, rxBytes, txBytes, a.cfg.Bandwidth.PerEnvironment, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := a.str.DeleteEnvironmentLimitJournalForEnvironment(env.Id, trx); err == nil {
@ -467,7 +468,7 @@ func (a *Agent) relax() error {
// run relax actions for account
for _, action := range a.acctRelaxActions {
if err := action.HandleAccount(acct, rxBytes, txBytes, a.cfg.Bandwidth.PerAccount, trx); err != nil {
return err
return errors.Wrapf(err, "%v", reflect.TypeOf(action).String())
}
}
if err := a.str.DeleteAccountLimitJournalForAccount(acct.Id, trx); err == nil {

View File

@ -1,6 +1,7 @@
package limits
import (
"github.com/openziti/zrok/build"
"github.com/openziti/zrok/controller/emailUi"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -11,13 +12,14 @@ func sendLimitWarningEmail(cfg *emailUi.Config, emailTo string, limit *Bandwidth
emailData := &emailUi.WarningEmail{
EmailAddress: emailTo,
Detail: describeLimit(limit, rxBytes, txBytes),
Version: build.String(),
}
plainBody, err := emailData.MergeTemplate("limitWarning.gotext")
if err != nil {
return err
}
htmlBody, err := emailData.MergeTemplate("resetPassword.gohtml")
htmlBody, err := emailData.MergeTemplate("limitWarning.gohtml")
if err != nil {
return err
}

View File

@ -27,7 +27,8 @@ func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int6
return err
}
acct, err := a.str.GetAccount(env.Id, trx)
if env.AccountId != nil {
acct, err := a.str.GetAccount(*env.AccountId, trx)
if err != nil {
return err
}
@ -35,6 +36,7 @@ func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int6
if err := sendLimitWarningEmail(a.cfg, acct.Email, limit, rxBytes, txBytes); err != nil {
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
}
}
return nil
}