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.
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
Enforce idempotency of dispatched jobs using token on dispatch request #10806
Enforce idempotency of dispatched jobs using token on dispatch request #10806
Changes from 7 commits
c4be87a
b5d21a9
f607c35
8502048
d83ff8b
63d8e92
aa3512d
4448cff
6a1a200
3a8febe
2bd2f58
16d43ae
d77329a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of special casing dead jobs? I fear that this becomes an edge case for super short dispatch jobs - where if the job finishes before the caller retries request (due to long exponential backoff sleep), the job gets re-run. Naively, I'd think we should enforce idempotency as long as possible, basically until the child job is garbage collected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, I hadn't considered the short dispatch case. For our use case on HCP, the idempotency token will map to an action for a specific resource (ie
consul-cluster/{uuid}/instance-create
). In the case of a transient error in the dispatched job, we'd like to retry immediately, using the same idempotency token. If idempotency is enforced for dead jobs waiting to be GC'd we wouldn't be able to retry as quickly as we'd prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. So there are two types of transient failures:
First, the dispatch request fails with network transient error (e.g. network or timeout) where the dispatch request may have failed but may also have succeed but the caller wasn't informed of the success. The API consumer will want to retry with idempotent token to avoid repeating the side-effects. I assume here we want to enforce the token for the longest reasonable time, as it never hurts.
The second failure is if the dispatch request succeeded but the dispatched job failed with a transient failure (e.g. instance creation failed for transient error and should be retried). Here, api consumer want to retry as soon as the job failed.
Is the second failure case that's driving this design? I would have hoped that the
restart
block addressed this case without the API consumers retrying dispatching jobs manually.Also, you can achieve the second failure handling semantics even if idempotent token is enforced for dead jobs. e.g. you can have
consul-cluster/{resource uuid}/instance-create/{request uuid}
, where{request uuid}
is updated when the dispatch job failed and you want to retry creating the same resource.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, totally forgot about the
restart
block and your{request uuid}
suggestion makes perfect sense so I will remove the check for job status and update the comment to say something about the job not being GC'd yet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return an error here? How should clients cope with this error? It might be best to return info of the existing job info.
The rationale is that clients should ensure that tokens are unique (e.g. uuids, etc) and this condition should only occur if the caller is retrying a request that failed due to transient error (e.g. network error, request timeout). As such, it will be nicer to return the original dispatch request results. If we return an error here (which Nomad codes as HTTP 500 code sadly :( ), api consumers will need to special case idempotency related errors (vs keep retrying) and need to parse the error to find the job id and potentially make a follow up query to get result data. Returning the existing job ID in such a case seems to be more ergonomics.
Returning success code seems to match EC2 RunInstance idempotent request behavior. I'd be curious to know how other common APIs handle retried idempotent requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to returning the existing job info as I do think that is what most APIs do for idempotent operations.
I do have 1 question about the
reply
in this case: do we need to fetch the current eval for the existing job if it's not periodic? It appears that non-periodic dispatches return the eval id etcnomad/nomad/job_endpoint.go
Lines 1999 to 2001 in 4448cff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I'd skip eval fields in this PR for now.
The eval creation code needs to change so the job dispatch and eval creation is atomic - I missed this case in #8435 . I can follow up there and re-examine this path again. Thanks!
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.