Refs #39448 - improve performance on host index page#614
Conversation
23e1e82 to
dfeb396
Compare
|
I like the general idea, it has some other benefits over just being faster (like search finally working reliably). However this sort of deviates from the pattern we generally use for statuses and makes the whole thing much more prone to showing stale data. For example we don't refresh the status when a policy is assigned/unassigned to the host (or its hostgroup or its ancestors). So either we should keep building the values dynamically or make sure to refresh the sub-status whenever any change that could affect its value happens. |
In katello, like https://github.com/Katello/katello/blob/master/app/models/katello/errata_status.rb#L25 it is done the same way. Actually, the compliance_status need to be updated if there is a new report. If another policy is set, its "nice" that the status is set ASAP to "not compliant" but it become really meanigful, if there is a report including this policy. |
I was thinking in slightly different direction - if a host was incompliant with its policy and that policy was replaced with some other, I'd expect the status to turn green immediately, even if (or maybe better "because") it has no reports with the new policy |
|
So if you have a host and a report, which tells the host is compliant/incompliant and you change the assigned policy, you cannot know if it is still compliant/incompliant until a report is there. So from my point of view the status should be "unknown" (warning instead of ok/error) or even empty. Just to add the user-perspective without knowing what the code does. |
def37a7 to
25d666f
Compare
|
Another thought but not yet verified. The relevant? method checks for, if policies are set. Maybe we should instead check, if there is a report? maybe this is faster. |
During testing, we found out multiple issues so that the performance of the host index page is really bad. Before this commit, using '/api/hosts?include_permissions=false&search=' took about 1min 30seconds. Simply returning "false" for "relevant?" decreased the access to 6seconds. With this commit, we are back at 9seconds - which is acceptable hopefully. Replace call to ".to_status" with ".status" to use the already calculated value of the complianace report. host_has_hostgroup_policies? is pretty fast because it answers a yes/no question with a cheap EXISTS query instead of loading and deduplicating all applicable policies in Ruby. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
From looking at the PR, it seems correct. The whole idea is not to recalculate the status on the fly (which can get really expensive). |
adjusting the compliance status is done by , isn't it?I 'm currently again looking if it would be easily possible to set the status to inconclusive if policies are added/removed. Regarding backgroup job, without foreman-tasks this might be a challenge, too :) |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I have changed this to draft again. |
|
Did a very high-level pass on the inconclusive commit. Looks quite OK to me. We may be able to improve it a bit, but overall it's OK. |
can you let me know, what you want to improve?
I have tested it and it looks like this. From the performance perspecitve, its OK to reset the state.
=> this PR works! Additionally, I want to notice again, that its currently not possible on the new all-hosts page to set policies to hosts - only host group because the bulk actions on the new all hosts page to set / unset compliance policy for a host don't exist: Actually, for a plugin like "openscap" it would be super good to have a host details card in which it is possible to a) see which policies are set and b) set a host policy and c) see the compliance status and maybe link to last report - this wouldn't be that hard to implement.... |
| def reset_changed_assignment_hosts_to_inconclusive | ||
| host_ids = Array(@compliance_status_reset_host_ids).compact.uniq |
There was a problem hiding this comment.
This could be a getter-method:
| def reset_changed_assignment_hosts_to_inconclusive | |
| host_ids = Array(@compliance_status_reset_host_ids).compact.uniq | |
| def compliance_status_reset_host_ids | |
| Array(@compliance_status_reset_host_ids).compact.uniq | |
| end | |
| def reset_changed_assignment_hosts_to_inconclusive | |
| host_ids = compliance_status_reset_host_ids |
But as long as we only use the value once, it does not really make a difference.
During testing, we found out multiple issues so that the performance of the host index page is really bad.
Before this commit, using '/api/hosts?include_permissions=false&search=' took about 1min 30seconds. Simply returning "false" for "relevant?" decreased the access to 6seconds. With this commit, we are back at 9seconds - which is acceptable hopefully.
Replace call to ".to_status" with ".status" to use the already calculated value of the complianace report.
host_has_hostgroup_policies? is pretty fast because it answers a yes/no question with a cheap EXISTS query instead of loading and deduplicating all applicable policies in Ruby.