bandwidth

package
v1.0.126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 8 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HumanRate

func HumanRate(bytesPerSec int64) string

HumanRate converts bytes/sec to a human-readable string.

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager manages bandwidth policies and their token buckets.

func NewManager

func NewManager(path string) *Manager

NewManager loads or creates a bandwidth policy store at the given path.

func (*Manager) Add

func (m *Manager) Add(p Policy) (Policy, error)

Add validates and appends a new policy, persists, and returns it.

func (*Manager) AllowBytes

func (m *Manager) AllowBytes(policyName string, n int64) bool

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) Delete

func (m *Manager) Delete(name string) bool

Delete removes a policy by name and persists. Returns true if found.

func (*Manager) FindPolicy

func (m *Manager) FindPolicy(labels map[string]string) *Policy

FindPolicy returns the highest-priority policy whose LabelSelector is a subset of the given labels. Returns nil if no policy matches.

func (*Manager) List

func (m *Manager) List() []Policy

List returns a copy of all policies.

func (*Manager) ReplaceAll

func (m *Manager) ReplaceAll(policies []Policy)

ReplaceAll atomically replaces all policies (used for config sync from CP).

func (*Manager) Save

func (m *Manager) Save()

Save persists the current policies to disk.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL