Repository navigation
fix: decode node drivers/class/pool/resources; list_jobs without N+1 requests - #71
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes two tools that fail or misbehave against a real Nomad cluster, plus a timeout in
list_jobs.get_node/list_nodesNode.Driverswasmap[string]bool, but/v1/node/:idreturns an object per driver, soget_nodefailed withjson: cannot unmarshal object into Go struct field Node.drivers of type bool. It is nowmap[string]DriverInfo(Detected,Healthy,HealthDescription).NodeClassandNodePoolused snake_case JSON tags that never match the API field names, sonode_classwas always empty. They now use the API names (NodeClass,NodePool); theResources/Reservedtags are corrected the same way.Resourcesfield zeroed and report node capacity underNodeResources(Cpu.CpuShares,Memory.MemoryMB,Disk.DiskMB), soget_nodealso decodesNodeResources.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_jobsGetJobandGetJobSummaryfor 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 nestedJobSummary, so the listing is now built from the single list call (about 0.3s for ~200 jobs, previously a timeout).?status=on/v1/jobs, so thestatusfilter had no effect; it is now applied client-side.prefixfilter.Tests
types/regression_test.go: decodes the real node/node-list shapes.test/unit/jobs_list_test.go: assertslist_jobsmakes no per-jobGetJob/GetJobSummarycalls and thatstatus/prefixfilter.go vet ./...andgo test ./...pass.Related: the
RescheduleTimedecode failure from #22/#49 is already fixed onmain; this PR does not touch it.🤖 Generated with Claude Code