-
Notifications
You must be signed in to change notification settings - Fork 580
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
Forget that attribute is modified if it's changed back to its original state via API #8036
Conversation
@lippserd This one covers only leaves, e.g. |
@Al2Klimov Yep, leaves should be should be sufficient. |
Testprotocol: Command to modify an object:
Now we reset this modified object.. Although we have reset this modified object to the previous value, it will only update the value in the file instead of completely removing it from the file. With this branch, Icinga2 is able to meet requirements. Firstly we modified an object just the same as before.
And now we set this object to the previous value and restart |
@cla-bot check |
ref/IP/43160 |
I find the use of JSON encoding in this PR very surprising.
Given that there seems to be no update to the PR since that comment, I presume that's still up-to-date. Shouldn't this imply that this PR would work for scalar values only anyways and if so, why would they need JSON encoding to compare them? |
This workarounds the console's
and
|
And why does this matter here? |
Admittedly the second example seems not to matter. But the first one shows that the DSL by itself doesn't compare values in a way we need here. |
Would additionally comparing the type do the trick here? |
Ah, now I've digged it out! I meant dict leaves – which include arrays:
😅 These may also include dicts:
And JSON catches them all. |
I'm wondering why you're using Apart from that, while testing I noticed some behavior. For the first one, my intuition is that it shouldn't be that way, for the second one, I'm not sure what it would need to change that as all that nested dict stuff is somewhat special anyways. Setting the same initial valueWhen setting a variable to the initial value while this is also the current value, this generates a modified attribute. Start with a host with Starting with the clean state, not modified attributes: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"original_attributes": null,
"vars": {
"x": "initial value"
} Now set that variable to the very same value: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs": {"vars.x": "initial value"}}'
"status": "Attributes updated.", Observe how this has created a modified attribute: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"attrs": {
"original_attributes": {
"vars.x": "initial value"
},
"vars": {
"x": "initial value"
} When reloading the daemon (or waiting long enough for the file to be rewritten by itself), this is also persisted to
Perform the very same update with the same value again: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs": {"vars.x": "initial value"}}'
"status": "Attributes updated.", Observe how the modified attribute is gone again: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"attrs": {
"original_attributes": {},
"vars": {
"x": "initial value"
} Inconsistent behavior with nested dictionariesStart with an object with two non-empty dicts as custom variables:
Starting with a clean state, original values are the current values, no modified attributes: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"original_attributes": null,
"vars": {
"y": {
"a": 42
},
"z": {
"a": 42
}
} Modify both numbers, one using the flattened key, one using a nested dict: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs": {"vars.y.a": 23, "vars.z": {"a": 23}}}'
"status": "Attributes updated.", The effect on both variables was exactly the same: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"original_attributes": {
"vars.y.a": 42,
"vars.z.a": 42
},
"vars": {
"y": {
"a": 23
},
"z": {
"a": 23
}
} Reset both values back to the original values using the same method: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs": {"vars.y.a": 42, "vars.z": {"a": 42}}}'
"status": "Attributes updated.", This only removed the modified attribute for the flattened one, the override with the nested dict remained: $ curl -sSku root:icinga https://localhost:5665/v1/objects/hosts/master-1 --json '{"pretty":1, "attrs":["original_attributes", "vars"]}' -X GET
"attrs": {
"original_attributes": {
"vars.z.a": 42
},
"vars": {
"y": {
"a": 42
},
"z": {
"a": 42
}
} All tests were done with the PR rebased onto the current master at d871c5c, responses are simplified to the relevant part. |
You're right. JsonEncode() already handles alien objects. 🛸🐘
Yes, admittedly this is weird. But it's what the user wants. Also you can construct the same case by changing the config e.g. true -> false, modifying the attribute false -> true and changing the config back to true. I.e. true in config and in a modified attribute. No #8739 to the rescue as we've disposed it. So I'm not worried.
Nice! (Would be bad if you couldn’t remove that thing.)
I know. I've explicitly asked permission not to over-engineer this PR: #8036 (comment) |
885a19f
to
700a216
Compare
Well, maybe. The code is using a value to guess what the use wants, as there's no explicit create/drop override information in the request. So the question is, which of these two statements better describes the desired behavior:
Let me quote the suggestion from #7986:
The current state of the PR adds a "but create it if there's nothing to drop" to that statement, which sounds kind of weird. And given that you also called the behavior weird yourself, I'm not sure that (1) is the better option. Also keep in mind that you can modify the attributes of multiple objects at once, so in case you do a
Not exactly the same. Yes, you end up in a state where there's an override that has the same value as the config, but there never was an API request updating the field to the value that was present in the config file at that time. |
This PR is about forgetting existing ones, not (not?) creating new ones. So your argument is valid, but not blocking anything. |
…s original state via API. #8036
The title says it all.
fixes #7986
Edit
E.g. if I change the Director-configured enable_active_checks=true via API to false and back to true, Icinga forgets the false instead of replacing it with true. I.e. mod. attrs. neutralise each other. Director config changes cause no such thing and IIRC we don't want that (#8739).