Skip to content

Commit 2ffeb2e

Browse files
committed
(maint) Add full catalog benchmark
1 parent fad5336 commit 2ffeb2e

9 files changed

+155
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "benchmarks/full_catalog/puppetlabs-puppetserver_perf_control"]
2+
path = benchmarks/full_catalog/puppetlabs-puppetserver_perf_control
3+
url = https://github.com/puppetlabs/puppetlabs-puppetserver_perf_control

benchmarks/full_catalog/Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source ENV['GEM_SOURCE'] || "https://rubygems.org"
2+
3+
gem "r10k", '~> 2.6'
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
require 'erb'
2+
require 'ostruct'
3+
require 'fileutils'
4+
require 'json'
5+
require 'bundler'
6+
7+
class Benchmarker
8+
include FileUtils
9+
10+
def initialize(target, size='medium')
11+
@target = target
12+
@size = 'large'
13+
end
14+
15+
def check_submodule
16+
submodule = File.join('benchmarks', 'full_catalog', 'puppetlabs-puppetserver_perf_control')
17+
unless File.exist?(File.join(submodule, 'Puppetfile'))
18+
raise RuntimeError, 'The perf control repo is not readable. Make sure to initialize submodules by running: git submodule update --init --recursive'
19+
end
20+
end
21+
22+
def setup
23+
require 'puppet'
24+
config = File.join(@target, 'puppet.conf')
25+
environment = File.join(@target, 'environments', 'perf_control')
26+
Puppet.initialize_settings(['--config', config])
27+
FileUtils.cd(@target) do
28+
Bundler::with_clean_env do
29+
system("bundle install")
30+
system("bundle exec r10k puppetfile install --puppetfile #{File.join(environment, 'Puppetfile')} --moduledir #{File.join(environment, 'modules')} --config r10k.yaml")
31+
end
32+
end
33+
34+
# Loading the base system affects the first run a lot so burn one run here
35+
run
36+
end
37+
38+
def run(args=nil)
39+
# Probably could pare down these facts a lot
40+
facts = Puppet::Node::Facts.new("testing", {
41+
'pe_concat_basedir' => '/tmp/file',
42+
'platform_symlink_writable' => true,
43+
'pe_build' => '2016.4.4',
44+
'identity' => {
45+
'privileged' => true,
46+
},
47+
'mountpoints' => {
48+
'/tmp' => {
49+
'options' => ['rw'],
50+
}
51+
},
52+
'puppet_files_dir_present' => true,
53+
'puppetversion' => '4.10.4',
54+
'aio_agent_version' => '1.10.4',
55+
'aio_agent_build' => '1.10.4',
56+
'memory' => {
57+
'system' => {
58+
'total_bytes' => 8589934592,
59+
}
60+
},
61+
'memorysize' => '8 GiB',
62+
'osfamily' => 'RedHat',
63+
'operatingsystem' => 'CentOS',
64+
'operatingsystemrelease' => '6.8',
65+
'processorcount' => '2',
66+
'fake_domain' => 'pgtomcat.mycompany.org',
67+
'function' => 'app',
68+
'group' => 'pgtomcat',
69+
'stage' => 'prod',
70+
'whereami' => 'portland',
71+
'hostname' => 'pgtomcat',
72+
'fqdn' => 'pgtomcat.mycompany.org',
73+
'lsbdistcodename' => 'n/a',
74+
'processor0' => 'AMD Ryzen 7 1700 Eight-Core Processor',
75+
})
76+
77+
env = Puppet.lookup(:environments).get('perf_control')
78+
node = Puppet::Node.indirection.find("testing", :environment => env, :facts => facts)
79+
80+
Puppet.push_context({:current_environment => env}, 'current env for benchmark')
81+
Puppet::Resource::Catalog.indirection.find("testing", :use_node => node)
82+
Puppet.pop_context
83+
Puppet.lookup(:environments).clear('perf_control')
84+
end
85+
86+
def generate
87+
check_submodule
88+
templates = File.join('benchmarks', 'full_catalog')
89+
source = File.join(templates, "puppetlabs-puppetserver_perf_control")
90+
environment = File.join(@target, 'environments', 'perf_control')
91+
mkdir_p(File.join(@target, 'environments'))
92+
FileUtils.cp_r(source, environment)
93+
94+
render(File.join(templates, 'puppet.conf.erb'),
95+
File.join(@target, 'puppet.conf'),
96+
:codedir => File.join(@target, 'environments'),
97+
:target => @target)
98+
99+
render(File.join(templates, 'site.pp.erb'),
100+
File.join(environment, 'manifests', 'site.pp'),
101+
:size => @size)
102+
103+
render(File.join(templates, 'hiera.yaml.erb'),
104+
File.join(@target, 'hiera.yaml'),
105+
:datadir => File.join(environment, 'hieradata'))
106+
107+
FileUtils.cp(File.join(templates, 'Gemfile'), @target)
108+
FileUtils.cp(File.join(templates, 'r10k.yaml'), @target)
109+
end
110+
111+
def render(erb_file, output_file, bindings)
112+
site = ERB.new(File.read(erb_file))
113+
File.open(output_file, 'w') do |fh|
114+
fh.write(site.result(OpenStruct.new(bindings).instance_eval { binding }))
115+
end
116+
end
117+
end

benchmarks/full_catalog/description

Whitespace-only changes.
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
:backends:
3+
- yaml
4+
:yaml:
5+
:datadir: "<%= datadir %>"
6+
:hierarchy:
7+
# This hierarchy is based on the one from the puppetlabs ops team.
8+
- "vagrant/%{is_vagrant}"
9+
- "nodes/%{fake_domain}/%{fqdn}"
10+
- "nodes/%{fake_domain}/%{hostname}"
11+
- "domains/%{fake_domain}/groups/%{group}"
12+
- "domains/%{fake_domain}/stages/%{stage}"
13+
- "domains/%{fake_domain}"
14+
- "groups/%{group}/%{function}/%{stage}"
15+
- "groups/%{group}/%{function}"
16+
- "groups/%{group}/%{whereami}/%{stage}"
17+
- "groups/%{group}/%{stage}"
18+
- "groups/%{group}"
19+
- "location/%{whereami}/%{stage}"
20+
- "location/%{whereami}"
21+
- "os/%{osfamily}/%{lsbdistcodename}"
22+
- "os/%{osfamily}"
23+
- "modules/%{module_name}"
24+
- "stages/%{stage}"
25+
- "common"
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
environmentpath = <%= codedir %>
2+
confdir = <%= target %>

benchmarks/full_catalog/r10k.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:cachedir: '/tmp/full_catalog_r10k_cache'

benchmarks/full_catalog/site.pp.erb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node 'default' {
2+
include ::role::by_size::<%= size %>
3+
}

0 commit comments

Comments
 (0)