Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12264 from dmarcoux/instrument_scm_webhook
Instrument ScmWebhook
- Loading branch information
Showing
2 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/api/app/instrumentations/scm_webhook_instrumentation.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module ScmWebhookInstrumentation | ||
extend ActiveSupport::Concern | ||
|
||
# Define callbacks with ActiveModel::Callback which is included in ActiveModel::Model | ||
included do | ||
define_model_callbacks :initialize | ||
|
||
after_initialize :track_webhook | ||
end | ||
|
||
private | ||
|
||
def track_webhook | ||
RabbitmqBus.send_to_bus('metrics', "scm_webhook,scm=#{@payload[:scm]},webhook_event=#{webhook_event} count=1") | ||
end | ||
|
||
def webhook_event | ||
case | ||
when push_event? | ||
'push' | ||
when tag_push_event? | ||
'tag_push' | ||
when pull_request_event? | ||
'pull_request' | ||
else | ||
'unsupported' | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters