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
Boxiang Sun
gitlab-ce
Commits
95a23d24
Commit
95a23d24
authored
Sep 07, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert rails_queue_duration to metric_rails_queue_duration_seconds
parent
44eedb22
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
lib/gitlab/middleware/rails_queue_duration.rb
lib/gitlab/middleware/rails_queue_duration.rb
+12
-1
spec/lib/gitlab/middleware/rails_queue_duration_spec.rb
spec/lib/gitlab/middleware/rails_queue_duration_spec.rb
+11
-1
No files found.
lib/gitlab/middleware/rails_queue_duration.rb
View file @
95a23d24
...
...
@@ -14,11 +14,22 @@ module Gitlab
proxy_start
=
env
[
'HTTP_GITLAB_WORKHORSE_PROXY_START'
].
presence
if
trans
&&
proxy_start
# Time in milliseconds since gitlab-workhorse started the request
trans
.
set
(
:rails_queue_duration
,
Time
.
now
.
to_f
*
1_000
-
proxy_start
.
to_f
/
1_000_000
)
duration
=
Time
.
now
.
to_f
*
1_000
-
proxy_start
.
to_f
/
1_000_000
trans
.
set
(
:rails_queue_duration
,
duration
)
self
.
class
.
metric_rails_queue_duration_seconds
.
observe
(
trans
.
labels
,
duration
/
1_000
)
end
@app
.
call
(
env
)
end
private
def
self
.
metric_rails_queue_duration_seconds
@metric_rails_queue_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_rails_queue_duration_seconds
,
Gitlab
::
Metrics
::
Transaction
::
BASE_LABELS
)
end
end
end
end
spec/lib/gitlab/middleware/rails_queue_duration_spec.rb
View file @
95a23d24
...
...
@@ -4,7 +4,7 @@ describe Gitlab::Middleware::RailsQueueDuration do
let
(
:app
)
{
double
(
:app
)
}
let
(
:middleware
)
{
described_class
.
new
(
app
)
}
let
(
:env
)
{
{}
}
let
(
:transaction
)
{
double
(
:transaction
)
}
let
(
:transaction
)
{
Gitlab
::
Metrics
::
Transaction
.
new
(
env
)
}
before
do
expect
(
app
).
to
receive
(
:call
).
with
(
env
).
and_return
(
'yay'
)
...
...
@@ -30,6 +30,16 @@ describe Gitlab::Middleware::RailsQueueDuration do
expect
(
transaction
).
to
receive
(
:set
).
with
(
:rails_queue_duration
,
an_instance_of
(
Float
))
expect
(
middleware
.
call
(
env
)).
to
eq
(
'yay'
)
end
it
'observes rails queue duration metrics and calls the app when the header is present'
do
env
[
'HTTP_GITLAB_WORKHORSE_PROXY_START'
]
=
'2000000000'
expect
(
described_class
.
metric_rails_queue_duration_seconds
).
to
receive
(
:observe
).
with
(
transaction
.
labels
,
1
)
Timecop
.
freeze
(
Time
.
at
(
3
))
do
expect
(
middleware
.
call
(
env
)).
to
eq
(
'yay'
)
end
end
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