Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
dce9599e
Commit
dce9599e
authored
Jul 16, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement action mailer delivery metrics observer
parent
51b81d7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
2 deletions
+73
-2
config/initializers/action_mailer_hooks.rb
config/initializers/action_mailer_hooks.rb
+7
-2
lib/gitlab/email/hook/delivery_metrics_observer.rb
lib/gitlab/email/hook/delivery_metrics_observer.rb
+31
-0
spec/lib/gitlab/email/hook/delivery_metrics_observer_spec.rb
spec/lib/gitlab/email/hook/delivery_metrics_observer_spec.rb
+35
-0
No files found.
config/initializers/action_mailer_hooks.rb
View file @
dce9599e
...
@@ -3,5 +3,10 @@ unless Gitlab.config.gitlab.email_enabled
...
@@ -3,5 +3,10 @@ unless Gitlab.config.gitlab.email_enabled
ActionMailer
::
Base
.
logger
=
nil
ActionMailer
::
Base
.
logger
=
nil
end
end
ActionMailer
::
Base
.
register_interceptor
(
::
Gitlab
::
Email
::
Hook
::
AdditionalHeadersInterceptor
)
ActionMailer
::
Base
.
register_interceptors
(
ActionMailer
::
Base
.
register_interceptor
(
::
Gitlab
::
Email
::
Hook
::
EmailTemplateInterceptor
)
::
Gitlab
::
Email
::
Hook
::
AdditionalHeadersInterceptor
,
::
Gitlab
::
Email
::
Hook
::
EmailTemplateInterceptor
,
::
Gitlab
::
Email
::
Hook
::
DeliveryMetricsObserver
)
ActionMailer
::
Base
.
register_observer
(
::
Gitlab
::
Email
::
Hook
::
DeliveryMetricsObserver
)
lib/gitlab/email/hook/delivery_metrics_observer.rb
0 → 100644
View file @
dce9599e
module
Gitlab
module
Email
module
Hook
class
DeliveryMetricsObserver
extend
Gitlab
::
Utils
::
StrongMemoize
def
self
.
delivering_email
(
_message
)
delivery_attempts_counter
.
increment
end
def
self
.
delivered_email
(
_message
)
delivered_emails_counter
.
increment
end
def
self
.
delivery_attempts_counter
strong_memoize
(
:delivery_attempts_counter
)
do
Gitlab
::
Metrics
.
counter
(
:gitlab_emails_delivery_attempts_total
,
'Counter of total emails delivery attempts'
)
end
end
def
self
.
delivered_emails_counter
strong_memoize
(
:delivered_emails_counter
)
do
Gitlab
::
Metrics
.
counter
(
:gitlab_emails_delivered_total
,
'Counter of total emails delievered'
)
end
end
end
end
end
end
spec/lib/gitlab/email/hook/delivery_metrics_observer_spec.rb
0 → 100644
View file @
dce9599e
require
'spec_helper'
describe
Gitlab
::
Email
::
Hook
::
DeliveryMetricsObserver
do
let
(
:email
)
do
ActionMailer
::
Base
.
mail
(
to:
'test@example.com'
,
from:
'info@example.com'
,
body:
'hello'
)
end
context
'when email has been delivered'
do
it
'increments both email delivery metrics'
do
expect
(
described_class
.
delivery_attempts_counter
).
to
receive
(
:increment
)
expect
(
described_class
.
delivered_emails_counter
).
to
receive
(
:increment
)
email
.
deliver_now
end
end
context
'when email has not been delivered due to an error'
do
before
do
allow
(
email
.
delivery_method
).
to
receive
(
:deliver!
)
.
and_raise
(
StandardError
,
'Some SMTP error'
)
end
it
'increments only delivery attempt metric'
do
expect
(
described_class
.
delivery_attempts_counter
)
.
to
receive
(
:increment
)
expect
(
described_class
.
delivered_emails_counter
)
.
not_to
receive
(
:increment
)
expect
{
email
.
deliver_now
}
.
to
raise_error
(
StandardError
,
'Some SMTP error'
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment