Skip to content

Add report for collecting Katello content facts#986

Merged
ehelms merged 3 commits intotheforeman:masterfrom
ianballou:initial-katello-analytics-fields
May 1, 2025
Merged

Add report for collecting Katello content facts#986
ehelms merged 3 commits intotheforeman:masterfrom
ianballou:initial-katello-analytics-fields

Conversation

@ianballou
Copy link
Copy Markdown
Contributor

@ianballou ianballou commented Feb 28, 2025

Begins Katello content fact collection for the analytics report. Starts with repository type information.

Example output:

[root@centos9-stream-katello-nightly foreman_maintain]# bin/foreman-maintain report generate | grep repositories
custom_library_yum_repositories_count: 1
redhat_library_yum_repositories_count: 1
library_debian_repositories_count: 1
library_container_repositories_count: 1
library_file_repositories_count: 1
library_python_repositories_count: 1
library_ansible_collection_repositories_count: 1
library_ostree_repositories_count: 1

Also adds some alternate content source fact collection:

[root@centos9-stream-katello-nightly foreman_maintain]# bin/foreman-maintain report generate | grep alternate
custom_alternate_content_sources_count: 2
simplified_alternate_content_sources_count: 1
rhui_alternate_content_sources_count: 1
yum_alternate_content_sources_count: 3
file_alternate_content_sources_count: 1

@ianballou ianballou force-pushed the initial-katello-analytics-fields branch 2 times, most recently from ccb9963 to 59cba93 Compare February 28, 2025 20:40
@ianballou
Copy link
Copy Markdown
Contributor Author

Edit: updated to have "count" at the ends of the data fields.

@ianballou ianballou force-pushed the initial-katello-analytics-fields branch from 59cba93 to 1064787 Compare February 28, 2025 20:44
@ianballou ianballou force-pushed the initial-katello-analytics-fields branch from 1064787 to 3ab3188 Compare March 14, 2025 15:23
@ianballou
Copy link
Copy Markdown
Contributor Author

Updated and still working:

---
custom_alternate_content_sources_count: 2
simplified_alternate_content_sources_count: 1
rhui_alternate_content_sources_count: 1
yum_alternate_content_sources_count: 3
file_alternate_content_sources_count: 1
custom_library_yum_repositories_count: 1
redhat_library_yum_repositories_count: 2
library_debian_repositories_count: 1
library_container_repositories_count: 1
library_file_repositories_count: 1
library_python_repositories_count: 1
library_ansible_collection_repositories_count: 1
library_ostree_repositories_count: 1

@ianballou ianballou force-pushed the initial-katello-analytics-fields branch from 3ab3188 to 53400a8 Compare March 14, 2025 16:18
@ianballou ianballou requested a review from adamruzicka March 17, 2025 17:45
Copy link
Copy Markdown
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Seems to work well, although it could be made a bit DRYer, but that might be just personal preference.

Comment on lines +40 to +50
query =
query(
<<-SQL
SELECT count(*) as yum_rh_count FROM "katello_root_repositories"
INNER JOIN "katello_products" ON "katello_products"."id" = "katello_root_repositories"."product_id"
INNER JOIN "katello_providers" ON "katello_providers"."id" = "katello_products"."provider_id"
WHERE "katello_providers"."provider_type" = 'Red Hat'
AND "katello_root_repositories"."content_type" = 'yum'
SQL
)
query.first['yum_rh_count'].to_i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: This could still be using the sql_count helper

Comment on lines +53 to +75
def library_container_repositories
sql_count("katello_root_repositories WHERE content_type = 'docker'")
end

def library_ostree_repositories
sql_count("katello_root_repositories WHERE content_type = 'ostree'")
end

def library_ansible_collection_repositories
sql_count("katello_root_repositories WHERE content_type = 'ansible_collection'")
end

def library_file_repositories
sql_count("katello_root_repositories WHERE content_type = 'file'")
end

def library_python_repositories
sql_count("katello_root_repositories WHERE content_type = 'python'")
end

def library_debian_repositories
sql_count("katello_root_repositories WHERE content_type = 'deb'")
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: While this works, it feels a bit repetitive

@ianballou
Copy link
Copy Markdown
Contributor Author

I can clean these ^ up a bit.

@ianballou
Copy link
Copy Markdown
Contributor Author

I've updated the content.rb file. It isn't tested yet.

Copy link
Copy Markdown
Contributor

@adamruzicka adamruzicka left a comment

Choose a reason for hiding this comment

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

Seems to work well, rubocop is unhappy though

Comment on lines +27 to +32
"katello_root_repositories"
WHERE "katello_root_repositories"."id" NOT IN
(SELECT "katello_root_repositories"."id" FROM "katello_root_repositories" INNER JOIN "katello_products"
ON "katello_products"."id" = "katello_root_repositories"."product_id" INNER JOIN "katello_providers"
ON "katello_providers"."id" = "katello_products"."provider_id" WHERE "katello_providers"."provider_type" = 'Red Hat')
AND "katello_root_repositories"."content_type" = 'yum'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason for going with a subquery directly joining all the necessary tables and then filtering out the rows we don't want to count?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I grabbed these queries directly from Katello & to_sql. Could be simplified perhaps.

@ianballou ianballou force-pushed the initial-katello-analytics-fields branch from a270a47 to 283d25c Compare April 16, 2025 19:26
@ehelms ehelms merged commit 39cc1d6 into theforeman:master May 1, 2025
8 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.

3 participants