From 57edc23385ad82d4428ba34f342aee07cb2d2ba6 Mon Sep 17 00:00:00 2001
From: Sean McGivern <sean@gitlab.com>
Date: Thu, 20 Apr 2017 11:32:10 +0100
Subject: [PATCH] Add metrics events for incoming emails

This lets us track how many incoming emails a GitLab instance is processing, by
email type (handler) and by project (where applicable).
---
 changelogs/unreleased/add-email-receiver-metrics.yml | 4 ++++
 lib/gitlab/email/receiver.rb                         | 4 ++++
 2 files changed, 8 insertions(+)
 create mode 100644 changelogs/unreleased/add-email-receiver-metrics.yml

diff --git a/changelogs/unreleased/add-email-receiver-metrics.yml b/changelogs/unreleased/add-email-receiver-metrics.yml
new file mode 100644
index 00000000000..53155651080
--- /dev/null
+++ b/changelogs/unreleased/add-email-receiver-metrics.yml
@@ -0,0 +1,4 @@
+---
+title: Add metrics events for incoming emails
+merge_request:
+author:
diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb
index ec0529b5a4b..bb4fdd1f1f4 100644
--- a/lib/gitlab/email/receiver.rb
+++ b/lib/gitlab/email/receiver.rb
@@ -32,6 +32,10 @@ module Gitlab
 
         raise UnknownIncomingEmail unless handler
 
+        Gitlab::Metrics.add_event(:receive_email,
+                                  project: handler.try(:project),
+                                  handler: handler.class.name)
+
         handler.execute
       end
 
-- 
2.30.9