mirror of
https://github.com/openziti/zrok.git
synced 2025-08-09 08:05:04 +02:00
basic global bandwidth enforcement testing tweaks (no clases) (#606)
This commit is contained in:
72
controller/limits/bandwidthClass.go
Normal file
72
controller/limits/bandwidthClass.go
Normal file
@ -0,0 +1,72 @@
|
||||
package limits
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/openziti/zrok/controller/store"
|
||||
"github.com/openziti/zrok/sdk/golang/sdk"
|
||||
)
|
||||
|
||||
type configBandwidthClass struct {
|
||||
periodInMinutes int
|
||||
bw *Bandwidth
|
||||
limitAction store.LimitAction
|
||||
}
|
||||
|
||||
func newConfigBandwidthClasses(cfg *BandwidthPerPeriod) []store.BandwidthClass {
|
||||
return []store.BandwidthClass{
|
||||
&configBandwidthClass{
|
||||
periodInMinutes: int(cfg.Period.Minutes()),
|
||||
bw: cfg.Warning,
|
||||
limitAction: store.WarningLimitAction,
|
||||
},
|
||||
&configBandwidthClass{
|
||||
periodInMinutes: int(cfg.Period.Minutes()),
|
||||
bw: cfg.Limit,
|
||||
limitAction: store.LimitLimitAction,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) IsGlobal() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetLimitClassId() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetShareMode() sdk.ShareMode {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetBackendMode() sdk.BackendMode {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetPeriodMinutes() int {
|
||||
return bc.periodInMinutes
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetRxBytes() int64 {
|
||||
return bc.bw.Rx
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetTxBytes() int64 {
|
||||
return bc.bw.Tx
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetTotalBytes() int64 {
|
||||
return bc.bw.Total
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) GetLimitAction() store.LimitAction {
|
||||
return bc.limitAction
|
||||
}
|
||||
|
||||
func (bc *configBandwidthClass) String() string {
|
||||
if out, err := json.Marshal(bc.bw); err == nil {
|
||||
return fmt.Sprintf("Config<period: %d, %s, action: %s>", bc.periodInMinutes, string(out), bc.limitAction)
|
||||
}
|
||||
return "<<ERROR>>"
|
||||
}
|
Reference in New Issue
Block a user