Skip to content

Commit

Permalink
(PUP-11900) Notify when X-Puppet-Compiler-Name header found
Browse files Browse the repository at this point in the history
This change will emit a notice when http traffic from a puppetserver
sends the `X-Puppet-Compiler-Name` header; this should help for
debugging purposes when troubleshooting compilation issues and
several compilers are behind a load balancer.
  • Loading branch information
tvpartytonight committed Nov 14, 2023
1 parent 03b3df3 commit 9594c58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/puppet/http/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def process_response(response)
site = Puppet::HTTP::Site.from_uri(response.url)
@server_versions[site] = version
end
if (compiler = response['X-Puppet-Compiler-Name'])
Puppet.notice("Catalog compiled by #{compiler}")
end
end

# Determine if a session supports a capability. Depending on the server version
Expand Down
13 changes: 13 additions & 0 deletions spec/integration/application/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def copy_fixtures(sources, dest)
end
end

context 'server identification' do
it 'emits a notice if the server sends the X-Puppet-Compiler-Name header' do
server.start_server do |port|
Puppet[:serverport] = port
expect {
agent.command_line.args << '--test'
agent.run
}.to exit_with(0)
.and output(%r{Notice: Catalog compiled by test-compiler-hostname}).to_stdout
end
end
end

context 'server_list' do
it "uses the first server in the list" do
Puppet[:server_list] = '127.0.0.1'
Expand Down
1 change: 1 addition & 0 deletions spec/lib/puppet_spec/puppetserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def do_GET request, response
class CatalogServlet < WEBrick::HTTPServlet::AbstractServlet
def do_POST request, response
response['Content-Type'] = 'application/json'
response['X-Puppet-Compiler-Name'] = 'test-compiler-hostname'
catalog = Puppet::Resource::Catalog.new(Puppet[:certname], 'production')
response.body = catalog.render(:json)
end
Expand Down
11 changes: 10 additions & 1 deletion spec/unit/http/session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

context 'when retrieving capabilities' do
let(:response) { Puppet::HTTP::Response.new(uri, 200, 'OK') }
let(:response) { Puppet::HTTP::ResponseNetHTTP.new(uri,
Net::HTTPResponse.new('http_version',
200,
"OK")) }

let(:session) do
resolver = DummyResolver.new(good_service)
Expand All @@ -244,6 +247,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "supports locales if the cached service's version is 5.3.4 or greater" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.3.4')

session.route_to(:puppet)
Expand All @@ -253,6 +257,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "does not support locales if the cached service's version is 5.3.3" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.3.3')

session.route_to(:puppet)
Expand All @@ -262,6 +267,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "does not support locales if the cached service's version is missing" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return(nil)

session.route_to(:puppet)
Expand All @@ -279,6 +285,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "supports json if the cached service's version is 5 or greater" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return('5.5.12')

session.route_to(:puppet)
Expand All @@ -288,6 +295,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "does not support json if the cached service's version is less than 5.0" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return('4.10.1')

session.route_to(:puppet)
Expand All @@ -297,6 +305,7 @@ def resolve(session, name, ssl_context: nil, canceled_handler: nil)
end

it "supports json if the cached service's version is missing" do
allow(response).to receive(:[]).and_call_original
allow(response).to receive(:[]).with('X-Puppet-Version').and_return(nil)

session.route_to(:puppet)
Expand Down

0 comments on commit 9594c58

Please sign in to comment.