fleet

package
v2.8.44 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fleet implements pure, deterministic worker-node selection, per-site telemetry folding, monotonic job timestamps, and multi-shard rotation shared between the self-hosted Go Hub (internal/hub) and the Cloudflare Worker Durable Object coordinator (via cmd/edgefetch-wasm).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRoutablePublicIP

func IsRoutablePublicIP(rawIP string) bool

IsRoutablePublicIP reports whether rawIP is a valid non-loopback, non-private, non-link-local IP address suitable for WAN egress grouping.

func NextJobStamp

func NextJobStamp(now, last, floor int64) int64

NextJobStamp returns a strictly increasing job timestamp >= now, >= last+1, and >= floor.

func OrderCandidates

func OrderCandidates(cands []Candidate, busy map[string]bool) []string

OrderCandidates splits cands into idle vs busy (using case-insensitive site IDs), groups each partition by publicIp (falling back to siteId), orders groups by Least-Recently-Used (then earliest connectedAt, then group key), orders members within each group by LRU (then earliest connectedAt, then siteId), and interleaves members across distinct IP groups.

func ShardOrder

func ShardOrder(hint string, shards []string) []string

ShardOrder deterministically rotates shards using FNV-1a(lower(trim(hint))). When hint is empty or len(shards) <= 1, a copy of shards in original order is returned.

Types

type Candidate

type Candidate struct {
	SiteID      string `json:"siteId"`
	PublicIP    string `json:"publicIp,omitempty"`
	LastJobAt   int64  `json:"lastJobAt"`
	ConnectedAt int64  `json:"connectedAt"`
}

Candidate describes one connected remote worker node eligible for dispatch.

type PlanRequest

type PlanRequest struct {
	Candidates []Candidate        `json:"candidates,omitempty"`
	Busy       []string           `json:"busy,omitempty"`
	Stats      map[string][]Stats `json:"stats,omitempty"`
	StatsList  []Stats            `json:"statsList,omitempty"`
	Now        int64              `json:"now,omitempty"`
	LastStamp  int64              `json:"lastStamp,omitempty"`
	Floor      int64              `json:"floor,omitempty"`
	ShardHint  string             `json:"shardHint,omitempty"`
	ShardSeq   uint64             `json:"shardSeq,omitempty"`
	Shards     []string           `json:"shards,omitempty"`
}

PlanRequest bundles all inputs for the single `fleet_plan` WASM op.

type PlanResponse

type PlanResponse struct {
	Order       []string         `json:"order,omitempty"`
	MergedStats map[string]Stats `json:"mergedStats,omitempty"`
	FoldedStats *Stats           `json:"foldedStats,omitempty"`
	NextStamp   int64            `json:"nextStamp,omitempty"`
	ShardOrder  []string         `json:"shardOrder,omitempty"`
}

PlanResponse returns the full fleet decision in one call.

func Plan

func Plan(req PlanRequest) PlanResponse

Plan evaluates candidate dispatch order, per-site stats folding, monotonic stamp advancement, and shard rotation in one call.

type Stats

type Stats struct {
	SiteID    string `json:"siteId,omitempty"`
	LastJobAt int64  `json:"lastJobAt"`
	JobsOK    int64  `json:"jobsOk"`
	JobsErr   int64  `json:"jobsErr"`
}

Stats holds cumulative per-site job counters and the last-job timestamp (epoch ms).

func FoldStats

func FoldStats(list ...Stats) Stats

FoldStats folds zero or more Stats records using MergeStats.

func MergeStats

func MergeStats(a, b Stats) Stats

MergeStats returns the component-wise maximum of two Stats records (clamped >= 0).

Jump to

Keyboard shortcuts

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