Skip to content

Commit 1dfb659

Browse files
authored
Patch/INV-1229 - Ruby logging issues (#31)
Fix the authorization error issue in Passenger
1 parent 814c4f9 commit 1dfb659

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

lib/stackify-api-ruby.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def internal_log level, msg
123123

124124
def run
125125
Stackify::Utils.is_api_enabled
126-
Stackify.internal_log :debug, "Stackify.run = #{Stackify.configuration.transport}"
126+
Stackify.internal_log :info, "Stackify.run() transportType = #{Stackify.configuration.transport} | API version: #{Stackify::VERSION}"
127127
if Stackify.configuration.api_enabled
128128
if Stackify.is_valid?
129129
# check transport types
@@ -141,7 +141,6 @@ def run
141141
when MODES[:metrics]
142142
t3 = start_metrics
143143
end
144-
145144
t1.join
146145
t3.join if t3
147146
else

lib/stackify/authorization/authorization_client.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ def auth attempts, delay_time= Stackify::ScheduleDelay.new
1414
end
1515

1616
def auth_task attempts
17-
properties = {
18-
limit: 1,
19-
attempts: attempts,
20-
success_condition: lambda do |result|
21-
result.try(:status) == 200
17+
begin
18+
properties = {
19+
limit: 1,
20+
attempts: attempts,
21+
success_condition: lambda do |result|
22+
result.try(:status) == 200
23+
end
24+
}
25+
Stackify::ScheduleTask.new properties do
26+
Stackify.internal_log :debug, '[AuthorizationClient] trying to authorize...'
27+
send_request BASE_URI, Stackify::EnvDetails.instance.auth_info.to_json
2228
end
23-
}
24-
Stackify::ScheduleTask.new properties do
25-
Stackify.internal_log :debug, '[AuthorizationClient] trying to authorize...'
26-
send_request BASE_URI, Stackify::EnvDetails.instance.auth_info.to_json
29+
rescue => exception
30+
Stackify.log_internal_error "[AuthorizationClient]: An error occured in auth_task!"
2731
end
2832
end
2933
end

lib/stackify/http_client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def send_request uri, body, headers = HEADERS
2525
req.headers = headers
2626
req.body = body
2727
end
28+
return @response
2829
rescue => ex
2930
@errors << ex
3031
Stackify.log_internal_error('HttpClient: ' + ex.message+ ' Backtrace: '+ Stackify::Backtrace.backtrace_in_line(ex.backtrace))

lib/stackify/logger_client.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ module Stackify
22
class LoggerClient
33

44
def initialize
5-
@@errors_governor = Stackify::ErrorsGovernor.new
6-
@@transport = Stackify::TransportSelector.new(Stackify.configuration.transport).transport
7-
return if @@transport.nil?
5+
begin
6+
@@errors_governor = Stackify::ErrorsGovernor.new
7+
@@transport = Stackify::TransportSelector.new(Stackify.configuration.transport).transport
8+
Stackify.internal_log :info, "[LoggerClient] initialize: #{@@transport}"
9+
return if @@transport.nil?
10+
rescue => ex
11+
Stackify.log_internal_error "[LoggerClient] initialize exception = #{ex.inspect}"
12+
end
813
end
914

1015
def log level, msg, call_trace
@@ -20,6 +25,7 @@ def log_exception level= :error, ex
2025
end
2126

2227
def get_transport
28+
return if @@transport.nil?
2329
@@transport
2430
end
2531

lib/stackify/transport_selector.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ class TransportSelector
66
def initialize type
77
case type
88
when Stackify::DEFAULT
9-
Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
10-
@transport = Stackify::LogsSender.new
11-
end
9+
@transport = Stackify::LogsSender.new
1210
when Stackify::UNIX_SOCKET, Stackify::AGENT_HTTP
1311
@transport = Stackify::AgentClient.new
1412
end

lib/stackify/utils/methods.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@ def self.is_mode_on? mode
1414
end
1515

1616
def self.do_only_if_authorized_and_mode_is_on mode, &block
17-
if Stackify.configuration.api_enabled
18-
if Stackify.authorized?
19-
if is_mode_on? mode
20-
yield
17+
begin
18+
if Stackify.configuration.api_enabled
19+
if Stackify.authorized?
20+
if is_mode_on? mode
21+
yield
22+
else
23+
Stackify.internal_log :warn, "[Stackify::Utils] - #{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration"
24+
end
2125
else
22-
Stackify.internal_log :warn, "#{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration"
26+
Stackify.internal_log :warn, "[Stackify::Utils] - #{caller[0]}: Skipped due to authorization failure"
2327
end
24-
else
25-
Stackify.internal_log :warn, "#{caller[0]}: Skipped due to authorization failure"
2628
end
29+
rescue => ex
30+
Stackify.internal_log :warn, "[Stackify::Utils] do_only_if_authorized_and_mode_is_on ex: #{ex.inspect}"
2731
end
2832
end
2933

0 commit comments

Comments
 (0)