Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Use GET /health for DNS SRV availability checks (#36300)

Rafael dos Santos Silva5ba7d279f9d8
diff --git a/plugins/discourse-ai/lib/utils/dns_srv.rb b/plugins/discourse-ai/lib/utils/dns_srv.rb
index 502d68d9bca..ae9eafb249e 100644
--- a/plugins/discourse-ai/lib/utils/dns_srv.rb
+++ b/plugins/discourse-ai/lib/utils/dns_srv.rb
@@ -41,8 +41,8 @@ module DiscourseAi
def self.server_available?(server)
begin
conn = Faraday.new { |f| f.adapter FinalDestination::FaradayAdapter }
- conn.head("https://#{server.target}:#{server.port}")
- true
+ response = conn.get("https://#{server.target}:#{server.port}/health")
+ response.success?
rescue StandardError
false
end
diff --git a/plugins/discourse-ai/spec/lib/utils/dns_srv_spec.rb b/plugins/discourse-ai/spec/lib/utils/dns_srv_spec.rb
index 7b58ad092c6..60238139460 100644
--- a/plugins/discourse-ai/spec/lib/utils/dns_srv_spec.rb
+++ b/plugins/discourse-ai/spec/lib/utils/dns_srv_spec.rb
@@ -21,7 +21,7 @@ describe DiscourseAi::Utils::DnsSrv do
Discourse.cache.delete("dns_srv_lookup:#{domain}")
(1..5).each do |i|
- stub_request(:head, "https://service#{i}.example.com/").to_return(status: 200)
+ stub_request(:get, "https://service#{i}.example.com/health").to_return(status: 200)
end
end
@@ -44,10 +44,10 @@ describe DiscourseAi::Utils::DnsSrv do
Discourse.cache.delete("dns_srv_lookup:#{domain}")
- stub_request(:head, "https://service1.example.com/").to_raise(Faraday::SSLError)
+ stub_request(:get, "https://service1.example.com/health").to_raise(Faraday::SSLError)
(2..5).each do |i|
- stub_request(:head, "https://service#{i}.example.com/").to_return(status: 200)
+ stub_request(:get, "https://service#{i}.example.com/health").to_return(status: 200)
end
end
@@ -67,11 +67,11 @@ describe DiscourseAi::Utils::DnsSrv do
Discourse.cache.delete("dns_srv_lookup:#{domain}")
(1..3).each do |i|
- stub_request(:head, "https://service#{i}.example.com/").to_raise(Faraday::SSLError)
+ stub_request(:get, "https://service#{i}.example.com/health").to_raise(Faraday::SSLError)
end
(4..5).each do |i|
- stub_request(:head, "https://service#{i}.example.com/").to_return(status: 200)
+ stub_request(:get, "https://service#{i}.example.com/health").to_return(status: 200)
end
end