Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-workhorse
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-workhorse
Commits
83e148de
Commit
83e148de
authored
Jul 25, 2017
by
Jacob Vosmaer (GitLab)
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bjk/histogram' into 'master'
Add histograms to routes See merge request !184
parents
e6cfe0c0
d1522d6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
2 deletions
+26
-2
internal/upstream/routes.go
internal/upstream/routes.go
+26
-2
No files found.
internal/upstream/routes.go
View file @
83e148de
...
...
@@ -4,8 +4,10 @@ import (
"net/http"
"path"
"regexp"
"time"
"github.com/gorilla/websocket"
"github.com/prometheus/client_golang/prometheus"
apipkg
"gitlab.com/gitlab-org/gitlab-workhorse/internal/api"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/artifacts"
...
...
@@ -39,6 +41,20 @@ const (
projectPattern
=
`^/([^/]+/){1,}[^/]+/`
)
var
(
routeRequestDurations
=
prometheus
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Name
:
"gitlab_workhorse_request_duration_seconds"
,
Help
:
"A histogram of request times in seconds"
,
Buckets
:
prometheus
.
ExponentialBuckets
(
0.01
,
2.5
,
10
),
},
[]
string
{
"method"
,
"route"
},
)
)
func
init
()
{
prometheus
.
MustRegister
(
routeRequestDurations
)
}
func
compileRegexp
(
regexpStr
string
)
*
regexp
.
Regexp
{
if
len
(
regexpStr
)
==
0
{
return
nil
...
...
@@ -47,11 +63,19 @@ func compileRegexp(regexpStr string) *regexp.Regexp {
return
regexp
.
MustCompile
(
regexpStr
)
}
func
instrumentDuration
(
h
http
.
Handler
,
method
string
,
regexpStr
string
)
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
start
:=
time
.
Now
()
h
.
ServeHTTP
(
w
,
r
)
routeRequestDurations
.
WithLabelValues
(
method
,
regexpStr
)
.
Observe
(
time
.
Since
(
start
)
.
Seconds
())
})
}
func
route
(
method
,
regexpStr
string
,
handler
http
.
Handler
,
matchers
...
matcherFunc
)
routeEntry
{
return
routeEntry
{
method
:
method
,
regex
:
compileRegexp
(
regexpStr
),
handler
:
denyWebsocket
(
handle
r
),
handler
:
instrumentDuration
(
denyWebsocket
(
handler
),
method
,
regexpSt
r
),
matchers
:
matchers
,
}
}
...
...
@@ -60,7 +84,7 @@ func wsRoute(regexpStr string, handler http.Handler, matchers ...matcherFunc) ro
return
routeEntry
{
method
:
"GET"
,
regex
:
compileRegexp
(
regexpStr
),
handler
:
handler
,
handler
:
instrumentDuration
(
handler
,
"GET"
,
regexpStr
)
,
matchers
:
append
(
matchers
,
websocket
.
IsWebSocketUpgrade
),
}
}
...
...
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