Skip to content

Commit

Permalink
Better logging when things go wrong
Browse files Browse the repository at this point in the history
linting code
  • Loading branch information
rarruda committed Jul 5, 2018
1 parent 54c8a81 commit ab7d14b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Naming/PredicateName:
NameWhitelist:
- is_enabled?

Metrics/LineLength:
Max: 120

Style/RedundantSelf:
Enabled: false
Style/PreferredHashMethods:
Enabled: false
9 changes: 7 additions & 2 deletions lib/unleash/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ def register
request = Net::HTTP::Post.new(uri.request_uri, headers)
request.body = info.to_json

# Send the request
response = http.request(request)
# Send the request, if possible
begin
response = http.request(request)
rescue Exception => e
Unleash.logger.error "unable to register client with unleash server due to exception #{e.class}:'#{e}'."
Unleash.logger.error "stacktrace: #{e.backtrace}"
end
end
end
end
6 changes: 3 additions & 3 deletions lib/unleash/scheduled_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def run(&blk)
self.retry_count = 0
rescue Exception => e
self.retry_count += 1
Unleash.logger.error "thread #{name} throwing exception (#{self.retry_count} of #{self.max_exceptions})"
Unleash.logger.error e
Unleash.logger.error "thread #{name} threw exception #{e.class}:'#{e}' (#{self.retry_count}/#{self.max_exceptions})"
Unleash.logger.error "stacktrace: #{e.backtrace}"
end

break if self.retry_count > self.max_exceptions
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/unleash/strategy/application_hostname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def name
end

# need: :params[:hostnames]
def is_enabled?(params = {}, context = nil)
def is_enabled?(params = {}, _context = nil)
return false unless params.is_a?(Hash) && params.has_key?('hostnames')

params['hostnames'].split(",").map(&:strip).map{|h| h.downcase }.include?(self.hostname)
Expand Down
6 changes: 2 additions & 4 deletions lib/unleash/strategy/gradual_rollout_random.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def name
end

# need: params['percentage']
def is_enabled?(params = {}, context = nil)
def is_enabled?(params = {}, _context = nil)
return false unless params.is_a?(Hash) && params.has_key?('percentage')

begin
Expand All @@ -17,9 +17,7 @@ def is_enabled?(params = {}, context = nil)
return false
end

randomNumber = Random.rand(100) + 1

(percentage >= randomNumber)
(percentage >= Random.rand(1..100))
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/unleash/strategy/remote_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def is_enabled?(params = {}, context = nil)
return false unless params.fetch('ips', nil).is_a? String
return false unless context.class.name == 'Unleash::Context'

params['ips'].split(',').map(&:strip).include?( context.remote_address )
params['ips'].split(',').map(&:strip).include?(context.remote_address)
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/unleash/toggle_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def save!
end
rescue Exception => e
# This is not really the end of the world. Swallowing the exception.
Unleash.logger.error "Unable to save backup file."
Unleash.logger.error "Unable to save backup file. Exception thrown #{e.class}:'#{e}'"
Unleash.logger.error "stacktrace: #{e.backtrace}"
ensure
file.close unless file.nil?
end
Expand All @@ -136,7 +137,8 @@ def read!
rescue JSON::ParserError => e
Unleash.logger.error "Unable to parse JSON from existing backup_file."
rescue Exception => e
Unleash.logger.error "Unable to extract valid data from backup_file."
Unleash.logger.error "Unable to extract valid data from backup_file. Exception thrown #{e.class}:'#{e}'"
Unleash.logger.error "stacktrace: #{e.backtrace}"
ensure
file.close unless file.nil?
end
Expand Down

0 comments on commit ab7d14b

Please sign in to comment.