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

Do not query for the exact facter version #151

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

ekohl
Copy link
Member

@ekohl ekohl commented Jul 5, 2023

This assumes that no exact match can be found in most cases. This saves a call to FacterDB. Some testing on puppet-nginx this reduced the time for a dry run by about 1 to 2 seconds, from about ~11 to ~9 seconds.

Implementation wise this switches to using Gem::Requirement to detect matching versions. This means you can also specify ~> 3.8 as a valid facterversion, or >= 3 < 5.

This is a reworked version of a patch in #124 that focuses on only reworking the facterversion selection.

There are some implementation differences that can be considered backwards incompatible. Right now this is not ready to be merged, but we should talk about what is desired. Please see the test cases and their diffs for how the behavior will change.

@ekohl ekohl mentioned this pull request Jul 5, 2023
@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.30 🎉

Comparison is base (8d9370c) 94.93% compared to head (2596ab7) 95.23%.

❗ Current head 2596ab7 differs from pull request most recent head d690765. Consider uploading reports for the commit d690765 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #151      +/-   ##
==========================================
+ Coverage   94.93%   95.23%   +0.30%     
==========================================
  Files           2        2              
  Lines         158      168      +10     
==========================================
+ Hits          150      160      +10     
  Misses          8        8              
Impacted Files Coverage Δ
lib/rspec-puppet-facts.rb 98.15% <100.00%> (+0.12%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

spec/rspec_puppet_facts_spec.rb Outdated Show resolved Hide resolved
This assumes that no exact match can be found in most cases. This saves
a call to FacterDB. Some testing on puppet-nginx this reduced the time
for a dry run by about 1 to 2 seconds, from about ~11 to ~9 seconds.

Implementation wise this switches to using Gem::Requirement to detect
matching versions. This means you can also specify `~> 3.8` as a valid
facterversion, or `>= 3 < 5`.
Comment on lines +367 to +368
# Interpret 3 as ~> 3.0
"~> #{version}.0"
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 isn't = #{version} because 3.3 should allow 3.3.1.

@ekohl
Copy link
Member Author

ekohl commented Jul 7, 2023

For me it does produce more warnings. Without the patch:

No facts were found in the FacterDB for Facter v4.2.8 on {:operatingsystem=>"RedHat", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead
No facts were found in the FacterDB for Facter v4.2.8 on {:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead
No facts were found in the FacterDB for Facter v4.2.8 on {:operatingsystem=>"Scientific", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead

With the patch:

No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"RedHat", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"RedHat", :operatingsystemrelease=>"/^7/", :hardwaremodel=>"x86_64"}, using v4.2.13 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"RedHat", :operatingsystemrelease=>"/^8/", :hardwaremodel=>"x86_64"}, using v4.2.13 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^7/", :hardwaremodel=>"x86_64"}, using v4.2.2 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"CentOS", :operatingsystemrelease=>"/^8/", :hardwaremodel=>"x86_64"}, using v4.2.2 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Scientific", :operatingsystemrelease=>"/^6/", :hardwaremodel=>"x86_64"}, using v3.14.1 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Scientific", :operatingsystemrelease=>"/^7/", :hardwaremodel=>"x86_64"}, using v4.2.2 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Debian", :operatingsystemrelease=>"/^9/", :hardwaremodel=>"x86_64"}, using v4.2.2 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Debian", :operatingsystemrelease=>"/^10/", :hardwaremodel=>"x86_64"}, using v4.2.2 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Ubuntu", :operatingsystemrelease=>"/^16\\.04/", :hardwaremodel=>"x86_64"}, using v4.2.5 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Ubuntu", :operatingsystemrelease=>"/^18\\.04/", :hardwaremodel=>"x86_64"}, using v4.2.5 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"FreeBSD", :operatingsystemrelease=>"/^11/", :hardwaremodel=>"amd64"}, using v4.2.1 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"FreeBSD", :operatingsystemrelease=>"/^12/", :hardwaremodel=>"amd64"}, using v4.2.4 instead
No facts were found in the FacterDB for Facter v4.2.11 on {:operatingsystem=>"Archlinux", :hardwaremodel=>"x86_64"}, using v4.2.9 instead

You could argue it's more correct that if you specify 4.2.11 that you should also get 4.2.11 facts.

Overall the (very unscientific) performance difference is:

Finished in 2.01 seconds (files took 10.32 seconds to load)

vs:

Finished in 1.55 seconds (files took 8.34 seconds to load)

So about 2 seconds or about 20% faster. #152 shaves off another 2 seconds and brings it down to 6.

@ekohl
Copy link
Member Author

ekohl commented Jul 14, 2023

I'd like to see this merged. Should I merge it myself?

I wonder if this qualifies as backwards-incompatible or not. I think it isn't, though it generates more warnings. How strict should the warnings be? It looks to me that 4.2.11 != 4.2.9, but on the other hand: that's probably ok.

@bastelfreak
Copy link
Member

I like the 'better safe than sorry' and suggest to merge this as backwards-incompatible. Then people won't pull it in automatically.

@ekohl ekohl merged commit 1c8a717 into voxpupuli:master Jul 20, 2023
@ekohl ekohl deleted the rework-facterversion branch July 20, 2023 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants