Help us shape the future of Go! Take the 2026 Go Developer Survey

serverwiring

package
v0.0.0-...-429f5ee Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package serverwiring is the process wiring the server binaries share: the --keyviz* and --autoSplit* flag groups and what they build, the metrics and pprof listeners, and the SigV4 static-credentials loader. Root main and the cmd/server demo both register and call it, so the demo cannot drift from the server binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyLeadership

func ApplyLeadership(cfg *autosplit.SchedulerConfig, leader Leader)

ApplyLeadership gates the scheduler on leadership of the catalog key when leader can answer per key (falling back to IsLeader), and wires term-scoped catalog and group leadership when leader reports terms.

func BuildSampler

func BuildSampler(k *KeyVizFlags, a *AutoSplitFlags) *keyviz.MemSampler

BuildSampler builds the in-memory KeyViz sampler, or returns nil when neither --keyvizEnabled nor --autoSplit is set. The coordinators and the admin server treat a nil sampler as "KeyViz disabled", so this is the one decision point.

func LoadSigV4StaticCredentials

func LoadSigV4StaticCredentials(path string, label string) (map[string]string, error)

LoadSigV4StaticCredentials parses a credentials file into an access key → secret map for WithS3StaticCredentials or WithSQSStaticCredentials. An empty path returns a nil map so authorization stays disabled. An empty field or an access key listed twice is an error: a second entry would silently replace the first. label names the adapter in errors ("s3 credentials file ...").

func PrepareMetricsServer

func PrepareMetricsServer(ctx context.Context, lc *net.ListenConfig, addr, token string, handler http.Handler) (*http.Server, net.Listener, string, error)

PrepareMetricsServer validates the metrics address and token and binds the listener. An empty address or a nil handler disables metrics and returns zero values. It returns the server, its listener and the trimmed address.

func PreparePprofServer

func PreparePprofServer(ctx context.Context, lc *net.ListenConfig, addr, token string) (*http.Server, net.Listener, string, error)

PreparePprofServer is PrepareMetricsServer for the pprof endpoints. An empty address disables pprof.

func SeedRoutes

func SeedRoutes(s *keyviz.MemSampler, engine *distribution.Engine)

SeedRoutes copies the engine's current route catalogue into the sampler so the first matrix snapshots have non-empty metadata. The auto-split reconciler keeps membership current after catalog changes.

func StartFlusher

func StartFlusher(ctx context.Context, eg *errgroup.Group, s *keyviz.MemSampler)

StartFlusher runs the sampler's flusher and hot-key aggregator in eg. The flusher harvests the in-progress step with a final Flush once ctx ends, so a graceful shutdown keeps the most recent partial column. Nothing starts when the sampler is disabled.

func StartScheduler

func StartScheduler(
	ctx context.Context,
	eg *errgroup.Group,
	catalog *distribution.CatalogStore,
	distServer *adapter.DistributionServer,
	leader Leader,
	sampler *keyviz.MemSampler,
	cfg autosplit.SchedulerConfig,
)

StartScheduler runs the auto-split scheduler in eg when cfg is enabled. Without a sampler there is nothing to evaluate, so it logs and returns.

Types

type AutoSplitFlags

type AutoSplitFlags struct {
	Enabled             *bool
	EvalInterval        *time.Duration
	SplitCooldown       *time.Duration
	SplitTimeout        *time.Duration
	KillSwitchFile      *string
	DefaultBuckets      *int
	WriteWeight         *float64
	ReadWeight          *float64
	ThresholdOpsMin     *float64
	CandidateWindows    *int
	MaxRoutes           *int
	MaxSplitsPerCycle   *int
	TopKeyShare         *float64
	TopKeyAbsoluteFloor *float64
}

AutoSplitFlags is the --autoSplit* flag group that configures automatic same-group hotspot splits on the catalog leader.

func RegisterAutoSplitFlags

func RegisterAutoSplitFlags(fs *flag.FlagSet) *AutoSplitFlags

RegisterAutoSplitFlags registers the --autoSplit* flags on fs.

func (*AutoSplitFlags) SchedulerConfig

func (a *AutoSplitFlags) SchedulerConfig(leader Leader, k *KeyVizFlags) (autosplit.SchedulerConfig, error)

SchedulerConfig builds the scheduler configuration the flags describe, wires leader into it when leader is non-nil, and validates it against the KeyViz flags the sampler is built from.

type DistributionSplitter

type DistributionSplitter struct {
	Server *adapter.DistributionServer
}

DistributionSplitter executes auto-split decisions through the local distribution server's SplitRange.

func (DistributionSplitter) SplitRange

SplitRange implements autosplit.Splitter. Only same-group splits are supported.

type KeyVizFlags

type KeyVizFlags struct {
	Enabled                *bool
	Step                   *time.Duration
	MaxTrackedRoutes       *int
	MaxMemberRoutesPerSlot *int
	HistoryColumns         *int
	KeyBucketsPerRoute     *int
	LabelsEnabled          *bool

	// Hot-key drill-down (design 2026_05_28_implemented_keyviz_hot_key_topk).
	// When enabled the sampler retains actual hot key bytes and exposes
	// them through the admin /keyviz/hotkeys drill-down.
	HotKeysEnabled    *bool
	HotKeysPerRoute   *int
	HotKeysSampleRate *int
	HotKeysQueueSize  *int
	HotKeysMaxKeyLen  *int
	// contains filtered or unexported fields
}

KeyVizFlags is the --keyviz* flag group that configures the in-memory key visualizer sampler. The sampler is off unless --keyvizEnabled or --autoSplit is set; the other flags are no-ops while it is off.

func RegisterKeyVizFlags

func RegisterKeyVizFlags(fs *flag.FlagSet) *KeyVizFlags

RegisterKeyVizFlags registers the --keyviz* sampler flags on fs.

func (*KeyVizFlags) RecordExplicit

func (k *KeyVizFlags) RecordExplicit(fs *flag.FlagSet)

RecordExplicit notes which of these flags fs saw on the command line. Call it after fs.Parse: --autoSplit raises the per-route key buckets only when the operator did not choose them.

type Leader

type Leader interface {
	IsLeader() bool
}

Leader is the leadership the auto-split scheduler consults. Both *kv.ShardedCoordinator and *kv.Coordinate implement it, along with the key- and term-scoped leadership the scheduler prefers when present.

Jump to

Keyboard shortcuts

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