Add More Logging to `app/models/web_hook.rb`
Created by: blaskovicz
Versions
GitLab 7.2.1 GitLab Shell 1.9.7 GitLab API v3 Ruby 2.1.0p0 Rails 4.1.1
Request
Log the response code of web hooks (app/models/web_hook.rb
).
Use Case
Earlier today I was trying to debug a communication issue between our sites; the site exposing the web hook saw no request and gitlab logged no response or errors.
Potential Patch
diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb
index 6cf0c1f..8d3a583 100644
--- a/app/models/web_hook.rb
+++ b/app/models/web_hook.rb
@@ -29,8 +29,9 @@ class WebHook < ActiveRecord::Base
format: { with: URI::regexp(%w(http https)), message: "should be a valid url" }
def execute(data)
+ logger = Sidekiq.logger
parsed_url = URI.parse(url)
- if parsed_url.userinfo.blank?
+ response = if parsed_url.userinfo.blank?
WebHook.post(url, body: data.to_json, headers: { "Content-Type" => "application/json" }, verify: false)
else
post_url = url.gsub("#{parsed_url.userinfo}@", "")
@@ -44,6 +45,12 @@ class WebHook < ActiveRecord::Base
verify: false,
basic_auth: auth)
end
+ if response.code >= 200 and response.code < 300
+ logger.info "Webhook #{id} returned HTTP-2xx [#{response.code}]"
+ else
+ logger.warn "Webhook #{id} returned Non-HTTP-2xx [#{response.code}]"
+ end
+ response
end