Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Issues
  • #8667

Closed
Open
Created Jan 27, 2015 by Administrator@rootOwner

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
Assignee
Assign to
Time tracking