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

Add endpoint and rabl nodes for IoP #934

Merged
merged 6 commits into from
Jan 14, 2025

Conversation

jeremylenz
Copy link
Collaborator

@jeremylenz jeremylenz commented Dec 18, 2024

  1. Add a scoped_search field, insights_uuid, so you can search hosts by their Insights UUID.
  2. Add rabl nodes to the host list API response so you can see insights information. This included adding RABL infrastructure to foreman_rh_cloud, since it didn't use rabl previously.
  3. Add an alias for insights_facet so I stop going crazy 😄
  4. Add a new API endpoint, /api/v2/insights_advisor/host_details, which returns only Insights-related details about hosts.

image

@jeremylenz jeremylenz force-pushed the add-rabl-and-scoped-search branch from 3f71c20 to 1d61d10 Compare December 18, 2024 19:26
@jeremylenz jeremylenz force-pushed the add-rabl-and-scoped-search branch 5 times, most recently from 02a9d1b to d477dd1 Compare December 20, 2024 15:59
@jeremylenz jeremylenz force-pushed the add-rabl-and-scoped-search branch from d477dd1 to 3b30531 Compare December 20, 2024 16:54
@parthaa
Copy link
Collaborator

parthaa commented Dec 21, 2024

I like the rabl + api work. But looks like we can do with a simpler host details controller for the advisors engine. So recommending changes.

-        before_action :find_organization
-
+        api :GET, "insights_advisor/host_details", N_('fetch host details given insights uuid')
+        param :host_uuids, Array, required: true
         def host_details
-          @hosts = ::Host::Managed.search_for(params[:search] || "", :order => params[:order]).where(:organization_id => @organization.id).includes(:insights)
+          uuids = params.require(:host_uuids)
+          @hosts = ::Host.joins(:insights).where(:insights => {:uuid => uuids })
           respond_to do |format|
             format.json { render 'api/v2/insights_advisor/host_details' }
           end
         end

No need to search as I initially thought we would. I just pass in a list of uuids that only insights and katello knows about.

@jeremylenz
Copy link
Collaborator Author

@parthaa Thanks, updated!

@jeremylenz jeremylenz requested a review from parthaa December 23, 2024 15:22
@jeremylenz
Copy link
Collaborator Author

No need to search as I initially thought we would

I removed the search param from the controller. But didn't remove it from scoped_search since I don't see any harm in keeping it.

Co-authored-by: Partha Aji <parthaa@gmail.com>
@parthaa
Copy link
Collaborator

parthaa commented Jan 14, 2025

Works well

$ curl -uadmin:changeme "https://buku.paji.example.com/api/v2/advisor_engine/host_details?host_uuids[]=85606035-29da-46ea-8bfd-020ce68a7b38"|jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   637  100   637    0     0   2181      0 --:--:-- --:--:-- --:--:--  2174
[
  {
    "name": "another-rhel9.paji.example.com",
    "insights_uuid": "85606035-29da-46ea-8bfd-020ce68a7b38",
    "insights_hit_details": "{.....}"
  }

@parthaa
Copy link
Collaborator

parthaa commented Jan 14, 2025

[1] pry(main)> Host.last.insights
=> #<InsightsFacet:0x00007f8501644e38 id: 11, host_id: 6, uuid: "85606035-29da-46ea-8bfd-020ce68a7b38", hits_count: -39>
[2] pry(main)> Host.search_for("insights_uuid=85606035-29da-46ea-8bfd-020ce68a7b38")
=> [#<Host::Managed:0x00007f85015f1210
  id: 6,
  name: "another-rhel9.paji.example.com",
  last_compile: Thu, 09 Jan 2025 20:32:54.000000000 UTC +00:00,
  last_report: nil,
  updated_at: Thu, 09 Jan 2025 20:32:54.149480000 UTC +00:00,
  created_at: Sat, 21 Dec 2024 05:47:58.270068000 UTC +00:00,
  root_pass: nil,
  architecture_id: 1,
  operatingsystem_id: 2,
  ptable_id: nil,
  medium_id: nil,
  build: false,
  comment: "",
  disk: nil,
  installed_at: Sat, 21 Dec 2024 05:48:30.956451000 UTC +00:00,
  model_id: 1,
  hostgroup_id: nil,
  owner_id: 4,
  owner_type: "User",
  enabled: true,
  puppet_ca_proxy_id: nil,
  managed: false,
  use_image: nil,
  image_file: nil,
  uuid: nil,
  compute_resource_id: nil,
  puppet_proxy_id: nil,
  certname: nil,
  image_id: nil,
  organization_id: 1,
  location_id: 2,
  type: "Host::Managed",
  otp: nil,
  realm_id: nil,
  compute_profile_id: nil,
  provision_method: nil,
  grub_pass: nil,
  global_status: 2,
  lookup_value_matcher: "[FILTERED]",
  pxe_loader: nil,
  initiated_at: Sat, 21 Dec 2024 05:48:06.327761000 UTC +00:00,
  build_errors: nil,
  creator_id: 1>]
[3] pry(main)> 

@jeremylenz jeremylenz changed the title Add scoped search and rabl nodes for IoP Add endpoint and rabl nodes for IoP Jan 14, 2025
@jeremylenz jeremylenz merged commit dc80828 into theforeman:develop Jan 14, 2025
12 checks passed
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.

4 participants