BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c3af43c3
Commit
c3af43c3
authored
Apr 06, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'add-dimension-etag-caching-metrics' into 'master'
Include endpoint in metrics for ETag caching middleware See merge request !10495
parents
46e4ed6b
894f01cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
24 deletions
+40
-24
add-dimension-etag-caching-metrics.yml
changelogs/unreleased/add-dimension-etag-caching-metrics.yml
+4
-0
middleware.rb
lib/gitlab/etag_caching/middleware.rb
+28
-16
middleware_spec.rb
spec/lib/gitlab/etag_caching/middleware_spec.rb
+8
-8
No files found.
changelogs/unreleased/add-dimension-etag-caching-metrics.yml
0 → 100644
View file @
c3af43c3
---
title
:
Include endpoint in metrics for ETag caching middleware
merge_request
:
10495
author
:
lib/gitlab/etag_caching/middleware.rb
View file @
c3af43c3
...
...
@@ -2,26 +2,34 @@ module Gitlab
module
EtagCaching
class
Middleware
RESERVED_WORDS
=
NamespaceValidator
::
WILDCARD_ROUTES
.
map
{
|
word
|
"/
#{
word
}
/"
}.
join
(
'|'
)
ROUTE_REGEXP
=
Regexp
.
union
(
%r(^(?!.*(
#{
RESERVED_WORDS
}
)).*/noteable/issue/
\d
+/notes
\z
)
,
%r(^(?!.*(
#{
RESERVED_WORDS
}
)).*/issues/
\d
+/rendered_title
\z
)
)
ROUTES
=
[
{
regexp:
%r(^(?!.*(
#{
RESERVED_WORDS
}
)).*/noteable/issue/
\d
+/notes
\z
)
,
name:
'issue_notes'
},
{
regexp:
%r(^(?!.*(
#{
RESERVED_WORDS
}
)).*/issues/
\d
+/rendered_title
\z
)
,
name:
'issue_title'
}
].
freeze
def
initialize
(
app
)
@app
=
app
end
def
call
(
env
)
return
@app
.
call
(
env
)
unless
enabled_for_current_route?
(
env
)
Gitlab
::
Metrics
.
add_event
(
:etag_caching_middleware_used
)
route
=
match_current_route
(
env
)
return
@app
.
call
(
env
)
unless
route
track_event
(
:etag_caching_middleware_used
,
route
)
etag
,
cached_value_present
=
get_etag
(
env
)
if_none_match
=
env
[
'HTTP_IF_NONE_MATCH'
]
if
if_none_match
==
etag
handle_cache_hit
(
etag
)
handle_cache_hit
(
etag
,
route
)
else
track_cache_miss
(
if_none_match
,
cached_value_present
)
track_cache_miss
(
if_none_match
,
cached_value_present
,
route
)
status
,
headers
,
body
=
@app
.
call
(
env
)
headers
[
'ETag'
]
=
etag
...
...
@@ -31,8 +39,8 @@ module Gitlab
private
def
enabled_for_current_route?
(
env
)
ROUTE
_REGEXP
.
match
(
env
[
'PATH_INFO'
])
def
match_current_route
(
env
)
ROUTE
S
.
find
{
|
route
|
route
[
:regexp
].
match
(
env
[
'PATH_INFO'
])
}
end
def
get_etag
(
env
)
...
...
@@ -52,23 +60,27 @@ module Gitlab
%Q{W/"
#{
value
}
"}
end
def
handle_cache_hit
(
etag
)
Gitlab
::
Metrics
.
add_event
(
:etag_caching_cache_hit
)
def
handle_cache_hit
(
etag
,
route
)
track_event
(
:etag_caching_cache_hit
,
route
)
status_code
=
Gitlab
::
PollingInterval
.
polling_enabled?
?
304
:
429
[
status_code
,
{
'ETag'
=>
etag
},
[
''
]]
end
def
track_cache_miss
(
if_none_match
,
cached_value_present
)
def
track_cache_miss
(
if_none_match
,
cached_value_present
,
route
)
if
if_none_match
.
blank?
Gitlab
::
Metrics
.
add_event
(
:etag_caching_header_missing
)
track_event
(
:etag_caching_header_missing
,
route
)
elsif
!
cached_value_present
Gitlab
::
Metrics
.
add_event
(
:etag_caching_key_not_found
)
track_event
(
:etag_caching_key_not_found
,
route
)
else
Gitlab
::
Metrics
.
add_event
(
:etag_caching_resource_changed
)
track_event
(
:etag_caching_resource_changed
,
route
)
end
end
def
track_event
(
name
,
route
)
Gitlab
::
Metrics
.
add_event
(
name
,
endpoint:
route
[
:name
])
end
end
end
end
spec/lib/gitlab/etag_caching/middleware_spec.rb
View file @
c3af43c3
...
...
@@ -47,9 +47,9 @@ describe Gitlab::EtagCaching::Middleware do
it
'tracks "etag_caching_key_not_found" event'
do
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_middleware_used
)
.
with
(
:etag_caching_middleware_used
,
endpoint:
'issue_notes'
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_key_not_found
)
.
with
(
:etag_caching_key_not_found
,
endpoint:
'issue_notes'
)
middleware
.
call
(
build_env
(
path
,
if_none_match
))
end
...
...
@@ -93,9 +93,9 @@ describe Gitlab::EtagCaching::Middleware do
it
'tracks "etag_caching_cache_hit" event'
do
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_middleware_used
)
.
with
(
:etag_caching_middleware_used
,
endpoint:
'issue_notes'
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_cache_hit
)
.
with
(
:etag_caching_cache_hit
,
endpoint:
'issue_notes'
)
middleware
.
call
(
build_env
(
path
,
if_none_match
))
end
...
...
@@ -132,9 +132,9 @@ describe Gitlab::EtagCaching::Middleware do
mock_app_response
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_middleware_used
)
.
with
(
:etag_caching_middleware_used
,
endpoint:
'issue_notes'
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_resource_changed
)
.
with
(
:etag_caching_resource_changed
,
endpoint:
'issue_notes'
)
middleware
.
call
(
build_env
(
path
,
if_none_match
))
end
...
...
@@ -150,9 +150,9 @@ describe Gitlab::EtagCaching::Middleware do
it
'tracks "etag_caching_header_missing" event'
do
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_middleware_used
)
.
with
(
:etag_caching_middleware_used
,
endpoint:
'issue_notes'
)
expect
(
Gitlab
::
Metrics
).
to
receive
(
:add_event
)
.
with
(
:etag_caching_header_missing
)
.
with
(
:etag_caching_header_missing
,
endpoint:
'issue_notes'
)
middleware
.
call
(
build_env
(
path
,
if_none_match
))
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