hashicorp/nomad · error

missing target region

Error message

missing target region

What it means

The monitor handler streams Agent.Monitor logs to a specific server and manually handles region routing. When RequestRegion() returns empty, it cannot resolve the destination server and emits a 400 error to the stream before closing. Like Profile, this is input validation on the forwarded/streamed RPC.

Source

Thrown at nomad/client_agent_endpoint.go:177

	if args.LogLevel == "" {
		logLevel = log.LevelFromString("INFO")
	}

	if logLevel == log.NoLevel {
		handleStreamResultError(errors.New("Unknown log level"), new(int64(400)), encoder)
		return
	}

	// Targeting a node, forward request to node
	if args.NodeID != "" {
		a.forwardMonitorClient(conn, args, encoder, decoder, args.NodeID, "Agent.Monitor")
		// forwarded request has ended, return
		return
	}

	region := args.RequestRegion()
	if region == "" {
		handleStreamResultError(fmt.Errorf("missing target region"), new(int64(400)), encoder)
		return
	}
	if region != a.srv.Region() {
		// Mark that we are forwarding
		args.SetForwarded()
	}

	// Try to forward request to remote region/server
	if args.ServerID != "" {
		serverToFwd, err := a.forwardFor(args.ServerID, region)
		if err != nil {
			handleStreamResultError(err, new(int64(400)), encoder)
			return
		}
		if serverToFwd != nil {
			// Empty ServerID to prevent forwarding loop
			args.ServerID = ""
			a.forwardMonitorServer(conn, serverToFwd, args, encoder, decoder, "Agent.Monitor")

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Populate the target region on the Monitor request before opening the stream.
  2. Use the official HTTP API (`/v1/agent/monitor`) with a region-scoped Nomad API client.
  3. Verify any proxy/load-balancer in front of Nomad is not stripping the region from request payloads.

Example fix

// before
req := &agent.MonitorRequest{} // no region → 400
// after
req := &agent.MonitorRequest{}
req.SetRegion("dc1")
Defensive patterns

Strategy: validation

Validate before calling

if req.RequestRegion() == "" {
    return fmt.Errorf("Agent.Monitor requires a target region")
}

Prevention

When it happens

Trigger: Invoking the Agent.Monitor streaming RPC without a region set on the request args — raw RPC usage or a client that cleared the region before streaming.

Common situations: Custom log-following clients built directly on the RPC layer; middleware that rewrites requests and drops QueryMeta/region fields; stale client code predating region-aware agent endpoints.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/d5cd4b4941f9f625. Report an issue: GitHub.