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
81fc0554
Commit
81fc0554
authored
Mar 01, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add open gauge counter
parent
73345bef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
8 deletions
+36
-8
internal/builds/register.go
internal/builds/register.go
+36
-8
No files found.
internal/builds/register.go
View file @
81fc0554
...
@@ -19,11 +19,18 @@ const (
...
@@ -19,11 +19,18 @@ const (
var
(
var
(
registerHandlerHits
=
prometheus
.
NewCounterVec
(
registerHandlerHits
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
prometheus
.
CounterOpts
{
Name
:
"gitlab_workhorse_builds_register_handler"
,
Name
:
"gitlab_workhorse_builds_register_handler
_hits
"
,
Help
:
"
How many connections gitlab-workhorse has opened in total. Can be used to track Redis connection rate for this process
"
,
Help
:
"
Describes how many requests in different states hit a register handler
"
,
},
},
[]
string
{
"status"
},
[]
string
{
"status"
},
)
)
registerHandlerOpen
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"gitlab_workhorse_builds_register_handler_open"
,
Help
:
"Describes how many requests is currently open in given state"
,
},
[]
string
{
"state"
},
)
)
)
type
largeBodyError
struct
{
error
}
type
largeBodyError
struct
{
error
}
...
@@ -32,6 +39,7 @@ type watchError struct{ error }
...
@@ -32,6 +39,7 @@ type watchError struct{ error }
func
init
()
{
func
init
()
{
prometheus
.
MustRegister
(
prometheus
.
MustRegister
(
registerHandlerHits
,
registerHandlerHits
,
registerHandlerOpen
,
)
)
}
}
...
@@ -45,6 +53,27 @@ func readRunnerToken(r *http.Request) (string, error) {
...
@@ -45,6 +53,27 @@ func readRunnerToken(r *http.Request) (string, error) {
return
token
,
nil
return
token
,
nil
}
}
func
readRunnerBody
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
([]
byte
,
error
)
{
registerHandlerOpen
.
WithLabelValues
(
"reading"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"reading"
)
.
Dec
()
return
helper
.
ReadRequestBody
(
w
,
r
,
maxRegisterBodySize
)
}
func
proxyRegisterRequest
(
h
http
.
Handler
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
registerHandlerOpen
.
WithLabelValues
(
"proxying"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"proxying"
)
.
Dec
()
h
.
ServeHTTP
(
w
,
r
)
}
func
watchForRunnerChange
(
token
,
lastUpdate
string
,
duration
time
.
Duration
)
(
redis
.
WatchKeyStatus
,
error
)
{
registerHandlerOpen
.
WithLabelValues
(
"watching"
)
.
Inc
()
defer
registerHandlerOpen
.
WithLabelValues
(
"watching"
)
.
Dec
()
return
redis
.
WatchKey
(
runnerBuildQueue
+
token
,
lastUpdate
,
duration
)
}
func
RegisterHandler
(
h
http
.
Handler
,
pollingDuration
time
.
Duration
)
http
.
Handler
{
func
RegisterHandler
(
h
http
.
Handler
,
pollingDuration
time
.
Duration
)
http
.
Handler
{
if
pollingDuration
==
0
{
if
pollingDuration
==
0
{
return
h
return
h
...
@@ -53,13 +82,12 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
...
@@ -53,13 +82,12 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
lastUpdate
:=
r
.
Header
.
Get
(
runnerBuildQueueValue
)
lastUpdate
:=
r
.
Header
.
Get
(
runnerBuildQueueValue
)
if
lastUpdate
==
""
{
if
lastUpdate
==
""
{
// The client doesn't have update, fail
registerHandlerHits
.
WithLabelValues
(
"missing-value"
)
.
Inc
()
registerHandlerHits
.
WithLabelValues
(
"missing-value"
)
.
Inc
()
h
.
ServeHTTP
(
w
,
r
)
proxyRegisterRequest
(
h
,
w
,
r
)
return
return
}
}
requestBody
,
err
:=
helper
.
ReadRequestBody
(
w
,
r
,
maxRegisterBodySize
)
requestBody
,
err
:=
readRunnerBody
(
w
,
r
)
if
err
!=
nil
{
if
err
!=
nil
{
registerHandlerHits
.
WithLabelValues
(
"body-read-error"
)
.
Inc
()
registerHandlerHits
.
WithLabelValues
(
"body-read-error"
)
.
Inc
()
helper
.
Fail500
(
w
,
r
,
&
largeBodyError
{
err
})
helper
.
Fail500
(
w
,
r
,
&
largeBodyError
{
err
})
...
@@ -69,11 +97,11 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
...
@@ -69,11 +97,11 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
runnerToken
,
err
:=
readRunnerToken
(
helper
.
CloneRequestWithNewBody
(
r
,
requestBody
))
runnerToken
,
err
:=
readRunnerToken
(
helper
.
CloneRequestWithNewBody
(
r
,
requestBody
))
if
runnerToken
==
""
||
err
!=
nil
{
if
runnerToken
==
""
||
err
!=
nil
{
registerHandlerHits
.
WithLabelValues
(
"body-parse-error"
)
.
Inc
()
registerHandlerHits
.
WithLabelValues
(
"body-parse-error"
)
.
Inc
()
h
.
ServeHTTP
(
w
,
r
)
proxyRegisterRequest
(
h
,
w
,
r
)
return
return
}
}
result
,
err
:=
redis
.
WatchKey
(
runnerBuildQueue
+
runnerToken
,
lastUpdate
,
pollingDuration
)
result
,
err
:=
watchForRunnerChange
(
runnerToken
,
lastUpdate
,
pollingDuration
)
if
err
!=
nil
{
if
err
!=
nil
{
registerHandlerHits
.
WithLabelValues
(
"watch-error"
)
.
Inc
()
registerHandlerHits
.
WithLabelValues
(
"watch-error"
)
.
Inc
()
helper
.
Fail500
(
w
,
r
,
&
watchError
{
err
})
helper
.
Fail500
(
w
,
r
,
&
watchError
{
err
})
...
@@ -85,7 +113,7 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
...
@@ -85,7 +113,7 @@ func RegisterHandler(h http.Handler, pollingDuration time.Duration) http.Handler
// We proxy request to Rails, to see whether we can receive the build
// We proxy request to Rails, to see whether we can receive the build
case
redis
.
WatchKeyStatusAlreadyChanged
:
case
redis
.
WatchKeyStatusAlreadyChanged
:
registerHandlerHits
.
WithLabelValues
(
"already-changed"
)
.
Inc
()
registerHandlerHits
.
WithLabelValues
(
"already-changed"
)
.
Inc
()
h
.
ServeHTTP
(
w
,
helper
.
CloneRequestWithNewBody
(
r
,
requestBody
))
proxyRegisterRequest
(
h
,
w
,
helper
.
CloneRequestWithNewBody
(
r
,
requestBody
))
// It means that we detected a change after watching.
// It means that we detected a change after watching.
// We could potentially proxy request to Rails, but...
// We could potentially proxy request to Rails, but...
...
...
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