diff --git a/controller/limits/agent.go b/controller/limits/agent.go index ec2186e5..0417ba47 100644 --- a/controller/limits/agent.go +++ b/controller/limits/agent.go @@ -32,15 +32,23 @@ type Agent struct { } func NewAgent(cfg *Config, ifxCfg *metrics.InfluxConfig, zCfg *zrokEdgeSdk.Config, str *store.Store) (*Agent, error) { - return &Agent{ - cfg: cfg, - ifx: newInfluxReader(ifxCfg), - zCfg: zCfg, - str: str, - queue: make(chan *metrics.Usage, 1024), - close: make(chan struct{}), - join: make(chan struct{}), - }, nil + edge, err := zrokEdgeSdk.Client(zCfg) + if err != nil { + return nil, err + } + a := &Agent{ + cfg: cfg, + ifx: newInfluxReader(ifxCfg), + zCfg: zCfg, + str: str, + queue: make(chan *metrics.Usage, 1024), + shrWarningEnforce: []ShareAction{newShareWarningAction(str, edge)}, + shrLimitEnforce: []ShareAction{newShareLimitAction(str, edge)}, + shrLimitRelax: []ShareAction{newShareRelaxAction(str, edge)}, + close: make(chan struct{}), + join: make(chan struct{}), + } + return a, nil } func (a *Agent) Start() { diff --git a/controller/limits/shareLimitAction.go b/controller/limits/shareLimitAction.go new file mode 100644 index 00000000..61655ef4 --- /dev/null +++ b/controller/limits/shareLimitAction.go @@ -0,0 +1,21 @@ +package limits + +import ( + "github.com/openziti/edge/rest_management_api_client" + "github.com/openziti/zrok/controller/store" + "github.com/sirupsen/logrus" +) + +type shareLimitAction struct { + str *store.Store + edge *rest_management_api_client.ZitiEdgeManagement +} + +func newShareLimitAction(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *shareLimitAction { + return &shareLimitAction{str, edge} +} + +func (a *shareLimitAction) HandleShare(s *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod) error { + logrus.Infof("limiting '%v'", s.Token) + return nil +} diff --git a/controller/limits/shareRelaxAction.go b/controller/limits/shareRelaxAction.go new file mode 100644 index 00000000..3c805dc7 --- /dev/null +++ b/controller/limits/shareRelaxAction.go @@ -0,0 +1,21 @@ +package limits + +import ( + "github.com/openziti/edge/rest_management_api_client" + "github.com/openziti/zrok/controller/store" + "github.com/sirupsen/logrus" +) + +type shareRelaxAction struct { + str *store.Store + edge *rest_management_api_client.ZitiEdgeManagement +} + +func newShareRelaxAction(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *shareRelaxAction { + return &shareRelaxAction{str, edge} +} + +func (a *shareRelaxAction) HandleShare(s *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod) error { + logrus.Infof("relaxing '%v'", s.Token) + return nil +} diff --git a/controller/limits/shareWarningAction.go b/controller/limits/shareWarningAction.go new file mode 100644 index 00000000..05085c74 --- /dev/null +++ b/controller/limits/shareWarningAction.go @@ -0,0 +1,21 @@ +package limits + +import ( + "github.com/openziti/edge/rest_management_api_client" + "github.com/openziti/zrok/controller/store" + "github.com/sirupsen/logrus" +) + +type shareWarningAction struct { + str *store.Store + edge *rest_management_api_client.ZitiEdgeManagement +} + +func newShareWarningAction(str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *shareWarningAction { + return &shareWarningAction{str, edge} +} + +func (a *shareWarningAction) HandleShare(s *store.Share, rxBytes, txBytes int64, limit *BandwidthPerPeriod) error { + logrus.Infof("warning '%v'", s.Token) + return nil +}