Skip to content

fix: decode node drivers/class/pool/resources; list_jobs without N+1 requests - #71

Merged
kocierik merged 2 commits into
kocierik:mainfrom
Niki-q:fix/decode-node-and-list-jobs
Oct 19, 2026
Merged

kocierik merged 2 commits into
kocierik:mainfrom
Niki-q:fix/decode-node-and-list-jobs

Conversation

@Niki-q

@Niki-q Niki-q commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes two tools that fail or misbehave against a real Nomad cluster, plus a timeout in list_jobs.

get_node / list_nodes

  • Node.Drivers was map[string]bool, but /v1/node/:id returns an object per driver, so get_node failed with json: cannot unmarshal object into Go struct field Node.drivers of type bool. It is now map[string]DriverInfo (Detected, Healthy, HealthDescription).
  • NodeClass and NodePool used snake_case JSON tags that never match the API field names, so node_class was always empty. They now use the API names (NodeClass, NodePool); the Resources/Reserved tags are corrected the same way.
  • Recent Nomad versions leave the legacy Resources field zeroed and report node capacity under NodeResources (Cpu.CpuShares, Memory.MemoryMB, Disk.DiskMB), so get_node also decodes NodeResources.
    • Heads-up: this renames some output keys (node_class -> NodeClass, cpu/memory_mb/disk_mb -> CPU/MemoryMB/DiskMB). Happy to keep the old output keys with a small projection if you prefer.

list_jobs

  • The handler called GetJob and GetJobSummary for every job from /v1/jobs (two serial extra requests per job). On a namespace with ~200 jobs that is ~400 round-trips and it timed out. The list stubs already carry Name/Type/Status/Priority/ParentID and a nested JobSummary, so the listing is now built from the single list call (about 0.3s for ~200 jobs, previously a timeout).
  • Nomad ignores ?status= on /v1/jobs, so the status filter had no effect; it is now applied client-side.
  • New optional prefix filter.

Tests

  • types/regression_test.go: decodes the real node/node-list shapes.
  • test/unit/jobs_list_test.go: asserts list_jobs makes no per-job GetJob/GetJobSummary calls and that status/prefix filter.
  • go vet ./... and go test ./... pass.

Related: the RescheduleTime decode failure from #22/#49 is already fixed on main; this PR does not touch it.

🤖 Generated with Claude Code

…ng N+1 requests

get_node
- Node.Drivers is declared map[string]bool, but /v1/node/:id returns an object per
  driver, so get_node failed with "cannot unmarshal object into Go struct field
  Node.drivers of type bool". It is now map[string]DriverInfo.
- NodeClass, NodePool and Resources were tagged with snake_case names that never
  match the API's field names, so list_nodes/get_node always reported an empty
  node_class and zero resources. They now use the API names (NodeClass, NodePool,
  CPU/MemoryMB/DiskMB). Note: this renames those output keys.

list_jobs
- The handler fetched the full job and the job summary for every job returned by
  /v1/jobs (two extra requests per job, serially), which timed out on namespaces
  with a few hundred jobs. The list stubs already carry Name/Type/Status/Priority/
  ParentID and a nested JobSummary, so the listing is now built from the single
  list call.
- Nomad ignores ?status= on /v1/jobs, so the status filter did nothing; it is now
  applied client-side. Add an optional prefix filter.

Tests: decoding regressions for the node shapes, and a handler test asserting
list_jobs makes no per-job GetJob/GetJobSummary calls.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Recent Nomad versions leave the legacy Resources field zeroed and report node
capacity under NodeResources (Cpu.CpuShares, Memory.MemoryMB, Disk.DiskMB), so
get_node showed zero resources even after fixing the tag names. Decode
NodeResources as well.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@kocierik
kocierik merged commit e00c9b9 into kocierik:main Oct 19, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants