Skip to content

Commit

Permalink
(PUP-11899) Log which server we request a catalog from
Browse files Browse the repository at this point in the history
When a catalog is requested, log which server is attempted to be used and if an
IP address is resolvable display that.
  • Loading branch information
cthorn42 committed Oct 13, 2023
1 parent d835ef6 commit 44507e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/puppet/indirector/catalog/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def find(request)

session = Puppet.lookup(:http_session)
api = session.route_to(:puppet)

ip_address = begin
" (#{Resolv.new.getaddress(api.url.host)})"
rescue Resolv::ResolvError
nil
end
Puppet.notice("Requesting catalog from #{URI(api.url).host}:#{URI(api.url).port}#{ip_address}")

_, catalog = api.post_catalog(
request.key,
facts: request.options[:facts_for_catalog],
Expand Down
17 changes: 17 additions & 0 deletions spec/unit/indirector/catalog/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ def catalog_response(catalog)
expect(described_class.indirection.find(certname)).to be_a(Puppet::Resource::Catalog)
end

it 'logs a notice when requesting a catalog' do
expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140")

stub_request(:post, uri).to_return(**catalog_response(catalog))

described_class.indirection.find(certname)
end

it 'logs a notice when the IP address is resolvable when requesting a catalog' do
allow(Resolv).to receive_message_chain(:new, :getaddress).and_return('192.0.2.0')
expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140 (192.0.2.0)")

stub_request(:post, uri).to_return(**catalog_response(catalog))

described_class.indirection.find(certname)
end

it "serializes the environment" do
stub_request(:post, uri)
.with(query: hash_including('environment' => 'outerspace'))
Expand Down

0 comments on commit 44507e0

Please sign in to comment.