Skip to content

Commit 71c7cd2

Browse files
committed
(PUP-11899) Log which server we request a catalog from
When a catalog is requested, log which server is attempted to be used and if an IP address is resolvable display that.
1 parent d835ef6 commit 71c7cd2

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/puppet/indirector/catalog/rest.rb

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ def find(request)
1313

1414
session = Puppet.lookup(:http_session)
1515
api = session.route_to(:puppet)
16+
17+
ip_address = begin
18+
" (#{Resolv.getaddress(api.url.host)})"
19+
rescue Resolv::ResolvError
20+
nil
21+
end
22+
Puppet.notice("Requesting catalog from #{api.url.host}:#{api.url.port}#{ip_address}")
23+
1624
_, catalog = api.post_catalog(
1725
request.key,
1826
facts: request.options[:facts_for_catalog],

spec/unit/indirector/catalog/rest_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ def catalog_response(catalog)
2525
expect(described_class.indirection.find(certname)).to be_a(Puppet::Resource::Catalog)
2626
end
2727

28+
it 'logs a notice when requesting a catalog' do
29+
expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140")
30+
31+
stub_request(:post, uri).to_return(**catalog_response(catalog))
32+
33+
described_class.indirection.find(certname)
34+
end
35+
36+
it 'logs a notice when the IP address is resolvable when requesting a catalog' do
37+
allow(Resolv).to receive_message_chain(:getaddress).and_return('192.0.2.0')
38+
expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140 (192.0.2.0)")
39+
40+
stub_request(:post, uri).to_return(**catalog_response(catalog))
41+
42+
described_class.indirection.find(certname)
43+
end
44+
2845
it "serializes the environment" do
2946
stub_request(:post, uri)
3047
.with(query: hash_including('environment' => 'outerspace'))

0 commit comments

Comments
 (0)