Checker / reload:
- Reload's update-in-place branch now mirrors b.Address onto the
runtime health.Backend. Without this, GetBackend kept returning
the pre-reload address indefinitely after a config edit that
touched addresses but not healthcheck settings — the VPP sync
path reads cfg.Backends directly so the dataplane moved on
while the gRPC and SPA view stayed wedged on the old IPv4/IPv6.
Sync (internal/vpp/lbsync.go):
- reconcileVIP now detects encap mismatch in addition to
src-ip-sticky mismatch and takes the full tear-down / re-add
path via a new shared recreateVIP helper. Triggered when every
backend flips address family (gre4 <-> gre6) and the existing
VIP can no longer accept new ASes — previously the sync wedged
with 'Invalid address family' until a full maglevd restart.
- setASWeight is issued whenever the state machine requests
flush (a.Flush=true), not only on the weight-value transition
edge. Fixes the case where a backend reached StateDisabled
after its effective weight had already been drained to 0 by
pool failover — the sticky-cache entries pointing at it were
previously never cleared.
maglev-frontend:
- signal.Ignore(SIGHUP) so a controlling-terminal disconnect
doesn't kill the daemon.
- debian/vpp-maglev.service grants CAP_SYS_ADMIN in addition to
CAP_NET_RAW so setns(CLONE_NEWNET) can join the healthcheck
netns. Comment documents the 'operation not permitted' symptom
and notes the knob can be dropped if the deployment doesn't use
the 'netns:' healthcheck option.
LB plugin counters (internal/vpp/lbstats.go + friends):
- Fix the VIP counter regex: the LB plugin registers
vlib_simple_counter_main_t names without a leading '/'
(vlib_validate_simple_counter in counter.c:50 uses cm->name
verbatim; only entries that set cm->stat_segment_name get a
slash). first/next/untracked/no-server now read through as
live values instead of zero.
- Drop the per-backend FIB counter block end-to-end (proto,
grpcapi, metrics, vpp.Client, lbstats, maglevc). Traced from
lb/node.c:558 into ip{4,6}_forward.h:141 — the LB plugin
forwards by writing adj_index[VLIB_TX] directly and bypassing
ip{4,6}_lookup_inline, which is the only path that increments
lbm_to_counters. The backend's FIB load_balance stats_index
literally never ticks for LB-forwarded traffic, so the column
was always zero and misleading. docs/implementation/TODO
records the full investigation and the recommended upstream
path (new lb_as_stats_dump API message) for when we're ready
to carry that VPP patch.
- maglevc show vpp lb counters: plain-text tabular headers.
label() wraps strings in ANSI escapes (~11 bytes of overhead),
but tabwriter counts bytes, not rendered width — so a header
row with label()'d cells and data rows with plain cells drifts
column alignment on every row. color.go comment now spells
out the constraint: label() only works when column N is
wrapped identically in every row (key-value layouts are fine,
multi-column tables with header-only labelling are not).
SPA:
- stores/scope.ts is cookie-backed (maglev_scope, 1 year,
SameSite=Lax). App.tsx hydrates from the cookie then validates
against the fetched snapshots: a cookie referencing a maglevd
that no longer exists falls through to snaps[0] instead of
leaving the user on a ghost selection.
- components/Flash.tsx wraps props.value in createMemo. Solid's
on() fires its callback on every dep notification, not on
value change — source is right in solid-js/dist/solid.js:460,
no equality check. Without the memo, flipping scope between
two 'connected' maglevds (or any other cross-store reactive
re-eval that doesn't actually change the concrete string)
replays the animation every time. createMemo's default ===
dedupe fixes it in one place for every Flash consumer,
superseding the local createMemo workaround we'd added in
BackendRow earlier.
149 lines
3.9 KiB
Go
149 lines
3.9 KiB
Go
// Copyright (c) 2026, Pim van Pelt <pim@ipng.ch>
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"flag"
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
buildinfo "git.ipng.ch/ipng/vpp-maglev/cmd"
|
|
)
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
slog.Error("startup-fatal", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run() error {
|
|
// All env vars are prefixed with MAGLEV_FRONTEND_ so a single
|
|
// /etc/default/vpp-maglev (or a Docker env file) can be shared
|
|
// with maglevd without its MAGLEV_LOG_LEVEL / MAGLEV_GRPC_ADDR /
|
|
// etc. leaking into this process's config.
|
|
printVersion := flag.Bool("version", false, "print version and exit")
|
|
servers := stringFlag("server", "", "MAGLEV_FRONTEND_SERVERS", "comma-separated maglevd gRPC addresses (required)")
|
|
listen := stringFlag("listen", ":8080", "MAGLEV_FRONTEND_LISTEN", "HTTP listen address")
|
|
logLevel := stringFlag("log-level", "info", "MAGLEV_FRONTEND_LOG_LEVEL", "log verbosity (debug|info|warn|error)")
|
|
flag.Parse()
|
|
|
|
if *printVersion {
|
|
fmt.Printf("maglevd-frontend %s (commit %s, built %s)\n",
|
|
buildinfo.Version(), buildinfo.Commit(), buildinfo.Date())
|
|
return nil
|
|
}
|
|
|
|
var level slog.Level
|
|
if err := level.UnmarshalText([]byte(*logLevel)); err != nil {
|
|
return fmt.Errorf("invalid log level %q: %w", *logLevel, err)
|
|
}
|
|
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: level})))
|
|
slog.Info("starting",
|
|
"version", buildinfo.Version(),
|
|
"commit", buildinfo.Commit(),
|
|
"date", buildinfo.Date())
|
|
|
|
addrs := parseServers(*servers)
|
|
if len(addrs) == 0 {
|
|
return errors.New("at least one -server address is required")
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
broker := NewBroker()
|
|
|
|
clients := make([]*maglevClient, 0, len(addrs))
|
|
for _, addr := range addrs {
|
|
c, err := newMaglevClient(addr, broker)
|
|
if err != nil {
|
|
return fmt.Errorf("connect %s: %w", addr, err)
|
|
}
|
|
clients = append(clients, c)
|
|
c.Start(ctx)
|
|
slog.Info("maglevd-configured", "name", c.name, "address", c.address)
|
|
}
|
|
|
|
admin := adminCreds{
|
|
User: os.Getenv("MAGLEV_FRONTEND_USER"),
|
|
Password: os.Getenv("MAGLEV_FRONTEND_PASSWORD"),
|
|
}
|
|
admin.Enabled = admin.User != "" && admin.Password != ""
|
|
if admin.Enabled {
|
|
slog.Info("admin-enabled", "user", admin.User)
|
|
} else {
|
|
slog.Info("admin-disabled",
|
|
"reason", "MAGLEV_FRONTEND_USER and MAGLEV_FRONTEND_PASSWORD must both be set and non-empty")
|
|
}
|
|
|
|
mux := http.NewServeMux()
|
|
registerHandlers(mux, clients, broker, admin)
|
|
|
|
srv := &http.Server{
|
|
Addr: *listen,
|
|
Handler: mux,
|
|
ReadHeaderTimeout: 10 * time.Second,
|
|
}
|
|
|
|
// Ignore SIGHUP so a controlling-terminal disconnect (or any
|
|
// stray process-group SIGHUP) doesn't kill the daemon — the
|
|
// default Go handler terminates the process with "Hangup",
|
|
// which is the wrong behaviour for a long-running network
|
|
// service. SIGTERM / SIGINT remain the clean-shutdown signals.
|
|
signal.Ignore(syscall.SIGHUP)
|
|
sigCh := make(chan os.Signal, 1)
|
|
signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT)
|
|
|
|
errCh := make(chan error, 1)
|
|
go func() {
|
|
slog.Info("http-listening", "addr", *listen)
|
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
|
errCh <- err
|
|
}
|
|
}()
|
|
|
|
select {
|
|
case sig := <-sigCh:
|
|
slog.Info("shutdown", "signal", sig)
|
|
case err := <-errCh:
|
|
cancel()
|
|
return err
|
|
}
|
|
|
|
cancel()
|
|
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer shutdownCancel()
|
|
_ = srv.Shutdown(shutdownCtx)
|
|
for _, c := range clients {
|
|
c.Close()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func parseServers(s string) []string {
|
|
var out []string
|
|
for _, part := range strings.Split(s, ",") {
|
|
if p := strings.TrimSpace(part); p != "" {
|
|
out = append(out, p)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func stringFlag(name, defaultVal, envKey, usage string) *string {
|
|
val := defaultVal
|
|
if v := os.Getenv(envKey); v != "" {
|
|
val = v
|
|
}
|
|
return flag.String(name, val, fmt.Sprintf("%s (env: %s)", usage, envKey))
|
|
}
|