mohamicorp / stash-jenkins-postreceive-webhook

Webhook used to notify Jenkins when commits are made to Stash
Other
138 stars 100 forks source link

fix request action logging #196

Open marvinthepa opened 6 years ago

marvinthepa commented 6 years ago

Problem: If a lot of commits are pushed to different repos that all have the hook installed, the bitbucket log may contain entries like the following one. Here the request logged is for the rep_1 repository, while the notification URL is for the rep_2 repository:

2017-07-12 16:22:14,009 ERROR [JenkinsWebhook:thread-1353] user@example.com @1NT5XEPx981x8325789x2 1oo66tb 127.0.0.1 SSH - git-receive-pack '/project_1/rep_1.git' com.nerdwin15.stash.webhook.Notifier Error triggering jenkins with url 'http://localhost:8080/jenkins/git/notifyCommit?url=http%3A%2F%2Flocalhost%3A7990%2Fbitbucket%2Fscm%2Fproject_2%2Frep_2.git'

(this one only occurs when the hook runs into an error, but similar ones can be found for succesful requests when setting the com.nerdwin15.stash logger to DEBUG)

This is caused by the fact that we are running in a thread pool, and the original request that caused this (that was run in a different thread) is not correctly associated in the MDC map of logback.

Fix: Tell logback about the original request manually.

See https://stackoverflow.com/questions/6073019/how-to-use-mdc-with-thread-pools#19329668 https://logback.qos.ch/manual/mdc.html#managedThreads

Also see https://jira.atlassian.com/browse/BSERV-8749