One bidirectional connect-go stream per node, carrying registration, heartbeats and shard status up, and start, stop and drain down. The agent dials out: GPU nodes sit behind firewalls far more often than a control plane does, and an outbound connection needs no inbound rule on every node in the fleet. - registration carries the whole hardware inventory, so there is no separate discovery call and a reconnecting agent refreshes what the scheduler knows. The fabric labels travel with it; they cannot be inferred from the wire, so losing them in transit would silently disable multi-node placement. - agentsvc is both the stream handler and the reconciler's dispatcher, because it holds the open streams and is therefore the only thing that can deliver a command to a node. - the agent validates a profile before launching anything, since an engine that refuses a profile does so after minutes of loading, then supervises the process and reports every transition with the engine's output tail on failure. - reconnects forever with jittered backoff. A control plane restart must not require touching every GPU node, and a fleet must not reconnect in lockstep and knock it over again. Engines keep serving throughout, because the router talks to them directly. llmgw agent is real now, and llmgw server runs a control plane whenever any model declares a profile. The static endpoint list stays for router-only runs. Verified with real binaries as separate processes: the agent registers, a replica is placed, an engine launches through the vLLM adapter's actual argument construction, streaming traffic is served, and killing the agent moves the node through unreachable to lost with placement explaining why nothing can run. config.Model and catalog.Model were the same thing described twice, so the router now reads catalog entries directly and the validation rules live in one place. Still missing: mTLS. The stream is plaintext HTTP/2 and must stay on a trusted network until that lands. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
188 lines
5.6 KiB
Go
188 lines
5.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"text/tabwriter"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/agent"
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/agent/discovery"
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/config"
|
|
"gitea.mynodes.xyz/ilker/llmgw/internal/version"
|
|
)
|
|
|
|
func newAgentCmd() *cobra.Command {
|
|
var configPath string
|
|
|
|
var (
|
|
server string
|
|
nodeID string
|
|
mgmtAddr string
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "agent",
|
|
Short: "Node agent: discovery and engine supervision",
|
|
Long: "Runs on every GPU node. It discovers the hardware, connects to the control\n" +
|
|
"plane, and starts, supervises and stops inference engines on demand.\n\n" +
|
|
"The agent dials out and keeps one stream open. Engines keep serving if the\n" +
|
|
"agent restarts or the control plane goes away: the router talks to them\n" +
|
|
"directly, and orphan adoption picks them up again.",
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
log := logger()
|
|
|
|
cfg, err := config.LoadAgent(configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if server != "" {
|
|
cfg.Server = server
|
|
}
|
|
if nodeID != "" {
|
|
cfg.NodeID = nodeID
|
|
}
|
|
if mgmtAddr != "" {
|
|
cfg.MgmtAddr = mgmtAddr
|
|
}
|
|
if cfg.NodeID == "" {
|
|
host, err := os.Hostname()
|
|
if err != nil {
|
|
return fmt.Errorf("node_id is unset and the hostname is unavailable: %w", err)
|
|
}
|
|
cfg.NodeID = host
|
|
}
|
|
if cfg.Hostname == "" {
|
|
cfg.Hostname, _ = os.Hostname()
|
|
}
|
|
cfg.Version = version.Version
|
|
|
|
a, err := agent.New(cfg, agent.HTTP2Client(30*time.Second), log)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ctx, stop := signal.NotifyContext(cmd.Context(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
log.Info("agent starting",
|
|
"node", cfg.NodeID, "server", cfg.Server,
|
|
"fabrics", len(cfg.Fabrics), "nvml", discovery.NVMLSupported())
|
|
|
|
err = a.Run(ctx)
|
|
if errors.Is(err, context.Canceled) {
|
|
return nil
|
|
}
|
|
return err
|
|
},
|
|
}
|
|
cmd.Flags().StringVar(&configPath, "config", "", "configuration file")
|
|
cmd.Flags().StringVar(&server, "server", "", "control plane address (overrides the config)")
|
|
cmd.Flags().StringVar(&nodeID, "node-id", "", "node id (defaults to the hostname)")
|
|
cmd.Flags().StringVar(&mgmtAddr, "mgmt-addr", "", "address engines are reachable on")
|
|
cmd.AddCommand(newInventoryCmd())
|
|
return cmd
|
|
}
|
|
|
|
func newInventoryCmd() *cobra.Command {
|
|
var (
|
|
asJSON bool
|
|
smiBin string
|
|
ibRoot string
|
|
skipGPU bool
|
|
useNVML bool
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "inventory",
|
|
Short: "Show this node's GPUs and InfiniBand adapters",
|
|
Long: "Reports what the scheduler would see on this node: GPU classes, health,\n" +
|
|
"and the fabric each adapter is attached to.\n\n" +
|
|
"Run it before adding a node to the cluster — it is the fastest way to find\n" +
|
|
"a card another process is already using, or a port with no subnet manager.",
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
inv, err := discovery.Discover(cmd.Context(), discovery.Options{
|
|
NvidiaSMI: smiBin,
|
|
IBRoot: ibRoot,
|
|
PreferNVML: useNVML,
|
|
SkipGPUs: skipGPU,
|
|
}, logger())
|
|
if err != nil {
|
|
// Not fatal: a node whose GPUs cannot be read still has IB
|
|
// worth showing, and the error is itself the useful output.
|
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
|
inv.Source = "unavailable"
|
|
}
|
|
|
|
if asJSON {
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(inv)
|
|
}
|
|
printInventory(inv)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
f := cmd.Flags()
|
|
f.BoolVar(&asJSON, "json", false, "emit JSON")
|
|
f.StringVar(&smiBin, "nvidia-smi", "", "path to nvidia-smi")
|
|
f.StringVar(&ibRoot, "ib-root", discovery.SysfsRoot, "sysfs InfiniBand directory")
|
|
f.BoolVar(&skipGPU, "no-gpu", false, "skip GPU discovery")
|
|
f.BoolVar(&useNVML, "nvml", true, "prefer the NVML backend when this build has one (it is the only source of NVLink topology)")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func printInventory(inv discovery.Inventory) {
|
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
|
|
|
fmt.Fprintf(w, "GPUs (%d, via %s)\n", len(inv.GPUs), inv.Source)
|
|
if len(inv.GPUs) == 0 {
|
|
fmt.Fprintln(w, " none")
|
|
} else {
|
|
fmt.Fprintln(w, " IDX\tCLASS\tNAME\tMEM\tCC\tHEALTH")
|
|
for _, g := range inv.GPUs {
|
|
health := "ok"
|
|
if !g.Health.OK() {
|
|
health = g.Health.Problems[0]
|
|
}
|
|
fmt.Fprintf(w, " %d\t%s\t%s\t%d MiB\t%s\t%s\n",
|
|
g.Index, g.Class(), g.Name, g.MemoryTotalMB, g.ComputeCapability, health)
|
|
}
|
|
fmt.Fprintf(w, " classes: %v\n", inv.Classes())
|
|
if !discovery.NVMLSupported() {
|
|
fmt.Fprintln(w, " NVLink topology unavailable: rebuild with -tags nvml.")
|
|
fmt.Fprintln(w, " Without it, placement cannot keep a tensor-parallel group inside")
|
|
fmt.Fprintln(w, " one NVLink domain (plan §6.2).")
|
|
}
|
|
}
|
|
|
|
fmt.Fprintf(w, "\nInfiniBand adapters (%d)\n", len(inv.HCAs))
|
|
if len(inv.HCAs) == 0 {
|
|
// Worth stating plainly: such a node is its own single-node island and
|
|
// can never host a multi-node replica.
|
|
fmt.Fprintln(w, " none — this node cannot host multi-node replicas")
|
|
} else {
|
|
fmt.Fprintln(w, " HCA\tPORT\tSTATE\tRATE\tLINK\tGID PREFIX\tNUMA")
|
|
for _, h := range inv.HCAs {
|
|
for _, p := range h.Ports {
|
|
fmt.Fprintf(w, " %s\t%d\t%s\t%d Gb/s\t%s\t%s\t%d\n",
|
|
h.Name, p.Num, p.State, p.RateGbps, p.LinkLayer, p.GIDPrefix, h.NUMANode)
|
|
}
|
|
}
|
|
fmt.Fprintln(w, "\n Fabric identity is not derived from the GID prefix by default:")
|
|
fmt.Fprintln(w, " OpenSM's default is fe80:: on every fabric, so a shared prefix proves")
|
|
fmt.Fprintln(w, " nothing. Label fabrics explicitly in agent.yaml (plan §5.2).")
|
|
}
|
|
|
|
_ = w.Flush()
|
|
}
|