-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Allow using specific object ID on diff #11400
Conversation
The interface usage makes sense and is nicer than your intial try with the function 👍 to bad that only those few can be changed, I was hoping for even more stanzas
…On Thu, Oct 28, 2021, at 01:17, Luiz Aoqui wrote:
Currently Nomad will use a generic diff method when computing changes
in a jobspec. This method uses a hash of the block content as a way to
match values from the old jobspec to the new one. This approach
generates less than ideal diffs since any change to block will result
in a add/delete pair instead of a more precise edit output.
This PR introduces a new interface that can be implemented by structs
that have some kind of stable and uniquely identifiable field that can
be used to match blocks from the old jobspec to the new one.
Implementing this interface for the `Template` struct, for example,
allows using the destination path as the ID. Nomad guarantees its
uniqueness in a task and If the user modifies it it's fair to assume
this is a new block.
Big thanks to @apollo13 <https://github.com/apollo13> for flagging this
and proposing a solution. Builds upon #11378
<#11378>.
Sample outpus
Before:
`$ nomad job plan example.nomad
+/- Job: "example"
+/- Task Group: "cache" (1 create/destroy update)
+/- Task: "redis" (forces create/destroy update)
+ Template {
+ ChangeMode: "restart"
ChangeSignal: ""
+ DestPath: "local/test"
+ EmbeddedTmpl: "new test"
+ Envvars: "false"
+ LeftDelim: "{{"
+ Perms: "0644"
+ RightDelim: "}}"
SourcePath: ""
+ Splay: "5000000000"
+ VaultGrace: "0"
}
- Template {
- ChangeMode: "restart"
ChangeSignal: ""
- DestPath: "local/test"
- EmbeddedTmpl: "test"
- Envvars: "false"
- LeftDelim: "{{"
- Perms: "0644"
- RightDelim: "}}"
SourcePath: ""
- Splay: "5000000000"
- VaultGrace: "0"
}
`
After:
`$ nomad job plan example.nomad
+/- Job: "example"
+/- Task Group: "cache" (1 create/destroy update)
+/- Task: "redis" (forces create/destroy update)
+/- Template {
ChangeMode: "restart"
ChangeSignal: ""
DestPath: "local/test"
+/- EmbeddedTmpl: "test" => "new test"
Envvars: "false"
LeftDelim: "{{"
Perms: "0644"
RightDelim: "}}"
SourcePath: ""
Splay: "5000000000"
VaultGrace: "0"
}
`
You can view, comment on, or merge this pull request online at:
#11400
Commit Summary
* allow using specific object id on diff
<3d6beda>
File Changes
(3 files <https://github.com/hashicorp/nomad/pull/11400/files>)
* *M* nomad/structs/diff.go
<https://github.com/hashicorp/nomad/pull/11400/files#diff-cc08e6b9f9b4a6ad617e54b7447a48a6cc8722f74319ac922387eae4018f348a>
(34)
* *M* nomad/structs/diff_test.go
<https://github.com/hashicorp/nomad/pull/11400/files#diff-486e32a5d4805af1ae5dc2d19ddd401ff61d6baf957b0c0abbce524d1ee6cd8c>
(28)
* *M* nomad/structs/structs.go
<https://github.com/hashicorp/nomad/pull/11400/files#diff-297649e31d8e88fd89ff63dac7aff450569cca19009616f08c1d73d1e8239725>
(10)
Patch Links:
* https://github.com/hashicorp/nomad/pull/11400.patch
* https://github.com/hashicorp/nomad/pull/11400.diff
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11400>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAT5C7CVMXO36VJ4TAQMBDUJCCA3ANCNFSM5G3P5D5A>.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
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.
Looks great.
Oh yeah, that was really just throw-away code to validate the idea 🙂
The other two fields that use the Maybe with another interface that provides a function that does the matching? But I'm not sure how that will look like and the benefit we would gain, since these 2 attributes are pretty small. |
I guess it boils down to how useful people think job planning is. I personally find it very useful and would love it to be as good as possible. So all in all improving is worthwhile imo -- that said I think there are more important planing issues to fix like:
#11255 where certain attributes are not diffed at all or #10531 (comment) where a change is listed as in place and simply not done. I'll happily work on those but I'll need a bit of guidance (especially how list diffing is supposed to work and whether the second change can actually be made in place).
So maybe let's takle issues like the ones mentioned before we attack a correct but suboptimal check/constraint output? My thinking here is that the more time we spend with diff.go the better our final solution for generalizing check/constraint diffs might turn out simply because we have a better view of the whole picture. (That shouldn't stop us from merging this PR which I think is good to go).
…On Thu, Oct 28, 2021, at 17:57, Luiz Aoqui wrote:
> The interface usage makes sense and is nicer than your intial try with the function 👍
>
Oh yeah, that was really just throw-away code to validate the idea 🙂
> to bad that only those few can be changed, I was hoping for even more stanzas
>
The other two fields that use the `primitiveObjectSetDiff` function are
`constraint` and `affinity`, which suffer from the same problem we had
with `check` before, in which there's no way to uniquely identify them.
We could try to port the heuristic approach we did there, but I think
it would take some work to make that generic and re-usable.
Maybe with another interface that provides a function that does the
matching? But I'm not sure how that will look like and the benefit we
would gain, since these 2 attributes are pretty small.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#11400 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAT5CYNWZ7ZDSR23UQYAUDUJFXHHANCNFSM5G3P5D5A>.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
|
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. |
Currently Nomad will use a generic diff method when computing changes in a jobspec. This method uses a hash of the block content as a way to match values from the old jobspec to the new one. This approach generates less than ideal diffs since any change to block will result in a add/delete pair instead of a more precise edit output.
This PR introduces a new interface that can be implemented by structs that have some kind of stable and uniquely identifiable field that can be used to match blocks from the old jobspec to the new one.
Implementing this interface for the
Template
struct, for example, allows using the destination path as the ID. Nomad guarantees its uniqueness in a task and If the user modifies it it's fair to assume this is a new block.Big thanks to @apollo13 for flagging this and proposing a solution. Builds upon #11378.
Sample outpus
Before:
After: