Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New API endpoint to back UI jobs index page uplift #20130

Merged
merged 54 commits into from
May 3, 2024

Conversation

gulducat
Copy link
Member

@gulducat gulducat commented Mar 13, 2024

Introduce a new API /v1/jobs/statuses, primarily for use in the UI, that collates info about jobs, their allocations, and latest deployment.

Closes #19339 ; UI changes that use it for /ui/jobs page: #20452

Some of noteworthy tidbits:

  • reads from 3 state tables ("jobs", "allocs", "deployment") to collate info about each job.
    • the "jobs" table is the primary table used to iterate, therefore any ?filter=s apply to structs.Job (i.e. one can not filter based on allocs or such)
  • in order to reproduce the current UI behavior which shows most-recently-changed jobs first, this uses a new "modify_index" index, so the jobs are sorted by ModifyIndex
    • the efficiency trade-off is a whole-table scan when filtering (since we're not using a namespace/id index)
    • currently the UI loads allll of /v1/jobs, then sorts client-side, but we're introducing pagination here, so less efficient in one sense, but more efficient in another
  • the reply.Index used to unblock the RPC is the highest of all objects' ModifyIndex, instead of the latest index on any of the state tables, in order to avoid unblocking the on changes that occur "off page"

Hopefully tests and code comments cover the rest of the nuances.

I'm leaving the whole messy commit history for posterity, but will squash on merge!

api/jobs.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
nomad/jobs_endpoint.go Outdated Show resolved Hide resolved
nomad/jobs_endpoint.go Outdated Show resolved Hide resolved
nomad/structs/job.go Outdated Show resolved Hide resolved
nomad/structs/job.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
command/agent/job_endpoint.go Outdated Show resolved Hide resolved
nomad/jobs_endpoint.go Outdated Show resolved Hide resolved
nomad/jobs_endpoint.go Outdated Show resolved Hide resolved
gulducat added 10 commits May 3, 2024 11:41
example usage:

```
$ cat jobs.json
{
  "jobs": [
    {"id": "clients", "namespace": "default"},
    {"id": "fail"}
  ]
}

$ cat jobs.json | nomad operator api -X POST /v1/jobs/statuses | jq .
```
with ?index= query param e.g.

```
$ cat jobs.json | nomad operator api -X POST /v1/jobs/statuses?index=1681 | jq .
```
will need to read response headers for index, next_token
gulducat added 9 commits May 3, 2024 11:41
in favor of LatestDeployment which has more info
* add ability to include them at all: ?include_children=true
* add ParentID to UIJob response, so they can be associated
  with the parent job
* for parent jobs, ChildStatuses should always be an array,
  rather than nil (null)
nomad/mock/alloc.go Show resolved Hide resolved
nomad/state/schema.go Show resolved Hide resolved
@gulducat gulducat marked this pull request as ready for review May 3, 2024 16:01
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @gulducat!

I've left a few minor comments, but the only one that really raises an eyebrow is the flaky test warning. I'd be open to fixing that in a separate PR though. Also, we'll need to add API docs. That can be a separate PR as well.

nomad/job_endpoint_statuses.go Outdated Show resolved Hide resolved
nomad/job_endpoint_statuses.go Outdated Show resolved Hide resolved
command/agent/job_endpoint_statuses.go Outdated Show resolved Hide resolved
Comment on lines +36 to +37
// ostensibly GETs should not accept structured body, but the HTTP spec
// on this is more what you'd call "guidelines" than actual rules.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

command/agent/job_endpoint_statuses.go Outdated Show resolved Hide resolved
nomad/job_endpoint_statuses.go Outdated Show resolved Hide resolved
Comment on lines +105 to +108
// this little cutie sets the latest state index to a predictable value,
// to ensure the below jobs span the boundary from 999->1000 which would
// break pagination without proper uint64 NextToken (ModifyIndex) comparison
must.NoError(t, s.State().UpsertNamespaces(996, nil))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clever, and good explanatory comment! 👍

nomad/job_endpoint_statuses_test.go Outdated Show resolved Hide resolved
my own subtest naming inconsistency was making me twitchy
Copy link

github-actions bot commented Jan 9, 2025

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hcc/bff Internal: server-side stuff in a client-side world theme/api HTTP API and SDK issues theme/ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-job watchable allocation endpoint
3 participants