Add [master] config section to agent for registration
Heartbeat client now reads master connection settings from the agent config ([master] section) with env var fallback. Includes address, ca_cert, token_path, and role fields. Agent's Run() creates and starts the heartbeat client automatically when [master] is configured. Tested on all three nodes: rift (master), svc (edge), orion (worker) all registered with the master and sending heartbeats every 30s. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,17 +44,31 @@ type HeartbeatClient struct {
|
||||
// NewHeartbeatClient creates a client that registers with the master and
|
||||
// sends periodic heartbeats. Returns nil if master address is not configured.
|
||||
func NewHeartbeatClient(cfg config.AgentConfig, logger interface{ Info(string, ...any); Warn(string, ...any); Error(string, ...any) }) (*HeartbeatClient, error) {
|
||||
masterAddr := os.Getenv("MCP_MASTER_ADDRESS")
|
||||
masterCACert := os.Getenv("MCP_MASTER_CA_CERT")
|
||||
masterToken := os.Getenv("MCP_MASTER_TOKEN_PATH")
|
||||
// Config takes precedence, env vars as fallback.
|
||||
masterAddr := cfg.Master.Address
|
||||
if masterAddr == "" {
|
||||
masterAddr = os.Getenv("MCP_MASTER_ADDRESS")
|
||||
}
|
||||
masterCACert := cfg.Master.CACert
|
||||
if masterCACert == "" {
|
||||
masterCACert = os.Getenv("MCP_MASTER_CA_CERT")
|
||||
}
|
||||
masterTokenPath := cfg.Master.TokenPath
|
||||
if masterTokenPath == "" {
|
||||
masterTokenPath = os.Getenv("MCP_MASTER_TOKEN_PATH")
|
||||
}
|
||||
role := cfg.Master.Role
|
||||
if role == "" {
|
||||
role = "worker"
|
||||
}
|
||||
|
||||
if masterAddr == "" {
|
||||
return nil, nil // master not configured
|
||||
}
|
||||
|
||||
token := ""
|
||||
if masterToken != "" {
|
||||
data, err := os.ReadFile(masterToken) //nolint:gosec // trusted config
|
||||
if masterTokenPath != "" {
|
||||
data, err := os.ReadFile(masterTokenPath) //nolint:gosec // trusted config
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read master token: %w", err)
|
||||
}
|
||||
@@ -92,7 +106,7 @@ func NewHeartbeatClient(cfg config.AgentConfig, logger interface{ Info(string, .
|
||||
client: mcpv1.NewMcpMasterServiceClient(conn),
|
||||
conn: conn,
|
||||
nodeName: cfg.Agent.NodeName,
|
||||
role: "worker", // default; master node sets this via config
|
||||
role: role,
|
||||
address: cfg.Server.GRPCAddr,
|
||||
arch: runtime.GOARCH,
|
||||
interval: 30 * time.Second,
|
||||
|
||||
Reference in New Issue
Block a user