-
Notifications
You must be signed in to change notification settings - Fork 50
Generate single-host reports without shell commands or rake task #1102
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
Generate single-host reports without shell commands or rake task #1102
Conversation
Reviewer's GuideRefactor host-specific report workflow to eliminate shell commands and rake tasks by introducing a dedicated asynchronous pipeline (SingleHostReportJob and GenerateSingleHostReport) for single-host reports, plus add a fallback in the slice generator for missing pulp URLs. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `lib/foreman_inventory_upload/async/generate_single_host_report.rb:10-12` </location>
<code_context>
+ filter: filter,
+ )
+ input[:target] = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(input[:organization_id], input[:filter]))
+ archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(input[:target])
+ archived_report_generator.render(organization: input[:organization_id], filter: input[:filter])
+ end
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider error handling for file creation and report generation.
Currently, exceptions from file creation or report generation are not handled. Please add error handling or logging to address possible failures.
```suggestion
begin
input[:target] = File.join(base_folder, ForemanInventoryUpload.facts_archive_name(input[:organization_id], input[:filter]))
archived_report_generator = ForemanInventoryUpload::Generators::ArchivedReport.new(input[:target])
archived_report_generator.render(organization: input[:organization_id], filter: input[:filter])
rescue => e
Rails.logger.error("Failed to generate archived report for organization #{input[:organization_id]}: #{e.message}\n#{e.backtrace.join("\n")}")
output[:error] = "Report generation failed: #{e.message}"
raise
end
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
3e76695 to
6ba56e7
Compare
|
@adamruzicka I can't tag you for review, but have a look :) |
|
I didn't realize that |
|
I do like the approach here. My only issue is we cant see the Shell output in Administer -> Inventory Upload (which is not a big deal imo). |
|
where are you accounting for this logic Added by 15f9c55 |
|
Also I dont like duplicating the logic for both rake and actions. Can you dry that part up. For example you can have this part of the logic common to both your action ad the rake task foreman_rh_cloud/lib/tasks/rh_cloud_inventory.rake Lines 43 to 65 in 6ba56e7
|
adamruzicka
left a comment
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.
Definitely a step in the right direction
I didn't realize that
QueueForUploadJobcallsUploadReportJobwhich also uses ShellProcess and uploads via uploader.sh. I'll have to think about what to do about that.
Ideally yes. Firing up a shell with curl is a relatively cheap thing to do, so I wouldn't expect any major performance gains, but it would be the more correct thing to do.
Seems I misread that |
Agree, let's do the upload in a followup. |
8f99ef9 to
b0c6358
Compare
ShimShtein
left a comment
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.
As a concept I like it. There are small changes that will make it a bit more adapted to the foreman tasks paradigm, but in general it looks good.
lib/foreman_inventory_upload/async/create_missing_insights_facets.rb
Outdated
Show resolved
Hide resolved
|
@adamruzicka @parthaa @ShimShtein Updated 👍 |
|
basically 'rh_cloud_inventory::generate' was never meant to upload (it was to only generate). So my suggested patch $ git diff
diff --git a/lib/foreman_inventory_upload/async/host_inventory_report_job.rb b/lib/foreman_inventory_upload/async/host_inventory_report_job.rb
index c4cb9e9..d6bd97f 100644
--- a/lib/foreman_inventory_upload/async/host_inventory_report_job.rb
+++ b/lib/foreman_inventory_upload/async/host_inventory_report_job.rb
@@ -1,7 +1,7 @@
module ForemanInventoryUpload
module Async
class HostInventoryReportJob < ::Actions::EntryAction
- def plan(base_folder, organization_id, hosts_filter = "")
+ def plan(base_folder, organization_id, hosts_filter = "", upload = true)
sequence do
plan_action(
GenerateHostReport,
@@ -10,12 +10,14 @@ module ForemanInventoryUpload
hosts_filter
)
- plan_action(
- QueueForUploadJob,
- base_folder,
- ForemanInventoryUpload.facts_archive_name(organization_id, hosts_filter),
- organization_id
- )
+ if upload
+ plan_action(
+ QueueForUploadJob,
+ base_folder,
+ ForemanInventoryUpload.facts_archive_name(organization_id, hosts_filter),
+ organization_id
+ )
+ end
if ForemanRhCloud.with_iop_smart_proxy?
plan_action(
diff --git a/lib/tasks/rh_cloud_inventory.rake b/lib/tasks/rh_cloud_inventory.rake
index 212d31f..b3bb10c 100644
--- a/lib/tasks/rh_cloud_inventory.rake
+++ b/lib/tasks/rh_cloud_inventory.rake
@@ -45,7 +45,8 @@ namespace :rh_cloud_inventory do
ForemanInventoryUpload::Async::HostInventoryReportJob,
base_folder,
organization_id,
- filter
+ filter,
+ false
)
end
puts "Check the Uploading tab for report uploading status." if Setting[:subscription_connection_enabled] |
adef572 to
b904b0f
Compare
|
updated & squashed |
|
One more suggested patch. I hit some errors when testing the rake rh_cloud_inventory calls (not connected to changes in this PR but related to IoP in the same file.) diff --git a/lib/foreman_inventory_upload/async/generate_report_job.rb b/lib/foreman_inventory_upload/async/generate_report_job.rb
index 86bf91f..c474415 100644
--- a/lib/foreman_inventory_upload/async/generate_report_job.rb
+++ b/lib/foreman_inventory_upload/async/generate_report_job.rb
@@ -5,7 +5,7 @@ module ForemanInventoryUpload
"report_for_#{label}"
end
- def plan(base_folder, organization_id, disconnected, hosts_filter = nil)
+ def plan(base_folder, organization_id, disconnected = false, hosts_filter = nil)
sequence do
super(
GenerateReportJob.output_label("#{organization_id}#{hosts_filter.empty? ? nil : "[#{hosts_filter.to_s.parameterize}]"}"),
diff --git a/lib/tasks/rh_cloud_inventory.rake b/lib/tasks/rh_cloud_inventory.rake
index 616001d..41bc1fc 100644
--- a/lib/tasks/rh_cloud_inventory.rake
+++ b/lib/tasks/rh_cloud_inventory.rake
@@ -9,14 +9,12 @@ namespace :rh_cloud_inventory do
else
organizations = [Organization.where(:id => ENV['organization_id']).first]
end
- disconnected = ForemanRhCloud.with_iop_smart_proxy?
User.as_anonymous_admin do
organizations.each do |organization|
ForemanTasks.async_task(
ForemanInventoryUpload::Async::GenerateReportJob,
ForemanInventoryUpload.generated_reports_folder,
- organization.id,
- disconnected
+ organization.id
)
puts "Generated and uploaded inventory report for organization '#{organization.name}'"
end
@@ -57,8 +55,7 @@ namespace :rh_cloud_inventory do
base_folder = ENV['target'] || ForemanInventoryUpload.generated_reports_folder
organization_id = ENV['organization_id']
report_file = ForemanInventoryUpload.facts_archive_name(organization_id)
- disconnected = ForemanRhCloud.with_iop_smart_proxy?
- ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id, disconnected)
+ ForemanTasks.sync_task(ForemanInventoryUpload::Async::QueueForUploadJob, base_folder, report_file, organization_id)
puts "Uploaded #{report_file}"
end
end |
b904b0f to
eb1aa4f
Compare
|
updated |
eb1aa4f to
99281a2
Compare
|
I 'd like tests for some of these changes in a follow up PR. I am happy with the current state from my testing. I tested
Going to approve. Please add tests in a follow up. |
|
🍏 |
(cherry picked from commit 596699a)
What are the changes introduced in this pull request?
As part of the IoP Vulnerability service, package profile upload triggers a single-host inventory report upload. Previously this was accomplished the same way as other inventory reports, meaning it was run in a shell process which ran a rake task, and report generation output was captured for display in the web UI. However, with hundreds or thousands of hosts it seems this caused large performance bottlenecks.
This change removes some of that overhead by extracting the report generation to a new Dynflow task and running it directly. This means no shell process and no rake task, hopefully eliminating that bloat and improving performance.
Considerations taken when implementing this change?
Both this and BulkGenerateApplicability are triggered by package profile upload and can run concurrently. But since inventory reports only require an updated package profile and not updated applicability calculation, I think this is fine.
I had to fix a line in slice.rb since my host didn't have a content source
What are the testing steps for this pull request?
yum -y upgrade jq or yum -y downgrade jq
Watch Foreman logs and verify that
ForemanInventoryUpload::Async::SingleHostReportJobcompletes with successInspect Dynflow console inputs and outputs and make sure everything looks ok
Extract the report tar and make sure it looks ok.
Summary by Sourcery
Support generating single-host inventory reports via a new async job pipeline, replace shell/rake-based approach, and improve yum repo URL handling.
New Features:
Enhancements: