better support for scoped/unscoped bandwidth limit coexistence (#606)

This commit is contained in:
Michael Quigley
2024-06-06 13:49:36 -04:00
parent cb4afd4a0f
commit bee5356e3c
8 changed files with 84 additions and 45 deletions

View File

@ -1,7 +1,6 @@
package limits
import (
"encoding/json"
"fmt"
"github.com/openziti/zrok/controller/store"
"github.com/openziti/zrok/sdk/golang/sdk"
@ -32,6 +31,10 @@ func (bc *configBandwidthClass) IsGlobal() bool {
return true
}
func (bc *configBandwidthClass) IsScoped() bool {
return false
}
func (bc *configBandwidthClass) GetLimitClassId() int {
return -1
}
@ -65,8 +68,16 @@ func (bc *configBandwidthClass) GetLimitAction() store.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)
out := fmt.Sprintf("ConfigClass<periodMinutes: %d", bc.periodInMinutes)
if bc.bw.Rx > store.Unlimited {
out += fmt.Sprintf(", rxBytes: %d", bc.bw.Rx)
}
return "<<ERROR>>"
if bc.bw.Tx > store.Unlimited {
out += fmt.Sprintf(", txBytes: %d", bc.bw.Tx)
}
if bc.bw.Total > store.Unlimited {
out += fmt.Sprintf(", totalBytes: %d", bc.bw.Total)
}
out += fmt.Sprintf(", limitAction: %s>", bc.limitAction)
return out
}