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,26 +23,30 @@ 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 { func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", acct.Email) logrus.Infof("warning '%v'", acct.Email)
rxLimit := "(unlimited bytes)" if a.cfg != nil {
if limit.Limit.Rx != Unlimited { rxLimit := "(unlimited bytes)"
rxLimit = util.BytesToSize(limit.Limit.Rx) if limit.Limit.Rx != Unlimited {
} rxLimit = util.BytesToSize(limit.Limit.Rx)
txLimit := "(unlimited bytes)" }
if limit.Limit.Tx != Unlimited { txLimit := "(unlimited bytes)"
txLimit = util.BytesToSize(limit.Limit.Tx) if limit.Limit.Tx != Unlimited {
} txLimit = util.BytesToSize(limit.Limit.Tx)
totalLimit := "(unlimited bytes)" }
if limit.Limit.Total != Unlimited { totalLimit := "(unlimited bytes)"
totalLimit = util.BytesToSize(limit.Limit.Total) if limit.Limit.Total != Unlimited {
} totalLimit = util.BytesToSize(limit.Limit.Total)
}
detail := newDetailMessage() detail := newDetailMessage()
detail = detail.append("Your account has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) detail = detail.append("Your account has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
detail = detail.append("This zrok instance only allows an account to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) detail = detail.append("This zrok instance only allows an account to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit)", limit.Period) detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit)", limit.Period)
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil { if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email) 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 return nil

View File

@ -23,33 +23,37 @@ 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 { func (a *environmentWarningAction) HandleEnvironment(env *store.Environment, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", env.ZId) logrus.Infof("warning '%v'", env.ZId)
if env.AccountId != nil { if a.cfg != nil {
acct, err := a.str.GetAccount(*env.AccountId, trx) if env.AccountId != nil {
if err != nil { acct, err := a.str.GetAccount(*env.AccountId, trx)
return err if err != nil {
} return err
}
rxLimit := "unlimited bytes" rxLimit := "unlimited bytes"
if limit.Limit.Rx != Unlimited { if limit.Limit.Rx != Unlimited {
rxLimit = util.BytesToSize(limit.Limit.Rx) rxLimit = util.BytesToSize(limit.Limit.Rx)
} }
txLimit := "unlimited bytes" txLimit := "unlimited bytes"
if limit.Limit.Tx != Unlimited { if limit.Limit.Tx != Unlimited {
txLimit = util.BytesToSize(limit.Limit.Tx) txLimit = util.BytesToSize(limit.Limit.Tx)
} }
totalLimit := "unlimited bytes" totalLimit := "unlimited bytes"
if limit.Limit.Total != Unlimited { if limit.Limit.Total != Unlimited {
totalLimit = util.BytesToSize(limit.Limit.Total) totalLimit = util.BytesToSize(limit.Limit.Total)
} }
detail := newDetailMessage() detail := newDetailMessage()
detail = detail.append("Your environment '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", env.Description, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) detail = detail.append("Your environment '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", env.Description, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period) detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil { if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil {
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email) 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 return nil

View File

@ -23,38 +23,42 @@ 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 { func (a *shareWarningAction) HandleShare(shr *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
logrus.Infof("warning '%v'", shr.Token) logrus.Infof("warning '%v'", shr.Token)
env, err := a.str.GetEnvironment(shr.EnvironmentId, trx) if a.cfg != nil {
if err != nil { env, err := a.str.GetEnvironment(shr.EnvironmentId, trx)
return err
}
if env.AccountId != nil {
acct, err := a.str.GetAccount(*env.AccountId, trx)
if err != nil { if err != nil {
return err return err
} }
rxLimit := "unlimited bytes" if env.AccountId != nil {
if limit.Limit.Rx != Unlimited { acct, err := a.str.GetAccount(*env.AccountId, trx)
rxLimit = util.BytesToSize(limit.Limit.Rx) if err != nil {
} return err
txLimit := "unlimited bytes" }
if limit.Limit.Tx != Unlimited {
txLimit = util.BytesToSize(limit.Limit.Tx)
}
totalLimit := "unlimited bytes"
if limit.Limit.Total != Unlimited {
totalLimit = util.BytesToSize(limit.Limit.Total)
}
detail := newDetailMessage() rxLimit := "unlimited bytes"
detail = detail.append("Your share '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", shr.Token, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes)) if limit.Limit.Rx != Unlimited {
detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period) rxLimit = util.BytesToSize(limit.Limit.Rx)
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period) }
txLimit := "unlimited bytes"
if limit.Limit.Tx != Unlimited {
txLimit = util.BytesToSize(limit.Limit.Tx)
}
totalLimit := "unlimited bytes"
if limit.Limit.Total != Unlimited {
totalLimit = util.BytesToSize(limit.Limit.Total)
}
if err := sendLimitWarningEmail(a.cfg, acct.Email, detail); err != nil { detail := newDetailMessage()
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email) detail = detail.append("Your share '%v' has received %v and sent %v (for a total of %v), which has triggered a transfer limit warning.", shr.Token, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
detail = detail.append("This zrok instance only allows a share to receive %v, send %v, totalling not more than %v for each %v.", rxLimit, txLimit, totalLimit, limit.Period)
detail = detail.append("If you exceed the transfer limit, access to your shares will be temporarily disabled (until the last %v falls below the transfer limit).", limit.Period)
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 share limit; no email configuration specified")
} }
return nil return nil

View File

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