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

Fixes #37888 - add host bootc information to API #11175

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

ianballou
Copy link
Member

@ianballou ianballou commented Oct 8, 2024

What are the changes introduced in this pull request?

  • Adds bootc image + digest string fields for booted, available, staged, and rollback images.
  • Adds this information to the hosts API under content_facet_attributes
  • Also adds a shortcut to check if a host is an image mode host.

Considerations taken when implementing this change?

  • The naming -- this is the first time "image mode" and "bootc" will appear in our code, so let's make sure we're happy with that.
  • I don't think we need to get into the business of validating that the image looks like a container image path, it would be a complicated check:
    • chatgpt says ^(?:[a-zA-Z0-9.-]+(?::[0-9]+)?/)?([a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*(?::[a-zA-Z0-9._-]+)?(?:@[A-Fa-f0-9]+:[A-Fa-f0-9]{64})?$
    • This is due to the number of optional add-ons that a tag can have, like a full digest, tag, etc.
    • However, we can at least check that the digest looks like a digest.

What are the testing steps for this pull request?

  • Run the migrations
  • Register a host
  • Check that the API values make sense
  • Add some dummy data to the new records
  • Check that the values still make sense.
  • Test that scoped searching works and is autocompleted for the bootc facts and "image_mode" (boolean).

Comment on lines +93 to +95
def image_mode_host?
bootc_booted_image.present?
end
Copy link
Member

Choose a reason for hiding this comment

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

May also think about adding this to scoped_search in host_managed_extensions. I would want to be able to see a list of all my image-mode hosts.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added!

@ianballou
Copy link
Member Author

ianballou commented Oct 10, 2024

I'm thinking the bootc facts should be removed from the content facet and put on the host itself instead. The content facet is more useful for connecting Katello content to hosts. However, the bootc facts are 'physical' facts about the machine, like installed packages. We associate installed packages directly to the host. The bootc facts might be different from content that is synced in Katello.

Edit: I realized for attributes like installed packages, the connection to host is through a joins table, so the table didn't need to be edited directly. Turns out we don't have precedent for altering the hosts table from Katello, so a facet is likely a better alternative.

@ianballou
Copy link
Member Author

ianballou commented Oct 10, 2024

I'm going to also add autocompleted searching on the images and their digests to help users filter image mode hosts.
Looks like ContentFacetHostExtensions might be the answer to solving this.

@sjha4
Copy link
Member

sjha4 commented Oct 10, 2024

Might be out of scope for this PR but we are still planning to add the relational models to tie host to katello managed manifest/list based on the stored digest, right?

@ianballou
Copy link
Member Author

Might be out of scope for this PR but we are still planning to add the relational models to tie host to katello managed manifest/list based on the stored digest, right?

Yes, I was thinking we'd do that when we implement fact fetching from sub-man.

@ianballou
Copy link
Member Author

I pushed an update that gets autocomplete working with the image_mode scoped_search. I also added searching for the other bootc fact fields.

@ianballou ianballou force-pushed the 37888-bootc-facts-api branch 2 times, most recently from 4f67f3e to cf5650a Compare October 10, 2024 20:56
@ianballou
Copy link
Member Author

TODO: Test performance querying all bootc_booted_image + bootc_booted_digest and making the list unique for ~50K hosts.

if hosts.empty?
{ :conditions => "1=0" }
else
{ :conditions => "#{::Host::Managed.table_name}.id IN (#{hosts.pluck(:id).join(',')})" }
Copy link
Member Author

Choose a reason for hiding this comment

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

This needs to be fixed, the plucking of the ID is unnecessary and slow. It also introduces duplicate problems in the IN condition.

@ianballou
Copy link
Member Author

ianballou commented Oct 31, 2024

TODO: Test performance querying all bootc_booted_image + bootc_booted_digest and making the list unique for ~50K hosts.

It was taking too long to register that many hosts, so I stuck to 6574 hosts with content facets.

Query results:

[7] pry(main)> Benchmark.measure do
[7] pry(main)*   ::Katello::Host::ContentFacet.where.not(bootc_booted_image: nil).select(:bootc_booted_image, :bootc_booted_digest).distinct.pluck(:bootc_booted_image, :bootc_booted_digest)
[7] pry(main)* end  
=> #<Benchmark::Tms:0x00007f91beaa6a20
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=0.02300092700170353,
 @stime=0.0,
 @total=0.009263999999999939,
 @utime=0.009263999999999939>

[9] pry(main)> ::Katello::Host::ContentFacet.count
=> 6574

Results when making a potential hash for the image mode images page:

[79] pry(main)> 
Benchmark.measure do
  results = ::Katello::Host::ContentFacet.select(:bootc_booted_image, :bootc_booted_digest, 'COUNT(hosts.id) as host_count').joins(:host).group(:bootc_booted_image, :bootc_booted_digest)
  image_mode_map = Hash.new { |h,k| h[k] = [] }
  results.each do |host_image|
    image_mode_map[host_image.bootc_booted_image] << { bootc_booted_digest: host_image.bootc_booted_digest, host_count: host_image.host_count.to_i  }
  end
end
=> #<Benchmark::Tms:0x00007f91b8716140
 @cstime=0.0,
 @cutime=0.0,
 @label="",
 @real=0.022486373025458306,
 @stime=0.0,
 @total=0.013446000000000069,
 @utime=0.013446000000000069>

Copy link
Member

@sjha4 sjha4 left a comment

Choose a reason for hiding this comment

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

Ack..The setup looks good..Able to see the new fields on the model and API correctly. Merge it.. :shipit:

@ianballou
Copy link
Member Author

I realized I have one small todo -- we need to add something to the host index API view for bootc. Either a "image mode" true/false or the image information itself.

@ianballou
Copy link
Member Author

Todo is done, I added the full values. We may want to display some more of that eventually I suppose. Let me know if you think otherwise.

Copy link
Member

@sjha4 sjha4 left a comment

Choose a reason for hiding this comment

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

Ack * 2 🎉

@ianballou ianballou merged commit db89c59 into Katello:master Nov 5, 2024
26 of 27 checks passed
@ianballou ianballou deleted the 37888-bootc-facts-api branch November 5, 2024 16:32
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.

3 participants