Skip to content

Commit

Permalink
Use ENV for ruby script
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyCTHsu committed Feb 12, 2025
1 parent 2c2ae11 commit 30fc13e
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions .github/scripts/test_agent_check.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
#!/usr/bin/env ruby

require 'net/http'
require 'uri'
require 'json'
require "net/http"
require "uri"
require "json"

# Disable exiting on command failure
agent_host = ENV["DD_AGENT_HOST"] || raise "DD_AGENT_HOST is not set"
agent_port = ENV["DD_TRACE_AGENT_PORT"] || raise "DD_TRACE_AGENT_PORT is not set"

begin
# Check if test agent is running
summary_uri = URI.parse('http://testagent:9126/test/trace_check/summary')
summary_uri = URI.parse("http://#{agent_host}:#{agent_port}/test/trace_check/summary")
summary_response = Net::HTTP.get_response(summary_uri)

if summary_response.code == '200'
puts 'APM Test Agent is running. (HTTP 200)'
if summary_response.code == "200"
puts "APM Test Agent is running. (HTTP 200)"
else
puts 'APM Test Agent is not running and was not used for testing. No checks failed.'
puts "APM Test Agent is not running and was not used for testing. No checks failed."
exit 0
end

# Check for test failures
failures_uri = URI.parse('http://testagent:9126/test/trace_check/failures')
failures_uri = URI.parse("http://#{agent_host}:#{agent_port}/test/trace_check/failures")
failures_response = Net::HTTP.get_response(failures_uri)

case failures_response.code
when '200'
puts 'All APM Test Agent Check Traces returned successful! (HTTP 200)'
puts 'APM Test Agent Check Traces Summary Results:'
when "200"
puts "All APM Test Agent Check Traces returned successful! (HTTP 200)"
puts "APM Test Agent Check Traces Summary Results:"
puts JSON.pretty_generate(JSON.parse(summary_response.body))
when '404'
puts 'Real APM Agent running in place of TestAgent, no checks to validate!'
when "404"
puts "Real APM Agent running in place of TestAgent, no checks to validate!"
else
puts "APM Test Agent Check Traces failed with response code: #{failures_response.code}"
puts 'Failures:'
puts "Failures:"
puts failures_response.body
puts 'APM Test Agent Check Traces Summary Results:'
puts "APM Test Agent Check Traces Summary Results:"
puts JSON.pretty_generate(JSON.parse(summary_response.body))
exit 1
end
Expand Down

0 comments on commit 30fc13e

Please sign in to comment.