Skip to content
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

Hits uploaded doesn't fail if system has no hits #942

Merged
merged 1 commit into from
Jan 22, 2025

Conversation

parthaa
Copy link
Collaborator

@parthaa parthaa commented Jan 22, 2025

So if the advisor engine did not have any hits for the host it would error saying no data passed for insert all. We need to handle it correctly and not try insert_all if hit values are empty.

@chris1984 chris1984 self-assigned this Jan 22, 2025
Copy link
Member

@chris1984 chris1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, works great

Before patch:

14:36:16 rails.1   | 2025-01-22T14:36:16 [I|app|80c611b0] Processing by Api::V2::AdvisorEngine::AdvisorEngineController#upload_hits as JSON
14:36:16 rails.1   | 2025-01-22T14:36:16 [I|app|80c611b0]   Parameters: {"host_name"=>"ip-10-0-168-112.rhos-01.prod.psi.rdu2.redhat.com", "host_uuid"=>"64a7d0d5-d4ad-4a08-bb0f-a002e67ca265", "payload"=>"[FILTERED]", "apiv"=>"v2", "advisor_engine"=>{"host_name"=>"ip-10-0-168-112.rhos-01.prod.psi.rdu2.redhat.com", "host_uuid"=>"64a7d0d5-d4ad-4a08-bb0f-a002e67ca265", "payload"=>"[FILTERED]"}}
14:36:16 rails.1   | 2025-01-22T14:36:16 [W|app|80c611b0] Action failed
14:36:16 rails.1   | 2025-01-22T14:36:16 [I|app|80c611b0] Backtrace for 'Action failed' error (ArgumentError): Empty list of attributes passed
14:36:16 rails.1   |  80c611b0 | /home/vagrant/foreman/.vendor/ruby/3.0.0/gems/activerecord-7.0.8.7/lib/active_record/insert_all.rb:11:in `initialize'
14:36:16 rails.1   |  80c611b0 | /home/vagrant/foreman/.vendor/ruby/3.0.0/gems/activerecord-7.0.8.7/lib/active_record/persistence.rb:146:in `new'
14:36:16 rails.1   |  80c611b0 | /home/vagrant/foreman/.vendor/ruby/3.0.0/gems/activerecord-7.0.8.7/lib/active_record/persistence.rb:146:in `insert_all'
14:36:16 rails.1   |  80c611b0 | (eval):6:in `block in insert_all'

Engine:

Traceback (most recent call last):
  File "/opt/app-root/src/insights_engine/foreman.py", line 53, in store_advisor_hits
    api.resource_action('advisor_engine', 'upload_hits', params=data)
  File "/opt/app-root/lib64/python3.12/site-packages/apypie/foreman.py", line 96, in resource_action
    raise ForemanApiException.from_exception(exc, msg) from exc
apypie.foreman.ForemanApiException: Error while performing upload_hits on advisor_engine: 500 Server Error: Internal Server Error for url: https://ip-10-0-167-73.rhos-01.prod.psi.rdu2.redhat.com/api/advisor_engine/upload_hits - {'message': 'Empty list of attributes passed'}

With PR:

Engine has no tracebacks and Rails log shows:

15:28:23 rails.1   | 2025-01-22T15:28:23 [I|app|ae10f168] Started PATCH "/api/advisor_engine/upload_hits" for 10.0.167.73 at 2025-01-22 15:28:23 -0500
15:28:23 rails.1   | 2025-01-22T15:28:23 [I|app|ae10f168] Processing by Api::V2::AdvisorEngine::AdvisorEngineController#upload_hits as JSON
15:28:23 rails.1   | 2025-01-22T15:28:23 [I|app|ae10f168]   Parameters: {"host_name"=>"ip-10-0-168-112.rhos-01.prod.psi.rdu2.redhat.com", "host_uuid"=>"64a7d0d5-d4ad-4a08-bb0f-a002e67ca265", "payload"=>"[FILTERED]", "apiv"=>"v2", "advisor_engine"=>{"host_name"=>"ip-10-0-168-112.rhos-01.prod.psi.rdu2.redhat.com", "host_uuid"=>"64a7d0d5-d4ad-4a08-bb0f-a002e67ca265", "payload"=>"[FILTERED]"}}
15:28:23 rails.1   | 2025-01-22T15:28:23 [D|app|ae10f168] Body: {"action_status":"success"}
15:28:23 rails.1   | 2025-01-22T15:28:23 [I|app|ae10f168] Completed 200 OK in 22ms (Views: 0.2ms | ActiveRecord: 6.7ms | Allocations: 9155)
15:28:23 rails.1   |  ae10f168 |
15:28:23 rails.1   |  ae10f168 |

@chris1984 chris1984 added this to the Local Advisor Engine milestone Jan 22, 2025
@parthaa parthaa merged commit 4cec882 into theforeman:develop Jan 22, 2025
12 checks passed
@parthaa parthaa deleted the empty-params branch January 22, 2025 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants