mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 08:44:14 +01:00
logging tweaks and improvements releated to limits agent (#606)
This commit is contained in:
parent
5e6ec4cde1
commit
883fe92848
@ -2,7 +2,7 @@
|
||||
|
||||
## v0.4.31
|
||||
|
||||
FEATURE: New "limits classes" limits implementation (https://github.com/openziti/zrok/issues/606)
|
||||
FEATURE: New "limits classes" limits implementation (https://github.com/openziti/zrok/issues/606). This new feature allows for extensive limits customization on a per-user basis, with fallback to the global defaults in the controller configuration.
|
||||
|
||||
FIX: Correct the syntax for the Docker and Linux zrok-share "frontdoor" service that broke OAuth email address pattern matching
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/controller/zrokEdgeSdk"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
"github.com/openziti/zrok/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"reflect"
|
||||
@ -134,15 +135,15 @@ func (a *Agent) CanCreateShare(acctId, envId int, reserved, uniqueName bool, _ s
|
||||
}
|
||||
}
|
||||
if total+1 > rc.GetShares() {
|
||||
logrus.Debugf("account '%d', environment '%d' over shares limit '%d'", acctId, envId, a.cfg.Shares)
|
||||
logrus.Debugf("account '#%d', environment '%d' over shares limit '%d'", acctId, envId, a.cfg.Shares)
|
||||
return false, nil
|
||||
}
|
||||
if reserved && reserveds+1 > rc.GetReservedShares() {
|
||||
logrus.Debugf("account '%v', environment '%d' over reserved shares limit '%d'", acctId, envId, a.cfg.ReservedShares)
|
||||
logrus.Debugf("account '#%d', environment '%d' over reserved shares limit '%d'", acctId, envId, a.cfg.ReservedShares)
|
||||
return false, nil
|
||||
}
|
||||
if reserved && uniqueName && uniqueNames+1 > rc.GetUniqueNames() {
|
||||
logrus.Debugf("account '%v', environment '%d' over unique names limit '%d'", acctId, envId, a.cfg.UniqueNames)
|
||||
logrus.Debugf("account '#%d', environment '%d' over unique names limit '%d'", acctId, envId, a.cfg.UniqueNames)
|
||||
return false, nil
|
||||
}
|
||||
logrus.Infof("total = %d", total)
|
||||
@ -263,7 +264,7 @@ func (a *Agent) enforce(u *metrics.Usage) error {
|
||||
return err
|
||||
}
|
||||
|
||||
exceededBwc, rxBytes, txBytes, err := a.anyBandwidthLimitExceeded(u, ul.toBandwidthArray(sdk.BackendMode(shr.BackendMode)))
|
||||
exceededBwc, rxBytes, txBytes, err := a.anyBandwidthLimitExceeded(acct, u, ul.toBandwidthArray(sdk.BackendMode(shr.BackendMode)))
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error checking limit classes")
|
||||
}
|
||||
@ -408,7 +409,7 @@ func (a *Agent) relax() error {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logrus.Infof("account '%v' still over limit: '%v' with rx: %d, tx: %d, total: %d", accounts[bwje.AccountId].Email, bwc, used.rx, used.tx, used.rx+used.tx)
|
||||
logrus.Infof("'%v' still over limit: '%v' with rx: %v, tx: %v, total: %v", accounts[bwje.AccountId].Email, bwc, util.BytesToSize(used.rx), util.BytesToSize(used.tx), util.BytesToSize(used.rx+used.tx))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -432,7 +433,7 @@ func (a *Agent) isBandwidthClassLimitedForAccount(acctId int, bwc store.Bandwidt
|
||||
return nil, err
|
||||
}
|
||||
if je.Action == store.LimitLimitAction {
|
||||
logrus.Infof("account '#%d' over bandwidth for global bandwidth class '%v'", acctId, bwc)
|
||||
logrus.Debugf("account '#%d' over bandwidth for global bandwidth class '%v'", acctId, bwc)
|
||||
return je, nil
|
||||
}
|
||||
} else if err != nil {
|
||||
@ -445,7 +446,7 @@ func (a *Agent) isBandwidthClassLimitedForAccount(acctId int, bwc store.Bandwidt
|
||||
return nil, err
|
||||
}
|
||||
if je.Action == store.LimitLimitAction {
|
||||
logrus.Infof("account '#%d' over bandwidth for limit class '%v'", acctId, bwc)
|
||||
logrus.Debugf("account '#%d' over bandwidth for limit class '%v'", acctId, bwc)
|
||||
return je, nil
|
||||
}
|
||||
} else if err != nil {
|
||||
@ -455,7 +456,7 @@ func (a *Agent) isBandwidthClassLimitedForAccount(acctId int, bwc store.Bandwidt
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (a *Agent) anyBandwidthLimitExceeded(u *metrics.Usage, bwcs []store.BandwidthClass) (store.BandwidthClass, int64, int64, error) {
|
||||
func (a *Agent) anyBandwidthLimitExceeded(acct *store.Account, u *metrics.Usage, bwcs []store.BandwidthClass) (store.BandwidthClass, int64, int64, error) {
|
||||
periodBw := make(map[int]struct {
|
||||
rx int64
|
||||
tx int64
|
||||
@ -469,7 +470,7 @@ func (a *Agent) anyBandwidthLimitExceeded(u *metrics.Usage, bwcs []store.Bandwid
|
||||
if _, found := periodBw[bwc.GetPeriodMinutes()]; !found {
|
||||
rx, tx, err := a.ifx.totalRxTxForAccount(u.AccountId, time.Minute*time.Duration(bwc.GetPeriodMinutes()))
|
||||
if err != nil {
|
||||
return nil, 0, 0, errors.Wrapf(err, "error getting rx/tx for account '%d'", u.AccountId)
|
||||
return nil, 0, 0, errors.Wrapf(err, "error getting rx/tx for account '%v'", acct.Email)
|
||||
}
|
||||
periodBw[bwc.GetPeriodMinutes()] = struct {
|
||||
rx int64
|
||||
@ -486,12 +487,12 @@ func (a *Agent) anyBandwidthLimitExceeded(u *metrics.Usage, bwcs []store.Bandwid
|
||||
rxBytes = period.rx
|
||||
txBytes = period.tx
|
||||
} else {
|
||||
logrus.Debugf("limit ok '%v' with rx: %d, tx: %d, total: %d", bwc, period.rx, period.tx, period.rx+period.tx)
|
||||
logrus.Debugf("'%v' limit ok '%v' with rx: %v, tx: %v, total: %v", acct.Email, bwc, util.BytesToSize(period.rx), util.BytesToSize(period.tx), util.BytesToSize(period.rx+period.tx))
|
||||
}
|
||||
}
|
||||
|
||||
if selectedLc != nil {
|
||||
logrus.Infof("exceeded limit '%v' with rx: %d, tx: %d, total: %d", selectedLc, rxBytes, txBytes, rxBytes+txBytes)
|
||||
logrus.Infof("'%v' exceeded limit '%v' with rx: %v, tx: %v, total: %v", acct.Email, selectedLc, util.BytesToSize(rxBytes), util.BytesToSize(txBytes), util.BytesToSize(rxBytes+txBytes))
|
||||
}
|
||||
|
||||
return selectedLc, rxBytes, txBytes, nil
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
"github.com/openziti/zrok/util"
|
||||
)
|
||||
|
||||
type configBandwidthClass struct {
|
||||
@ -70,13 +71,13 @@ func (bc *configBandwidthClass) GetLimitAction() store.LimitAction {
|
||||
func (bc *configBandwidthClass) String() string {
|
||||
out := fmt.Sprintf("ConfigClass<periodMinutes: %d", bc.periodInMinutes)
|
||||
if bc.bw.Rx > store.Unlimited {
|
||||
out += fmt.Sprintf(", rxBytes: %d", bc.bw.Rx)
|
||||
out += fmt.Sprintf(", rxBytes: %v", util.BytesToSize(bc.bw.Rx))
|
||||
}
|
||||
if bc.bw.Tx > store.Unlimited {
|
||||
out += fmt.Sprintf(", txBytes: %d", bc.bw.Tx)
|
||||
out += fmt.Sprintf(", txBytes: %v", util.BytesToSize(bc.bw.Tx))
|
||||
}
|
||||
if bc.bw.Total > store.Unlimited {
|
||||
out += fmt.Sprintf(", totalBytes: %d", bc.bw.Total)
|
||||
out += fmt.Sprintf(", totalBytes: %v", util.BytesToSize(bc.bw.Total))
|
||||
}
|
||||
out += fmt.Sprintf(", limitAction: %s>", bc.limitAction)
|
||||
return out
|
||||
|
@ -19,8 +19,6 @@ func newLimitAction(str *store.Store, zCfg *zrokEdgeSdk.Config) *limitAction {
|
||||
}
|
||||
|
||||
func (a *limitAction) HandleAccount(acct *store.Account, _, _ int64, bwc store.BandwidthClass, ul *userLimits, trx *sqlx.Tx) error {
|
||||
logrus.Infof("limiting '%v'", acct.Email)
|
||||
|
||||
envs, err := a.str.FindEnvironmentsForAccount(acct.Id, trx)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error finding environments for account '%v'", acct.Email)
|
||||
@ -32,7 +30,6 @@ func (a *limitAction) HandleAccount(acct *store.Account, _, _ int64, bwc store.B
|
||||
}
|
||||
|
||||
ignoreBackends := ul.ignoreBackends(bwc)
|
||||
logrus.Warnf("ignore backends excluding '%v': %v", bwc, ignoreBackends)
|
||||
for _, env := range envs {
|
||||
shrs, err := a.str.FindSharesForEnvironment(env.Id, trx)
|
||||
if err != nil {
|
||||
|
@ -20,7 +20,7 @@ func newRelaxAction(str *store.Store, zCfg *zrokEdgeSdk.Config) *relaxAction {
|
||||
}
|
||||
|
||||
func (a *relaxAction) HandleAccount(acct *store.Account, _, _ int64, bwc store.BandwidthClass, _ *userLimits, trx *sqlx.Tx) error {
|
||||
logrus.Infof("relaxing '%v'", acct.Email)
|
||||
logrus.Debugf("relaxing '%v'", acct.Email)
|
||||
|
||||
envs, err := a.str.FindEnvironmentsForAccount(acct.Id, trx)
|
||||
if err != nil {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
"github.com/openziti/zrok/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -104,7 +105,7 @@ func (lc LimitClass) GetLimitAction() LimitAction {
|
||||
}
|
||||
|
||||
func (lc LimitClass) String() string {
|
||||
out := fmt.Sprintf("LimitClass<id: %d", lc.Id)
|
||||
out := fmt.Sprintf("LimitClass<#%d", lc.Id)
|
||||
if lc.BackendMode != nil {
|
||||
out += fmt.Sprintf(", backendMode: '%s'", *lc.BackendMode)
|
||||
}
|
||||
@ -124,13 +125,13 @@ func (lc LimitClass) String() string {
|
||||
out += fmt.Sprintf(", periodMinutes: %d", lc.PeriodMinutes)
|
||||
}
|
||||
if lc.RxBytes > Unlimited {
|
||||
out += fmt.Sprintf(", rxBytes: %d", lc.RxBytes)
|
||||
out += fmt.Sprintf(", rxBytes: %v", util.BytesToSize(lc.RxBytes))
|
||||
}
|
||||
if lc.TxBytes > Unlimited {
|
||||
out += fmt.Sprintf(", txBytes: %d", lc.TxBytes)
|
||||
out += fmt.Sprintf(", txBytes: %v", util.BytesToSize(lc.TxBytes))
|
||||
}
|
||||
if lc.TotalBytes > Unlimited {
|
||||
out += fmt.Sprintf(", totalBytes: %d", lc.TotalBytes)
|
||||
out += fmt.Sprintf(", totalBytes: %v", util.BytesToSize(lc.TotalBytes))
|
||||
}
|
||||
out += fmt.Sprintf(", limitAction: '%v'>", lc.LimitAction)
|
||||
return out
|
||||
|
@ -1,7 +1,6 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -10,7 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func Middleware(handler http.Handler, healthCheck func(w http.ResponseWriter, r *http.Request)) http.Handler {
|
||||
logrus.Infof("building")
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if strings.HasPrefix(r.URL.Path, "/api/v1") {
|
||||
handler.ServeHTTP(w, r)
|
||||
|
Loading…
Reference in New Issue
Block a user