Documentation
¶
Overview ¶
Package bandwidth is the per-node-group bandwidth/QoS policy engine: named policies with label selectors, priority-based matching (F10 overlap detection), token-bucket rate limiting, and atomic JSON persistence. It is extracted from package main per ADR-0002; the admin API handler and the globalBandwidth singleton stay in main (bandwidth.go shim).
Index ¶
- func HumanRate(bytesPerSec int64) string
- type Manager
- func (m *Manager) Add(p Policy) (Policy, error)
- func (m *Manager) AllowBytes(policyName string, n int64) bool
- func (m *Manager) Delete(name string) bool
- func (m *Manager) FindPolicy(labels map[string]string) *Policy
- func (m *Manager) List() []Policy
- func (m *Manager) ReplaceAll(policies []Policy)
- func (m *Manager) Save()
- type Policy
- type PolicyInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages bandwidth policies and their token buckets.
func NewManager ¶
NewManager loads or creates a bandwidth policy store at the given path.
func (*Manager) AllowBytes ¶
AllowBytes checks the token bucket for the named policy. Returns true if n bytes are available (and consumes them). Returns true for unknown policies or unlimited (0 rate) policies.
func (*Manager) FindPolicy ¶
FindPolicy returns the highest-priority policy whose LabelSelector is a subset of the given labels. Returns nil if no policy matches.
func (*Manager) ReplaceAll ¶
ReplaceAll atomically replaces all policies (used for config sync from CP).
type Policy ¶
type Policy struct {
Name string `json:"name"`
LabelSelector map[string]string `json:"label_selector"` // matches nodes by labels
MaxBytesPerSec int64 `json:"max_bytes_per_sec"` // 0 = unlimited
Priority int `json:"priority"` // higher = more important (for QoS ordering)
CreatedAt string `json:"created_at"`
}
Policy defines rate limits for a node group or label match. Policies are evaluated against a node's labels; the highest-priority match wins. A MaxBytesPerSec of 0 means unlimited.
type PolicyInfo ¶
type PolicyInfo struct {
Policy
HumanRate string `json:"human_rate"` // e.g. "10 MB/s", "1 GB/s", "unlimited"
}
PolicyInfo extends Policy with a human-readable rate.