{"record":{"id":"d5cd4b4941f9f625","repo":"hashicorp/nomad","slug":"missing-target-region","errorCode":null,"errorMessage":"missing target region","messagePattern":"missing target region","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"nomad/client_agent_endpoint.go","lineNumber":177,"sourceCode":"\tif args.LogLevel == \"\" {\n\t\tlogLevel = log.LevelFromString(\"INFO\")\n\t}\n\n\tif logLevel == log.NoLevel {\n\t\thandleStreamResultError(errors.New(\"Unknown log level\"), new(int64(400)), encoder)\n\t\treturn\n\t}\n\n\t// Targeting a node, forward request to node\n\tif args.NodeID != \"\" {\n\t\ta.forwardMonitorClient(conn, args, encoder, decoder, args.NodeID, \"Agent.Monitor\")\n\t\t// forwarded request has ended, return\n\t\treturn\n\t}\n\n\tregion := args.RequestRegion()\n\tif region == \"\" {\n\t\thandleStreamResultError(fmt.Errorf(\"missing target region\"), new(int64(400)), encoder)\n\t\treturn\n\t}\n\tif region != a.srv.Region() {\n\t\t// Mark that we are forwarding\n\t\targs.SetForwarded()\n\t}\n\n\t// Try to forward request to remote region/server\n\tif args.ServerID != \"\" {\n\t\tserverToFwd, err := a.forwardFor(args.ServerID, region)\n\t\tif err != nil {\n\t\t\thandleStreamResultError(err, new(int64(400)), encoder)\n\t\t\treturn\n\t\t}\n\t\tif serverToFwd != nil {\n\t\t\t// Empty ServerID to prevent forwarding loop\n\t\t\targs.ServerID = \"\"\n\t\t\ta.forwardMonitorServer(conn, serverToFwd, args, encoder, decoder, \"Agent.Monitor\")","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/client_agent_endpoint.go#L159-L195","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Populate the target region on the Monitor request before opening the stream.","Use the official HTTP API (`/v1/agent/monitor`) with a region-scoped Nomad API client.","Verify any proxy/load-balancer in front of Nomad is not stripping the region from request payloads."],"exampleFix":"// before\nreq := &agent.MonitorRequest{} // no region → 400\n// after\nreq := &agent.MonitorRequest{}\nreq.SetRegion(\"dc1\")","handlingStrategy":"validation","validationCode":"if req.RequestRegion() == \"\" {\n    return fmt.Errorf(\"Agent.Monitor requires a target region\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set region on Monitor requests before opening the stream.","Prefer the /v1/agent/monitor HTTP endpoint with a region-scoped client.","Check proxies don't strip region fields from RPC payloads."],"tags":["nomad","rpc","log-monitoring","region","streaming"],"backgroundTag":"missing-request-parameter","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}