Commit 01e12b05 authored by Stan Hu's avatar Stan Hu

Merge branch 'bw-fix-servicedesk-events' into 'master'

Use a unique metric tag for each email handler

See merge request gitlab-org/gitlab-ee!16577
parents ce5554c3 134b9241
---
title: Fix service desk emails not creating issues intermittently
merge_request: 16577
author:
type: fixed
...@@ -39,6 +39,10 @@ module Gitlab ...@@ -39,6 +39,10 @@ module Gitlab
super.merge(project: project&.full_path) super.merge(project: project&.full_path)
end end
def metrics_event
:receive_email_service_desk
end
private private
attr_reader :project_id, :project_path attr_reader :project_id, :project_path
......
...@@ -24,6 +24,14 @@ module Gitlab ...@@ -24,6 +24,14 @@ module Gitlab
def metrics_params def metrics_params
{ handler: self.class.name } { handler: self.class.name }
end end
# Each handler should use it's own metric event. Otherwise there
# is a possibility that within the same Sidekiq process, that same
# event with different metrics_params will cause Prometheus to
# throw an error
def metrics_event
raise NotImplementedError
end
end end
end end
end end
......
...@@ -48,6 +48,10 @@ module Gitlab ...@@ -48,6 +48,10 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
def metrics_event
:receive_email_create_issue
end
private private
def create_issue def create_issue
......
...@@ -54,6 +54,10 @@ module Gitlab ...@@ -54,6 +54,10 @@ module Gitlab
super.merge(includes_patches: patch_attachments.any?) super.merge(includes_patches: patch_attachments.any?)
end end
def metrics_event
:receive_email_create_merge_request
end
private private
def build_merge_request def build_merge_request
......
...@@ -32,6 +32,10 @@ module Gitlab ...@@ -32,6 +32,10 @@ module Gitlab
record_name: 'comment') record_name: 'comment')
end end
def metrics_event
:receive_email_create_note
end
private private
def author def author
......
...@@ -36,6 +36,10 @@ module Gitlab ...@@ -36,6 +36,10 @@ module Gitlab
noteable.unsubscribe(sent_notification.recipient) noteable.unsubscribe(sent_notification.recipient)
end end
def metrics_event
:receive_email_unsubscribe
end
private private
attr_reader :reply_token attr_reader :reply_token
......
...@@ -39,9 +39,9 @@ module Gitlab ...@@ -39,9 +39,9 @@ module Gitlab
raise UnknownIncomingEmail unless handler raise UnknownIncomingEmail unless handler
Gitlab::Metrics.add_event(:receive_email, handler.metrics_params) handler.execute.tap do
Gitlab::Metrics.add_event(handler.metrics_event, handler.metrics_params)
handler.execute end
end end
private private
......
...@@ -14,6 +14,7 @@ describe Gitlab::Email::Receiver do ...@@ -14,6 +14,7 @@ describe Gitlab::Email::Receiver do
allow(handler).to receive(:execute) allow(handler).to receive(:execute)
allow(handler).to receive(:metrics_params) allow(handler).to receive(:metrics_params)
allow(handler).to receive(:metrics_event)
end end
it "finds the mail key" do it "finds the mail key" do
...@@ -46,4 +47,12 @@ describe Gitlab::Email::Receiver do ...@@ -46,4 +47,12 @@ describe Gitlab::Email::Receiver do
expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError) expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError)
end end
end end
it "requires all handlers to have a unique metric_event" do
events = Gitlab::Email::Handler.handlers.map do |handler|
handler.new(Mail::Message.new, 'gitlabhq/gitlabhq+auth_token').metrics_event
end
expect(events.uniq.count).to eq events.count
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment