-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
proxmox inventory: proposal for #9710 (caching) #9760
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
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.
Thanks for your contribution! I've added some comments below, I'd change the flow slightly so that the cache is still used if both update_cache
and use_cache
are true.
Also, can you please add a changelog fragment? Thanks.
This comment was marked as outdated.
This comment was marked as outdated.
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 good from my side. @Thulium-Drake if it's ok for you as well I'll merge.
self._cache[self.cache_key][url] = data | ||
|
||
return make_unsafe(self._cache[self.cache_key][url]) | ||
self._results[url] = data |
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'm not sure about this - the _get_json()
method is used multiple times during the execution of "higher" level _populate()
. This looks similar to a "global" variable that is used to go behind the logic of the program. data
is already being returned by the method (and it is marked unsafe as it should). It is completely out of the scope of what this method is supposed to do.
IMO this is a very cheap solution to the short term problem and an expensive problem in the long term.
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.
How does this differ from what the code was doing before? Except that it was using self._cache[self.cache_key][url]
instead of self._results[url]
.
Also yes, the cache is a global variable and that's how the cache should work, shouldn't it? How else should it cache?
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 would argue that it was already a poor design (IMO) before :-) Literally ALL urls passed to _get_json()
are being stored and that includes more than just the URLs containing inventory data.
That being said, I believe this method should not be concerned with storing its results in the "global" cache. Some other method on a higher level should be doing that.
One other point worth of mention is the make_unsafe()
. I am not familiar with the semantics of this and I can only make inferences based on the name, but if this data is unsafe in anyway, why is a raw copy of it being stored unchecked in the cache for global consumption? Shouldn't it be marked unsafe as well?
I won't be able to produce a better design at short notice, but I would definitely like to take a look at that later on.
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.
Yes, that's a different story :) The thing is that that's harder to change, since it is a breaking change (in the sense that existing caches will stop working and we need to make sure that the plugin won't produce garbage out when finding a cache from an older version, or alternatively an older version finding a cache from a newer version). This is likely also something we should only merge for a new major release, just in case :)
As a general note, this could mean that the module this module is originally based on also needs some love to fix cache handling. As I (5 years ago already 😮) copied that module as a basis to build this one. I've opened an issue on the foreman repo, maybe @evgeni has a good idea about @russoz 's points :-) |
I did some digging in the changes made to the source module since the fork, these commits might be of interest/inspiration (by the sole virtue of having something to do with caching):
|
Thank you for your remarks. I agree, the solution may be called very cheap ;) but it is an effective bugfix without rewriting the plugin. The reference design forsees the steps:
This plugin bundled steps 1-3 "below" the A further unbundling of reading (cached) data from source and populating the inventory object requires some redesign. community.general/plugins/inventory/proxmox.py Lines 374 to 377 in 94e1511
I.e. a logic is required to a) dynamically read the (cached) data from source and b) dynamically populate the inventory object ps: the foreman plugin still suffers the same issue |
Backport to stable-9: 💚 backport PR created✅ Backport PR branch: Backported as #9769 🤖 @patchback |
Backport to stable-10: 💚 backport PR created✅ Backport PR branch: Backported as #9770 🤖 @patchback |
@iqt4 thanks for fixing this! |
Thanks @Thulium-Drake @iqt4 @felixfontein for the comments. As I wrote before I am interested in looking into that but when time allows it, which won't be soon. |
…nsible-collections#9760) * Proposal for ansible-collections#9710 * Fixed comments * Fixed trailing whitespace * Fixed changelog fragment
SUMMARY
Updated cache logic according to Anible's dynamic inventory description
Fixes #9710
bugfixes:
ISSUE TYPE
COMPONENT NAME
proxmox inventory
ADDITIONAL INFORMATION
Details see #9710