Class: Contrast::Agent::Reporter
- Inherits:
-
WorkerThread
- Object
- WorkerThread
- Contrast::Agent::Reporter
- Defined in:
- lib/contrast/agent/reporting/reporter.rb
Overview
This module will hold everything essential to reporting to TeamServer
Constant Summary collapse
- RETRY_ATTEMPTS =
How many tries to reconnect the Reporter should make.
10
- MAX_QUEUE_SIZE =
1000
Constants included from Utils::ObjectShare
Utils::ObjectShare::AMPERSAND, Utils::ObjectShare::ASTERISK, Utils::ObjectShare::AT, Utils::ObjectShare::BACK_SLASH, Utils::ObjectShare::BANG, Utils::ObjectShare::CACHE, Utils::ObjectShare::CARROT, Utils::ObjectShare::COLON, Utils::ObjectShare::COLON_SLASH_SLASH, Utils::ObjectShare::COMMA, Utils::ObjectShare::CONTRAST_DOT, Utils::ObjectShare::CONTRAST_PATCHED_METHOD_START, Utils::ObjectShare::DASH, Utils::ObjectShare::DIGIT_REGEXP, Utils::ObjectShare::DOLLAR_SIGN, Utils::ObjectShare::DOUBLE_QUOTE, Utils::ObjectShare::DOUBLE_UNDERSCORE, Utils::ObjectShare::EMPTY_ARRAY, Utils::ObjectShare::EMPTY_HASH, Utils::ObjectShare::EMPTY_STRING, Utils::ObjectShare::EQUALS, Utils::ObjectShare::EXCLAMATION, Utils::ObjectShare::FALSE, Utils::ObjectShare::HTTPS_START, Utils::ObjectShare::HTTP_SCORE, Utils::ObjectShare::HTTP_START, Utils::ObjectShare::INDEX, Utils::ObjectShare::LEFT_ANGLE, Utils::ObjectShare::NEW_LINE, Utils::ObjectShare::NIL_64_STRING, Utils::ObjectShare::NIL_STRING, Utils::ObjectShare::NOT_WHITE_SPACE_REGEXP, Utils::ObjectShare::OBJECT_KEY, Utils::ObjectShare::OVERRIDE_MESSAGE, Utils::ObjectShare::PARENT_PATH, Utils::ObjectShare::PERIOD, Utils::ObjectShare::POUND_SIGN, Utils::ObjectShare::QUESTION_MARK, Utils::ObjectShare::RETURN, Utils::ObjectShare::RETURN_KEY, Utils::ObjectShare::RUBY, Utils::ObjectShare::SEMICOLON, Utils::ObjectShare::SINGLE_QUOTE, Utils::ObjectShare::SLASH, Utils::ObjectShare::SPACE, Utils::ObjectShare::TRUE, Utils::ObjectShare::UNDERSCORE, Utils::ObjectShare::UNKNOWN, Utils::ObjectShare::WHITE_SPACE_REGEXP, Utils::ObjectShare::WRITE_FLAG
Class Method Summary collapse
-
.enabled? ⇒ Boolean
check if we can report to TS.
Instance Method Summary collapse
- #client ⇒ Object
- #delete_queue! ⇒ Object
-
#handle_resend(event) ⇒ Object
Suspend the Reporter and try sending the event after the timeout.
- #send_event(event) ⇒ Object
-
#send_event_immediately(event) ⇒ Net::HTTPResponse?
Use this to bypass the messaging queue and leave response processing to the caller.
- #start_thread! ⇒ Object
- #stop! ⇒ Object
Methods included from Components::Logger::InstanceMethods
Methods inherited from WorkerThread
#attempt_to_start?, #clean_properties, #initialize, #running?
Constructor Details
This class inherits a constructor from Contrast::Agent::WorkerThread
Class Method Details
Instance Method Details
#client ⇒ Object
32 33 34 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 32 def client @_client ||= Contrast::Agent::Reporting::Client::Interface.new end |
#delete_queue! ⇒ Object
100 101 102 103 104 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 100 def delete_queue! @_queue&.clear @_queue&.close @_queue = nil end |
#handle_resend(event) ⇒ Object
Suspend the Reporter and try sending the event after the timeout. The timeout is either default 15 min or received via TS response.
59 60 61 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 59 def handle_resend event client.handle_resend(event) end |
#send_event(event) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 64 def send_event event if ::Contrast::AGENT.disabled? logger.warn('[Reporter] Attempted to queue event with Agent disabled', caller: caller, event: event) return end return unless event if queue.size >= MAX_QUEUE_SIZE Contrast::Agent::Telemetry::Base.enabled? && Contrast::Agent.thread_watcher.telemetry_queue. send_event(queue_limit_telemetry_event) return end queue << event end |
#send_event_immediately(event) ⇒ Net::HTTPResponse?
Use this to bypass the messaging queue and leave response processing to the caller. Do not use this in separate threads since this will create a race condition, when two threads need to use the same OpenSSL::SSL::SSLSocket raising frozen error.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 86 def send_event_immediately event if ::Contrast::AGENT.disabled? logger.warn('[Reporter] attempted to send event immediately with Agent disabled', caller: caller, event: event) return end return unless event return unless connected? client.send_event(event) rescue StandardError => e logger.error('[Reporter] Could not send message to TeamServer from reporting queue.', e) end |
#start_thread! ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 36 def start_thread! return unless attempt_to_start? return if running? @connection_attempts = 0 @_thread = Contrast::Agent::Thread.new do logger.debug('[Reporter] Starting background Reporter thread.') client.startup loop do break unless attempt_to_start? next unless connected? process_event(queue.pop) rescue StandardError => e logger.debug('[Reporter] thread could not process because of:', e) end end end |
#stop! ⇒ Object
106 107 108 109 110 111 |
# File 'lib/contrast/agent/reporting/reporter.rb', line 106 def stop! return unless running? super delete_queue! end |