Skip to content

Commit c45fb90

Browse files
committed
get the logger ready
1 parent 06a9fed commit c45fb90

File tree

3 files changed

+24
-23
lines changed

3 files changed

+24
-23
lines changed

lib/service.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def current_sha
5858
# data - A Hash with the configuration data for the Service.
5959
# payload - A Hash with the unique payload data for this Service instance.
6060
#
61-
# Returns true if the Service responded to the event, or false if the
62-
# Service does not respond to this event.
61+
# Returns the Service instance if it responds to this event, or nil.
6362
def receive(event, data, payload = nil)
6463
svc = new(event, data, payload)
6564

@@ -72,9 +71,7 @@ def receive(event, data, payload = nil)
7271
end
7372
end
7473

75-
true
76-
else
77-
false
74+
svc
7875
end
7976
rescue Service::ConfigurationError, Errno::EHOSTUNREACH, Errno::ECONNRESET, SocketError, Net::ProtocolError => err
8077
Service.stats.increment "hook.fail.config.#{hook_name}"
@@ -572,7 +569,7 @@ def sanitize_log_value(value)
572569
string.strip!
573570
if string =~ /^[a-z]+\:\/\//
574571
uri = Addressable::URI.parse(string)
575-
uri.password = "*" * uri.password.size
572+
uri.password = "*" * uri.password.size if uri.password
576573
uri.to_s
577574
else
578575
string

lib/service/app.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ class Service::App < Sinatra::Base
66

77
# Hooks the given Service to a Sinatra route.
88
#
9-
# svc - Service class.
9+
# svc_class - Service class.
1010
#
1111
# Returns nothing.
12-
def self.service(svc)
13-
post "/#{svc.hook_name}/:event" do
12+
def self.service(svc_class)
13+
post "/#{svc_class.hook_name}/:event" do
1414
boom = nil
1515
time = Time.now.to_f
1616
data = nil
1717
begin
1818
event, data, payload = parse_request
19-
if svc.receive(event, data, payload)
20-
status 200
21-
""
19+
if svc = svc_class.receive(event, data, payload)
20+
log_service_request svc, 200
21+
"OK"
2222
else
23-
status 404
24-
status "#{svc.hook_name} Service does not respond to 'push' events"
23+
log_service_request svc, 200
24+
"#{svc_class.hook_name} Service does not respond to 'push' events"
2525
end
2626
rescue Faraday::Error::ConnectionFailed => boom
27-
status 503
27+
log_service_request svc, 503
2828
boom.message
2929
rescue Service::ConfigurationError => boom
30-
status 400
30+
log_service_request svc, 400
3131
boom.message
3232
rescue Timeout::Error, Service::TimeoutError => boom
33-
status 504
33+
log_service_request svc, 504
3434
"Service Timeout"
3535
rescue Service::MissingError => boom
36-
status 404
36+
log_service_request svc, 404
3737
boom.message
3838
rescue Object => boom
39-
report_exception svc, data, boom,
39+
report_exception svc_class, data, boom,
4040
:event => event, :payload => payload.inspect
41-
status 500
41+
log_service_request svc, 500
4242
"ERROR"
4343
ensure
4444
duration = Time.now.to_f - time
45-
if svc != Service::Web && duration > 9
45+
if svc_class != Service::Web && duration > 9
4646
boom ||= Service::TimeoutError.new("Long Service Hook")
47-
report_exception svc, data, boom,
47+
report_exception svc_class, data, boom,
4848
:event => event, :payload => payload.inspect,
4949
:duration => "#{duration}s"
5050
end
@@ -77,6 +77,10 @@ def parse_http_request
7777
[params[:event], data, payload]
7878
end
7979

80+
def log_service_request(svc, code)
81+
status code
82+
end
83+
8084
# Reports the given exception to Haystack.
8185
#
8286
# exception - An Exception instance.

test/web_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_log_data
122122

123123
def test_log_message
124124
data = {
125-
'url' => 'http://user:pass@abc.com/def',
125+
'url' => 'http://abc.com/def',
126126
'secret' => 'monkey',
127127
'content_type' => 'json'
128128
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy