Skip to content

Commit

Permalink
Rename methods for clarity
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Upton <brian.upton@broadcom.com>
  • Loading branch information
aramprice authored and jpalermo committed Sep 26, 2024
1 parent 294e585 commit 3621b91
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/bosh-monitor/lib/bosh/monitor/plugins/event_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def director_info

director_info_url = @url.dup
director_info_url.path = '/info'
body, status = send_http_get_request(director_info_url.to_s)
body, status = send_http_get_request_synchronous(director_info_url.to_s)
return nil if status != 200

@director_info = JSON.parse(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def send_http_post_request(uri, request)
process_async_http_request(method: :post, uri: uri, headers: request.fetch(:head, {}), body: request.fetch(:body, nil), proxy: request.fetch(:proxy, nil))
end

def send_http_get_request(uri, headers = nil)
def send_http_get_request_synchronous(uri, headers = nil)
parsed_uri = URI.parse(uri.to_s)

# we are interested in response, so send sync request
Expand All @@ -27,7 +27,7 @@ def send_http_get_request(uri, headers = nil)
[response.body, response.code.to_i]
end

def send_http_post_sync_request(uri, request)
def send_http_post_request_synchronous_with_tls_verify_peer(uri, request)
parsed_uri = URI.parse(uri.to_s)

net_http = sync_client(parsed_uri, OpenSSL::SSL::VERIFY_PEER)
Expand Down
2 changes: 1 addition & 1 deletion src/bosh-monitor/lib/bosh/monitor/plugins/pagerduty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def process(event)
request[:proxy] = options['http_proxy'] if options['http_proxy']

Async do
send_http_post_sync_request(API_URI, request)
send_http_post_request_synchronous_with_tls_verify_peer(API_URI, request)
rescue StandardError => e
logger.error("Error sending pagerduty event: #{e}")
end
Expand Down
6 changes: 3 additions & 3 deletions src/bosh-monitor/lib/bosh/monitor/plugins/resurrector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ def scan_and_fix_already_queued_or_processing?(deployment_name)
'Content-Type' => 'application/json',
}
url.query = URI.encode_www_form({ deployment: deployment_name, state: 'queued,processing', verbose: 2 })
body, status = send_http_get_request(url.to_s, headers)
body, status = send_http_get_request_synchronous(url.to_s, headers)

# Getting the current tasks may fail. In a situation where the director is already dealing with lots of scan and fix tasks,
# we may want to postpone adding another one to the queue to give the director time to deal with the currently scheduled tasks.
# In the case of the tasks endpoint misbehaving ( status != 200 ) we can safely skip scheduling the the scan and fix in the current iteration.
# The alerts about missing healthchecks will trigger again some time later (when the director is under less pressure).
# The alerts about missing health-checks will trigger again some time later (when the director is under less pressure).
return true if status != 200

queued_scan_and_fix = JSON.parse(body).select do |task|
Expand All @@ -142,7 +142,7 @@ def director_info

url = @uri.dup
url.path = '/info'
body, status = send_http_get_request(url.to_s)
body, status = send_http_get_request_synchronous(url.to_s)
return nil if status != 200

