From 9ab5e8711ef2963ea6152590bd18c5b03ca2bcb8 Mon Sep 17 00:00:00 2001 From: Christopher Thorn Date: Thu, 12 Oct 2023 07:45:16 -0700 Subject: [PATCH] (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. --- lib/puppet/indirector/catalog/rest.rb | 8 ++++++++ spec/unit/indirector/catalog/rest_spec.rb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/puppet/indirector/catalog/rest.rb b/lib/puppet/indirector/catalog/rest.rb index f246d2eccc9..1766a0180e6 100644 --- a/lib/puppet/indirector/catalog/rest.rb +++ b/lib/puppet/indirector/catalog/rest.rb @@ -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], diff --git a/spec/unit/indirector/catalog/rest_spec.rb b/spec/unit/indirector/catalog/rest_spec.rb index 4f2730b13f6..a0b917857e3 100644 --- a/spec/unit/indirector/catalog/rest_spec.rb +++ b/spec/unit/indirector/catalog/rest_spec.rb @@ -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('145.120.120.0') + expect(Puppet).to receive(:notice).with("Requesting catalog from compiler.example.com:8140 (145.120.120.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'))