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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
2d0741e5
Commit
2d0741e5
authored
Jul 13, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ConnectionRackMiddleware to RequestsRackMiddleware.
+ fix tests after metrics rename
parent
79465fb3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
20 deletions
+54
-20
config/initializers/8_metrics.rb
config/initializers/8_metrics.rb
+1
-1
lib/gitlab/metrics/requests_rack_middleware.rb
lib/gitlab/metrics/requests_rack_middleware.rb
+40
-0
spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb
spec/lib/gitlab/metrics/requests_rack_middleware_spec.rb
+13
-19
No files found.
config/initializers/8_metrics.rb
View file @
2d0741e5
...
...
@@ -123,7 +123,7 @@ Gitlab::Metrics::UnicornSampler.initialize_instance(Settings.monitoring.unicorn_
Gitlab
::
Application
.
configure
do
|
config
|
# 0 should be Sentry to catch errors in this middleware
config
.
middleware
.
insert
(
1
,
Gitlab
::
Metrics
::
Connection
RackMiddleware
)
config
.
middleware
.
insert
(
1
,
Gitlab
::
Metrics
::
Requests
RackMiddleware
)
end
if
Gitlab
::
Metrics
.
enabled?
...
...
lib/gitlab/metrics/
connection
_rack_middleware.rb
→
lib/gitlab/metrics/
requests
_rack_middleware.rb
View file @
2d0741e5
module
Gitlab
module
Metrics
class
Connection
RackMiddleware
class
Requests
RackMiddleware
def
initialize
(
app
)
@app
=
app
end
def
self
.
rack_request_count
@
rack_request_count
||=
Gitlab
::
Metrics
.
counter
(
:http_requests_total
,
'Rack r
equest count'
)
def
self
.
http_request_total
@
http_request_total
||=
Gitlab
::
Metrics
.
counter
(
:http_requests_total
,
'R
equest count'
)
end
def
self
.
rack_uncaught_errors_count
@rack_uncaught_errors_count
||=
Gitlab
::
Metrics
.
counter
(
:rack_uncaught_errors_total
,
'R
ack connections
handling uncaught errors count'
)
@rack_uncaught_errors_count
||=
Gitlab
::
Metrics
.
counter
(
:rack_uncaught_errors_total
,
'R
equest
handling uncaught errors count'
)
end
def
self
.
rack_execution_time
@
rack_execution_time
||=
Gitlab
::
Metrics
.
histogram
(
:http_request_duration_seconds
,
'Rack connection
handling execution time'
,
{},
[
0.05
,
0.1
,
0.25
,
0.5
,
0.7
,
1
,
1.5
,
2
,
2.5
,
3
,
5
,
7
,
10
])
def
self
.
http_request_duration_seconds
@
http_request_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:http_request_duration_seconds
,
'Request
handling execution time'
,
{},
[
0.05
,
0.1
,
0.25
,
0.5
,
0.7
,
1
,
2.5
,
5
,
10
,
25
])
end
def
call
(
env
)
method
=
env
[
'REQUEST_METHOD'
].
downcase
started
=
Time
.
now
.
to_f
begin
ConnectionRackMiddleware
.
rack_request_count
.
increment
(
method:
method
)
RequestsRackMiddleware
.
http_request_total
.
increment
(
method:
method
)
status
,
headers
,
body
=
@app
.
call
(
env
)
elapsed
=
Time
.
now
.
to_f
-
started
RequestsRackMiddleware
.
http_request_duration_seconds
.
observe
({
method:
method
,
status:
status
},
elapsed
)
[
status
,
headers
,
body
]
rescue
Connection
RackMiddleware
.
rack_uncaught_errors_count
.
increment
Requests
RackMiddleware
.
rack_uncaught_errors_count
.
increment
raise
ensure
elapsed
=
Time
.
now
.
to_f
-
started
ConnectionRackMiddleware
.
rack_execution_time
.
observe
({
method:
method
,
status:
status
},
elapsed
)
end
end
end
...
...
spec/lib/gitlab/metrics/
connection
_rack_middleware_spec.rb
→
spec/lib/gitlab/metrics/
requests
_rack_middleware_spec.rb
View file @
2d0741e5
require
'spec_helper'
describe
Gitlab
::
Metrics
::
Connection
RackMiddleware
do
describe
Gitlab
::
Metrics
::
Requests
RackMiddleware
do
let
(
:app
)
{
double
(
'app'
)
}
subject
{
described_class
.
new
(
app
)
}
...
...
@@ -23,7 +23,7 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
end
it
'increments requests count'
do
expect
(
described_class
).
to
receive_message_chain
(
:
rack_request_count
,
:increment
).
with
(
method:
'get'
)
expect
(
described_class
).
to
receive_message_chain
(
:
http_request_total
,
:increment
).
with
(
method:
'get'
)
subject
.
call
(
env
)
end
...
...
@@ -32,16 +32,22 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
execution_time
=
10
allow
(
app
).
to
receive
(
:call
)
do
|*
args
|
Timecop
.
freeze
(
execution_time
.
seconds
)
[
200
,
nil
,
nil
]
end
expect
(
described_class
).
to
receive_message_chain
(
:
rack_execution_time
,
:observe
).
with
({
status:
200
,
method:
'get'
},
execution_time
)
expect
(
described_class
).
to
receive_message_chain
(
:
http_request_duration_seconds
,
:observe
).
with
({
status:
200
,
method:
'get'
},
execution_time
)
subject
.
call
(
env
)
end
end
context
'@app.call throws exception'
do
let
(
:rack_response_count
)
{
double
(
'rack_response_count'
)
}
let
(
:http_request_duration_seconds
)
{
double
(
'http_request_duration_seconds'
)
}
before
do
allow
(
app
).
to
receive
(
:call
).
and_raise
(
StandardError
)
allow
(
described_class
).
to
receive
(
:http_request_duration_seconds
).
and_return
(
http_request_duration_seconds
)
end
it
'increments exceptions count'
do
expect
(
described_class
).
to
receive_message_chain
(
:rack_uncaught_errors_count
,
:increment
)
...
...
@@ -50,25 +56,13 @@ describe Gitlab::Metrics::ConnectionRackMiddleware do
end
it
'increments requests count'
do
expect
(
described_class
).
to
receive_message_chain
(
:rack_request_count
,
:increment
).
with
(
method:
'get'
)
expect
{
subject
.
call
(
env
)
}.
to
raise_error
(
StandardError
)
end
it
"does't increment response count"
do
expect
(
described_class
.
rack_response_count
).
not_to
receive
(
:increment
)
expect
(
described_class
).
to
receive_message_chain
(
:http_request_total
,
:increment
).
with
(
method:
'get'
)
expect
{
subject
.
call
(
env
)
}.
to
raise_error
(
StandardError
)
end
it
'measures execution time'
do
execution_time
=
10
allow
(
app
).
to
receive
(
:call
)
do
|*
args
|
Timecop
.
freeze
(
execution_time
.
seconds
)
raise
StandardError
end
expect
(
described_class
).
to
receive_message_chain
(
:rack_execution_time
,
:observe
).
with
({},
execution_time
)
it
"does't measure request execution time"
do
expect
(
described_class
.
http_request_duration_seconds
).
not_to
receive
(
:increment
)
expect
{
subject
.
call
(
env
)
}.
to
raise_error
(
StandardError
)
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