This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEA sends heartbeats to HM9000 over HTTP
- change heartbeat method to only take uuid - no longer give entire bootstrap - create hm9000 - dea sends heartbeats over http - Change integration helpers for http heartbeat - Fix dea logging and heartbeat URI [#112002745] Signed-off-by: Jonathan Berkhahn <jaberkha@us.ibm.com>
- Loading branch information
1 parent
08d8315
commit 298d25c
Showing
11 changed files
with
242 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
require 'dea/utils/uri_cleaner' | ||
|
||
class HM9000 | ||
INACTIVITY_TIMEOUT = 300.freeze | ||
|
||
attr_reader :logger | ||
|
||
def initialize(destination, custom_logger=nil) | ||
@destination = destination | ||
@logger = custom_logger || self.class.logger | ||
end | ||
|
||
def send_heartbeat(heartbeat) | ||
logger.info("send_heartbeat", destination: URICleaner.clean(@destination)) | ||
|
||
http = EM::HttpRequest.new(@destination, inactivity_timeout: INACTIVITY_TIMEOUT).post( body: Yajl::Encoder.encode(heartbeat)) | ||
|
||
http.errback do | ||
handle_error(http) | ||
end | ||
|
||
http.callback do | ||
handle_http_response(http) | ||
end | ||
end | ||
|
||
def handle_http_response(http) | ||
http_status = http.response_header.status | ||
|
||
if http_status == 202 | ||
logger.debug("heartbeat accepted") | ||
else | ||
handle_error(http) | ||
end | ||
end | ||
|
||
|
||
def handle_error(http) | ||
open_connection_count = EM.connection_count # https://github.com/igrigorik/em-http-request/issues/190 says to check connection_count | ||
logger.warn("Sending heartbeat failed", | ||
destination: URICleaner.clean(@destination), | ||
connection_count: open_connection_count, | ||
http_error: http.error, | ||
http_status: http.response_header.status, | ||
http_response: http.response) | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.