@director_info = JSON.parse(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
end
end

describe '#send_http_get_request' do
describe '#send_http_get_request_synchronous' do
let(:some_uri) { URI.parse('https://send-http-get-request.example.com/some-path') }
let(:some_uri_response) { 'hello send_http_get_request' }

Expand Down Expand Up @@ -100,7 +100,7 @@
end

it 'configures the SSL Verify mode' do
send_http_get_request(some_uri)
send_http_get_request_synchronous(some_uri)

expect(Net::HTTP).to have_received(:new).with(some_uri.host, some_uri.port)
expect(http_client).to have_received(:use_ssl=).with(true)
Expand All @@ -109,7 +109,7 @@

context 'when URI#find_proxy is nil' do
it 'does not set any proxy value on the client' do
send_http_get_request(some_uri)
send_http_get_request_synchronous(some_uri)

expect(http_client).to_not have_received(:proxy_address=)
expect(http_client).to_not have_received(:proxy_port=)
Expand All @@ -122,7 +122,7 @@
let(:proxy_uri) { URI.parse('https://proxy-user:proxy-pass@proxy.example.com:8080/proxy-path') }

it 'sets proxy values on the client' do
send_http_get_request(some_uri)
send_http_get_request_synchronous(some_uri)

expect(http_client).to have_received(:proxy_address=).with(proxy_uri.host)
expect(http_client).to have_received(:proxy_port=).with(proxy_uri.port)
Expand All @@ -135,14 +135,14 @@
context 'making the request' do
context 'when headers are NOT specified' do
it 'sends a get request' do
body, status = send_http_get_request(some_uri)
body, status = send_http_get_request_synchronous(some_uri)

expect(status).to eq(200)
expect(body).to eq(some_uri_response)
end

it 'logs the request' do
send_http_get_request(some_uri)
send_http_get_request_synchronous(some_uri)

expect(logger).to have_received(:debug).with("Sending GET request to #{some_uri}")
end
Expand All @@ -157,22 +157,22 @@
end

it 'sends a get request with custom headers' do
body, status = send_http_get_request(some_uri, custom_headers)
body, status = send_http_get_request_synchronous(some_uri, custom_headers)

expect(status).to eq(200)
expect(body).to eq(some_uri_response)
end

it 'logs the request' do
send_http_get_request(some_uri, custom_headers)
send_http_get_request_synchronous(some_uri, custom_headers)

expect(logger).to have_received(:debug).with("Sending GET request to #{some_uri}")
end
end
end
end

describe '#send_http_post_sync_request' do
describe '#send_http_post_request_synchronous_with_tls_verify_peer' do
let(:some_uri) { URI.parse('https://send-http-post-sync-request.example.com/some-path') }
let(:some_uri_response) { 'hello send_http_post_sync_request' }
let(:request) do
Expand Down Expand Up @@ -208,7 +208,7 @@
end

it 'configures the SSL Verify mode' do
send_http_post_sync_request(some_uri, request)
send_http_post_request_synchronous_with_tls_verify_peer(some_uri, request)

expect(Net::HTTP).to have_received(:new).with(some_uri.host, some_uri.port)
expect(http_client).to have_received(:use_ssl=).with(true)
Expand All @@ -217,7 +217,7 @@

context 'when URI#find_proxy is nil' do
it 'does not set any proxy value on the client' do
send_http_post_sync_request(some_uri, request)
send_http_post_request_synchronous_with_tls_verify_peer(some_uri, request)

expect(http_client).to_not have_received(:proxy_address=)
expect(http_client).to_not have_received(:proxy_port=)
Expand All @@ -230,7 +230,7 @@
let(:proxy_uri) { URI.parse('https://proxy-user:proxy-pass@proxy.example.com:8080/proxy-path') }

it 'sets proxy values on the client' do
send_http_post_sync_request(some_uri, request)
send_http_post_request_synchronous_with_tls_verify_peer(some_uri, request)

expect(http_client).to have_received(:proxy_address=).with(proxy_uri.host)
expect(http_client).to have_received(:proxy_port=).with(proxy_uri.port)
Expand All @@ -242,7 +242,7 @@

context 'making the request' do
it 'sends a get request' do
body, status = send_http_post_sync_request(some_uri, request)
body, status = send_http_post_request_synchronous_with_tls_verify_peer(some_uri, request)

expect(status).to eq(200)
expect(body).to eq(some_uri_response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
Sync do
@plugin.run

expect(@plugin).to receive(:send_http_post_sync_request).with(uri, alert_request)
expect(@plugin).to receive(:send_http_post_sync_request).with(uri, heartbeat_request)
expect(@plugin).to receive(:send_http_post_request_synchronous_with_tls_verify_peer).with(uri, alert_request)
expect(@plugin).to receive(:send_http_post_request_synchronous_with_tls_verify_peer).with(uri, heartbeat_request)

@plugin.process(alert)
@plugin.process(heartbeat)
Expand Down

0 comments on commit 3621b91

Please sign in to comment.