Commit 134b9241 authored by Brett Walker's avatar Brett Walker

Use a unique metric tag for each email handler

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, "labels must have the same signature"
parent ce5554c3
---
title: Fix service desk emails not creating issues intermittently
merge_request: 16577
author:
type: fixed
......@@ -39,6 +39,10 @@ module Gitlab
super.merge(project: project&.full_path)
end
def metrics_event
:receive_email_service_desk
end
private
attr_reader :project_id, :project_path
......
......@@ -24,6 +24,14 @@ module Gitlab
def metrics_params
{ handler: self.class.name }
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
......
......@@ -48,6 +48,10 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
def metrics_event
:receive_email_create_issue
end
private
def create_issue
......
......@@ -54,6 +54,10 @@ module Gitlab
super.merge(includes_patches: patch_attachments.any?)
end
def metrics_event
:receive_email_create_merge_request
end
private
def build_merge_request
......
......@@ -32,6 +32,10 @@ module Gitlab
record_name: 'comment')
end
def metrics_event
:receive_email_create_note
end
private
def author
......
......@@ -36,6 +36,10 @@ module Gitlab
noteable.unsubscribe(sent_notification.recipient)
end
def metrics_event
:receive_email_unsubscribe
end
private
attr_reader :reply_token
......
......@@ -39,9 +39,9 @@ module Gitlab
raise UnknownIncomingEmail unless handler
Gitlab::Metrics.add_event(:receive_email, handler.metrics_params)
handler.execute
handler.execute.tap do
Gitlab::Metrics.add_event(handler.metrics_event, handler.metrics_params)
end
end
private
......
......@@ -14,6 +14,7 @@ describe Gitlab::Email::Receiver do
allow(handler).to receive(:execute)
allow(handler).to receive(:metrics_params)
allow(handler).to receive(:metrics_event)
end
it "finds the mail key" do
......@@ -46,4 +47,12 @@ describe Gitlab::Email::Receiver do
expect { receiver.execute }.to raise_error(Gitlab::Email::AutoGeneratedEmailError)
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
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