Merge pull request #315 from openziti/v0.4_metrics_and_limits_tweaks

v0.4 Metrics and Limits Tweaks
This commit is contained in:
Michael Quigley 2023-05-01 14:31:47 -04:00 committed by GitHub
commit 0be4bbc513
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 74 deletions

View File

@ -23,6 +23,7 @@ func newAccountWarningAction(cfg *emailUi.Config, str *store.Store, edge *rest_m
func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", acct.Email)
if a.cfg != nil {
rxLimit := "(unlimited bytes)"
if limit.Limit.Rx != Unlimited {
rxLimit = util.BytesToSize(limit.Limit.Rx)
@ -44,6 +45,9 @@ func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txByt
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
}
} else {
logrus.Warnf("skipping warning email for account limit; no email configuration specified")
}
return nil
}

View File

@ -23,6 +23,7 @@ func newEnvironmentWarningAction(cfg *emailUi.Config, str *store.Store, edge *re
func (a *environmentWarningAction) HandleEnvironment(env *store.Environment, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", env.ZId)
if a.cfg != nil {
if env.AccountId != nil {
acct, err := a.str.GetAccount(*env.AccountId, trx)
if err != nil {
@ -51,6 +52,9 @@ func (a *environmentWarningAction) HandleEnvironment(env *store.Environment, rxB
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
}
}
} else {
logrus.Warnf("skipping warning email for environment limit; no email configuration specified")
}
return nil
}

View File

@ -23,6 +23,7 @@ func newShareWarningAction(cfg *emailUi.Config, str *store.Store, edge *rest_man
func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", shr.Token)
if a.cfg != nil {
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
if err != nil {
return err
@ -56,6 +57,9 @@ func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int6
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
}
}
} else {
logrus.Warnf("skipping warning email for share limit; no email configuration specified")
}
return nil
}

View File

@ -47,8 +47,6 @@ func Ingest(event ZitiEventJson) (*Usage, error) {
} else {
logrus.Error("unable to assert 'usage/ingress.tx'")
}
} else {
logrus.Warn("missing 'usage/ingress.tx'")
}
if v, found := usage["ingress.rx"]; found {
if vFloat64, ok := v.(float64); ok {
@ -56,8 +54,6 @@ func Ingest(event ZitiEventJson) (*Usage, error) {
} else {
logrus.Error("unable to assert 'usage/ingress.rx")
}
} else {
logrus.Warn("missing 'usage/ingress.rx")
}
if v, found := usage["egress.tx"]; found {
if vFloat64, ok := v.(float64); ok {
@ -65,8 +61,6 @@ func Ingest(event ZitiEventJson) (*Usage, error) {
} else {
logrus.Error("unable to assert 'usage/egress.tx'")
}
} else {
logrus.Warn("missing 'usage/egress.tx'")
}
if v, found := usage["egress.rx"]; found {
if vFloat64, ok := v.(float64); ok {
@ -74,8 +68,6 @@ func Ingest(event ZitiEventJson) (*Usage, error) {
} else {
logrus.Error("unable to assert 'usage/egress.rx'")
}
} else {
logrus.Warn("missing 'usage/egress.rx'")
}
} else {
logrus.Errorf("unable to assert 'usage' (%v) %v", reflect.TypeOf(v), event)